Files
reactos/sdk/lib/drivers/wdf/shared/support/fxspinlockapi.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

185 lines
4.2 KiB
C++

/*++
Copyright (c) Microsoft Corporation
Module Name:
FxSpinLockAPI.cpp
Abstract:
This module implements external APIS to access FxSpinLock
Author:
Environment:
Both kernel and user mode
Revision History:
--*/
#include "fxsupportpch.hpp"
#include "fxspinlock.hpp"
extern "C" {
// #include "FxSpinLockAPI.tmh"
}
//
// Extern the entire file
//
extern "C" {
_Must_inspect_result_
__drv_maxIRQL(DISPATCH_LEVEL)
NTSTATUS
NTAPI
WDFEXPORT(WdfSpinLockCreate)(
__in
PWDF_DRIVER_GLOBALS DriverGlobals,
__in_opt
PWDF_OBJECT_ATTRIBUTES SpinLockAttributes,
__out
WDFSPINLOCK* SpinLock
)
{
DDI_ENTRY();
PFX_DRIVER_GLOBALS pFxDriverGlobals;
NTSTATUS status;
FxSpinLock* pLock;
WDFSPINLOCK lock;
USHORT extra;
pFxDriverGlobals = GetFxDriverGlobals(DriverGlobals);
//
// Get the parent's globals if it is present
//
if (NT_SUCCESS(FxValidateObjectAttributesForParentHandle(
pFxDriverGlobals, SpinLockAttributes))) {
FxObject* pParent;
FxObjectHandleGetPtrAndGlobals(pFxDriverGlobals,
SpinLockAttributes->ParentObject,
FX_TYPE_OBJECT,
(PVOID*)&pParent,
&pFxDriverGlobals);
}
FxPointerNotNull(pFxDriverGlobals, SpinLock);
status = FxValidateObjectAttributes(pFxDriverGlobals, SpinLockAttributes);
if (!NT_SUCCESS(status)) {
return status;
}
if (pFxDriverGlobals->FxVerifierLock) {
extra = sizeof(FX_SPIN_LOCK_HISTORY);
}
else {
extra = 0;
}
*SpinLock = NULL;
pLock = new(pFxDriverGlobals, SpinLockAttributes, extra)
FxSpinLock(pFxDriverGlobals, extra);
if (pLock == NULL) {
return STATUS_INSUFFICIENT_RESOURCES;
}
status = pLock->Commit(SpinLockAttributes, (WDFOBJECT*)&lock);
if (NT_SUCCESS(status)) {
*SpinLock = lock;
}
else {
pLock->DeleteFromFailedCreate();
}
return status;
}
__drv_raisesIRQL(DISPATCH_LEVEL)
__drv_maxIRQL(DISPATCH_LEVEL)
VOID
NTAPI
WDFEXPORT(WdfSpinLockAcquire)(
__in
PWDF_DRIVER_GLOBALS DriverGlobals,
__in
__drv_savesIRQL
_Requires_lock_not_held_(_Curr_)
_Acquires_lock_(_Curr_)
WDFSPINLOCK SpinLock
)
{
DDI_ENTRY();
PFX_DRIVER_GLOBALS pFxDriverGlobals;
FxSpinLock* pLock;
FxObjectHandleGetPtrAndGlobals(GetFxDriverGlobals(DriverGlobals),
SpinLock,
FX_TYPE_SPIN_LOCK,
(PVOID*) &pLock,
&pFxDriverGlobals);
if (pLock->IsInterruptLock()) {
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGERROR,
"WDFSPINLOCK %p is associated with an interrupt, "
"cannot be used for normal sync operations",
SpinLock);
FxVerifierDbgBreakPoint(pFxDriverGlobals);
return;
}
pLock->AcquireLock(
pFxDriverGlobals->FxVerifierLock ? _ReturnAddress() : NULL);
}
__drv_maxIRQL(DISPATCH_LEVEL)
__drv_minIRQL(DISPATCH_LEVEL)
VOID
NTAPI
WDFEXPORT(WdfSpinLockRelease)(
__in
PWDF_DRIVER_GLOBALS DriverGlobals,
__in
__drv_restoresIRQL
_Requires_lock_held_(_Curr_)
_Releases_lock_(_Curr_)
WDFSPINLOCK SpinLock
)
{
DDI_ENTRY();
PFX_DRIVER_GLOBALS pFxDriverGlobals;
FxSpinLock* pLock;
FxObjectHandleGetPtrAndGlobals(GetFxDriverGlobals(DriverGlobals),
SpinLock,
FX_TYPE_SPIN_LOCK,
(PVOID*) &pLock,
&pFxDriverGlobals);
if (pLock->IsInterruptLock()) {
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGERROR,
"WDFSPINLOCK %p is associated with an interrupt, "
"cannot be used for normal sync operations",
SpinLock);
FxVerifierDbgBreakPoint(pFxDriverGlobals);
return;
}
pLock->ReleaseLock();
}
} // extern "C"