ReactOS 0.4.15-dev-7942-gd23573b
fxpoolinlines.hpp
Go to the documentation of this file.
1/*++
2
3Copyright (c) Microsoft Corporation
4
5Module Name:
6
7 FxPoolInlines.h
8
9Abstract:
10
11 This module contains inline functions for pool
12
13Environment:
14
15 kernel/user mode
16
17Revision History:
18
19 Made it mode agnostic
20
21--*/
22
23#ifndef __FX_POOL_INLINES_HPP__
24#define __FX_POOL_INLINES_HPP__
25
26extern "C" {
27
28#if defined(EVENT_TRACING)
29#include "FxPoolInlines.hpp.tmh"
30#endif
31
32}
33
36__inline
38 __in PFX_DRIVER_GLOBALS FxDriverGlobals,
39 __in size_t AllocationSize,
40 __out size_t* NewSize
41 )
42{
44 size_t total;
45
47
48 //
49 // sizeof(FX_POOL_HEADER) is too large since it will contain enough memory
50 // for AllocationStart which we compute on our own.
51 //
52 status = RtlSizeTAdd(total, FX_POOL_HEADER_SIZE, &total);
53
54 if (!NT_SUCCESS(status)) {
56 FxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGDEVICE,
57 "Size overflow, could not add pool header, %!STATUS!", status);
58
59 return status;
60 }
61
62 if (FxDriverGlobals->IsPoolTrackingOn()) {
63 status = RtlSizeTAdd(total, sizeof(FX_POOL_TRACKER), &total);
64
65 if (!NT_SUCCESS(status)) {
67 FxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGDEVICE,
68 "Size overflow, could not add pool tracker, %!STATUS!", status);
69 return status;
70 }
71 }
72
73 *NewSize = total;
74
75 return STATUS_SUCCESS;
76}
77
78VOID
79__inline
82 __in PFX_POOL_TRACKER Tracker,
85 __in PVOID Caller
86 )
87/*++
88
89Routine Description:
90
91 Format and insert a Tracker for a NonPaged allocation.
92
93Arguments:
94
95 Pool - Pointer to FX_POOL structure
96
97 Tracker - Pointer to raw FX_POOL_TRACKER structure.
98
99 Size - Size in bytes of the allocation
100
101 Tag - Caller specified additional tag value for debugging/tracing
102
103 Caller - Caller's address
104
105Returns:
106
107 VOID
108
109--*/
110{
111 KIRQL irql;
112
113 Tracker->Tag = Tag;
114 Tracker->PoolType = NonPagedPool;
115 Tracker->Pool = Pool;
116 Tracker->Size = Size;
117 Tracker->CallersAddress = Caller;
118
119 Pool->NonPagedLock.Acquire(&irql);
120
121 InsertTailList(&Pool->NonPagedHead, &Tracker->Link);
122
123 Pool->NonPagedBytes += Size;
124 Pool->NonPagedAllocations++;
125
126 if( Pool->NonPagedBytes > Pool->PeakNonPagedBytes ) {
127 Pool->PeakNonPagedBytes = Pool->NonPagedBytes;
128 }
129
130 if( Pool->NonPagedAllocations > Pool->PeakNonPagedAllocations ) {
131 Pool->PeakNonPagedAllocations = Pool->NonPagedAllocations;
132 }
133
134 Pool->NonPagedLock.Release(irql);
135}
136
137VOID
138__inline
140 __in PFX_POOL_TRACKER Tracker
141 )
142/*++
143
144Routine Description:
145
146 Decommission a Tracker for a NonPaged allocation.
147
148Arguments:
149
150 Tracker - Pointer to the formatted FX_POOL_TRACKER structure.
151
152Returns:
153
154 VOID
155
156--*/
157{
158 KIRQL irql;
159
160 Tracker->Pool->NonPagedLock.Acquire(&irql);
161
162 RemoveEntryList(&Tracker->Link);
163
164 Tracker->Pool->NonPagedBytes -= Tracker->Size;
165 Tracker->Pool->NonPagedAllocations--;
166
167 Tracker->Pool->NonPagedLock.Release(irql);
168}
169
170VOID
171__inline
174 __in PFX_POOL_TRACKER Tracker,
176 __in ULONG Tag,
177 __in PVOID Caller
178 )
179/*++
180
181Routine Description:
182
183 Format and insert a Tracker for a Paged allocation.
184
185Arguments:
186
187 Pool - Pointer to FX_POOL structure
188
189 Tracker - Pointer to raw FX_POOL_TRACKER structure.
190
191 Size - Size in bytes of the allocation
192
193 Tag - Caller specified additional tag value for debugging/tracing
194
195 Caller - Caller's address
196
197Returns:
198
199 VOID
200
201--*/
202{
203 Tracker->Tag = Tag;
204 Tracker->PoolType = PagedPool;
205 Tracker->Pool = Pool;
206 Tracker->Size = Size;
207 Tracker->CallersAddress = Caller;
208
209 Pool->PagedLock.Acquire();
210
211 InsertTailList(&Pool->PagedHead, &Tracker->Link);
212
213 Pool->PagedBytes += Size;
214 Pool->PagedAllocations++;
215
216 if( Pool->PagedBytes > Pool->PeakPagedBytes ) {
217 Pool->PeakPagedBytes = Pool->PagedBytes;
218 }
219
220 if( Pool->PagedAllocations > Pool->PeakPagedAllocations ) {
221 Pool->PeakPagedAllocations = Pool->PagedAllocations;
222 }
223
224 Pool->PagedLock.Release();
225}
226
227VOID
228__inline
230 __in PFX_POOL_TRACKER Tracker
231 )
232/*++
233
234Routine Description:
235
236 Decommission a Tracker for a Paged allocation.
237
238Arguments:
239
240 Tracker - Pointer to the formatted FX_POOL_TRACKER structure.
241
242Returns:
243
244 VOID
245
246--*/
247{
248 Tracker->Pool->PagedLock.Acquire();
249
250 RemoveEntryList(&Tracker->Link);
251
252 Tracker->Pool->PagedBytes -= Tracker->Size;
253 Tracker->Pool->PagedAllocations--;
254
255 Tracker->Pool->PagedLock.Release();
256}
257
258#endif // __FX_POOL_INLINES_HPP__
LONG NTSTATUS
Definition: precomp.h:26
Definition: bufpool.h:50
#define __in
Definition: dbghelp.h:35
#define __out
Definition: dbghelp.h:62
#define TRACINGDEVICE
Definition: dbgtrace.h:58
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
KIRQL irql
Definition: wave.h:1
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
#define InsertTailList(ListHead, Entry)
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define NonPagedPool
Definition: env_spec_w32.h:307
#define PagedPool
Definition: env_spec_w32.h:308
IN PFCB IN PFILE_OBJECT FileObject IN ULONG AllocationSize
Definition: fatprocs.h:322
_Must_inspect_result_ _In_ USHORT NewSize
Definition: fltkernel.h:975
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
#define FX_POOL_HEADER_SIZE
Definition: fxpool.h:53
FX_POOL_TRACKER * PFX_POOL_TRACKER
Definition: fxpool.h:109
VOID __inline FxPoolRemoveNonPagedAllocateTracker(__in PFX_POOL_TRACKER Tracker)
_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)
VOID __inline FxPoolRemovePagedAllocateTracker(__in PFX_POOL_TRACKER Tracker)
VOID __inline FxPoolInsertPagedAllocateTracker(__in PFX_POOL Pool, __in PFX_POOL_TRACKER Tracker, __in SIZE_T Size, __in ULONG Tag, __in PVOID Caller)
size_t total
#define _Must_inspect_result_
Definition: ms_sal.h:558
#define STATUS_SUCCESS
Definition: shellext.h:65
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
Definition: fxpool.h:63
Definition: ps.c:97
ULONG_PTR SIZE_T
Definition: typedefs.h:80
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFDEVICE _In_ BOOLEAN _In_opt_ PVOID Tag
Definition: wdfdevice.h:4065
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533