Signed-off-by: Huw Davies huw@codeweavers.com --- dlls/ntdll/ntdll.spec | 1 + dlls/ntdll/time.c | 33 +++++++++++++++++++++++++++++++++ include/winternl.h | 1 + 3 files changed, 35 insertions(+)
diff --git a/dlls/ntdll/ntdll.spec b/dlls/ntdll/ntdll.spec index 292b0f6a9f..aeb9735ba1 100644 --- a/dlls/ntdll/ntdll.spec +++ b/dlls/ntdll/ntdll.spec @@ -680,6 +680,7 @@ @ stdcall RtlGetSaclSecurityDescriptor(ptr ptr ptr ptr) # @ stub RtlGetSecurityDescriptorRMControl # @ stub RtlGetSetBootStatusData +@ stdcall -ret64 RtlGetSystemTimePrecise() @ stdcall RtlGetThreadErrorMode() @ stdcall RtlGetUnloadEventTrace() @ stdcall RtlGetUnloadEventTraceEx(ptr ptr ptr) diff --git a/dlls/ntdll/time.c b/dlls/ntdll/time.c index 443d8b26be..d0a7954377 100644 --- a/dlls/ntdll/time.c +++ b/dlls/ntdll/time.c @@ -474,6 +474,39 @@ NTSTATUS WINAPI NtQuerySystemTime( PLARGE_INTEGER Time ) return STATUS_SUCCESS; }
+/*********************************************************************** + * RtlGetSystemTimePrecise [NTDLL.@] + * + * Get a more accurate current system time. + * + * RETURNS + * The current system time. + */ +LONGLONG WINAPI RtlGetSystemTimePrecise( void ) +{ + LONGLONG time; + +#if defined(HAVE_CLOCK_GETTIME) + struct timespec ts; + + if (!clock_gettime( CLOCK_REALTIME, &ts )) + { + time = ts.tv_sec * (ULONGLONG)TICKSPERSEC + TICKS_1601_TO_1970; + time += (ts.tv_nsec + 50) / 100; + } + else +#endif + { + struct timeval now; + + gettimeofday( &now, 0 ); + time = now.tv_sec * (ULONGLONG)TICKSPERSEC + TICKS_1601_TO_1970; + time += now.tv_usec * 10; + } + + return time; +} + /****************************************************************************** * NtQueryPerformanceCounter [NTDLL.@] */ diff --git a/include/winternl.h b/include/winternl.h index 2b3fb947b9..e7f89b0059 100644 --- a/include/winternl.h +++ b/include/winternl.h @@ -2710,6 +2710,7 @@ NTSYSAPI NTSTATUS WINAPI RtlGetOwnerSecurityDescriptor(PSECURITY_DESCRIPTOR,PSI NTSYSAPI ULONG WINAPI RtlGetProcessHeaps(ULONG,HANDLE*); NTSYSAPI DWORD WINAPI RtlGetThreadErrorMode(void); NTSYSAPI NTSTATUS WINAPI RtlGetSaclSecurityDescriptor(PSECURITY_DESCRIPTOR,PBOOLEAN,PACL *,PBOOLEAN); +NTSYSAPI LONGLONG WINAPI RtlGetSystemTimePrecise(void); NTSYSAPI NTSTATUS WINAPI RtlGetVersion(RTL_OSVERSIONINFOEXW*); NTSYSAPI NTSTATUS WINAPI RtlGUIDFromString(PUNICODE_STRING,GUID*); NTSYSAPI PSID_IDENTIFIER_AUTHORITY WINAPI RtlIdentifierAuthoritySid(PSID);
On May 2, 2019, at 3:45 AM, Huw Davies huw@codeweavers.com wrote:
Signed-off-by: Huw Davies huw@codeweavers.com
dlls/ntdll/ntdll.spec | 1 + dlls/ntdll/time.c | 33 +++++++++++++++++++++++++++++++++ include/winternl.h | 1 + 3 files changed, 35 insertions(+)
diff --git a/dlls/ntdll/time.c b/dlls/ntdll/time.c index 443d8b26be..d0a7954377 100644 --- a/dlls/ntdll/time.c +++ b/dlls/ntdll/time.c @@ -474,6 +474,39 @@ NTSTATUS WINAPI NtQuerySystemTime( PLARGE_INTEGER Time ) return STATUS_SUCCESS; }
+/***********************************************************************
RtlGetSystemTimePrecise [NTDLL.@]
- Get a more accurate current system time.
- RETURNS
- The current system time.
- */
+LONGLONG WINAPI RtlGetSystemTimePrecise( void ) +{
- LONGLONG time;
+#if defined(HAVE_CLOCK_GETTIME)
- struct timespec ts;
- if (!clock_gettime( CLOCK_REALTIME, &ts ))
- {
time = ts.tv_sec * (ULONGLONG)TICKSPERSEC + TICKS_1601_TO_1970;
time += (ts.tv_nsec + 50) / 100;
- }
- else
+#endif
Using clock_gettime() on macOS is a bit problematic because of backward deployment and weak linking. See <https://source.winehq.org/git/wine.git/commit/27c71e09ad51ba6aa672a46379efd1... https://source.winehq.org/git/wine.git/commit/27c71e09ad51ba6aa672a46379efd10b5959863f>, although that's not necessarily my preferred approach. (I wanted to check if it was available at run-time and use it, if so. Alexandre didn't like that.)
-Ken
On Thu, May 02, 2019 at 08:55:39AM -0500, Ken Thomases wrote:
On May 2, 2019, at 3:45 AM, Huw Davies huw@codeweavers.com wrote:
+/***********************************************************************
RtlGetSystemTimePrecise [NTDLL.@]
- Get a more accurate current system time.
- RETURNS
- The current system time.
- */
+LONGLONG WINAPI RtlGetSystemTimePrecise( void ) +{
- LONGLONG time;
+#if defined(HAVE_CLOCK_GETTIME)
- struct timespec ts;
- if (!clock_gettime( CLOCK_REALTIME, &ts ))
- {
time = ts.tv_sec * (ULONGLONG)TICKSPERSEC + TICKS_1601_TO_1970;
time += (ts.tv_nsec + 50) / 100;
- }
- else
+#endif
Using clock_gettime() on macOS is a bit problematic because of backward deployment and weak linking. See <https://source.winehq.org/git/wine.git/commit/27c71e09ad51ba6aa672a46379efd1... although that's not necessarily my preferred approach. (I wanted to check if it was available at run-time and use it, if so. Alexandre didn't like that.)
Gah, how annoying! Perhaps we should disable the HAVE_CLOCK_GETTIME configure test on macOS in that case?
Huw.
On May 2, 2019, at 9:12 AM, Huw Davies huw@codeweavers.com wrote:
On Thu, May 02, 2019 at 08:55:39AM -0500, Ken Thomases wrote:
On May 2, 2019, at 3:45 AM, Huw Davies huw@codeweavers.com wrote:
+/***********************************************************************
RtlGetSystemTimePrecise [NTDLL.@]
- Get a more accurate current system time.
- RETURNS
- The current system time.
- */
+LONGLONG WINAPI RtlGetSystemTimePrecise( void ) +{
- LONGLONG time;
+#if defined(HAVE_CLOCK_GETTIME)
- struct timespec ts;
- if (!clock_gettime( CLOCK_REALTIME, &ts ))
- {
time = ts.tv_sec * (ULONGLONG)TICKSPERSEC + TICKS_1601_TO_1970;
time += (ts.tv_nsec + 50) / 100;
- }
- else
+#endif
Using clock_gettime() on macOS is a bit problematic because of backward deployment and weak linking. See <https://source.winehq.org/git/wine.git/commit/27c71e09ad51ba6aa672a46379efd1... although that's not necessarily my preferred approach. (I wanted to check if it was available at run-time and use it, if so. Alexandre didn't like that.)
Gah, how annoying! Perhaps we should disable the HAVE_CLOCK_GETTIME configure test on macOS in that case?
Perhaps we could try to detect if it's strong linked or weak linked in the configure test. It will be strong linked if the deployment target is guaranteed to have it.
One way would be to check the output of "nm -m conftest.o" for "weak .* _clock_gettime" or so.
Another would be to compile code with "if (clock_gettime == NULL) …" with "-Werror=tautological-pointer-compare". If that fails, then it's strong linked. If it gets no error, then it's weak linked.
-Ken