Rework initial timer support

This commit is contained in:
Rafal Kupiec 2024-04-20 23:15:57 +02:00
parent 12ce7aae3f
commit 331c5bfeda
Signed by: belliash
GPG Key ID: 4E829243E0CFE6B4
6 changed files with 111 additions and 20 deletions

View File

@ -24,6 +24,10 @@ XTFASTCALL
VOID
KeAcquireSpinLock(IN OUT PKSPIN_LOCK SpinLock);
XTAPI
BOOLEAN
KeCancelTimer(IN PKTIMER Timer);
XTFASTCALL
KRUNLEVEL
KeGetCurrentRunLevel(VOID);
@ -63,12 +67,8 @@ KeInitializeThreadedDpc(IN PKDPC Dpc,
XTAPI
VOID
KeInitializeTimer(OUT PKTIMER Timer);
XTAPI
VOID
KeInitializeTimerEx(OUT PKTIMER Timer,
IN KTIMER_TYPE Type);
KeInitializeTimer(OUT PKTIMER Timer,
IN KTIMER_TYPE Type);
XTFASTCALL
VOID

View File

@ -17,6 +17,10 @@ XTAPI
VOID
KeClearEvent(IN PKEVENT Event);
XTAPI
VOID
KeClearTimer(IN PKTIMER Timer);
XTAPI
VOID
KeHaltSystem(VOID);
@ -78,6 +82,14 @@ XTAPI
VOID
KeStartXtSystem(IN PKERNEL_INITIALIZATION_BLOCK Parameters);
XTFASTCALL
VOID
KepExitDispatcher(IN KRUNLEVEL OldRunLevel);
XTAPI
VOID
KepRemoveTimer(IN OUT PKTIMER Timer);
XTFASTCALL
VOID
KepRetireDpcList(IN PKPROCESSOR_CONTROL_BLOCK Prcb);

View File

@ -113,7 +113,7 @@ KeInitializeThread(IN PKPROCESS Process,
KeInitializeSemaphore(&Thread->SuspendSemaphore, 0, 2);
/* Initialize the builtin timer */
KeInitializeTimer(&Thread->Timer);
KeInitializeTimer(&Thread->Timer, NotificationTimer);
TimerWaitBlock = &Thread->WaitBlock[KTIMER_WAIT_BLOCK];
TimerWaitBlock->Object = &Thread->Timer;
TimerWaitBlock->WaitKey = STATUS_TIMEOUT;
@ -194,6 +194,26 @@ KeStartThread(IN PKTHREAD Thread)
UNIMPLEMENTED;
}
/**
* Exits the dispatcher, switches context to a new thread and lowers runlevel to its original state.
*
* @param OldRunLevel
* Supplies the original runlevel state.
*
* @return This routine does not return any value.
*
* @since XT 1.0
*/
XTFASTCALL
VOID
KepExitDispatcher(IN KRUNLEVEL OldRunLevel)
{
UNIMPLEMENTED;
/* Lower runlevel */
KeLowerRunLevel(OldRunLevel);
}
/**
* Suspend APC-built thread NOP routine. It takes no actions.
*

View File

@ -10,21 +10,61 @@
/**
* Initializes a kernel timer.
* Cancels the timer.
*
* @param Timer
* Supplies a pointer to a time object.
* Supplies a pointer to a timer object.
*
* @return This routine does not return any value.
* @return This routine returns TRUE if the cancelled timer was set, or FALSE otherwise.
*
* @since NT 3.5
*/
XTAPI
VOID
KeInitializeTimer(OUT PKTIMER Timer)
BOOLEAN
KeCancelTimer(IN PKTIMER Timer)
{
/* Initialize the timer */
KeInitializeTimerEx(Timer, NotificationTimer);
BOOLEAN Result;
KRUNLEVEL OldRunLevel;
/* Set default result value */
Result = FALSE;
/* Raise run level and acquire dispatcher lock */
OldRunLevel = KeRaiseRunLevel(SYNC_LEVEL);
KeAcquireQueuedSpinLock(DispatcherLock);
/* Check timer status */
if(Timer->Header.Inserted)
{
/* Remove the timer from the list */
KepRemoveTimer(Timer);
Result = TRUE;
}
/* Release dispatcher lock and processes the deferred ready list */
KeReleaseQueuedSpinLock(DispatcherLock);
KepExitDispatcher(OldRunLevel);
/* Return result */
return Result;
}
/**
* Clears the signal state of the timer.
*
* @param Timer
* Supplies a pointer to a timer object.
*
* @return This routine does not return any value.
*
* @since NT 4.0
*/
XTAPI
VOID
KeClearTimer(IN PKTIMER Timer)
{
/* Clear signal state */
Timer->Header.SignalState = 0;
}
/**
@ -38,12 +78,12 @@ KeInitializeTimer(OUT PKTIMER Timer)
*
* @return This routine does not return any value.
*
* @since NT 3.5
* @since XT 1.0
*/
XTAPI
VOID
KeInitializeTimerEx(OUT PKTIMER Timer,
IN KTIMER_TYPE Type)
KeInitializeTimer(OUT PKTIMER Timer,
IN KTIMER_TYPE Type)
{
/* Initialize the header */
Timer->Header.Type = TimerNotificationObject + Type;
@ -58,3 +98,22 @@ KeInitializeTimerEx(OUT PKTIMER Timer,
RtlInitializeListHead(&Timer->Header.WaitListHead);
RtlInitializeListHead(&Timer->TimerListEntry);
}
/**
* Removes a specified timer from the timer list.
*
* @param Timer
* Supplies a pointer to a timer object.
*
* @return This routine does not return any value.
*
* @since XT 1.0
*/
XTAPI
VOID
KepRemoveTimer(IN OUT PKTIMER Timer)
{
/* Remove the timer from the list */
Timer->Header.Inserted = FALSE;
RtlRemoveEntryList(&Timer->TimerListEntry);
}

View File

@ -34,7 +34,7 @@ PoInitializeProcessorControlBlock(IN OUT PKPROCESSOR_CONTROL_BLOCK Prcb)
/* Initialize DPC and Timer */
KeInitializeDpc(&Prcb->PowerState.PerfDpc, PopPerfIdleDpc, Prcb);
KeSetTargetProcessorDpc(&Prcb->PowerState.PerfDpc, Prcb->Number);
KeInitializeTimerEx(&Prcb->PowerState.PerfTimer, SynchronizationTimer);
KeInitializeTimer(&Prcb->PowerState.PerfTimer, SynchronizationTimer);
}
/**

View File

@ -13,14 +13,14 @@
@ cdecl HlIoPortOutShort(ptr long)
@ fastcall KeAcquireQueuedSpinLock(long)
@ fastcall KeAcquireSpinLock(ptr)
@ stdcall KeCancelTimer(ptr)
@ fastcall KeGetCurrentRunLevel()
@ stdcall KeInitializeApc(ptr ptr long ptr ptr ptr long ptr)
@ stdcall KeInitializeDpc(ptr ptr ptr)
@ stdcall KeInitializeSemaphore(ptr long long)
@ stdcall KeInitializeSpinLock(ptr)
@ stdcall KeInitializeThreadedDpc(ptr ptr ptr)
@ stdcall KeInitializeTimer(ptr)
@ stdcall KeInitializeTimerEx(ptr long)
@ stdcall KeInitializeTimer(ptr long)
@ fastcall KeLowerRunLevel(long)
@ fastcall KeRaiseRunLevel(long)
@ stdcall KeReadSemaphoreState(ptr)