ReactOS  0.4.15-dev-3173-g40ee59d
fxdriverkm.cpp
Go to the documentation of this file.
1 /*++
2 
3 Copyright (c) Microsoft Corporation
4 
5 Module Name:
6 
7  FxDriverKm.cpp
8 
9 Abstract:
10 
11  This is the main driver framework.
12 
13 Author:
14 
15 
16 
17 Environment:
18 
19  Kernel mode only
20 
21 Revision History:
22 
23 
24 
25 --*/
26 
27 #include "coreprivshared.hpp"
28 #include "fxiotarget.hpp"
29 
30 // Tracing support
31 extern "C" {
32 // #include "FxDriverKm.tmh"
33 }
34 
37 STDCALL
41  )
42 {
44 
46 
47  if (pDriver != NULL) {
49  }
50 
51  return STATUS_UNSUCCESSFUL;
52 }
53 
58  )
59 {
60  WDFDEVICE_INIT init(this);
63 
65  "Enter AddDevice PDO %p", PhysicalDeviceObject);
66 
67  pDevice = NULL;
68  init.CreatedOnStack = TRUE;
69 
70  init.InitType = FxDeviceInitTypeFdo;
71  init.Fdo.PhysicalDevice = PhysicalDeviceObject;
72 
74 
75  //
76  // Caller returned w/out creating a device, we are done. Returning
77  // STATUS_SUCCESS w/out creating a device and attaching to the stack is OK,
78  // especially for filter drivers which selectively attach to devices.
79  //
80  if (init.CreatedDevice == NULL) {
82  "Driver did not create a device in "
83  "EvtDriverAddDevice, status %!STATUS!", status);
84 
85  //
86  // We do not let filters affect the building of the rest of the stack.
87  // If they return error, we convert it to STATUS_SUCCESS.
88  //
89  if (init.Fdo.Filter && !NT_SUCCESS(status)) {
92  "Filter returned %!STATUS! without creating a WDFDEVICE, "
93  "converting to STATUS_SUCCESS", status);
95  }
96 
97  return status;
98  }
99 
100  pDevice = init.CreatedDevice;
101 
102  if (NT_SUCCESS(status)) {
103  //
104  // Make sure that DO_DEVICE_INITIALIZING is cleared.
105  // FxDevice::FdoInitialize does not do this b/c the driver writer may
106  // want the bit set until sometime after WdfDeviceCreate returns
107  //
109  }
110  else {
111  //
112  // Created a device, but returned error.
113  //
114  ASSERT(pDevice->IsPnp());
116 
118  pDevice = NULL;
119  }
120 
122  "Exit, status %!STATUS!", status);
123 
124  return status;
125 }
126 
127 
129 NTSTATUS
131  VOID
132  )
133 {
135  FxDriver** ppDriver;
136 
137  //
138  // Prefast is much happier if we take the size of the type rather then
139  // the size of the variable.
140  //
142  FX_DRIVER_ID,
143  sizeof(FxDriver**),
144  (PVOID*)&ppDriver);
145  if (!NT_SUCCESS(status)) {
146  return status;
147  }
148 
149  //
150  // If we succeeded in creating the driver object extension,
151  // then store our FxDriver pointer in the DriverObjectExtension.
152  //
153  *ppDriver = this;
154 
155  return STATUS_SUCCESS;
156 }
157 
158 FxDriver*
161  )
162 {
163  FxDriver* objExt;
165  FX_DRIVER_ID);
166  ASSERT(objExt != NULL);
167 
168  return objExt;
169 }
170 
171 
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
__inline BOOLEAN IsPnp(VOID)
Definition: fxdevice.hpp:1200
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1155
#define TRACE_LEVEL_INFORMATION
Definition: storswtr.h:29
static int init
Definition: wintirpc.c:33
#define TRACE_LEVEL_VERBOSE
Definition: storswtr.h:30
#define _In_
Definition: ms_sal.h:308
static FxDriver * GetFxDriver(__in MdDriverObject DriverObject)
Definition: fxdriverkm.cpp:159
#define FX_DRIVER_ID
Definition: fxdriver.hpp:49
_Must_inspect_result_ NTSTATUS AllocateDriverObjectExtensionAndStoreFxDriver(VOID)
Definition: fxdriverkm.cpp:130
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
FxDevice * pDevice
__inline WDFDRIVER GetHandle(VOID)
Definition: fxdriver.hpp:202
static __inline NTSTATUS MxAllocateDriverObjectExtension(_In_ MdDriverObject DriverObject, _In_ PVOID ClientIdentificationAddress, _In_ ULONG DriverObjectExtensionSize, _Post_ _At_(*DriverObjectExtension, _When_(return==0, __drv_aliasesMem __drv_allocatesMem(Mem) _Post_notnull_)) _When_(return==0, _Outptr_result_bytebuffer_(DriverObjectExtensionSize)) PVOID *DriverObjectExtension)
Definition: mxgeneralkm.h:396
FxDriver * pDriver
#define STDCALL
Definition: wdf.h:45
#define ASSERT(a)
Definition: mode.c:44
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static MdDriverAddDeviceType AddDevice
Definition: fxdriver.hpp:125
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define _Must_inspect_result_
Definition: ms_sal.h:558
__inline MdDriverObject GetObject(VOID)
#define TRACE_LEVEL_WARNING
Definition: storswtr.h:28
#define TRACINGPNP
Definition: dbgtrace.h:67
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
Definition: fxobject.hpp:734
WDF_DEVICE_PNP_STATE m_CurrentPnpState
Definition: fxdevice.hpp:507
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
#define NULL
Definition: types.h:112
_Must_inspect_result_ NTSTATUS Invoke(__in WDFDRIVER Driver, __in PWDFDEVICE_INIT DeviceInit)
VOID FinishInitializing(VOID)
Definition: fxdevice.cpp:1109
static __inline PVOID MxGetDriverObjectExtension(__in MdDriverObject DriverObject, __in PVOID ClientIdentificationAddress)
Definition: mxgeneralkm.h:385
_Must_inspect_result_ NTSTATUS DeleteDeviceFromFailedCreate(__in NTSTATUS FailedStatus, __in BOOLEAN UseStateMachine)
Definition: fxdevice.cpp:644
#define STATUS_SUCCESS
Definition: shellext.h:65
#define __in
Definition: dbghelp.h:35
static SERVICE_STATUS status
Definition: service.c:31
MxDriverObject m_DriverObject
Definition: fxdriver.hpp:62
FxDriverDeviceAdd m_DriverDeviceAdd
Definition: fxdriver.hpp:70
Definition: ps.c:97