ReactOS  0.4.15-dev-3440-g915569a
fxmemorybufferpreallocatedapi.cpp
Go to the documentation of this file.
1 /*++
2 
3 Copyright (c) Microsoft Corporation
4 
5 Module Name:
6 
7  FxMemoryBufferPreallocatedApi.cpp
8 
9 Abstract:
10 
11  This modules implements the C API's for the FxMemoryBufferPreallocated.
12 
13 Author:
14 
15 
16 Environment:
17 
18  kernel mode only
19 
20 Revision History:
21 
22 --*/
23 
24 #include "coreprivshared.hpp"
26 
27 extern "C" {
28 // #include "FxMemoryBufferPreallocatedAPI.tmh"
29 }
30 
31 extern "C" {
32 
35 WDFAPI
37 STDCALL
38 WDFEXPORT(WdfMemoryCreatePreallocated)(
39  __in
41  __in_opt
43  __in
44  PVOID Buffer,
45  __in
47  size_t BufferSize,
48  __out //deref cud be null if unable to allocate memory
49  WDFMEMORY* PMemory
50  )/*++
51 
52 Routine 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 
59 Arguments:
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 
68 Return 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 
138 WDFAPI
139 NTSTATUS
140 STDCALL
141 WDFEXPORT(WdfMemoryAssignBuffer)(
142  _In_
144  _In_
145  WDFMEMORY Memory,
147  PVOID Buffer,
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"
#define DDI_ENTRY()
Definition: fxglobalskm.h:56
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define __drv_reportError(why)
Definition: driverspecs.h:319
_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_opt
Definition: dbghelp.h:38
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_Must_inspect_result_ _In_ WDFMEMORY _Pre_notnull_ _Pre_writable_byte_size_(BufferSize) PVOID Buffer
LONG NTSTATUS
Definition: precomp.h:26
_Must_inspect_result_ __in_opt PWDF_OBJECT_ATTRIBUTES Attributes
_Must_inspect_result_ __drv_maxIRQL(DISPATCH_LEVEL) WDFAPI NTSTATUS STDCALL WDFEXPORT(WdfMemoryCreatePreallocated)(__in PWDF_DRIVER_GLOBALS DriverGlobals
FxMemoryObject * pMemory
WDFMEMORY hMemory
DriverGlobals
_Must_inspect_result_ _In_ WDFMEMORY Memory
_Must_inspect_result_ __in_opt PWDF_OBJECT_ATTRIBUTES __in PVOID Buffer
#define WDFEXPORT(a)
Definition: fxmacros.hpp:157
#define WDFAPI
Definition: wdftypes.h:53
_Must_inspect_result_ __in_opt PWDF_OBJECT_ATTRIBUTES __in PVOID __in __drv_when(BufferSize==0, __drv_reportError(BufferSize cannot be zero)) size_t BufferSize
_Must_inspect_result_ NTSTATUS __inline FxValidateObjectAttributesForParentHandle(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PWDF_OBJECT_ATTRIBUTES Attributes, __in ULONG Flags=FX_VALIDATE_OPTION_NONE_SPECIFIED)
#define __out
Definition: dbghelp.h:62
int zero
Definition: sehframes.cpp:29
#define _In_
Definition: ms_sal.h:308
Definition: bufpool.h:45
_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
#define TRACINGDEVICE
Definition: dbgtrace.h:58
#define STDCALL
Definition: wdf.h:45
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
PFX_DRIVER_GLOBALS pFxDriverGlobals
#define _Pre_notnull_
Definition: ms_sal.h:680
_Must_inspect_result_ NTSTATUS FxValidateObjectAttributes(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PWDF_OBJECT_ATTRIBUTES Attributes, __in ULONG Flags=FX_VALIDATE_OPTION_NONE_SPECIFIED)
#define _Must_inspect_result_
Definition: ms_sal.h:558
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
_Must_inspect_result_ __in_opt PWDF_OBJECT_ATTRIBUTES __in PVOID __in __out WDFMEMORY * PMemory
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
#define NULL
Definition: types.h:112
VOID DeleteFromFailedCreate(VOID)
Definition: fxobject.cpp:391
FxMemoryBufferPreallocated * pBuffer
FxPointerNotNull(pFxDriverGlobals, Buffer)
FxObject * pParent
Definition: fxdpcapi.cpp:86
FxObjectHandleGetPtrAndGlobals(GetFxDriverGlobals(DriverGlobals), Device, FX_TYPE_DEVICE,(PVOID *)&pDevice, &pFxDriverGlobals)
#define STATUS_SUCCESS
Definition: shellext.h:65
__inline PFX_DRIVER_GLOBALS GetFxDriverGlobals(__in PWDF_DRIVER_GLOBALS DriverGlobals)
Definition: fxglobals.h:597
#define __in
Definition: dbghelp.h:35
#define BufferSize
Definition: mmc.h:75
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:251
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes
Definition: ps.c:97