[KS] Use KeQueryTickCount for timeouts instead of KeQuerySystemTime

This avoids overflow when system time is changed between calls (for example, via NTP)
This commit is contained in:
Victor Perevertkin 2019-12-16 02:28:41 +03:00
parent 7908e2e41f
commit 1d9e03b708
No known key found for this signature in database
GPG key ID: C750B7222E9C7830

View file

@ -77,7 +77,7 @@ KspCreatePDO(
DeviceEntry->DeviceState = NotStarted;
/* get current time */
KeQuerySystemTime(&DeviceEntry->TimeCreated);
KeQueryTickCount(&DeviceEntry->TimeCreated);
/* setup flags */
DeviceObject->Flags |= DO_POWER_PAGABLE;
@ -807,7 +807,7 @@ KspStartBusDevice(
DeviceEntry->DeviceState = Started;
/* reference start time */
KeQuerySystemTime(&DeviceEntry->TimeCreated);
KeQueryTickCount(&DeviceEntry->TimeCreated);
DPRINT1("KspStartBusDevice Name %S DeviceName %S Instance %S Started\n", Name, DeviceEntry->DeviceName, DeviceEntry->Instance);
@ -1193,7 +1193,7 @@ KspBusWorkerRoutine(
KeAcquireSpinLock(&BusDeviceExtension->Lock, &OldLevel);
/* get current time */
KeQuerySystemTime(&Time);
KeQueryTickCount(&Time);
/* enumerate all device entries */
Entry = BusDeviceExtension->Common.Entry.Flink;
@ -1211,14 +1211,20 @@ KspBusWorkerRoutine(
{
if (DeviceEntry->DeviceState == NotStarted)
{
Diff.QuadPart = Time.QuadPart - DeviceEntry->TimeCreated.QuadPart;
Diff.QuadPart = (Time.QuadPart - DeviceEntry->TimeCreated.QuadPart) * KeQueryTimeIncrement();
/* wait for 15 sec */
if (Diff.QuadPart > Int32x32To64(15000, 10000))
{
/* release spin lock */
KeReleaseSpinLock(&BusDeviceExtension->Lock, OldLevel);
DPRINT1("DeviceID %S Instance %S TimeCreated %I64u Now %I64u Diff %I64u hung\n", DeviceEntry->DeviceName, DeviceEntry->Instance, DeviceEntry->TimeCreated.QuadPart, Time.QuadPart, Diff.QuadPart);
DPRINT1("DeviceID %S Instance %S TimeCreated %I64u Now %I64u Diff %I64u hung\n",
DeviceEntry->DeviceName,
DeviceEntry->Instance,
DeviceEntry->TimeCreated.QuadPart * KeQueryTimeIncrement(),
Time.QuadPart * KeQueryTimeIncrement(),
Diff.QuadPart);
/* deactivate interfaces */
//KspEnableBusDeviceInterface(DeviceEntry, FALSE);