KeEnterCriticalRegion function (wdm.h)

The KeEnterCriticalRegion routine temporarily disables the execution of normal kernel APCs, but does not prevent special kernel APCs from running.

Syntax

void KeEnterCriticalRegion();

Return value

None

Remarks

A driver calls this routine to enter a critical region in which the execution of normal kernel APCs is deferred until this driver exits the critical region by calling the KeLeaveCriticalRegion routine. Any caller of KeEnterCriticalRegion should call KeLeaveCriticalRegion as quickly as possible after entering a critical region.

Highest-level drivers can call KeEnterCriticalRegion while running in the context of the thread that requested the current I/O operation.

A thread that is inside a critical region has both user APCs and normal kernel APCs disabled, but not special kernel APCs. For more information about these APC types, see Types of APCs.

Critical regions can be entered recursively and each call to KeEnterCriticalRegion must have a matching call to KeLeaveCriticalRegion.

A driver can use a critical region to acquire and release exclusive access to a shared resource. In this case, the ExEnterCriticalRegionAndAcquireResourceExclusive and ExReleaseResourceAndLeaveCriticalRegion routines can be used instead of the KeEnterCriticalRegion and KeLeaveCriticalRegion routines. For more information, see the code example in ExEnterCriticalRegionAndAcquireResourceExclusive.

For more information about APCs, see Asynchronous Procedure Calls.

Requirements

Requirement Value
Minimum supported client Available starting with Windows 2000.
Target Platform Universal
Header wdm.h (include Wdm.h, Ntddk.h, Ntifs.h)
Library NtosKrnl.lib
DLL NtosKrnl.exe
IRQL <= APC_LEVEL
DDI compliance rules CriticalRegions(wdm), HwStorPortProhibitedDDIs(storport), IrqlKeApcLte2(wdm), WithinCriticalRegion(storport), WithinCriticalRegion(storport), WithinCriticalRegion(wdm)

See also

ExEnterCriticalRegionAndAcquireResourceExclusive

ExReleaseResourceAndLeaveCriticalRegion

KeAreApcsDisabled

KeLeaveCriticalRegion