Files
reactos/sdk/lib/drivers/wdf/shared/support/fxwaitlockapi.cpp
T
3fe5b8b0bb [SDK][WDF][USBDEX][NTOSKRNL_VISTA] Fully enable KMDF (#8396)
[SDK][WDFLDR] Add kmdf loader driver
[SDK][WDF] Add kmdf drver init static library
[SDK][WDF] Modify kmdf driver for working with wdfldr driver
[SDK][CDROM] Cdrom driver dynamically linking with kmdf
[SDK][WDF] Add kmdfdriver module type
[SDK][WDF][USBDEX][NTOSKRNL_VISTA] Fully enable KMDF
[KMDF][WDFLDR][WDF01000] Fix Windows 10 Compatibility WDFLDR and WDF01000
[WDF01000] NO_KERNEL_LIST_ENTRY_CHECKS for wdf01000 3rd party code

This PR is an accumulation of three peoples work, with the goal of the trying to get WDF to work like it should.
This has been tested in combination with some extra NT6+ ntoskrnl against multiple drivers.

---------

Co-authored-by: Max Korostil <[email protected]>
Co-authored-by: Victor Perevertkin <[email protected]>
Co-authored-by: Adam Słaboń <[email protected]>
Co-authored-by: Hermès BÉLUSCA - MAÏTO <[email protected]>
2025-11-03 06:38:52 -08:00

188 lines
4.3 KiB
C++

/*++
Copyright (c) Microsoft Corporation
Module Name:
FxWaitLockAPI.cpp
Abstract:
This module implements the external APIs for FxWaitLock
Author:
Environment:
Both kernel and user mode
Revision History:
--*/
#include "fxsupportpch.hpp"
// extern the entire file
extern "C" {
_Must_inspect_result_
__drv_maxIRQL(DISPATCH_LEVEL)
NTSTATUS
WDFAPI
NTAPI
WDFEXPORT(WdfWaitLockCreate)(
__in
PWDF_DRIVER_GLOBALS DriverGlobals,
__in_opt
PWDF_OBJECT_ATTRIBUTES LockAttributes,
__out
WDFWAITLOCK* Lock
)
/*++
Routine Description:
Creates a lock object which can be acquired at PASSIVE_LEVEL and will return
to the caller at PASSIVE_LEVEL once acquired.
Arguments:
LockAttributes - generic attributes to be associated with the created lock
Lock - pointer to receive the newly created lock
Return Value:
NTSTATUS
--*/
{
DDI_ENTRY();
PFX_DRIVER_GLOBALS fxDriverGlobals;
NTSTATUS status;
FxObject* parent;
fxDriverGlobals = GetFxDriverGlobals(DriverGlobals);
parent = NULL;
//
// Get the parent's globals if it is present
//
if (NT_SUCCESS(FxValidateObjectAttributesForParentHandle(fxDriverGlobals,
LockAttributes))) {
FxObjectHandleGetPtrAndGlobals(fxDriverGlobals,
LockAttributes->ParentObject,
FX_TYPE_OBJECT,
(PVOID*)&parent,
&fxDriverGlobals);
}
FxPointerNotNull(fxDriverGlobals, Lock);
status = FxValidateObjectAttributes(fxDriverGlobals, LockAttributes);
if (!NT_SUCCESS(status)) {
return status;
}
return FxWaitLock::_Create(fxDriverGlobals,
LockAttributes,
parent,
TRUE,
Lock);
}
__drv_when(Timeout != 0, _Must_inspect_result_)
__drv_when(Timeout == 0, __drv_maxIRQL(PASSIVE_LEVEL))
__drv_when(Timeout != 0 && *Timeout == 0, __drv_maxIRQL(DISPATCH_LEVEL))
__drv_when(Timeout != 0 && *Timeout != 0, __drv_maxIRQL(PASSIVE_LEVEL))
NTSTATUS
WDFAPI
NTAPI
WDFEXPORT(WdfWaitLockAcquire)(
__in
PWDF_DRIVER_GLOBALS DriverGlobals,
__in
WDFWAITLOCK Lock,
__in_opt
PLONGLONG Timeout
)
/*++
Routine Description:
Attempts to acquire the lock object. If a non NULL timeout is provided, the
attempt to acquire the lock may fail if it cannot be acquired in the
specified time.
Arguments:
Lock - the lock to acquire
Timeout - optional timeout in acquiring the lock. If calling at an IRQL >=
DISPATCH_LEVEL, then this parameter is not NULL (and should more
then likely be zero)
Return Value:
STATUS_TIMEOUT if a timeout was provided and the lock could not be acquired
in the specified time, otherwise STATUS_SUCCESS
--*/
{
DDI_ENTRY();
PFX_DRIVER_GLOBALS pFxDriverGlobals;
FxWaitLock* pLock;
NTSTATUS status;
FxObjectHandleGetPtrAndGlobals(GetFxDriverGlobals(DriverGlobals),
Lock,
FX_TYPE_WAIT_LOCK,
(PVOID*) &pLock,
&pFxDriverGlobals);
if (Timeout == NULL || *Timeout != 0) {
status = FxVerifierCheckIrqlLevel(pFxDriverGlobals, PASSIVE_LEVEL);
if (!NT_SUCCESS(status)) {
return status;
}
}
return pLock->AcquireLock(pFxDriverGlobals, Timeout);
}
__drv_maxIRQL(DISPATCH_LEVEL)
VOID
WDFAPI
NTAPI
WDFEXPORT(WdfWaitLockRelease)(
__in
PWDF_DRIVER_GLOBALS DriverGlobals,
__in
WDFWAITLOCK Lock
)
/*++
Routine Description:
Releases a previously acquired wait lock
Arguments:
Lock - the lock to release
--*/
{
DDI_ENTRY();
PFX_DRIVER_GLOBALS pFxDriverGlobals;
FxWaitLock* pLock;
FxObjectHandleGetPtrAndGlobals(GetFxDriverGlobals(DriverGlobals),
Lock,
FX_TYPE_WAIT_LOCK,
(PVOID*) &pLock,
&pFxDriverGlobals);
pLock->ReleaseLock(pFxDriverGlobals);
}
} // extern "C"