ReactOS 0.4.15-dev-8408-g466a198
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 611 of file time.c.

613{
614 SystemTime->QuadPart = LocalTime->QuadPart + ExpTimeZoneBias.QuadPart;
615}
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 361 of file time.c.

362{
363 LARGE_INTEGER LocalTime, SystemTime, OldTime, NewTimeZoneBias;
367 LARGE_INTEGER LocalTimeNow;
368
369 DPRINT("ExpSetTimeZoneInformation called\n");
370
371 /* Read time zone information from the registry */
373 if (!NT_SUCCESS(Status))
374 {
375 DPRINT1("RtlQueryTimeZoneInformation failed (Status 0x%08lx)\n", Status);
376 return FALSE;
377 }
378
379 /* Get the default bias */
381
382 /* Get the Shared User Data System Time into the local SystemTime */
383 KeQuerySystemTime(&SystemTime);
384
385 LocalTimeNow = SystemTime;
386
387 /* Adjust LocalTimeNow for Time Zone Bias to use UTC for comparisons */
388 LocalTimeNow.QuadPart -= NewTimeZoneBias.QuadPart;
389
390 /* Set the Global Data for ExpTimeZoneBias and ExpTimeZoneId */
391 Success = ExpGetTimeZoneId(&LocalTimeNow, &ExpTimeZoneId, &NewTimeZoneBias);
392 if (!Success)
393 {
394 DPRINT1("ExpGetTimeZoneId failed\n");
395 return STATUS_UNSUCCESSFUL;
396 }
397 DPRINT("ExpTimeZoneId is %lu\n", ExpTimeZoneId);
398
399 ExpTimeZoneBias = NewTimeZoneBias;
400
401 DPRINT("Old time zone bias: %d minutes\n", ExpTimeZoneInfo.Bias);
402 DPRINT("Old time zone standard bias: %d minutes\n",
404 DPRINT("New time zone bias: %d minutes\n", TimeZoneInformation->Bias);
405 DPRINT("New time zone standard bias: %d minutes\n",
406 TimeZoneInformation->StandardBias);
407
408 /* Get the local time */
410 RtlTimeFieldsToTime(&TimeFields, &LocalTime);
411
412 /* Calculate the bias */
413 ExpTimeZoneBias.QuadPart = ((LONGLONG)(TimeZoneInformation->Bias +
414 TimeZoneInformation->StandardBias)) *
416
417 /* If Daylight Savings Time then add the DayLightBias to the Time Zone Bias */
420
421 /* Copy the timezone information */
423 TimeZoneInformation,
425
426 /* Set the new time zone information */
427 SharedUserData->TimeZoneBias.High1Time = ExpTimeZoneBias.u.HighPart;
428 SharedUserData->TimeZoneBias.High2Time = ExpTimeZoneBias.u.HighPart;
429 SharedUserData->TimeZoneBias.LowPart = ExpTimeZoneBias.u.LowPart;
430 SharedUserData->TimeZoneId = ExpTimeZoneId;
431
432 DPRINT("New time zone bias: %I64d minutes\n",
434
435 /* Calculate the new system time */
436 ExLocalTimeToSystemTime(&LocalTime, &SystemTime);
437
438 /* Set the new system time and notify the system */
439 KeSetSystemTime(&SystemTime, &OldTime, FALSE, NULL);
441
442 /* Return success */
443 DPRINT("ExpSetTimeZoneInformation done\n");
444 return STATUS_SUCCESS;
445}
unsigned char BOOLEAN
#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:104
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
struct _LARGE_INTEGER::@2289 u

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 */
339 SharedUserData->TimeZoneBias.High2Time = ExpTimeZoneBias.u.HighPart;
340 SharedUserData->TimeZoneBias.LowPart = ExpTimeZoneBias.u.LowPart;
341 SharedUserData->TimeZoneBias.High1Time = ExpTimeZoneBias.u.HighPart;
342 SharedUserData->TimeZoneId = ExpTimeZoneId;
343
344 /* Convert boot time from local time to UTC */
346
347 /* Convert system time from local time to UTC */
348 KeQuerySystemTime(&CurrentTime);;
349
350 /* Change it for user-mode applications */
351 CurrentTime.QuadPart += ExpTimeZoneBias.QuadPart;
352 SharedUserData->SystemTime.High2Time = CurrentTime.u.HighPart;
353 SharedUserData->SystemTime.LowPart = CurrentTime.u.LowPart;
354 SharedUserData->SystemTime.High1Time = CurrentTime.u.HighPart;
355
356 /* Return success */
357 return TRUE;
358}
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 622 of file time.c.

624{
625 LocalTime->QuadPart = SystemTime->QuadPart - ExpTimeZoneBias.QuadPart;
626}

◆ 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 569 of file time.c.

570{
572 PAGED_CODE();
573
574 /* Check if we were called from user-mode */
576 {
578 {
579 /* Verify the time pointer */
580 ProbeForWriteLargeInteger(SystemTime);
581
582 /*
583 * It's safe to pass the pointer directly to KeQuerySystemTime
584 * as it's just a basic copy to this pointer. If it raises an
585 * exception nothing dangerous can happen!
586 */
587 KeQuerySystemTime(SystemTime);
588 }
590 {
591 /* Return the exception code */
593 }
594 _SEH2_END;
595 }
596 else
597 {
598 /* Query the time directly */
599 KeQuerySystemTime(SystemTime);
600 }
601
602 /* Return success */
603 return STATUS_SUCCESS;
604}
#define PAGED_CODE()
#define ExGetPreviousMode
Definition: ex.h:140
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define KernelMode
Definition: asm.h:34
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:66
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:168
#define ProbeForWriteLargeInteger(Ptr)
Definition: probe.h:46
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103

Referenced by CalcVolumeSerialNumber(), create_bad_block_inode(), ElfReportEventA(), ElfReportEventW(), ext2_flush(), ext2_initialize_sb(), ext2_mkdir(), GetPasswordAge(), HTTP_ProcessExpires(), LogfReportEvent(), LogfWriteRecord(), LsapCreateDatabaseObjects(), LsapCreateRandomDomainSid(), LsarCreateSecret(), LsarSetSecret(), LsarStorePrivateData(), NetrRemoteTOD(), NtProcessStartup(), RtlRunEncodeUnicodeString(), SampSetupCreateDomain(), SampSetUserAll(), SampSetUserInternal1(), SampSetUserInternal2(), SamrChangePasswordUser(), SamValidateNormalUser(), SetDiskSignature(), START_TEST(), Test_ProcessTimes(), test_tp_timer(), test_tp_wait(), and test_tp_window_length().

◆ NtQueryTimerResolution()

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

Definition at line 633 of file time.c.

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

Referenced by START_TEST().

◆ NtSetSystemTime()

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

Definition at line 458 of file time.c.

460{
461 LARGE_INTEGER OldSystemTime;
462 LARGE_INTEGER NewSystemTime;
463 LARGE_INTEGER LocalTime;
467 RTL_TIME_ZONE_INFORMATION TimeZoneInformation = { 0 };
468 ULONG TimeZoneIdSave;
469
470 PAGED_CODE();
471
472 // TODO: Handle the case when SystemTime == NULL, which means:
473 // "update system time using the current time-zone information".
474 if (!SystemTime)
475 {
478 }
479
480 /* Check if we were called from user-mode */
482 {
484 {
485 /* Verify the time pointers */
486 NewSystemTime = ProbeForReadLargeInteger(SystemTime);
487 if (PreviousTime) ProbeForWriteLargeInteger(PreviousTime);
488 }
490 {
491 /* Return the exception code */
493 }
494 _SEH2_END;
495 }
496 else
497 {
498 /* Reuse the pointer */
499 NewSystemTime = *SystemTime;
500 }
501
502 /* Make sure we have permission to change the time */
504 {
505 DPRINT1("NtSetSystemTime: Caller requires the "
506 "SeSystemtimePrivilege privilege!\n");
508 }
509
510 /* Convert the time and set it in HAL */
511 ExSystemTimeToLocalTime(&NewSystemTime, &LocalTime);
512 RtlTimeToTimeFields(&LocalTime, &TimeFields);
514
515 /* Now set the system time and notify the system */
516 KeSetSystemTime(&NewSystemTime, &OldSystemTime, FALSE, NULL);
518
519 /* Check if caller wanted previous time */
520 if (PreviousTime)
521 {
522 /* Enter SEH Block for return */
524 {
525 /* Return the previous time */
526 *PreviousTime = OldSystemTime;
527 }
529 {
530 /* Get the exception code */
532 }
533 _SEH2_END;
534 }
535
536 /* Read time zone information from the registry and set the clock */
537 Status = RtlQueryTimeZoneInformation(&TimeZoneInformation);
538 if (!NT_SUCCESS(Status))
539 {
540 DPRINT1("RtlQueryTimeZoneInformation failed (Status 0x%08lx)\n", Status);
541 }
542
543 /* Test if we went from Daylight to Standard Time or vice versa */
544 TimeZoneIdSave = ExpTimeZoneId;
545 ExpSetTimeZoneInformation(&TimeZoneInformation);
546
547 if (ExpTimeZoneId != TimeZoneIdSave)
548 {
549 /* Going from DT to ST or vice versa we need to repeat this */
550 DPRINT("Daylight Time and Standard Time are switching\n");
551
552 /* Set the system time and notify the system */
553 KeSetSystemTime(&NewSystemTime, &OldSystemTime, FALSE, NULL);
555 }
556
557 /* Return status */
558 return Status;
559}
#define STATUS_PRIVILEGE_NOT_HELD
Definition: DriverTester.h:9
#define UNIMPLEMENTED
Definition: debug.h:118
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:361
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
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:239
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 684 of file time.c.

687{
691 ULONG NewResolution;
692
693 /* Check if the call came from user-mode */
695 {
697 {
698 /* Probe the parameter */
699 ProbeForWriteUlong(CurrentResolution);
700 }
702 {
703 /* Return the exception code */
705 }
706 _SEH2_END;
707 }
708
709 /* Set and return the new resolution */
710 NewResolution = ExSetTimerResolution(DesiredResolution, SetResolution);
711
713 {
715 {
716 *CurrentResolution = NewResolution;
717 }
719 {
720 /* Return the exception code */
722 }
723 _SEH2_END;
724 }
725 else
726 {
727 *CurrentResolution = NewResolution;
728 }
729
730 if (SetResolution || Process->SetTimerResolution)
731 {
732 /* The resolution has been changed now or in an earlier call */
734 }
735 else
736 {
737 /* The resolution hasn't been changed */
739 }
740
741 /* Update the flag */
742 Process->SetTimerResolution = SetResolution;
743
744 return Status;
745}
_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:713
#define PsGetCurrentProcess
Definition: psfuncs.h:17

Referenced by START_TEST().

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().