2
0

ntapi.patch 1.6 KB

123456789101112131415161718192021222324252627282930313233343536
  1. diff --git a/core/shared/platform/windows/win_clock.c b/core/shared/platform/windows/win_clock.c
  2. index c96bdfb3..48e2c449 100644
  3. --- a/core/shared/platform/windows/win_clock.c
  4. +++ b/core/shared/platform/windows/win_clock.c
  5. @@ -55,14 +55,30 @@ os_clock_res_get(__wasi_clockid_t clock_id, __wasi_timestamp_t *resolution)
  6. case __WASI_CLOCK_THREAD_CPUTIME_ID:
  7. {
  8. #if WINAPI_PARTITION_DESKTOP
  9. + HMODULE ntdll = LoadLibrary("ntdll.dll");
  10. + if (!ntdll) {
  11. + return __WASI_ENOTSUP;
  12. + }
  13. +
  14. + typedef NTSTATUS(NTAPI *LPFN_NtQueryTimerResolution)(
  15. + OUT PULONG MinimumResolution,
  16. + OUT PULONG MaximumResolution,
  17. + OUT PULONG CurrentResolution
  18. + );
  19. + LPFN_NtQueryTimerResolution pNtQueryTimerResolution = (LPFN_NtQueryTimerResolution)GetProcAddress(ntdll, "NtQueryTimerResolution");
  20. + if (!pNtQueryTimerResolution) {
  21. + return __WASI_ENOTSUP;
  22. + }
  23. +
  24. ULONG maximum_time;
  25. ULONG minimum_time;
  26. ULONG current_time;
  27. NTSTATUS
  28. - status = NtQueryTimerResolution(&maximum_time, &minimum_time,
  29. + status = pNtQueryTimerResolution(&maximum_time, &minimum_time,
  30. &current_time);
  31. uint64 result = (uint64)current_time * NANOSECONDS_PER_TICK;
  32. *resolution = result / (uint64)NANOSECONDS_PER_SECOND;
  33. + FreeLibrary(ntdll);
  34. return error;
  35. #else
  36. return __WASI_ENOTSUP;