2005-12-29 19:02:06 +00:00
|
|
|
/*
|
1998-08-25 04:27:26 +00:00
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
2005-12-29 19:02:06 +00:00
|
|
|
* PROJECT: ReactOS Kernel
|
2000-10-22 16:36:53 +00:00
|
|
|
* FILE: ntoskrnl/ex/time.c
|
2005-12-29 19:02:06 +00:00
|
|
|
* PURPOSE: Time and Timezone Management
|
|
|
|
* PROGRAMMERS: Eric Kohl
|
|
|
|
* Thomas Weidenmueller
|
1998-08-25 04:27:26 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES *****************************************************************/
|
|
|
|
|
2004-08-15 16:39:12 +00:00
|
|
|
#include <ntoskrnl.h>
|
2004-12-05 00:20:22 +00:00
|
|
|
#define NDEBUG
|
2008-08-30 16:31:06 +00:00
|
|
|
#include <debug.h>
|
1998-08-25 04:27:26 +00:00
|
|
|
|
1999-05-13 14:52:35 +00:00
|
|
|
#define TICKSPERMINUTE 600000000
|
|
|
|
|
|
|
|
/* GLOBALS ******************************************************************/
|
|
|
|
|
1999-08-11 23:29:26 +00:00
|
|
|
/* Note: Bias[minutes] = UTC - local time */
|
2018-05-31 15:48:29 +00:00
|
|
|
RTL_TIME_ZONE_INFORMATION ExpTimeZoneInfo;
|
2006-10-08 04:05:27 +00:00
|
|
|
ULONG ExpLastTimeZoneBias = -1;
|
2004-11-06 16:05:49 +00:00
|
|
|
LARGE_INTEGER ExpTimeZoneBias;
|
2007-05-09 00:29:38 +00:00
|
|
|
ULONG ExpAltTimeZoneBias;
|
2004-11-06 16:05:49 +00:00
|
|
|
ULONG ExpTimeZoneId;
|
2006-10-02 15:52:58 +00:00
|
|
|
ULONG ExpTickCountMultiplier;
|
- Add EXCEPTION_RECORD64 and LIST_ENTRY64, KeTryToAcquireSpinLockAtDpcLevel, BREAKPOINT_COMMAND_STRING, Ke386SetCr2, Ke386SetDr3, Ke386SetDr6.
- Remove non-kernel routines from kdfuncs.h and remove deprecated routines from ke.h.
- Implement KiRestoreProcessorControlState, KeFreezeExecution, KeThawExecution, ExAcquireTimeRefreshLock, ExReleaseTimeRefreshLock.
- Rename ModuleLoadList to PsLoadedModuleList. Add PsNtosImageBase and set value in it.
- Add skeleton wdbgexts.h with what's needed until now, this is a PSDK header.
- Add kddll.h for KDCOM/1394/USB2.DLL prototypes.
- Add windbgkd.h with KD protocol definitions. Used to be an NT5 DDK header, but was removed, so this goes into include\reactos.
svn path=/branches/alex-kd-branch/; revision=25833
2007-02-18 07:21:03 +00:00
|
|
|
ERESOURCE ExpTimeRefreshLock;
|
2010-01-03 18:29:30 +00:00
|
|
|
ULONG ExpKernelResolutionCount = 0;
|
|
|
|
ULONG ExpTimerResolutionCount = 0;
|
1999-05-13 14:52:35 +00:00
|
|
|
|
|
|
|
/* FUNCTIONS ****************************************************************/
|
1998-08-25 04:27:26 +00:00
|
|
|
|
2010-01-03 18:29:30 +00:00
|
|
|
/*++
|
|
|
|
* @name ExAcquireTimeRefreshLock
|
|
|
|
*
|
|
|
|
* The ExReleaseTimeRefreshLock routine acquires the system-wide lock used
|
|
|
|
* to synchronize clock interrupt frequency changes.
|
|
|
|
*
|
|
|
|
* @param Wait
|
|
|
|
* If TRUE, the system will block the caller thread waiting for the lock
|
|
|
|
* to become available. If FALSE, the routine will fail if the lock has
|
|
|
|
* already been acquired.
|
|
|
|
*
|
|
|
|
* @return Boolean value indicating success or failure of the lock acquisition.
|
|
|
|
*
|
|
|
|
* @remarks None.
|
|
|
|
*
|
|
|
|
*--*/
|
- Add EXCEPTION_RECORD64 and LIST_ENTRY64, KeTryToAcquireSpinLockAtDpcLevel, BREAKPOINT_COMMAND_STRING, Ke386SetCr2, Ke386SetDr3, Ke386SetDr6.
- Remove non-kernel routines from kdfuncs.h and remove deprecated routines from ke.h.
- Implement KiRestoreProcessorControlState, KeFreezeExecution, KeThawExecution, ExAcquireTimeRefreshLock, ExReleaseTimeRefreshLock.
- Rename ModuleLoadList to PsLoadedModuleList. Add PsNtosImageBase and set value in it.
- Add skeleton wdbgexts.h with what's needed until now, this is a PSDK header.
- Add kddll.h for KDCOM/1394/USB2.DLL prototypes.
- Add windbgkd.h with KD protocol definitions. Used to be an NT5 DDK header, but was removed, so this goes into include\reactos.
svn path=/branches/alex-kd-branch/; revision=25833
2007-02-18 07:21:03 +00:00
|
|
|
BOOLEAN
|
|
|
|
NTAPI
|
2013-08-21 16:54:19 +00:00
|
|
|
ExAcquireTimeRefreshLock(IN BOOLEAN Wait)
|
- Add EXCEPTION_RECORD64 and LIST_ENTRY64, KeTryToAcquireSpinLockAtDpcLevel, BREAKPOINT_COMMAND_STRING, Ke386SetCr2, Ke386SetDr3, Ke386SetDr6.
- Remove non-kernel routines from kdfuncs.h and remove deprecated routines from ke.h.
- Implement KiRestoreProcessorControlState, KeFreezeExecution, KeThawExecution, ExAcquireTimeRefreshLock, ExReleaseTimeRefreshLock.
- Rename ModuleLoadList to PsLoadedModuleList. Add PsNtosImageBase and set value in it.
- Add skeleton wdbgexts.h with what's needed until now, this is a PSDK header.
- Add kddll.h for KDCOM/1394/USB2.DLL prototypes.
- Add windbgkd.h with KD protocol definitions. Used to be an NT5 DDK header, but was removed, so this goes into include\reactos.
svn path=/branches/alex-kd-branch/; revision=25833
2007-02-18 07:21:03 +00:00
|
|
|
{
|
2010-01-03 18:29:30 +00:00
|
|
|
/* Block APCs */
|
- Add EXCEPTION_RECORD64 and LIST_ENTRY64, KeTryToAcquireSpinLockAtDpcLevel, BREAKPOINT_COMMAND_STRING, Ke386SetCr2, Ke386SetDr3, Ke386SetDr6.
- Remove non-kernel routines from kdfuncs.h and remove deprecated routines from ke.h.
- Implement KiRestoreProcessorControlState, KeFreezeExecution, KeThawExecution, ExAcquireTimeRefreshLock, ExReleaseTimeRefreshLock.
- Rename ModuleLoadList to PsLoadedModuleList. Add PsNtosImageBase and set value in it.
- Add skeleton wdbgexts.h with what's needed until now, this is a PSDK header.
- Add kddll.h for KDCOM/1394/USB2.DLL prototypes.
- Add windbgkd.h with KD protocol definitions. Used to be an NT5 DDK header, but was removed, so this goes into include\reactos.
svn path=/branches/alex-kd-branch/; revision=25833
2007-02-18 07:21:03 +00:00
|
|
|
KeEnterCriticalRegion();
|
2010-01-03 18:29:30 +00:00
|
|
|
|
|
|
|
/* Attempt lock acquisition */
|
- Add EXCEPTION_RECORD64 and LIST_ENTRY64, KeTryToAcquireSpinLockAtDpcLevel, BREAKPOINT_COMMAND_STRING, Ke386SetCr2, Ke386SetDr3, Ke386SetDr6.
- Remove non-kernel routines from kdfuncs.h and remove deprecated routines from ke.h.
- Implement KiRestoreProcessorControlState, KeFreezeExecution, KeThawExecution, ExAcquireTimeRefreshLock, ExReleaseTimeRefreshLock.
- Rename ModuleLoadList to PsLoadedModuleList. Add PsNtosImageBase and set value in it.
- Add skeleton wdbgexts.h with what's needed until now, this is a PSDK header.
- Add kddll.h for KDCOM/1394/USB2.DLL prototypes.
- Add windbgkd.h with KD protocol definitions. Used to be an NT5 DDK header, but was removed, so this goes into include\reactos.
svn path=/branches/alex-kd-branch/; revision=25833
2007-02-18 07:21:03 +00:00
|
|
|
if (!(ExAcquireResourceExclusiveLite(&ExpTimeRefreshLock, Wait)))
|
|
|
|
{
|
2010-01-03 18:29:30 +00:00
|
|
|
/* Lock was not acquired, enable APCs and fail */
|
- Add EXCEPTION_RECORD64 and LIST_ENTRY64, KeTryToAcquireSpinLockAtDpcLevel, BREAKPOINT_COMMAND_STRING, Ke386SetCr2, Ke386SetDr3, Ke386SetDr6.
- Remove non-kernel routines from kdfuncs.h and remove deprecated routines from ke.h.
- Implement KiRestoreProcessorControlState, KeFreezeExecution, KeThawExecution, ExAcquireTimeRefreshLock, ExReleaseTimeRefreshLock.
- Rename ModuleLoadList to PsLoadedModuleList. Add PsNtosImageBase and set value in it.
- Add skeleton wdbgexts.h with what's needed until now, this is a PSDK header.
- Add kddll.h for KDCOM/1394/USB2.DLL prototypes.
- Add windbgkd.h with KD protocol definitions. Used to be an NT5 DDK header, but was removed, so this goes into include\reactos.
svn path=/branches/alex-kd-branch/; revision=25833
2007-02-18 07:21:03 +00:00
|
|
|
KeLeaveCriticalRegion();
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-01-03 18:29:30 +00:00
|
|
|
/* Lock has been acquired */
|
- Add EXCEPTION_RECORD64 and LIST_ENTRY64, KeTryToAcquireSpinLockAtDpcLevel, BREAKPOINT_COMMAND_STRING, Ke386SetCr2, Ke386SetDr3, Ke386SetDr6.
- Remove non-kernel routines from kdfuncs.h and remove deprecated routines from ke.h.
- Implement KiRestoreProcessorControlState, KeFreezeExecution, KeThawExecution, ExAcquireTimeRefreshLock, ExReleaseTimeRefreshLock.
- Rename ModuleLoadList to PsLoadedModuleList. Add PsNtosImageBase and set value in it.
- Add skeleton wdbgexts.h with what's needed until now, this is a PSDK header.
- Add kddll.h for KDCOM/1394/USB2.DLL prototypes.
- Add windbgkd.h with KD protocol definitions. Used to be an NT5 DDK header, but was removed, so this goes into include\reactos.
svn path=/branches/alex-kd-branch/; revision=25833
2007-02-18 07:21:03 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-01-03 18:29:30 +00:00
|
|
|
/*++
|
|
|
|
* @name ExReleaseTimeRefreshLock
|
|
|
|
*
|
|
|
|
* The ExReleaseTimeRefreshLock routine releases the system-wide lock used
|
|
|
|
* to synchronize clock interrupt frequency changes.
|
|
|
|
*
|
|
|
|
* @param None.
|
|
|
|
*
|
|
|
|
* @return None.
|
|
|
|
*
|
|
|
|
* @remarks None.
|
|
|
|
*
|
|
|
|
*--*/
|
- Add EXCEPTION_RECORD64 and LIST_ENTRY64, KeTryToAcquireSpinLockAtDpcLevel, BREAKPOINT_COMMAND_STRING, Ke386SetCr2, Ke386SetDr3, Ke386SetDr6.
- Remove non-kernel routines from kdfuncs.h and remove deprecated routines from ke.h.
- Implement KiRestoreProcessorControlState, KeFreezeExecution, KeThawExecution, ExAcquireTimeRefreshLock, ExReleaseTimeRefreshLock.
- Rename ModuleLoadList to PsLoadedModuleList. Add PsNtosImageBase and set value in it.
- Add skeleton wdbgexts.h with what's needed until now, this is a PSDK header.
- Add kddll.h for KDCOM/1394/USB2.DLL prototypes.
- Add windbgkd.h with KD protocol definitions. Used to be an NT5 DDK header, but was removed, so this goes into include\reactos.
svn path=/branches/alex-kd-branch/; revision=25833
2007-02-18 07:21:03 +00:00
|
|
|
VOID
|
|
|
|
NTAPI
|
2013-08-21 16:54:19 +00:00
|
|
|
ExReleaseTimeRefreshLock(VOID)
|
- Add EXCEPTION_RECORD64 and LIST_ENTRY64, KeTryToAcquireSpinLockAtDpcLevel, BREAKPOINT_COMMAND_STRING, Ke386SetCr2, Ke386SetDr3, Ke386SetDr6.
- Remove non-kernel routines from kdfuncs.h and remove deprecated routines from ke.h.
- Implement KiRestoreProcessorControlState, KeFreezeExecution, KeThawExecution, ExAcquireTimeRefreshLock, ExReleaseTimeRefreshLock.
- Rename ModuleLoadList to PsLoadedModuleList. Add PsNtosImageBase and set value in it.
- Add skeleton wdbgexts.h with what's needed until now, this is a PSDK header.
- Add kddll.h for KDCOM/1394/USB2.DLL prototypes.
- Add windbgkd.h with KD protocol definitions. Used to be an NT5 DDK header, but was removed, so this goes into include\reactos.
svn path=/branches/alex-kd-branch/; revision=25833
2007-02-18 07:21:03 +00:00
|
|
|
{
|
2010-01-03 18:29:30 +00:00
|
|
|
/* Release the lock and re-enable APCs */
|
- Add EXCEPTION_RECORD64 and LIST_ENTRY64, KeTryToAcquireSpinLockAtDpcLevel, BREAKPOINT_COMMAND_STRING, Ke386SetCr2, Ke386SetDr3, Ke386SetDr6.
- Remove non-kernel routines from kdfuncs.h and remove deprecated routines from ke.h.
- Implement KiRestoreProcessorControlState, KeFreezeExecution, KeThawExecution, ExAcquireTimeRefreshLock, ExReleaseTimeRefreshLock.
- Rename ModuleLoadList to PsLoadedModuleList. Add PsNtosImageBase and set value in it.
- Add skeleton wdbgexts.h with what's needed until now, this is a PSDK header.
- Add kddll.h for KDCOM/1394/USB2.DLL prototypes.
- Add windbgkd.h with KD protocol definitions. Used to be an NT5 DDK header, but was removed, so this goes into include\reactos.
svn path=/branches/alex-kd-branch/; revision=25833
2007-02-18 07:21:03 +00:00
|
|
|
ExReleaseResourceLite(&ExpTimeRefreshLock);
|
|
|
|
KeLeaveCriticalRegion();
|
|
|
|
}
|
|
|
|
|
2010-01-03 18:29:30 +00:00
|
|
|
/*++
|
|
|
|
* @name ExSetTimerResolution
|
|
|
|
* @exported
|
|
|
|
*
|
|
|
|
* The KiInsertQueueApc routine modifies the frequency at which the system
|
|
|
|
* clock interrupts.
|
|
|
|
*
|
|
|
|
* @param DesiredTime
|
|
|
|
* Specifies the amount of time that should elapse between each timer
|
|
|
|
* interrupt, in 100-nanosecond units.
|
|
|
|
*
|
|
|
|
* This parameter is ignored if SetResolution is FALSE.
|
|
|
|
*
|
|
|
|
* @param SetResolution
|
|
|
|
* If TRUE, the call is a request to set the clock interrupt frequency to
|
|
|
|
* the value specified by DesiredTime. If FALSE, the call is a request to
|
|
|
|
* restore the clock interrupt frequency to the system's default value.
|
|
|
|
*
|
|
|
|
* @return New timer resolution, in 100-nanosecond ticks.
|
|
|
|
*
|
|
|
|
* @remarks (1) The clock frequency is changed only if the DesiredTime value is
|
|
|
|
* less than the current setting.
|
|
|
|
*
|
|
|
|
* (2) The routine just returns the current setting if the DesiredTime
|
|
|
|
* value is greater than what is currently set.
|
|
|
|
*
|
|
|
|
* (3) If the DesiredTime value is less than the system clock can
|
|
|
|
* support, the routine uses the smallest resolution the system can
|
|
|
|
* support, and returns that value.
|
|
|
|
*
|
|
|
|
* (4) If multiple drivers have attempted to change the clock interrupt
|
|
|
|
* frequency, the system will only restore the default frequency
|
|
|
|
* once ALL drivers have called the routine with SetResolution set
|
|
|
|
* to FALSE.
|
|
|
|
*
|
|
|
|
* NB. This routine synchronizes with IRP_MJ_POWER requests through the
|
|
|
|
* TimeRefreshLock.
|
|
|
|
*
|
|
|
|
*--*/
|
|
|
|
ULONG
|
|
|
|
NTAPI
|
|
|
|
ExSetTimerResolution(IN ULONG DesiredTime,
|
|
|
|
IN BOOLEAN SetResolution)
|
|
|
|
{
|
|
|
|
ULONG CurrentIncrement;
|
|
|
|
|
|
|
|
/* Wait for clock interrupt frequency and power requests to synchronize */
|
|
|
|
ExAcquireTimeRefreshLock(TRUE);
|
|
|
|
|
|
|
|
/* Obey remark 2*/
|
|
|
|
CurrentIncrement = KeTimeIncrement;
|
|
|
|
|
|
|
|
/* Check the type of operation this is */
|
|
|
|
if (SetResolution)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* If this is the first kernel change, bump the timer resolution change
|
|
|
|
* count, then bump the kernel change count as well.
|
|
|
|
*
|
|
|
|
* These two variables are tracked differently since user-mode processes
|
|
|
|
* can also change the timer resolution through the NtSetTimerResolution
|
|
|
|
* system call. A per-process flag in the EPROCESS then stores the per-
|
|
|
|
* process change state.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
if (!ExpKernelResolutionCount++) ExpTimerResolutionCount++;
|
|
|
|
|
|
|
|
/* Obey remark 3 */
|
|
|
|
if (DesiredTime < KeMinimumIncrement) DesiredTime = KeMinimumIncrement;
|
|
|
|
|
|
|
|
/* Obey remark 1 */
|
|
|
|
if (DesiredTime < KeTimeIncrement)
|
|
|
|
{
|
|
|
|
/* Force this thread on CPU zero, since we don't want it to drift */
|
|
|
|
KeSetSystemAffinityThread(1);
|
|
|
|
|
|
|
|
/* Now call the platform driver (HAL) to make the change */
|
|
|
|
CurrentIncrement = HalSetTimeIncrement(DesiredTime);
|
|
|
|
|
|
|
|
/* Put the thread back to its original affinity */
|
|
|
|
KeRevertToUserAffinityThread();
|
|
|
|
|
|
|
|
/* Finally, keep track of the new value in the kernel */
|
|
|
|
KeTimeIncrement = CurrentIncrement;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* First, make sure that a driver has actually changed the resolution */
|
|
|
|
if (ExpKernelResolutionCount)
|
|
|
|
{
|
|
|
|
/* Obey remark 4 */
|
|
|
|
if (--ExpKernelResolutionCount)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* All kernel drivers have requested the original frequency to
|
|
|
|
* be restored, but there might still be user processes with an
|
|
|
|
* ongoing clock interrupt frequency change, so make sure that
|
|
|
|
* this isn't the case.
|
|
|
|
*/
|
|
|
|
if (--ExpTimerResolutionCount)
|
|
|
|
{
|
|
|
|
/* Force this thread on one CPU so that it doesn't drift */
|
|
|
|
KeSetSystemAffinityThread(1);
|
|
|
|
|
|
|
|
/* Call the HAL to restore the frequency to its default */
|
|
|
|
CurrentIncrement = HalSetTimeIncrement(KeMaximumIncrement);
|
|
|
|
|
|
|
|
/* Put the thread back to its original affinity */
|
|
|
|
KeRevertToUserAffinityThread();
|
|
|
|
|
|
|
|
/* Finally, keep track of the new value in the kernel */
|
|
|
|
KeTimeIncrement = CurrentIncrement;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Release the clock interrupt frequency lock since changes are done */
|
|
|
|
ExReleaseTimeRefreshLock();
|
|
|
|
|
|
|
|
/* And return the current value -- which could reflect the new frequency */
|
|
|
|
return CurrentIncrement;
|
|
|
|
}
|
|
|
|
|
- Add EXCEPTION_RECORD64 and LIST_ENTRY64, KeTryToAcquireSpinLockAtDpcLevel, BREAKPOINT_COMMAND_STRING, Ke386SetCr2, Ke386SetDr3, Ke386SetDr6.
- Remove non-kernel routines from kdfuncs.h and remove deprecated routines from ke.h.
- Implement KiRestoreProcessorControlState, KeFreezeExecution, KeThawExecution, ExAcquireTimeRefreshLock, ExReleaseTimeRefreshLock.
- Rename ModuleLoadList to PsLoadedModuleList. Add PsNtosImageBase and set value in it.
- Add skeleton wdbgexts.h with what's needed until now, this is a PSDK header.
- Add kddll.h for KDCOM/1394/USB2.DLL prototypes.
- Add windbgkd.h with KD protocol definitions. Used to be an NT5 DDK header, but was removed, so this goes into include\reactos.
svn path=/branches/alex-kd-branch/; revision=25833
2007-02-18 07:21:03 +00:00
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
ExUpdateSystemTimeFromCmos(IN BOOLEAN UpdateInterruptTime,
|
|
|
|
IN ULONG MaxSepInSeconds)
|
|
|
|
{
|
|
|
|
/* FIXME: TODO */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-10-08 04:05:27 +00:00
|
|
|
BOOLEAN
|
2005-12-29 19:02:06 +00:00
|
|
|
NTAPI
|
2006-10-08 04:05:27 +00:00
|
|
|
ExRefreshTimeZoneInformation(IN PLARGE_INTEGER CurrentBootTime)
|
1999-08-11 23:29:26 +00:00
|
|
|
{
|
2005-12-29 19:02:06 +00:00
|
|
|
LARGE_INTEGER CurrentTime;
|
|
|
|
NTSTATUS Status;
|
1999-08-11 23:29:26 +00:00
|
|
|
|
2006-10-08 04:05:27 +00:00
|
|
|
/* Read time zone information from the registry */
|
2005-12-29 19:02:06 +00:00
|
|
|
Status = RtlQueryTimeZoneInformation(&ExpTimeZoneInfo);
|
|
|
|
if (!NT_SUCCESS(Status))
|
2004-11-05 17:42:20 +00:00
|
|
|
{
|
2005-12-29 19:02:06 +00:00
|
|
|
/* Failed, clear all data */
|
2018-05-31 15:48:29 +00:00
|
|
|
RtlZeroMemory(&ExpTimeZoneInfo, sizeof(RTL_TIME_ZONE_INFORMATION));
|
2005-12-29 19:02:06 +00:00
|
|
|
ExpTimeZoneBias.QuadPart = (LONGLONG)0;
|
|
|
|
ExpTimeZoneId = TIME_ZONE_ID_UNKNOWN;
|
2004-11-05 17:42:20 +00:00
|
|
|
}
|
2005-12-29 19:02:06 +00:00
|
|
|
else
|
2004-11-06 16:05:49 +00:00
|
|
|
{
|
2005-12-29 19:02:06 +00:00
|
|
|
/* FIXME: Calculate transition dates */
|
2004-11-06 16:05:49 +00:00
|
|
|
|
2005-12-29 19:02:06 +00:00
|
|
|
/* Set bias and ID */
|
|
|
|
ExpTimeZoneBias.QuadPart = ((LONGLONG)(ExpTimeZoneInfo.Bias +
|
2006-10-08 04:05:27 +00:00
|
|
|
ExpTimeZoneInfo.StandardBias)) *
|
|
|
|
TICKSPERMINUTE;
|
2005-12-29 19:02:06 +00:00
|
|
|
ExpTimeZoneId = TIME_ZONE_ID_STANDARD;
|
2004-11-06 16:05:49 +00:00
|
|
|
}
|
|
|
|
|
2005-12-29 19:02:06 +00:00
|
|
|
/* Change it for user-mode applications */
|
|
|
|
SharedUserData->TimeZoneBias.High1Time = ExpTimeZoneBias.u.HighPart;
|
|
|
|
SharedUserData->TimeZoneBias.High2Time = ExpTimeZoneBias.u.HighPart;
|
|
|
|
SharedUserData->TimeZoneBias.LowPart = ExpTimeZoneBias.u.LowPart;
|
|
|
|
SharedUserData->TimeZoneId = ExpTimeZoneId;
|
2004-11-29 15:00:46 +00:00
|
|
|
|
2005-12-29 19:02:06 +00:00
|
|
|
/* Convert boot time from local time to UTC */
|
2006-10-08 04:05:27 +00:00
|
|
|
KeBootTime.QuadPart += ExpTimeZoneBias.QuadPart;
|
2004-11-29 15:00:46 +00:00
|
|
|
|
2005-12-29 19:02:06 +00:00
|
|
|
/* Convert system time from local time to UTC */
|
|
|
|
do
|
2004-11-29 15:00:46 +00:00
|
|
|
{
|
2005-12-29 19:02:06 +00:00
|
|
|
CurrentTime.u.HighPart = SharedUserData->SystemTime.High1Time;
|
|
|
|
CurrentTime.u.LowPart = SharedUserData->SystemTime.LowPart;
|
|
|
|
} while (CurrentTime.u.HighPart != SharedUserData->SystemTime.High2Time);
|
|
|
|
|
|
|
|
/* Change it for user-mode applications */
|
|
|
|
CurrentTime.QuadPart += ExpTimeZoneBias.QuadPart;
|
|
|
|
SharedUserData->SystemTime.LowPart = CurrentTime.u.LowPart;
|
|
|
|
SharedUserData->SystemTime.High1Time = CurrentTime.u.HighPart;
|
|
|
|
SharedUserData->SystemTime.High2Time = CurrentTime.u.HighPart;
|
2006-10-08 04:05:27 +00:00
|
|
|
|
|
|
|
/* Return success */
|
|
|
|
return TRUE;
|
1999-08-11 23:29:26 +00:00
|
|
|
}
|
|
|
|
|
2004-12-01 14:28:54 +00:00
|
|
|
NTSTATUS
|
2018-05-31 15:48:29 +00:00
|
|
|
ExpSetTimeZoneInformation(PRTL_TIME_ZONE_INFORMATION TimeZoneInformation)
|
2004-12-01 14:28:54 +00:00
|
|
|
{
|
2007-01-25 05:14:55 +00:00
|
|
|
LARGE_INTEGER LocalTime, SystemTime, OldTime;
|
2005-12-29 19:02:06 +00:00
|
|
|
TIME_FIELDS TimeFields;
|
|
|
|
DPRINT("ExpSetTimeZoneInformation() called\n");
|
|
|
|
|
|
|
|
DPRINT("Old time zone bias: %d minutes\n", ExpTimeZoneInfo.Bias);
|
|
|
|
DPRINT("Old time zone standard bias: %d minutes\n",
|
|
|
|
ExpTimeZoneInfo.StandardBias);
|
|
|
|
DPRINT("New time zone bias: %d minutes\n", TimeZoneInformation->Bias);
|
|
|
|
DPRINT("New time zone standard bias: %d minutes\n",
|
|
|
|
TimeZoneInformation->StandardBias);
|
|
|
|
|
|
|
|
/* Get the local time */
|
|
|
|
HalQueryRealTimeClock(&TimeFields);
|
|
|
|
RtlTimeFieldsToTime(&TimeFields, &LocalTime);
|
|
|
|
|
|
|
|
/* FIXME: Calculate transition dates */
|
|
|
|
|
|
|
|
/* Calculate the bias and set the ID */
|
|
|
|
ExpTimeZoneBias.QuadPart = ((LONGLONG)(TimeZoneInformation->Bias +
|
|
|
|
TimeZoneInformation->StandardBias)) *
|
|
|
|
TICKSPERMINUTE;
|
|
|
|
ExpTimeZoneId = TIME_ZONE_ID_STANDARD;
|
|
|
|
|
|
|
|
/* Copy the timezone information */
|
2006-10-22 09:06:58 +00:00
|
|
|
RtlCopyMemory(&ExpTimeZoneInfo,
|
2005-12-29 19:02:06 +00:00
|
|
|
TimeZoneInformation,
|
2018-05-31 15:48:29 +00:00
|
|
|
sizeof(RTL_TIME_ZONE_INFORMATION));
|
2005-12-29 19:02:06 +00:00
|
|
|
|
|
|
|
/* Set the new time zone information */
|
|
|
|
SharedUserData->TimeZoneBias.High1Time = ExpTimeZoneBias.u.HighPart;
|
|
|
|
SharedUserData->TimeZoneBias.High2Time = ExpTimeZoneBias.u.HighPart;
|
|
|
|
SharedUserData->TimeZoneBias.LowPart = ExpTimeZoneBias.u.LowPart;
|
|
|
|
SharedUserData->TimeZoneId = ExpTimeZoneId;
|
|
|
|
|
|
|
|
DPRINT("New time zone bias: %I64d minutes\n",
|
|
|
|
ExpTimeZoneBias.QuadPart / TICKSPERMINUTE);
|
|
|
|
|
|
|
|
/* Calculate the new system time */
|
|
|
|
ExLocalTimeToSystemTime(&LocalTime, &SystemTime);
|
|
|
|
|
|
|
|
/* Set the new system time */
|
2007-01-25 05:14:55 +00:00
|
|
|
KeSetSystemTime(&SystemTime, &OldTime, FALSE, NULL);
|
2005-12-29 19:02:06 +00:00
|
|
|
|
|
|
|
/* Return success */
|
|
|
|
DPRINT("ExpSetTimeZoneInformation() done\n");
|
|
|
|
return STATUS_SUCCESS;
|
2004-12-01 14:28:54 +00:00
|
|
|
}
|
|
|
|
|
2004-11-05 17:42:20 +00:00
|
|
|
/*
|
|
|
|
* FUNCTION: Sets the system time.
|
|
|
|
* PARAMETERS:
|
|
|
|
* NewTime - Points to a variable that specified the new time
|
|
|
|
* of day in the standard time format.
|
|
|
|
* OldTime - Optionally points to a variable that receives the
|
|
|
|
* old time of day in the standard time format.
|
|
|
|
* RETURNS: Status
|
|
|
|
*/
|
2005-12-29 19:02:06 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
2005-01-23 23:02:19 +00:00
|
|
|
NtSetSystemTime(IN PLARGE_INTEGER SystemTime,
|
2005-12-29 19:02:06 +00:00
|
|
|
OUT PLARGE_INTEGER PreviousTime OPTIONAL)
|
1998-10-05 04:01:30 +00:00
|
|
|
{
|
2005-12-29 19:02:06 +00:00
|
|
|
LARGE_INTEGER OldSystemTime;
|
|
|
|
LARGE_INTEGER NewSystemTime;
|
|
|
|
LARGE_INTEGER LocalTime;
|
|
|
|
TIME_FIELDS TimeFields;
|
|
|
|
KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
|
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
|
|
|
PAGED_CODE();
|
|
|
|
|
|
|
|
/* Check if we were called from user-mode */
|
2009-08-26 17:31:02 +00:00
|
|
|
if (PreviousMode != KernelMode)
|
2001-09-06 20:26:36 +00:00
|
|
|
{
|
2008-11-24 13:40:26 +00:00
|
|
|
_SEH2_TRY
|
2005-12-29 19:02:06 +00:00
|
|
|
{
|
|
|
|
/* Verify the time pointers */
|
|
|
|
NewSystemTime = ProbeForReadLargeInteger(SystemTime);
|
|
|
|
if(PreviousTime) ProbeForWriteLargeInteger(PreviousTime);
|
|
|
|
}
|
2009-08-26 17:31:02 +00:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2005-12-29 19:02:06 +00:00
|
|
|
{
|
2009-08-26 17:31:02 +00:00
|
|
|
/* Return the exception code */
|
|
|
|
_SEH2_YIELD(return _SEH2_GetExceptionCode());
|
2005-12-29 19:02:06 +00:00
|
|
|
}
|
2008-11-24 13:40:26 +00:00
|
|
|
_SEH2_END;
|
2001-09-06 20:26:36 +00:00
|
|
|
}
|
2005-12-29 19:02:06 +00:00
|
|
|
else
|
2001-09-06 20:26:36 +00:00
|
|
|
{
|
2005-12-29 19:02:06 +00:00
|
|
|
/* Reuse the pointer */
|
|
|
|
NewSystemTime = *SystemTime;
|
2001-09-06 20:26:36 +00:00
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-12-29 19:02:06 +00:00
|
|
|
/* Make sure we have permission to change the time */
|
2009-08-26 17:31:02 +00:00
|
|
|
if (!SeSinglePrivilegeCheck(SeSystemtimePrivilege, PreviousMode))
|
2005-01-23 23:02:19 +00:00
|
|
|
{
|
2005-12-29 19:02:06 +00:00
|
|
|
DPRINT1("NtSetSystemTime: Caller requires the "
|
|
|
|
"SeSystemtimePrivilege privilege!\n");
|
|
|
|
return STATUS_PRIVILEGE_NOT_HELD;
|
2005-01-23 23:02:19 +00:00
|
|
|
}
|
2005-12-29 19:02:06 +00:00
|
|
|
|
|
|
|
/* Convert the time and set it in HAL */
|
|
|
|
ExSystemTimeToLocalTime(&NewSystemTime, &LocalTime);
|
|
|
|
RtlTimeToTimeFields(&LocalTime, &TimeFields);
|
|
|
|
HalSetRealTimeClock(&TimeFields);
|
|
|
|
|
|
|
|
/* Now set system time */
|
2007-01-25 05:14:55 +00:00
|
|
|
KeSetSystemTime(&NewSystemTime, &OldSystemTime, FALSE, NULL);
|
2005-12-29 19:02:06 +00:00
|
|
|
|
|
|
|
/* Check if caller wanted previous time */
|
2009-08-26 17:31:02 +00:00
|
|
|
if (PreviousTime)
|
2005-01-23 23:02:19 +00:00
|
|
|
{
|
2005-12-29 19:02:06 +00:00
|
|
|
/* Enter SEH Block for return */
|
2008-11-24 13:40:26 +00:00
|
|
|
_SEH2_TRY
|
2005-12-29 19:02:06 +00:00
|
|
|
{
|
|
|
|
/* Return the previous time */
|
|
|
|
*PreviousTime = OldSystemTime;
|
|
|
|
}
|
2008-11-24 13:40:26 +00:00
|
|
|
_SEH2_EXCEPT(ExSystemExceptionFilter())
|
2005-12-29 19:02:06 +00:00
|
|
|
{
|
2009-08-26 17:31:02 +00:00
|
|
|
/* Get the exception code */
|
2008-11-24 13:40:26 +00:00
|
|
|
Status = _SEH2_GetExceptionCode();
|
2005-12-29 19:02:06 +00:00
|
|
|
}
|
2008-11-24 13:40:26 +00:00
|
|
|
_SEH2_END;
|
2005-01-23 23:02:19 +00:00
|
|
|
}
|
2004-11-28 12:59:33 +00:00
|
|
|
|
2005-12-29 19:02:06 +00:00
|
|
|
/* Return status */
|
|
|
|
return Status;
|
1998-10-05 04:01:30 +00:00
|
|
|
}
|
|
|
|
|
2004-11-05 17:42:20 +00:00
|
|
|
/*
|
|
|
|
* FUNCTION: Retrieves the system time.
|
|
|
|
* PARAMETERS:
|
|
|
|
* CurrentTime - Points to a variable that receives the current
|
|
|
|
* time of day in the standard time format.
|
|
|
|
*/
|
2005-12-29 19:02:06 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
2005-01-23 23:02:19 +00:00
|
|
|
NtQuerySystemTime(OUT PLARGE_INTEGER SystemTime)
|
1998-10-05 04:01:30 +00:00
|
|
|
{
|
2005-12-29 19:02:06 +00:00
|
|
|
KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
|
|
|
|
PAGED_CODE();
|
2001-09-06 20:26:36 +00:00
|
|
|
|
2005-12-29 19:02:06 +00:00
|
|
|
/* Check if we were called from user-mode */
|
2009-08-26 17:31:02 +00:00
|
|
|
if (PreviousMode != KernelMode)
|
2001-09-06 20:26:36 +00:00
|
|
|
{
|
2008-11-24 13:40:26 +00:00
|
|
|
_SEH2_TRY
|
2005-12-29 19:02:06 +00:00
|
|
|
{
|
|
|
|
/* Verify the time pointer */
|
|
|
|
ProbeForWriteLargeInteger(SystemTime);
|
|
|
|
|
|
|
|
/*
|
2013-12-31 20:47:05 +00:00
|
|
|
* It's safe to pass the pointer directly to KeQuerySystemTime
|
|
|
|
* as it's just a basic copy to this pointer. If it raises an
|
2005-12-29 19:02:06 +00:00
|
|
|
* exception nothing dangerous can happen!
|
|
|
|
*/
|
|
|
|
KeQuerySystemTime(SystemTime);
|
|
|
|
}
|
2009-08-26 17:31:02 +00:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2005-12-29 19:02:06 +00:00
|
|
|
{
|
2013-12-31 20:47:05 +00:00
|
|
|
/* Return the exception code */
|
|
|
|
_SEH2_YIELD(return _SEH2_GetExceptionCode());
|
2005-12-29 19:02:06 +00:00
|
|
|
}
|
2008-11-24 13:40:26 +00:00
|
|
|
_SEH2_END;
|
2001-09-06 20:26:36 +00:00
|
|
|
}
|
2005-12-29 19:02:06 +00:00
|
|
|
else
|
2005-01-23 23:02:19 +00:00
|
|
|
{
|
2005-12-29 19:02:06 +00:00
|
|
|
/* Query the time directly */
|
|
|
|
KeQuerySystemTime(SystemTime);
|
2005-01-23 23:02:19 +00:00
|
|
|
}
|
1998-10-05 04:01:30 +00:00
|
|
|
|
2013-12-31 20:47:05 +00:00
|
|
|
/* Return success */
|
|
|
|
return STATUS_SUCCESS;
|
2005-12-29 19:02:06 +00:00
|
|
|
}
|
1998-10-05 04:01:30 +00:00
|
|
|
|
2003-07-10 06:27:13 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
1999-06-18 22:11:21 +00:00
|
|
|
VOID
|
2005-12-29 19:02:06 +00:00
|
|
|
NTAPI
|
|
|
|
ExLocalTimeToSystemTime(PLARGE_INTEGER LocalTime,
|
|
|
|
PLARGE_INTEGER SystemTime)
|
1998-08-25 04:27:26 +00:00
|
|
|
{
|
2005-12-29 19:02:06 +00:00
|
|
|
SystemTime->QuadPart = LocalTime->QuadPart + ExpTimeZoneBias.QuadPart;
|
1998-08-25 04:27:26 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 06:27:13 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
1999-06-18 22:11:21 +00:00
|
|
|
VOID
|
2005-12-29 19:02:06 +00:00
|
|
|
NTAPI
|
|
|
|
ExSystemTimeToLocalTime(PLARGE_INTEGER SystemTime,
|
|
|
|
PLARGE_INTEGER LocalTime)
|
1998-08-25 04:27:26 +00:00
|
|
|
{
|
2005-12-29 19:02:06 +00:00
|
|
|
LocalTime->QuadPart = SystemTime->QuadPart - ExpTimeZoneBias.QuadPart;
|
1998-08-25 04:27:26 +00:00
|
|
|
}
|
1999-08-11 23:29:26 +00:00
|
|
|
|
2013-08-21 16:54:19 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
NtQueryTimerResolution(OUT PULONG MinimumResolution,
|
|
|
|
OUT PULONG MaximumResolution,
|
|
|
|
OUT PULONG ActualResolution)
|
|
|
|
{
|
|
|
|
KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
|
|
|
|
|
2013-12-31 20:47:05 +00:00
|
|
|
/* Check if the call came from user-mode */
|
2013-08-21 16:54:19 +00:00
|
|
|
if (PreviousMode != KernelMode)
|
|
|
|
{
|
|
|
|
_SEH2_TRY
|
|
|
|
{
|
|
|
|
/* Probe the parameters */
|
|
|
|
ProbeForWriteUlong(MinimumResolution);
|
|
|
|
ProbeForWriteUlong(MaximumResolution);
|
|
|
|
ProbeForWriteUlong(ActualResolution);
|
2013-12-31 20:47:05 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the parameters to the actual values.
|
|
|
|
*
|
|
|
|
* NOTE:
|
|
|
|
* MinimumResolution corresponds to the biggest time increment and
|
|
|
|
* MaximumResolution corresponds to the smallest time increment.
|
|
|
|
*/
|
|
|
|
*MinimumResolution = KeMaximumIncrement;
|
|
|
|
*MaximumResolution = KeMinimumIncrement;
|
|
|
|
*ActualResolution = KeTimeIncrement;
|
2013-08-21 16:54:19 +00:00
|
|
|
}
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
|
|
|
/* Return the exception code */
|
|
|
|
_SEH2_YIELD(return _SEH2_GetExceptionCode());
|
|
|
|
}
|
|
|
|
_SEH2_END;
|
|
|
|
}
|
2013-12-31 20:47:05 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Set the parameters to the actual values */
|
|
|
|
*MinimumResolution = KeMaximumIncrement;
|
|
|
|
*MaximumResolution = KeMinimumIncrement;
|
|
|
|
*ActualResolution = KeTimeIncrement;
|
|
|
|
}
|
2013-08-21 16:54:19 +00:00
|
|
|
|
|
|
|
/* Return success */
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
NtSetTimerResolution(IN ULONG DesiredResolution,
|
|
|
|
IN BOOLEAN SetResolution,
|
|
|
|
OUT PULONG CurrentResolution)
|
|
|
|
{
|
2013-09-28 11:37:08 +00:00
|
|
|
NTSTATUS Status;
|
2013-08-21 16:54:19 +00:00
|
|
|
KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
|
|
|
|
PEPROCESS Process = PsGetCurrentProcess();
|
|
|
|
ULONG NewResolution;
|
|
|
|
|
2013-12-31 20:47:05 +00:00
|
|
|
/* Check if the call came from user-mode */
|
2013-08-21 16:54:19 +00:00
|
|
|
if (PreviousMode != KernelMode)
|
|
|
|
{
|
|
|
|
_SEH2_TRY
|
|
|
|
{
|
|
|
|
/* Probe the parameter */
|
|
|
|
ProbeForWriteUlong(CurrentResolution);
|
|
|
|
}
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
|
|
|
/* Return the exception code */
|
|
|
|
_SEH2_YIELD(return _SEH2_GetExceptionCode());
|
|
|
|
}
|
|
|
|
_SEH2_END;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set and return the new resolution */
|
|
|
|
NewResolution = ExSetTimerResolution(DesiredResolution, SetResolution);
|
2013-12-31 20:47:05 +00:00
|
|
|
|
|
|
|
if (PreviousMode != KernelMode)
|
|
|
|
{
|
|
|
|
_SEH2_TRY
|
|
|
|
{
|
|
|
|
*CurrentResolution = NewResolution;
|
|
|
|
}
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
|
|
|
/* Return the exception code */
|
|
|
|
_SEH2_YIELD(return _SEH2_GetExceptionCode());
|
|
|
|
}
|
|
|
|
_SEH2_END;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*CurrentResolution = NewResolution;
|
|
|
|
}
|
2013-08-21 16:54:19 +00:00
|
|
|
|
2013-09-28 11:37:08 +00:00
|
|
|
if (SetResolution || Process->SetTimerResolution)
|
2013-08-21 16:54:19 +00:00
|
|
|
{
|
2013-09-28 11:37:08 +00:00
|
|
|
/* The resolution has been changed now or in an earlier call */
|
|
|
|
Status = STATUS_SUCCESS;
|
2013-08-21 16:54:19 +00:00
|
|
|
}
|
2013-09-28 11:37:08 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* The resolution hasn't been changed */
|
|
|
|
Status = STATUS_TIMER_RESOLUTION_NOT_SET;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update the flag */
|
|
|
|
Process->SetTimerResolution = SetResolution;
|
2013-08-21 16:54:19 +00:00
|
|
|
|
2013-09-28 11:37:08 +00:00
|
|
|
return Status;
|
2013-08-21 16:54:19 +00:00
|
|
|
}
|
|
|
|
|
1999-08-11 23:29:26 +00:00
|
|
|
/* EOF */
|