ExIsResourceAcquiredSharedLite

This function tests whether the current thread has acquired a given Executive Resource for either exclusive or shared access.

Declaration

ULONG ExIsResourceAcquiredSharedLite (ERESOURCE *Resource);

in version 5.0 and higher, but

USHORT ExIsResourceAcquiredSharedLite (ERESOURCE *Resource);

in versions 3.50 to 4.0 inclusive.

Parameters

The Resource argument is the address of the ERESOURCE to test.

Return Value

The function returns the current thread’s acquisition count. This is the number of times the thread would have to release the resource (without reacquiring it) before losing access. If the current thread does not have access to the resource, whether exclusive or shared, then the function returns zero.

Availability

The ExIsResourceAcquiredSharedLite function is exported by name from the kernel in versions 3.50 and higher.

Documentation Status

The ExIsResourceAcquiredSharedLite function has plausibly always been documented. Certainly it is documented as early as the Device Driver Kit (DDK) for Windows NT 3.51. (No DDK for Windows NT 3.50 is available for reference.)

Note, however, that although the function’s declaration in NTDDK.H was updated for the change of return type in version 5.0, the documentation was not updated for it until the Windows Driver Kit (WDK) for Windows Vista. Documentation since the WDK for Windows 7 would have it that the function is “Available in Windows 2000 and later versions”.

Behaviour

The ExIsResourceAcquiredSharedLite function examines the given resource’s OWNER_ENTRY table, including its one or two built-in entries, while holding the resource’s spin lock. If the current thread is in the table, the function returns the corresponding count, else it returns zero.

The table is for all owners, both shared and exclusive. To this function, exclusive ownership is a particular kind of shared ownership.

Variations

The count, as the OwnerCount member in the OWNER_ENTRY structure, was widened from SHORT to LONG for version 5.0. It is not known why the count is signed in the structure but is returned by this function as unsigned. This difference was reconciled by a rearrangement of the structure for version 6.1, which reduced the count’s width in the structure to 30 bits while making it unsigned.

The ResourceIndex in the KTHREAD, which version 4.0 introduced to provide for remembering where a thread’s OWNER_ENTRY is in the owner table of the last resource the thread acquired, is not used for this function until version 5.0.

Version 6.0 is the first to treat exclusive ownership not just incidentally as a particular kind of shared ownership but as a special case.

Single-processor builds do not acquire and release the resource’s spin lock, even in the usual sense of just raising the IRQL to DISPATCH_LEVEL: they instead disable and re-enable interrupts.

IRQL

The ExIsResourceAcquiredShared function can be called at any IRQL up to and including DISPATCH_LEVEL. The Resource is assumed to be in non-paged memory.