ReactOS  0.4.14-dev-323-g6fe6a88
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.

◆ ALLOCATOR_TYPE

Enumerator
ALLOCATOR_NPAGED_LOOKASIDE 
ALLOCATOR_PAGED_LOOKASIDE 
ALLOCATOR_CUSTOM 

Definition at line 14 of file allocators.c.

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 }
LONG NTSTATUS
Definition: precomp.h:26
smooth NULL
Definition: ftsmooth.c:416
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
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
Status
Definition: gdiplustypes.h:24

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 }
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS NTAPI CompleteRequest(IN PIRP Irp, IN NTSTATUS Status, IN ULONG_PTR Information)
Definition: dispatch.c:19
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
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
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
#define IO_NO_INCREMENT
Definition: iotypes.h:566

◆ 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 }
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS NTAPI CompleteRequest(IN PIRP Irp, IN NTSTATUS Status, IN ULONG_PTR Information)
Definition: dispatch.c:19
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
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
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
#define IO_NO_INCREMENT
Definition: iotypes.h:566

◆ 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  }
466  else if (Request == ALLOCATOR_DEVICE_CLOSE)
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 }
_In_ PIRP Irp
Definition: csq.h:116
struct KSIOBJECT_HEADER * PKSIOBJECT_HEADER
LONG NTSTATUS
Definition: precomp.h:26
_In_ NDIS_HANDLE _In_ PNDIS_REQUEST Request
Definition: ndis.h:5173
Definition: Header.h:8
const GUID IID_IKsAllocator
Definition: allocators.c:79
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
nsrefcnt Release()
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
return STATUS_SUCCESS
Definition: btrfs.c:2938

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
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define InterlockedIncrement
Definition: armddk.h:53

◆ 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 }
struct ALLOCATOR * PALLOCATOR
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define InterlockedIncrement
Definition: armddk.h:53
return STATUS_SUCCESS
Definition: btrfs.c:2938
signed int * PLONG
Definition: retypes.h:5

◆ 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 }
struct ALLOCATOR * PALLOCATOR
KSDDKAPI VOID NTAPI KsFreeObjectHeader(IN PVOID Header)
Definition: api.c:720
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
return STATUS_SUCCESS
Definition: btrfs.c:2938

◆ 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 
170  return STATUS_NOT_IMPLEMENTED;
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 */
244  RtlMoveMemory(State, &This->Status, sizeof(KSSTREAMALLOCATOR_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 
260  return STATUS_NOT_SUPPORTED;
261 }
#define IOCTL_KS_PROPERTY
Definition: ks.h:127
NTSTATUS NTAPI IKsAllocator_Allocate(IN PFILE_OBJECT FileObject, PVOID *Frame)
Definition: allocators.c:535
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define KSPROPERTY_TYPE_GET
Definition: dmksctrl.h:42
struct ALLOCATOR * PALLOCATOR
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
#define IsEqualGUIDAligned(guid1, guid2)
Definition: wdm.template.h:233
struct KSSTREAMALLOCATOR_STATUS * PKSSTREAMALLOCATOR_STATUS
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
if(!(yy_init))
Definition: macro.lex.yy.c:714
NTSTATUS NTAPI CompleteRequest(IN PIRP Irp, IN NTSTATUS Status, IN ULONG_PTR Information)
Definition: dispatch.c:19
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
VOID NTAPI IKsAllocator_FreeFrame(IN PFILE_OBJECT FileObject, PVOID Frame)
Definition: allocators.c:549
_In_ DWORD Property
Definition: setupapi.h:1545
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
enum State_ State
Definition: pofuncs.h:54
const GUID KSPROPSETID_StreamAllocator
Definition: allocators.c:80
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
#define IO_NO_INCREMENT
Definition: iotypes.h:566
#define UNIMPLEMENTED
Definition: debug.h:114
static WLX_DISPATCH_VERSION_1_4 FunctionTable
Definition: wlx.c:736
struct KSIDENTIFIER * PKSPROPERTY
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:2938

◆ 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 }
struct ALLOCATOR * PALLOCATOR
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560

◆ 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 }
struct ALLOCATOR * PALLOCATOR
#define IsEqualGUIDAligned(guid1, guid2)
Definition: wdm.template.h:233
long __cdecl _InterlockedIncrement(_Interlocked_operand_ long volatile *_Addend)
const GUID IID_IKsAllocator
Definition: allocators.c:79
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
const GUID IID_IUnknown
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
Definition: arc.h:85
return STATUS_SUCCESS
Definition: btrfs.c:2938

◆ IKsAllocator_fnRelease()

ULONG NTAPI IKsAllocator_fnRelease ( IKsAllocator *  iface)

Definition at line 127 of file allocators.c.

129 {
131 
132  InterlockedDecrement(&This->ref);
133 
134  if (This->ref == 0)
135  {
136  FreeItem(This);
137  return 0;
138  }
139  /* Return new reference count */
140  return This->ref;
141 }
struct ALLOCATOR * PALLOCATOR
VOID FreeItem(IN PVOID Item)
Definition: misc.c:43
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define InterlockedDecrement
Definition: armddk.h:52

◆ 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 }
smooth NULL
Definition: ftsmooth.c:416
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
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

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),
376  GENERIC_READ,
378 }
#define KSSTRING_Allocator
Definition: ks.h:50
NTSTATUS NTAPI KspCreateObjectType(IN HANDLE ParentHandle, IN LPWSTR ObjectType, PVOID CreateParameters, UINT CreateParametersSize, IN ACCESS_MASK DesiredAccess, OUT PHANDLE NodeHandle)
Definition: topology.c:16
_In_ PKSALLOCATOR_FRAMING AllocatorFraming
Definition: ks.h:4518
#define GENERIC_READ
Definition: compat.h:124
_In_ PKSALLOCATOR_FRAMING _Out_ PHANDLE AllocatorHandle
Definition: ks.h:4518
_In_ PKSPIN_CONNECT _In_ ACCESS_MASK _Out_ PHANDLE ConnectionHandle
Definition: ks.h:4536

◆ KsCreateDefaultAllocator()

KSDDKAPI NTSTATUS NTAPI KsCreateDefaultAllocator ( IN PIRP  Irp)

Definition at line 384 of file allocators.c.

386 {
388 }
_In_ PIRP Irp
Definition: csq.h:116
smooth NULL
Definition: ftsmooth.c:416
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  }
649  else if (AllocatorFraming->PoolType == PagedPool)
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 }
KSDDKAPI NTSTATUS NTAPI KsValidateAllocatorCreateRequest(IN PIRP Irp, OUT PKSALLOCATOR_FRAMING *OutAllocatorFraming)
Definition: allocators.c:396
KSALLOCATOR_FRAMING Framing
Definition: ks.h:2724
PUNKNOWN Unknown
Definition: kstypes.h: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:274
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
IUnknown * PUNKNOWN
Definition: com_apitest.h:45
VOID InitializeContext(IN PCALLBACK16 Context, IN USHORT Segment, IN USHORT Offset)
Definition: callback.c:60
PVOID AllocateItem(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
Definition: misc.c:30
union ALLOCATOR::@978 Delete
LONG NTSTATUS
Definition: precomp.h:26
union ALLOCATOR::@976 Allocate
_In_ PKSALLOCATOR_FRAMING AllocatorFraming
Definition: ks.h:4518
NPAGED_LOOKASIDE_LIST NPagedList
Definition: allocators.c:50
KSDDKAPI VOID NTAPI KsFreeObjectHeader(IN PVOID Header)
Definition: api.c:720
static KSDISPATCH_TABLE DispatchTable
Definition: allocators.c:558
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:263
VOID FreeItem(IN PVOID Item)
Definition: misc.c:43
PAGED_LOOKASIDE_LIST PagedList
Definition: allocators.c:51
PFNKSDEFAULTFREE DefaultFree
Definition: allocators.c:64
smooth NULL
Definition: ftsmooth.c:416
VOID NTAPI ExDeletePagedLookasideList(IN PPAGED_LOOKASIDE_LIST Lookaside)
Definition: lookas.c:198
LONG ref
Definition: allocators.c:42
IKsAllocatorVtbl * lpVtbl
Definition: allocators.c:41
static IKsAllocatorVtbl vt_IKsAllocator
Definition: allocators.c:351
union ALLOCATOR::@975 u
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:222
if(!(yy_init))
Definition: macro.lex.yy.c:714
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
PFNKSDEFAULTALLOCATE DefaultAllocate
Definition: allocators.c:57
PKSIOBJECT_HEADER Header
Definition: allocators.c:43
ALLOCATOR_TYPE Type
Definition: allocators.c:44
#define PAGE_SIZE
Definition: env_spec_w32.h:49
PFNKSNPAGEDPOOLALLOCATE NPagedPool
Definition: allocators.c:59
Status
Definition: gdiplustypes.h:24
ULONG PoolType
Definition: ks.h:1668
PFNKSPAGEDPOOLALLOCATE PagedPool
Definition: allocators.c:58
KSSTREAMALLOCATOR_STATUS Status
Definition: allocators.c:46
union ALLOCATOR::@977 Free
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
PVOID CustomList
Definition: allocators.c:52
PFNKSDELETEALLOCATOR DefaultDelete
Definition: allocators.c:71
ULONG FileAlignment
Definition: ks.h:1672
VOID NTAPI ExDeleteNPagedLookasideList(IN PNPAGED_LOOKASIDE_LIST Lookaside)
Definition: lookas.c:174
ULONG FrameSize
Definition: ks.h:1671

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 KSSTRING_Allocator
Definition: ks.h:50
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
_In_ PKSALLOCATOR_FRAMING AllocatorFraming
Definition: ks.h:4518
NTSTATUS KspCopyCreateRequest(IN PIRP Irp, IN LPWSTR ObjectClass, IN OUT PULONG Size, OUT PVOID *Result)
Definition: misc.c:101
VOID FreeItem(IN PVOID Item)
Definition: misc.c:43
#define KSALLOCATOR_OPTIONF_SYSTEM_MEMORY
Definition: ks.h:1691
#define KSALLOCATOR_REQUIREMENTF_SYSTEM_MEMORY
Definition: ks.h:1685
#define KSALLOCATOR_OPTIONF_COMPATIBLE
Definition: ks.h:1690
#define KSALLOCATOR_REQUIREMENTF_INPLACE_MODIFIER
Definition: ks.h:1684
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define KSALLOCATOR_REQUIREMENTF_MUST_ALLOCATE
Definition: ks.h:1687
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
Status
Definition: gdiplustypes.h:24
unsigned int ULONG
Definition: retypes.h:1
#define KSALLOCATOR_REQUIREMENTF_FRAME_INTEGRITY
Definition: ks.h:1686
ULONG FrameSize
Definition: ks.h:1671
ULONG OptionsFlags
Definition: ks.h:1662

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 {
676  if (BufferSize < sizeof(KSALLOCATOR_FRAMING_EX))
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 STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define KSALLOCATOR_FLAG_PARTIAL_READ_SUPPORT
Definition: ks.h:1694
#define BufferSize
Definition: classpnp.h:419
#define MAXULONG
Definition: typedefs.h:250
return STATUS_SUCCESS
Definition: btrfs.c:2938

Variable Documentation

◆ DispatchTable

KSDISPATCH_TABLE DispatchTable
static
Initial value:
=
{
}
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:1218
NTSTATUS NTAPI IKsAllocator_DispatchDeviceIoControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: allocators.c:491
NTSTATUS NTAPI IKsAllocator_DispatchClose(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: allocators.c:513
KSDDKAPI NTSTATUS NTAPI KsDispatchInvalidDeviceRequest(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1156
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:1238

Definition at line 558 of file allocators.c.

Referenced by KsCreateDefaultAllocatorEx().

◆ 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_fnQueryInterface(IKsAllocator *iface, IN REFIID refiid, OUT PVOID *Output)
Definition: allocators.c:98
NTSTATUS NTAPI IKsAllocator_fnDeviceIoControl(IKsAllocator *iface, IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: allocators.c:145
NTSTATUS NTAPI IKsAllocator_fnAllocateFrame(IKsAllocator *iface, IN PVOID *OutFrame)
Definition: allocators.c:294
ULONG NTAPI IKsAllocator_fnAddRef(IKsAllocator *iface)
Definition: allocators.c:117
ULONG NTAPI IKsAllocator_fnRelease(IKsAllocator *iface)
Definition: allocators.c:127
NTSTATUS NTAPI IKsAllocator_fnClose(IKsAllocator *iface)
Definition: allocators.c:265
VOID NTAPI IKsAllocator_fnFreeFrame(IKsAllocator *iface, IN PVOID Frame)
Definition: allocators.c:329

Definition at line 351 of file allocators.c.

Referenced by KsCreateDefaultAllocatorEx().