mirror of
https://github.com/gnif/LookingGlass.git
synced 2025-11-29 20:58:18 +00:00
[host] windows: add delayExecution function for more accurate sleeps
This change not only exposes and allows use of NtDelayExecution, but also moves the code to set the system timer resolution.
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
|
||||
#include "platform.h"
|
||||
#include "service.h"
|
||||
#include "windows/delay.h"
|
||||
#include "windows/mousehook.h"
|
||||
|
||||
#include <windows.h>
|
||||
@@ -61,10 +62,6 @@ struct AppState
|
||||
static struct AppState app = {0};
|
||||
HWND MessageHWND;
|
||||
|
||||
// undocumented API to adjust the system timer resolution (yes, its a nasty hack)
|
||||
typedef NTSTATUS (__stdcall *ZwSetTimerResolution_t)(ULONG RequestedResolution, BOOLEAN Set, PULONG ActualResolution);
|
||||
static ZwSetTimerResolution_t ZwSetTimerResolution = NULL;
|
||||
|
||||
// linux mingw64 is missing this
|
||||
#ifndef MSGFLT_RESET
|
||||
#define MSGFLT_RESET (0)
|
||||
@@ -504,7 +501,7 @@ void boostPriority(void)
|
||||
|
||||
bool app_init(void)
|
||||
{
|
||||
const char * logFile = option_get_string("os", "logFile" );
|
||||
const char * logFile = option_get_string("os", "logFile");
|
||||
|
||||
// redirect stderr to a file
|
||||
if (logFile && strcmp(logFile, "stderr") != 0)
|
||||
@@ -513,14 +510,7 @@ bool app_init(void)
|
||||
// always flush stderr
|
||||
setbuf(stderr, NULL);
|
||||
|
||||
// Increase the timer resolution
|
||||
ZwSetTimerResolution = (ZwSetTimerResolution_t)GetProcAddress(GetModuleHandle("ntdll.dll"), "ZwSetTimerResolution");
|
||||
if (ZwSetTimerResolution)
|
||||
{
|
||||
ULONG actualResolution;
|
||||
ZwSetTimerResolution(1, true, &actualResolution);
|
||||
DEBUG_INFO("System timer resolution: %lu ns", actualResolution * 100);
|
||||
}
|
||||
delayInit();
|
||||
|
||||
// get the performance frequency for spinlocks
|
||||
QueryPerformanceFrequency(&app.perfFreq);
|
||||
|
||||
Reference in New Issue
Block a user