ReactOS  0.4.15-dev-5137-g826bd41
misc.c File Reference
#include "precomp.h"
#include <debug.h>
Include dependency graph for misc.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define TAG_KS   'ssKK'
 

Functions

VOID CompleteRequest (PIRP Irp, CCHAR PriorityBoost)
 
PVOID AllocateItem (IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
 
VOID FreeItem (IN PVOID Item)
 
NTSTATUS KspCopyCreateRequest (IN PIRP Irp, IN LPWSTR ObjectClass, IN OUT PULONG Size, OUT PVOID *Result)
 
KSDDKAPI PVOID NTAPI KsGetObjectFromFileObject (IN PFILE_OBJECT FileObject)
 
KSDDKAPI KSOBJECTTYPE NTAPI KsGetObjectTypeFromFileObject (IN PFILE_OBJECT FileObject)
 
KSOBJECTTYPE NTAPI KsGetObjectTypeFromIrp (IN PIRP Irp)
 
PUNKNOWN NTAPI KsGetOuterUnknown (IN PVOID Object)
 
KSDDKAPI PVOID NTAPI KsGetParent (IN PVOID Object)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 11 of file misc.c.

◆ TAG_KS

#define TAG_KS   'ssKK'

Definition at line 14 of file misc.c.

Function Documentation

◆ AllocateItem()

PVOID AllocateItem ( IN POOL_TYPE  PoolType,
IN SIZE_T  NumberOfBytes 
)

Definition at line 30 of file misc.c.

33 {
35  if (!Item)
36  return Item;
37 
39  return Item;
40 }
#define TAG_KS
Definition: misc.c:14
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS _Inout_ PLARGE_INTEGER NumberOfBytes
Definition: iotypes.h:1035
_In_ WDFCOLLECTION _In_ WDFOBJECT Item
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ _Strict_type_match_ POOL_TYPE PoolType
Definition: wdfdevice.h:3810
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262

Referenced by KspCopyCreateRequest(), USBSTOR_ClassRequest(), and USBSTOR_GetMaxLUN().

◆ CompleteRequest()

VOID CompleteRequest ( PIRP  Irp,
CCHAR  PriorityBoost 
)

Definition at line 17 of file misc.c.

20 {
21  DPRINT("Completing IRP %p Status %x\n", Irp, Irp->IoStatus.Status);
22 
23  ASSERT(Irp->IoStatus.Status != STATUS_PENDING);
24 
25 
27 }
_In_ WDFREQUEST _In_ NTSTATUS _In_ CCHAR PriorityBoost
Definition: wdfrequest.h:1011
_In_ PIRP Irp
Definition: csq.h:116
#define IoCompleteRequest
Definition: irp.c:1240
#define ASSERT(a)
Definition: mode.c:44
#define STATUS_PENDING
Definition: ntstatus.h:82
#define DPRINT
Definition: sndvol32.h:71

◆ FreeItem()

VOID FreeItem ( IN PVOID  Item)

Definition at line 43 of file misc.c.

45 {
47 }
_In_ WDFCOLLECTION _In_ WDFOBJECT Item
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by USBSTOR_ClassRequest(), and USBSTOR_GetMaxLUN().

◆ KsGetObjectFromFileObject()

KSDDKAPI PVOID NTAPI KsGetObjectFromFileObject ( IN PFILE_OBJECT  FileObject)

Definition at line 94 of file misc.c.

96 {
97  PKSIOBJECT_HEADER ObjectHeader;
98 
99  /* get object header */
100  ObjectHeader = (PKSIOBJECT_HEADER)FileObject->FsContext2;
101 
102  /* return associated object */
103  return ObjectHeader->ObjectType;
104 }
struct KSIOBJECT_HEADER * PKSIOBJECT_HEADER
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
PVOID ObjectType
Definition: kstypes.h:30

◆ KsGetObjectTypeFromFileObject()

KSDDKAPI KSOBJECTTYPE NTAPI KsGetObjectTypeFromFileObject ( IN PFILE_OBJECT  FileObject)

Definition at line 112 of file misc.c.

114 {
115  PKSIOBJECT_HEADER ObjectHeader;
116 
117  /* get object header */
118  ObjectHeader = (PKSIOBJECT_HEADER)FileObject->FsContext2;
119  /* return type */
120  return ObjectHeader->Type;
121 }
KSOBJECTTYPE Type
Definition: kstypes.h:23
struct KSIOBJECT_HEADER * PKSIOBJECT_HEADER
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547

◆ KsGetObjectTypeFromIrp()

KSOBJECTTYPE NTAPI KsGetObjectTypeFromIrp ( IN PIRP  Irp)

Definition at line 128 of file misc.c.

130 {
131  PKSIOBJECT_HEADER ObjectHeader;
132  PIO_STACK_LOCATION IoStack;
133 
134  /* get current irp stack */
136  /* get object header */
137  ObjectHeader = (PKSIOBJECT_HEADER)IoStack->FileObject->FsContext2;
138  /* return type */
139  return ObjectHeader->Type;
140 }
KSOBJECTTYPE Type
Definition: kstypes.h:23
struct KSIOBJECT_HEADER * PKSIOBJECT_HEADER
_In_ PIRP Irp
Definition: csq.h:116
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2793
PFILE_OBJECT FileObject
Definition: iotypes.h:3169

◆ KsGetOuterUnknown()

PUNKNOWN NTAPI KsGetOuterUnknown ( IN PVOID  Object)

Definition at line 147 of file misc.c.

149 {
150  PKSBASIC_HEADER BasicHeader = (PKSBASIC_HEADER)((ULONG_PTR)Object - sizeof(KSBASIC_HEADER));
151 
152  /* sanity check */
153  ASSERT(BasicHeader->Type == KsObjectTypeDevice || BasicHeader->Type == KsObjectTypeFilterFactory ||
154  BasicHeader->Type == KsObjectTypeFilter || BasicHeader->Type == KsObjectTypePin);
155 
156  /* return objects outer unknown */
157  return BasicHeader->OuterUnknown;
158 }
struct KSBASIC_HEADER * PKSBASIC_HEADER
PUNKNOWN OuterUnknown
Definition: kstypes.h:62
uint32_t ULONG_PTR
Definition: typedefs.h:65
KSOBJECTTYPE Type
Definition: kstypes.h:56
#define ASSERT(a)
Definition: mode.c:44
_Must_inspect_result_ _In_ WDFCOLLECTION _In_ WDFOBJECT Object

◆ KsGetParent()

KSDDKAPI PVOID NTAPI KsGetParent ( IN PVOID  Object)

Definition at line 166 of file misc.c.

168 {
169  PKSBASIC_HEADER BasicHeader = (PKSBASIC_HEADER)((ULONG_PTR)Object - sizeof(KSBASIC_HEADER));
170  /* sanity check */
171  ASSERT(BasicHeader->Parent.KsDevice != NULL);
172  /* return object type */
173  return (PVOID)BasicHeader->Parent.KsDevice;
174 }
struct KSBASIC_HEADER * PKSBASIC_HEADER
uint32_t ULONG_PTR
Definition: typedefs.h:65
union KSBASIC_HEADER::@956 Parent
PKSDEVICE KsDevice
Definition: kstypes.h:57
#define ASSERT(a)
Definition: mode.c:44
_Must_inspect_result_ _In_ WDFCOLLECTION _In_ WDFOBJECT Object
#define NULL
Definition: types.h:112

Referenced by USBAudioFilterCreate().

◆ KspCopyCreateRequest()

NTSTATUS KspCopyCreateRequest ( IN PIRP  Irp,
IN LPWSTR  ObjectClass,
IN OUT PULONG  Size,
OUT PVOID Result 
)

Definition at line 50 of file misc.c.

55 {
56  PIO_STACK_LOCATION IoStack;
57  SIZE_T ObjectLength, ParametersLength;
58  PVOID Buffer;
59 
60  /* get current irp stack */
62 
63  /* get object class length */
64  ObjectLength = (wcslen(ObjectClass) + 1) * sizeof(WCHAR);
65 
66  /* check for minium length requirement */
67  if (ObjectLength + *Size > IoStack->FileObject->FileName.MaximumLength)
68  return STATUS_UNSUCCESSFUL;
69 
70  /* extract parameters length */
71  ParametersLength = IoStack->FileObject->FileName.MaximumLength - ObjectLength;
72 
73  /* allocate buffer */
74  Buffer = AllocateItem(NonPagedPool, ParametersLength);
75  if (!Buffer)
77 
78  /* copy parameters */
79  RtlMoveMemory(Buffer, &IoStack->FileObject->FileName.Buffer[ObjectLength / sizeof(WCHAR)], ParametersLength);
80 
81  /* store result */
82  *Result = Buffer;
83  *Size = (ULONG)ParametersLength;
84 
85  return STATUS_SUCCESS;
86 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264
_In_ PIRP Irp
Definition: csq.h:116
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
Definition: bufpool.h:45
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2793
ULONG_PTR SIZE_T
Definition: typedefs.h:80
PFILE_OBJECT FileObject
Definition: iotypes.h:3169
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
PVOID AllocateItem(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
Definition: misc.c:30
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by KspValidateConnectRequest(), KsValidateAllocatorCreateRequest(), KsValidateClockCreateRequest(), and KsValidateTopologyNodeCreateRequest().