1 /*++ 2 3 Copyright (c) Microsoft Corporation 4 5 Module Name: 6 7 FxMemoryBuffer.hpp 8 9 Abstract: 10 11 Author: 12 13 Environment: 14 15 kernel mode only 16 17 Revision History: 18 19 20 --*/ 21 22 #ifndef _FXMEMORYBUFFER_H_ 23 #define _FXMEMORYBUFFER_H_ 24 25 class FxMemoryBuffer : public FxMemoryObject { 26 27 public: 28 29 // Factory function 30 static 31 _Must_inspect_result_ 32 NTSTATUS 33 _Create( 34 __in PFX_DRIVER_GLOBALS DriverGlobals, 35 __in_opt PWDF_OBJECT_ATTRIBUTES Attributes, 36 __in ULONG PoolTag, 37 __in size_t BufferSize, 38 __in POOL_TYPE PoolType, 39 __out FxMemoryObject** Object 40 ); 41 42 FxMemoryBuffer( 43 __in PFX_DRIVER_GLOBALS FxDriverGlobals, 44 __in size_t BufferSize 45 ); 46 47 PVOID 48 GetBuffer( 49 VOID 50 ); 51 52 PVOID 53 __inline 54 operator new( 55 __in size_t Size, 56 __in PFX_DRIVER_GLOBALS FxDriverGlobals, 57 __in_opt PWDF_OBJECT_ATTRIBUTES Attributes, 58 __in USHORT ExtraSize, 59 __in ULONG Tag, 60 __in POOL_TYPE PoolType 61 ) 62 { 63 // 64 // PoolType must be non paged pool but it can be NonPagedPool 65 // or NonPagedPoolNx or their variants 66 // 67 ASSERT(!FxIsPagedPoolType(PoolType)); 68 69 // 70 // Specialize operator new so that we can use the caller's tag when 71 // making the object allocation vs using the default driver-wide tag. 72 // 73 return FxObjectHandleAlloc(FxDriverGlobals, 74 PoolType, 75 Size, 76 Tag, 77 Attributes, 78 ExtraSize, 79 FxObjectTypeExternal); 80 } 81 82 protected: 83 84 FxMemoryBuffer( 85 __in PFX_DRIVER_GLOBALS FxDriverGlobals, 86 __in USHORT ObjectSize, 87 __in size_t BufferSize 88 ); 89 90 ~FxMemoryBuffer(); 91 }; 92 93 #endif // _FXMEMORYBUFFER_H_ 94