ReactOS  0.4.15-dev-2700-g4b4ffa9
fxpoolinlines.hpp
Go to the documentation of this file.
1 /*++
2 
3 Copyright (c) Microsoft Corporation
4 
5 Module Name:
6 
7  FxPoolInlines.h
8 
9 Abstract:
10 
11  This module contains inline functions for pool
12 
13 Environment:
14 
15  kernel/user mode
16 
17 Revision History:
18 
19  Made it mode agnostic
20 
21 --*/
22 
23 #ifndef __FX_POOL_INLINES_HPP__
24 #define __FX_POOL_INLINES_HPP__
25 
26 extern "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 
78 VOID
79 __inline
82  __in PFX_POOL_TRACKER Tracker,
84  __in ULONG Tag,
85  __in PVOID Caller
86  )
87 /*++
88 
89 Routine Description:
90 
91  Format and insert a Tracker for a NonPaged allocation.
92 
93 Arguments:
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 
105 Returns:
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 
137 VOID
138 __inline
140  __in PFX_POOL_TRACKER Tracker
141  )
142 /*++
143 
144 Routine Description:
145 
146  Decommission a Tracker for a NonPaged allocation.
147 
148 Arguments:
149 
150  Tracker - Pointer to the formatted FX_POOL_TRACKER structure.
151 
152 Returns:
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 
170 VOID
171 __inline
174  __in PFX_POOL_TRACKER Tracker,
175  __in SIZE_T Size,
176  __in ULONG Tag,
177  __in PVOID Caller
178  )
179 /*++
180 
181 Routine Description:
182 
183  Format and insert a Tracker for a Paged allocation.
184 
185 Arguments:
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 
197 Returns:
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 
227 VOID
228 __inline
230  __in PFX_POOL_TRACKER Tracker
231  )
232 /*++
233 
234 Routine Description:
235 
236  Decommission a Tracker for a Paged allocation.
237 
238 Arguments:
239 
240  Tracker - Pointer to the formatted FX_POOL_TRACKER structure.
241 
242 Returns:
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__
#define _Must_inspect_result_
Definition: no_sal2.h:62
LONG NTSTATUS
Definition: precomp.h:26
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
KIRQL irql
Definition: wave.h:1
#define InsertTailList(ListHead, Entry)
VOID __inline FxPoolInsertNonPagedAllocateTracker(__in PFX_POOL Pool, __in PFX_POOL_TRACKER Tracker, __in SIZE_T Size, __in ULONG Tag, __in PVOID Caller)
VOID __inline FxPoolRemoveNonPagedAllocateTracker(__in PFX_POOL_TRACKER Tracker)
VOID __inline FxPoolRemovePagedAllocateTracker(__in PFX_POOL_TRACKER Tracker)
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
UCHAR KIRQL
Definition: env_spec_w32.h:591
Definition: fxpool.h:63
#define __out
Definition: dbghelp.h:62
#define TRACINGDEVICE
Definition: dbgtrace.h:58
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Definition: bufpool.h:50
_Must_inspect_result_ NTSTATUS __inline FxPoolAddHeaderSize(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in size_t AllocationSize, __out size_t *NewSize)
_Must_inspect_result_ _In_ USHORT NewSize
Definition: fltkernel.h:975
_Must_inspect_result_ _In_ WDFDEVICE _In_ BOOLEAN _In_opt_ PVOID Tag
Definition: wdfdevice.h:4061
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
IN PFCB IN PFILE_OBJECT FileObject IN ULONG AllocationSize
Definition: fatprocs.h:319
ULONG_PTR SIZE_T
Definition: typedefs.h:80
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
size_t total
VOID __inline FxPoolInsertPagedAllocateTracker(__in PFX_POOL Pool, __in PFX_POOL_TRACKER Tracker, __in SIZE_T Size, __in ULONG Tag, __in PVOID Caller)
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_SUCCESS
Definition: shellext.h:65
#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 FX_POOL_HEADER_SIZE
Definition: fxpool.h:53
Definition: ps.c:97