mirror of
https://github.com/reactos/reactos.git
synced 2025-08-06 15:53:03 +00:00
[WDF] Add Windows Driver Framework files
Takern from Microsoft GitHub repo:
d9c6040fe9
Licensed under MIT
This commit is contained in:
parent
545df81502
commit
8a978a179f
475 changed files with 285099 additions and 0 deletions
58
sdk/lib/drivers/wdf/shared/primitives/km/mxgeneralkm.cpp
Normal file
58
sdk/lib/drivers/wdf/shared/primitives/km/mxgeneralkm.cpp
Normal file
|
@ -0,0 +1,58 @@
|
|||
//
|
||||
// Copyright (C) Microsoft. All rights reserved.
|
||||
//
|
||||
#include "Mx.h"
|
||||
|
||||
VOID
|
||||
Mx::MxDbgPrint(
|
||||
__drv_formatString(printf)
|
||||
__in PCSTR DebugMessage,
|
||||
...
|
||||
)
|
||||
{
|
||||
#if DBG
|
||||
|
||||
#define TEMP_BUFFER_SIZE 1024
|
||||
va_list list;
|
||||
CHAR debugMessageBuffer[TEMP_BUFFER_SIZE];
|
||||
NTSTATUS status;
|
||||
|
||||
va_start(list, DebugMessage);
|
||||
|
||||
if (DebugMessage) {
|
||||
|
||||
//
|
||||
// Using new safe string functions instead of _vsnprintf.
|
||||
// This function takes care of NULL terminating if the message
|
||||
// is longer than the buffer.
|
||||
//
|
||||
status = RtlStringCbVPrintfA( debugMessageBuffer,
|
||||
sizeof(debugMessageBuffer),
|
||||
DebugMessage,
|
||||
list );
|
||||
if(!NT_SUCCESS(status)) {
|
||||
|
||||
DbgPrint ("WDF DbgPrint: Unable to expand: %s", DebugMessage);
|
||||
}
|
||||
else {
|
||||
DbgPrint("%s", debugMessageBuffer);
|
||||
}
|
||||
}
|
||||
va_end(list);
|
||||
|
||||
#else
|
||||
UNREFERENCED_PARAMETER(DebugMessage);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
VOID
|
||||
Mx::MxGlobalInit(
|
||||
VOID
|
||||
)
|
||||
{
|
||||
//
|
||||
// Global initialization for kernel-mode primitives
|
||||
//
|
||||
}
|
74
sdk/lib/drivers/wdf/shared/primitives/um/errtostatus.cpp
Normal file
74
sdk/lib/drivers/wdf/shared/primitives/um/errtostatus.cpp
Normal file
|
@ -0,0 +1,74 @@
|
|||
//
|
||||
// Copyright (C) Microsoft. All rights reserved.
|
||||
//
|
||||
#include "Mx.h"
|
||||
|
||||
BOOL
|
||||
ConvertWinErrorToNtstatus(
|
||||
__in ULONG WinError,
|
||||
__out NTSTATUS * Status
|
||||
)
|
||||
{
|
||||
ULONG index = 0;
|
||||
BOOL found = FALSE;
|
||||
|
||||
*Status = INVALID_STATUS;
|
||||
|
||||
for ( ULONG i = 0; i < ARRAYSIZE(ErrorBucketTable); i++ )
|
||||
{
|
||||
if (WinError < ErrorBucketTable[i].BaseErrorCode)
|
||||
{
|
||||
//
|
||||
// The error code falls between previous bucket end and current
|
||||
// bucket begin, hence there is no mapping for it
|
||||
//
|
||||
break;
|
||||
}
|
||||
|
||||
if ( WinError < (ErrorBucketTable[i].BaseErrorCode +
|
||||
ErrorBucketTable[i].RunLength) )
|
||||
{
|
||||
//
|
||||
// Index falls within the current bucket
|
||||
//
|
||||
index += (WinError - ErrorBucketTable[i].BaseErrorCode);
|
||||
found = TRUE;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// Index is beyond current bucket, continue search
|
||||
//
|
||||
index += ErrorBucketTable[i].RunLength;
|
||||
}
|
||||
}
|
||||
|
||||
if (TRUE == found)
|
||||
{
|
||||
*Status = ErrorTable[index];
|
||||
if (INVALID_STATUS == (*Status))
|
||||
{
|
||||
found = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
NTSTATUS
|
||||
WinErrorToNtStatus(
|
||||
__in ULONG WinError
|
||||
)
|
||||
{
|
||||
NTSTATUS status;
|
||||
|
||||
if (TRUE == ConvertWinErrorToNtstatus(WinError, &status))
|
||||
{
|
||||
return status;
|
||||
}
|
||||
else
|
||||
{
|
||||
return STATUS_UNSUCCESSFUL;
|
||||
}
|
||||
}
|
206
sdk/lib/drivers/wdf/shared/primitives/um/mxdeviceobjectum.cpp
Normal file
206
sdk/lib/drivers/wdf/shared/primitives/um/mxdeviceobjectum.cpp
Normal file
|
@ -0,0 +1,206 @@
|
|||
/*++
|
||||
|
||||
Copyright (c) Microsoft Corporation
|
||||
|
||||
ModuleName:
|
||||
|
||||
MxDeviceObjectUm.cpp
|
||||
|
||||
Abstract:
|
||||
|
||||
User Mode implementation of Device Object defined in MxDeviceObject.h
|
||||
|
||||
--*/
|
||||
|
||||
#include "fxmin.hpp"
|
||||
|
||||
CCHAR
|
||||
MxDeviceObject::GetStackSize(
|
||||
VOID
|
||||
)
|
||||
{
|
||||
return (CCHAR) (static_cast<IWudfDevice2*>(m_DeviceObject))->GetStackSize2();
|
||||
}
|
||||
|
||||
VOID
|
||||
MxDeviceObject::ReferenceObject(
|
||||
)
|
||||
{
|
||||
m_DeviceObject->AddRef();
|
||||
|
||||
//
|
||||
// We take a reference on device stack object as it is the reference on
|
||||
// device stack object that keeps the driver loaded
|
||||
//
|
||||
m_DeviceObject->GetDeviceStackInterface()->AddRef();
|
||||
}
|
||||
|
||||
MdDeviceObject
|
||||
MxDeviceObject::GetAttachedDeviceReference(
|
||||
VOID
|
||||
)
|
||||
{
|
||||
FX_VERIFY(INTERNAL, TRAPMSG("MxDeviceObject::GetAttachedDeviceReference "
|
||||
"not implemented for UMDF"));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
VOID
|
||||
MxDeviceObject::DereferenceObject(
|
||||
)
|
||||
{
|
||||
m_DeviceObject->Release();
|
||||
|
||||
//
|
||||
// We also take a device stack reference (see ReferenceObject)
|
||||
// release it now
|
||||
//
|
||||
m_DeviceObject->GetDeviceStackInterface()->Release();
|
||||
}
|
||||
|
||||
ULONG
|
||||
MxDeviceObject::GetFlags(
|
||||
VOID
|
||||
)
|
||||
{
|
||||
return m_DeviceObject->GetDeviceObjectWdmFlags();
|
||||
}
|
||||
|
||||
POWER_STATE
|
||||
MxDeviceObject::SetPowerState(
|
||||
__in POWER_STATE_TYPE /*Type*/,
|
||||
__in POWER_STATE State
|
||||
)
|
||||
{
|
||||
ULONG oldState;
|
||||
POWER_STATE oldStateEnum;
|
||||
|
||||
m_DeviceObject->GetDeviceStackInterface()->SetPowerState(
|
||||
State.DeviceState,
|
||||
&oldState
|
||||
);
|
||||
|
||||
oldStateEnum.DeviceState = (DEVICE_POWER_STATE) oldState;
|
||||
|
||||
return oldStateEnum;
|
||||
}
|
||||
|
||||
VOID
|
||||
MxDeviceObject::InvalidateDeviceRelations(
|
||||
__in DEVICE_RELATION_TYPE Type
|
||||
)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(Type);
|
||||
|
||||
ASSERTMSG("Not implemented for UMDF\n", FALSE);
|
||||
|
||||
//IoInvalidateDeviceRelations(DeviceObject, Type);
|
||||
}
|
||||
|
||||
VOID
|
||||
MxDeviceObject::InvalidateDeviceState(
|
||||
__in MdDeviceObject Fdo
|
||||
)
|
||||
{
|
||||
//
|
||||
// DO NOT use m_DeviceObject. That specifies PDO in this case which is
|
||||
// currently NULL for UMDF. Use the passed in Fdo instead.
|
||||
//
|
||||
Fdo->GetDeviceStackInterface()->InvalidateDeviceState();
|
||||
}
|
||||
|
||||
PVOID
|
||||
MxDeviceObject::GetDeviceExtension(
|
||||
VOID
|
||||
)
|
||||
{
|
||||
ASSERTMSG("Not implemented for UMDF\n", FALSE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
VOID
|
||||
MxDeviceObject::SetDeviceExtension(
|
||||
PVOID Value
|
||||
)
|
||||
{
|
||||
//
|
||||
// This will set the context
|
||||
//
|
||||
(static_cast<IWudfDevice2*>(m_DeviceObject))->SetContext(Value);
|
||||
}
|
||||
|
||||
DEVICE_TYPE
|
||||
MxDeviceObject::GetDeviceType(
|
||||
VOID
|
||||
)
|
||||
{
|
||||
ASSERTMSG("Not implemented for UMDF\n", FALSE);
|
||||
return (DEVICE_TYPE) 0;
|
||||
}
|
||||
|
||||
ULONG
|
||||
MxDeviceObject::GetCharacteristics(
|
||||
VOID
|
||||
)
|
||||
{
|
||||
ASSERTMSG("Not implemented for UMDF\n", FALSE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
VOID
|
||||
MxDeviceObject::SetDeviceType(
|
||||
DEVICE_TYPE /* Value */
|
||||
)
|
||||
{
|
||||
ASSERTMSG("Not implemented for UMDF\n", FALSE);
|
||||
}
|
||||
|
||||
VOID
|
||||
MxDeviceObject::SetCharacteristics(
|
||||
ULONG /* Characteristics */
|
||||
)
|
||||
{
|
||||
ASSERTMSG("Not implemented for UMDF\n", FALSE);
|
||||
}
|
||||
|
||||
VOID
|
||||
MxDeviceObject::SetAlignmentRequirement(
|
||||
_In_ ULONG /* Value */
|
||||
)
|
||||
{
|
||||
ASSERTMSG("Not implemented for UMDF\n", FALSE);
|
||||
}
|
||||
|
||||
ULONG
|
||||
MxDeviceObject::GetAlignmentRequirement(
|
||||
VOID
|
||||
)
|
||||
{
|
||||
ASSERTMSG("Not implemented for UMDF\n", FALSE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
VOID
|
||||
MxDeviceObject::SetStackSize(
|
||||
_In_ CCHAR Size
|
||||
)
|
||||
{
|
||||
(static_cast<IWudfDevice2*>(m_DeviceObject))->SetStackSize2((ULONG)Size);
|
||||
}
|
||||
|
||||
VOID
|
||||
MxDeviceObject::SetFlags(
|
||||
ULONG Flags
|
||||
)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(Flags);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
/*++
|
||||
|
||||
Copyright (c) Microsoft Corporation
|
||||
|
||||
ModuleName:
|
||||
|
||||
MxDeviceObjectUm.cpp
|
||||
|
||||
Abstract:
|
||||
|
||||
User Mode implementation of Device Object defined in MxDeviceObject.h
|
||||
|
||||
--*/
|
||||
|
||||
#include "fxmin.hpp"
|
||||
#include "fxldrum.h"
|
||||
|
||||
PVOID
|
||||
MxDriverObject::GetDriverExtensionAddDevice(
|
||||
VOID
|
||||
)
|
||||
{
|
||||
return m_DriverObject->AddDevice;
|
||||
}
|
||||
|
||||
VOID
|
||||
MxDriverObject::SetDriverExtensionAddDevice(
|
||||
_In_ MdDriverAddDevice Value
|
||||
)
|
||||
{
|
||||
m_DriverObject->AddDevice = Value;
|
||||
}
|
||||
|
||||
MdDriverUnload
|
||||
MxDriverObject::GetDriverUnload(
|
||||
VOID
|
||||
)
|
||||
{
|
||||
m_DriverObject->DriverUnload;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
VOID
|
||||
MxDriverObject::SetDriverUnload(
|
||||
_In_ MdDriverUnload Value
|
||||
)
|
||||
{
|
||||
m_DriverObject->DriverUnload = Value;
|
||||
}
|
||||
|
||||
VOID
|
||||
MxDriverObject::SetMajorFunction(
|
||||
_In_ UCHAR i,
|
||||
_In_ MdDriverDispatch Value
|
||||
)
|
||||
{
|
||||
m_DriverObject->MajorFunction[i] = Value;
|
||||
}
|
||||
|
||||
VOID
|
||||
MxDriverObject::SetDriverObjectFlag(
|
||||
_In_ FxDriverObjectUmFlags Flag
|
||||
)
|
||||
{
|
||||
m_DriverObject->Flags |= Flag;
|
||||
}
|
||||
|
||||
BOOLEAN
|
||||
MxDriverObject::IsDriverObjectFlagSet(
|
||||
_In_ FxDriverObjectUmFlags Flag
|
||||
)
|
||||
{
|
||||
return (!!(m_DriverObject->Flags & Flag));
|
||||
}
|
||||
|
41
sdk/lib/drivers/wdf/shared/primitives/um/mxfileobjectum.cpp
Normal file
41
sdk/lib/drivers/wdf/shared/primitives/um/mxfileobjectum.cpp
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*++
|
||||
|
||||
Copyright (c) Microsoft Corporation
|
||||
|
||||
ModuleName:
|
||||
|
||||
MxFileObjectUm.cpp
|
||||
|
||||
Abstract:
|
||||
|
||||
Implementation of MxFileObjectUm functions.
|
||||
|
||||
Author:
|
||||
|
||||
Revision History:
|
||||
|
||||
|
||||
|
||||
--*/
|
||||
|
||||
#include "Mx.h"
|
||||
|
||||
#include <strsafe.h>
|
||||
|
||||
#include "fxmin.hpp"
|
||||
|
||||
PUNICODE_STRING
|
||||
MxFileObject::GetFileName(
|
||||
_Inout_opt_ PUNICODE_STRING Filename
|
||||
)
|
||||
{
|
||||
LPCWSTR name;
|
||||
|
||||
ASSERTMSG("Filename parameter cannot be NULL\n", Filename != NULL);
|
||||
|
||||
name = m_FileObject->GetName();
|
||||
RtlInitUnicodeString(Filename, name);
|
||||
|
||||
return Filename;
|
||||
}
|
||||
|
123
sdk/lib/drivers/wdf/shared/primitives/um/mxgeneralum.cpp
Normal file
123
sdk/lib/drivers/wdf/shared/primitives/um/mxgeneralum.cpp
Normal file
|
@ -0,0 +1,123 @@
|
|||
/*++
|
||||
|
||||
Copyright (c) Microsoft Corporation
|
||||
|
||||
ModuleName:
|
||||
|
||||
MxGeneralUm.cpp
|
||||
|
||||
Abstract:
|
||||
|
||||
Implementation of MxGeneralUm functions.
|
||||
|
||||
Author:
|
||||
|
||||
|
||||
|
||||
Revision History:
|
||||
|
||||
|
||||
|
||||
--*/
|
||||
|
||||
#include "Mx.h"
|
||||
|
||||
#include <strsafe.h>
|
||||
|
||||
#include "fxmin.hpp"
|
||||
|
||||
extern "C" IUMDFPlatform *g_IUMDFPlatform;
|
||||
|
||||
VOID
|
||||
Mx::MxDbgPrint(
|
||||
__drv_formatString(printf)
|
||||
__in PCSTR DebugMessage,
|
||||
...
|
||||
)
|
||||
{
|
||||
#if DBG
|
||||
|
||||
#define TEMP_BUFFER_SIZE 1024
|
||||
va_list list;
|
||||
CHAR debugMessageBuffer[TEMP_BUFFER_SIZE];
|
||||
HRESULT hr;
|
||||
|
||||
va_start(list, DebugMessage);
|
||||
|
||||
if (DebugMessage) {
|
||||
|
||||
//
|
||||
// Using new safe string functions instead of _vsnprintf.
|
||||
// This function takes care of NULL terminating if the message
|
||||
// is longer than the buffer.
|
||||
//
|
||||
hr = StringCbVPrintfA( debugMessageBuffer,
|
||||
sizeof(debugMessageBuffer),
|
||||
DebugMessage,
|
||||
list );
|
||||
if(!SUCCEEDED(hr)) {
|
||||
OutputDebugStringA("WDF DbgPrint: Unable to expand: ");
|
||||
OutputDebugStringA(DebugMessage);
|
||||
}
|
||||
else {
|
||||
OutputDebugStringA(debugMessageBuffer);
|
||||
}
|
||||
}
|
||||
va_end(list);
|
||||
|
||||
#else
|
||||
UNREFERENCED_PARAMETER(DebugMessage);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
VOID
|
||||
Mx::MxBugCheckEx(
|
||||
_In_ ULONG BugCheckCode,
|
||||
_In_ ULONG_PTR BugCheckParameter1,
|
||||
_In_ ULONG_PTR BugCheckParameter2,
|
||||
_In_ ULONG_PTR BugCheckParameter3,
|
||||
_In_ ULONG_PTR BugCheckParameter4
|
||||
)
|
||||
{
|
||||
|
||||
UNREFERENCED_PARAMETER(BugCheckParameter1);
|
||||
UNREFERENCED_PARAMETER(BugCheckParameter2);
|
||||
UNREFERENCED_PARAMETER(BugCheckParameter3);
|
||||
UNREFERENCED_PARAMETER(BugCheckParameter4);
|
||||
|
||||
FX_VERIFY(DRIVER(BadAction, BugCheckCode), TRAPMSG("UMDF verification "
|
||||
"faults should not call this code path"));
|
||||
}
|
||||
|
||||
VOID
|
||||
Mx::MxGlobalInit(
|
||||
VOID
|
||||
)
|
||||
{
|
||||
//
|
||||
// Currently just a placeholder. If there is any global initialization
|
||||
// needed for the user-mode primitives, it can be done here.
|
||||
//
|
||||
}
|
||||
|
||||
VOID
|
||||
Mx::MxDetachDevice(
|
||||
_Inout_ MdDeviceObject Device
|
||||
)
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
HRESULT hrDetachDev =
|
||||
Device->GetDeviceStackInterface()->DetachDevice(Device);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
UNREFERENCED_PARAMETER(hrDetachDev);
|
||||
}
|
||||
|
66
sdk/lib/drivers/wdf/shared/primitives/um/mxworkitemum.cpp
Normal file
66
sdk/lib/drivers/wdf/shared/primitives/um/mxworkitemum.cpp
Normal file
|
@ -0,0 +1,66 @@
|
|||
/*++
|
||||
|
||||
Copyright (c) Microsoft Corporation
|
||||
|
||||
ModuleName:
|
||||
|
||||
MxWorkItemUm.cpp
|
||||
|
||||
Abstract:
|
||||
|
||||
Work item callback thunk implementation for user mode
|
||||
|
||||
We need this thunk to wire the um callback to a mode agnostic work item
|
||||
callback.
|
||||
|
||||
Author:
|
||||
|
||||
|
||||
|
||||
Revision History:
|
||||
|
||||
|
||||
|
||||
--*/
|
||||
|
||||
#include "Mx.h"
|
||||
|
||||
VOID
|
||||
CALLBACK
|
||||
MxWorkItem::_WorkerThunk (
|
||||
_Inout_ PTP_CALLBACK_INSTANCE Instance,
|
||||
_Inout_opt_ PVOID Parameter,
|
||||
_Inout_ PTP_WAIT Wait,
|
||||
_In_ TP_WAIT_RESULT WaitResult
|
||||
)
|
||||
{
|
||||
MdWorkItem workItem = (MdWorkItem) Parameter;
|
||||
|
||||
UNREFERENCED_PARAMETER(Instance);
|
||||
UNREFERENCED_PARAMETER(Wait);
|
||||
UNREFERENCED_PARAMETER(WaitResult);
|
||||
|
||||
(*workItem->Callback)(
|
||||
workItem->DeviceObject,
|
||||
workItem->Context
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
VOID
|
||||
MxWorkItem::WaitForCallbacksToComplete(
|
||||
VOID
|
||||
)
|
||||
{
|
||||
Mx::MxAssert(NULL != m_WorkItem->WaitBlock);
|
||||
|
||||
//
|
||||
// Wait for outstanding callbacks to complete.
|
||||
//
|
||||
WaitForThreadpoolWaitCallbacks(m_WorkItem->WaitBlock,
|
||||
FALSE // donot cancel pending waits
|
||||
);
|
||||
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue