forked from xt-sys/exectos
Add guarded region support
This commit is contained in:
@@ -24,6 +24,8 @@ namespace KE
|
||||
STATIC XTAPI VOID AttachThread(IN PKTHREAD Thread);
|
||||
STATIC XTFASTCALL VOID EnterCriticalRegion();
|
||||
STATIC XTFASTCALL VOID EnterCriticalRegion(IN PKTHREAD Thread);
|
||||
STATIC XTFASTCALL VOID EnterGuardedRegion();
|
||||
STATIC XTFASTCALL VOID EnterGuardedRegion(IN PKTHREAD Thread);
|
||||
STATIC XTAPI PETHREAD GetInitialThread(VOID);
|
||||
STATIC XTAPI XTSTATUS InitializeIdleThread(IN PKPROCESS IdleProcess,
|
||||
IN OUT PKTHREAD IdleThread,
|
||||
@@ -40,6 +42,8 @@ namespace KE
|
||||
IN BOOLEAN AttachToProcess);
|
||||
STATIC XTFASTCALL VOID LeaveCriticalRegion();
|
||||
STATIC XTFASTCALL VOID LeaveCriticalRegion(IN PKTHREAD Thread);
|
||||
STATIC XTFASTCALL VOID LeaveGuardedRegion();
|
||||
STATIC XTFASTCALL VOID LeaveGuardedRegion(IN PKTHREAD Thread);
|
||||
|
||||
private:
|
||||
STATIC XTAPI VOID HandleSystemThreadExit(VOID);
|
||||
|
||||
@@ -111,6 +111,42 @@ KE::KThread::EnterCriticalRegion(IN PKTHREAD Thread)
|
||||
AR::CpuFunctions::ReadWriteBarrier();
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables the delivery of special APCs for the current thread.
|
||||
*
|
||||
* @return This routine does not return any value.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTFASTCALL
|
||||
VOID
|
||||
KE::KThread::EnterGuardedRegion()
|
||||
{
|
||||
/* Prevent the thread from being preempted by an APC */
|
||||
EnterGuardedRegion(KE::Processor::GetCurrentThread());
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables the delivery of special APCs for the specified thread.
|
||||
*
|
||||
* @param Thread
|
||||
* Supplies a pointer to the thread object whose APC delivery is to be disabled.
|
||||
*
|
||||
* @return This routine does not return any value.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTFASTCALL
|
||||
VOID
|
||||
KE::KThread::EnterGuardedRegion(IN PKTHREAD Thread)
|
||||
{
|
||||
/* Disable Special APCs */
|
||||
Thread->SpecialApcDisable--;
|
||||
|
||||
/* Prevent the compiler from reordering code */
|
||||
AR::CpuFunctions::ReadWriteBarrier();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a pointer to the system's initial executive thread object.
|
||||
*
|
||||
@@ -437,6 +473,57 @@ KE::KThread::LeaveCriticalRegion(IN PKTHREAD Thread)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-enables the delivery of special APCs for the current thread.
|
||||
*
|
||||
* @return This routine does not return any value.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTFASTCALL
|
||||
VOID
|
||||
KE::KThread::LeaveGuardedRegion()
|
||||
{
|
||||
/* Allow APCs to preempt the thread */
|
||||
LeaveGuardedRegion(KE::Processor::GetCurrentThread());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Re-enables the delivery of special APCs for the specified thread.
|
||||
*
|
||||
* @param Thread
|
||||
* Supplies a pointer to the thread object whose APC delivery is to be re-enabled.
|
||||
*
|
||||
* @return This routine does not return any value.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTFASTCALL
|
||||
VOID
|
||||
KE::KThread::LeaveGuardedRegion(IN PKTHREAD Thread)
|
||||
{
|
||||
/* Ensure the compiler does not reorder code */
|
||||
AR::CpuFunctions::ReadWriteBarrier();
|
||||
|
||||
/* Re-enable APC delivery */
|
||||
Thread->SpecialApcDisable++;
|
||||
|
||||
/* Check if APC delivery is enabled */
|
||||
if(!Thread->SpecialApcDisable)
|
||||
{
|
||||
/* Memory barrier */
|
||||
AR::CpuFunctions::MemoryBarrier();
|
||||
|
||||
/* Check for any pending kernel APCs */
|
||||
if(!RTL::LinkedList::ListEmpty(&Thread->ApcState.ApcListHead[KernelMode]))
|
||||
{
|
||||
/* Initiate delivery of the pending APCs */
|
||||
KE::Apc::CheckApcDelivery();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Suspend APC-built thread NOP routine. It takes no actions.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user