1 /*++
2 
3 Copyright (c) Microsoft Corporation
4 
5 ModuleName:
6 
7     MxUm.h
8 
9 Abstract:
10 
11     This file includes standard NT headers and
12     user mode versions of mode agnostic headers
13 
14     It also contains definitions pulled out from wdm.h
15 
16 Author:
17 
18 
19 
20 Revision History:
21 
22 
23 
24 --*/
25 
26 #pragma once
27 
28 #ifndef UMDF_USING_NTSTATUS
29 #define UMDF_USING_NTSTATUS
30 #endif
31 
32 #include <windows.h>
33 #include <devpropdef.h>
34 #include <winioctl.h>
35 
36 
37 
38 
39 #ifdef UMDF_INFRASTRUCTURE
40 #ifndef WUDF_KERNEL
41 typedef PVOID PIRP;
42 typedef PVOID PIO_REMOVE_LOCK;
43 #endif
44 #endif
45 
46 #include "wdmdefs.h"
47 
48 #define FX_PLUGPLAY_REGKEY_DEVICEMAP 0x8
49 
50 //
51 // Define the callback function to be supplied by a user-mode user of MxTimer
52 // It has the extra parameters Reserved1, Reserved2 and Reserved3 to make it
53 // look like the KDEFERRED_ROUTINE that used as the callback function for the
54 // kernel mode version of MxTimer. The user-mode user of MxTimer should not
55 // use these ReservedX parameters.
56 //
57 
58 typedef
59 VOID
60 TIMER_CALLBACK_ROUTINE(
61     __in     PKDPC Reserved1,
62     __in_opt PVOID Context,
63     __in_opt PVOID Reserved2,
64     __in_opt PVOID Reserved3
65     );
66 
67 typedef PVOID PEX_TIMER;
68 
69 typedef
70 VOID
71 TIMER_CALLBACK_ROUTINE_EX(
72     __in     PEX_TIMER Reserved1,
73     __in_opt PVOID Context
74     );
75 
76 typedef TIMER_CALLBACK_ROUTINE MdDeferredRoutineType, *MdDeferredRoutine;
77 typedef TIMER_CALLBACK_ROUTINE_EX MdExtCallbackType, *MdExtCallback;
78 
79 //
80 // Forward defines
81 //
82 struct IFxMessageDispatch;
83 struct IUnknown;
84 struct IWudfIrp;
85 struct IWudfIoIrp;
86 struct IWudfFile;
87 struct IWDFObject;
88 struct IObjectCleanup;
89 struct IWudfDeviceStack;
90 struct IWudfDeviceStack2;
91 struct IWudfTargetCallbackDeviceChange;
92 struct IWudfIoDispatcher;
93 struct IWudfRemoteDispatcher;
94 struct IWudfDevice;
95 struct IWudfDevice2;
96 struct IWudfHost;
97 struct IWudfHost2;
98 
99 //
100 // typedefs
101 //
102 typedef IWudfDevice *           MdDeviceObject;
103 typedef IWudfIrp*               MdIrp;
104 typedef LPCSTR                  MxFuncName;
105 typedef PVOID                   MxThread;
106 typedef PVOID                   MdEThread;
107 typedef PWUDF_IO_REMOVE_LOCK    MdRemoveLock;
108 typedef PVOID                   MdInterrupt;
109 
110 typedef struct _STACK_DEVICE_CAPABILITIES *PSTACK_DEVICE_CAPABILITIES;
111 typedef UINT64 WUDF_INTERFACE_CONTEXT;
112 typedef enum _WDF_REQUEST_TYPE WDF_REQUEST_TYPE;
113 typedef struct _WDF_INTERRUPT_INFO *PWDF_INTERRUPT_INFO;
114 typedef enum _WDF_INTERRUPT_POLICY WDF_INTERRUPT_POLICY;
115 typedef enum _WDF_INTERRUPT_PRIORITY WDF_INTERRUPT_PRIORITY;
116 typedef struct _WDF_OBJECT_ATTRIBUTES *PWDF_OBJECT_ATTRIBUTES;
117 typedef enum _WDF_DEVICE_IO_BUFFER_RETRIEVAL WDF_DEVICE_IO_BUFFER_RETRIEVAL;
118 typedef enum RdWmiPowerAction;
119 typedef struct _WDF_REQUEST_PARAMETERS *PWDF_REQUEST_PARAMETERS;
120 typedef enum _WDF_EVENT_TYPE WDF_EVENT_TYPE;
121 typedef enum _WDF_FILE_INFORMATION_CLASS WDF_FILE_INFORMATION_CLASS;
122 typedef WDF_FILE_INFORMATION_CLASS *PWDF_FILE_INFORMATION_CLASS;
123 
124 typedef
125 NTSTATUS
126 WUDF_IO_COMPLETION_ROUTINE (
127      __in MdDeviceObject DeviceObject,
128      __in MdIrp Irp,
129      __in PVOID Context
130     );
131 
132 typedef WUDF_IO_COMPLETION_ROUTINE *PWUDF_IO_COMPLETION_ROUTINE;
133 
134 typedef
135 VOID
136 WUDF_DRIVER_CANCEL (
137      __in MdDeviceObject DeviceObject,
138      __in MdIrp Irp
139     );
140 
141 typedef WUDF_DRIVER_CANCEL *PWUDF_DRIVER_CANCEL;
142 typedef WUDF_IO_COMPLETION_ROUTINE MdCompletionRoutineType, *MdCompletionRoutine;
143 typedef WUDF_DRIVER_CANCEL MdCancelRoutineType, *MdCancelRoutine;
144 
145 //
146 // From wdm.h
147 //
148 
149 typedef
150 __drv_functionClass(REQUEST_POWER_COMPLETE)
151 __drv_sameIRQL
152 VOID
153 REQUEST_POWER_COMPLETE (
154     __in MdDeviceObject DeviceObject,
155     __in UCHAR MinorFunction,
156     __in POWER_STATE PowerState,
157     __in_opt PVOID Context,
158     __in PIO_STATUS_BLOCK IoStatus
159     );
160 
161 typedef REQUEST_POWER_COMPLETE *PREQUEST_POWER_COMPLETE;
162 typedef REQUEST_POWER_COMPLETE MdRequestPowerCompleteType, *MdRequestPowerComplete;
163 
164 typedef enum _WDF_DEVICE_IO_TYPE WDF_DEVICE_IO_TYPE;
165 typedef struct _DRIVER_OBJECT_UM *PDRIVER_OBJECT_UM;
166 
167 //
168 // Driver object's basic interface.
169 //
170 typedef
171 NTSTATUS
172 DRIVER_ADD_DEVICE_UM (
173     _In_  PDRIVER_OBJECT_UM         DriverObject,
174     _In_  PVOID                     Context,
175     _In_  IWudfDeviceStack *        DevStack,
176     _In_  LPCWSTR                   KernelDeviceName,
177     _In_opt_ HKEY                   hPdoKey,
178     _In_  LPCWSTR                   pwszServiceName,
179     _In_  LPCWSTR                   pwszDevInstanceID,
180     _In_  ULONG                     ulDriverID
181     );
182 
183 typedef DRIVER_ADD_DEVICE_UM *PFN_DRIVER_ADD_DEVICE_UM;
184 
185 typedef
186 VOID
187 DRIVER_DISPATCH_UM (
188     _In_ IWudfDevice *              DeviceObject,
189     _In_ IWudfIrp *                 Irp,
190     _In_opt_ IUnknown *             Context
191     );
192 
193 typedef DRIVER_DISPATCH_UM *PFN_DRIVER_DISPATCH_UM;
194 
195 typedef
196 VOID
197 DRIVER_UNLOAD_UM (
198     _In_ PDRIVER_OBJECT_UM          DriverObject
199     );
200 
201 typedef DRIVER_UNLOAD_UM *PFN_DRIVER_UNLOAD_UM;
202 
203 
204 
205 
206 #ifdef UMDF_INFRASTRUCTURE
207 #ifndef WUDF_KERNEL
208 typedef CCHAR KPROCESSOR_MODE;
209 typedef PVOID PMDL;
210 typedef
211 _IRQL_requires_same_
212 _Function_class_(ALLOCATE_FUNCTION)
213 PVOID
214 ALLOCATE_FUNCTION (
215     _In_ POOL_TYPE PoolType,
216     _In_ SIZE_T NumberOfBytes,
217     _In_ ULONG Tag
218     );
219 typedef ALLOCATE_FUNCTION *PALLOCATE_FUNCTION;
220 typedef
221 _IRQL_requires_same_
222 _Function_class_(FREE_FUNCTION)
223 VOID
224 FREE_FUNCTION (
225     _In_ __drv_freesMem(Mem) PVOID Buffer
226     );
227 typedef FREE_FUNCTION *PFREE_FUNCTION;
228 #endif
229 #endif
230 
231 //===============================================================================
232 #include <limits.h>
233 #include <driverspecs.h>
234 
235 #include "ErrToStatus.h"
236 
237 #include "MxDriverObjectUm.h"
238 #include "MxDeviceObjectUm.h"
239 #include "MxFileObjectUm.h"
240 #include "MxGeneralUm.h"
241 #include "MxLockUm.h"
242 #include "MxPagedLockUm.h"
243 #include "MxEventUm.h"
244 #include "MxMemoryUm.h"
245 #include "MxTimerUm.h"
246 #include "MxWorkItemUm.h"
247