ReactOS 0.4.16-dev-319-g6cf4263
fxlookasidelist.cpp
Go to the documentation of this file.
1/*++
2
3Copyright (c) Microsoft Corporation
4
5Module Name:
6
7 FxLookasideList.cpp
8
9Abstract:
10
11 This module implements a frameworks managed FxLookasideList
12
13Author:
14
15
16Environment:
17
18 kernel mode only
19
20Revision 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
36Routine Description:
37 Constructor for FxLookasideList
38
39Arguments:
40 ObjectSize - Size of the derived object.
41
42 PoolTag - Tag to use when allocating memory.
43
44Return Value:
45 None
46
47 --*/
48{
49}
50
52/*++
53
54Routine 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
59Arguments:
60 None
61
62Return Value:
63 None
64
65 --*/
66{
67}
68
73 __in USHORT MemoryObjectSize,
75 )
76/*++
77
78Routine 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
83Arguments:
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
91Return 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,
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)
146PVOID
148 __out_bcount(this->m_MemoryObjectSize) PVOID Alloc
149 )
150/*++
151
152Routine Description:
153 Initializes the object allocation so that it can be tracked and inserted
154 in this drivers POOL.
155
156Arguments:
157 Alloc - the raw allocation
158
159Return 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,
189 m_PoolTag,
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
205VOID
207 __in PFX_DRIVER_GLOBALS FxDriverGlobals,
210 )
211{
213
214 pHeader = FxObject::_CleanupPointer(FxDriverGlobals, (FxObject*) Memory);
215
217}
LONG NTSTATUS
Definition: precomp.h:26
PVOID Alloc(IN DWORD dwFlags, IN SIZE_T dwBytes)
Definition: main.c:63
PVOID InitObjectAlloc(__out_bcount(this->m_MemoryObjectSize) PVOID Alloc)
FxLookasideList(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in USHORT ObjectSize, __in ULONG PoolTag)
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 ~FxLookasideList()
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
Definition: fxobject.hpp:734
static PFX_POOL_HEADER _CleanupPointer(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in FxObject *Object)
Definition: fxobject.hpp:1273
#define __in
Definition: dbghelp.h:35
#define __out_bcount(x)
Definition: dbghelp.h:68
#define __inout
Definition: dbghelp.h:50
#define BufferSize
Definition: mmc.h:75
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
PFX_DRIVER_GLOBALS pFxDriverGlobals
__inline VOID FxFreeToNPagedLookasideList(__in PNPAGED_LOOKASIDE_LIST Lookaside, __in PVOID Entry)
Definition: fxglobalskm.h:611
_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
FX_POOL_TRACKER * PFX_POOL_TRACKER
Definition: fxpool.h:109
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)
VOID __inline FxPoolInsertNonPagedAllocateTracker(__in PFX_POOL Pool, __in PFX_POOL_TRACKER Tracker, __in SIZE_T Size, __in ULONG Tag, __in PVOID Caller)
@ FX_TYPE_LOOKASIDE
Definition: fxtypes.h:54
GLsizeiptr size
Definition: glext.h:5919
FxContextHeader * pHeader
Definition: handleapi.cpp:604
#define _ReturnAddress()
Definition: intrin_arm.h:35
#define _Must_inspect_result_
Definition: no_sal2.h:62
unsigned short USHORT
Definition: pedump.c:61
FX_POOL FxPoolFrameworks
Definition: fxglobals.h:388
BOOLEAN IsPoolTrackingOn(VOID)
Definition: fxglobals.h:215
Definition: ps.c:97
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG
Definition: typedefs.h:59
#define WDF_PTR_ADD_OFFSET_TYPE(_ptr, _offset, _type)
Definition: wdfcore.h:141
_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
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
struct LOOKASIDE_ALIGN _NPAGED_LOOKASIDE_LIST * PNPAGED_LOOKASIDE_LIST