ReactOS 0.4.15-dev-7918-g2a2556c
fxmemorybufferpreallocatedapi.cpp
Go to the documentation of this file.
1/*++
2
3Copyright (c) Microsoft Corporation
4
5Module Name:
6
7 FxMemoryBufferPreallocatedApi.cpp
8
9Abstract:
10
11 This modules implements the C API's for the FxMemoryBufferPreallocated.
12
13Author:
14
15
16Environment:
17
18 kernel mode only
19
20Revision History:
21
22--*/
23
24#include "coreprivshared.hpp"
26
27extern "C" {
28// #include "FxMemoryBufferPreallocatedAPI.tmh"
29}
30
31extern "C" {
32
38WDFEXPORT(WdfMemoryCreatePreallocated)(
39 __in
43 __in
45 __in
47 size_t BufferSize,
48 __out //deref cud be null if unable to allocate memory
49 WDFMEMORY* PMemory
50 )/*++
51
52Routine Description:
53 External API provided to the client driver to create a WDFMEMORY object
54 whose associated buffers are supplied by the caller. This API is provided
55 so that the caller does not need to allocate a new buffer every time she
56 wants to pass a WDFMEMORY object to an API which requires it. It is up to
57 the client driver to free the Buffer and Context at the appropriate time.
58
59Arguments:
60 Attributes - Context to associate with the returned WDFMEMORY handle
61
62 Buffer - Buffer to associate with the returned WDFMEMORY handle
63
64 BufferSize - Size of Buffer in bytes
65
66 PMemory - Handle to be returned to the caller
67
68Return Value:
69 STATUS_INVALID_PARAMETER - if required parameters are incorrect
70
71 STATUS_INSUFFICIENT_RESOURCES - if no resources are available
72
73 STATUS_SUCCESS - success
74
75 --*/
76{
77 DDI_ENTRY();
78
81 WDFMEMORY hMemory;
83
85
86 //
87 // Get the parent's globals if it is present
88 //
90 Attributes))) {
92
94 Attributes->ParentObject,
96 (PVOID*)&pParent,
98 }
99
102
103 *PMemory = NULL;
104
105 if (BufferSize == 0) {
108 "Zero BufferSize not allowed, %!STATUS!", status);
109 return status;
110 }
111
114 return status;
115 }
116
119
120 if (pBuffer == NULL) {
122 }
123
125
127 *PMemory = hMemory;
128 }
129 else {
131 }
132
133 return status;
134}
135
138WDFAPI
141WDFEXPORT(WdfMemoryAssignBuffer)(
142 _In_
144 _In_
145 WDFMEMORY Memory,
148 _In_
150 size_t BufferSize
151 )
152{
153 DDI_ENTRY();
154
158
160 Memory,
162 (PVOID*) &pMemory,
164
166
167 if (BufferSize == 0) {
170 "Zero BufferSize not allowed, %!STATUS!", status);
171 return status;
172 }
173
174 pMemory->UpdateBuffer(Buffer, BufferSize);
175
176 return STATUS_SUCCESS;
177}
178
179} // extern "C"
LONG NTSTATUS
Definition: precomp.h:26
Definition: bufpool.h:45
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
#define __in
Definition: dbghelp.h:35
#define __in_opt
Definition: dbghelp.h:38
#define __out
Definition: dbghelp.h:62
#define TRACINGDEVICE
Definition: dbgtrace.h:58
#define BufferSize
Definition: mmc.h:75
#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 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
FxMemoryObject * pMemory
#define WDFEXPORT(a)
Definition: fxmacros.hpp:157
#define FxPointerNotNull(FxDriverGlobals, Ptr)
Definition: fxmacros.hpp:253
_Must_inspect_result_ __in_opt PWDF_OBJECT_ATTRIBUTES __in PVOID __in __out WDFMEMORY * PMemory
_Must_inspect_result_ __in_opt PWDF_OBJECT_ATTRIBUTES __in PVOID Buffer
_Must_inspect_result_ __in_opt PWDF_OBJECT_ATTRIBUTES Attributes
FxMemoryBufferPreallocated * pBuffer
_Must_inspect_result_ _In_ WDFMEMORY Memory
WDFMEMORY hMemory
PFX_DRIVER_GLOBALS pFxDriverGlobals
@ FX_TYPE_MEMORY_PREALLOCATED
Definition: fxtypes.h:75
@ FX_TYPE_OBJECT
Definition: fxtypes.h:45
_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)
#define _Pre_writable_byte_size_(size)
Definition: ms_sal.h:647
#define _Pre_notnull_
Definition: ms_sal.h:680
#define _Must_inspect_result_
Definition: ms_sal.h:558
#define _In_
Definition: ms_sal.h:308
int zero
Definition: sehframes.cpp:29
#define STATUS_SUCCESS
Definition: shellext.h:65
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
Definition: ps.c:97
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define STDCALL
Definition: wdf.h:45
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes
_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
#define WDFAPI
Definition: wdftypes.h:53