ReactOS  0.4.15-dev-2947-g59e1b78
fxcommonbufferapi.cpp
Go to the documentation of this file.
1 /*++
2 
3 Copyright (c) Microsoft Corporation
4 
5 Module Name:
6 
7  FxCommonBufferAPI.cpp
8 
9 Abstract:
10 
11  Base for WDF CommonBuffer APIs
12 
13 Environment:
14 
15  Kernel mode only.
16 
17 Notes:
18 
19 
20 Revision History:
21 
22 --*/
23 
24 #include "fxdmapch.hpp"
25 
26 extern "C" {
27 // #include "FxCommonBufferAPI.tmh"
28 }
29 
30 //
31 // Extern "C" the entire file
32 //
33 extern "C" {
34 
38 STDCALL
39 WDFEXPORT(WdfCommonBufferCreate)(
40  __in
42  __in
43  WDFDMAENABLER DmaEnabler,
44  __in
46  size_t Length,
47  __in_opt
49  __out
50  WDFCOMMONBUFFER * CommonBufferHandle
51  )
52 {
58 
59  //
60  // Get validate DmaEnabler handle
61  //
63  DmaEnabler,
65  (PVOID *) &pDmaEnabler,
67 
69 
71 
73  if (!NT_SUCCESS(status)) {
74  return status;
75  }
76 
77  //
78  // Basic parameter validation
79  //
80  if (Length == 0) {
83  "Length is 0, %!STATUS!", status);
84  return status;
85  }
86 
88  Attributes,
90  );
91  if (!NT_SUCCESS(status)) {
92  return status;
93  }
94 
95  //
96  // Create a new CommonBuffer object
97  //
100 
101  if (pComBuf == NULL) {
103 
105  "Could not allocate memory for a WDFCOMMONBUFFER, "
106  "%!STATUS!", status);
107  return status;
108  }
109 
110  //
111  // Assign this FxCommonBuffer to its parent FxDmaEnabler object.
112  //
114 
116  //
117  // Ok: now allocate a CommonBuffer via this DmaEnabler
118  //
119  status = pComBuf->AllocateCommonBuffer( Length );
120  }
121 
122  if (NT_SUCCESS(status)) {
123  //
124  // Only return a valid handle on success.
125  //
126  *CommonBufferHandle = (WDFCOMMONBUFFER) handle;
127  }
128  else {
129  pComBuf->DeleteFromFailedCreate();
130  }
131 
132  return status;
133 }
134 
137 NTSTATUS
138 STDCALL
139 WDFEXPORT(WdfCommonBufferCreateWithConfig)(
140  __in
142  __in
143  WDFDMAENABLER DmaEnabler,
144  __in
145  __drv_when(Length == 0, __drv_reportError(Length cannot be zero))
146  size_t Length,
147  __in
149  __in_opt
151  __out
152  WDFCOMMONBUFFER * CommonBufferHandle
153  )
154 {
160 
161  //
162  // Get validate DmaEnabler handle
163  //
165  DmaEnabler,
167  (PVOID *) &pDmaEnabler,
169 
170  //
171  // Basic parameter validation
172  //
174 
175  if (Config->Size != sizeof(WDF_COMMON_BUFFER_CONFIG)) {
177 
180  "WDF_COMMON_BUFFER_CONFIG Size 0x%x, expected 0x%x, %!STATUS!",
181  Config->Size, sizeof(WDF_COMMON_BUFFER_CONFIG), status);
182 
183  return status;
184  }
185 
187 
189 
191  if (!NT_SUCCESS(status)) {
192  return status;
193  }
194 
195  if (Length == 0) {
198  "Length is 0, %!STATUS!", status);
199  return status;
200  }
201 
203  Attributes,
205  );
206  if (!NT_SUCCESS(status)) {
207  return status;
208  }
209 
212 
213  if (pComBuf == NULL) {
215 
217  "Could not allocate memory for a WDFCOMMONBUFFER, "
218  "%!STATUS!", status);
219  return status;
220  }
221 
222  //
223  // Assign this FxCommonBuffer to its parent FxDmaEnabler object.
224  //
226 
227  if (NT_SUCCESS(status)) {
228  //
229  // Set the alignment value before calling AllocateCommonBuffer.
230  //
231  pComBuf->SetAlignment(Config->AlignmentRequirement);
232  status = pComBuf->AllocateCommonBuffer( Length );
233  }
234 
235  if (NT_SUCCESS(status)) {
236  //
237  // Only return a valid handle on success.
238  //
239  *CommonBufferHandle = (WDFCOMMONBUFFER) handle;
240  }
241  else {
242  pComBuf->DeleteFromFailedCreate();
243  }
244 
245  return status;
246 }
247 
249 PVOID
250 STDCALL
251 WDFEXPORT(WdfCommonBufferGetAlignedVirtualAddress)(
252  __in
254  __in
255  WDFCOMMONBUFFER CommonBuffer
256  )
257 {
259 
261  CommonBuffer,
263  (PVOID *) &pComBuf);
264 
265  return pComBuf->GetAlignedVirtualAddress();
266 }
267 
270 STDCALL
271 WDFEXPORT(WdfCommonBufferGetAlignedLogicalAddress)(
272  __in
274  __in
275  WDFCOMMONBUFFER CommonBuffer
276  )
277 {
279 
281  CommonBuffer,
283  (PVOID *) &pComBuf);
284 
285  return pComBuf->GetAlignedLogicalAddress();
286 }
287 
289 size_t
290 STDCALL
291 WDFEXPORT(WdfCommonBufferGetLength)(
292  __in
294  __in
295  WDFCOMMONBUFFER CommonBuffer
296  )
297 {
299 
301  CommonBuffer,
303  (PVOID *) &pComBuf);
304 
305  return pComBuf->GetLength();
306 }
307 
308 } // extern "C"
FxObjectHandleGetPtr(GetFxDriverGlobals(DriverGlobals), CommonBuffer, FX_TYPE_COMMON_BUFFER,(PVOID *) &pComBuf)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define __drv_reportError(why)
Definition: driverspecs.h:319
_Must_inspect_result_ __in WDFDMAENABLER __in __in_opt WDF_OBJECT_ATTRIBUTES * Attributes
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
#define __in_opt
Definition: dbghelp.h:38
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
WDF_EXTERN_C_START struct _WDF_COMMON_BUFFER_CONFIG * PWDF_COMMON_BUFFER_CONFIG
LONG NTSTATUS
Definition: precomp.h:26
DriverGlobals
PFX_DRIVER_GLOBALS pFxDriverGlobals
#define TRACINGDMA
Definition: dbgtrace.h:71
#define WDFEXPORT(a)
Definition: fxmacros.hpp:157
#define __out
Definition: dbghelp.h:62
int zero
Definition: sehframes.cpp:29
__in WDFCOMMONBUFFER CommonBuffer
__inline NTSTATUS FxVerifierCheckIrqlLevel(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in KIRQL Irql)
Definition: fxverifier.h:158
#define STDCALL
Definition: wdf.h:45
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_Must_inspect_result_ __in WDFDMAENABLER __in __drv_when(Length==0, __drv_reportError(Length cannot be zero)) size_t Length
FxObjectHandleGetPtrAndGlobals(GetFxDriverGlobals(DriverGlobals), DmaEnabler, FX_TYPE_DMA_ENABLER,(PVOID *) &pDmaEnabler, &pFxDriverGlobals)
_Must_inspect_result_ NTSTATUS FxValidateObjectAttributes(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PWDF_OBJECT_ATTRIBUTES Attributes, __in ULONG Flags=FX_VALIDATE_OPTION_NONE_SPECIFIED)
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
#define _Must_inspect_result_
Definition: ms_sal.h:558
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_CHILD_LIST_CONFIG Config
Definition: wdfchildlist.h:474
WDF_EXTERN_C_START struct _WDF_COMMON_BUFFER_CONFIG WDF_COMMON_BUFFER_CONFIG
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
FxDmaEnabler * pDmaEnabler
FxPointerNotNull(pFxDriverGlobals, CommonBufferHandle)
_Must_inspect_result_ __in WDFDMAENABLER DmaEnabler
_Must_inspect_result_ __in WDFDMAENABLER __in __in_opt WDF_OBJECT_ATTRIBUTES __out WDFCOMMONBUFFER * CommonBufferHandle
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
WDFOBJECT handle
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFCOMMONBUFFER * CommonBuffer
#define NULL
Definition: types.h:112
_Must_inspect_result_ __drv_maxIRQL(PASSIVE_LEVEL) NTSTATUS STDCALL WDFEXPORT(WdfCommonBufferCreate)(__in PWDF_DRIVER_GLOBALS DriverGlobals
_Must_inspect_result_ _In_ WDFDMAENABLER DmaEnabler
__inline PFX_DRIVER_GLOBALS GetFxDriverGlobals(__in PWDF_DRIVER_GLOBALS DriverGlobals)
Definition: fxglobals.h:597
_Must_inspect_result_ __in WDFDMAENABLER __in __in PWDF_COMMON_BUFFER_CONFIG Config
#define __in
Definition: dbghelp.h:35
NTSTATUS status
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes
Definition: ps.c:97