ReactOS 0.4.15-dev-8241-g63935f8
handleapi.cpp File Reference
#include "fxobjectpch.hpp"
Include dependency graph for handleapi.cpp:

Go to the source code of this file.

Functions

size_t FxGetContextSize (__in_opt PWDF_OBJECT_ATTRIBUTES Attributes)
 
_Must_inspect_result_ NTSTATUS FxCalculateObjectTotalSize2 (__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in USHORT RawObjectSize, __in USHORT ExtraSize, __in size_t ContextSize, __out size_t *Total)
 
_Must_inspect_result_ NTSTATUS FxCalculateObjectTotalSize (__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in USHORT RawObjectSize, __in USHORT ExtraSize, __in_opt PWDF_OBJECT_ATTRIBUTES Attributes, __out size_t *Total)
 
PVOID FxObjectHandleAlloc (__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in POOL_TYPE PoolType, __in size_t Size, __in ULONG Tag, __in_opt PWDF_OBJECT_ATTRIBUTES Attributes, __in USHORT ExtraSize, __in FxObjectType ObjectType)
 
VOID FxContextHeaderInit (__in FxContextHeader *Header, __in FxObject *Object, __in_opt PWDF_OBJECT_ATTRIBUTES Attributes)
 
PVOID FxObjectAndHandleHeaderInit (__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PVOID AllocationStart, __in USHORT ObjectSize, __in_opt PWDF_OBJECT_ATTRIBUTES Attributes, __in FxObjectType ObjectType)
 
VOID FxObjectHandleGetPtrQI (__in FxObject *Object, __out PVOID *PPObject, __in WDFOBJECT Handle, __in WDFTYPE Type, __in WDFOBJECT_OFFSET Offset)
 
_Must_inspect_result_ NTSTATUS FxObjectAllocateContext (__in FxObject *Object, __in PWDF_OBJECT_ATTRIBUTES Attributes, __in BOOLEAN AllowCallbacksOnly, __deref_opt_out PVOID *Context)
 
_Must_inspect_result_ __drv_maxIRQL (DISPATCH_LEVEL) WDFAPI NTSTATUS STDCALL WDFEXPORT(WdfObjectAllocateContext)(__in PWDF_DRIVER_GLOBALS DriverGlobals
 
 FxPointerNotNull (GetFxDriverGlobals(DriverGlobals), Handle)
 
 if (offset !=0)
 
 __drv_maxIRQL (DISPATCH_LEVEL+1) WDFAPI PVOID FASTCALL WDFEXPORT(WdfObjectGetTypedContextWorker)(__in PWDF_DRIVER_GLOBALS DriverGlobals
 
 FxPointerNotNull (pFxDriverGlobals, TypeInfo)
 
 for (;pHeader !=NULL;pHeader=pHeader->NextHeader)
 
 if (TypeInfo->ContextName !=NULL)
 
 DoTraceLevelMessage (pFxDriverGlobals, TRACE_LEVEL_WARNING, TRACINGHANDLE, "Attempting to get context type %s from WDFOBJECT 0x%p", pGivenName, Handle)
 
 return (WDFOBJECT) pObject -> GetObjectHandle()
 

Variables

_Must_inspect_result_ __in WDFOBJECT Handle
 
_Must_inspect_result_ __in WDFOBJECT __in PWDF_OBJECT_ATTRIBUTES Attributes
 
_Must_inspect_result_ __in WDFOBJECT __in PWDF_OBJECT_ATTRIBUTES __deref_opt_out PVOIDContext
 
NTSTATUS status = FxObjectAllocateContext(object, Attributes, FALSE, Context)
 
FxObjectobject = FxObject::_GetObjectFromHandle(Handle, &offset)
 
WDFOBJECT_OFFSET offset = 0
 
Done __pad0__
 
__in WDFOBJECT __in PCWDF_OBJECT_CONTEXT_TYPE_INFO TypeInfo
 
FxContextHeaderpHeader = pObject->GetContextHeader()
 
FxObjectpObject = FxObject::_GetObjectFromHandle(Handle, &offset)
 
PFX_DRIVER_GLOBALS pFxDriverGlobals = pObject->GetDriverGlobals()
 
PCHAR pGivenName
 
 else
 
return NULL
 
__in PVOID ContextPointer
 

Function Documentation

◆ __drv_maxIRQL() [1/2]

◆ __drv_maxIRQL() [2/2]

__drv_maxIRQL ( DISPATCH_LEVEL 1)

◆ DoTraceLevelMessage()

◆ for()

for ( ;pHeader = NULLpHeader = pHeader->NextHeader)

Definition at line 634 of file handleapi.cpp.

634 {
636 return &pHeader->Context[0];
637 }
638 }
__in WDFOBJECT __in PCWDF_OBJECT_CONTEXT_TYPE_INFO TypeInfo
Definition: handleapi.cpp:601
FxContextHeader * pHeader
Definition: handleapi.cpp:604
PCWDF_OBJECT_CONTEXT_TYPE_INFO ContextTypeInfo
Definition: fxhandle.h:87

◆ FxCalculateObjectTotalSize()

_Must_inspect_result_ NTSTATUS FxCalculateObjectTotalSize ( __in PFX_DRIVER_GLOBALS  FxDriverGlobals,
__in USHORT  RawObjectSize,
__in USHORT  ExtraSize,
__in_opt PWDF_OBJECT_ATTRIBUTES  Attributes,
__out size_t Total 
)

Definition at line 147 of file handleapi.cpp.

154{
155 return FxCalculateObjectTotalSize2(FxDriverGlobals,
156 RawObjectSize,
157 ExtraSize,
159 Total);
160}
size_t FxGetContextSize(__in_opt PWDF_OBJECT_ATTRIBUTES Attributes)
Definition: handleapi.cpp:38
_Must_inspect_result_ NTSTATUS FxCalculateObjectTotalSize2(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in USHORT RawObjectSize, __in USHORT ExtraSize, __in size_t ContextSize, __out size_t *Total)
Definition: handleapi.cpp:73
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes

Referenced by FxObjectAllocateContext(), FxObjectHandleAlloc(), FxLookasideList::InitializeLookaside(), and VfAllocateContext().

◆ FxCalculateObjectTotalSize2()

_Must_inspect_result_ NTSTATUS FxCalculateObjectTotalSize2 ( __in PFX_DRIVER_GLOBALS  FxDriverGlobals,
__in USHORT  RawObjectSize,
__in USHORT  ExtraSize,
__in size_t  ContextSize,
__out size_t Total 
)

Definition at line 73 of file handleapi.cpp.

97{
99
100 *Total = 0;
101
102 status = RtlSizeTAdd(
105 Total
106 );
107
108 if (NT_SUCCESS(status)) {
109 if (ContextSize != 0) {
110 size_t alignUp;
111
112 alignUp = ALIGN_UP(ContextSize, PVOID);
113
114 //
115 // overflow after aligning up to a pointer boundary;
116 //
117 if (alignUp < ContextSize) {
119 }
120
121 status = RtlSizeTAdd(*Total, alignUp, Total);
122 }
123 }
124
125 if (NT_SUCCESS(status) && FxDriverGlobals->IsObjectDebugOn()) {
126 //
127 // Attempt to add in the debug extension
128 //
129 status = RtlSizeTAdd(*Total,
131 Total);
132 }
133
134 if (!NT_SUCCESS(status)) {
136 FxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGOBJECT,
137 "Size overflow, object size 0x%x, extra object size 0x%x, "
138 "context size 0x%I64x, %!STATUS!",
139 RawObjectSize, ExtraSize, ContextSize, status);
140 }
141
142 return status;
143}
LONG NTSTATUS
Definition: precomp.h:26
#define TRACINGOBJECT
Definition: dbgtrace.h:59
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_Must_inspect_result_ _In_ FLT_CONTEXT_TYPE _In_ SIZE_T ContextSize
Definition: fltkernel.h:1444
#define FX_CONTEXT_HEADER_SIZE
Definition: fxhandle.h:98
#define COMPUTE_OBJECT_SIZE(_rawObjectSize, _extraSize)
Definition: fxhandle.h:107
@ FxObjectDebugExtensionSize
Definition: fxobject.hpp:226
NTSTATUS status
Definition: handleapi.cpp:537
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_WARNING, TRACINGHANDLE, "Attempting to get context type %s from WDFOBJECT 0x%p", pGivenName, Handle)
#define MEMORY_ALLOCATION_ALIGNMENT
Definition: ntbasedef.h:90
#define STATUS_INTEGER_OVERFLOW
Definition: ntstatus.h:385
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
Definition: ps.c:97
#define ALIGN_UP(size, type)
Definition: umtypes.h:91
FORCEINLINE size_t WDF_ALIGN_SIZE_UP(_In_ size_t Length, _In_ size_t AlignTo)
Definition: wdfcore.h:129

Referenced by FxCalculateObjectTotalSize(), and FxDevice::Initialize().

◆ FxContextHeaderInit()

VOID FxContextHeaderInit ( __in FxContextHeader Header,
__in FxObject Object,
__in_opt PWDF_OBJECT_ATTRIBUTES  Attributes 
)

Definition at line 248 of file handleapi.cpp.

264{
266
267 Header->Object = Object;
268
269 if (Attributes != NULL) {
270 if (Attributes->ContextTypeInfo != NULL) {
271 size_t contextSize;
272
273 if (Attributes->ContextSizeOverride != 0) {
274 contextSize = Attributes->ContextSizeOverride;
275
276 }
277 else {
278 contextSize = Attributes->ContextTypeInfo->ContextSize;
279 }
280
281 //
282 // Zero initialize the entire context
283 //
284 RtlZeroMemory(&Header->Context[0], ALIGN_UP(contextSize, PVOID));
285 }
286
287 Header->ContextTypeInfo = Attributes->ContextTypeInfo;
288 }
289}
Definition: Header.h:9
return NULL
Definition: handleapi.cpp:653
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
_Must_inspect_result_ _In_ WDFCOLLECTION _In_ WDFOBJECT Object

Referenced by FxObjectAllocateContext(), FxObjectAndHandleHeaderInit(), and VfAddContextToHandle().

◆ FxGetContextSize()

size_t FxGetContextSize ( __in_opt PWDF_OBJECT_ATTRIBUTES  Attributes)

Definition at line 38 of file handleapi.cpp.

54{
55 size_t contextSize = 0;
56
57 if (Attributes != NULL) {
58 if (Attributes->ContextTypeInfo != NULL) {
59 if (Attributes->ContextSizeOverride != 0) {
60 contextSize = Attributes->ContextSizeOverride;
61 }
62 else {
63 contextSize = Attributes->ContextTypeInfo->ContextSize;
64 }
65 }
66 }
67
68 return contextSize;
69}

Referenced by FxCalculateObjectTotalSize(), and FxDevice::Initialize().

◆ FxObjectAllocateContext()

_Must_inspect_result_ NTSTATUS FxObjectAllocateContext ( __in FxObject Object,
__in PWDF_OBJECT_ATTRIBUTES  Attributes,
__in BOOLEAN  AllowCallbacksOnly,
__deref_opt_out PVOID Context 
)

Definition at line 397 of file handleapi.cpp.

419{
423 size_t size;
424 BOOLEAN relRef;
425 ULONG flags;
426
427 fxDriverGlobals = Object->GetDriverGlobals();
428 header = NULL;
429 relRef = FALSE;
430
431 //
432 // Init validation flags.
433 //
437 }
438
439 //
440 // Basic validations.
441 //
443 if (!NT_SUCCESS(status)) {
444 goto Done;
445 }
446
447 //
448 // Check for context type!
449 //
450 if (Attributes->ContextTypeInfo == NULL && AllowCallbacksOnly == FALSE) {
454 "Attributes %p ContextTypeInfo is NULL, %!STATUS!",
456 goto Done;
457 }
458
459 Object->ADDREF(&status);
460 relRef = TRUE;
461
462 //
463 // By passing 0's for raw object size and extra size, we can compute the
464 // size of only the header and its contents.
465 //
467 if (!NT_SUCCESS(status)) {
468 goto Done;
469 }
470
472 FxPoolAllocate(fxDriverGlobals, NonPagedPool, size);
473
474 if (header == NULL) {
476 goto Done;
477 }
478
480
481 status = Object->AddContext(header, Context, Attributes);
482
483 //
484 // STATUS_OBJECT_NAME_EXISTS will not fail NT_SUCCESS, so check
485 // explicitly for STATUS_SUCCESS.
486 //
487 if (status != STATUS_SUCCESS) {
489 }
490
491Done:
492
493 if (relRef) {
494 Object->RELEASE(&status);
495 }
496
497 return status;
498}
unsigned char BOOLEAN
#define TRACINGHANDLE
Definition: dbgtrace.h:61
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NonPagedPool
Definition: env_spec_w32.h:307
PFX_DRIVER_GLOBALS fxDriverGlobals
void FxPoolFree(__in_xcount(ptr is at an offset from AllocationStart) PVOID ptr)
Definition: wdfpool.cpp:361
@ FX_VALIDATE_OPTION_ATTRIBUTES_REQUIRED
@ FX_VALIDATE_OPTION_PARENT_NOT_ALLOWED
_Must_inspect_result_ NTSTATUS FxValidateObjectAttributes(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PWDF_OBJECT_ATTRIBUTES Attributes, __in ULONG Flags=FX_VALIDATE_OPTION_NONE_SPECIFIED)
GLsizeiptr size
Definition: glext.h:5919
GLbitfield flags
Definition: glext.h:7161
_Must_inspect_result_ NTSTATUS FxCalculateObjectTotalSize(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in USHORT RawObjectSize, __in USHORT ExtraSize, __in_opt PWDF_OBJECT_ATTRIBUTES Attributes, __out size_t *Total)
Definition: handleapi.cpp:147
VOID FxContextHeaderInit(__in FxContextHeader *Header, __in FxObject *Object, __in_opt PWDF_OBJECT_ATTRIBUTES Attributes)
Definition: handleapi.cpp:248
#define STATUS_SUCCESS
Definition: shellext.h:65
#define TRACE_LEVEL_WARNING
Definition: storswtr.h:28
_Must_inspect_result_ BOOLEAN IsVersionGreaterThanOrEqualTo(__in ULONG Major, __in ULONG Minor)
Definition: globalskm.cpp:92
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_OBJECT_NAME_INVALID
Definition: udferr_usr.h:148
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158

Referenced by FxPkgGeneral::OnCreate(), and FxUsbInterface::UpdatePipeAttributes().

◆ FxObjectAndHandleHeaderInit()

PVOID FxObjectAndHandleHeaderInit ( __in PFX_DRIVER_GLOBALS  FxDriverGlobals,
__in PVOID  AllocationStart,
__in USHORT  ObjectSize,
__in_opt PWDF_OBJECT_ATTRIBUTES  Attributes,
__in FxObjectType  ObjectType 
)

Definition at line 292 of file handleapi.cpp.

318{
320
321 if (FxDriverGlobals->IsObjectDebugOn()) {
322 FxObjectDebugExtension* pExtension;
323
324 pExtension = (FxObjectDebugExtension*) AllocationStart;
325
328
329 pObject = (FxObject*) &pExtension->AllocationStart[0];
330 }
331 else {
332 pObject = (FxObject*) AllocationStart;
333 }
334
338 pObject,
340 );
341 }
342
343 return pObject;
344}
@ FxObjectDebugExtensionSignature
Definition: fxobject.hpp:227
@ FxObjectTypeExternal
Definition: fxobject.hpp:120
FxObject * pObject
Definition: handleapi.cpp:605
ObjectType
Definition: metafile.c:81
#define WDF_PTR_ADD_OFFSET(_ptr, _offset)
Definition: wdfcore.h:144

Referenced by FxDevice::AllocateRequestMemory(), FxObjectHandleAlloc(), FxMemoryBufferFromPoolLookaside::operator new(), and FxMemoryBufferFromLookaside::operator new().

◆ FxObjectHandleAlloc()

PVOID FxObjectHandleAlloc ( __in PFX_DRIVER_GLOBALS  FxDriverGlobals,
__in POOL_TYPE  PoolType,
__in size_t  Size,
__in ULONG  Tag,
__in_opt PWDF_OBJECT_ATTRIBUTES  Attributes,
__in USHORT  ExtraSize,
__in FxObjectType  ObjectType 
)

Definition at line 163 of file handleapi.cpp.

195{
196 PVOID blob;
197 size_t totalSize;
199
200 if (Tag == 0) {
201 Tag = FxDriverGlobals->Tag;
202 ASSERT(Tag != 0);
203 }
204
206 //
207 // An internal object might need the debug extension size added to it,
208 // but that's it. No extra size, no FxContextHeader.
209 //
210 if (FxDriverGlobals->IsObjectDebugOn()) {
211 status = RtlSizeTAdd(Size,
213 &totalSize);
214 }
215 else {
216 totalSize = Size;
218 }
219 }
220 else {
221 status = FxCalculateObjectTotalSize(FxDriverGlobals,
222 (USHORT) Size,
223 ExtraSize,
225 &totalSize);
226 }
227
228 if (!NT_SUCCESS(status)) {
229 return NULL;
230 }
231
232 blob = FxPoolAllocateWithTag(FxDriverGlobals, PoolType, totalSize, Tag);
233
234 if (blob != NULL) {
236 FxDriverGlobals,
237 blob,
238 COMPUTE_OBJECT_SIZE((USHORT) Size, ExtraSize),
241 );
242 }
243
244 return blob;
245}
@ FxObjectTypeInternal
Definition: fxobject.hpp:119
PVOID FxObjectAndHandleHeaderInit(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PVOID AllocationStart, __in USHORT ObjectSize, __in_opt PWDF_OBJECT_ATTRIBUTES Attributes, __in FxObjectType ObjectType)
Definition: handleapi.cpp:292
#define ASSERT(a)
Definition: mode.c:44
unsigned short USHORT
Definition: pedump.c:61
Definition: image.c:134
_Must_inspect_result_ _In_ WDFDEVICE _In_ BOOLEAN _In_opt_ PVOID Tag
Definition: wdfdevice.h:4065
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ _Strict_type_match_ POOL_TYPE PoolType
Definition: wdfdevice.h:3815
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533

Referenced by FxObject::operator new(), and FxMemoryBuffer::operator new().

◆ FxObjectHandleGetPtrQI()

VOID FxObjectHandleGetPtrQI ( __in FxObject Object,
__out PVOID PPObject,
__in WDFOBJECT  Handle,
__in WDFTYPE  Type,
__in WDFOBJECT_OFFSET  Offset 
)

Definition at line 347 of file handleapi.cpp.

370{
371 FxQueryInterfaceParams params = { PPObject, Type, Offset };
373
374 *PPObject = NULL;
375
376 status = Object->QueryInterface(&params);
377
378 if (!NT_SUCCESS(status)) {
380 Object->GetDriverGlobals(), TRACE_LEVEL_ERROR, TRACINGDEVICE,
381 "Object Type Mismatch, Handle 0x%p, Type 0x%x, "
382 "Obj 0x%p, SB 0x%x",
383 Handle, Type, Object, Object->GetType());
384
385 FxVerifierBugCheck(Object->GetDriverGlobals(),
388 Type);
389
390 /* NOTREACHED */
391 return;
392 }
393}
Type
Definition: Type.h:7
#define TRACINGDEVICE
Definition: dbgtrace.h:58
#define FxVerifierBugCheck(FxDriverGlobals, Error,...)
Definition: fxverifier.h:58
GLenum const GLfloat * params
Definition: glext.h:5645
_Must_inspect_result_ __in WDFOBJECT Handle
Definition: handleapi.cpp:512
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
uint32_t ULONG_PTR
Definition: typedefs.h:65
@ WDF_INVALID_HANDLE
Definition: wdfbugcodes.h:62

Referenced by FxObjectHandleGetPtr(), and FxObjectHandleGetPtrOffset().

◆ FxPointerNotNull() [1/2]

FxPointerNotNull ( GetFxDriverGlobals(DriverGlobals ,
Handle   
)

◆ FxPointerNotNull() [2/2]

FxPointerNotNull ( pFxDriverGlobals  ,
TypeInfo   
)

◆ if() [1/2]

if ( offset = 0)

Definition at line 552 of file handleapi.cpp.

552 {
553
554
555
558 object->GetDriverGlobals(), TRACE_LEVEL_WARNING, TRACINGHANDLE,
559 "WDFHANDLE %p cannot have contexts added to it, %!STATUS!",
560 Handle, status);
561 goto Done;
562 }
#define STATUS_OBJECT_PATH_INVALID
Definition: ntstatus.h:293

◆ if() [2/2]

if ( TypeInfo->ContextName !  = NULL)

Definition at line 642 of file handleapi.cpp.

642 {
643 pGivenName = TypeInfo->ContextName;
644 }
PCHAR pGivenName
Definition: handleapi.cpp:640

◆ return()

return ( WDFOBJECT  ) -> GetObjectHandle()

Variable Documentation

◆ __pad0__

Done __pad0__

Definition at line 569 of file handleapi.cpp.

◆ Attributes

◆ Context

◆ ContextPointer

__in PVOID ContextPointer
Initial value:

Definition at line 664 of file handleapi.cpp.

Referenced by KiInitializeContextThread(), WdfObjectContextGetObject(), and WriteMinidump().

◆ else

else
Initial value:
{
pGivenName = "<no typename given>"

Definition at line 645 of file handleapi.cpp.

◆ Handle

__in WDFOBJECT Handle

Definition at line 512 of file handleapi.cpp.

Referenced by FxObjectHandleGetPtrQI(), and if().

◆ NULL

◆ object

◆ offset

offset = 0

Definition at line 539 of file handleapi.cpp.

◆ pFxDriverGlobals

pFxDriverGlobals = pObject->GetDriverGlobals()

Definition at line 606 of file handleapi.cpp.

◆ pGivenName

PCHAR pGivenName

Definition at line 640 of file handleapi.cpp.

Referenced by if(), and VfWdfObjectGetTypedContext().

◆ pHeader

◆ pObject

Definition at line 605 of file handleapi.cpp.

Referenced by FxObjectAndHandleHeaderInit().

◆ status

◆ TypeInfo