1 /*++ 2 3 Copyright (c) Microsoft. All rights reserved. 4 5 Module Name: 6 7 FxRequestBuffer.hpp 8 9 Abstract: 10 11 Author: 12 13 14 15 Environment: 16 17 Both kernel and user mode 18 19 Revision History: 20 21 --*/ 22 23 #ifndef _FXREQUESTBUFFER_H_ 24 #define _FXREQUESTBUFFER_H_ 25 26 enum FxRequestBufferType { 27 FxRequestBufferUnspecified, 28 FxRequestBufferMemory, // framework managed memory 29 FxRequestBufferMdl, // raw MDL 30 FxRequestBufferBuffer, // raw PVOID 31 FxRequestBufferReferencedMdl, // MDL belonging to a FxMemoryObject 32 }; 33 34 enum FxValidateMemoryDescriptorFlags { 35 MemoryDescriptorNullAllowed = 0x1, 36 MemoryDescriptorNoBufferAllowed = 0x2, 37 }; 38 39 struct FxRequestBuffer { 40 public: 41 FxRequestBuffer(VOID); 42 43 NTSTATUS 44 ValidateMemoryDescriptor( 45 __in PFX_DRIVER_GLOBALS FxDriverGlobals, 46 __in PWDF_MEMORY_DESCRIPTOR Descriptor, 47 __in ULONG Flags = 0x0 48 ); 49 50 VOID 51 SetMemory( 52 __in IFxMemory* Memory, 53 __in PWDFMEMORY_OFFSET Offsets 54 ); 55 56 VOID 57 SetMdl( 58 __in PMDL Mdl, 59 __in ULONG Length 60 ); 61 62 __inline 63 VOID 64 SetBuffer( 65 __in PVOID Buffer, 66 __in ULONG Length 67 ) 68 { 69 DataType = FxRequestBufferBuffer; 70 u.Buffer.Buffer = Buffer; 71 u.Buffer.Length = Length; 72 } 73 74 __inline 75 BOOLEAN 76 HasMdl( 77 VOID 78 ) 79 { 80 return (DataType == FxRequestBufferMdl || 81 DataType == FxRequestBufferReferencedMdl) ? TRUE : FALSE; 82 } 83 84 ULONG 85 GetBufferLength( 86 VOID 87 ); 88 89 _Must_inspect_result_ 90 NTSTATUS 91 GetBuffer( 92 __deref_out PVOID* Buffer 93 ); 94 95 _Must_inspect_result_ 96 NTSTATUS 97 GetOrAllocateMdl( 98 __in PFX_DRIVER_GLOBALS FxDriverGlobals, 99 __deref_out_opt PMDL* Mdl, 100 __inout PMDL* MdlToFree, 101 __inout PBOOLEAN UnlockWhenFreed, 102 __in LOCK_OPERATION Operation, 103 __in BOOLEAN ReuseMdl = FALSE, 104 __inout_opt size_t* SizeOfMdl = NULL 105 ); 106 107 NTSTATUS 108 GetOrAllocateMdlWorker( 109 __in PFX_DRIVER_GLOBALS FxDriverGlobals, 110 __deref_out PMDL* Mdl, 111 __in BOOLEAN * ReuseMdl, 112 __in LONG Length, 113 __in PVOID Buffer, 114 __inout size_t* SizeOfMdl, 115 __in BOOLEAN UnlockWhenFreed, 116 __deref_out_opt PMDL* MdlToFree 117 ); 118 119 VOID 120 AssignValues( 121 __deref_out_opt PVOID* PPBuffer, 122 __deref_out_opt PMDL* PPMdl, 123 __out PULONG BufferLength 124 ); 125 126 public: 127 FxRequestBufferType DataType; 128 129 union { 130 struct { 131 IFxMemory* Memory; 132 PWDFMEMORY_OFFSET Offsets; 133 } Memory; 134 struct { 135 PMDL Mdl; 136 ULONG Length; 137 } Mdl; 138 struct { 139 PVOID Buffer; 140 ULONG Length; 141 } Buffer; 142 struct { 143 IFxMemory* Memory; 144 PWDFMEMORY_OFFSET Offsets; 145 PMDL Mdl; 146 } RefMdl; 147 } u; 148 }; 149 150 #if ((FX_CORE_MODE)==(FX_CORE_KERNEL_MODE)) 151 #include "fxrequestbufferkm.hpp" 152 #elif ((FX_CORE_MODE)==(FX_CORE_USER_MODE)) 153 #include "fxrequestbufferum.hpp" 154 #endif 155 156 157 #endif // _FXREQUESTBUFFER_H_ 158