mirror of
https://github.com/ApfelTeeSaft/reactos.git
synced 2026-08-27 19:25:36 +00:00
[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]>
390 lines
8.8 KiB
C++
390 lines
8.8 KiB
C++
/*++
|
|
|
|
Copyright (c) Microsoft Corporation
|
|
|
|
Module Name:
|
|
|
|
FxCollectionApi.cpp
|
|
|
|
Abstract:
|
|
|
|
This module implements the "C" interface to the collection object.
|
|
|
|
Author:
|
|
|
|
|
|
|
|
Environment:
|
|
|
|
Both kernel and user mode
|
|
|
|
Revision History:
|
|
|
|
--*/
|
|
|
|
#include "fxsupportpch.hpp"
|
|
|
|
extern "C" {
|
|
// #include "FxCollectionApi.tmh"
|
|
}
|
|
|
|
//
|
|
// Extern the entire file
|
|
//
|
|
extern "C" {
|
|
_Must_inspect_result_
|
|
__drv_maxIRQL(DISPATCH_LEVEL)
|
|
NTSTATUS
|
|
NTAPI
|
|
WDFEXPORT(WdfCollectionCreate)(
|
|
__in
|
|
PWDF_DRIVER_GLOBALS DriverGlobals,
|
|
__in_opt
|
|
PWDF_OBJECT_ATTRIBUTES CollectionAttributes,
|
|
__out
|
|
WDFCOLLECTION *Collection
|
|
)
|
|
{
|
|
DDI_ENTRY();
|
|
|
|
PFX_DRIVER_GLOBALS pFxDriverGlobals;
|
|
NTSTATUS status;
|
|
FxCollection *pCollection;
|
|
WDFCOLLECTION hCol;
|
|
|
|
pFxDriverGlobals = GetFxDriverGlobals(DriverGlobals);
|
|
|
|
//
|
|
// Get the parent's globals if it is present
|
|
//
|
|
if (NT_SUCCESS(FxValidateObjectAttributesForParentHandle(
|
|
pFxDriverGlobals, CollectionAttributes))) {
|
|
FxObject* pParent;
|
|
|
|
FxObjectHandleGetPtrAndGlobals(pFxDriverGlobals,
|
|
CollectionAttributes->ParentObject,
|
|
FX_TYPE_OBJECT,
|
|
(PVOID*)&pParent,
|
|
&pFxDriverGlobals);
|
|
}
|
|
|
|
FxPointerNotNull(pFxDriverGlobals, Collection);
|
|
|
|
*Collection = NULL;
|
|
|
|
status = FxValidateObjectAttributes(pFxDriverGlobals, CollectionAttributes);
|
|
if (!NT_SUCCESS(status)) {
|
|
return status;
|
|
}
|
|
|
|
pCollection = new (pFxDriverGlobals, CollectionAttributes)
|
|
FxCollection(pFxDriverGlobals);
|
|
|
|
if (pCollection != NULL) {
|
|
status = pCollection->Commit(CollectionAttributes, (WDFOBJECT*)&hCol);
|
|
|
|
if (NT_SUCCESS(status)) {
|
|
*Collection = hCol;
|
|
}
|
|
else {
|
|
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGERROR,
|
|
"Could not create collection object: %!STATUS!",
|
|
status);
|
|
|
|
pCollection->DeleteFromFailedCreate();
|
|
}
|
|
}
|
|
else {
|
|
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGERROR,
|
|
"Could not create collection object: "
|
|
"STATUS_INSUFFICIENT_RESOURCES" );
|
|
status = STATUS_INSUFFICIENT_RESOURCES;
|
|
}
|
|
|
|
return status;
|
|
}
|
|
|
|
__drv_maxIRQL(DISPATCH_LEVEL)
|
|
ULONG
|
|
NTAPI
|
|
WDFEXPORT(WdfCollectionGetCount)(
|
|
__in
|
|
PWDF_DRIVER_GLOBALS DriverGlobals,
|
|
__in
|
|
WDFCOLLECTION Collection
|
|
)
|
|
{
|
|
DDI_ENTRY();
|
|
|
|
FxCollection *pCollection;
|
|
KIRQL irql;
|
|
ULONG count;
|
|
|
|
FxObjectHandleGetPtr(GetFxDriverGlobals(DriverGlobals),
|
|
Collection,
|
|
FX_TYPE_COLLECTION,
|
|
(PVOID *)&pCollection);
|
|
|
|
pCollection->Lock(&irql);
|
|
count = pCollection->Count();
|
|
pCollection->Unlock(irql);
|
|
|
|
return count;
|
|
}
|
|
|
|
_Must_inspect_result_
|
|
__drv_maxIRQL(DISPATCH_LEVEL)
|
|
NTSTATUS
|
|
NTAPI
|
|
WDFEXPORT(WdfCollectionAdd)(
|
|
__in
|
|
PWDF_DRIVER_GLOBALS DriverGlobals,
|
|
__in
|
|
WDFCOLLECTION Collection,
|
|
__in
|
|
WDFOBJECT Object
|
|
)
|
|
{
|
|
DDI_ENTRY();
|
|
|
|
PFX_DRIVER_GLOBALS pFxDriverGlobals;
|
|
FxCollection *pCollection;
|
|
FxObject *pObject;
|
|
NTSTATUS status;
|
|
KIRQL irql;
|
|
|
|
FxObjectHandleGetPtrAndGlobals(GetFxDriverGlobals(DriverGlobals),
|
|
Collection,
|
|
FX_TYPE_COLLECTION,
|
|
(PVOID*) &pCollection,
|
|
&pFxDriverGlobals);
|
|
|
|
FxObjectHandleGetPtr(pFxDriverGlobals,
|
|
Object,
|
|
FX_TYPE_OBJECT,
|
|
(PVOID*) &pObject);
|
|
|
|
pCollection->Lock(&irql);
|
|
status = pCollection->Add(pObject) ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL;
|
|
pCollection->Unlock(irql);
|
|
|
|
return status;
|
|
}
|
|
|
|
__drv_maxIRQL(DISPATCH_LEVEL)
|
|
VOID
|
|
NTAPI
|
|
WDFEXPORT(WdfCollectionRemoveItem)(
|
|
__in
|
|
PWDF_DRIVER_GLOBALS DriverGlobals,
|
|
__in
|
|
WDFCOLLECTION Collection,
|
|
__in
|
|
ULONG Index
|
|
)
|
|
{
|
|
DDI_ENTRY();
|
|
|
|
PFX_DRIVER_GLOBALS pFxDriverGlobals;
|
|
FxCollection* pCollection;
|
|
FxCollectionEntry* pEntry;
|
|
FxObject* pObject;
|
|
NTSTATUS status;
|
|
KIRQL irql;
|
|
|
|
FxObjectHandleGetPtrAndGlobals(GetFxDriverGlobals(DriverGlobals),
|
|
Collection,
|
|
FX_TYPE_COLLECTION,
|
|
(PVOID*) &pCollection,
|
|
&pFxDriverGlobals);
|
|
|
|
pCollection->Lock(&irql);
|
|
|
|
pEntry = pCollection->FindEntry(Index);
|
|
|
|
if (pEntry != NULL) {
|
|
pObject = pEntry->m_Object;
|
|
pCollection->CleanupEntry(pEntry);
|
|
status = STATUS_SUCCESS;
|
|
}
|
|
else {
|
|
pObject = NULL;
|
|
status = STATUS_NOT_FOUND;
|
|
}
|
|
|
|
pCollection->Unlock(irql);
|
|
|
|
if (pObject != NULL) {
|
|
pCollection->CleanupEntryObject(pObject);
|
|
}
|
|
|
|
if (!NT_SUCCESS(status)) {
|
|
DoTraceLevelMessage(
|
|
pFxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGERROR,
|
|
"Index %d is not valid in WDFCOLLECTION %p (count is %d), %!STATUS!",
|
|
Index, Collection, pCollection->Count(), status);
|
|
FxVerifierDbgBreakPoint(pFxDriverGlobals);
|
|
}
|
|
}
|
|
|
|
__drv_maxIRQL(DISPATCH_LEVEL)
|
|
VOID
|
|
NTAPI
|
|
WDFEXPORT(WdfCollectionRemove)(
|
|
__in
|
|
PWDF_DRIVER_GLOBALS DriverGlobals,
|
|
__in
|
|
WDFCOLLECTION Collection,
|
|
__in
|
|
WDFOBJECT Item
|
|
)
|
|
{
|
|
DDI_ENTRY();
|
|
|
|
PFX_DRIVER_GLOBALS pFxDriverGlobals;
|
|
FxCollection *pCollection;
|
|
FxCollectionEntry *pEntry;
|
|
FxObject* pObject;
|
|
NTSTATUS status;
|
|
KIRQL irql;
|
|
|
|
FxObjectHandleGetPtrAndGlobals(GetFxDriverGlobals(DriverGlobals),
|
|
Collection,
|
|
FX_TYPE_COLLECTION,
|
|
(PVOID*) &pCollection,
|
|
&pFxDriverGlobals);
|
|
|
|
FxObjectHandleGetPtr(pFxDriverGlobals,
|
|
Item,
|
|
FX_TYPE_OBJECT,
|
|
(PVOID*) &pObject);
|
|
|
|
pCollection->Lock(&irql);
|
|
|
|
pEntry = pCollection->FindEntryByObject(pObject);
|
|
|
|
if (pEntry != NULL) {
|
|
pCollection->CleanupEntry(pEntry);
|
|
status = STATUS_SUCCESS;
|
|
}
|
|
else {
|
|
pObject = NULL;
|
|
status = STATUS_NOT_FOUND;
|
|
}
|
|
|
|
pCollection->Unlock(irql);
|
|
|
|
if (pObject != NULL) {
|
|
pCollection->CleanupEntryObject(pObject);
|
|
}
|
|
|
|
if (!NT_SUCCESS(status)) {
|
|
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGERROR,
|
|
"WDFOBJECT %p not in WDFCOLLECTION %p, %!STATUS!",
|
|
Item, Collection, status);
|
|
FxVerifierDbgBreakPoint(pFxDriverGlobals);
|
|
}
|
|
}
|
|
|
|
__drv_maxIRQL(DISPATCH_LEVEL)
|
|
WDFOBJECT
|
|
NTAPI
|
|
WDFEXPORT(WdfCollectionGetItem)(
|
|
__in
|
|
PWDF_DRIVER_GLOBALS DriverGlobals,
|
|
__in
|
|
WDFCOLLECTION Collection,
|
|
__in
|
|
ULONG Index
|
|
)
|
|
{
|
|
DDI_ENTRY();
|
|
|
|
FxCollection *pCollection;
|
|
FxObject *pObject;
|
|
KIRQL irql;
|
|
|
|
FxObjectHandleGetPtr(GetFxDriverGlobals(DriverGlobals),
|
|
Collection,
|
|
FX_TYPE_COLLECTION,
|
|
(PVOID*) &pCollection);
|
|
|
|
pCollection->Lock(&irql);
|
|
pObject = pCollection->GetItem(Index);
|
|
pCollection->Unlock(irql);
|
|
|
|
if (pObject == NULL) {
|
|
return NULL;
|
|
}
|
|
|
|
return pObject->GetObjectHandle();
|
|
}
|
|
|
|
__drv_maxIRQL(DISPATCH_LEVEL)
|
|
WDFOBJECT
|
|
NTAPI
|
|
WDFEXPORT(WdfCollectionGetFirstItem)(
|
|
__in
|
|
PWDF_DRIVER_GLOBALS DriverGlobals,
|
|
__in
|
|
WDFCOLLECTION Collection
|
|
)
|
|
{
|
|
DDI_ENTRY();
|
|
|
|
FxCollection *pCollection;
|
|
FxObject* pObject;
|
|
KIRQL irql;
|
|
|
|
FxObjectHandleGetPtr(GetFxDriverGlobals(DriverGlobals),
|
|
Collection,
|
|
FX_TYPE_COLLECTION,
|
|
(PVOID*) &pCollection);
|
|
|
|
pCollection->Lock(&irql);
|
|
pObject = pCollection->GetFirstItem();
|
|
pCollection->Unlock(irql);
|
|
|
|
if (pObject != NULL) {
|
|
return pObject->GetObjectHandle();
|
|
}
|
|
else {
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
__drv_maxIRQL(DISPATCH_LEVEL)
|
|
WDFOBJECT
|
|
NTAPI
|
|
WDFEXPORT(WdfCollectionGetLastItem)(
|
|
__in
|
|
PWDF_DRIVER_GLOBALS DriverGlobals,
|
|
__in
|
|
WDFCOLLECTION Collection
|
|
)
|
|
{
|
|
DDI_ENTRY();
|
|
|
|
FxCollection *pCollection;
|
|
FxObject* pObject;
|
|
KIRQL irql;
|
|
|
|
FxObjectHandleGetPtr(GetFxDriverGlobals(DriverGlobals),
|
|
Collection,
|
|
FX_TYPE_COLLECTION,
|
|
(PVOID*) &pCollection);
|
|
|
|
pCollection->Lock(&irql);
|
|
pObject = pCollection->GetLastItem();
|
|
pCollection->Unlock(irql);
|
|
|
|
if (pObject != NULL) {
|
|
return pObject->GetObjectHandle();
|
|
}
|
|
else {
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
} // extern "C" of entire file
|