ntdll: Return the current time and timezone bias in NtQuerySystemInformation(SystemTimeOfDayInformation).

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2020-06-25 12:30:00 +02:00
parent c031662fd0
commit 7161dcd426
5 changed files with 23 additions and 53 deletions

View File

@ -228,44 +228,6 @@ BOOLEAN WINAPI RtlTimeFieldsToTime(
return TRUE; return TRUE;
} }
/***********************************************************************
* TIME_GetBias [internal]
*
* Helper function calculates delta local time from UTC.
*
* PARAMS
* utc [I] The current utc time.
* pdaylight [I] Local daylight.
*
* RETURNS
* The bias for the current timezone.
*/
static LONG TIME_GetBias(void)
{
static time_t last_utc;
static LONG last_bias;
LONG ret;
time_t utc;
utc = time( NULL );
RtlEnterCriticalSection( &TIME_tz_section );
if (utc != last_utc)
{
RTL_DYNAMIC_TIME_ZONE_INFORMATION tzi;
int is_dst = init_tz_info( &tzi );
last_utc = utc;
last_bias = tzi.Bias;
last_bias += is_dst ? tzi.DaylightBias : tzi.StandardBias;
last_bias *= SECSPERMIN;
}
ret = last_bias;
RtlLeaveCriticalSection( &TIME_tz_section );
return ret;
}
/****************************************************************************** /******************************************************************************
* RtlLocalTimeToSystemTime [NTDLL.@] * RtlLocalTimeToSystemTime [NTDLL.@]
@ -283,12 +245,12 @@ static LONG TIME_GetBias(void)
NTSTATUS WINAPI RtlLocalTimeToSystemTime( const LARGE_INTEGER *LocalTime, NTSTATUS WINAPI RtlLocalTimeToSystemTime( const LARGE_INTEGER *LocalTime,
PLARGE_INTEGER SystemTime) PLARGE_INTEGER SystemTime)
{ {
LONG bias; SYSTEM_TIMEOFDAY_INFORMATION info;
TRACE("(%p, %p)\n", LocalTime, SystemTime); TRACE("(%p, %p)\n", LocalTime, SystemTime);
bias = TIME_GetBias(); NtQuerySystemInformation( SystemTimeOfDayInformation, &info, sizeof(info), NULL );
SystemTime->QuadPart = LocalTime->QuadPart + bias * (LONGLONG)TICKSPERSEC; SystemTime->QuadPart = LocalTime->QuadPart + info.TimeZoneBias.QuadPart;
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
@ -308,12 +270,12 @@ NTSTATUS WINAPI RtlLocalTimeToSystemTime( const LARGE_INTEGER *LocalTime,
NTSTATUS WINAPI RtlSystemTimeToLocalTime( const LARGE_INTEGER *SystemTime, NTSTATUS WINAPI RtlSystemTimeToLocalTime( const LARGE_INTEGER *SystemTime,
PLARGE_INTEGER LocalTime ) PLARGE_INTEGER LocalTime )
{ {
LONG bias; SYSTEM_TIMEOFDAY_INFORMATION info;
TRACE("(%p, %p)\n", SystemTime, LocalTime); TRACE("(%p, %p)\n", SystemTime, LocalTime);
bias = TIME_GetBias(); NtQuerySystemInformation( SystemTimeOfDayInformation, &info, sizeof(info), NULL );
LocalTime->QuadPart = SystemTime->QuadPart - bias * (LONGLONG)TICKSPERSEC; LocalTime->QuadPart = SystemTime->QuadPart - info.TimeZoneBias.QuadPart;
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }

View File

@ -1690,10 +1690,18 @@ NTSTATUS WINAPI NtQuerySystemInformation( SYSTEM_INFORMATION_CLASS class,
case SystemTimeOfDayInformation: case SystemTimeOfDayInformation:
{ {
struct tm *tm;
time_t now;
SYSTEM_TIMEOFDAY_INFORMATION sti = {{{ 0 }}}; SYSTEM_TIMEOFDAY_INFORMATION sti = {{{ 0 }}};
/* liKeSystemTime, liExpTimeZoneBias, uCurrentTimeZoneId */ sti.BootTime.QuadPart = server_start_time;
sti.liKeBootTime.QuadPart = server_start_time; now = time( NULL );
tm = gmtime( &now );
sti.TimeZoneBias.QuadPart = mktime( tm ) - now;
tm = localtime( &now );
if (tm->tm_isdst) sti.TimeZoneBias.QuadPart -= 3600;
sti.TimeZoneBias.QuadPart *= TICKSPERSEC;
NtQuerySystemTime( &sti.SystemTime );
if (size <= sizeof(sti)) if (size <= sizeof(sti))
{ {

View File

@ -3275,7 +3275,7 @@ static WCHAR *get_lastbootuptime(void)
if (!(ret = heap_alloc( 26 * sizeof(WCHAR) ))) return NULL; if (!(ret = heap_alloc( 26 * sizeof(WCHAR) ))) return NULL;
NtQuerySystemInformation( SystemTimeOfDayInformation, &ti, sizeof(ti), NULL ); NtQuerySystemInformation( SystemTimeOfDayInformation, &ti, sizeof(ti), NULL );
RtlTimeToTimeFields( &ti.liKeBootTime, &tf ); RtlTimeToTimeFields( &ti.BootTime, &tf );
swprintf( ret, 26, L"%04u%02u%02u%02u%02u%02u.%06u+000", tf.Year, tf.Month, tf.Day, tf.Hour, tf.Minute, swprintf( ret, 26, L"%04u%02u%02u%02u%02u%02u.%06u+000", tf.Year, tf.Month, tf.Day, tf.Hour, tf.Minute,
tf.Second, tf.Milliseconds * 1000 ); tf.Second, tf.Milliseconds * 1000 );
return ret; return ret;

View File

@ -1482,10 +1482,10 @@ typedef struct _SYSTEM_PERFORMANCE_INFORMATION {
typedef struct _SYSTEM_TIMEOFDAY_INFORMATION { typedef struct _SYSTEM_TIMEOFDAY_INFORMATION {
#ifdef __WINESRC__ #ifdef __WINESRC__
LARGE_INTEGER liKeBootTime; LARGE_INTEGER BootTime;
LARGE_INTEGER liKeSystemTime; LARGE_INTEGER SystemTime;
LARGE_INTEGER liExpTimeZoneBias; LARGE_INTEGER TimeZoneBias;
ULONG uCurrentTimeZoneId; ULONG TimeZoneId;
ULONG Reserved; ULONG Reserved;
ULONGLONG BootTimeBias; ULONGLONG BootTimeBias;
ULONGLONG SleepTimeBias; ULONGLONG SleepTimeBias;

View File

@ -199,7 +199,7 @@ void PerfDataRefresh(void)
/* CurrentValue = NewValue - OldValue */ /* CurrentValue = NewValue - OldValue */
dbIdleTime = Li2Double(SysPerfInfo.IdleTime) - Li2Double(liOldIdleTime); dbIdleTime = Li2Double(SysPerfInfo.IdleTime) - Li2Double(liOldIdleTime);
dbKernelTime = CurrentKernelTime - OldKernelTime; dbKernelTime = CurrentKernelTime - OldKernelTime;
dbSystemTime = Li2Double(SysTimeInfo.liKeSystemTime) - Li2Double(liOldSystemTime); dbSystemTime = Li2Double(SysTimeInfo.SystemTime) - Li2Double(liOldSystemTime);
/* CurrentCpuIdle = IdleTime / SystemTime */ /* CurrentCpuIdle = IdleTime / SystemTime */
dbIdleTime = dbIdleTime / dbSystemTime; dbIdleTime = dbIdleTime / dbSystemTime;
@ -212,7 +212,7 @@ void PerfDataRefresh(void)
/* Store new CPU's idle and system time */ /* Store new CPU's idle and system time */
liOldIdleTime = SysPerfInfo.IdleTime; liOldIdleTime = SysPerfInfo.IdleTime;
liOldSystemTime = SysTimeInfo.liKeSystemTime; liOldSystemTime = SysTimeInfo.SystemTime;
OldKernelTime = CurrentKernelTime; OldKernelTime = CurrentKernelTime;
/* Determine the process count /* Determine the process count