ReactOS  0.4.14-dev-323-g6fe6a88
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 NTAPI KspForwardIrpSynchronousCompletion (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
 
NTSTATUS KspForwardIrpSynchronous (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
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:998
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
_Must_inspect_result_ _In_ FLT_CONTEXT_TYPE _In_ SIZE_T _In_ POOL_TYPE PoolType
Definition: fltkernel.h:1444

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_ PIRP Irp
Definition: csq.h:116
_In_ CCHAR PriorityBoost
Definition: iofuncs.h:763
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
#define STATUS_PENDING
Definition: ntstatus.h:82
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)

◆ FreeItem()

VOID FreeItem ( IN PVOID  Item)

Definition at line 43 of file misc.c.

45 {
46  ExFreePool(Item);
47 }
#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 145 of file misc.c.

147 {
148  PKSIOBJECT_HEADER ObjectHeader;
149 
150  /* get object header */
151  ObjectHeader = (PKSIOBJECT_HEADER)FileObject->FsContext2;
152 
153  /* return associated object */
154  return ObjectHeader->ObjectType;
155 }
struct KSIOBJECT_HEADER * PKSIOBJECT_HEADER
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
PVOID ObjectType
Definition: kstypes.h:30

◆ KsGetObjectTypeFromFileObject()

KSDDKAPI KSOBJECTTYPE NTAPI KsGetObjectTypeFromFileObject ( IN PFILE_OBJECT  FileObject)

Definition at line 163 of file misc.c.

165 {
166  PKSIOBJECT_HEADER ObjectHeader;
167 
168  /* get object header */
169  ObjectHeader = (PKSIOBJECT_HEADER)FileObject->FsContext2;
170  /* return type */
171  return ObjectHeader->Type;
172 }
KSOBJECTTYPE Type
Definition: kstypes.h:23
struct KSIOBJECT_HEADER * PKSIOBJECT_HEADER
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593

◆ KsGetObjectTypeFromIrp()

KSOBJECTTYPE NTAPI KsGetObjectTypeFromIrp ( IN PIRP  Irp)

Definition at line 179 of file misc.c.

181 {
182  PKSIOBJECT_HEADER ObjectHeader;
183  PIO_STACK_LOCATION IoStack;
184 
185  /* get current irp stack */
187  /* get object header */
188  ObjectHeader = (PKSIOBJECT_HEADER)IoStack->FileObject->FsContext2;
189  /* return type */
190  return ObjectHeader->Type;
191 }
KSOBJECTTYPE Type
Definition: kstypes.h:23
_In_ PIRP Irp
Definition: csq.h:116
struct KSIOBJECT_HEADER * PKSIOBJECT_HEADER
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PFILE_OBJECT FileObject
Definition: iotypes.h:2813

◆ KsGetOuterUnknown()

PUNKNOWN NTAPI KsGetOuterUnknown ( IN PVOID  Object)

Definition at line 198 of file misc.c.

200 {
201  PKSBASIC_HEADER BasicHeader = (PKSBASIC_HEADER)((ULONG_PTR)Object - sizeof(KSBASIC_HEADER));
202 
203  /* sanity check */
204  ASSERT(BasicHeader->Type == KsObjectTypeDevice || BasicHeader->Type == KsObjectTypeFilterFactory ||
205  BasicHeader->Type == KsObjectTypeFilter || BasicHeader->Type == KsObjectTypePin);
206 
207  /* return objects outer unknown */
208  return BasicHeader->OuterUnknown;
209 }
struct KSBASIC_HEADER * PKSBASIC_HEADER
PUNKNOWN OuterUnknown
Definition: kstypes.h:62
uint32_t ULONG_PTR
Definition: typedefs.h:63
KSOBJECTTYPE Type
Definition: kstypes.h:56
static IUnknown Object
Definition: main.c:512
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)

◆ KsGetParent()

KSDDKAPI PVOID NTAPI KsGetParent ( IN PVOID  Object)

Definition at line 217 of file misc.c.

219 {
220  PKSBASIC_HEADER BasicHeader = (PKSBASIC_HEADER)((ULONG_PTR)Object - sizeof(KSBASIC_HEADER));
221  /* sanity check */
222  ASSERT(BasicHeader->Parent.KsDevice != NULL);
223  /* return object type */
224  return (PVOID)BasicHeader->Parent.KsDevice;
225 }
struct KSBASIC_HEADER * PKSBASIC_HEADER
uint32_t ULONG_PTR
Definition: typedefs.h:63
union KSBASIC_HEADER::@979 Parent
smooth NULL
Definition: ftsmooth.c:416
PKSDEVICE KsDevice
Definition: kstypes.h:57
static IUnknown Object
Definition: main.c:512
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)

Referenced by USBAudioFilterCreate().

◆ KspCopyCreateRequest()

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

Definition at line 101 of file misc.c.

106 {
107  PIO_STACK_LOCATION IoStack;
108  SIZE_T ObjectLength, ParametersLength;
109  PVOID Buffer;
110 
111  /* get current irp stack */
113 
114  /* get object class length */
115  ObjectLength = (wcslen(ObjectClass) + 1) * sizeof(WCHAR);
116 
117  /* check for minium length requirement */
118  if (ObjectLength + *Size > IoStack->FileObject->FileName.MaximumLength)
119  return STATUS_UNSUCCESSFUL;
120 
121  /* extract parameters length */
122  ParametersLength = IoStack->FileObject->FileName.MaximumLength - ObjectLength;
123 
124  /* allocate buffer */
125  Buffer = AllocateItem(NonPagedPool, ParametersLength);
126  if (!Buffer)
128 
129  /* copy parameters */
130  RtlMoveMemory(Buffer, &IoStack->FileObject->FileName.Buffer[ObjectLength / sizeof(WCHAR)], ParametersLength);
131 
132  /* store result */
133  *Result = Buffer;
134  *Size = (ULONG)ParametersLength;
135 
136  return STATUS_SUCCESS;
137 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ PIRP Irp
Definition: csq.h:116
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:263
_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
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
ULONG_PTR SIZE_T
Definition: typedefs.h:78
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
PVOID AllocateItem(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
Definition: misc.c:30
unsigned int ULONG
Definition: retypes.h:1
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
return STATUS_SUCCESS
Definition: btrfs.c:2938
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

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

◆ KspForwardIrpSynchronous()

NTSTATUS KspForwardIrpSynchronous ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 65 of file misc.c.

68 {
69  KEVENT Event;
71  PDEVICE_EXTENSION DeviceExtension;
72  PKSIDEVICE_HEADER DeviceHeader;
73 
75 
76  /* get device extension */
78  /* get device header */
79  DeviceHeader = DeviceExtension->DeviceHeader;
80 
81  /* initialize the notification event */
83 
85 
87 
88  /* now call the driver */
89  Status = IoCallDriver(DeviceHeader->KsDevice.NextDeviceObject, Irp);
90  /* did the request complete yet */
91  if (Status == STATUS_PENDING)
92  {
93  /* not yet, lets wait a bit */
95  Status = Irp->IoStatus.Status;
96  }
97  return Status;
98 }
#define TRUE
Definition: types.h:120
_In_ PIRP Irp
Definition: csq.h:116
#define ASSERT_IRQL_EQUAL(x)
Definition: debug.h:43
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
KSDEVICE KsDevice
Definition: kstypes.h:88
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:515
FORCEINLINE VOID IoCopyCurrentIrpStackLocationToNext(_Inout_ PIRP Irp)
Definition: iofuncs.h:2820
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:435
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
#define STATUS_PENDING
Definition: ntstatus.h:82
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
NTSTATUS NTAPI KspForwardIrpSynchronousCompletion(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
Definition: misc.c:51
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
struct _BEEP_DEVICE_EXTENSION * PDEVICE_EXTENSION

Referenced by IKsDevice_Pnp(), and IKsDevice_PnpStartDevice().

◆ KspForwardIrpSynchronousCompletion()

NTSTATUS NTAPI KspForwardIrpSynchronousCompletion ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp,
IN PVOID  Context 
)

Definition at line 51 of file misc.c.

55 {
56  if (Irp->PendingReturned != FALSE)
57  {
59  }
61 }
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:68
_In_ PIRP Irp
Definition: csq.h:116
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
#define IO_NO_INCREMENT
Definition: iotypes.h:566

Referenced by KspForwardIrpSynchronous().