ReactOS  0.4.13-dev-257-gfabbd7c
misc.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS Kernel Streaming
4  * FILE: drivers/ksfilter/ks/misc.c
5  * PURPOSE: KS Allocator functions
6  * PROGRAMMER: Johannes Anderwald
7  */
8 
9 #include "precomp.h"
10 
11 #define NDEBUG
12 #include <debug.h>
13 
14 #define TAG_KS 'ssKK'
15 
16 VOID
18  PIRP Irp,
20 {
21  DPRINT("Completing IRP %p Status %x\n", Irp, Irp->IoStatus.Status);
22 
23  ASSERT(Irp->IoStatus.Status != STATUS_PENDING);
24 
25 
27 }
28 
29 PVOID
33 {
35  if (!Item)
36  return Item;
37 
39  return Item;
40 }
41 
42 VOID
44  IN PVOID Item)
45 {
46  ExFreePool(Item);
47 }
48 
50 NTAPI
53  IN PIRP Irp,
55 {
56  if (Irp->PendingReturned != FALSE)
57  {
59  }
61 }
62 
63 
67  IN PIRP Irp)
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 }
99 
100 NTSTATUS
102  IN PIRP Irp,
103  IN LPWSTR ObjectClass,
104  IN OUT PULONG Size,
105  OUT PVOID * Result)
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 }
138 
139 /*
140  @implemented
141 */
142 KSDDKAPI
143 PVOID
144 NTAPI
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 }
156 
157 /*
158  @implemented
159 */
160 KSDDKAPI
162 NTAPI
165 {
166  PKSIOBJECT_HEADER ObjectHeader;
167 
168  /* get object header */
169  ObjectHeader = (PKSIOBJECT_HEADER)FileObject->FsContext2;
170  /* return type */
171  return ObjectHeader->Type;
172 }
173 
174 /*
175  @implemented
176 */
178 NTAPI
180  IN PIRP Irp)
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 }
192 
193 /*
194  @implemented
195 */
196 PUNKNOWN
197 NTAPI
199  IN PVOID Object)
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 }
210 
211 /*
212  @implemented
213 */
214 KSDDKAPI
215 PVOID
216 NTAPI
218  IN PVOID Object)
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 }
226 
227 
VOID FreeItem(IN PVOID Item)
Definition: misc.c:43
struct KSBASIC_HEADER * PKSBASIC_HEADER
#define IN
Definition: typedefs.h:38
KSDDKAPI KSOBJECTTYPE NTAPI KsGetObjectTypeFromFileObject(IN PFILE_OBJECT FileObject)
Definition: misc.c:163
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
KSDDKAPI PVOID NTAPI KsGetParent(IN PVOID Object)
Definition: misc.c:217
KSOBJECTTYPE Type
Definition: kstypes.h:23
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:63
_In_ PIRP Irp
Definition: csq.h:116
#define TAG_KS
Definition: misc.c:14
#define ASSERT_IRQL_EQUAL(x)
Definition: debug.h:43
struct KSIOBJECT_HEADER * PKSIOBJECT_HEADER
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS KspCopyCreateRequest(IN PIRP Irp, IN LPWSTR ObjectClass, IN OUT PULONG Size, OUT PVOID *Result)
Definition: misc.c:101
PUNKNOWN OuterUnknown
Definition: kstypes.h:62
NTSTATUS KspForwardIrpSynchronous(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: misc.c:65
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
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
#define KSDDKAPI
Definition: ks.h:40
KSDEVICE KsDevice
Definition: kstypes.h:88
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:515
uint32_t ULONG_PTR
Definition: typedefs.h:63
FORCEINLINE VOID IoCopyCurrentIrpStackLocationToNext(_Inout_ PIRP Irp)
Definition: iofuncs.h:2820
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
_In_ CCHAR PriorityBoost
Definition: iofuncs.h:763
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:434
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
_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
#define IoCompleteRequest
Definition: irp.c:1240
KSOBJECTTYPE Type
Definition: kstypes.h:56
void DPRINT(...)
Definition: polytest.cpp:61
Definition: bufpool.h:45
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
PVOID ObjectType
Definition: kstypes.h:30
PKSDEVICE KsDevice
Definition: kstypes.h:57
KSOBJECTTYPE NTAPI KsGetObjectTypeFromIrp(IN PIRP Irp)
Definition: misc.c:179
VOID CompleteRequest(PIRP Irp, CCHAR PriorityBoost)
Definition: misc.c:17
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define STATUS_PENDING
Definition: ntstatus.h:82
char CCHAR
Definition: typedefs.h:50
INT POOL_TYPE
Definition: typedefs.h:76
* PFILE_OBJECT
Definition: iotypes.h:1954
static IUnknown Object
Definition: main.c:512
KSDDKAPI PVOID NTAPI KsGetObjectFromFileObject(IN PFILE_OBJECT FileObject)
Definition: misc.c:145
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
union KSBASIC_HEADER::@953 Parent
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__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:2812
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
unsigned int * PULONG
Definition: retypes.h:1
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
PVOID AllocateItem(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
Definition: misc.c:30
#define OUT
Definition: typedefs.h:39
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS _Inout_ PLARGE_INTEGER NumberOfBytes
Definition: iotypes.h:997
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:565
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
KSOBJECTTYPE
Definition: ks.h:1237
WCHAR * LPWSTR
Definition: xmlstorage.h:184
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
return STATUS_SUCCESS
Definition: btrfs.c:2745
_Must_inspect_result_ _In_ FLT_CONTEXT_TYPE _In_ SIZE_T _In_ POOL_TYPE PoolType
Definition: fltkernel.h:1444
PUNKNOWN NTAPI KsGetOuterUnknown(IN PVOID Object)
Definition: misc.c:198
struct _BEEP_DEVICE_EXTENSION * PDEVICE_EXTENSION
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define ExFreePool(addr)
Definition: env_spec_w32.h:352