ReactOS 0.4.17-dev-116-ga4b6fe9
time.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for time.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define TICKSPERMINUTE   600000000
 

Functions

static BOOLEAN ExpGetTimeZoneId (_In_ PLARGE_INTEGER TimeNow, _Out_ PULONG TimeZoneId, _Out_ PLARGE_INTEGER NewTimeZoneBias)
 
BOOLEAN NTAPI ExAcquireTimeRefreshLock (IN BOOLEAN Wait)
 
VOID NTAPI ExReleaseTimeRefreshLock (VOID)
 
ULONG NTAPI ExSetTimerResolution (IN ULONG DesiredTime, IN BOOLEAN SetResolution)
 
VOID NTAPI ExUpdateSystemTimeFromCmos (IN BOOLEAN UpdateInterruptTime, IN ULONG MaxSepInSeconds)
 
BOOLEAN NTAPI ExRefreshTimeZoneInformation (IN PLARGE_INTEGER CurrentBootTime)
 
NTSTATUS ExpSetTimeZoneInformation (PRTL_TIME_ZONE_INFORMATION TimeZoneInformation)
 
NTSTATUS NTAPI NtSetSystemTime (IN PLARGE_INTEGER SystemTime, OUT PLARGE_INTEGER PreviousTime OPTIONAL)
 
NTSTATUS NTAPI NtQuerySystemTime (OUT PLARGE_INTEGER SystemTime)
 
VOID NTAPI ExLocalTimeToSystemTime (PLARGE_INTEGER LocalTime, PLARGE_INTEGER SystemTime)
 
VOID NTAPI ExSystemTimeToLocalTime (PLARGE_INTEGER SystemTime, PLARGE_INTEGER LocalTime)
 
NTSTATUS NTAPI NtQueryTimerResolution (OUT PULONG MinimumResolution, OUT PULONG MaximumResolution, OUT PULONG ActualResolution)
 
NTSTATUS NTAPI NtSetTimerResolution (IN ULONG DesiredResolution, IN BOOLEAN SetResolution, OUT PULONG CurrentResolution)
 

Variables

RTL_TIME_ZONE_INFORMATION ExpTimeZoneInfo
 
ULONG ExpLastTimeZoneBias = -1
 
LARGE_INTEGER ExpTimeZoneBias
 
ULONG ExpAltTimeZoneBias
 
ULONG ExpTimeZoneId
 
ULONG ExpTickCountMultiplier
 
ERESOURCE ExpTimeRefreshLock
 
ULONG ExpKernelResolutionCount = 0
 
ULONG ExpTimerResolutionCount = 0
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file time.c.

◆ TICKSPERMINUTE

#define TICKSPERMINUTE   600000000

Definition at line 16 of file time.c.

Function Documentation

◆ ExAcquireTimeRefreshLock()

BOOLEAN NTAPI ExAcquireTimeRefreshLock ( IN BOOLEAN  Wait)

Definition at line 145 of file time.c.

146{
147 /* Block APCs */
149
150 /* Attempt lock acquisition */
152 {
153 /* Lock was not acquired, enable APCs and fail */
155 return FALSE;
156 }
157
158 /* Lock has been acquired */
159 return TRUE;
160}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define ExAcquireResourceExclusiveLite(res, wait)
Definition: env_spec_w32.h:615
#define KeLeaveCriticalRegion()
Definition: ke_x.h:119
#define KeEnterCriticalRegion()
Definition: ke_x.h:88
ERESOURCE ExpTimeRefreshLock
Definition: time.c:27
_In_ WDFDPC _In_ BOOLEAN Wait
Definition: wdfdpc.h:170

Referenced by ExSetTimerResolution(), and KdpTimeSlipWork().

◆ ExLocalTimeToSystemTime()

VOID NTAPI ExLocalTimeToSystemTime ( PLARGE_INTEGER  LocalTime,
PLARGE_INTEGER  SystemTime 
)

Definition at line 605 of file time.c.

607{
608 SystemTime->QuadPart = LocalTime->QuadPart + ExpTimeZoneBias.QuadPart;
609}
LARGE_INTEGER ExpTimeZoneBias
Definition: time.c:23
LONGLONG QuadPart
Definition: typedefs.h:114

◆ ExpGetTimeZoneId()

static BOOLEAN ExpGetTimeZoneId ( _In_ PLARGE_INTEGER  TimeNow,
_Out_ PULONG  TimeZoneId,
_Out_ PLARGE_INTEGER  NewTimeZoneBias 
)
static

Definition at line 39 of file time.c.

43{
44 LARGE_INTEGER StandardTime;
45 LARGE_INTEGER DaylightTime;
46 LARGE_INTEGER LocalTimeNow = *TimeNow;
48
49 DPRINT("ExpGetTimeZoneId\n");
50
51 /* Read time zone information from the registry */
53 if (!NT_SUCCESS(Status))
54 {
55 DPRINT1("RtlQueryTimeZoneInformation failed (Status 0x%08lx)\n", Status);
56 return FALSE;
57 }
58
59 /* Get the default bias */
60 NewTimeZoneBias->QuadPart = (LONGLONG)ExpTimeZoneInfo.Bias * TICKSPERMINUTE;
61
64 {
65 /* Get this year's standard start time */
67 &StandardTime,
68 &LocalTimeNow,
69 TRUE))
70 {
71 DPRINT1("RtlCutoverTimeToSystemTime for StandardDate failed\n");
72 return FALSE;
73 }
74
75 /* Get this year's daylight start time */
77 &DaylightTime,
78 &LocalTimeNow,
79 TRUE))
80 {
81 DPRINT1("RtlCutoverTimeToSystemTime for DaylightDate failed\n");
82 return FALSE;
83 }
84
85 /* Determine the time zone id and update the time zone bias */
86 if (DaylightTime.QuadPart < StandardTime.QuadPart)
87 {
88 if ((LocalTimeNow.QuadPart >= DaylightTime.QuadPart) &&
89 (LocalTimeNow.QuadPart < StandardTime.QuadPart))
90 {
91 DPRINT("Daylight time\n");
92 *TimeZoneId = TIME_ZONE_ID_DAYLIGHT;
93 NewTimeZoneBias->QuadPart += (LONGLONG)ExpTimeZoneInfo.DaylightBias * TICKSPERMINUTE;
94 }
95 else
96 {
97 DPRINT("Standard time\n");
98 *TimeZoneId = TIME_ZONE_ID_STANDARD;
99 NewTimeZoneBias->QuadPart += (LONGLONG)ExpTimeZoneInfo.StandardBias * TICKSPERMINUTE;
100 }
101 }
102 else
103 {
104 if ((LocalTimeNow.QuadPart >= StandardTime.QuadPart) &&
105 (LocalTimeNow.QuadPart < DaylightTime.QuadPart))
106 {
107 DPRINT("Standard time\n");
108 *TimeZoneId = TIME_ZONE_ID_STANDARD;
109 NewTimeZoneBias->QuadPart += (LONGLONG)ExpTimeZoneInfo.StandardBias * TICKSPERMINUTE;
110 }
111 else
112 {
113 DPRINT("Daylight time\n");
114 *TimeZoneId = TIME_ZONE_ID_DAYLIGHT;
115 NewTimeZoneBias->QuadPart += (LONGLONG)ExpTimeZoneInfo.DaylightBias * TICKSPERMINUTE;
116 }
117 }
118 }
119 else
120 {
121 *TimeZoneId = TIME_ZONE_ID_UNKNOWN;
122 }
123
124 return TRUE;
125}
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
Status
Definition: gdiplustypes.h:25
if(dx< 0)
Definition: linetemp.h:194
NTSYSAPI NTSTATUS NTAPI RtlQueryTimeZoneInformation(_Out_ PRTL_TIME_ZONE_INFORMATION TimeZoneInformation)
NTSYSAPI BOOLEAN NTAPI RtlCutoverTimeToSystemTime(_In_ PTIME_FIELDS CutoverTimeFields, _Out_ PLARGE_INTEGER SystemTime, _In_ PLARGE_INTEGER CurrentTime, _In_ BOOLEAN ThisYearsCutoverOnly)
#define TIME_ZONE_ID_UNKNOWN
Definition: rtltypes.h:252
#define TIME_ZONE_ID_STANDARD
Definition: rtltypes.h:253
#define TIME_ZONE_ID_DAYLIGHT
Definition: rtltypes.h:254
RTL_TIME_ZONE_INFORMATION ExpTimeZoneInfo
Definition: time.c:21
#define TICKSPERMINUTE
Definition: time.c:16
#define DPRINT
Definition: sndvol32.h:73
int64_t LONGLONG
Definition: typedefs.h:68

Referenced by ExpSetTimeZoneInformation(), and ExRefreshTimeZoneInformation().

◆ ExpSetTimeZoneInformation()

NTSTATUS ExpSetTimeZoneInformation ( PRTL_TIME_ZONE_INFORMATION  TimeZoneInformation)

Definition at line 357 of file time.c.

358{
359 LARGE_INTEGER LocalTime, SystemTime, OldTime, NewTimeZoneBias;
363 LARGE_INTEGER LocalTimeNow;
364
365 DPRINT("ExpSetTimeZoneInformation called\n");
366
367 /* Read time zone information from the registry */
369 if (!NT_SUCCESS(Status))
370 {
371 DPRINT1("RtlQueryTimeZoneInformation failed (Status 0x%08lx)\n", Status);
372 return FALSE;
373 }
374
375 /* Get the default bias */
377
378 /* Get the Shared User Data System Time into the local SystemTime */
379 KeQuerySystemTime(&SystemTime);
380
381 LocalTimeNow = SystemTime;
382
383 /* Adjust LocalTimeNow for Time Zone Bias to use UTC for comparisons */
384 LocalTimeNow.QuadPart -= NewTimeZoneBias.QuadPart;
385
386 /* Set the Global Data for ExpTimeZoneBias and ExpTimeZoneId */
387 Success = ExpGetTimeZoneId(&LocalTimeNow, &ExpTimeZoneId, &NewTimeZoneBias);
388 if (!Success)
389 {
390 DPRINT1("ExpGetTimeZoneId failed\n");
391 return STATUS_UNSUCCESSFUL;
392 }
393 DPRINT("ExpTimeZoneId is %lu\n", ExpTimeZoneId);
394
395 ExpTimeZoneBias = NewTimeZoneBias;
396
397 DPRINT("Old time zone bias: %d minutes\n", ExpTimeZoneInfo.Bias);
398 DPRINT("Old time zone standard bias: %d minutes\n",
400 DPRINT("New time zone bias: %d minutes\n", TimeZoneInformation->Bias);
401 DPRINT("New time zone standard bias: %d minutes\n",
402 TimeZoneInformation->StandardBias);
403
404 /* Get the local time */
406 RtlTimeFieldsToTime(&TimeFields, &LocalTime);
407
408 /* Calculate the bias */
409 ExpTimeZoneBias.QuadPart = ((LONGLONG)(TimeZoneInformation->Bias +
410 TimeZoneInformation->StandardBias)) *
412
413 /* If Daylight Savings Time then add the DayLightBias to the Time Zone Bias */
416
417 /* Copy the timezone information */
419 TimeZoneInformation,
421
422 /* Set the new time zone information */
424 SharedUserData->TimeZoneId = ExpTimeZoneId;
425
426 DPRINT("New time zone bias: %I64d minutes\n",
428
429 /* Calculate the new system time */
430 ExLocalTimeToSystemTime(&LocalTime, &SystemTime);
431
432 /* Set the new system time and notify the system */
433 KeSetSystemTime(&SystemTime, &OldTime, FALSE, NULL);
435
436 /* Return success */
437 DPRINT("ExpSetTimeZoneInformation done\n");
438 return STATUS_SUCCESS;
439}
unsigned char BOOLEAN
Definition: actypes.h:127
#define NULL
Definition: types.h:112
BOOLEAN RtlTimeFieldsToTime(IN PTIME_FIELDS TimeFields, IN PLARGE_INTEGER Time)
#define ExLocalTimeToSystemTime(LocTime, SysTime)
Definition: env_spec_w32.h:738
#define KeQuerySystemTime(t)
Definition: env_spec_w32.h:570
@ Success
Definition: eventcreate.c:712
static PTIME_FIELDS TimeFields
Definition: time.c:36
FORCEINLINE VOID KiWriteSystemTime(_Out_ volatile KSYSTEM_TIME *SystemTime, _In_ LARGE_INTEGER NewTime)
Definition: kefuncs.h:429
static BOOLEAN ExpGetTimeZoneId(_In_ PLARGE_INTEGER TimeNow, _Out_ PULONG TimeZoneId, _Out_ PLARGE_INTEGER NewTimeZoneBias)
Definition: time.c:39
ULONG ExpTimeZoneId
Definition: time.c:25
VOID NTAPI KeSetSystemTime(IN PLARGE_INTEGER NewSystemTime, OUT PLARGE_INTEGER OldSystemTime, IN BOOLEAN FixInterruptTime, IN PLARGE_INTEGER HalTime)
Definition: clock.c:28
VOID NTAPI PoNotifySystemTimeSet(VOID)
Definition: events.c:39
BOOLEAN NTAPI HalQueryRealTimeClock(IN PTIME_FIELDS Time)
Definition: rtc.c:24
#define SharedUserData
#define STATUS_SUCCESS
Definition: shellext.h:65
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132

Referenced by NtSetSystemTime(), and SSI_DEF().

◆ ExRefreshTimeZoneInformation()

BOOLEAN NTAPI ExRefreshTimeZoneInformation ( IN PLARGE_INTEGER  CurrentBootTime)

Definition at line 320 of file time.c.

321{
322 LARGE_INTEGER CurrentTime, NewTimeZoneBias;
324
325 DPRINT("ExRefreshTimeZoneInformation\n");
326
327 /* Set the global data for ExpTimeZoneBias and the Time Zone ID */
328 Success = ExpGetTimeZoneId(CurrentBootTime, &ExpTimeZoneId, &NewTimeZoneBias);
329 if (!Success)
330 {
331 DPRINT1("ExpGetTimeZoneId failed\n");
332 return FALSE;
333 }
334 DPRINT("ExpTimeZoneId is %lu\n", ExpTimeZoneId);
335
336 ExpTimeZoneBias = NewTimeZoneBias;
337
338 /* Change SharedUserData->TimeZoneBias for user-mode applications */
340 SharedUserData->TimeZoneId = ExpTimeZoneId;
341
342 /* Convert boot time from local time to UTC */
344
345 /* Convert system time from local time to UTC */
346 KeQuerySystemTime(&CurrentTime);;
347
348 /* Change it for user-mode applications */
349 CurrentTime.QuadPart += ExpTimeZoneBias.QuadPart;
350 KiWriteSystemTime(&SharedUserData->SystemTime, CurrentTime);
351
352 /* Return success */
353 return TRUE;
354}
LARGE_INTEGER KeBootTime
Definition: clock.c:17

Referenced by Phase1InitializationDiscard().

◆ ExReleaseTimeRefreshLock()

VOID NTAPI ExReleaseTimeRefreshLock ( VOID  )

Definition at line 177 of file time.c.

178{
179 /* Release the lock and re-enable APCs */
182}
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1822

Referenced by ExSetTimerResolution(), and KdpTimeSlipWork().

◆ ExSetTimerResolution()

ULONG NTAPI ExSetTimerResolution ( IN ULONG  DesiredTime,
IN BOOLEAN  SetResolution 
)

Definition at line 225 of file time.c.

227{
228 ULONG CurrentIncrement;
229
230 /* Wait for clock interrupt frequency and power requests to synchronize */
232
233 /* Obey remark 2*/
234 CurrentIncrement = KeTimeIncrement;
235
236 /* Check the type of operation this is */
237 if (SetResolution)
238 {
239 /*
240 * If this is the first kernel change, bump the timer resolution change
241 * count, then bump the kernel change count as well.
242 *
243 * These two variables are tracked differently since user-mode processes
244 * can also change the timer resolution through the NtSetTimerResolution
245 * system call. A per-process flag in the EPROCESS then stores the per-
246 * process change state.
247 *
248 */
250
251 /* Obey remark 3 */
252 if (DesiredTime < KeMinimumIncrement) DesiredTime = KeMinimumIncrement;
253
254 /* Obey remark 1 */
255 if (DesiredTime < KeTimeIncrement)
256 {
257 /* Force this thread on CPU zero, since we don't want it to drift */
259
260 /* Now call the platform driver (HAL) to make the change */
261 CurrentIncrement = HalSetTimeIncrement(DesiredTime);
262
263 /* Put the thread back to its original affinity */
265
266 /* Finally, keep track of the new value in the kernel */
267 KeTimeIncrement = CurrentIncrement;
268 }
269 }
270 else
271 {
272 /* First, make sure that a driver has actually changed the resolution */
274 {
275 /* Obey remark 4 */
277 {
278 /*
279 * All kernel drivers have requested the original frequency to
280 * be restored, but there might still be user processes with an
281 * ongoing clock interrupt frequency change, so make sure that
282 * this isn't the case.
283 */
285 {
286 /* Force this thread on one CPU so that it doesn't drift */
288
289 /* Call the HAL to restore the frequency to its default */
290 CurrentIncrement = HalSetTimeIncrement(KeMaximumIncrement);
291
292 /* Put the thread back to its original affinity */
294
295 /* Finally, keep track of the new value in the kernel */
296 KeTimeIncrement = CurrentIncrement;
297 }
298 }
299 }
300 }
301
302 /* Release the clock interrupt frequency lock since changes are done */
304
305 /* And return the current value -- which could reflect the new frequency */
306 return CurrentIncrement;
307}
ULONG NTAPI HalSetTimeIncrement(IN ULONG Increment)
Definition: timer.c:102
ULONG ExpTimerResolutionCount
Definition: time.c:29
VOID NTAPI ExReleaseTimeRefreshLock(VOID)
Definition: time.c:177
ULONG ExpKernelResolutionCount
Definition: time.c:28
BOOLEAN NTAPI ExAcquireTimeRefreshLock(IN BOOLEAN Wait)
Definition: time.c:145
ULONG KeTimeIncrement
Definition: clock.c:22
ULONG KeMinimumIncrement
Definition: clock.c:21
ULONG KeMaximumIncrement
Definition: clock.c:20
VOID NTAPI KeSetSystemAffinityThread(IN KAFFINITY Affinity)
Definition: thrdobj.c:1107
VOID NTAPI KeRevertToUserAffinityThread(VOID)
Definition: thrdobj.c:1021
uint32_t ULONG
Definition: typedefs.h:59
_In_ BOOLEAN SetResolution
Definition: exfuncs.h:1078

Referenced by NtSetTimerResolution().

◆ ExSystemTimeToLocalTime()

VOID NTAPI ExSystemTimeToLocalTime ( PLARGE_INTEGER  SystemTime,
PLARGE_INTEGER  LocalTime 
)

Definition at line 616 of file time.c.

618{
619 LocalTime->QuadPart = SystemTime->QuadPart - ExpTimeZoneBias.QuadPart;
620}

◆ ExUpdateSystemTimeFromCmos()

VOID NTAPI ExUpdateSystemTimeFromCmos ( IN BOOLEAN  UpdateInterruptTime,
IN ULONG  MaxSepInSeconds 
)

Definition at line 311 of file time.c.

313{
314 /* FIXME: TODO */
315 return;
316}

Referenced by KdpTimeSlipWork().

◆ NtQuerySystemTime()

NTSTATUS NTAPI NtQuerySystemTime ( OUT PLARGE_INTEGER  SystemTime)

Definition at line 563 of file time.c.

564{
566 PAGED_CODE();
567
568 /* Check if we were called from user-mode */
570 {
572 {
573 /* Verify the time pointer */
574 ProbeForWriteLargeInteger(SystemTime);
575
576 /*
577 * It's safe to pass the pointer directly to KeQuerySystemTime
578 * as it's just a basic copy to this pointer. If it raises an
579 * exception nothing dangerous can happen!
580 */
581 KeQuerySystemTime(SystemTime);
582 }
584 {
585 /* Return the exception code */
587 }
588 _SEH2_END;
589 }
590 else
591 {
592 /* Query the time directly */
593 KeQuerySystemTime(SystemTime);
594 }
595
596 /* Return success */
597 return STATUS_SUCCESS;
598}
#define PAGED_CODE()
_In_ PVOID _In_ ULONG _Out_ PVOID _In_ ULONG _Inout_ PULONG _In_ KPROCESSOR_MODE PreviousMode
#define ExGetPreviousMode
Definition: ex.h:143
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:90
#define KernelMode
Definition: asm.h:38
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:204
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:104
#define _SEH2_END
Definition: pseh2_64.h:194
#define _SEH2_TRY
Definition: pseh2_64.h:93
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:207
#define ProbeForWriteLargeInteger(Ptr)
Definition: probe.h:46
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7

Referenced by CalcVolumeSerialNumber(), clock(), create_bad_block_inode(), CreateSignature(), ElfReportEventA(), ElfReportEventW(), ext2_flush(), ext2_initialize_sb(), ext2_mkdir(), GetDynamicTimeZoneInformation(), GetLocalTime(), GetPasswordAge(), GetSystemTime(), GetSystemTimeAsFileTime(), HTTP_ProcessExpires(), LogfReportEvent(), LogfWriteRecord(), LsapCreateDatabaseObjects(), LsapCreateRandomDomainSid(), LsarCreateSecret(), LsarSetSecret(), LsarStorePrivateData(), msvcrt_init_clock(), NetrRemoteTOD(), NtProcessStartup(), RtlRunEncodeUnicodeString(), SampSetupCreateDomain(), SampSetUserAll(), SampSetUserInternal1(), SampSetUserInternal2(), SamrChangePasswordUser(), SamValidateNormalUser(), SetDiskSignature(), SetLogonTimestamp(), START_TEST(), test_GetSystemTimeAsFileTime(), test_perf_counters(), test_performance_keys(), Test_ProcessTimes(), test_tp_timer(), test_tp_wait(), test_tp_window_length(), test_user_shared_data_time(), timerqueue_thread_proc(), TpSetTimer(), TpSetWait(), and waitqueue_thread_proc().

◆ NtQueryTimerResolution()

NTSTATUS NTAPI NtQueryTimerResolution ( OUT PULONG  MinimumResolution,
OUT PULONG  MaximumResolution,
OUT PULONG  ActualResolution 
)

Definition at line 627 of file time.c.

630{
632
633 /* Check if the call came from user-mode */
635 {
637 {
638 /* Probe the parameters */
639 ProbeForWriteUlong(MinimumResolution);
640 ProbeForWriteUlong(MaximumResolution);
641 ProbeForWriteUlong(ActualResolution);
642
643 /*
644 * Set the parameters to the actual values.
645 *
646 * NOTE:
647 * MinimumResolution corresponds to the biggest time increment and
648 * MaximumResolution corresponds to the smallest time increment.
649 */
650 *MinimumResolution = KeMaximumIncrement;
651 *MaximumResolution = KeMinimumIncrement;
652 *ActualResolution = KeTimeIncrement;
653 }
655 {
656 /* Return the exception code */
658 }
659 _SEH2_END;
660 }
661 else
662 {
663 /* Set the parameters to the actual values */
664 *MinimumResolution = KeMaximumIncrement;
665 *MaximumResolution = KeMinimumIncrement;
666 *ActualResolution = KeTimeIncrement;
667 }
668
669 /* Return success */
670 return STATUS_SUCCESS;
671}
#define ProbeForWriteUlong(Ptr)
Definition: probe.h:36

Referenced by START_TEST(), and test_TimerResolution().

◆ NtSetSystemTime()

NTSTATUS NTAPI NtSetSystemTime ( IN PLARGE_INTEGER  SystemTime,
OUT PLARGE_INTEGER PreviousTime  OPTIONAL 
)

Definition at line 452 of file time.c.

454{
455 LARGE_INTEGER OldSystemTime;
456 LARGE_INTEGER NewSystemTime;
457 LARGE_INTEGER LocalTime;
461 RTL_TIME_ZONE_INFORMATION TimeZoneInformation = { 0 };
462 ULONG TimeZoneIdSave;
463
464 PAGED_CODE();
465
466 // TODO: Handle the case when SystemTime == NULL, which means:
467 // "update system time using the current time-zone information".
468 if (!SystemTime)
469 {
472 }
473
474 /* Check if we were called from user-mode */
476 {
478 {
479 /* Verify the time pointers */
480 NewSystemTime = ProbeForReadLargeInteger(SystemTime);
481 if (PreviousTime) ProbeForWriteLargeInteger(PreviousTime);
482 }
484 {
485 /* Return the exception code */
487 }
488 _SEH2_END;
489 }
490 else
491 {
492 /* Reuse the pointer */
493 NewSystemTime = *SystemTime;
494 }
495
496 /* Make sure we have permission to change the time */
498 {
499 DPRINT1("NtSetSystemTime: Caller requires the "
500 "SeSystemtimePrivilege privilege!\n");
502 }
503
504 /* Convert the time and set it in HAL */
505 ExSystemTimeToLocalTime(&NewSystemTime, &LocalTime);
506 RtlTimeToTimeFields(&LocalTime, &TimeFields);
508
509 /* Now set the system time and notify the system */
510 KeSetSystemTime(&NewSystemTime, &OldSystemTime, FALSE, NULL);
512
513 /* Check if caller wanted previous time */
514 if (PreviousTime)
515 {
516 /* Enter SEH Block for return */
518 {
519 /* Return the previous time */
520 *PreviousTime = OldSystemTime;
521 }
523 {
524 /* Get the exception code */
526 }
527 _SEH2_END;
528 }
529
530 /* Read time zone information from the registry and set the clock */
531 Status = RtlQueryTimeZoneInformation(&TimeZoneInformation);
532 if (!NT_SUCCESS(Status))
533 {
534 DPRINT1("RtlQueryTimeZoneInformation failed (Status 0x%08lx)\n", Status);
535 }
536
537 /* Test if we went from Daylight to Standard Time or vice versa */
538 TimeZoneIdSave = ExpTimeZoneId;
539 ExpSetTimeZoneInformation(&TimeZoneInformation);
540
541 if (ExpTimeZoneId != TimeZoneIdSave)
542 {
543 /* Going from DT to ST or vice versa we need to repeat this */
544 DPRINT("Daylight Time and Standard Time are switching\n");
545
546 /* Set the system time and notify the system */
547 KeSetSystemTime(&NewSystemTime, &OldSystemTime, FALSE, NULL);
549 }
550
551 /* Return status */
552 return Status;
553}
#define STATUS_PRIVILEGE_NOT_HELD
Definition: DriverTester.h:9
#define UNIMPLEMENTED
Definition: ntoskrnl.c:15
#define STATUS_NOT_IMPLEMENTED
Definition: d3dkmdt.h:42
BOOLEAN RtlTimeToTimeFields(IN PLARGE_INTEGER Time, IN PTIME_FIELDS TimeFields)
#define ExSystemTimeToLocalTime(SysTime, LocTime)
Definition: env_spec_w32.h:729
LONG NTAPI ExSystemExceptionFilter(VOID)
Definition: harderr.c:349
NTSTATUS ExpSetTimeZoneInformation(PRTL_TIME_ZONE_INFORMATION TimeZoneInformation)
Definition: time.c:357
const LUID SeSystemtimePrivilege
Definition: priv.c:31
BOOLEAN NTAPI SeSinglePrivilegeCheck(_In_ LUID PrivilegeValue, _In_ KPROCESSOR_MODE PreviousMode)
Checks if a single privilege is present in the context of the calling thread.
Definition: priv.c:744
BOOLEAN NTAPI HalSetRealTimeClock(IN PTIME_FIELDS Time)
Definition: rtc.c:45
#define ProbeForReadLargeInteger(Ptr)
Definition: probe.h:75

Referenced by SetLocalTime(), and SetSystemTime().

◆ NtSetTimerResolution()

NTSTATUS NTAPI NtSetTimerResolution ( IN ULONG  DesiredResolution,
IN BOOLEAN  SetResolution,
OUT PULONG  CurrentResolution 
)

Definition at line 678 of file time.c.

681{
685 ULONG NewResolution;
686
687 /* Check if the call came from user-mode */
689 {
691 {
692 /* Probe the parameter */
693 ProbeForWriteUlong(CurrentResolution);
694 }
696 {
697 /* Return the exception code */
699 }
700 _SEH2_END;
701 }
702
703 /* Set and return the new resolution */
704 NewResolution = ExSetTimerResolution(DesiredResolution, SetResolution);
705
707 {
709 {
710 *CurrentResolution = NewResolution;
711 }
713 {
714 /* Return the exception code */
716 }
717 _SEH2_END;
718 }
719 else
720 {
721 *CurrentResolution = NewResolution;
722 }
723
724 if (SetResolution || Process->SetTimerResolution)
725 {
726 /* The resolution has been changed now or in an earlier call */
728 }
729 else
730 {
731 /* The resolution hasn't been changed */
733 }
734
735 /* Update the flag */
736 Process->SetTimerResolution = SetResolution;
737
738 return Status;
739}
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:223
ULONG NTAPI ExSetTimerResolution(IN ULONG DesiredTime, IN BOOLEAN SetResolution)
Definition: time.c:225
#define STATUS_TIMER_RESOLUTION_NOT_SET
Definition: ntstatus.h:835
#define PsGetCurrentProcess
Definition: psfuncs.h:17

Referenced by START_TEST(), and test_TimerResolution().

Variable Documentation

◆ ExpAltTimeZoneBias

ULONG ExpAltTimeZoneBias

Definition at line 24 of file time.c.

Referenced by Phase1InitializationDiscard().

◆ ExpKernelResolutionCount

ULONG ExpKernelResolutionCount = 0

Definition at line 28 of file time.c.

Referenced by ExSetTimerResolution().

◆ ExpLastTimeZoneBias

ULONG ExpLastTimeZoneBias = -1

Definition at line 22 of file time.c.

Referenced by Phase1InitializationDiscard().

◆ ExpTickCountMultiplier

ULONG ExpTickCountMultiplier

Definition at line 26 of file time.c.

Referenced by ExpInitializeExecutive().

◆ ExpTimeRefreshLock

ERESOURCE ExpTimeRefreshLock

Definition at line 27 of file time.c.

Referenced by ExAcquireTimeRefreshLock(), ExpInitSystemPhase0(), and ExReleaseTimeRefreshLock().

◆ ExpTimerResolutionCount

ULONG ExpTimerResolutionCount = 0

Definition at line 29 of file time.c.

Referenced by ExSetTimerResolution().

◆ ExpTimeZoneBias

◆ ExpTimeZoneId

ULONG ExpTimeZoneId

◆ ExpTimeZoneInfo

RTL_TIME_ZONE_INFORMATION ExpTimeZoneInfo

Definition at line 21 of file time.c.

Referenced by ExpGetTimeZoneId(), ExpSetTimeZoneInformation(), and QSI_DEF().