ReactOS  0.4.15-dev-3294-ge98684e
fxlookasidelist.cpp
Go to the documentation of this file.
1 /*++
2 
3 Copyright (c) Microsoft Corporation
4 
5 Module Name:
6 
7  FxLookasideList.cpp
8 
9 Abstract:
10 
11  This module implements a frameworks managed FxLookasideList
12 
13 Author:
14 
15 
16 Environment:
17 
18  kernel mode only
19 
20 Revision History:
21 
22 --*/
23 
24 #include "coreprivshared.hpp"
25 #include "fxlookasidelist.hpp"
26 
28  __in PFX_DRIVER_GLOBALS FxDriverGlobals,
29  __in USHORT ObjectSize,
31  ) :
32  FxObject(FX_TYPE_LOOKASIDE, ObjectSize, FxDriverGlobals),
33  m_BufferSize(0), m_PoolTag(PoolTag), m_MemoryObjectSize(0)
34 /*++
35 
36 Routine Description:
37  Constructor for FxLookasideList
38 
39 Arguments:
40  ObjectSize - Size of the derived object.
41 
42  PoolTag - Tag to use when allocating memory.
43 
44 Return Value:
45  None
46 
47  --*/
48 {
49 }
50 
52 /*++
53 
54 Routine Description:
55  Destructor for FxLookasideList. Default implementation does nothing.
56  Derived classes will call the appropriate NTOS export to remove itself from
57  the list of lookaside lists.
58 
59 Arguments:
60  None
61 
62 Return Value:
63  None
64 
65  --*/
66 {
67 }
68 
73  __in USHORT MemoryObjectSize,
75  )
76 /*++
77 
78 Routine Description:
79  Computes the memory object size to be used by the derived class. This
80  function handles the overflow in computing the size and returns an error
81  if that occurs.
82 
83 Arguments:
84  BufferSize - the length of the buffer being allocated alongside the object
85 
86  MemoryObjectSize - the raw size of the FxObject derived object, ie
87  sizeof(FxMemoryBufferFromLookaside)
88 
89  MemoryAttributes - attributes to be associated for each memory object created
90 
91 Return Value:
92  None
93 
94  --*/
95 {
96  size_t size;
98 
99  if (MemoryAttributes != NULL) {
102  sizeof(m_MemoryAttributes));
103  }
104  else {
106  }
107 
109  MemoryObjectSize,
110  BufferSize,
112  &size);
113 
114  if (!NT_SUCCESS(status)) {
115  //
116  // FxCalculateObjectTotalSize logs an error to the IFR
117  //
118  return status;
119  }
120 
122  if (!NT_SUCCESS(status)) {
123  //
124  // FxPoolAddHeaderSize logs to the IFR on error
125  //
126  return status;
127  }
128 
129  //
130  // It is *required* to set these values only once we know we are returning
131  // success b/c the derived classes use == 0 as an indication that Initialization
132  // failed and that any associated lookaside lists were not initialized.
133  //
136 
137  return status;
138 }
139 
140 #pragma prefast(push)
141 
142 
143 
144 //This routine intentionally accesses the header of the allocated memory.
145 #pragma prefast(disable:__WARNING_POTENTIAL_BUFFER_OVERFLOW_HIGH_PRIORITY)
146 PVOID
148  __out_bcount(this->m_MemoryObjectSize) PVOID Alloc
149  )
150 /*++
151 
152 Routine Description:
153  Initializes the object allocation so that it can be tracked and inserted
154  in this drivers POOL.
155 
156 Arguments:
157  Alloc - the raw allocation
158 
159 Return Value:
160  the start of where the object memory should be, not necessarily == Alloc
161 
162  --*/
163 {
166  PFX_POOL_TRACKER tracker;
167 
169 
171 
173  //
174  // PoolTracking is active, so format and insert
175  // a tracker in the NonPagedHeader list of the pool.
176  //
177  tracker = (PFX_POOL_TRACKER) Alloc;
179  sizeof(FX_POOL_TRACKER),
181 
182  pHeader->Base = Alloc;
183  pHeader->FxDriverGlobals = pFxDriverGlobals;
184 
187  tracker,
188  m_BufferSize,
189  m_PoolTag,
190  _ReturnAddress());
191  }
192  else {
193  //
194  // PoolTracking is inactive, only format FX_POOL_HEADER area.
195  //
197  pHeader->Base = Alloc;
198  pHeader->FxDriverGlobals = pFxDriverGlobals;
199  }
200 
201  return &pHeader->AllocationStart[0];
202 }
203 #pragma prefast(pop)
204 
205 VOID
207  __in PFX_DRIVER_GLOBALS FxDriverGlobals,
210  )
211 {
213 
214  pHeader = FxObject::_CleanupPointer(FxDriverGlobals, (FxObject*) Memory);
215 
217 }
FxLookasideList(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in USHORT ObjectSize, __in ULONG PoolTag)
PVOID InitObjectAlloc(__out_bcount(this->m_MemoryObjectSize) PVOID Alloc)
static VOID _Reclaim(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __inout PNPAGED_LOOKASIDE_LIST List, __in FxMemoryBufferFromLookaside *Memory)
_Must_inspect_result_ NTSTATUS InitializeLookaside(__in USHORT BufferSize, __in USHORT MemoryObjectSize, __in PWDF_OBJECT_ATTRIBUTES MemoryAttributes)
#define __out_bcount(x)
Definition: dbghelp.h:68
LONG NTSTATUS
Definition: precomp.h:26
VOID __inline FxPoolInsertNonPagedAllocateTracker(__in PFX_POOL Pool, __in PFX_POOL_TRACKER Tracker, __in SIZE_T Size, __in ULONG Tag, __in PVOID Caller)
static PFX_POOL_HEADER _CleanupPointer(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in FxObject *Object)
Definition: fxobject.hpp:1273
struct LOOKASIDE_ALIGN _NPAGED_LOOKASIDE_LIST * PNPAGED_LOOKASIDE_LIST
FX_POOL FxPoolFrameworks
Definition: fxglobals.h:388
BOOLEAN IsPoolTrackingOn(VOID)
Definition: fxglobals.h:215
FxContextHeader * pHeader
Definition: handleapi.cpp:604
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _In_ _Strict_type_match_ POOL_TYPE _In_opt_ ULONG _In_ _Out_ WDFMEMORY * Memory
Definition: wdfmemory.h:169
GLsizeiptr size
Definition: glext.h:5919
PFX_DRIVER_GLOBALS pFxDriverGlobals
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
PVOID Alloc(IN DWORD dwFlags, IN SIZE_T dwBytes)
Definition: main.c:63
FX_POOL_HEADER * PFX_POOL_HEADER
Definition: fxpool.h:51
_Must_inspect_result_ NTSTATUS __inline FxPoolAddHeaderSize(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in size_t AllocationSize, __out size_t *NewSize)
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _In_ _Strict_type_match_ POOL_TYPE _In_opt_ ULONG PoolTag
Definition: wdfmemory.h:159
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _In_ _In_ _Strict_type_match_ POOL_TYPE _In_opt_ PWDF_OBJECT_ATTRIBUTES MemoryAttributes
Definition: wdfmemory.h:407
_Must_inspect_result_ NTSTATUS FxCalculateObjectTotalSize(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in USHORT RawObjectSize, __in USHORT ExtraSize, __in_opt PWDF_OBJECT_ATTRIBUTES Attributes, __out size_t *Total)
Definition: handleapi.cpp:147
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
#define __inout
Definition: dbghelp.h:50
__inline VOID FxFreeToNPagedLookasideList(__in PNPAGED_LOOKASIDE_LIST Lookaside, __in PVOID Entry)
Definition: fxglobalskm.h:611
#define _Must_inspect_result_
Definition: ms_sal.h:558
WDF_OBJECT_ATTRIBUTES m_MemoryAttributes
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
Definition: fxobject.hpp:734
unsigned short USHORT
Definition: pedump.c:61
#define NULL
Definition: types.h:112
virtual ~FxLookasideList()
void * _ReturnAddress(void)
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define __in
Definition: dbghelp.h:35
static SERVICE_STATUS status
Definition: service.c:31
FX_POOL_TRACKER * PFX_POOL_TRACKER
Definition: fxpool.h:107
#define BufferSize
Definition: mmc.h:75
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:251
#define WDF_PTR_ADD_OFFSET_TYPE(_ptr, _offset, _type)
Definition: wdfcore.h:141
Definition: ps.c:97