1 /*++ 2 3 Copyright (c) Microsoft Corporation 4 5 Module Name: 6 7 FxLookasideList.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 _FXLOOKASIDELIST_H_ 23 #define _FXLOOKASIDELIST_H_ 24 25 class FxLookasideList : public FxObject { 26 27 friend FxMemoryBufferFromLookaside; 28 29 public: 30 FxLookasideList( 31 __in PFX_DRIVER_GLOBALS FxDriverGlobals, 32 __in USHORT ObjectSize, 33 __in ULONG PoolTag 34 ); 35 36 virtual 37 _Must_inspect_result_ 38 NTSTATUS 39 Initialize( 40 __in size_t BufferSize, 41 __in PWDF_OBJECT_ATTRIBUTES MemoryAttributes 42 ) =0; 43 44 virtual 45 _Must_inspect_result_ 46 NTSTATUS 47 Allocate( 48 __out FxMemoryObject** PPMemory 49 ) =0; 50 51 size_t GetBufferSize(VOID)52 GetBufferSize( 53 VOID 54 ) 55 { 56 return m_BufferSize; 57 } 58 59 protected: 60 virtual 61 ~FxLookasideList( 62 ); 63 64 // 65 // Function used by IFxMemoryBuffer to return itself to the lookaside list 66 // 67 virtual 68 VOID 69 Reclaim( 70 __in FxMemoryBufferFromLookaside* Memory 71 ) =0; 72 73 _Must_inspect_result_ 74 NTSTATUS 75 InitializeLookaside( 76 __in USHORT BufferSize, 77 __in USHORT MemoryObjectSize, 78 __in PWDF_OBJECT_ATTRIBUTES MemoryAttributes 79 ); 80 81 PVOID 82 InitObjectAlloc( 83 __out_bcount(this->m_MemoryObjectSize) PVOID Alloc 84 ); 85 86 static 87 VOID 88 _Reclaim( 89 __in PFX_DRIVER_GLOBALS FxDriverGlobals, 90 __inout PNPAGED_LOOKASIDE_LIST List, 91 __in FxMemoryBufferFromLookaside* Memory 92 ); 93 94 public: 95 WDF_OBJECT_ATTRIBUTES m_MemoryAttributes; 96 97 protected: 98 size_t m_BufferSize; 99 100 size_t m_MemoryObjectSize; 101 102 ULONG m_PoolTag; 103 }; 104 105 class FxLookasideListFromPool : public FxLookasideList { 106 friend FxMemoryBufferFromPoolLookaside; 107 108 public: FxLookasideListFromPool(__in PFX_DRIVER_GLOBALS FxDriverGlobals,__in USHORT ObjectSize,__in ULONG PoolTag)109 FxLookasideListFromPool( 110 __in PFX_DRIVER_GLOBALS FxDriverGlobals, 111 __in USHORT ObjectSize, 112 __in ULONG PoolTag 113 ) : FxLookasideList(FxDriverGlobals, ObjectSize, PoolTag) 114 { 115 } 116 117 protected: 118 virtual 119 VOID 120 ReclaimPool( 121 __inout PVOID Pool 122 ) =0; 123 }; 124 125 126 #endif // _FXLOOKASIDELIST_H_ 127