ReactOS 0.4.15-dev-8096-ga0eec98
fxmemorybufferapi.cpp
Go to the documentation of this file.
1/*++
2
3Copyright (c) Microsoft Corporation
4
5Module Name:
6
7 FxMemoryBufferApi.cpp
8
9Abstract:
10
11 This modules implements the C API's for the FxMemoryBuffer.
12
13Author:
14
15
16Environment:
17
18 kernel mode only
19
20Revision History:
21
22--*/
23
24#include "coreprivshared.hpp"
25#include "fxmemorybuffer.hpp"
26
27extern "C" {
28// #include "FxMemoryBufferAPI.tmh"
29}
30
31extern "C" {
32
39WDFEXPORT(WdfMemoryCreate)(
40 __in
44 __in
45 __drv_strictTypeMatch(__drv_typeExpr)
49 __in
51 size_t BufferSize,
52 __out
53 WDFMEMORY* Memory,
56 )
57/*++
58
59Routine Description:
60 Creates a WDFMEMORY handle based on the caller's specifications
61
62Arguments:
63 Attributes - Attributes associated with this object
64
65 PoolType - The type of pool created
66
67 PoolTag - Tag to use when allocating the memory. If 0, then the frameworks
68 tag is used
69
70 BufferSize - The size of the buffer represented by the returned handle
71
72 Memory - The returned handle to the caller
73
74 Buffer - (opt) Pointer to the associated memory buffer.
75
76Return Value:
77 STATUS_INVALID_PARAMETER - any required parameters are not present
78
79 STATUS_INSUFFICIENT_RESOURCES - could not allocated the object that backs
80 the handle
81
82 STATUS_SUCCESS - success
83
84 --*/
85{
86 DDI_ENTRY();
87
90 WDFMEMORY hMemory;
92
94
95 //
96 // Get the parent's globals if it is present
97 //
99 Attributes))) {
101
103 Attributes->ParentObject,
105 (PVOID*)&pParent,
107 }
108
110
113 if (!NT_SUCCESS(status)) {
114 return status;
115 }
116 }
117
118 if (BufferSize == 0) {
121 "BufferSize == 0 not allowed, %!STATUS!", status);
122 return status;
123 }
124
125 *Memory = NULL;
126
129 return status;
130 }
131
132 if (PoolTag == 0) {
134 }
135
137
141 PoolType,
142 PoolTag,
144 &pBuffer);
145
146 if (!NT_SUCCESS(status)) {
147 return status;
148 }
149
151
153 *Memory = hMemory;
154 if (Buffer != NULL) {
156 }
157 }
158 else {
160 }
161
162 return status;
163}
164
166PVOID
167WDFAPI
169WDFEXPORT(WdfMemoryGetBuffer)(
170 __in
172 __in
173 WDFMEMORY Memory,
176 )
177/*++
178
179Routine Description:
180 Retrieves the raw pointers associated with WDFMEMORY handle
181
182Arguments:
183 Memory - handle to the WDFMEMORY
184
185 BufferSize - the size / length of the buffer
186
187Return Value:
188 raw buffer
189
190 --*/
191{
192 DDI_ENTRY();
193
195
197 Memory,
199 (PVOID*)&pMemory);
200
201 if (BufferSize != NULL) {
203 }
204
206}
207
211WDFAPI
213WDFEXPORT(WdfMemoryCopyToBuffer)(
214 __in
216 __in
217 WDFMEMORY SourceMemory,
218 __in
220 __out_bcount( NumBytesToCopyTo)
222 __in
223 __drv_when(NumBytesToCopyTo == 0, __drv_reportError(NumBytesToCopyTo cannot be zero))
224 size_t NumBytesToCopyTo
225 )
226/*++
227
228Routine Description:
229 Copies memory from a WDFMEMORY handle to a raw pointer
230
231Arguments:
232 SourceMemory - Memory handle whose contents we are copying from.
233
234 SourceOffset - Offset into SourceMemory from which the copy starts.
235
236 Buffer - Memory whose contents we are copying into
237
238 NumBytesToCopyTo - Number of bytes to copy into buffer.
239
240Return Value:
241
242 STATUS_BUFFER_TOO_SMALL - SourceMemory is smaller than the requested number
243 of bytes to be copied.
244
245 NTSTATUS
246
247 --*/
248{
249 DDI_ENTRY();
250
252 IFxMemory* pSource;
253 WDFMEMORY_OFFSET srcOffsets;
254 WDFMEMORY_OFFSET dstOffsets;
256
260 (PVOID*) &pSource);
261
263
265
266 if (NumBytesToCopyTo == 0) {
269 "Zero bytes to copy not allowed, %!STATUS!", status);
270 return status;
271 }
272
273 RtlZeroMemory(&srcOffsets, sizeof(srcOffsets));
274 srcOffsets.BufferLength = NumBytesToCopyTo;
275 srcOffsets.BufferOffset = SourceOffset;
276
277 RtlZeroMemory(&dstOffsets, sizeof(dstOffsets));
278 dstOffsets.BufferLength = NumBytesToCopyTo;
279 dstOffsets.BufferOffset = 0;
280
281 return pSource->CopyToPtr(&srcOffsets,
282 Buffer,
283 NumBytesToCopyTo,
284 &dstOffsets);
285}
286
290WDFAPI
292WDFEXPORT(WdfMemoryCopyFromBuffer)(
293 __in
295 __in
297 __in
299 __in
301 __in
302 __drv_when(NumBytesToCopyFrom == 0, __drv_reportError(NumBytesToCopyFrom cannot be zero))
303 size_t NumBytesToCopyFrom
304 )
305/*++
306
307Routine Description:
308 Copies memory from a raw pointer into a WDFMEMORY handle
309
310Arguments:
311 DestinationMemory - Memory handle whose contents we are copying into
312
313 DestinationOffset - Offset into DestinationMemory from which the copy
314 starts.
315
316 Buffer - Buffer whose context we are copying from
317
318 NumBytesToCopyFrom - Number of bytes to copy from
319
320Return Value:
321
322 STATUS_INVALID_BUFFER_SIZE - DestinationMemory is not large enough to contain
323 the number of bytes requested to be copied
324
325 NTSATUS
326
327 --*/
328
329{
330 DDI_ENTRY();
331
333 WDFMEMORY_OFFSET srcOffsets;
334 WDFMEMORY_OFFSET dstOffsets;
335 IFxMemory* pDest;
337
341 (PVOID*) &pDest);
342
344
346
347 if (NumBytesToCopyFrom == 0) {
350 "Zero bytes to copy not allowed, %!STATUS!", status);
351 return status;
352 }
353
354 RtlZeroMemory(&srcOffsets, sizeof(srcOffsets));
355 srcOffsets.BufferLength = NumBytesToCopyFrom;
356 srcOffsets.BufferOffset = 0;
357
358 RtlZeroMemory(&dstOffsets, sizeof(dstOffsets));
359 dstOffsets.BufferLength = NumBytesToCopyFrom;
360 dstOffsets.BufferOffset = DestinationOffset;
361
362 return pDest->CopyFromPtr(&dstOffsets,
363 Buffer,
364 NumBytesToCopyFrom,
365 &srcOffsets);
366}
367
368} // extern "C"
LONG NTSTATUS
Definition: precomp.h:26
Definition: bufpool.h:45
static _Must_inspect_result_ NTSTATUS _Create(__in PFX_DRIVER_GLOBALS DriverGlobals, __in_opt PWDF_OBJECT_ATTRIBUTES Attributes, __in POOL_TYPE PoolType, __in ULONG PoolTag, __in size_t BufferSize, __out FxMemoryObject **Object)
VOID DeleteFromFailedCreate(VOID)
Definition: fxobject.cpp:391
_Must_inspect_result_ NTSTATUS Commit(__in_opt PWDF_OBJECT_ATTRIBUTES Attributes, __out_opt WDFOBJECT *ObjectHandle, __in_opt FxObject *Parent=NULL, __in BOOLEAN AssignDriverAsDefaultParent=TRUE)
Definition: fxobject.cpp:904
virtual size_t GetBufferSize(VOID)=0
virtual PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)=0
_Must_inspect_result_ NTSTATUS CopyToPtr(__in_opt PWDFMEMORY_OFFSET SourceOffsets, __out_bcount(DestinationBufferLength) PVOID DestinationBuffer, __in size_t DestinationBufferLength, __in_opt PWDFMEMORY_OFFSET DestinationOffsets)
virtual PVOID GetBuffer(VOID)=0
_Must_inspect_result_ NTSTATUS CopyFromPtr(__in_opt PWDFMEMORY_OFFSET DestinationOffsets, __in_bcount(SourceBufferLength) PVOID SourceBuffer, __in size_t SourceBufferLength, __in_opt PWDFMEMORY_OFFSET SourceOffsets)
#define __out_opt
Definition: dbghelp.h:65
#define __in
Definition: dbghelp.h:35
#define __out_bcount(x)
Definition: dbghelp.h:68
#define __in_opt
Definition: dbghelp.h:38
#define __out
Definition: dbghelp.h:62
#define TRACINGDEVICE
Definition: dbgtrace.h:58
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define __drv_when(cond, annotes)
Definition: driverspecs.h:335
#define __drv_reportError(why)
Definition: driverspecs.h:320
#define __drv_maxIRQL(irql)
Definition: driverspecs.h:291
#define __drv_strictTypeMatch(mode)
Definition: driverspecs.h:330
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
#define APC_LEVEL
Definition: env_spec_w32.h:695
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
FxObjectHandleGetPtrAndGlobals(GetFxDriverGlobals(DriverGlobals), Device, FX_TYPE_DEVICE,(PVOID *)&pDevice, &pFxDriverGlobals)
FxObject * pParent
Definition: fxdpcapi.cpp:86
DriverGlobals
__inline PFX_DRIVER_GLOBALS GetFxDriverGlobals(__in PWDF_DRIVER_GLOBALS DriverGlobals)
Definition: fxglobals.h:597
#define DDI_ENTRY()
Definition: fxglobalskm.h:56
#define WDFEXPORT(a)
Definition: fxmacros.hpp:157
#define FxPointerNotNull(FxDriverGlobals, Ptr)
Definition: fxmacros.hpp:253
__in WDFMEMORY __out_opt size_t * BufferSize
_Must_inspect_result_ __in WDFMEMORY SourceMemory
_Must_inspect_result_ __in_opt PWDF_OBJECT_ATTRIBUTES __in __in_opt ULONG __in __out WDFMEMORY * Memory
_Must_inspect_result_ __in_opt PWDF_OBJECT_ATTRIBUTES __in __in_opt ULONG __in __out WDFMEMORY __out_opt PVOID * Buffer
_Must_inspect_result_ __in WDFMEMORY DestinationMemory
NTSTATUS status
_Must_inspect_result_ __in WDFMEMORY __in size_t SourceOffset
IFxMemory * pMemory
FxObjectHandleGetPtr(GetFxDriverGlobals(DriverGlobals), Memory, IFX_TYPE_MEMORY,(PVOID *)&pMemory)
FxVerifierCheckNxPoolType(pFxDriverGlobals, PoolType, PoolTag)
WDFMEMORY hMemory
_Must_inspect_result_ __in WDFMEMORY __in size_t DestinationOffset
FxMemoryObject * pBuffer
PFX_DRIVER_GLOBALS pFxDriverGlobals
BOOLEAN FxIsPagedPoolType(__in POOL_TYPE Type)
Definition: wdfpool.cpp:43
@ FX_TYPE_OBJECT
Definition: fxtypes.h:45
@ IFX_TYPE_MEMORY
Definition: fxtypes.h:55
_Must_inspect_result_ NTSTATUS __inline FxValidateObjectAttributesForParentHandle(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PWDF_OBJECT_ATTRIBUTES Attributes, __in ULONG Flags=FX_VALIDATE_OPTION_NONE_SPECIFIED)
_Must_inspect_result_ NTSTATUS FxValidateObjectAttributes(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PWDF_OBJECT_ATTRIBUTES Attributes, __in ULONG Flags=FX_VALIDATE_OPTION_NONE_SPECIFIED)
__inline NTSTATUS FxVerifierCheckIrqlLevel(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in KIRQL Irql)
Definition: fxverifier.h:158
#define _Must_inspect_result_
Definition: ms_sal.h:558
int zero
Definition: sehframes.cpp:29
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
size_t BufferOffset
Definition: wdfmemory.h:65
size_t BufferLength
Definition: wdfmemory.h:72
Definition: ps.c:97
INT POOL_TYPE
Definition: typedefs.h:78
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STDCALL
Definition: wdf.h:45
_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
_Must_inspect_result_ _In_ WDFMEMORY SourceMemory
Definition: wdfmemory.h:318
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _In_ _Strict_type_match_ POOL_TYPE _In_opt_ ULONG _In_ _Out_ WDFMEMORY * Memory
Definition: wdfmemory.h:169
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254
_Must_inspect_result_ _In_ WDFMEMORY DestinationMemory
Definition: wdfmemory.h:359
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _In_ _Strict_type_match_ POOL_TYPE _In_opt_ ULONG PoolTag
Definition: wdfmemory.h:164
#define WDFAPI
Definition: wdftypes.h:53