ReactOS  0.4.15-dev-2720-g5ee0925
fxlookasidelistapi.cpp
Go to the documentation of this file.
1 /*++
2 
3 Copyright (c) Microsoft Corporation
4 
5 Module Name:
6 
7  FxLookasideListApi.cpp
8 
9 Abstract:
10 
11  This modules implements the C API's for the FxLookasideList.
12 
13 Author:
14 
15 
16 Environment:
17 
18  kernel mode only
19 
20 Revision History:
21 
22 --*/
23 
24 #include "coreprivshared.hpp"
26 #include "fxpagedlookasidelist.hpp"
27 
28 extern "C" {
29 // #include "FxLookasideListAPI.tmh"
30 }
31 
32 extern "C" {
33 
38 WDFAPI
39 STDCALL
40 WDFEXPORT(WdfLookasideListCreate)(
41  __in
43  __in_opt
45  __in
47  size_t BufferSize,
48  __in
49  __drv_strictTypeMatch(__drv_typeExpr)
51  __in_opt
53  __in_opt
54  ULONG PoolTag,
55  __out
56  WDFLOOKASIDE* PLookaside
57  )
58 /*++
59 
60 Routine 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 
66 Arguments:
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 
83 Return 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  }
115  MemoryAttributes))) {
117  MemoryAttributes->ParentObject,
119  (PVOID*)&pParent,
121  }
122 
124 
125  hLookaside = NULL;
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) {
146  PoolTag = pFxDriverGlobals->Tag;
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 
178  if (pLookasideDB != NULL && pMemoryDB != NULL &&
179  pLookasideDB != pMemoryDB) {
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,
207  pLookasideDB,
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 
237 NTSTATUS
238 WDFAPI
239 STDCALL
240 WDFEXPORT(WdfMemoryCreateFromLookaside)(
241  __in
243  __in
244  WDFLOOKASIDE Lookaside,
245  __out
246  WDFMEMORY* Memory
247  )
248 /*++
249 
250 Routine Description:
251  Allocates a WDFMEMORY handle from a lookaside HANDLE that the caller
252  previously created with WdfLookasideListCreate.
253 
254 Arguments:
255  Lookaside - Handle to a lookaside list previously created by the caller
256 
257  Memory - Handle to be returned to the caller
258 
259 Return Value:
260  NTSTATUS
261 
262  --*/
263 {
266  WDFMEMORY hMemory;
268 
269  pLookaside = NULL;
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"
BOOLEAN FxIsPagedPoolType(__in POOL_TYPE Type)
Definition: wdfpool.cpp:43
#define _Must_inspect_result_
Definition: no_sal2.h:62
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define __drv_reportError(why)
Definition: driverspecs.h:302
_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:407
_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
_Must_inspect_result_ __in_opt PWDF_OBJECT_ATTRIBUTES __in __in __in_opt PWDF_OBJECT_ATTRIBUTES __in_opt ULONG __out WDFLOOKASIDE * PLookaside
#define __in_opt
Definition: dbghelp.h:38
_Must_inspect_result_ __in_opt PWDF_OBJECT_ATTRIBUTES __in __in __drv_strictTypeMatch(__drv_typeExpr) POOL_TYPE PoolType
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_Must_inspect_result_ __drv_maxIRQL(DISPATCH_LEVEL)) NTSTATUS WDFAPI STDCALL WDFEXPORT(WdfLookasideListCreate)(__in PWDF_DRIVER_GLOBALS DriverGlobals
LONG NTSTATUS
Definition: precomp.h:26
_Must_inspect_result_ __drv_when(PoolType==1||PoolType==257, __drv_maxIRQL(APC_LEVEL)) __drv_when(PoolType
FxMemoryObject * pMemory
DriverGlobals
WDFLOOKASIDE hLookaside
_Must_inspect_result_ __in_opt PWDF_OBJECT_ATTRIBUTES __in __in __in_opt PWDF_OBJECT_ATTRIBUTES __in_opt ULONG PoolTag
static FxDeviceBase * _SearchForDevice(__in FxObject *Object, __out_opt IFxHasCallbacks **Callbacks)
FxLookasideList * pLookaside
#define FALSE
Definition: types.h:117
#define WDFEXPORT(a)
Definition: fxmacros.hpp:157
#define WDFAPI
Definition: wdftypes.h:53
virtual _Must_inspect_result_ NTSTATUS Allocate(__out FxMemoryObject **PPMemory)=0
_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
FxObjectHandleGetPtr(GetFxDriverGlobals(DriverGlobals), Lookaside, FX_TYPE_LOOKASIDE,(PVOID *)&pLookaside)
FxPointerNotNull(pFxDriverGlobals, PLookaside)
_Must_inspect_result_ __in WDFLOOKASIDE Lookaside
FxVerifierCheckNxPoolType(pFxDriverGlobals, PoolType, PoolTag)
_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
_Must_inspect_result_ __in WDFLOOKASIDE __out WDFMEMORY * Memory
virtual _Must_inspect_result_ NTSTATUS Initialize(__in size_t BufferSize, __in PWDF_OBJECT_ATTRIBUTES MemoryAttributes)=0
__inline NTSTATUS FxVerifierCheckIrqlLevel(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in KIRQL Irql)
Definition: fxverifier.h:158
#define TRACINGDEVICE
Definition: dbgtrace.h:58
#define STDCALL
Definition: wdf.h:45
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
INT POOL_TYPE
Definition: typedefs.h:78
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _In_ _Strict_type_match_ POOL_TYPE _In_opt_ ULONG PoolTag
Definition: wdfmemory.h:159
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _In_ _In_ _Strict_type_match_ POOL_TYPE _In_opt_ PWDF_OBJECT_ATTRIBUTES MemoryAttributes
Definition: wdfmemory.h:407
NTSTATUS status
_Must_inspect_result_ NTSTATUS FxValidateObjectAttributes(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PWDF_OBJECT_ATTRIBUTES Attributes, __in ULONG Flags=FX_VALIDATE_OPTION_NONE_SPECIFIED)
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
WDFMEMORY hMemory
WDF_OBJECT_ATTRIBUTES m_MemoryAttributes
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
_Must_inspect_result_ __in_opt PWDF_OBJECT_ATTRIBUTES LookasideAttributes
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
Definition: fxobject.hpp:734
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
#define NULL
Definition: types.h:112
VOID DeleteFromFailedCreate(VOID)
Definition: fxobject.cpp:391
_Must_inspect_result_ __in_opt PWDF_OBJECT_ATTRIBUTES __in __in __in_opt PWDF_OBJECT_ATTRIBUTES MemoryAttributes
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ _Strict_type_match_ POOL_TYPE PoolType
Definition: wdfdevice.h:3810
unsigned int ULONG
Definition: retypes.h:1
FxObjectHandleGetPtrAndGlobals(GetFxDriverGlobals(DriverGlobals), Device, FX_TYPE_DEVICE,(PVOID *)&pDevice, &pFxDriverGlobals)
pFxDriverGlobals
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES LookasideAttributes
Definition: wdfmemory.h:401
__inline PFX_DRIVER_GLOBALS GetFxDriverGlobals(__in PWDF_DRIVER_GLOBALS DriverGlobals)
Definition: fxglobals.h:597
#define __in
Definition: dbghelp.h:35
#define APC_LEVEL
Definition: env_spec_w32.h:695
#define BufferSize
Definition: mmc.h:75
FxObject * pParent
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:251
Definition: ps.c:97