ReactOS 0.4.16-dev-226-g79f2289
allocators.c File Reference
#include "precomp.h"
#include <debug.h>
Include dependency graph for allocators.c:

Go to the source code of this file.

Classes

struct  ALLOCATOR
 

Macros

#define NDEBUG
 

Typedefs

typedef PVOID(* PFNKSPAGEDPOOLALLOCATE) (IN PPAGED_LOOKASIDE_LIST Lookaside)
 
typedef PVOID(* PFNKSNPAGEDPOOLALLOCATE) (IN PNPAGED_LOOKASIDE_LIST Lookaside)
 
typedef VOID(* PFNKSPAGEDPOOLFREE) (IN PPAGED_LOOKASIDE_LIST Lookaside, IN PVOID Entry)
 
typedef VOID(* PFNKSNPAGEDPOOLFREE) (IN PNPAGED_LOOKASIDE_LIST Lookaside, IN PVOID Entry)
 
typedef VOID(NTAPIPFNKSNPAGEDPOOLDELETE) (IN PNPAGED_LOOKASIDE_LIST Lookaside)
 
typedef VOID(NTAPIPFNKSPAGEDPOOLDELETE) (IN PPAGED_LOOKASIDE_LIST Lookaside)
 
typedef struct ALLOCATORPALLOCATOR
 

Enumerations

enum  ALLOCATOR_TYPE { ALLOCATOR_NPAGED_LOOKASIDE , ALLOCATOR_PAGED_LOOKASIDE , ALLOCATOR_CUSTOM }
 
enum  ALLOC_REQUEST { ALLOCATOR_DEVICE_CONTROL , ALLOCATOR_DEVICE_CLOSE , ALLOCATOR_ALLOCATE , ALLOCATOR_FREE }
 

Functions

NTSTATUS NTAPI IKsAllocator_Allocate (IN PFILE_OBJECT FileObject, PVOID *Frame)
 
VOID NTAPI IKsAllocator_FreeFrame (IN PFILE_OBJECT FileObject, PVOID Frame)
 
NTSTATUS NTAPI IKsAllocator_fnQueryInterface (IKsAllocator *iface, IN REFIID refiid, OUT PVOID *Output)
 
ULONG NTAPI IKsAllocator_fnAddRef (IKsAllocator *iface)
 
ULONG NTAPI IKsAllocator_fnRelease (IKsAllocator *iface)
 
NTSTATUS NTAPI IKsAllocator_fnDeviceIoControl (IKsAllocator *iface, IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI IKsAllocator_fnClose (IKsAllocator *iface)
 
NTSTATUS NTAPI IKsAllocator_fnAllocateFrame (IKsAllocator *iface, IN PVOID *OutFrame)
 
VOID NTAPI IKsAllocator_fnFreeFrame (IKsAllocator *iface, IN PVOID Frame)
 
KSDDKAPI NTSTATUS NTAPI KsCreateAllocator (IN HANDLE ConnectionHandle, IN PKSALLOCATOR_FRAMING AllocatorFraming, OUT PHANDLE AllocatorHandle)
 
KSDDKAPI NTSTATUS NTAPI KsCreateDefaultAllocator (IN PIRP Irp)
 
KSDDKAPI NTSTATUS NTAPI KsValidateAllocatorCreateRequest (IN PIRP Irp, OUT PKSALLOCATOR_FRAMING *OutAllocatorFraming)
 
NTSTATUS IKsAllocator_DispatchRequest (IN PDEVICE_OBJECT DeviceObject, IN PFILE_OBJECT FileObject, IN PIRP Irp, IN PVOID Frame, IN ALLOC_REQUEST Request)
 
NTSTATUS NTAPI IKsAllocator_DispatchDeviceIoControl (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI IKsAllocator_DispatchClose (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
KSDDKAPI NTSTATUS NTAPI KsCreateDefaultAllocatorEx (IN PIRP Irp, IN PVOID InitializeContext OPTIONAL, IN PFNKSDEFAULTALLOCATE DefaultAllocate OPTIONAL, IN PFNKSDEFAULTFREE DefaultFree OPTIONAL, IN PFNKSINITIALIZEALLOCATOR InitializeAllocator OPTIONAL, IN PFNKSDELETEALLOCATOR DeleteAllocator OPTIONAL)
 
KSDDKAPI NTSTATUS NTAPI KsValidateAllocatorFramingEx (IN PKSALLOCATOR_FRAMING_EX Framing, IN ULONG BufferSize, IN const KSALLOCATOR_FRAMING_EX *PinFraming)
 

Variables

const GUID IID_IKsAllocator = {0x642F5D00L, 0x4791, 0x11D0, {0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00}}
 
const GUID KSPROPSETID_StreamAllocator = {0x0cf6e4342, 0xec87, 0x11cf, {0xa1, 0x30, 0x00, 0x20, 0xaf, 0xd1, 0x56, 0xe4}}
 
static IKsAllocatorVtbl vt_IKsAllocator
 
static KSDISPATCH_TABLE DispatchTable
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 11 of file allocators.c.

Typedef Documentation

◆ PALLOCATOR

◆ PFNKSNPAGEDPOOLALLOCATE

typedef PVOID(* PFNKSNPAGEDPOOLALLOCATE) (IN PNPAGED_LOOKASIDE_LIST Lookaside)

Definition at line 31 of file allocators.c.

◆ PFNKSNPAGEDPOOLDELETE

typedef VOID(NTAPI * PFNKSNPAGEDPOOLDELETE) (IN PNPAGED_LOOKASIDE_LIST Lookaside)

Definition at line 36 of file allocators.c.

◆ PFNKSNPAGEDPOOLFREE

typedef VOID(* PFNKSNPAGEDPOOLFREE) (IN PNPAGED_LOOKASIDE_LIST Lookaside, IN PVOID Entry)

Definition at line 34 of file allocators.c.

◆ PFNKSPAGEDPOOLALLOCATE

typedef PVOID(* PFNKSPAGEDPOOLALLOCATE) (IN PPAGED_LOOKASIDE_LIST Lookaside)

Definition at line 30 of file allocators.c.

◆ PFNKSPAGEDPOOLDELETE

typedef VOID(NTAPI * PFNKSPAGEDPOOLDELETE) (IN PPAGED_LOOKASIDE_LIST Lookaside)

Definition at line 37 of file allocators.c.

◆ PFNKSPAGEDPOOLFREE

typedef VOID(* PFNKSPAGEDPOOLFREE) (IN PPAGED_LOOKASIDE_LIST Lookaside, IN PVOID Entry)

Definition at line 33 of file allocators.c.

Enumeration Type Documentation

◆ ALLOC_REQUEST

Enumerator
ALLOCATOR_DEVICE_CONTROL 
ALLOCATOR_DEVICE_CLOSE 
ALLOCATOR_ALLOCATE 
ALLOCATOR_FREE 

Definition at line 21 of file allocators.c.

22{
27
ALLOC_REQUEST
Definition: allocators.c:22
@ ALLOCATOR_ALLOCATE
Definition: allocators.c:25
@ ALLOCATOR_FREE
Definition: allocators.c:26
@ ALLOCATOR_DEVICE_CONTROL
Definition: allocators.c:23
@ ALLOCATOR_DEVICE_CLOSE
Definition: allocators.c:24

◆ ALLOCATOR_TYPE

Enumerator
ALLOCATOR_NPAGED_LOOKASIDE 
ALLOCATOR_PAGED_LOOKASIDE 
ALLOCATOR_CUSTOM 

Definition at line 14 of file allocators.c.

15{
ALLOCATOR_TYPE
Definition: allocators.c:15
@ ALLOCATOR_CUSTOM
Definition: allocators.c:18
@ ALLOCATOR_PAGED_LOOKASIDE
Definition: allocators.c:17
@ ALLOCATOR_NPAGED_LOOKASIDE
Definition: allocators.c:16

Function Documentation

◆ IKsAllocator_Allocate()

NTSTATUS NTAPI IKsAllocator_Allocate ( IN PFILE_OBJECT  FileObject,
PVOID Frame 
)

Definition at line 535 of file allocators.c.

538{
540
541 /* dispatch request */
543
544 return Status;
545}
NTSTATUS IKsAllocator_DispatchRequest(IN PDEVICE_OBJECT DeviceObject, IN PFILE_OBJECT FileObject, IN PIRP Irp, IN PVOID Frame, IN ALLOC_REQUEST Request)
Definition: allocators.c:435
LONG NTSTATUS
Definition: precomp.h:26
#define NULL
Definition: types.h:112
Status
Definition: gdiplustypes.h:25
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:550

Referenced by IKsAllocator_fnDeviceIoControl().

◆ IKsAllocator_DispatchClose()

NTSTATUS NTAPI IKsAllocator_DispatchClose ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 513 of file allocators.c.

516{
517 PIO_STACK_LOCATION IoStack;
519
520 /* get current irp stack */
522
523 /* dispatch request */
525
526 /* complete request */
527 Irp->IoStatus.Status = Status;
529
530 return Status;
531}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
_In_ PIRP Irp
Definition: csq.h:116
NTSTATUS NTAPI CompleteRequest(IN PIRP Irp, IN NTSTATUS Status, IN ULONG_PTR Information)
Definition: dispatch.c:19
PFILE_OBJECT FileObject
Definition: iotypes.h:3169
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define IO_NO_INCREMENT
Definition: iotypes.h:598

◆ IKsAllocator_DispatchDeviceIoControl()

NTSTATUS NTAPI IKsAllocator_DispatchDeviceIoControl ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 491 of file allocators.c.

494{
495 PIO_STACK_LOCATION IoStack;
497
498 /* get current irp stack */
500
501 /* dispatch request */
503
504 /* complete request */
505 Irp->IoStatus.Status = Status;
507
508 return Status;
509}

◆ IKsAllocator_DispatchRequest()

NTSTATUS IKsAllocator_DispatchRequest ( IN PDEVICE_OBJECT  DeviceObject,
IN PFILE_OBJECT  FileObject,
IN PIRP  Irp,
IN PVOID  Frame,
IN ALLOC_REQUEST  Request 
)

Definition at line 435 of file allocators.c.

441{
444 IKsAllocator * Allocator;
445
446 /* sanity check */
448
449 /* get object header */
450 Header = (PKSIOBJECT_HEADER)FileObject->FsContext2;
451
452 /* get real allocator */
453 Status = Header->Unknown->lpVtbl->QueryInterface(Header->Unknown, &IID_IKsAllocator, (PVOID*)&Allocator);
454
455 if (!NT_SUCCESS(Status))
456 {
457 /* misbehaving object */
458 return STATUS_UNSUCCESSFUL;
459 }
460
462 {
463 /* dispatch request allocator */
464 Status = Allocator->lpVtbl->DispatchDeviceIoControl(Allocator, DeviceObject, Irp);
465 }
467 {
468 /* delete allocator */
469 Status = Allocator->lpVtbl->Close(Allocator);
470 }
471 else if (Request == ALLOCATOR_ALLOCATE)
472 {
473 /* allocate frame */
474 Status = Allocator->lpVtbl->AllocateFrame(Allocator, (PVOID*)Frame);
475
476 }else if (Request == ALLOCATOR_FREE)
477 {
478 /* allocate frame */
479 Allocator->lpVtbl->FreeFrame(Allocator, Frame);
481 }
482
483 /* release interface */
484 Allocator->lpVtbl->Release(Allocator);
485
486 return Status;
487}
const GUID IID_IKsAllocator
Definition: allocators.c:79
Definition: Header.h:9
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
struct KSIOBJECT_HEADER * PKSIOBJECT_HEADER
#define ASSERT(a)
Definition: mode.c:44
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
_In_ WDFREQUEST Request
Definition: wdfdevice.h:547

Referenced by IKsAllocator_Allocate(), IKsAllocator_DispatchClose(), IKsAllocator_DispatchDeviceIoControl(), and IKsAllocator_FreeFrame().

◆ IKsAllocator_fnAddRef()

ULONG NTAPI IKsAllocator_fnAddRef ( IKsAllocator *  iface)

Definition at line 117 of file allocators.c.

119{
121
122 return InterlockedIncrement(&This->ref);
123}
struct ALLOCATOR * PALLOCATOR
#define InterlockedIncrement
Definition: armddk.h:53
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260

◆ IKsAllocator_fnAllocateFrame()

NTSTATUS NTAPI IKsAllocator_fnAllocateFrame ( IKsAllocator *  iface,
IN PVOID OutFrame 
)

Definition at line 294 of file allocators.c.

297{
298 PVOID Frame = NULL;
300
301 /* FIXME locks */
302
303 /* now allocate frame */
304 if (This->Type == ALLOCATOR_CUSTOM)
305 {
306 Frame = This->Allocate.DefaultAllocate(This->u.CustomList);
307 }
308 else if (This->Type == ALLOCATOR_NPAGED_LOOKASIDE)
309 {
310 Frame = This->Allocate.NPagedPool(&This->u.NPagedList);
311 }
312 else if (This->Type == ALLOCATOR_PAGED_LOOKASIDE)
313 {
314 Frame = This->Allocate.PagedPool(&This->u.PagedList);
315 }
316
317 if (Frame)
318 {
319 *OutFrame = Frame;
320 InterlockedIncrement((PLONG)&This->Status.AllocatedFrames);
321 return STATUS_SUCCESS;
322 }
323
324 return STATUS_UNSUCCESSFUL;
325}
int32_t * PLONG
Definition: typedefs.h:58

◆ IKsAllocator_fnClose()

NTSTATUS NTAPI IKsAllocator_fnClose ( IKsAllocator *  iface)

Definition at line 265 of file allocators.c.

267{
269
270 /* FIXME locks */
271
272 /* now close allocator */
273 if (This->Type == ALLOCATOR_CUSTOM)
274 {
275 This->Delete.DefaultDelete(This->u.CustomList);
276 }
277 else if (This->Type == ALLOCATOR_NPAGED_LOOKASIDE)
278 {
279 This->Delete.NPagedPool(&This->u.NPagedList);
280 }
281 else if (This->Type == ALLOCATOR_PAGED_LOOKASIDE)
282 {
283 This->Delete.PagedPool(&This->u.PagedList);
284 }
285
286 /* free object header */
287 KsFreeObjectHeader(&This->Header);
288
289 return STATUS_SUCCESS;
290}
KSDDKAPI VOID NTAPI KsFreeObjectHeader(IN PVOID Header)
Definition: api.c:720

◆ IKsAllocator_fnDeviceIoControl()

NTSTATUS NTAPI IKsAllocator_fnDeviceIoControl ( IKsAllocator *  iface,
IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 145 of file allocators.c.

149{
151 PIO_STACK_LOCATION IoStack;
152 PKSSTREAMALLOCATOR_FUNCTIONTABLE FunctionTable;
155
156 /* FIXME locks */
157
158 /* get current irp stack */
160
161 if (IoStack->Parameters.DeviceIoControl.IoControlCode != IOCTL_KS_PROPERTY)
162 {
163 /* only KSPROPERTY requests are supported */
165
166 /* complete and forget irps */
167 Irp->IoStatus.Status = STATUS_NOT_IMPLEMENTED;
169
171 }
172
173 if (IoStack->Parameters.DeviceIoControl.InputBufferLength < sizeof(KSPROPERTY))
174 {
175 /* invalid request */
176 Irp->IoStatus.Status = STATUS_INVALID_DEVICE_REQUEST;
178
180 }
181
182 /* check the request */
183 Property = (PKSPROPERTY)IoStack->Parameters.DeviceIoControl.Type3InputBuffer;
184
186 {
188 {
189 if (IoStack->Parameters.DeviceIoControl.OutputBufferLength < sizeof(KSSTREAMALLOCATOR_FUNCTIONTABLE))
190 {
191 /* buffer too small */
192 Irp->IoStatus.Status = STATUS_BUFFER_TOO_SMALL;
193 Irp->IoStatus.Information = sizeof(KSSTREAMALLOCATOR_FUNCTIONTABLE);
194 /* complete and forget irp */
197 }
198 if (!(Property->Flags & KSPROPERTY_TYPE_GET))
199 {
200 /* only support retrieving the property */
201 Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
202 /* complete and forget irp */
204 return STATUS_UNSUCCESSFUL;
205 }
206
207 /* get output buffer */
208 FunctionTable = (PKSSTREAMALLOCATOR_FUNCTIONTABLE)Irp->UserBuffer;
209
210 FunctionTable->AllocateFrame = IKsAllocator_Allocate;
212
213 /* save result */
214 Irp->IoStatus.Status = STATUS_SUCCESS;
215 Irp->IoStatus.Information = sizeof(KSSTREAMALLOCATOR_FUNCTIONTABLE);
216 /* complete request */
218 return STATUS_SUCCESS;
219 }
221 {
222 if (IoStack->Parameters.DeviceIoControl.OutputBufferLength < sizeof(KSPROPERTY_STREAMALLOCATOR_STATUS))
223 {
224 /* buffer too small */
225 Irp->IoStatus.Status = STATUS_BUFFER_TOO_SMALL;
226 Irp->IoStatus.Information = sizeof(KSPROPERTY_STREAMALLOCATOR_STATUS);
227 /* complete and forget irp */
230 }
231 if (!(Property->Flags & KSPROPERTY_TYPE_GET))
232 {
233 /* only support retrieving the property */
234 Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
235 /* complete and forget irp */
237 return STATUS_UNSUCCESSFUL;
238 }
239
240 /* get output buffer */
241 State = (PKSSTREAMALLOCATOR_STATUS)Irp->UserBuffer;
242
243 /* copy allocator status */
245
246 /* save result */
247 Irp->IoStatus.Status = STATUS_SUCCESS;
248 Irp->IoStatus.Information = sizeof(KSSTREAMALLOCATOR_STATUS);
249
250 /* complete request */
252 return STATUS_SUCCESS;
253 }
254 }
255
256 /* unhandled request */
257 Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
259
261}
VOID NTAPI IKsAllocator_FreeFrame(IN PFILE_OBJECT FileObject, PVOID Frame)
Definition: allocators.c:549
NTSTATUS NTAPI IKsAllocator_Allocate(IN PFILE_OBJECT FileObject, PVOID *Frame)
Definition: allocators.c:535
const GUID KSPROPSETID_StreamAllocator
Definition: allocators.c:80
#define UNIMPLEMENTED
Definition: ntoskrnl.c:15
#define STATUS_NOT_SUPPORTED
Definition: d3dkmdt.h:48
#define STATUS_NOT_IMPLEMENTED
Definition: d3dkmdt.h:42
struct KSIDENTIFIER * PKSPROPERTY
#define KSPROPERTY_TYPE_GET
Definition: dmksctrl.h:42
@ KSPROPERTY_STREAMALLOCATOR_FUNCTIONTABLE
Definition: ks.h:803
@ KSPROPERTY_STREAMALLOCATOR_STATUS
Definition: ks.h:804
#define IOCTL_KS_PROPERTY
Definition: ks.h:127
struct KSSTREAMALLOCATOR_STATUS * PKSSTREAMALLOCATOR_STATUS
if(dx< 0)
Definition: linetemp.h:194
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
struct _IO_STACK_LOCATION::@1575::@1576 DeviceIoControl
union _IO_STACK_LOCATION::@1575 Parameters
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define IsEqualGUIDAligned(guid1, guid2)
Definition: wdm.template.h:235
static WLX_DISPATCH_VERSION_1_4 FunctionTable
Definition: wlx.c:722

◆ IKsAllocator_fnFreeFrame()

VOID NTAPI IKsAllocator_fnFreeFrame ( IKsAllocator *  iface,
IN PVOID  Frame 
)

Definition at line 329 of file allocators.c.

332{
334
335 /* now allocate frame */
336 if (This->Type == ALLOCATOR_CUSTOM)
337 {
338 This->Free.DefaultFree(This->u.CustomList, Frame);
339 }
340 else if (This->Type == ALLOCATOR_NPAGED_LOOKASIDE)
341 {
342 This->Free.NPagedPool(&This->u.NPagedList, Frame);
343 }
344 else if (This->Type == ALLOCATOR_PAGED_LOOKASIDE)
345 {
346 This->Free.PagedPool(&This->u.PagedList, Frame);
347 }
348}

◆ IKsAllocator_fnQueryInterface()

NTSTATUS NTAPI IKsAllocator_fnQueryInterface ( IKsAllocator *  iface,
IN REFIID  refiid,
OUT PVOID Output 
)

Definition at line 98 of file allocators.c.

102{
104
105 if (IsEqualGUIDAligned(refiid, &IID_IUnknown) ||
107 {
108 *Output = &This->lpVtbl;
110 return STATUS_SUCCESS;
111 }
112 return STATUS_UNSUCCESSFUL;
113}
const GUID IID_IUnknown
long __cdecl _InterlockedIncrement(_Interlocked_operand_ long volatile *_Addend)
@ Output
Definition: arc.h:85

◆ IKsAllocator_fnRelease()

ULONG NTAPI IKsAllocator_fnRelease ( IKsAllocator *  iface)

Definition at line 127 of file allocators.c.

129{
131
133
134 if (This->ref == 0)
135 {
136 FreeItem(This);
137 return 0;
138 }
139 /* Return new reference count */
140 return This->ref;
141}
#define InterlockedDecrement
Definition: armddk.h:52
VOID FreeItem(IN PVOID Item)
Definition: misc.c:37

◆ IKsAllocator_FreeFrame()

VOID NTAPI IKsAllocator_FreeFrame ( IN PFILE_OBJECT  FileObject,
PVOID  Frame 
)

Definition at line 549 of file allocators.c.

552{
553 /* dispatch request */
555}

Referenced by IKsAllocator_fnDeviceIoControl().

◆ KsCreateAllocator()

KSDDKAPI NTSTATUS NTAPI KsCreateAllocator ( IN HANDLE  ConnectionHandle,
IN PKSALLOCATOR_FRAMING  AllocatorFraming,
OUT PHANDLE  AllocatorHandle 
)

Definition at line 367 of file allocators.c.

371{
375 sizeof(KSALLOCATOR_FRAMING),
378}
#define GENERIC_READ
Definition: compat.h:135
#define KSSTRING_Allocator
Definition: ks.h:50
_In_ PKSALLOCATOR_FRAMING AllocatorFraming
Definition: ks.h:4518
_In_ PKSPIN_CONNECT _In_ ACCESS_MASK _Out_ PHANDLE ConnectionHandle
Definition: ks.h:4538
_In_ PKSALLOCATOR_FRAMING _Out_ PHANDLE AllocatorHandle
Definition: ks.h:4519
NTSTATUS NTAPI KspCreateObjectType(IN HANDLE ParentHandle, IN LPWSTR ObjectType, PVOID CreateParameters, UINT CreateParametersSize, IN ACCESS_MASK DesiredAccess, OUT PHANDLE NodeHandle)
Definition: topology.c:16

◆ KsCreateDefaultAllocator()

KSDDKAPI NTSTATUS NTAPI KsCreateDefaultAllocator ( IN PIRP  Irp)

Definition at line 384 of file allocators.c.

386{
388}
KSDDKAPI NTSTATUS NTAPI KsCreateDefaultAllocatorEx(IN PIRP Irp, IN PVOID InitializeContext OPTIONAL, IN PFNKSDEFAULTALLOCATE DefaultAllocate OPTIONAL, IN PFNKSDEFAULTFREE DefaultFree OPTIONAL, IN PFNKSINITIALIZEALLOCATOR InitializeAllocator OPTIONAL, IN PFNKSDELETEALLOCATOR DeleteAllocator OPTIONAL)
Definition: allocators.c:576

Referenced by DispatchCreateKMixAllocator().

◆ KsCreateDefaultAllocatorEx()

KSDDKAPI NTSTATUS NTAPI KsCreateDefaultAllocatorEx ( IN PIRP  Irp,
IN PVOID InitializeContext  OPTIONAL,
IN PFNKSDEFAULTALLOCATE DefaultAllocate  OPTIONAL,
IN PFNKSDEFAULTFREE DefaultFree  OPTIONAL,
IN PFNKSINITIALIZEALLOCATOR InitializeAllocator  OPTIONAL,
IN PFNKSDELETEALLOCATOR DeleteAllocator  OPTIONAL 
)

Definition at line 576 of file allocators.c.

583{
586 PALLOCATOR Allocator;
587 PVOID Ctx;
588
589 /* first validate connect request */
591 if (!NT_SUCCESS(Status))
593
594 /* check the valid file alignment */
596 {
599 }
600
601 /* allocate allocator struct */
602 Allocator = AllocateItem(NonPagedPool, sizeof(ALLOCATOR));
603 if (!Allocator)
604 {
607 }
608
609 /* allocate object header */
610
612 if (!NT_SUCCESS(Status))
613 {
615 FreeItem(Allocator);
616 return Status;
617 }
618
619 /* set allocator type in object header */
620 Allocator->lpVtbl = &vt_IKsAllocator;
621 Allocator->Header->Unknown = (PUNKNOWN)&Allocator->lpVtbl;
622 Allocator->ref = 1;
623
624 if (DefaultAllocate)
625 {
626 /* use external allocator */
627 Allocator->Type = ALLOCATOR_CUSTOM;
628 Allocator->Allocate.DefaultAllocate = DefaultAllocate;
629 Allocator->Free.DefaultFree = DefaultFree;
630 Allocator->Delete.DefaultDelete = DeleteAllocator;
631 Ctx = InitializeAllocator(InitializeContext, AllocatorFraming, &Allocator->u.CustomList);
632 /* check for success */
633 if (!Ctx)
634 {
635 KsFreeObjectHeader(Allocator->Header);
636 FreeItem(Allocator);
637 return Status;
638 }
639 }
641 {
642 /* use non-paged pool allocator */
643 Allocator->Type = ALLOCATOR_NPAGED_LOOKASIDE;
644 Allocator->Allocate.NPagedPool = ExAllocateFromNPagedLookasideList;
645 Allocator->Free.NPagedPool = ExFreeToNPagedLookasideList;
648 }
650 {
651 /* use paged pool allocator */
652 Allocator->Allocate.PagedPool = ExAllocateFromPagedLookasideList;
653 Allocator->Free.PagedPool = ExFreeToPagedLookasideList;
655 Allocator->Type = ALLOCATOR_PAGED_LOOKASIDE;
657
658 }
659
660 /* backup allocator framing */
663
664 return Status;
665}
static IKsAllocatorVtbl vt_IKsAllocator
Definition: allocators.c:351
KSDDKAPI NTSTATUS NTAPI KsValidateAllocatorCreateRequest(IN PIRP Irp, OUT PKSALLOCATOR_FRAMING *OutAllocatorFraming)
Definition: allocators.c:396
IUnknown * PUNKNOWN
Definition: com_apitest.h:45
KSDDKAPI NTSTATUS NTAPI KsAllocateObjectHeader(OUT KSOBJECT_HEADER *Header, IN ULONG ItemsCount, IN PKSOBJECT_CREATE_ITEM ItemsList OPTIONAL, IN PIRP Irp, IN KSDISPATCH_TABLE *Table)
Definition: api.c:610
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define NonPagedPool
Definition: env_spec_w32.h:307
#define PagedPool
Definition: env_spec_w32.h:308
PVOID AllocateItem(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
Definition: misc.c:29
VOID NTAPI ExInitializePagedLookasideList(IN PPAGED_LOOKASIDE_LIST Lookaside, IN PALLOCATE_FUNCTION Allocate OPTIONAL, IN PFREE_FUNCTION Free OPTIONAL, IN ULONG Flags, IN SIZE_T Size, IN ULONG Tag, IN USHORT Depth)
Definition: lookas.c:270
VOID NTAPI ExDeletePagedLookasideList(IN PPAGED_LOOKASIDE_LIST Lookaside)
Definition: lookas.c:194
VOID NTAPI ExDeleteNPagedLookasideList(IN PNPAGED_LOOKASIDE_LIST Lookaside)
Definition: lookas.c:170
VOID NTAPI ExInitializeNPagedLookasideList(IN PNPAGED_LOOKASIDE_LIST Lookaside, IN PALLOCATE_FUNCTION Allocate OPTIONAL, IN PFREE_FUNCTION Free OPTIONAL, IN ULONG Flags, IN SIZE_T Size, IN ULONG Tag, IN USHORT Depth)
Definition: lookas.c:218
PFNKSDEFAULTFREE DefaultFree
Definition: allocators.c:64
PFNKSNPAGEDPOOLALLOCATE NPagedPool
Definition: allocators.c:59
KSSTREAMALLOCATOR_STATUS Status
Definition: allocators.c:46
union ALLOCATOR::@980 Free
union ALLOCATOR::@978 u
LONG ref
Definition: allocators.c:42
PVOID CustomList
Definition: allocators.c:52
PFNKSDELETEALLOCATOR DefaultDelete
Definition: allocators.c:71
PAGED_LOOKASIDE_LIST PagedList
Definition: allocators.c:51
PFNKSDEFAULTALLOCATE DefaultAllocate
Definition: allocators.c:57
PFNKSPAGEDPOOLALLOCATE PagedPool
Definition: allocators.c:58
union ALLOCATOR::@979 Allocate
ALLOCATOR_TYPE Type
Definition: allocators.c:44
PKSIOBJECT_HEADER Header
Definition: allocators.c:43
union ALLOCATOR::@981 Delete
IKsAllocatorVtbl * lpVtbl
Definition: allocators.c:41
NPAGED_LOOKASIDE_LIST NPagedList
Definition: allocators.c:50
ULONG PoolType
Definition: ks.h:1668
ULONG FileAlignment
Definition: ks.h:1672
ULONG FrameSize
Definition: ks.h:1671
PUNKNOWN Unknown
Definition: kstypes.h:29
KSALLOCATOR_FRAMING Framing
Definition: ks.h:2724
VOID InitializeContext(IN PCALLBACK16 Context, IN USHORT Segment, IN USHORT Offset)
Definition: callback.c:60
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ PWDFDEVICE_INIT _In_ PWDF_PDO_EVENT_CALLBACKS DispatchTable
Definition: wdfpdo.h:248

Referenced by KsCreateDefaultAllocator().

◆ KsValidateAllocatorCreateRequest()

KSDDKAPI NTSTATUS NTAPI KsValidateAllocatorCreateRequest ( IN PIRP  Irp,
OUT PKSALLOCATOR_FRAMING OutAllocatorFraming 
)

Definition at line 396 of file allocators.c.

399{
401 ULONG Size;
403 ULONG SupportedFlags;
404
405 /* set minimum request size */
406 Size = sizeof(KSALLOCATOR_FRAMING);
407
410 &Size,
412
413 if (!NT_SUCCESS(Status))
414 return Status;
415
416 /* allowed supported flags */
420
421
422 if (!AllocatorFraming->FrameSize || (AllocatorFraming->OptionsFlags & (~SupportedFlags)))
423 {
426 }
427
428 /* store result */
429 *OutAllocatorFraming = AllocatorFraming;
430
431 return Status;
432}
#define KSALLOCATOR_REQUIREMENTF_INPLACE_MODIFIER
Definition: ks.h:1684
#define KSALLOCATOR_REQUIREMENTF_SYSTEM_MEMORY
Definition: ks.h:1685
#define KSALLOCATOR_OPTIONF_SYSTEM_MEMORY
Definition: ks.h:1691
#define KSALLOCATOR_OPTIONF_COMPATIBLE
Definition: ks.h:1690
#define KSALLOCATOR_REQUIREMENTF_FRAME_INTEGRITY
Definition: ks.h:1686
#define KSALLOCATOR_REQUIREMENTF_MUST_ALLOCATE
Definition: ks.h:1687
NTSTATUS KspCopyCreateRequest(IN PIRP Irp, IN LPWSTR ObjectClass, IN OUT PULONG Size, OUT PVOID *Result)
Definition: misc.c:44
ULONG OptionsFlags
Definition: ks.h:1662
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533

Referenced by KsCreateDefaultAllocatorEx().

◆ KsValidateAllocatorFramingEx()

KSDDKAPI NTSTATUS NTAPI KsValidateAllocatorFramingEx ( IN PKSALLOCATOR_FRAMING_EX  Framing,
IN ULONG  BufferSize,
IN const KSALLOCATOR_FRAMING_EX PinFraming 
)

Definition at line 671 of file allocators.c.

675{
678
679 /* verify framing */
680 if ((Framing->FramingItem[0].Flags & KSALLOCATOR_FLAG_PARTIAL_READ_SUPPORT) &&
681 Framing->OutputCompression.RatioNumerator != MAXULONG &&
682 Framing->OutputCompression.RatioDenominator != 0 &&
683 Framing->OutputCompression.RatioDenominator < Framing->OutputCompression.RatioNumerator)
684 {
685 /* framing request is ok */
686 return STATUS_SUCCESS;
687 }
688
690}
#define KSALLOCATOR_FLAG_PARTIAL_READ_SUPPORT
Definition: ks.h:1694
#define MAXULONG
Definition: typedefs.h:251
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254

Variable Documentation

◆ DispatchTable

KSDISPATCH_TABLE DispatchTable
static
Initial value:
=
{
}
NTSTATUS NTAPI IKsAllocator_DispatchClose(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: allocators.c:513
NTSTATUS NTAPI IKsAllocator_DispatchDeviceIoControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: allocators.c:491
KSDDKAPI NTSTATUS NTAPI KsDispatchInvalidDeviceRequest(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1189
KSDDKAPI BOOLEAN NTAPI KsDispatchFastReadFailure(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN BOOLEAN Wait, IN ULONG LockKey, OUT PVOID Buffer, OUT PIO_STATUS_BLOCK IoStatus, IN PDEVICE_OBJECT DeviceObject)
Definition: irp.c:1271
KSDDKAPI NTSTATUS NTAPI KsDispatchSetSecurity(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:67
KSDDKAPI NTSTATUS NTAPI KsDispatchQuerySecurity(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:22
KSDDKAPI BOOLEAN NTAPI KsDispatchFastIoDeviceControlFailure(IN PFILE_OBJECT FileObject, IN BOOLEAN Wait, IN PVOID InputBuffer OPTIONAL, IN ULONG InputBufferLength, OUT PVOID OutputBuffer OPTIONAL, IN ULONG OutputBufferLength, IN ULONG IoControlCode, OUT PIO_STATUS_BLOCK IoStatus, IN PDEVICE_OBJECT DeviceObject)
Definition: irp.c:1251

Definition at line 558 of file allocators.c.

◆ IID_IKsAllocator

const GUID IID_IKsAllocator = {0x642F5D00L, 0x4791, 0x11D0, {0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00}}

Definition at line 79 of file allocators.c.

Referenced by IKsAllocator_DispatchRequest(), and IKsAllocator_fnQueryInterface().

◆ KSPROPSETID_StreamAllocator

const GUID KSPROPSETID_StreamAllocator = {0x0cf6e4342, 0xec87, 0x11cf, {0xa1, 0x30, 0x00, 0x20, 0xaf, 0xd1, 0x56, 0xe4}}

Definition at line 80 of file allocators.c.

Referenced by IKsAllocator_fnDeviceIoControl().

◆ vt_IKsAllocator

IKsAllocatorVtbl vt_IKsAllocator
static
Initial value:
=
{
}
NTSTATUS NTAPI IKsAllocator_fnAllocateFrame(IKsAllocator *iface, IN PVOID *OutFrame)
Definition: allocators.c:294
NTSTATUS NTAPI IKsAllocator_fnQueryInterface(IKsAllocator *iface, IN REFIID refiid, OUT PVOID *Output)
Definition: allocators.c:98
VOID NTAPI IKsAllocator_fnFreeFrame(IKsAllocator *iface, IN PVOID Frame)
Definition: allocators.c:329
ULONG NTAPI IKsAllocator_fnAddRef(IKsAllocator *iface)
Definition: allocators.c:117
NTSTATUS NTAPI IKsAllocator_fnDeviceIoControl(IKsAllocator *iface, IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: allocators.c:145
NTSTATUS NTAPI IKsAllocator_fnClose(IKsAllocator *iface)
Definition: allocators.c:265
ULONG NTAPI IKsAllocator_fnRelease(IKsAllocator *iface)
Definition: allocators.c:127

Definition at line 351 of file allocators.c.

Referenced by KsCreateDefaultAllocatorEx().