diff --git a/NTOSKRNL/CC/ccinternal.hpp b/NTOSKRNL/CC/ccinternal.hpp index 94a0e72..ee6e29b 100644 --- a/NTOSKRNL/CC/ccinternal.hpp +++ b/NTOSKRNL/CC/ccinternal.hpp @@ -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 class Array { public: