ReactOS  0.4.15-dev-2700-g4b4ffa9
fxmemorybufferfrompool.cpp
Go to the documentation of this file.
1 /*++
2 
3 Copyright (c) Microsoft Corporation
4 
5 Module Name:
6 
7  FxMemoryBufferFromPool.cpp
8 
9 Abstract:
10 
11  This module implements a frameworks managed FxMemoryBufferFromPool
12 
13 Author:
14 
15 
16 Environment:
17 
18  kernel mode only
19 
20 Revision History:
21 
22 --*/
23 
24 #include "coreprivshared.hpp"
25 
27  __in PFX_DRIVER_GLOBALS FxDriverGlobals,
28  __in size_t BufferSize
29  ) :
30  FxMemoryObject(FxDriverGlobals, sizeof(*this), BufferSize)
31 /*++
32 
33 Routine Description:
34  Constructor for this object.
35 
36 Arguments:
37  BufferSize - The buffer size associated with this object
38 
39 Return Value:
40  None
41 
42  --*/
43 {
44  m_Pool = NULL;
45 }
46 
48  __in PFX_DRIVER_GLOBALS FxDriverGlobals,
49  __in size_t BufferSize,
50  __in USHORT ObjectSize
51  ) :
52  FxMemoryObject(FxDriverGlobals, ObjectSize, BufferSize)
53 /*++
54 
55 Routine Description:
56  Constructor for this object.
57 
58 Arguments:
59  BufferSize - The buffer size associated with this object
60 
61  ObjectSize - size of the derived object
62 
63 Return Value:
64  None
65 
66  --*/
67 {
68  m_Pool = NULL;
69 }
70 
72 /*++
73 
74 Routine Description:
75  Destructor for this object. This function does nothing, it lets
76  SelfDestruct do all the work.
77 
78 Arguments:
79  None
80 
81 Return Value:
82  None
83 
84  --*/
85 {
86  if (m_Pool != NULL) {
88  }
89 }
90 
94  __in PFX_DRIVER_GLOBALS FxDriverGlobals,
98  __in size_t BufferSize,
100  )
101 {
105  BOOLEAN isPaged;
106 
107  isPaged = FxIsPagedPoolType(PoolType);
108 
109  if (isPaged) {
111  Attributes);
112  }
113  else {
114  pDeviceBase = NULL;
115  }
116 
117  //
118  // FxMemoryBufferFromPool can handle paged allocation as well. We only
119  // use FxMemoryPagedBufferFromPool if we have an FxDeviceBase that we can use
120  // in the dispose path, otherwise these 2 classes are the same.
121  //
122  if (pDeviceBase != NULL) {
123  ASSERT(isPaged);
124  pBuffer = new(FxDriverGlobals, Attributes)
126  }
127  else {
128  pBuffer = new(FxDriverGlobals, Attributes)
129  FxMemoryBufferFromPool(FxDriverGlobals, BufferSize);
130  }
131 
132  if (pBuffer == NULL) {
134  }
135 
137 
138  if (pBuffer->AllocateBuffer(PoolType, PoolTag) == FALSE) {
140  }
141 
142  if (!NT_SUCCESS(status)) {
143  pBuffer->DeleteFromFailedCreate();
144  return status;
145  }
146 
147  if (isPaged) {
148  //
149  // Callbacks might be a bit excessive (passive dispose is what we are
150  // really after) because this object has no callbacks, but this is being
151  // proactive in case any callbacks are added. If they are added, this
152  // will take care of them w/out additional changes to object setup.
153  //
154  pBuffer->MarkPassiveCallbacks(ObjectDoNotLock);
155  }
156 
157  *Buffer = pBuffer;
158 
159  return STATUS_SUCCESS;
160 }
BOOLEAN FxIsPagedPoolType(__in POOL_TYPE Type)
Definition: wdfpool.cpp:43
#define _Must_inspect_result_
Definition: no_sal2.h:62
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
FxDeviceBase * pDeviceBase
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
#define __in_opt
Definition: dbghelp.h:38
LONG NTSTATUS
Definition: precomp.h:26
static _Must_inspect_result_ NTSTATUS _Create(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in_opt PWDF_OBJECT_ATTRIBUTES Attributes, __in POOL_TYPE PoolType, __in ULONG PoolTag, __in size_t BufferSize, __out FxMemoryObject **Buffer)
static __inline VOID MxFreePool(__in PVOID Ptr)
Definition: mxmemorykm.h:41
static FxDeviceBase * _SearchForDevice(__in FxObject *Object, __out_opt IFxHasCallbacks **Callbacks)
#define FALSE
Definition: types.h:117
#define __out
Definition: dbghelp.h:62
unsigned char BOOLEAN
PVOID pBuffer
Definition: bufpool.h:45
#define ASSERT(a)
Definition: mode.c:44
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
INT POOL_TYPE
Definition: typedefs.h:78
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _In_ _Strict_type_match_ POOL_TYPE _In_opt_ ULONG PoolTag
Definition: wdfmemory.h:159
FxMemoryBufferFromPool(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in size_t BufferSize)
unsigned short USHORT
Definition: pedump.c:61
#define NULL
Definition: types.h:112
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ _Strict_type_match_ POOL_TYPE PoolType
Definition: wdfdevice.h:3810
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
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:251
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes
Definition: ps.c:97