- Fix formatting and a bug in NtSetSystemTime.

svn path=/trunk/; revision=20434
This commit is contained in:
Alex Ionescu 2005-12-29 19:02:06 +00:00
parent a0f65e8fb1
commit 8b5a187ddc

View file

@ -1,11 +1,10 @@
/* $Id$ /*
*
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS Kernel
* FILE: ntoskrnl/ex/time.c * FILE: ntoskrnl/ex/time.c
* PURPOSE: Time * PURPOSE: Time and Timezone Management
* * PROGRAMMERS: Eric Kohl
* PROGRAMMERS: David Welch (welch@mcmail.com) * Thomas Weidenmueller
*/ */
/* INCLUDES *****************************************************************/ /* INCLUDES *****************************************************************/
@ -14,7 +13,6 @@
#define NDEBUG #define NDEBUG
#include <internal/debug.h> #include <internal/debug.h>
#define TICKSPERMINUTE 600000000 #define TICKSPERMINUTE 600000000
#if defined (ALLOC_PRAGMA) #if defined (ALLOC_PRAGMA)
@ -28,12 +26,11 @@ TIME_ZONE_INFORMATION ExpTimeZoneInfo;
LARGE_INTEGER ExpTimeZoneBias; LARGE_INTEGER ExpTimeZoneBias;
ULONG ExpTimeZoneId; ULONG ExpTimeZoneId;
/* FUNCTIONS ****************************************************************/ /* FUNCTIONS ****************************************************************/
VOID VOID
INIT_FUNCTION INIT_FUNCTION
STDCALL NTAPI
ExpInitTimeZoneInfo(VOID) ExpInitTimeZoneInfo(VOID)
{ {
LARGE_INTEGER CurrentTime; LARGE_INTEGER CurrentTime;
@ -43,8 +40,8 @@ ExpInitTimeZoneInfo(VOID)
Status = RtlQueryTimeZoneInformation(&ExpTimeZoneInfo); Status = RtlQueryTimeZoneInformation(&ExpTimeZoneInfo);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
memset(&ExpTimeZoneInfo, 0, sizeof(TIME_ZONE_INFORMATION)); /* Failed, clear all data */
RtlZeroMemory(&ExpTimeZoneInfo, sizeof(TIME_ZONE_INFORMATION));
ExpTimeZoneBias.QuadPart = (LONGLONG)0; ExpTimeZoneBias.QuadPart = (LONGLONG)0;
ExpTimeZoneId = TIME_ZONE_ID_UNKNOWN; ExpTimeZoneId = TIME_ZONE_ID_UNKNOWN;
} }
@ -52,11 +49,14 @@ ExpInitTimeZoneInfo(VOID)
{ {
/* FIXME: Calculate transition dates */ /* FIXME: Calculate transition dates */
ExpTimeZoneBias.QuadPart = /* Set bias and ID */
((LONGLONG)(ExpTimeZoneInfo.Bias + ExpTimeZoneInfo.StandardBias)) * TICKSPERMINUTE; ExpTimeZoneBias.QuadPart = ((LONGLONG)(ExpTimeZoneInfo.Bias +
ExpTimeZoneInfo.StandardBias)) *
TICKSPERMINUTE;
ExpTimeZoneId = TIME_ZONE_ID_STANDARD; ExpTimeZoneId = TIME_ZONE_ID_STANDARD;
} }
/* Change it for user-mode applications */
SharedUserData->TimeZoneBias.High1Time = ExpTimeZoneBias.u.HighPart; SharedUserData->TimeZoneBias.High1Time = ExpTimeZoneBias.u.HighPart;
SharedUserData->TimeZoneBias.High2Time = ExpTimeZoneBias.u.HighPart; SharedUserData->TimeZoneBias.High2Time = ExpTimeZoneBias.u.HighPart;
SharedUserData->TimeZoneBias.LowPart = ExpTimeZoneBias.u.LowPart; SharedUserData->TimeZoneBias.LowPart = ExpTimeZoneBias.u.LowPart;
@ -65,53 +65,48 @@ ExpInitTimeZoneInfo(VOID)
/* Convert boot time from local time to UTC */ /* Convert boot time from local time to UTC */
SystemBootTime.QuadPart += ExpTimeZoneBias.QuadPart; SystemBootTime.QuadPart += ExpTimeZoneBias.QuadPart;
/* Convert sytem time from local time to UTC */ /* Convert system time from local time to UTC */
do do
{ {
CurrentTime.u.HighPart = SharedUserData->SystemTime.High1Time; CurrentTime.u.HighPart = SharedUserData->SystemTime.High1Time;
CurrentTime.u.LowPart = SharedUserData->SystemTime.LowPart; CurrentTime.u.LowPart = SharedUserData->SystemTime.LowPart;
} } while (CurrentTime.u.HighPart != SharedUserData->SystemTime.High2Time);
while (CurrentTime.u.HighPart != SharedUserData->SystemTime.High2Time);
/* Change it for user-mode applications */
CurrentTime.QuadPart += ExpTimeZoneBias.QuadPart; CurrentTime.QuadPart += ExpTimeZoneBias.QuadPart;
SharedUserData->SystemTime.LowPart = CurrentTime.u.LowPart; SharedUserData->SystemTime.LowPart = CurrentTime.u.LowPart;
SharedUserData->SystemTime.High1Time = CurrentTime.u.HighPart; SharedUserData->SystemTime.High1Time = CurrentTime.u.HighPart;
SharedUserData->SystemTime.High2Time = CurrentTime.u.HighPart; SharedUserData->SystemTime.High2Time = CurrentTime.u.HighPart;
} }
NTSTATUS NTSTATUS
ExpSetTimeZoneInformation(PTIME_ZONE_INFORMATION TimeZoneInformation) ExpSetTimeZoneInformation(PTIME_ZONE_INFORMATION TimeZoneInformation)
{ {
LARGE_INTEGER LocalTime; LARGE_INTEGER LocalTime, SystemTime;
LARGE_INTEGER SystemTime;
TIME_FIELDS TimeFields; TIME_FIELDS TimeFields;
DPRINT("ExpSetTimeZoneInformation() called\n"); DPRINT("ExpSetTimeZoneInformation() called\n");
DPRINT("Old time zone bias: %d minutes\n", DPRINT("Old time zone bias: %d minutes\n", ExpTimeZoneInfo.Bias);
ExpTimeZoneInfo.Bias);
DPRINT("Old time zone standard bias: %d minutes\n", DPRINT("Old time zone standard bias: %d minutes\n",
ExpTimeZoneInfo.StandardBias); ExpTimeZoneInfo.StandardBias);
DPRINT("New time zone bias: %d minutes\n", TimeZoneInformation->Bias);
DPRINT("New time zone bias: %d minutes\n",
TimeZoneInformation->Bias);
DPRINT("New time zone standard bias: %d minutes\n", DPRINT("New time zone standard bias: %d minutes\n",
TimeZoneInformation->StandardBias); TimeZoneInformation->StandardBias);
/* Get the local time */ /* Get the local time */
HalQueryRealTimeClock(&TimeFields); HalQueryRealTimeClock(&TimeFields);
RtlTimeFieldsToTime(&TimeFields, RtlTimeFieldsToTime(&TimeFields, &LocalTime);
&LocalTime);
/* FIXME: Calculate transition dates */ /* FIXME: Calculate transition dates */
ExpTimeZoneBias.QuadPart = /* Calculate the bias and set the ID */
((LONGLONG)(TimeZoneInformation->Bias + TimeZoneInformation->StandardBias)) * TICKSPERMINUTE; ExpTimeZoneBias.QuadPart = ((LONGLONG)(TimeZoneInformation->Bias +
TimeZoneInformation->StandardBias)) *
TICKSPERMINUTE;
ExpTimeZoneId = TIME_ZONE_ID_STANDARD; ExpTimeZoneId = TIME_ZONE_ID_STANDARD;
memcpy(&ExpTimeZoneInfo, /* Copy the timezone information */
RtlMoveMemory(&ExpTimeZoneInfo,
TimeZoneInformation, TimeZoneInformation,
sizeof(TIME_ZONE_INFORMATION)); sizeof(TIME_ZONE_INFORMATION));
@ -125,18 +120,16 @@ ExpSetTimeZoneInformation(PTIME_ZONE_INFORMATION TimeZoneInformation)
ExpTimeZoneBias.QuadPart / TICKSPERMINUTE); ExpTimeZoneBias.QuadPart / TICKSPERMINUTE);
/* Calculate the new system time */ /* Calculate the new system time */
ExLocalTimeToSystemTime(&LocalTime, ExLocalTimeToSystemTime(&LocalTime, &SystemTime);
&SystemTime);
/* Set the new system time */ /* Set the new system time */
KiSetSystemTime(&SystemTime); KiSetSystemTime(&SystemTime);
/* Return success */
DPRINT("ExpSetTimeZoneInformation() done\n"); DPRINT("ExpSetTimeZoneInformation() done\n");
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
/* /*
* FUNCTION: Sets the system time. * FUNCTION: Sets the system time.
* PARAMETERS: * PARAMETERS:
@ -146,7 +139,8 @@ ExpSetTimeZoneInformation(PTIME_ZONE_INFORMATION TimeZoneInformation)
* old time of day in the standard time format. * old time of day in the standard time format.
* RETURNS: Status * RETURNS: Status
*/ */
NTSTATUS STDCALL NTSTATUS
NTAPI
NtSetSystemTime(IN PLARGE_INTEGER SystemTime, NtSetSystemTime(IN PLARGE_INTEGER SystemTime,
OUT PLARGE_INTEGER PreviousTime OPTIONAL) OUT PLARGE_INTEGER PreviousTime OPTIONAL)
{ {
@ -154,22 +148,18 @@ NtSetSystemTime(IN PLARGE_INTEGER SystemTime,
LARGE_INTEGER NewSystemTime; LARGE_INTEGER NewSystemTime;
LARGE_INTEGER LocalTime; LARGE_INTEGER LocalTime;
TIME_FIELDS TimeFields; TIME_FIELDS TimeFields;
KPROCESSOR_MODE PreviousMode; KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
NTSTATUS Status = STATUS_SUCCESS; NTSTATUS Status = STATUS_SUCCESS;
PAGED_CODE(); PAGED_CODE();
PreviousMode = ExGetPreviousMode(); /* Check if we were called from user-mode */
if(PreviousMode != KernelMode) if(PreviousMode != KernelMode)
{ {
_SEH_TRY _SEH_TRY
{ {
/* Verify the time pointers */
NewSystemTime = ProbeForReadLargeInteger(SystemTime); NewSystemTime = ProbeForReadLargeInteger(SystemTime);
if(PreviousTime != NULL) if(PreviousTime) ProbeForWriteLargeInteger(PreviousTime);
{
ProbeForWriteLargeInteger(PreviousTime);
}
} }
_SEH_EXCEPT(_SEH_ExSystemExceptionFilter) _SEH_EXCEPT(_SEH_ExSystemExceptionFilter)
{ {
@ -177,41 +167,41 @@ NtSetSystemTime(IN PLARGE_INTEGER SystemTime,
} }
_SEH_END; _SEH_END;
if(!NT_SUCCESS(Status)) /* If the pointers were invalid, bail out */
{ if(!NT_SUCCESS(Status)) return Status;
return Status;
}
} }
else else
{ {
/* Reuse the pointer */
NewSystemTime = *SystemTime; NewSystemTime = *SystemTime;
} }
if(!SeSinglePrivilegeCheck(SeSystemtimePrivilege, /* Make sure we have permission to change the time */
PreviousMode)) if(!SeSinglePrivilegeCheck(SeSystemtimePrivilege, PreviousMode))
{ {
DPRINT1("NtSetSystemTime: Caller requires the SeSystemtimePrivilege privilege!\n"); DPRINT1("NtSetSystemTime: Caller requires the "
"SeSystemtimePrivilege privilege!\n");
return STATUS_PRIVILEGE_NOT_HELD; return STATUS_PRIVILEGE_NOT_HELD;
} }
if(PreviousTime != NULL) /* Check if caller wants the old time */
{ if(PreviousTime) KeQuerySystemTime(&OldSystemTime);
KeQuerySystemTime(&OldSystemTime);
}
ExSystemTimeToLocalTime(&NewSystemTime, /* Convert the time and set it in HAL */
&LocalTime); ExSystemTimeToLocalTime(&NewSystemTime, &LocalTime);
RtlTimeToTimeFields(&LocalTime, RtlTimeToTimeFields(&LocalTime, &TimeFields);
&TimeFields);
HalSetRealTimeClock(&TimeFields); HalSetRealTimeClock(&TimeFields);
/* Set system time */ /* Now set system time */
KiSetSystemTime(&NewSystemTime); KiSetSystemTime(&NewSystemTime);
if(PreviousTime != NULL) /* Check if caller wanted previous time */
if(PreviousTime)
{ {
/* Enter SEH Block for return */
_SEH_TRY _SEH_TRY
{ {
/* Return the previous time */
*PreviousTime = OldSystemTime; *PreviousTime = OldSystemTime;
} }
_SEH_EXCEPT(_SEH_ExSystemExceptionFilter) _SEH_EXCEPT(_SEH_ExSystemExceptionFilter)
@ -221,35 +211,37 @@ NtSetSystemTime(IN PLARGE_INTEGER SystemTime,
_SEH_END; _SEH_END;
} }
return STATUS_SUCCESS; /* Return status */
return Status;
} }
/* /*
* FUNCTION: Retrieves the system time. * FUNCTION: Retrieves the system time.
* PARAMETERS: * PARAMETERS:
* CurrentTime - Points to a variable that receives the current * CurrentTime - Points to a variable that receives the current
* time of day in the standard time format. * time of day in the standard time format.
*/ */
NTSTATUS STDCALL NTSTATUS
NTAPI
NtQuerySystemTime(OUT PLARGE_INTEGER SystemTime) NtQuerySystemTime(OUT PLARGE_INTEGER SystemTime)
{ {
KPROCESSOR_MODE PreviousMode; KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
NTSTATUS Status = STATUS_SUCCESS; NTSTATUS Status = STATUS_SUCCESS;
PAGED_CODE(); PAGED_CODE();
PreviousMode = ExGetPreviousMode(); /* Check if we were called from user-mode */
if(PreviousMode != KernelMode) if(PreviousMode != KernelMode)
{ {
_SEH_TRY _SEH_TRY
{ {
/* Verify the time pointer */
ProbeForWriteLargeInteger(SystemTime); ProbeForWriteLargeInteger(SystemTime);
/* it's safe to pass the pointer directly to KeQuerySystemTime as it's just /*
a basic copy to these pointer, if it raises an exception nothing dangerous * It's safe to pass the pointer directly to KeQuerySystemTime as
can happen! */ * it's just a basic copy to this pointer. If it raises an
* exception nothing dangerous can happen!
*/
KeQuerySystemTime(SystemTime); KeQuerySystemTime(SystemTime);
} }
_SEH_EXCEPT(_SEH_ExSystemExceptionFilter) _SEH_EXCEPT(_SEH_ExSystemExceptionFilter)
@ -260,56 +252,46 @@ NtQuerySystemTime(OUT PLARGE_INTEGER SystemTime)
} }
else else
{ {
/* Query the time directly */
KeQuerySystemTime(SystemTime); KeQuerySystemTime(SystemTime);
} }
/* Return status to caller */
return Status; return Status;
} }
/* /*
* @implemented * @implemented
*/ */
VOID VOID
STDCALL NTAPI
ExLocalTimeToSystemTime ( ExLocalTimeToSystemTime(PLARGE_INTEGER LocalTime,
PLARGE_INTEGER LocalTime, PLARGE_INTEGER SystemTime)
PLARGE_INTEGER SystemTime
)
{ {
SystemTime->QuadPart = SystemTime->QuadPart = LocalTime->QuadPart + ExpTimeZoneBias.QuadPart;
LocalTime->QuadPart + ExpTimeZoneBias.QuadPart;
} }
/* /*
* @unimplemented * @unimplemented
*/ */
ULONG ULONG
STDCALL NTAPI
ExSetTimerResolution ( ExSetTimerResolution(IN ULONG DesiredTime,
IN ULONG DesiredTime, IN BOOLEAN SetResolution)
IN BOOLEAN SetResolution
)
{ {
UNIMPLEMENTED; UNIMPLEMENTED;
return 0; return 0;
} }
/* /*
* @implemented * @implemented
*/ */
VOID VOID
STDCALL NTAPI
ExSystemTimeToLocalTime ( ExSystemTimeToLocalTime(PLARGE_INTEGER SystemTime,
PLARGE_INTEGER SystemTime, PLARGE_INTEGER LocalTime)
PLARGE_INTEGER LocalTime
)
{ {
LocalTime->QuadPart = LocalTime->QuadPart = SystemTime->QuadPart - ExpTimeZoneBias.QuadPart;
SystemTime->QuadPart - ExpTimeZoneBias.QuadPart;
} }
/* EOF */ /* EOF */