pub struct KMutexGuard<'a, T> { /* private fields */ }
Expand description
A RAII scoped guard for the inner data protected by the mutex. Once this guard is given out, the protected data may be safely mutated by the caller as we guarantee exclusive access via Windows Kernel Mutex primitives.
When this structure is dropped (falls out of scope), the lock will be unlocked.
§IRQL
Access to the data within this guard must be done at <= APC_LEVEL if a non-alertable lock was acquired, or <= DISPATCH_LEVEL if an alertable lock was acquired. It is the callers responsible to manage APC levels whilst using the KMutex.
If you wish to manually drop the lock with a safety check, call the function Self::drop_safe
.
§Kernel panic
Raising the IRQL above safe limits whilst using the mutex will cause a Kernel Panic if not appropriately handled. When RAII drops this type, the mutex is released, if the mutex goes out of scope whilst you hold an IRQL that is too high, you will receive a kernel panic.
Implementations§
Source§impl<T> KMutexGuard<'_, T>
impl<T> KMutexGuard<'_, T>
Sourcepub fn drop_safe(&mut self) -> Result<(), DriverMutexError>
pub fn drop_safe(&mut self) -> Result<(), DriverMutexError>
Safely drop the KMutexGuard, an alternative to RAII.
This function checks the IRQL before attempting to drop the guard.
§Errors
If the IRQL > DISPATCH_LEVEL, no unlock will occur and a DriverMutexError will be returned to the caller.
§IRQL
This function is safe to call at any IRQL, but it will not release the mutex if IRQL > DISPATCH_LEVEL