Update timers support

This commit is contained in:
Rafal Kupiec 2024-04-21 13:57:55 +02:00
parent 331c5bfeda
commit 30a2cb9849
Signed by: belliash
GPG Key ID: 4E829243E0CFE6B4
5 changed files with 108 additions and 4 deletions

View File

@ -32,6 +32,10 @@ XTFASTCALL
KRUNLEVEL KRUNLEVEL
KeGetCurrentRunLevel(VOID); KeGetCurrentRunLevel(VOID);
XTAPI
BOOLEAN
KeGetTimerState(IN PKTIMER Timer);
XTAPI XTAPI
VOID VOID
KeInitializeApc(IN PKAPC Apc, KeInitializeApc(IN PKAPC Apc,
@ -102,6 +106,13 @@ VOID
KeSetTargetProcessorDpc(IN PKDPC Dpc, KeSetTargetProcessorDpc(IN PKDPC Dpc,
IN CCHAR Number); IN CCHAR Number);
XTAPI
VOID
KeSetTimer(IN PKTIMER Timer,
IN LARGE_INTEGER DueTime,
IN LONG Period,
IN PKDPC Dpc);
XTAPI XTAPI
VOID VOID
KeSignalCallDpcDone(IN PVOID SystemArgument); KeSignalCallDpcDone(IN PVOID SystemArgument);

View File

@ -330,6 +330,7 @@ typedef struct _KTIMER
DISPATCHER_HEADER Header; DISPATCHER_HEADER Header;
ULARGE_INTEGER DueTime; ULARGE_INTEGER DueTime;
LIST_ENTRY TimerListEntry; LIST_ENTRY TimerListEntry;
PKDPC Dpc;
LONG Period; LONG Period;
} KTIMER, *PKTIMER; } KTIMER, *PKTIMER;

View File

@ -63,6 +63,10 @@ KePanicEx(IN ULONG Code,
IN ULONG_PTR Parameter3, IN ULONG_PTR Parameter3,
IN ULONG_PTR Parameter4); IN ULONG_PTR Parameter4);
XTAPI
ULONGLONG
KeQueryTimer(IN PKTIMER Timer);
XTAPI XTAPI
LONG LONG
KeSetEvent(IN PKEVENT Event, KeSetEvent(IN PKEVENT Event,

View File

@ -24,13 +24,13 @@ BOOLEAN
KeCancelTimer(IN PKTIMER Timer) KeCancelTimer(IN PKTIMER Timer)
{ {
BOOLEAN Result; BOOLEAN Result;
KRUNLEVEL OldRunLevel; KRUNLEVEL RunLevel;
/* Set default result value */ /* Set default result value */
Result = FALSE; Result = FALSE;
/* Raise run level and acquire dispatcher lock */ /* Raise run level and acquire dispatcher lock */
OldRunLevel = KeRaiseRunLevel(SYNC_LEVEL); RunLevel = KeRaiseRunLevel(SYNC_LEVEL);
KeAcquireQueuedSpinLock(DispatcherLock); KeAcquireQueuedSpinLock(DispatcherLock);
/* Check timer status */ /* Check timer status */
@ -41,9 +41,9 @@ KeCancelTimer(IN PKTIMER Timer)
Result = TRUE; Result = TRUE;
} }
/* Release dispatcher lock and processes the deferred ready list */ /* Release dispatcher lock and process the deferred ready list */
KeReleaseQueuedSpinLock(DispatcherLock); KeReleaseQueuedSpinLock(DispatcherLock);
KepExitDispatcher(OldRunLevel); KepExitDispatcher(RunLevel);
/* Return result */ /* Return result */
return Result; return Result;
@ -67,6 +67,24 @@ KeClearTimer(IN PKTIMER Timer)
Timer->Header.SignalState = 0; Timer->Header.SignalState = 0;
} }
/**
* Reads the current signal state of the given timer.
*
* @param Timer
* Supplies a pointer to a timer object.
*
* @return This routine returns TRUE if the timer is set, or FALSE otherwise.
*
* @since XT 1.0
*/
XTAPI
BOOLEAN
KeGetTimerState(IN PKTIMER Timer)
{
/* Return timer state */
return (BOOLEAN)Timer->Header.SignalState;
}
/** /**
* Initializes an extended kernel timer. * Initializes an extended kernel timer.
* *
@ -99,6 +117,74 @@ KeInitializeTimer(OUT PKTIMER Timer,
RtlInitializeListHead(&Timer->TimerListEntry); RtlInitializeListHead(&Timer->TimerListEntry);
} }
/**
* Queries the timer's interrupt due time.
*
* @param Timer
* Supplies a pointer to a timer object.
*
* @return This routine returns the time remaining on the timer, or 0 if the timer is not set.
*
* @since XT 1.0
*/
XTAPI
ULONGLONG
KeQueryTimer(IN PKTIMER Timer)
{
KRUNLEVEL RunLevel;
ULONGLONG DueTime;
/* Set initial due time */
DueTime = 0;
/* Raise run level and acquire dispatcher lock */
RunLevel = KeRaiseRunLevel(SYNC_LEVEL);
KeAcquireQueuedSpinLock(DispatcherLock);
/* Check timer status */
if(Timer->Header.Inserted)
{
/* Get timer's due time */
DueTime = Timer->DueTime.QuadPart;
}
/* Release dispatcher lock and process the deferred ready list */
KeReleaseQueuedSpinLock(DispatcherLock);
KepExitDispatcher(RunLevel);
/* Return timer's due time */
return DueTime;
}
/**
* Sets the supplied timer to expire at the specified time.
*
* @param Timer
* Supplies a pointer to a timer object.
*
* @param DueTime
* Supplies the time at which the timer should expire (both absolute and relative times are supported).
*
* @param Period
* Supplies the timer period.
*
* @param Dpc
* Supplies a pointer to a Deferred Procedure Call (DPC) object.
*
* @return This routine does not return any value.
*
* @since XT 1.0
*/
XTAPI
VOID
KeSetTimer(IN PKTIMER Timer,
IN LARGE_INTEGER DueTime,
IN LONG Period,
IN PKDPC Dpc)
{
UNIMPLEMENTED;
}
/** /**
* Removes a specified timer from the timer list. * Removes a specified timer from the timer list.
* *

View File

@ -15,6 +15,7 @@
@ fastcall KeAcquireSpinLock(ptr) @ fastcall KeAcquireSpinLock(ptr)
@ stdcall KeCancelTimer(ptr) @ stdcall KeCancelTimer(ptr)
@ fastcall KeGetCurrentRunLevel() @ fastcall KeGetCurrentRunLevel()
@ stdcall KeGetTimerState(ptr)
@ stdcall KeInitializeApc(ptr ptr long ptr ptr ptr long ptr) @ stdcall KeInitializeApc(ptr ptr long ptr ptr ptr long ptr)
@ stdcall KeInitializeDpc(ptr ptr ptr) @ stdcall KeInitializeDpc(ptr ptr ptr)
@ stdcall KeInitializeSemaphore(ptr long long) @ stdcall KeInitializeSemaphore(ptr long long)
@ -28,6 +29,7 @@
@ fastcall KeReleaseQueuedSpinLock(long) @ fastcall KeReleaseQueuedSpinLock(long)
@ fastcall KeReleaseSpinLock(ptr) @ fastcall KeReleaseSpinLock(ptr)
@ stdcall KeSetTargetProcessorDpc(ptr long) @ stdcall KeSetTargetProcessorDpc(ptr long)
@ stdcall KeSetTimer(ptr long long long ptr)
@ stdcall KeSignalCallDpcDone(ptr) @ stdcall KeSignalCallDpcDone(ptr)
@ stdcall KeSignalCallDpcSynchronize(ptr) @ stdcall KeSignalCallDpcSynchronize(ptr)
@ stdcall RtlClearAllBits(ptr) @ stdcall RtlClearAllBits(ptr)