ReactOS  0.4.15-dev-4614-ga5a6101
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 {
47 }
48 
51  IN PIRP Irp,
52  IN LPWSTR ObjectClass,
53  IN OUT PULONG Size,
54  OUT PVOID * Result)
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 }
87 
88 /*
89  @implemented
90 */
92 PVOID
93 NTAPI
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 }
105 
106 /*
107  @implemented
108 */
109 KSDDKAPI
111 NTAPI
114 {
115  PKSIOBJECT_HEADER ObjectHeader;
116 
117  /* get object header */
118  ObjectHeader = (PKSIOBJECT_HEADER)FileObject->FsContext2;
119  /* return type */
120  return ObjectHeader->Type;
121 }
122 
123 /*
124  @implemented
125 */
127 NTAPI
129  IN PIRP Irp)
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 }
141 
142 /*
143  @implemented
144 */
145 PUNKNOWN
146 NTAPI
148  IN PVOID Object)
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 }
159 
160 /*
161  @implemented
162 */
163 KSDDKAPI
164 PVOID
165 NTAPI
167  IN PVOID Object)
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 }
175 
176 
VOID FreeItem(IN PVOID Item)
Definition: misc.c:43
struct KSBASIC_HEADER * PKSBASIC_HEADER
#define IN
Definition: typedefs.h:39
KSDDKAPI KSOBJECTTYPE NTAPI KsGetObjectTypeFromFileObject(IN PFILE_OBJECT FileObject)
Definition: misc.c:112
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
KSDDKAPI PVOID NTAPI KsGetParent(IN PVOID Object)
Definition: misc.c:166
KSOBJECTTYPE Type
Definition: kstypes.h:23
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
#define TAG_KS
Definition: misc.c:14
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:50
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
PUNKNOWN OuterUnknown
Definition: kstypes.h:62
#define KSDDKAPI
Definition: ks.h:40
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264
uint32_t ULONG_PTR
Definition: typedefs.h:65
union KSBASIC_HEADER::@955 Parent
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
_In_ WDFREQUEST _In_ NTSTATUS _In_ CCHAR PriorityBoost
Definition: wdfrequest.h:1011
_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
#define IoCompleteRequest
Definition: irp.c:1240
KSOBJECTTYPE Type
Definition: kstypes.h:56
Definition: bufpool.h:45
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
PVOID ObjectType
Definition: kstypes.h:30
PKSDEVICE KsDevice
Definition: kstypes.h:57
KSOBJECTTYPE NTAPI KsGetObjectTypeFromIrp(IN PIRP Irp)
Definition: misc.c:128
VOID CompleteRequest(PIRP Irp, CCHAR PriorityBoost)
Definition: misc.c:17
#define ASSERT(a)
Definition: mode.c:44
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define STATUS_PENDING
Definition: ntstatus.h:82
char CCHAR
Definition: typedefs.h:51
INT POOL_TYPE
Definition: typedefs.h:78
* PFILE_OBJECT
Definition: iotypes.h:1998
KSDDKAPI PVOID NTAPI KsGetObjectFromFileObject(IN PFILE_OBJECT FileObject)
Definition: misc.c:94
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
_Must_inspect_result_ _In_ WDFCOLLECTION _In_ WDFOBJECT Object
__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
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS _Inout_ PLARGE_INTEGER NumberOfBytes
Definition: iotypes.h:1035
unsigned int * PULONG
Definition: retypes.h:1
#define NULL
Definition: types.h:112
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
_In_ WDFCOLLECTION _In_ WDFOBJECT Item
PVOID AllocateItem(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
Definition: misc.c:30
#define OUT
Definition: typedefs.h:40
_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
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define STATUS_SUCCESS
Definition: shellext.h:65
KSOBJECTTYPE
Definition: ks.h:1207
#define DPRINT
Definition: sndvol32.h:71
WCHAR * LPWSTR
Definition: xmlstorage.h:184
PUNKNOWN NTAPI KsGetOuterUnknown(IN PVOID Object)
Definition: misc.c:147
#define ExFreePool(addr)
Definition: env_spec_w32.h:352