1 /*++ 2 3 Copyright (c) Microsoft Corporation 4 5 Module Name: 6 7 FxPkgGeneral.hpp 8 9 Abstract: 10 11 This module implements a package to handle general dispath entry points 12 such as IRP_MJ_CREATE and IRP_MJ_CLOSE. 13 14 Author: 15 16 17 18 Environment: 19 20 Both kernel and user mode 21 22 Revision History: 23 24 --*/ 25 26 #ifndef _FXPKGGENERAL_H_ 27 #define _FXPKGGENERAL_H_ 28 29 #include "fxfileobjectcallbacks.hpp" 30 31 class FxShutDown : public FxCallback { 32 33 public: 34 PFN_WDF_DEVICE_SHUTDOWN_NOTIFICATION m_Method; 35 36 FxShutDown( 37 VOID 38 ) : 39 FxCallback(), 40 m_Method(NULL) 41 { 42 } 43 44 VOID 45 Invoke( 46 __in WDFDEVICE Device 47 ) 48 { 49 if (m_Method != NULL) { 50 CallbackStart(); 51 m_Method(Device); 52 CallbackEnd(); 53 } 54 } 55 }; 56 57 #define FX_PKG_GENERAL_FLAG_CX_INFO 0x00000001 58 #define FX_PKG_GENERAL_FLAG_CLIENT_INFO 0x00000002 59 #define FX_PKG_GENERAL_FLAG_CX_CREATE 0x00000004 60 #define FX_PKG_GENERAL_FLAG_CLIENT_CREATE 0x00000008 61 62 #define FX_PKG_GENERAL_FLAG_CREATE \ 63 (FX_PKG_GENERAL_FLAG_CX_CREATE | FX_PKG_GENERAL_FLAG_CLIENT_CREATE) 64 65 66 class FxPkgGeneral : public FxPackage { 67 68 private: 69 70 // 71 // FileObject attributes 72 // 73 LONG m_OpenHandleCount; 74 75 // 76 // List of file objects info (driver and cx). 77 // 78 LIST_ENTRY m_FileObjectInfoHeadList; 79 80 FxIoQueue* m_DefaultQueueForCreates; 81 FxIoQueue* m_DriverCreatedQueue; 82 83 // 84 // Generic file object flags. 85 // 86 ULONG m_Flags; 87 88 // 89 // Execution and synchronization for cx and client driver. 90 // 91 WDF_EXECUTION_LEVEL m_ExecutionLevel; 92 WDF_SYNCHRONIZATION_SCOPE m_SynchronizationScope; 93 94 // 95 // This pointer allows the proper lock to be acquired 96 // based on the configuration with a minimal of runtime 97 // checks. This is configured by ConfigureConstraints(). 98 // We basically inherit device's lock. 99 // 100 FxCallbackLock* m_CallbackLockPtr; 101 FxObject* m_CallbackLockObjectPtr; 102 103 FxShutDown m_EvtDeviceShutdown; 104 105 private: 106 _Must_inspect_result_ 107 NTSTATUS 108 OnCreate( 109 __inout FxIrp* FxIrp 110 ); 111 112 _Must_inspect_result_ 113 NTSTATUS 114 OnClose( 115 __inout FxIrp* FxIrp 116 ); 117 118 BOOLEAN 119 AcquireRemoveLockForClose( 120 __inout FxIrp* FxIrp 121 ); 122 123 _Must_inspect_result_ 124 NTSTATUS 125 OnCleanup( 126 __inout FxIrp* FxIrp 127 ); 128 129 _Must_inspect_result_ 130 NTSTATUS 131 OnShutdown( 132 __inout FxIrp* FxIrp 133 ); 134 135 _Must_inspect_result_ 136 NTSTATUS 137 ConfigureConstraints( 138 __in PLIST_ENTRY FileObjInfoList 139 ); 140 141 _Must_inspect_result_ 142 NTSTATUS 143 ConfigureFileObjectClass( 144 __in PLIST_ENTRY FileObjInfoList 145 ); 146 147 VOID 148 DecrementOpenHandleCount( 149 VOID 150 ); 151 152 _Must_inspect_result_ 153 NTSTATUS 154 ForwardCreateRequest( 155 __in FxIrp* FxIrp, 156 __in MdCompletionRoutine CompletionRoutine, 157 __in PVOID Context 158 ); 159 160 static 161 MdCompletionRoutineType _CreateCompletionRoutine; 162 163 static 164 MdCompletionRoutineType _CreateCompletionRoutine2; 165 166 public: 167 168 FxPkgGeneral( 169 __in PFX_DRIVER_GLOBALS FxDriverGlobals, 170 __in CfxDevice *Device 171 ); 172 173 ~FxPkgGeneral(); 174 175 _Must_inspect_result_ 176 virtual 177 NTSTATUS 178 Dispatch( 179 __inout MdIrp Irp 180 ); 181 182 _Must_inspect_result_ 183 NTSTATUS 184 Initialize( 185 __in PWDFDEVICE_INIT DeviceInit 186 ); 187 188 _Must_inspect_result_ 189 NTSTATUS 190 PostCreateDeviceInitialize( 191 __in PWDFDEVICE_INIT Init 192 ); 193 194 VOID 195 CreateCompleted( 196 __in FxIrp *Irp 197 ); 198 199 _Must_inspect_result_ 200 NTSTATUS 201 ConfigureForwarding( 202 __in FxIoQueue *FxQueue 203 ); 204 205 BOOLEAN 206 CanDestroyControlDevice( 207 VOID 208 ); 209 210 VOID 211 GetConstraintsHelper( 212 __out_opt WDF_EXECUTION_LEVEL* ExecutionLevel, 213 __out_opt WDF_SYNCHRONIZATION_SCOPE* SynchronizationScope 214 ) ; 215 216 FxCallbackLock* 217 GetCallbackLockPtrHelper( 218 __deref_out_opt FxObject** LockObject 219 ); 220 221 __inline 222 FxIoQueue* 223 GetDeafultInternalCreateQueue( 224 ) 225 { 226 return m_DefaultQueueForCreates; 227 } 228 }; 229 230 #endif // _FXPKGGENERAL_H_ 231