Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions include/wil/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -6845,7 +6845,8 @@ namespace details
}

_IRQL_requires_(DISPATCH_LEVEL)
static void Release(_In_ _IRQL_restores_ const kspin_lock_saved_irql& spinLockSavedIrql)
_IRQL_restores_global_(savedIrql, spinLockSavedIrql)
static void Release(_In_ const kspin_lock_saved_irql& spinLockSavedIrql)
{
KeReleaseSpinLock(spinLockSavedIrql.spinLock, spinLockSavedIrql.savedIrql);
}
Expand All @@ -6869,7 +6870,7 @@ using kspin_lock_at_dpc_guard =

WI_NODISCARD
inline _IRQL_requires_max_(DISPATCH_LEVEL)
_IRQL_saves_
_IRQL_saves_global_(savedIrql, return)
_IRQL_raises_(DISPATCH_LEVEL)
kspin_lock_guard acquire_kspin_lock(_In_ PKSPIN_LOCK spinLock)
{
Expand Down Expand Up @@ -6905,7 +6906,7 @@ class kernel_spin_lock

WI_NODISCARD
_IRQL_requires_max_(DISPATCH_LEVEL)
_IRQL_saves_
_IRQL_saves_global_(savedIrql, return)
_IRQL_raises_(DISPATCH_LEVEL)
kspin_lock_guard acquire() WI_NOEXCEPT
{
Expand Down Expand Up @@ -7013,6 +7014,8 @@ using fast_mutex_guard = unique_any<FAST_MUTEX*, decltype(::ExReleaseFastMutex),

WI_NODISCARD
inline _IRQL_requires_max_(APC_LEVEL)
_IRQL_raises_(APC_LEVEL)
_IRQL_saves_global_(OldIrql, return)
fast_mutex_guard acquire_fast_mutex(FAST_MUTEX* fastMutex) WI_NOEXCEPT
{
::ExAcquireFastMutex(fastMutex);
Expand All @@ -7021,6 +7024,8 @@ fast_mutex_guard acquire_fast_mutex(FAST_MUTEX* fastMutex) WI_NOEXCEPT

WI_NODISCARD
inline _IRQL_requires_max_(APC_LEVEL)
_IRQL_raises_(APC_LEVEL)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ExTryToAcquire... only raises to APC_LEVEL if it acquired the mutex. See https://learn.microsoft.com/en-us/windows-hardware/drivers/devtest/irql-annotations-for-drivers and https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/wdm/nf-wdm-extrytoacquirefastmutex .. This probably needs a When() in here, like:

_When_(return, _IRQL_raises_(APC_LEVEL) _IRQ_saves_global_(OldIrql, return))

Not sure how to have the return peek into the returned object to see if it's active or not.

_IRQL_saves_global_(OldIrql, fastMutex)
fast_mutex_guard try_acquire_fast_mutex(FAST_MUTEX* fastMutex) WI_NOEXCEPT
{
if (::ExTryToAcquireFastMutex(fastMutex))
Expand Down Expand Up @@ -7053,6 +7058,8 @@ class fast_mutex
// destruction.
WI_NODISCARD
_IRQL_requires_max_(APC_LEVEL)
_IRQL_raises_(APC_LEVEL)
_IRQL_saves_global_(OldIrql, return)
fast_mutex_guard acquire() WI_NOEXCEPT
{
return acquire_fast_mutex(&m_fastMutex);
Expand All @@ -7062,6 +7069,8 @@ class fast_mutex
// calls ExReleaseFastMutex on destruction.
WI_NODISCARD
_IRQL_requires_max_(APC_LEVEL)
_IRQL_raises_(APC_LEVEL)
_IRQL_saves_global_(OldIrql, return)
fast_mutex_guard try_acquire() WI_NOEXCEPT
{
return try_acquire_fast_mutex(&m_fastMutex);
Expand Down