ReactOS  0.4.15-dev-2703-g05fb0f1
fxmemorybuffer.cpp
Go to the documentation of this file.
1 /*++
2 
3 Copyright (c) Microsoft Corporation
4 
5 Module Name:
6 
7  FxMemoryBuffer.cpp
8 
9 Abstract:
10 
11  This module implements a frameworks managed FxMemoryBuffer
12 
13 Author:
14 
15 Environment:
16 
17  kernel mode only
18 
19 Revision History:
20 
21 --*/
22 
23 #include "coreprivshared.hpp"
24 #include "fxmemorybuffer.hpp"
25 
26 extern "C" {
27 // #include "FxMemoryBuffer.tmh"
28 }
29 
36  __in size_t BufferSize,
39  )
40 {
42 
45 
46  if (pBuffer == NULL) {
48  }
49 
50  *Object = pBuffer;
51 
52  return STATUS_SUCCESS;
53 }
54 
56  __in PFX_DRIVER_GLOBALS FxDriverGlobals,
57  __in size_t BufferSize
58  ) :
59  FxMemoryObject(FxDriverGlobals,
61  BufferSize)
62 /*++
63 
64 Routine Description:
65  Constructor for FxMemoryBuffer. Initializes the entire data structure.
66 
67 Arguments:
68  BufferSize - Size of the buffer represented by this object
69 
70  We round up the object size (via COMPUTE_OBJECT_SIZE) because the object,
71  the context and the memory it returns via GetBuffer() are all in one allocation
72  and the returned memory needs to match the alignment that raw pool follows.
73 
74  Note on downcasting to USHORT
75  ==============================
76  Note that FxMemoryBuffer is used for buffer less than a page size, and
77  object-size and buffer-size are added and allocated together.
78  Downcasting to USHORT is safe because size of object plus buffer (<page size)
79  would be smaller than 64K that could fit in USHORT.
80 
81  For buffer larger than 1 page size, object memory is allocated separately
82  from buffer memory and the object used is FxMemoryBufferFromPool.
83  There is no downcasting done in that case.
84 
85  See comments in FxMemoryObject.hpp for info on various fx memory objects.
86 
87 Assumes:
88  FxMemoryBuffer::operator new has already initialized the entire allocation
89 
90 Return Value:
91  None
92 
93  --*/
94 {
96 }
97 
99  __in PFX_DRIVER_GLOBALS FxDriverGlobals,
100  __in USHORT ObjectSize,
101  __in size_t BufferSize
102  ) :
103  FxMemoryObject(FxDriverGlobals,
104  (USHORT) COMPUTE_OBJECT_SIZE(ObjectSize, (ULONG) BufferSize),
105  BufferSize)
106 
107 /*++
108 
109 Routine Description:
110  Constructor for derivations FxMemoryBuffer. Initializes the entire data
111  structure.
112 
113  We round up the object size (via COMPUTE_OBJECT_SIZE) because the object,
114  the context and the memory it returns via GetBuffer() are all in one allocation
115  and the returned memory needs to match the alignment that raw pool follows.
116 
117  Note on downcasting to USHORT
118  ==============================
119  Note that FxMemoryBuffer is used for buffer less than a page size, and
120  object-size and buffer-size are added and allocated together.
121  Downcasting to USHORT is safe because size of object plus buffer (<page size)
122  would be smaller than 64K that could fit in USHORT.
123 
124  For buffer larger than 1 page size, object memory is allocated separately
125  from buffer memory and the object used is FxMemoryBufferFromPool.
126  There is no downcasting done in that case.
127 
128  See comments in FxMemoryObject.hpp for info on various fx memory objects.
129 
130 Arguments:
131  ObjectSize - Size of the derived object
132 
133  BufferSize - Size of the buffer represented by this object
134 
135 Return Value:
136  None
137 
138  --*/
139 {
141 }
142 
144 /*++
145 
146 Routine Description:
147  Destructor for this object. Since the object + buffer is one
148  allocation, there is no need to free any more memory.
149 
150 Arguments:
151  None
152 
153 Return Value:
154  None
155 
156  --*/
157 {
158 }
159 
160 PVOID
162  VOID
163  )
164 /*++
165 
166 Routine Description:
167  Returns the buffer associated with this object
168 
169 Arguments:
170  None
171 
172 Return Value:
173  a valid pointer, of size GetBufferSize()
174 
175  --*/
176 {
177  //
178  // The buffer follows the struct itself
179  //
180  return ((PUCHAR) this) + COMPUTE_RAW_OBJECT_SIZE(sizeof(*this));
181 }
#define USHORT_MAX
Definition: intsafe.h:145
#define _Must_inspect_result_
Definition: no_sal2.h:62
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
#define COMPUTE_RAW_OBJECT_SIZE(_rawObjectSize)
Definition: fxhandle.h:100
#define __in_opt
Definition: dbghelp.h:38
FxMemoryBuffer(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in size_t BufferSize)
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
DriverGlobals
PVOID GetBuffer(VOID)
#define __out
Definition: dbghelp.h:62
PVOID pBuffer
#define COMPUTE_OBJECT_SIZE(_rawObjectSize, _extraSize)
Definition: fxhandle.h:107
#define ASSERT(a)
Definition: mode.c:44
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
_Must_inspect_result_ _In_ WDFCOLLECTION _In_ WDFOBJECT Object
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
static _Must_inspect_result_ NTSTATUS _Create(__in PFX_DRIVER_GLOBALS DriverGlobals, __in_opt PWDF_OBJECT_ATTRIBUTES Attributes, __in ULONG PoolTag, __in size_t BufferSize, __in POOL_TYPE PoolType, __out FxMemoryObject **Object)
#define STATUS_SUCCESS
Definition: shellext.h:65
#define __in
Definition: dbghelp.h:35
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:251
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes