/* * Here is what we have to do: * * We take in time structure that is > January 1, 1970. * We create a structure that is the first second of January 1, 1970. * Since the From Time is > 1970, to get the number of 100-nanoseconds * since 1970 we just subtract the two dates. * we then have to convert the LARGE_INTEGER to a 32bit integer. */ void ConvertToSecondsFrom1970(CONST PLARGE_INTEGER pFrom, PULONG pTo, PULONG pMillseconds) { TIME_FIELDS tf1970; LARGE_INTEGER t1970, tmp; #if (_WIN32_WINNT == 0x0500) // WIN2k LARGE_INTEGER remainder, divisor; divisor.QuadPart = 10000000; #endif if(!pFrom || !pTo) return; tf1970.Year = 1970; tf1970.Day = 1; tf1970.Hour = 0; tf1970.Minute = 0; tf1970.Second = 1; tf1970.Month = 1; tf1970.Milliseconds = 0; RtlTimeFieldsToTime(&tf1970, &t1970); tmp.QuadPart = pFrom->QuadPart - t1970.QuadPart; *pTo = (ULONG)(*((__int64 *) &tmp) / 10000000U); if(pMillseconds) { #if (_WIN32_WINNT == 0x0500) // WIN2k RtlLargeIntegerDivide(tmp, divisor, &remainder); *pMillseconds = (ULONG)remainder.QuadPart / 1000; #else *pMillseconds = (ULONG)(*((__int64 *) &tmp) % 10000000U) / 1000; #endif } }
/****************************************************************************** * RtlTimeToSecondsSince1980 [NTDLL.@] */ BOOLEAN WINAPI RtlTimeToSecondsSince1980( const LARGE_INTEGER *time, LPDWORD res ) { ULONGLONG tmp = RtlLargeIntegerDivide( time->QuadPart, 10000000LL, NULL ); tmp -= SECS_1601_to_1980; if (tmp > 0xffffffff) return FALSE; *res = (DWORD)tmp; return TRUE; }
BOOLEAN WINAPI RtlTimeToSecondsSince1970( const LARGE_INTEGER *Time, DWORD *Seconds ) { ULONGLONG tmp = Time->QuadPart; TRACEN((printf("RtlTimeToSecondsSince1970-1 %llx\n",tmp))) tmp = RtlLargeIntegerDivide( tmp, 10000000, NULL ); tmp -= SECS_1601_TO_1970; TRACEN((printf("RtlTimeToSecondsSince1970-2 %llx\n",tmp))) if (tmp > 0xffffffff) return FALSE; *Seconds = (DWORD)tmp; return TRUE; }
VOID NTHALAPI KeStallExecutionProcessor(ULONG USec) { LARGE_INTEGER Freq, Start = KeQueryPerformanceCounter(&Freq), End; LARGE_INTEGER Timebase, Remainder; Timebase.QuadPart = 1000000; Freq.QuadPart *= USec; End = RtlLargeIntegerDivide(Freq, Timebase, &Remainder); End.QuadPart += Start.QuadPart; while(End.QuadPart > __rdtsc()); }