ReactOS 0.4.15-dev-8131-g4988de4
fxlookasidelistapi.cpp
Go to the documentation of this file.
1/*++
2
3Copyright (c) Microsoft Corporation
4
5Module Name:
6
7 FxLookasideListApi.cpp
8
9Abstract:
10
11 This modules implements the C API's for the FxLookasideList.
12
13Author:
14
15
16Environment:
17
18 kernel mode only
19
20Revision History:
21
22--*/
23
24#include "coreprivshared.hpp"
27
28extern "C" {
29// #include "FxLookasideListAPI.tmh"
30}
31
32extern "C" {
33
40WDFEXPORT(WdfLookasideListCreate)(
41 __in
45 __in
47 size_t BufferSize,
48 __in
49 __drv_strictTypeMatch(__drv_typeExpr)
55 __out
56 WDFLOOKASIDE* PLookaside
57 )
58/*++
59
60Routine Description:
61 Creates a WDFLOOKASIDE list handle. The returned handle can then create
62 WDFMEMORY handles on behalf of the client driver. The underlying
63 WDFLOOKASIDE is a true NTOS lookaside list (of the appropriate paged or
64 npaged variety).
65
66Arguments:
67 LookasideAttributes - Object attributes for the lookaside handle being
68 created
69
70 BufferSize - Specifies how big each buffer created by the lookaside is
71
72 PoolType - Indicates whether the lookaside list is to create paged or
73 nonpaged WDFMEMORY handles.
74
75 MemoryAttributes - Attributes to be associated with each memory handle created
76 using the created lookaside list handle
77
78 PoolTag - Pool tag to use for each allocation. If 0, the frameworks tag
79 will be used
80
81 PLookaside - Pointer to store the created handle
82
83Return Value:
84 STATUS_INVALID_PARAMETER if any of the required parameters are incorrect
85
86 STATUS_INSUFFICIENT_RESOURCES if no memory is available to create the list
87
88 STATUS SUCCESS if succesful
89
90 --*/
91{
94 WDFLOOKASIDE hLookaside;
97
98 pParent = NULL;
100
101 //
102 // Get the parent's globals if it is present
103 //
108 LookasideAttributes->ParentObject,
110 (PVOID*)&pParent,
112 }
117 MemoryAttributes->ParentObject,
119 (PVOID*)&pParent,
121 }
122
124
126 *PLookaside = NULL;
127
128 if (BufferSize == 0) {
131 "Zero BufferSize not allowed, %!STATUS!", status);
132 return status;
133 }
134
137 return status;
138 }
139
141 if (!NT_SUCCESS(status)) {
142 return status;
143 }
144
145 if (PoolTag == 0) {
147 }
148
150
151 //
152 // Create the appropriate object
153 //
155 if (BufferSize < PAGE_SIZE) {
158 }
159 else {
162 }
163 }
164 else {
166
168 if (!NT_SUCCESS(status)) {
169 return status;
170 }
171
174
177
181
182 //
183 // No need to check if LookasideAttributes or MemoryAttributes are
184 // equal to NULL b/c we could not get a valid pLookasideDB or
185 // pMemoryDB if they were NULL.
186 //
189 "Lookaside Attributes ancestor WDFDEVICE %p (from ParentObject %p) "
190 " is not the same as Memory Attributes ancestor WDFDEVICE %p "
191 "(from ParentObject %p), %!STATUS!",
192 pLookasideDB->GetHandle(), LookasideAttributes->ParentObject,
193 pMemoryDB->GetHandle(), MemoryAttributes->ParentObject,
194 status);
195
196 return status;
197 }
198
199 //
200 // For paged allocations we always split the WDFMEMORY from its buffer
201 // pointer because the memory behind the WDFMEMORY must be non pageable
202 // while its buffer is pageable.
203 //
206 PoolTag,
208 pMemoryDB);
209 }
210
211 if (pLookaside == NULL) {
213 }
214
216
218 //
219 // Follow the global driver policy and either return a PVOID cookie or
220 // an index into a handle table.
221 //
223 }
224
225 if (NT_SUCCESS(status)) {
227 }
228 else {
230 }
231
232 return status;
233}
234
238WDFAPI
240WDFEXPORT(WdfMemoryCreateFromLookaside)(
241 __in
243 __in
244 WDFLOOKASIDE Lookaside,
245 __out
246 WDFMEMORY* Memory
247 )
248/*++
249
250Routine Description:
251 Allocates a WDFMEMORY handle from a lookaside HANDLE that the caller
252 previously created with WdfLookasideListCreate.
253
254Arguments:
255 Lookaside - Handle to a lookaside list previously created by the caller
256
257 Memory - Handle to be returned to the caller
258
259Return Value:
260 NTSTATUS
261
262 --*/
263{
266 WDFMEMORY hMemory;
268
270 pMemory = NULL;
271
272 //
273 // Make sure the caller passed in a valid handle
274 //
276 Lookaside,
278 (PVOID*)&pLookaside);
279
281
282 *Memory = NULL;
283
285 if (!NT_SUCCESS(status)) {
286 return status;
287 }
288
290 (WDFOBJECT*) &hMemory);
291
292 if (NT_SUCCESS(status)) {
293 *Memory = hMemory;
294 }
295 else {
297 }
298
299 return status;
300}
301
302} // extern "C"
LONG NTSTATUS
Definition: precomp.h:26
static FxDeviceBase * _SearchForDevice(__in FxObject *Object, __out_opt IFxHasCallbacks **Callbacks)
virtual _Must_inspect_result_ NTSTATUS Allocate(__out FxMemoryObject **PPMemory)=0
WDF_OBJECT_ATTRIBUTES m_MemoryAttributes
virtual _Must_inspect_result_ NTSTATUS Initialize(__in size_t BufferSize, __in PWDF_OBJECT_ATTRIBUTES MemoryAttributes)=0
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
Definition: fxobject.hpp:734
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 NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#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 PAGE_SIZE
Definition: env_spec_w32.h:49
#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)
DriverGlobals
__inline PFX_DRIVER_GLOBALS GetFxDriverGlobals(__in PWDF_DRIVER_GLOBALS DriverGlobals)
Definition: fxglobals.h:597
FxObjectHandleGetPtr(GetFxDriverGlobals(DriverGlobals), Lookaside, FX_TYPE_LOOKASIDE,(PVOID *)&pLookaside)
_Must_inspect_result_ __in_opt PWDF_OBJECT_ATTRIBUTES __in __in __in_opt PWDF_OBJECT_ATTRIBUTES __in_opt ULONG __out WDFLOOKASIDE * PLookaside
_Must_inspect_result_ __in_opt PWDF_OBJECT_ATTRIBUTES LookasideAttributes
FxLookasideList * pLookaside
_Must_inspect_result_ __in WDFLOOKASIDE Lookaside
NTSTATUS status
FxMemoryObject * pMemory
FxObject * pParent
_Must_inspect_result_ __in WDFLOOKASIDE __out WDFMEMORY * Memory
WDFLOOKASIDE hLookaside
FxVerifierCheckNxPoolType(pFxDriverGlobals, PoolType, PoolTag)
WDFMEMORY hMemory
pFxDriverGlobals
#define WDFEXPORT(a)
Definition: fxmacros.hpp:157
#define FxPointerNotNull(FxDriverGlobals, Ptr)
Definition: fxmacros.hpp:253
BOOLEAN FxIsPagedPoolType(__in POOL_TYPE Type)
Definition: wdfpool.cpp:43
@ FX_TYPE_OBJECT
Definition: fxtypes.h:45
@ FX_TYPE_LOOKASIDE
Definition: fxtypes.h:54
_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
Definition: ps.c:97
INT POOL_TYPE
Definition: typedefs.h:78
uint32_t ULONG
Definition: typedefs.h:59
#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_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ _Strict_type_match_ POOL_TYPE PoolType
Definition: wdfdevice.h:3815
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _In_ _In_ _Strict_type_match_ POOL_TYPE _In_opt_ PWDF_OBJECT_ATTRIBUTES MemoryAttributes
Definition: wdfmemory.h:409
_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_opt_ PWDF_OBJECT_ATTRIBUTES _In_ _In_ _Strict_type_match_ POOL_TYPE _In_opt_ PWDF_OBJECT_ATTRIBUTES _In_opt_ ULONG _Out_ WDFLOOKASIDE * Lookaside
Definition: wdfmemory.h:414
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _In_ _Strict_type_match_ POOL_TYPE _In_opt_ ULONG PoolTag
Definition: wdfmemory.h:164
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES LookasideAttributes
Definition: wdfmemory.h:401
#define WDFAPI
Definition: wdftypes.h:53