Add RAII guard for kernel guarded regions

This commit is contained in:
2026-08-06 16:07:17 +02:00
parent 7e66630c1b
commit 577621e082

View File

@@ -53,6 +53,40 @@ namespace KE
CriticalRegionGuard& operator=(const CriticalRegionGuard&) = delete; CriticalRegionGuard& operator=(const CriticalRegionGuard&) = delete;
}; };
class GuardedRegionGuard
{
private:
BOOLEAN Owned;
PKTHREAD SystemThread;
public:
GuardedRegionGuard(IN PKTHREAD Thread = NULLPTR,
IN BOOLEAN Acquire = TRUE)
{
Owned = Acquire;
SystemThread = Thread;
if(Owned)
{
if(!SystemThread)
{
SystemThread = KE::Processor::GetCurrentThread();
}
KE::KThread::EnterGuardedRegion(SystemThread);
}
}
~GuardedRegionGuard()
{
if(Owned)
{
KE::KThread::LeaveGuardedRegion(SystemThread);
}
}
GuardedRegionGuard(const GuardedRegionGuard&) = delete;
GuardedRegionGuard& operator=(const GuardedRegionGuard&) = delete;
};
class PushLockExclusiveGuard class PushLockExclusiveGuard
{ {
private: private: