Skip to content

Commit

Permalink
ntdll: Return the current time and timezone bias in NtQuerySystemInfo…
Browse files Browse the repository at this point in the history
…rmation(SystemTimeOfDayInformation).

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
  • Loading branch information
julliard committed Jun 25, 2020
1 parent c031662 commit 7161dcd
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 53 deletions.
50 changes: 6 additions & 44 deletions dlls/ntdll/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,44 +228,6 @@ BOOLEAN WINAPI RtlTimeFieldsToTime(
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.@]
Expand All @@ -283,12 +245,12 @@ static LONG TIME_GetBias(void)
NTSTATUS WINAPI RtlLocalTimeToSystemTime( const LARGE_INTEGER *LocalTime,
PLARGE_INTEGER SystemTime)
{
LONG bias;
SYSTEM_TIMEOFDAY_INFORMATION info;

TRACE("(%p, %p)\n", LocalTime, SystemTime);

bias = TIME_GetBias();
SystemTime->QuadPart = LocalTime->QuadPart + bias * (LONGLONG)TICKSPERSEC;
NtQuerySystemInformation( SystemTimeOfDayInformation, &info, sizeof(info), NULL );
SystemTime->QuadPart = LocalTime->QuadPart + info.TimeZoneBias.QuadPart;
return STATUS_SUCCESS;
}

Expand All @@ -308,12 +270,12 @@ NTSTATUS WINAPI RtlLocalTimeToSystemTime( const LARGE_INTEGER *LocalTime,
NTSTATUS WINAPI RtlSystemTimeToLocalTime( const LARGE_INTEGER *SystemTime,
PLARGE_INTEGER LocalTime )
{
LONG bias;
SYSTEM_TIMEOFDAY_INFORMATION info;

TRACE("(%p, %p)\n", SystemTime, LocalTime);

bias = TIME_GetBias();
LocalTime->QuadPart = SystemTime->QuadPart - bias * (LONGLONG)TICKSPERSEC;
NtQuerySystemInformation( SystemTimeOfDayInformation, &info, sizeof(info), NULL );
LocalTime->QuadPart = SystemTime->QuadPart - info.TimeZoneBias.QuadPart;
return STATUS_SUCCESS;
}

Expand Down
12 changes: 10 additions & 2 deletions dlls/ntdll/unix/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -1690,10 +1690,18 @@ NTSTATUS WINAPI NtQuerySystemInformation( SYSTEM_INFORMATION_CLASS class,

case SystemTimeOfDayInformation:
{
struct tm *tm;
time_t now;
SYSTEM_TIMEOFDAY_INFORMATION sti = {{{ 0 }}};

/* liKeSystemTime, liExpTimeZoneBias, uCurrentTimeZoneId */
sti.liKeBootTime.QuadPart = server_start_time;
sti.BootTime.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))
{
Expand Down
2 changes: 1 addition & 1 deletion dlls/wbemprox/builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -3275,7 +3275,7 @@ static WCHAR *get_lastbootuptime(void)
if (!(ret = heap_alloc( 26 * sizeof(WCHAR) ))) return 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,
tf.Second, tf.Milliseconds * 1000 );
return ret;
Expand Down
8 changes: 4 additions & 4 deletions include/winternl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1482,10 +1482,10 @@ typedef struct _SYSTEM_PERFORMANCE_INFORMATION {

typedef struct _SYSTEM_TIMEOFDAY_INFORMATION {
#ifdef __WINESRC__
LARGE_INTEGER liKeBootTime;
LARGE_INTEGER liKeSystemTime;
LARGE_INTEGER liExpTimeZoneBias;
ULONG uCurrentTimeZoneId;
LARGE_INTEGER BootTime;
LARGE_INTEGER SystemTime;
LARGE_INTEGER TimeZoneBias;
ULONG TimeZoneId;
ULONG Reserved;
ULONGLONG BootTimeBias;
ULONGLONG SleepTimeBias;
Expand Down
4 changes: 2 additions & 2 deletions programs/taskmgr/perfdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ void PerfDataRefresh(void)
/* CurrentValue = NewValue - OldValue */
dbIdleTime = Li2Double(SysPerfInfo.IdleTime) - Li2Double(liOldIdleTime);
dbKernelTime = CurrentKernelTime - OldKernelTime;
dbSystemTime = Li2Double(SysTimeInfo.liKeSystemTime) - Li2Double(liOldSystemTime);
dbSystemTime = Li2Double(SysTimeInfo.SystemTime) - Li2Double(liOldSystemTime);

/* CurrentCpuIdle = IdleTime / SystemTime */
dbIdleTime = dbIdleTime / dbSystemTime;
Expand All @@ -212,7 +212,7 @@ void PerfDataRefresh(void)

/* Store new CPU's idle and system time */
liOldIdleTime = SysPerfInfo.IdleTime;
liOldSystemTime = SysTimeInfo.liKeSystemTime;
liOldSystemTime = SysTimeInfo.SystemTime;
OldKernelTime = CurrentKernelTime;

/* Determine the process count
Expand Down

0 comments on commit 7161dcd

Please sign in to comment.