Changeset 53471 in vbox for trunk/src/VBox/Runtime/r3/win
- Timestamp:
- Dec 6, 2014 3:57:52 AM (10 years ago)
- Location:
- trunk/src/VBox/Runtime/r3/win
- Files:
-
- 2 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/win/ntdll-mini-implib.def
r52953 r53471 126 126 RtlSizeHeap ;;= _RtlSizeHeap@12 127 127 RtlSubAuthoritySid ;;= _RtlSubAuthoritySid@8 128 RtlQueryPerformanceCounter ;;= _RtlQueryPerformanceCounter@4 129 RtlGetSystemTimePrecise ;;= _RtlGetSystemTimePrecise@0 128 130 -
trunk/src/VBox/Runtime/r3/win/time-win.cpp
r52823 r53471 162 162 163 163 164 RTDECL(int) RTTimeSet(PCRTTIMESPEC pTime)165 {166 FILETIME FileTime;167 SYSTEMTIME SysTime;168 if (FileTimeToSystemTime(RTTimeSpecGetNtFileTime(pTime, &FileTime), &SysTime))169 {170 if (SetSystemTime(&SysTime))171 return VINF_SUCCESS;172 }173 return RTErrConvertFromWin32(GetLastError());174 }175 176 177 164 RTDECL(PRTTIMESPEC) RTTimeLocalNow(PRTTIMESPEC pTime) 178 165 { … … 200 187 } 201 188 202 203 RTDECL(PRTTIME) RTTimeLocalExplode(PRTTIME pTime, PCRTTIMESPEC pTimeSpec)204 {205 /*206 * FileTimeToLocalFileTime does not do the right thing, so we'll have207 * to convert to system time and SystemTimeToTzSpecificLocalTime instead.208 */209 RTTIMESPEC LocalTime;210 SYSTEMTIME SystemTimeIn;211 FILETIME FileTime;212 if (FileTimeToSystemTime(RTTimeSpecGetNtFileTime(pTimeSpec, &FileTime), &SystemTimeIn))213 {214 SYSTEMTIME SystemTimeOut;215 if (SystemTimeToTzSpecificLocalTime(NULL /* use current TZI */,216 &SystemTimeIn,217 &SystemTimeOut))218 {219 if (SystemTimeToFileTime(&SystemTimeOut, &FileTime))220 {221 RTTimeSpecSetNtFileTime(&LocalTime, &FileTime);222 pTime = RTTimeExplode(pTime, &LocalTime);223 if (pTime)224 pTime->fFlags = (pTime->fFlags & ~RTTIME_FLAGS_TYPE_MASK) | RTTIME_FLAGS_TYPE_LOCAL;225 return pTime;226 }227 }228 }229 230 /*231 * The fallback is to use the current offset.232 * (A better fallback would be to use the offset of the same time of the year.)233 */234 LocalTime = *pTimeSpec;235 RTTimeSpecAddNano(&LocalTime, RTTimeLocalDeltaNano());236 pTime = RTTimeExplode(pTime, &LocalTime);237 if (pTime)238 pTime->fFlags = (pTime->fFlags & ~RTTIME_FLAGS_TYPE_MASK) | RTTIME_FLAGS_TYPE_LOCAL;239 return pTime;240 }241 -
trunk/src/VBox/Runtime/r3/win/time2-win.cpp
r53467 r53471 35 35 #include "internal/iprt.h" 36 36 37 #include <iprt/asm.h>38 37 #include <iprt/assert.h> 39 38 #include <iprt/err.h> 40 39 #include "internal/time.h" 41 40 42 /*43 * Note! The selected time source be the exact same one as we use in kernel land!44 */45 //#define USE_TICK_COUNT46 //#define USE_PERFORMANCE_COUNTER47 //# define USE_FILE_TIME48 //#if defined(RT_ARCH_X86) || defined(RT_ARCH_AMD64)49 # define USE_INTERRUPT_TIME50 //#else51 //# define USE_TICK_COUNT52 //#endif53 54 55 #ifdef USE_INTERRUPT_TIME56 57 typedef struct _MY_KSYSTEM_TIME58 {59 ULONG LowPart;60 LONG High1Time;61 LONG High2Time;62 } MY_KSYSTEM_TIME;63 64 typedef struct _MY_KUSER_SHARED_DATA65 {66 ULONG TickCountLowDeprecated;67 ULONG TickCountMultiplier;68 volatile MY_KSYSTEM_TIME InterruptTime;69 /* The rest is not relevant. */70 } MY_KUSER_SHARED_DATA, *PMY_KUSER_SHARED_DATA;71 72 #endif /* USE_INTERRUPT_TIME */73 74 75 DECLINLINE(uint64_t) rtTimeGetSystemNanoTS(void)76 {77 #if defined USE_TICK_COUNT78 /*79 * This would work if it didn't flip over every 49 (or so) days.80 */81 return (uint64_t)GetTickCount() * RT_NS_1MS_64;82 83 #elif defined USE_PERFORMANCE_COUNTER84 /*85 * Slow and not derived from InterruptTime.86 */87 static LARGE_INTEGER llFreq;88 static unsigned uMult;89 if (!llFreq.QuadPart)90 {91 if (!QueryPerformanceFrequency(&llFreq))92 return (uint64_t)GetTickCount() * RT_NS_1MS_64;93 llFreq.QuadPart /= 1000;94 uMult = 1000000; /* no math genius, but this seemed to help avoiding floating point. */95 }96 97 LARGE_INTEGER ll;98 if (QueryPerformanceCounter(&ll))99 return (ll.QuadPart * uMult) / llFreq.QuadPart;100 return (uint64_t)GetTickCount() * RT_NS_1MS_64;101 102 #elif defined USE_FILE_TIME103 /*104 * This is SystemTime not InterruptTime.105 */106 uint64_t u64; /* manual say larger integer, should be safe to assume it's the same. */107 GetSystemTimeAsFileTime((LPFILETIME)&u64);108 return u64 * 100;109 110 #elif defined USE_INTERRUPT_TIME111 # if 0 /* ASSUME 0x7ffe0000 is set in stone */112 /*113 * This is exactly what we want, but we have to obtain it by non-official114 * means.115 */116 static MY_KUSER_SHARED_DATA *s_pUserSharedData = NULL;117 if (!s_pUserSharedData)118 {119 /** @todo find official way of getting this or some more clever120 * detection algorithm if necessary. The com debugger class121 * exports this too, windbg knows it too... */122 s_pUserSharedData = (PMY_KUSER_SHARED_DATA)(uintptr_t)0x7ffe0000;123 }124 # endif125 PMY_KUSER_SHARED_DATA pUserSharedData = (PMY_KUSER_SHARED_DATA)(uintptr_t)0x7ffe0000;126 127 /* use interrupt time */128 LARGE_INTEGER Time;129 do130 {131 Time.HighPart = pUserSharedData->InterruptTime.High1Time;132 Time.LowPart = pUserSharedData->InterruptTime.LowPart;133 } while (pUserSharedData->InterruptTime.High2Time != Time.HighPart);134 135 return (uint64_t)Time.QuadPart * 100;136 137 #else138 # error "Must select a method bright guy!"139 #endif140 }141 142 143 RTDECL(uint64_t) RTTimeSystemNanoTS(void)144 {145 return rtTimeGetSystemNanoTS();146 }147 148 149 RTDECL(uint64_t) RTTimeSystemMilliTS(void)150 {151 return rtTimeGetSystemNanoTS() / RT_NS_1MS;152 }153 154 155 RTDECL(PRTTIMESPEC) RTTimeNow(PRTTIMESPEC pTime)156 {157 uint64_t u64;158 AssertCompile(sizeof(u64) == sizeof(FILETIME));159 GetSystemTimeAsFileTime((LPFILETIME)&u64);160 return RTTimeSpecSetNtTime(pTime, u64);161 }162 41 163 42 … … 172 51 } 173 52 return RTErrConvertFromWin32(GetLastError()); 174 }175 176 177 RTDECL(PRTTIMESPEC) RTTimeLocalNow(PRTTIMESPEC pTime)178 {179 uint64_t u64;180 AssertCompile(sizeof(u64) == sizeof(FILETIME));181 GetSystemTimeAsFileTime((LPFILETIME)&u64);182 uint64_t u64Local;183 if (!FileTimeToLocalFileTime((FILETIME const *)&u64, (LPFILETIME)&u64Local))184 u64Local = u64;185 return RTTimeSpecSetNtTime(pTime, u64Local);186 }187 188 189 RTDECL(int64_t) RTTimeLocalDeltaNano(void)190 {191 /*192 * UTC = local + Tzi.Bias;193 * The bias is given in minutes.194 */195 TIME_ZONE_INFORMATION Tzi;196 Tzi.Bias = 0;197 if (GetTimeZoneInformation(&Tzi) != TIME_ZONE_ID_INVALID)198 return -(int64_t)Tzi.Bias * 60 * RT_NS_1SEC_64;199 return 0;200 53 } 201 54
Note:
See TracChangeset
for help on using the changeset viewer.