From d76f9f9637e668f56b593d655e0ba4e816ca8d27 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Sun, 1 Oct 2000 01:40:42 +0000 Subject: [PATCH] Implemented a bunch of large integer functions in ntdll. --- dlls/kernel/time.c | 10 +++ dlls/ntdll/Makefile.in | 1 + dlls/ntdll/large_int.c | 182 +++++++++++++++++++++++++++++++++++++++++++++++++ dlls/ntdll/ntdll.spec | 32 ++++----- dlls/ntdll/rtl.c | 43 ------------ dlls/ntdll/time.c | 55 ++++++++++----- include/ntddk.h | 57 +++++++--------- include/winnt.h | 4 +- scheduler/timer.c | 24 +++---- win32/time.c | 13 ---- 10 files changed, 282 insertions(+), 139 deletions(-) create mode 100644 dlls/ntdll/large_int.c diff --git a/dlls/kernel/time.c b/dlls/kernel/time.c index 3db968e269f..b7cd314b7e2 100644 --- a/dlls/kernel/time.c +++ b/dlls/kernel/time.c @@ -194,6 +194,16 @@ BOOL WINAPI SystemTimeToTzSpecificLocalTime( return FALSE; } + +/*********************************************************************** + * GetSystemTimeAsFileTime (KERNEL32) + */ +VOID WINAPI GetSystemTimeAsFileTime( LPFILETIME time ) +{ + NtQuerySystemTime( (LARGE_INTEGER *)time ); +} + + /********************************************************************* * TIME_ClockTimeToFileTime * (olorin@fandra.org, 20-Sep-1998) diff --git a/dlls/ntdll/Makefile.in b/dlls/ntdll/Makefile.in index e5e24816609..e240706ca3c 100644 --- a/dlls/ntdll/Makefile.in +++ b/dlls/ntdll/Makefile.in @@ -12,6 +12,7 @@ C_SRCS = \ exception.c \ error.c \ file.c \ + large_int.c \ misc.c \ nt.c \ om.c \ diff --git a/dlls/ntdll/large_int.c b/dlls/ntdll/large_int.c new file mode 100644 index 00000000000..da32b390397 --- /dev/null +++ b/dlls/ntdll/large_int.c @@ -0,0 +1,182 @@ +/* + * Large integer functions + * + * Copyright 2000 Alexandre Julliard + */ + +#include "winnt.h" +#include "ntddk.h" + +/* + * Note: we use LONGLONG instead of LARGE_INTEGER, because + * the latter is a structure and the calling convention for + * returning a structure would not be binary-compatible. + * + * FIXME: for platforms that don't have a native LONGLONG type, + * we should define LONGLONG as a structure similar to LARGE_INTEGER + * and do everything by hand. You are welcome to do it... + */ + +/****************************************************************************** + * RtlLargeIntegerAdd (NTDLL.@) + */ +LONGLONG WINAPI RtlLargeIntegerAdd( LONGLONG a, LONGLONG b ) +{ + return a + b; +} + + +/****************************************************************************** + * RtlLargeIntegerSubtract (NTDLL.@) + */ +LONGLONG WINAPI RtlLargeIntegerSubtract( LONGLONG a, LONGLONG b ) +{ + return a - b; +} + + +/****************************************************************************** + * RtlLargeIntegerNegate (NTDLL.@) + */ +LONGLONG WINAPI RtlLargeIntegerNegate( LONGLONG a ) +{ + return -a; +} + + +/****************************************************************************** + * RtlLargeIntegerShiftLeft (NTDLL.@) + */ +LONGLONG WINAPI RtlLargeIntegerShiftLeft( LONGLONG a, INT count ) +{ + return a << count; +} + + +/****************************************************************************** + * RtlLargeIntegerShiftRight (NTDLL.@) + */ +LONGLONG WINAPI RtlLargeIntegerShiftRight( LONGLONG a, INT count ) +{ + return (ULONGLONG)a >> count; +} + + +/****************************************************************************** + * RtlLargeIntegerArithmeticShift (NTDLL.@) + */ +LONGLONG WINAPI RtlLargeIntegerArithmeticShift( LONGLONG a, INT count ) +{ + /* FIXME: gcc does arithmetic shift here, but it may not be true on all platforms */ + return a >> count; +} + + +/****************************************************************************** + * RtlLargeIntegerDivide (NTDLL.@) + * + * FIXME: should it be signed division instead? + */ +ULONGLONG WINAPI RtlLargeIntegerDivide( ULONGLONG a, ULONGLONG b, ULONGLONG *rem ) +{ + ULONGLONG ret = a / b; + if (rem) *rem = a - ret * b; + return ret; +} + + +/****************************************************************************** + * RtlConvertLongToLargeInteger (NTDLL.@) + */ +LONGLONG WINAPI RtlConvertLongToLargeInteger( LONG a ) +{ + return a; +} + + +/****************************************************************************** + * RtlConvertUlongToLargeInteger (NTDLL.@) + */ +ULONGLONG WINAPI RtlConvertUlongToLargeInteger( ULONG a ) +{ + return a; +} + + +/****************************************************************************** + * RtlEnlargedIntegerMultiply (NTDLL.@) + */ +LONGLONG WINAPI RtlEnlargedIntegerMultiply( INT a, INT b ) +{ + return (LONGLONG)a * b; +} + + +/****************************************************************************** + * RtlEnlargedUnsignedMultiply (NTDLL.@) + */ +LONGLONG WINAPI RtlEnlargedUnsignedMultiply( UINT a, UINT b ) +{ + return (ULONGLONG)a * b; +} + + +/****************************************************************************** + * RtlEnlargedUnsignedDivide (NTDLL.@) + */ +UINT WINAPI RtlEnlargedUnsignedDivide( ULONGLONG a, UINT b, UINT *remptr ) +{ +#if defined(__i386__) && defined(__GNUC__) + UINT ret, rem; + __asm__("div %4,%%eax" + : "=a" (ret), "=d" (rem) + : "0" (*(UINT*)&a), "1" (*((UINT*)&a+1)), "g" (b) ); + if (remptr) *remptr = rem; + return ret; +#else + UINT ret = a / b; + if (remptr) *remptr = a % b; + return ret; +#endif +} + + +/****************************************************************************** + * RtlExtendedLargeIntegerDivide (NTDLL.@) + */ +LONGLONG WINAPI RtlExtendedLargeIntegerDivide( LONGLONG a, INT b, INT *rem ) +{ + LONGLONG ret = a / b; + if (rem) *rem = a - b * ret; + return ret; +} + + +/****************************************************************************** + * RtlExtendedIntegerMultiply (NTDLL.@) + */ +LONGLONG WINAPI RtlExtendedIntegerMultiply( LONGLONG a, INT b ) +{ + return a * b; +} + + +/****************************************************************************** + * RtlExtendedMagicDivide (NTDLL.@) + * + * This function computes (a * b) >> (64 + shift) + * + * This allows replacing a division by a longlong constant + * by a multiplication by the inverse constant. + * + * If 'c' is the constant divisor, the constants 'b' and 'shift' + * must be chosen such that b = 2^(64+shift) / c. + * Then we have RtlExtendedMagicDivide(a,b,shift) == a * b / 2^(64+shift) == a / c. + * + * I'm too lazy to implement it right now... + */ +/* LONGLONG WINAPI RtlExtendedMagicDivide( LONGLONG a, LONGLONG b, INT shift ) + * { + * return 0; + * } + */ diff --git a/dlls/ntdll/ntdll.spec b/dlls/ntdll/ntdll.spec index 53dcdeb9889..99284760c4f 100644 --- a/dlls/ntdll/ntdll.spec +++ b/dlls/ntdll/ntdll.spec @@ -174,7 +174,7 @@ type win32 @ stdcall NtQuerySymbolicLinkObject(long ptr ptr) NtQuerySymbolicLinkObject @ stub NtQuerySystemEnvironmentValue @ stdcall NtQuerySystemInformation(long long long long) NtQuerySystemInformation -@ stdcall NtQuerySystemTime(ptr) GetSystemTimeAsFileTime +@ stdcall NtQuerySystemTime(ptr) NtQuerySystemTime @ stub NtQueryTimer @ stdcall NtQueryTimerResolution(long long long) NtQueryTimerResolution @ stdcall NtQueryValueKey(long long long long long long) NtQueryValueKey @@ -298,11 +298,11 @@ type win32 @ stub RtlCompressBuffer @ stub RtlConsoleMultiByteToUnicodeN @ stub RtlConvertExclusiveToShared -@ stub RtlConvertLongToLargeInteger +@ stdcall64 RtlConvertLongToLargeInteger(long) RtlConvertLongToLargeInteger @ stub RtlConvertSharedToExclusive @ stdcall RtlConvertSidToUnicodeString(ptr ptr)RtlConvertSidToUnicodeString @ stub RtlConvertUiListToApiList -@ stub RtlConvertUlongToLargeInteger +@ stdcall64 RtlConvertUlongToLargeInteger(long) RtlConvertUlongToLargeInteger @ stub RtlCopyLuid @ stub RtlCopyLuidAndAttributesArray @ stub RtlCopySecurityDescriptor @@ -345,9 +345,9 @@ type win32 @ stdcall RtlDosPathNameToNtPathName_U(ptr ptr long long) RtlDosPathNameToNtPathName_U @ stub RtlDosSearchPath_U @ stdcall RtlDumpResource(ptr) RtlDumpResource -@ stub RtlEnlargedIntegerMultiply -@ stub RtlEnlargedUnsignedDivide -@ stub RtlEnlargedUnsignedMultiply +@ stdcall64 RtlEnlargedIntegerMultiply(long long) RtlEnlargedIntegerMultiply +@ stdcall RtlEnlargedUnsignedDivide(long long long ptr) RtlEnlargedUnsignedDivide +@ stdcall64 RtlEnlargedUnsignedMultiply(long long) RtlEnlargedUnsignedMultiply @ stdcall RtlEnterCriticalSection(ptr) RtlEnterCriticalSection @ stub RtlEnumProcessHeaps @ stub RtlEnumerateGenericTable @@ -362,8 +362,8 @@ type win32 @ stdcall RtlEraseUnicodeString(ptr) RtlEraseUnicodeString @ stub RtlExpandEnvironmentStrings_U @ stub RtlExtendHeap -@ stdcall RtlExtendedIntegerMultiply(long long long) RtlExtendedIntegerMultiply -@ stdcall RtlExtendedLargeIntegerDivide(long long long ptr) RtlExtendedLargeIntegerDivide +@ stdcall64 RtlExtendedIntegerMultiply(long long long) RtlExtendedIntegerMultiply +@ stdcall64 RtlExtendedLargeIntegerDivide(long long long ptr) RtlExtendedLargeIntegerDivide @ stub RtlExtendedMagicDivide @ stdcall RtlFillMemory(ptr long long) RtlFillMemory @ stub RtlFillMemoryUlong @@ -422,13 +422,13 @@ type win32 @ stub RtlIsGenericTableEmpty @ stub RtlIsNameLegalDOS8Dot3 @ stdcall RtlIsTextUnicode(ptr long ptr) RtlIsTextUnicode -@ stub RtlLargeIntegerAdd -@ stub RtlLargeIntegerArithmeticShift -@ stub RtlLargeIntegerDivide -@ stub RtlLargeIntegerNegate -@ stub RtlLargeIntegerShiftLeft -@ stub RtlLargeIntegerShiftRight -@ stub RtlLargeIntegerSubtract +@ stdcall64 RtlLargeIntegerAdd(long long long long) RtlLargeIntegerAdd +@ stdcall64 RtlLargeIntegerArithmeticShift(long long long) RtlLargeIntegerArithmeticShift +@ stdcall64 RtlLargeIntegerDivide(long long long long ptr) RtlLargeIntegerDivide +@ stdcall64 RtlLargeIntegerNegate(long long) RtlLargeIntegerNegate +@ stdcall64 RtlLargeIntegerShiftLeft(long long long) RtlLargeIntegerShiftLeft +@ stdcall64 RtlLargeIntegerShiftRight(long long long) RtlLargeIntegerShiftRight +@ stdcall64 RtlLargeIntegerSubtract(long long long long) RtlLargeIntegerSubtract @ stub RtlLargeIntegerToChar @ stdcall RtlLeaveCriticalSection(ptr) RtlLeaveCriticalSection @ stdcall RtlLengthRequiredSid(long) RtlLengthRequiredSid @@ -674,7 +674,7 @@ type win32 @ stub ZwQuerySymbolicLinkObject @ stub ZwQuerySystemEnvironmentValue @ stdcall ZwQuerySystemInformation(long long long long) NtQuerySystemInformation -@ stdcall ZwQuerySystemTime(ptr) GetSystemTimeAsFileTime +@ stdcall ZwQuerySystemTime(ptr) NtQuerySystemTime @ stub ZwQueryTimer @ stub ZwQueryTimerResolution @ stub ZwQueryValueKey diff --git a/dlls/ntdll/rtl.c b/dlls/ntdll/rtl.c index 3097148e08b..bd8e45db537 100644 --- a/dlls/ntdll/rtl.c +++ b/dlls/ntdll/rtl.c @@ -370,49 +370,6 @@ void WINAPI NTDLL_alloca_probe( CONTEXT86 *context ) context->Esp -= context->Eax; } -/****************************************************************************** - * RtlExtendedLargeIntegerDivide [NTDLL.359] - */ -INT WINAPI RtlExtendedLargeIntegerDivide( - LARGE_INTEGER dividend, - DWORD divisor, - LPDWORD rest -) { -#if SIZEOF_LONG_LONG==8 - long long x1 = *(long long*)÷nd; - - if (*rest) - *rest = x1 % divisor; - return x1/divisor; -#else - FIXME("((%ld<<32)+%ld,%ld,%p), implement this using normal integer arithmetic!\n", - dividend.s.HighPart,dividend.s.LowPart,divisor,rest); - return 0; -#endif -} - -/****************************************************************************** - * RtlExtendedIntegerMultiply [NTDLL.359] - * Note: This even works, since gcc returns 64bit values in eax/edx just like - * the caller expects. However... The relay code won't grok this I think. - */ -LARGE_INTEGER WINAPI RtlExtendedIntegerMultiply( - LARGE_INTEGER factor1, - INT factor2) -{ -#if SIZEOF_LONG_LONG==8 - long long result = (*(long long*)&factor1) * factor2; - return (*(LARGE_INTEGER*)&result); -#else - LARGE_INTEGER result; - result.s.HighPart = 0; - result.s.LowPart = 0; - FIXME("((%ld<<32)+%ld,%d), implement this using normal integer arithmetic!\n", - factor1.s.HighPart,factor1.s.LowPart,factor2); - return result; -#endif -} - /************************************************************************** * RtlDosPathNameToNtPathName_U [NTDLL.338] * diff --git a/dlls/ntdll/time.c b/dlls/ntdll/time.c index c9f717edc73..1f7ad4e582a 100644 --- a/dlls/ntdll/time.c +++ b/dlls/ntdll/time.c @@ -9,11 +9,13 @@ */ #include +#include +#include +#include #include "ntddk.h" #include "debugtools.h" -#include "file.h" -DEFAULT_DEBUG_CHANNEL(ntdll) +DEFAULT_DEBUG_CHANNEL(ntdll); #define TICKSPERSEC 10000000 #define TICKSPERMSEC 10000 @@ -29,6 +31,12 @@ DEFAULT_DEBUG_CHANNEL(ntdll) #define DAYSPERLEAPYEAR 366 #define MONSPERYEAR 12 +/* 1601 to 1970 is 369 years plus 89 leap days */ +#define SECS_1601_TO_1970 ((369 * 365 + 89) * 86400ULL) +/* 1601 to 1980 is 379 years plus 91 leap days */ +#define SECS_1601_to_1980 ((379 * 365 + 91) * 86400ULL) + + static const int YearLengths[2] = {DAYSPERNORMALYEAR, DAYSPERLEAPYEAR}; static const int MonthLengths[2][MONSPERYEAR] = { @@ -182,41 +190,43 @@ VOID WINAPI RtlSystemTimeToLocalTime( /****************************************************************************** * RtlTimeToSecondsSince1970 [NTDLL] */ -BOOLEAN WINAPI RtlTimeToSecondsSince1970( - LPFILETIME ft, - LPDWORD timeret) +BOOLEAN WINAPI RtlTimeToSecondsSince1970( const FILETIME *time, LPDWORD res ) { - *timeret = DOSFS_FileTimeToUnixTime(ft,NULL); + ULONGLONG tmp = RtlLargeIntegerDivide( ((LARGE_INTEGER *)time)->QuadPart, 10000000LL, NULL ); + tmp -= SECS_1601_TO_1970; + if (tmp > 0xffffffff) return FALSE; + *res = (DWORD)tmp; return TRUE; } /****************************************************************************** * RtlTimeToSecondsSince1980 [NTDLL] */ -BOOLEAN WINAPI RtlTimeToSecondsSince1980( - LPFILETIME ft, - LPDWORD timeret) +BOOLEAN WINAPI RtlTimeToSecondsSince1980( const FILETIME *time, LPDWORD res ) { - /* 1980 = 1970+10*365 days + 29. februar 1972 + 29.februar 1976 */ - if (!RtlTimeToSecondsSince1970( ft, timeret )) return FALSE; - *timeret -= (10*365+2)*24*60*60; + ULONGLONG tmp = RtlLargeIntegerDivide( ((LARGE_INTEGER *)time)->QuadPart, 10000000LL, NULL ); + tmp -= SECS_1601_to_1980; + if (tmp > 0xffffffff) return FALSE; + *res = (DWORD)tmp; return TRUE; } /****************************************************************************** * RtlSecondsSince1970ToTime [NTDLL] */ -void WINAPI RtlSecondsSince1970ToTime( DWORD time, LPFILETIME ft ) +void WINAPI RtlSecondsSince1970ToTime( DWORD time, FILETIME *res ) { - DOSFS_UnixTimeToFileTime( time, ft, 0 ); + LONGLONG secs = time + SECS_1601_TO_1970; + ((LARGE_INTEGER *)res)->QuadPart = RtlExtendedIntegerMultiply( secs, 10000000 ); } /****************************************************************************** * RtlSecondsSince1980ToTime [NTDLL] */ -void WINAPI RtlSecondsSince1980ToTime( DWORD time, LPFILETIME ft ) +void WINAPI RtlSecondsSince1980ToTime( DWORD time, FILETIME *res ) { - RtlSecondsSince1970ToTime( time + (10*365+2)*24*60*60, ft ); + LONGLONG secs = time + SECS_1601_to_1980; + ((LARGE_INTEGER *)res)->QuadPart = RtlExtendedIntegerMultiply( secs, 10000000 ); } /****************************************************************************** @@ -229,3 +239,16 @@ VOID WINAPI RtlTimeToElapsedTimeFields( { FIXME("(%p,%p): stub\n",liTime,TimeFields); } + +/*********************************************************************** + * NtQuerySystemTime (NTDLL.@) + */ +void WINAPI NtQuerySystemTime( LARGE_INTEGER *time ) +{ + LONGLONG secs; + struct timeval now; + + gettimeofday( &now, 0 ); + secs = now.tv_sec + SECS_1601_TO_1970; + time->QuadPart = RtlExtendedIntegerMultiply( secs, 10000000 ) + now.tv_usec * 10; +} diff --git a/include/ntddk.h b/include/ntddk.h index 620a4affac5..8aef5cb11bc 100644 --- a/include/ntddk.h +++ b/include/ntddk.h @@ -694,16 +694,12 @@ VOID WINAPI RtlTimeToElapsedTimeFields( PLARGE_INTEGER liTime, PTIME_FIELDS TimeFields); -BOOLEAN WINAPI RtlTimeToSecondsSince1980( - LPFILETIME ft, - LPDWORD timeret); +void WINAPI NtQuerySystemTime( LARGE_INTEGER *time ); -BOOLEAN WINAPI RtlTimeToSecondsSince1970( - LPFILETIME ft, - LPDWORD timeret); - -void WINAPI RtlSecondsSince1970ToTime( DWORD time, LPFILETIME ft ); -void WINAPI RtlSecondsSince1980ToTime( DWORD time, LPFILETIME ft ); +BOOLEAN WINAPI RtlTimeToSecondsSince1980( const FILETIME *time, LPDWORD res ); +BOOLEAN WINAPI RtlTimeToSecondsSince1970( const FILETIME *time, LPDWORD res ); +void WINAPI RtlSecondsSince1970ToTime( DWORD time, FILETIME *res ); +void WINAPI RtlSecondsSince1980ToTime( DWORD time, FILETIME *res ); /* heap functions */ @@ -756,14 +752,21 @@ VOID WINAPI RtlAcquirePebLock(void); VOID WINAPI RtlReleasePebLock(void); /* mathematics */ -INT WINAPI RtlExtendedLargeIntegerDivide( - LARGE_INTEGER dividend, - DWORD divisor, - LPDWORD rest); - -LARGE_INTEGER WINAPI RtlExtendedIntegerMultiply( - LARGE_INTEGER factor1, - INT factor2); +LONGLONG WINAPI RtlConvertLongToLargeInteger( LONG a ); +LONGLONG WINAPI RtlEnlargedIntegerMultiply( INT a, INT b ); +LONGLONG WINAPI RtlEnlargedUnsignedMultiply( UINT a, UINT b ); +LONGLONG WINAPI RtlExtendedMagicDivide( LONGLONG a, LONGLONG b, INT shift ); +LONGLONG WINAPI RtlExtendedIntegerMultiply( LONGLONG a, INT b ); +LONGLONG WINAPI RtlExtendedLargeIntegerDivide( LONGLONG a, INT b, INT *rem ); +LONGLONG WINAPI RtlLargeIntegerAdd( LONGLONG a, LONGLONG b ); +LONGLONG WINAPI RtlLargeIntegerArithmeticShift( LONGLONG a, INT count ); +LONGLONG WINAPI RtlLargeIntegerNegate( LONGLONG a ); +LONGLONG WINAPI RtlLargeIntegerShiftLeft( LONGLONG a, INT count ); +LONGLONG WINAPI RtlLargeIntegerShiftRight( LONGLONG a, INT count ); +LONGLONG WINAPI RtlLargeIntegerSubtract( LONGLONG a, LONGLONG b ); +UINT WINAPI RtlEnlargedUnsignedDivide( ULONGLONG a, UINT b, UINT *remptr ); +ULONGLONG WINAPI RtlConvertUlongToLargeInteger( ULONG a ); +ULONGLONG WINAPI RtlLargeIntegerDivide( ULONGLONG a, ULONGLONG b, ULONGLONG *rem ); /* environment */ DWORD WINAPI RtlCreateEnvironment( @@ -817,6 +820,10 @@ NTSTATUS WINAPI NtCreateKey(PHANDLE,ACCESS_MASK,const OBJECT_ATTRIBUTES*,ULON NTSTATUS WINAPI NtDeleteKey(HANDLE); NTSTATUS WINAPI NtDeleteValueKey(HANDLE,const UNICODE_STRING*); NTSTATUS WINAPI NtOpenKey(PHANDLE,ACCESS_MASK,const OBJECT_ATTRIBUTES*); +NTSTATUS WINAPI NtSetValueKey(HANDLE,const UNICODE_STRING*,ULONG,ULONG,const void*,ULONG); +NTSTATUS WINAPI NtQueryValueKey(HANDLE,const UNICODE_STRING*,KEY_VALUE_INFORMATION_CLASS, + void*,DWORD,DWORD*); + NTSTATUS WINAPI NtEnumerateKey( HANDLE KeyHandle, @@ -867,14 +874,6 @@ NTSTATUS WINAPI NtQueryMultipleValueKey( ULONG Length, PULONG ReturnLength); -NTSTATUS WINAPI NtQueryValueKey( - IN HANDLE KeyHandle, - IN PUNICODE_STRING ValueName, - IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass, - OUT PVOID KeyValueInformation, - IN ULONG Length, - OUT PULONG ResultLength); - NTSTATUS WINAPI NtReplaceKey( IN POBJECT_ATTRIBUTES ObjectAttributes, IN HANDLE Key, @@ -895,14 +894,6 @@ NTSTATUS WINAPI NtSetInformationKey( IN PVOID KeyInformation, IN ULONG KeyInformationLength); -NTSTATUS WINAPI NtSetValueKey( - HANDLE KeyHandle, - PUNICODE_STRING ValueName, - ULONG TitleIndex, - ULONG Type, - PVOID Data, - ULONG DataSize); - NTSTATUS WINAPI NtUnloadKey( IN HANDLE KeyHandle); diff --git a/include/winnt.h b/include/winnt.h index aead0550237..c678cc15152 100644 --- a/include/winnt.h +++ b/include/winnt.h @@ -2326,9 +2326,9 @@ typedef union _LARGE_INTEGER { typedef union _ULARGE_INTEGER { struct { DWORD LowPart; - LONG HighPart; + DWORD HighPart; } DUMMYSTRUCTNAME; - LONGLONG QuadPart; + ULONGLONG QuadPart; } ULARGE_INTEGER, *LPULARGE_INTEGER, *PULARGE_INTEGER; /* diff --git a/scheduler/timer.c b/scheduler/timer.c index 5fc851fb53b..a5de434a27c 100644 --- a/scheduler/timer.c +++ b/scheduler/timer.c @@ -134,29 +134,20 @@ BOOL WINAPI SetWaitableTimer( HANDLE handle, const LARGE_INTEGER *when, LONG per PTIMERAPCROUTINE callback, LPVOID arg, BOOL resume ) { BOOL ret; - FILETIME ft; - DWORD remainder; + LARGE_INTEGER exp = *when; - if (when->s.HighPart < 0) /* relative time */ + if (exp.s.HighPart < 0) /* relative time */ { - DWORD low; - GetSystemTimeAsFileTime( &ft ); - low = ft.dwLowDateTime; - ft.dwLowDateTime -= when->s.LowPart; - ft.dwHighDateTime -= when->s.HighPart; - if (low < ft.dwLowDateTime) ft.dwHighDateTime--; /* overflow */ - } - else /* absolute time */ - { - ft.dwLowDateTime = when->s.LowPart; - ft.dwHighDateTime = when->s.HighPart; + LARGE_INTEGER now; + NtQuerySystemTime( &now ); + exp.QuadPart = RtlLargeIntegerSubtract( now.QuadPart, exp.QuadPart ); } SERVER_START_REQ { struct set_timer_request *req = server_alloc_req( sizeof(*req), 0 ); - if (!ft.dwLowDateTime && !ft.dwHighDateTime) + if (!exp.s.LowPart && !exp.s.HighPart) { /* special case to start timeout on now+period without too many calculations */ req->sec = 0; @@ -164,7 +155,8 @@ BOOL WINAPI SetWaitableTimer( HANDLE handle, const LARGE_INTEGER *when, LONG per } else { - req->sec = DOSFS_FileTimeToUnixTime( &ft, &remainder ); + DWORD remainder; + req->sec = DOSFS_FileTimeToUnixTime( (FILETIME *)&exp, &remainder ); req->usec = remainder / 10; /* convert from 100-ns to us units */ } req->handle = handle; diff --git a/win32/time.c b/win32/time.c index fa0a9c29f4e..2f0e997aef8 100644 --- a/win32/time.c +++ b/win32/time.c @@ -59,16 +59,3 @@ VOID WINAPI GetSystemTime(LPSYSTEMTIME systime) systime->wSecond = local_tm->tm_sec; systime->wMilliseconds = (tv.tv_usec / 1000) % 1000; } - - -/*********************************************************************** - * GetSystemTimeAsFileTime (KERNEL32) - */ -VOID WINAPI GetSystemTimeAsFileTime(LPFILETIME systemtimeAsfiletime) -{ - struct timeval now; - gettimeofday( &now, 0 ); - /* FIXME: convert to UTC */ - DOSFS_UnixTimeToFileTime( now.tv_sec, systemtimeAsfiletime, now.tv_usec * 10 ); -} - -- 2.11.4.GIT