[NTOSKRNL:CC] Add Lock Guard for DPC Level SPinlock

This commit is contained in:
Dibyamartanda Samanta 2024-11-01 14:44:28 +01:00 committed by CodingWorkshop Signing Team
parent 2472e39635
commit 377ff4fb9b
Signed by: CodingWorkshop Signing Team
GPG Key ID: 6DC88369C82795D2

View File

@ -105,6 +105,31 @@ private:
KIRQL m_OldIrql;
};
class QueuedSpinlockAtDPC {
public:
// Constructor to acquire the lock
explicit QueuedSpinlockAtDPC(KSPIN_LOCK_QUEUE_NUMBER lockNumber)
: m_lockNumber(lockNumber) {
// Acquire the lock at DPC level
m_lockHandle = KeAcquireQueuedSpinLockAtDpcLevel(&KeGetCurrentPrcb()->LockQueue[m_lockNumber]);
}
// Destructor to release the lock automatically
~QueuedSpinlockAtDPC() {
// Release the lock at DPC level
KeReleaseQueuedSpinLockFromDpcLevel(&KeGetCurrentPrcb()->LockQueue[m_lockNumber], m_lockHandle);
}
// Deleting copy and move constructors to prevent unintended copying
QueuedSpinlockAtDPC(const QueuedSpinlockAtDPC&) = delete;
QueuedSpinlockAtDPC& operator=(const QueuedSpinlockAtDPC&) = delete;
private:
KSPIN_LOCK_QUEUE_NUMBER m_lockNumber; // Spinlock queue number
KIRQL m_lockHandle; // Lock handle returned by KeAcquireQueuedSpinLockAtDpcLevel
};
template <typename T>
class Array {
public: