ReactOS 0.4.15-dev-8058-ga7cbb60
fxnpagedlookasidelistkm.cpp
Go to the documentation of this file.
1/*++
2
3Copyright (c) Microsoft Corporation
4
5Module Name:
6
7 FxNPagedLookasideList.cpp
8
9Abstract:
10
11 This module implements a frameworks managed FxNPagedLookasideList
12
13Author:
14
15Environment:
16
17 kernel mode only
18
19Revision 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) {
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,
84 0);
85 }
86
87Done:
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
115
116 //
117 // Construct new FxMemoryBufferFromLookaside
118 //
121
122 //
123 // pBuffer might be displaced if there is a debug extension
124 //
126
127 *PPMemory = pBuffer;
128
129 return STATUS_SUCCESS;
130}
131
132VOID
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
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,
202 m_PoolTag,
203 0);
204
205 return status;
206}
207
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,
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
262VOID
265 )
266{
268}
LONG NTSTATUS
Definition: precomp.h:26
PVOID InitObjectAlloc(__out_bcount(this->m_MemoryObjectSize) PVOID Alloc)
friend FxMemoryBufferFromLookaside
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)
WDF_OBJECT_ATTRIBUTES m_MemoryAttributes
virtual _Must_inspect_result_ NTSTATUS Initialize(__in size_t BufferSize, __in PWDF_OBJECT_ATTRIBUTES MemoryAttributes)
virtual VOID Reclaim(__in FxMemoryBufferFromLookaside *Memory)
FxNPagedLookasideListFromPool(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in ULONG PoolTag)
virtual _Must_inspect_result_ NTSTATUS Allocate(__out FxMemoryObject **PPMemory)
virtual VOID Reclaim(__in FxMemoryBufferFromLookaside *Memory)
NPAGED_LOOKASIDE_LIST m_ObjectLookaside
virtual _Must_inspect_result_ NTSTATUS Allocate(__out FxMemoryObject **PPMemory)
FxNPagedLookasideList(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in ULONG PoolTag)
virtual _Must_inspect_result_ NTSTATUS Initialize(__in size_t BufferSize, __in PWDF_OBJECT_ATTRIBUTES MemoryAttributes)
static PVOID _GetBase(__in FxObject *Object)
Definition: fxobject.hpp:418
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
Definition: fxobject.hpp:734
#define __in
Definition: dbghelp.h:35
#define __out
Definition: dbghelp.h:62
#define BufferSize
Definition: mmc.h:75
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
__inline PVOID FxAllocateFromNPagedLookasideList(_In_ PNPAGED_LOOKASIDE_LIST Lookaside, _In_opt_ size_t ElementSize=0)
Definition: fxglobalskm.h:565
GLfloat GLfloat p
Definition: glext.h:8902
VOID NTAPI ExDeleteNPagedLookasideList(IN PNPAGED_LOOKASIDE_LIST Lookaside)
Definition: lookas.c:170
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 _Must_inspect_result_
Definition: ms_sal.h:558
#define STATUS_INVALID_BUFFER_SIZE
Definition: ntstatus.h:650
unsigned short USHORT
Definition: pedump.c:61
PVOID pBuffer
#define STATUS_SUCCESS
Definition: shellext.h:65
Definition: ps.c:97
#define MAXUSHORT
Definition: typedefs.h:83
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _In_ _In_ _Strict_type_match_ POOL_TYPE _In_opt_ PWDF_OBJECT_ATTRIBUTES MemoryAttributes
Definition: wdfmemory.h:409
_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
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _In_ _Strict_type_match_ POOL_TYPE _In_opt_ ULONG PoolTag
Definition: wdfmemory.h:164
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList