ReactOS  0.4.15-dev-3453-gff89651
fxnpagedlookasidelistkm.cpp
Go to the documentation of this file.
1 /*++
2 
3 Copyright (c) Microsoft Corporation
4 
5 Module Name:
6 
7  FxNPagedLookasideList.cpp
8 
9 Abstract:
10 
11  This module implements a frameworks managed FxNPagedLookasideList
12 
13 Author:
14 
15 Environment:
16 
17  kernel mode only
18 
19 Revision History:
20 
21 
22 --*/
23 
24 #include "coreprivshared.hpp"
25 
28 
30  __in PFX_DRIVER_GLOBALS FxDriverGlobals,
32  ) :
33  FxLookasideList(FxDriverGlobals, sizeof(*this), PoolTag)
34 {
35 }
36 
38 {
39  if (m_MemoryObjectSize != 0) {
41  }
42 }
43 
47  __in size_t BufferSize,
49  )
50 {
52 
53  //
54  // This type of class does not support BufferSize greater than 0xFFFF.
55  // The verification below ensures this contract is respected in both
56  // free and chk builds.
57  //
58  if (BufferSize > MAXUSHORT) {
59  ASSERT(FALSE);
61  goto Done;
62  }
63 
67 
68  //
69  // Must be called after InitializeLookaside so that m_MemoryObjectSize is
70  // computed correctly.
71  //
72  if (NT_SUCCESS(status)) {
74 
75  //
76  // Initialize a non-paged pool with these characteristics.
77  //
79  NULL,
80  NULL,
81  0,
83  m_PoolTag,
84  0);
85  }
86 
87 Done:
88  return status;
89 }
90 
94  __out FxMemoryObject** PPMemory
95  )
96 {
98  PVOID p;
99 
100  if (PPMemory == NULL) {
102  }
103 
104  *PPMemory = NULL;
105 
106  //
107  // Get the raw memory allocation.
108  //
110  if (p == NULL) {
112  }
113 
114  p = InitObjectAlloc(p);
115 
116  //
117  // Construct new FxMemoryBufferFromLookaside
118  //
121 
122  //
123  // pBuffer might be displaced if there is a debug extension
124  //
125  ASSERT(_GetBase(pBuffer) == p);
126 
127  *PPMemory = pBuffer;
128 
129  return STATUS_SUCCESS;
130 }
131 
132 VOID
135  )
136 {
138 }
139 
141  __in PFX_DRIVER_GLOBALS FxDriverGlobals,
143  ) : FxLookasideListFromPool(FxDriverGlobals, sizeof(*this), PoolTag)
144 {
145 }
146 
148  VOID
149  )
150 {
151  if (m_MemoryObjectSize != 0) {
153  }
154 
155  if (m_BufferSize != 0) {
157  }
158 }
159 
161 NTSTATUS
163  __in size_t BufferSize,
165  )
166 {
168 
172 
173  if (!NT_SUCCESS(status)) {
174  return status;
175  }
176 
177  //
178  // Initialize a non-paged pool with these characteristics.
179  //
181  NULL,
182  NULL,
183  0,
185  m_PoolTag,
186  0);
187 
189 
190  //
191  // Initialize a non-paged pool with these characteristics.
192  //
193  // Free and Allocate are left intentionally NULL so that we use the Ex
194  // versions. We want to use the Ex versions because the allocations are >=
195  // PAGE_SIZE and we don't want to burn a whole page for pool tracking.
196  //
198  NULL,
199  NULL,
200  0,
201  m_BufferSize,
202  m_PoolTag,
203  0);
204 
205  return status;
206 }
207 
209 NTSTATUS
211  __out FxMemoryObject** PPMemory
212  )
213 {
215  PVOID pObj, pBuf;
216 
217  //
218  // Allocate the object which will contain the 2ndary allocation
219  //
221 
222  if (pObj == NULL) {
224  }
225 
226  pObj = InitObjectAlloc(pObj);
227 
228  //
229  // Create the 2ndary allocation (the one the driver writer uses), what will
230  // be FxMemoryBufferFromPoolLookaside::m_Pool below.
231  //
233  if (pBuf == NULL) {
234  //
235  // This case is safe because Reclaim doesn't treat the pointer as an
236  // object, rather it just performs pointer math and then frees the alloc
237  //
240  }
241 
242  //
243  // Construct a new FxMemoryBufferFromLookaside using the pool allocated
244  // above.
245  //
248  this,
249  m_BufferSize,
250  pBuf);
251 
252  //
253  // pBuffer might be displaced if there is a debug extension
254  //
255  ASSERT(_GetBase(pBuffer) == pObj);
256 
257  *PPMemory = pBuffer;
258 
259  return STATUS_SUCCESS;
260 }
261 
262 VOID
265  )
266 {
268 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
PVOID InitObjectAlloc(__out_bcount(this->m_MemoryObjectSize) PVOID Alloc)
virtual _Must_inspect_result_ NTSTATUS Allocate(__out FxMemoryObject **PPMemory)
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
static VOID _Reclaim(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __inout PNPAGED_LOOKASIDE_LIST List, __in FxMemoryBufferFromLookaside *Memory)
static PVOID _GetBase(__in FxObject *Object)
Definition: fxobject.hpp:418
_Must_inspect_result_ NTSTATUS InitializeLookaside(__in USHORT BufferSize, __in USHORT MemoryObjectSize, __in PWDF_OBJECT_ATTRIBUTES MemoryAttributes)
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
virtual _Must_inspect_result_ NTSTATUS Initialize(__in size_t BufferSize, __in PWDF_OBJECT_ATTRIBUTES MemoryAttributes)
__inline PVOID FxAllocateFromNPagedLookasideList(_In_ PNPAGED_LOOKASIDE_LIST Lookaside, _In_opt_ size_t ElementSize=0)
Definition: fxglobalskm.h:565
FxNPagedLookasideList(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in ULONG PoolTag)
#define FALSE
Definition: types.h:117
virtual VOID Reclaim(__in FxMemoryBufferFromLookaside *Memory)
#define __out
Definition: dbghelp.h:62
PVOID pBuffer
_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
#define STATUS_INVALID_BUFFER_SIZE
Definition: ntstatus.h:650
VOID NTAPI ExInitializeNPagedLookasideList(IN PNPAGED_LOOKASIDE_LIST Lookaside, IN PALLOCATE_FUNCTION Allocate OPTIONAL, IN PFREE_FUNCTION Free OPTIONAL, IN ULONG Flags, IN SIZE_T Size, IN ULONG Tag, IN USHORT Depth)
Definition: lookas.c:218
#define ASSERT(a)
Definition: mode.c:44
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NPAGED_LOOKASIDE_LIST m_ObjectLookaside
friend FxMemoryBufferFromLookaside
_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
#define _Must_inspect_result_
Definition: ms_sal.h:558
WDF_OBJECT_ATTRIBUTES m_MemoryAttributes
FxNPagedLookasideListFromPool(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in ULONG PoolTag)
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
Definition: fxobject.hpp:734
unsigned short USHORT
Definition: pedump.c:61
#define NULL
Definition: types.h:112
virtual _Must_inspect_result_ NTSTATUS Allocate(__out FxMemoryObject **PPMemory)
#define MAXUSHORT
Definition: typedefs.h:83
unsigned int ULONG
Definition: retypes.h:1
virtual VOID Reclaim(__in FxMemoryBufferFromLookaside *Memory)
#define STATUS_SUCCESS
Definition: shellext.h:65
GLfloat GLfloat p
Definition: glext.h:8902
VOID NTAPI ExDeleteNPagedLookasideList(IN PNPAGED_LOOKASIDE_LIST Lookaside)
Definition: lookas.c:170
#define __in
Definition: dbghelp.h:35
static SERVICE_STATUS status
Definition: service.c:31
#define BufferSize
Definition: mmc.h:75
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:251
virtual _Must_inspect_result_ NTSTATUS Initialize(__in size_t BufferSize, __in PWDF_OBJECT_ATTRIBUTES MemoryAttributes)
Definition: ps.c:97