ReactOS 0.4.15-dev-7958-gcd0bb1a
fxmemorybuffer.cpp
Go to the documentation of this file.
1/*++
2
3Copyright (c) Microsoft Corporation
4
5Module Name:
6
7 FxMemoryBuffer.cpp
8
9Abstract:
10
11 This module implements a frameworks managed FxMemoryBuffer
12
13Author:
14
15Environment:
16
17 kernel mode only
18
19Revision History:
20
21--*/
22
23#include "coreprivshared.hpp"
24#include "fxmemorybuffer.hpp"
25
26extern "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,
62/*++
63
64Routine Description:
65 Constructor for FxMemoryBuffer. Initializes the entire data structure.
66
67Arguments:
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
87Assumes:
88 FxMemoryBuffer::operator new has already initialized the entire allocation
89
90Return 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,
106
107/*++
108
109Routine 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
130Arguments:
131 ObjectSize - Size of the derived object
132
133 BufferSize - Size of the buffer represented by this object
134
135Return Value:
136 None
137
138 --*/
139{
141}
142
144/*++
145
146Routine Description:
147 Destructor for this object. Since the object + buffer is one
148 allocation, there is no need to free any more memory.
149
150Arguments:
151 None
152
153Return Value:
154 None
155
156 --*/
157{
158}
159
160PVOID
162 VOID
163 )
164/*++
165
166Routine Description:
167 Returns the buffer associated with this object
168
169Arguments:
170 None
171
172Return 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}
LONG NTSTATUS
Definition: precomp.h:26
FxMemoryBuffer(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in size_t BufferSize)
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)
PVOID GetBuffer(VOID)
#define __in
Definition: dbghelp.h:35
#define __in_opt
Definition: dbghelp.h:38
#define __out
Definition: dbghelp.h:62
#define NULL
Definition: types.h:112
DriverGlobals
#define COMPUTE_RAW_OBJECT_SIZE(_rawObjectSize)
Definition: fxhandle.h:100
#define COMPUTE_OBJECT_SIZE(_rawObjectSize, _extraSize)
Definition: fxhandle.h:107
#define USHORT_MAX
Definition: intsafe.h:147
#define ASSERT(a)
Definition: mode.c:44
#define _Must_inspect_result_
Definition: ms_sal.h:558
unsigned short USHORT
Definition: pedump.c:61
PVOID pBuffer
#define STATUS_SUCCESS
Definition: shellext.h:65
INT POOL_TYPE
Definition: typedefs.h:78
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Must_inspect_result_ _In_ WDFCOLLECTION _In_ WDFOBJECT Object
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ _Strict_type_match_ POOL_TYPE PoolType
Definition: wdfdevice.h:3815
_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
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList