ReactOS  0.4.14-dev-49-gfb4591c
event.c File Reference
#include "precomp.h"
#include <debug.h>
Include dependency graph for event.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

BOOLEAN KspSynchronizedEventRoutine (IN KSEVENTS_LOCKTYPE EventsFlags, IN PVOID EventsLock, IN PKSEVENT_SYNCHRONIZED_ROUTINE SynchronizedRoutine, IN PKSEVENT_CTX Ctx)
 
BOOLEAN NTAPI SyncAddEvent (PKSEVENT_CTX Context)
 
NTSTATUS KspEnableEvent (IN PIRP Irp, IN ULONG EventSetsCount, IN const KSEVENT_SET *EventSet, IN OUT PLIST_ENTRY EventsList OPTIONAL, IN KSEVENTS_LOCKTYPE EventsFlags OPTIONAL, IN PVOID EventsLock OPTIONAL, IN PFNKSALLOCATOR Allocator OPTIONAL, IN ULONG EventItemSize OPTIONAL)
 
KSDDKAPI NTSTATUS NTAPI KsEnableEvent (IN PIRP Irp, IN ULONG EventSetsCount, IN KSEVENT_SET *EventSet, IN OUT PLIST_ENTRY EventsList OPTIONAL, IN KSEVENTS_LOCKTYPE EventsFlags OPTIONAL, IN PVOID EventsLock OPTIONAL)
 
 _IRQL_requires_max_ (PASSIVE_LEVEL)
 
BOOLEAN NTAPI KspDisableEvent (IN PKSEVENT_CTX Ctx)
 
KSDDKAPI NTSTATUS NTAPI KsDisableEvent (IN PIRP Irp, IN OUT PLIST_ENTRY EventsList, IN KSEVENTS_LOCKTYPE EventsFlags, IN PVOID EventsLock)
 
KSDDKAPI VOID NTAPI KsDiscardEvent (IN PKSEVENT_ENTRY EventEntry)
 
BOOLEAN NTAPI KspFreeEventList (IN PKSEVENT_CTX Ctx)
 
KSDDKAPI VOID NTAPI KsFreeEventList (IN PFILE_OBJECT FileObject, IN OUT PLIST_ENTRY EventsList, IN KSEVENTS_LOCKTYPE EventsFlags, IN PVOID EventsLock)
 
KSDDKAPI NTSTATUS NTAPI KsGenerateEvent (IN PKSEVENT_ENTRY EntryEvent)
 
KSDDKAPI NTSTATUS NTAPI KsGenerateDataEvent (IN PKSEVENT_ENTRY EventEntry, IN ULONG DataSize, IN PVOID Data)
 
KSDDKAPI VOID NTAPI KsGenerateEventList (IN GUID *Set OPTIONAL, IN ULONG EventId, IN PLIST_ENTRY EventsList, IN KSEVENTS_LOCKTYPE EventsFlags, IN PVOID EventsLock)
 
KSDDKAPI VOID NTAPI KsAddEvent (IN PVOID Object, IN PKSEVENT_ENTRY EventEntry)
 
NTSTATUS NTAPI KsDefaultAddEventHandler (IN PIRP Irp, IN PKSEVENTDATA EventData, IN OUT PKSEVENT_ENTRY EventEntry)
 
KSDDKAPI void NTAPI KsGenerateEvents (IN PVOID Object, IN const GUID *EventSet OPTIONAL, IN ULONG EventId, IN ULONG DataSize, IN PVOID Data OPTIONAL, IN PFNKSGENERATEEVENTCALLBACK CallBack OPTIONAL, IN PVOID CallBackContext OPTIONAL)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 11 of file event.c.

Function Documentation

◆ _IRQL_requires_max_()

_IRQL_requires_max_ ( PASSIVE_LEVEL  )

Definition at line 401 of file event.c.

414 {
415  return KspEnableEvent(Irp, EventSetsCount, EventSet, EventsList, EventsFlags, EventsLock, Allocator, EventItemSize);
416 }
_In_ PIRP Irp
Definition: csq.h:116
NTSTATUS KspEnableEvent(IN PIRP Irp, IN ULONG EventSetsCount, IN const KSEVENT_SET *EventSet, IN OUT PLIST_ENTRY EventsList OPTIONAL, IN KSEVENTS_LOCKTYPE EventsFlags OPTIONAL, IN PVOID EventsLock OPTIONAL, IN PFNKSALLOCATOR Allocator OPTIONAL, IN ULONG EventItemSize OPTIONAL)
Definition: event.c:87

◆ KsAddEvent()

KSDDKAPI VOID NTAPI KsAddEvent ( IN PVOID  Object,
IN PKSEVENT_ENTRY  EventEntry 
)

Definition at line 684 of file event.c.

687 {
689 
690  ExInterlockedInsertTailList(&Header->EventList, &EventEntry->ListEntry, &Header->EventListLock);
691 }
struct KSBASIC_HEADER * PKSBASIC_HEADER
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
uint32_t ULONG_PTR
Definition: typedefs.h:63
Definition: Header.h:8
static IUnknown Object
Definition: main.c:512

◆ KsDefaultAddEventHandler()

NTSTATUS NTAPI KsDefaultAddEventHandler ( IN PIRP  Irp,
IN PKSEVENTDATA  EventData,
IN OUT PKSEVENT_ENTRY  EventEntry 
)

Definition at line 698 of file event.c.

702 {
703  PIO_STACK_LOCATION IoStack;
704  PKSIOBJECT_HEADER ObjectHeader;
706 
707  /* first get the io stack location */
709 
710  /* now get the object header */
711  ObjectHeader =(PKSIOBJECT_HEADER)IoStack->FileObject->FsContext2;
712 
713  /* sanity check */
714  ASSERT(ObjectHeader->ObjectType);
715 
716  /* obtain basic header */
717  Header = (PKSBASIC_HEADER)((ULONG_PTR)ObjectHeader->ObjectType - sizeof(KSBASIC_HEADER));
718 
719  /* now insert the event entry */
720  ExInterlockedInsertTailList(&Header->EventList, &EventEntry->ListEntry, &Header->EventListLock);
721 
722  /* done */
723  return STATUS_SUCCESS;
724 }
struct KSBASIC_HEADER * PKSBASIC_HEADER
_In_ PIRP Irp
Definition: csq.h:116
struct KSIOBJECT_HEADER * PKSIOBJECT_HEADER
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
uint32_t ULONG_PTR
Definition: typedefs.h:63
Definition: Header.h:8
PVOID ObjectType
Definition: kstypes.h:30
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
return STATUS_SUCCESS
Definition: btrfs.c:2966

◆ KsDisableEvent()

KSDDKAPI NTSTATUS NTAPI KsDisableEvent ( IN PIRP  Irp,
IN OUT PLIST_ENTRY  EventsList,
IN KSEVENTS_LOCKTYPE  EventsFlags,
IN PVOID  EventsLock 
)

Definition at line 469 of file event.c.

474 {
475  PIO_STACK_LOCATION IoStack;
476  KSEVENT_CTX Ctx;
477 
478  /* get current irp stack location */
480 
481  /* is there a event entry */
482  if (IoStack->Parameters.DeviceIoControl.InputBufferLength < sizeof(KSEVENTDATA))
483  {
484  if (IoStack->Parameters.DeviceIoControl.InputBufferLength == 0)
485  {
486  /* caller wants to free event items */
487  KsFreeEventList(IoStack->FileObject, EventsList, EventsFlags, EventsLock);
488  return STATUS_SUCCESS;
489  }
490  /* invalid parameter */
492  }
493 
494  /* setup event ctx */
495  Ctx.List = EventsList;
496  Ctx.FileObject = IoStack->FileObject;
497  Ctx.Irp = Irp;
498  Ctx.EventEntry = NULL;
499 
500  if (KspSynchronizedEventRoutine(EventsFlags, EventsLock, KspDisableEvent, &Ctx))
501  {
502  /* was the event entry found */
503  if (Ctx.EventEntry)
504  {
505  /* discard event */
507  return STATUS_SUCCESS;
508  }
509  /* event was not found */
510  return STATUS_UNSUCCESSFUL;
511  }
512 
513  /* invalid parameters */
515 }
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
PKSEVENT_ENTRY EventEntry
Definition: kstypes.h:138
BOOLEAN KspSynchronizedEventRoutine(IN KSEVENTS_LOCKTYPE EventsFlags, IN PVOID EventsLock, IN PKSEVENT_SYNCHRONIZED_ROUTINE SynchronizedRoutine, IN PKSEVENT_CTX Ctx)
Definition: event.c:15
smooth NULL
Definition: ftsmooth.c:416
#define STATUS_INVALID_BUFFER_SIZE
Definition: ntstatus.h:636
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
PFILE_OBJECT FileObject
Definition: kstypes.h:137
PIRP Irp
Definition: kstypes.h:139
BOOLEAN NTAPI KspDisableEvent(IN PKSEVENT_CTX Ctx)
Definition: event.c:420
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
KSDDKAPI VOID NTAPI KsDiscardEvent(IN PKSEVENT_ENTRY EventEntry)
Definition: event.c:523
KSDDKAPI VOID NTAPI KsFreeEventList(IN PFILE_OBJECT FileObject, IN OUT PLIST_ENTRY EventsList, IN KSEVENTS_LOCKTYPE EventsFlags, IN PVOID EventsLock)
Definition: event.c:579
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:2966
PLIST_ENTRY List
Definition: kstypes.h:136

Referenced by IKsFilter_DispatchDeviceIoControl(), IKsPin_DispatchDeviceIoControl(), and PcHandleDisableEventWithTable().

◆ KsDiscardEvent()

KSDDKAPI VOID NTAPI KsDiscardEvent ( IN PKSEVENT_ENTRY  EventEntry)

Definition at line 523 of file event.c.

525 {
526  /* sanity check */
527  ASSERT(EventEntry->Object);
528 
529  if (EventEntry->NotificationType == KSEVENTF_SEMAPHORE_HANDLE || EventEntry->NotificationType == KSEVENTF_EVENT_HANDLE)
530  {
531  /* release object */
532  ObDereferenceObject(EventEntry->Object);
533  }
534 
535  /* free event entry */
536  FreeItem(EventEntry);
537 }
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
VOID FreeItem(IN PVOID Item)
Definition: misc.c:43
#define KSEVENTF_SEMAPHORE_HANDLE
Definition: ks.h:1779
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define KSEVENTF_EVENT_HANDLE
Definition: ks.h:1778

Referenced by KsDisableEvent(), KsFreeEventList(), and KspEnableEvent().

◆ KsEnableEvent()

KSDDKAPI NTSTATUS NTAPI KsEnableEvent ( IN PIRP  Irp,
IN ULONG  EventSetsCount,
IN KSEVENT_SET *  EventSet,
IN OUT PLIST_ENTRY EventsList  OPTIONAL,
IN KSEVENTS_LOCKTYPE EventsFlags  OPTIONAL,
IN PVOID EventsLock  OPTIONAL 
)

Definition at line 387 of file event.c.

394 {
395  return KspEnableEvent(Irp, EventSetsCount, EventSet, EventsList, EventsFlags, EventsLock, NULL, 0);
396 }
_In_ PIRP Irp
Definition: csq.h:116
NTSTATUS KspEnableEvent(IN PIRP Irp, IN ULONG EventSetsCount, IN const KSEVENT_SET *EventSet, IN OUT PLIST_ENTRY EventsList OPTIONAL, IN KSEVENTS_LOCKTYPE EventsFlags OPTIONAL, IN PVOID EventsLock OPTIONAL, IN PFNKSALLOCATOR Allocator OPTIONAL, IN ULONG EventItemSize OPTIONAL)
Definition: event.c:87
smooth NULL
Definition: ftsmooth.c:416

Referenced by PcHandleEnableEventWithTable().

◆ KsFreeEventList()

KSDDKAPI VOID NTAPI KsFreeEventList ( IN PFILE_OBJECT  FileObject,
IN OUT PLIST_ENTRY  EventsList,
IN KSEVENTS_LOCKTYPE  EventsFlags,
IN PVOID  EventsLock 
)

Definition at line 579 of file event.c.

584 {
585  KSEVENT_CTX Ctx;
586 
587  /* setup event ctx */
588  Ctx.List = EventsList;
589  Ctx.FileObject = FileObject;
590  Ctx.EventEntry = NULL;
591 
592  while(KspSynchronizedEventRoutine(EventsFlags, EventsLock, KspFreeEventList, &Ctx))
593  {
594  if (Ctx.EventEntry)
595  {
597  }
598  }
599 }
PKSEVENT_ENTRY EventEntry
Definition: kstypes.h:138
BOOLEAN KspSynchronizedEventRoutine(IN KSEVENTS_LOCKTYPE EventsFlags, IN PVOID EventsLock, IN PKSEVENT_SYNCHRONIZED_ROUTINE SynchronizedRoutine, IN PKSEVENT_CTX Ctx)
Definition: event.c:15
smooth NULL
Definition: ftsmooth.c:416
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
PFILE_OBJECT FileObject
Definition: kstypes.h:137
KSDDKAPI VOID NTAPI KsDiscardEvent(IN PKSEVENT_ENTRY EventEntry)
Definition: event.c:523
BOOLEAN NTAPI KspFreeEventList(IN PKSEVENT_CTX Ctx)
Definition: event.c:542
PLIST_ENTRY List
Definition: kstypes.h:136

Referenced by KsDisableEvent().

◆ KsGenerateDataEvent()

KSDDKAPI NTSTATUS NTAPI KsGenerateDataEvent ( IN PKSEVENT_ENTRY  EventEntry,
IN ULONG  DataSize,
IN PVOID  Data 
)

Definition at line 653 of file event.c.

657 {
659  return STATUS_UNSUCCESSFUL;
660 }
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define UNIMPLEMENTED
Definition: debug.h:114

◆ KsGenerateEvent()

KSDDKAPI NTSTATUS NTAPI KsGenerateEvent ( IN PKSEVENT_ENTRY  EntryEvent)

Definition at line 608 of file event.c.

610 {
611  if (EntryEvent->NotificationType == KSEVENTF_EVENT_HANDLE || EntryEvent->NotificationType == KSEVENTF_EVENT_OBJECT)
612  {
613  /* signal event */
614  KeSetEvent(EntryEvent->Object, EntryEvent->Reserved, FALSE);
615  }
616  else if (EntryEvent->NotificationType == KSEVENTF_SEMAPHORE_HANDLE || EntryEvent->NotificationType == KSEVENTF_SEMAPHORE_OBJECT)
617  {
618  /* release semaphore */
619  KeReleaseSemaphore(EntryEvent->Object, EntryEvent->Reserved, EntryEvent->SemaphoreAdjustment, FALSE);
620  }
621  else if (EntryEvent->NotificationType == KSEVENTF_DPC)
622  {
623  /* increment reference count to indicate dpc is pending */
624  InterlockedIncrement((PLONG)&EntryEvent->EventData->Dpc.ReferenceCount);
625  /* queue dpc */
626  KeInsertQueueDpc((PRKDPC)EntryEvent->Object, NULL, NULL);
627  }
628  else if (EntryEvent->NotificationType == KSEVENTF_WORKITEM)
629  {
630  /* queue work item */
631  ExQueueWorkItem((PWORK_QUEUE_ITEM)EntryEvent->Object, PtrToUlong(EntryEvent->BufferItem));
632  }
633  else if (EntryEvent->NotificationType == KSEVENTF_KSWORKITEM)
634  {
635  /* queue work item of ks worker */
636  return KsQueueWorkItem((PKSWORKER)EntryEvent->Object, (PWORK_QUEUE_ITEM)EntryEvent->DpcItem);
637  }
638  else
639  {
640  /* unsupported type requested */
642  }
643 
644  return STATUS_SUCCESS;
645 }
VOID NTAPI ExQueueWorkItem(IN PWORK_QUEUE_ITEM WorkItem, IN WORK_QUEUE_TYPE QueueType)
Definition: work.c:717
KSDDKAPI NTSTATUS NTAPI KsQueueWorkItem(IN PKSWORKER Worker, IN PWORK_QUEUE_ITEM WorkItem)
Definition: worker.c:252
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
BOOLEAN NTAPI KeInsertQueueDpc(IN PKDPC Dpc, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: dpc.c:724
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
smooth NULL
Definition: ftsmooth.c:416
#define KSEVENTF_SEMAPHORE_HANDLE
Definition: ks.h:1779
#define PtrToUlong(u)
Definition: config.h:107
Definition: ketypes.h:687
#define InterlockedIncrement
Definition: armddk.h:53
LONG NTAPI KeReleaseSemaphore(IN PKSEMAPHORE Semaphore, IN KPRIORITY Increment, IN LONG Adjustment, IN BOOLEAN Wait)
Definition: semphobj.c:54
#define KSEVENTF_EVENT_HANDLE
Definition: ks.h:1778
return STATUS_SUCCESS
Definition: btrfs.c:2966
signed int * PLONG
Definition: retypes.h:5

Referenced by CPortPinWaveCyclic::GeneratePositionEvents().

◆ KsGenerateEventList()

KSDDKAPI VOID NTAPI KsGenerateEventList ( IN GUID *Set  OPTIONAL,
IN ULONG  EventId,
IN PLIST_ENTRY  EventsList,
IN KSEVENTS_LOCKTYPE  EventsFlags,
IN PVOID  EventsLock 
)

Definition at line 668 of file event.c.

674 {
676 }
#define UNIMPLEMENTED
Definition: debug.h:114

◆ KsGenerateEvents()

KSDDKAPI void NTAPI KsGenerateEvents ( IN PVOID  Object,
IN const GUID *EventSet  OPTIONAL,
IN ULONG  EventId,
IN ULONG  DataSize,
IN PVOID Data  OPTIONAL,
IN PFNKSGENERATEEVENTCALLBACK CallBack  OPTIONAL,
IN PVOID CallBackContext  OPTIONAL 
)

Definition at line 734 of file event.c.

742 {
744 }
#define UNIMPLEMENTED
Definition: debug.h:114

◆ KspDisableEvent()

BOOLEAN NTAPI KspDisableEvent ( IN PKSEVENT_CTX  Ctx)

Definition at line 420 of file event.c.

422 {
423  PIO_STACK_LOCATION IoStack;
424  PKSEVENTDATA EventData;
425  PKSEVENT_ENTRY EventEntry;
427 
428  if (!Ctx || !Ctx->List || !Ctx->FileObject || !Ctx->Irp)
429  {
430  /* invalid parameter */
431  return FALSE;
432  }
433 
434  /* get current irp stack location */
435  IoStack = IoGetCurrentIrpStackLocation(Ctx->Irp);
436 
437  /* get event data */
438  EventData = (PKSEVENTDATA)IoStack->Parameters.DeviceIoControl.Type3InputBuffer;
439 
440  /* point to first entry */
441  Entry = Ctx->List->Flink;
442 
443  while(Entry != Ctx->List)
444  {
445  /* get event entry */
446  EventEntry = (PKSEVENT_ENTRY)CONTAINING_RECORD(Entry, KSEVENT_ENTRY, ListEntry);
447 
448  if (EventEntry->EventData == EventData && EventEntry->FileObject == Ctx->FileObject)
449  {
450  /* found the entry */
451  RemoveEntryList(&EventEntry->ListEntry);
452  Ctx->EventEntry = EventEntry;
453  return TRUE;
454  }
455 
456  /* move to next item */
457  Entry = Entry->Flink;
458  }
459  /* entry not found */
460  return TRUE;
461 }
#define TRUE
Definition: types.h:120
struct _Entry Entry
Definition: kefuncs.h:640
struct KSEVENTDATA * PKSEVENTDATA
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
struct _KSEVENT_ENTRY KSEVENT_ENTRY
Definition: ks.h:2101
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
Definition: typedefs.h:117
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
struct _KSEVENT_ENTRY * PKSEVENT_ENTRY
Definition: ks.h:2101
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
base of all file and directory entries
Definition: entries.h:82

Referenced by KsDisableEvent().

◆ KspEnableEvent()

NTSTATUS KspEnableEvent ( IN PIRP  Irp,
IN ULONG  EventSetsCount,
IN const KSEVENT_SET *  EventSet,
IN OUT PLIST_ENTRY EventsList  OPTIONAL,
IN KSEVENTS_LOCKTYPE EventsFlags  OPTIONAL,
IN PVOID EventsLock  OPTIONAL,
IN PFNKSALLOCATOR Allocator  OPTIONAL,
IN ULONG EventItemSize  OPTIONAL 
)

Definition at line 87 of file event.c.

96 {
97  PIO_STACK_LOCATION IoStack;
99  KSEVENT Event;
100  PKSEVENT_ITEM EventItem, FoundEventItem;
101  PKSEVENTDATA EventData;
102  const KSEVENT_SET *FoundEventSet;
103  PKSEVENT_ENTRY EventEntry;
104  ULONG Index, SubIndex, Size;
105  PVOID Object;
106  KSEVENT_CTX Ctx;
107  LPGUID Guid;
108 
109  /* get current stack location */
111 
112  if (IoStack->Parameters.DeviceIoControl.InputBufferLength < sizeof(KSEVENT))
113  {
114  /* invalid parameter */
115  return STATUS_NOT_SUPPORTED;
116  }
117 
118  if (Irp->RequestorMode == UserMode)
119  {
120  _SEH2_TRY
121  {
122  ProbeForRead(IoStack->Parameters.DeviceIoControl.Type3InputBuffer, sizeof(KSEVENT), sizeof(UCHAR));
123  ProbeForRead(Irp->UserBuffer, IoStack->Parameters.DeviceIoControl.OutputBufferLength, sizeof(UCHAR));
124  RtlMoveMemory(&Event, IoStack->Parameters.DeviceIoControl.Type3InputBuffer, sizeof(KSEVENT));
126  }
128  {
129  /* Exception, get the error code */
131  }
132  _SEH2_END;
133 
134  /* check for success */
135  if (!NT_SUCCESS(Status))
136  {
137  /* failed to probe parameters */
138  return Status;
139  }
140  }
141  else
142  {
143  /* copy event struct */
144  RtlMoveMemory(&Event, IoStack->Parameters.DeviceIoControl.Type3InputBuffer, sizeof(KSEVENT));
145  }
146 
147  FoundEventItem = NULL;
148  FoundEventSet = NULL;
149 
150 
151  if (IsEqualGUIDAligned(&Event.Set, &GUID_NULL) && Event.Id == 0 && Event.Flags == KSEVENT_TYPE_SETSUPPORT)
152  {
153  // store output size
154  Irp->IoStatus.Information = sizeof(GUID) * EventSetsCount;
155  if (IoStack->Parameters.DeviceIoControl.OutputBufferLength < sizeof(GUID) * EventSetsCount)
156  {
157  // buffer too small
158  return STATUS_MORE_ENTRIES;
159  }
160 
161  // get output buffer
162  Guid = (LPGUID)Irp->UserBuffer;
163 
164  // copy property guids from property sets
165  for(Index = 0; Index < EventSetsCount; Index++)
166  {
167  RtlMoveMemory(&Guid[Index], EventSet[Index].Set, sizeof(GUID));
168  }
169  return STATUS_SUCCESS;
170  }
171 
172  /* now try to find event set */
173  for(Index = 0; Index < EventSetsCount; Index++)
174  {
175  if (IsEqualGUIDAligned(&Event.Set, EventSet[Index].Set))
176  {
177  EventItem = (PKSEVENT_ITEM)EventSet[Index].EventItem;
178 
179  /* sanity check */
180  ASSERT(EventSet[Index].EventsCount);
181  ASSERT(EventItem);
182 
183  /* now find matching event id */
184  for(SubIndex = 0; SubIndex < EventSet[Index].EventsCount; SubIndex++)
185  {
186  if (EventItem[SubIndex].EventId == Event.Id)
187  {
188  /* found event item */
189  FoundEventItem = &EventItem[SubIndex];
190  FoundEventSet = &EventSet[Index];
191  break;
192  }
193  }
194 
195  if (FoundEventSet)
196  break;
197  }
198  }
199 
200  if (!FoundEventSet)
201  {
203 
205 
206  DPRINT("Guid %S Id %u Flags %x not found\n", GuidString.Buffer, Event.Id, Event.Flags);
209 
210 
211  }
212 
213  if (IoStack->Parameters.DeviceIoControl.OutputBufferLength < FoundEventItem->DataInput)
214  {
215  /* buffer too small */
216  DPRINT1("Got %u expected %u\n", IoStack->Parameters.DeviceIoControl.OutputBufferLength, FoundEventItem->DataInput);
217  return STATUS_SUCCESS;
218  }
219 
220  if (!FoundEventItem->AddHandler && !EventsList)
221  {
222  /* no add handler and no list to add the new entry to */
224  }
225 
226  /* get event data */
227  EventData = Irp->UserBuffer;
228 
229  /* sanity check */
230  ASSERT(EventData);
231 
232  if (Irp->RequestorMode == UserMode)
233  {
235  {
236  /* get semaphore object handle */
238 
239  if (!NT_SUCCESS(Status))
240  {
241  /* invalid semaphore handle */
243  }
244  }
245  else if (EventData->NotificationType == KSEVENTF_EVENT_HANDLE)
246  {
247  /* get event object handle */
249 
250  if (!NT_SUCCESS(Status))
251  {
252  /* invalid event handle */
254  }
255  }
256  else
257  {
258  /* user mode client can only pass an event or semaphore handle */
260  }
261  }
262  else
263  {
264  if (EventData->NotificationType != KSEVENTF_EVENT_OBJECT &&
265  EventData->NotificationType != KSEVENTF_SEMAPHORE_OBJECT &&
266  EventData->NotificationType != KSEVENTF_DPC &&
267  EventData->NotificationType != KSEVENTF_WORKITEM &&
268  EventData->NotificationType != KSEVENTF_KSWORKITEM)
269  {
270  /* invalid type requested */
272  }
273  }
274 
275 
276  /* calculate request size */
277  Size = sizeof(KSEVENT_ENTRY) + FoundEventItem->ExtraEntryData;
278 
279  /* do we have an allocator */
280  if (Allocator)
281  {
282  /* allocate event entry */
283  Status = Allocator(Irp, Size, FALSE);
284 
285  if (!NT_SUCCESS(Status))
286  {
287  /* failed */
288  return Status;
289  }
290 
291  /* assume the caller put it there */
292  EventEntry = KSEVENT_ENTRY_IRP_STORAGE(Irp);
293 
294  }
295  else
296  {
297  /* allocate it from nonpaged pool */
298  EventEntry = AllocateItem(NonPagedPool, Size);
299  }
300 
301  if (!EventEntry)
302  {
303  /* not enough memory */
305  }
306 
307  /* zero event entry */
308  RtlZeroMemory(EventEntry, Size);
309 
310  /* initialize event entry */
311  EventEntry->EventData = EventData;
312  EventEntry->NotificationType = EventData->NotificationType;
313  EventEntry->EventItem = FoundEventItem;
314  EventEntry->EventSet = FoundEventSet;
315  EventEntry->FileObject = IoStack->FileObject;
316 
317  switch(EventEntry->NotificationType)
318  {
320  EventEntry->Object = Object;
321  EventEntry->Reserved = 0;
322  break;
324  EventEntry->Object = Object;
325  EventEntry->SemaphoreAdjustment = EventData->SemaphoreHandle.Adjustment;
326  EventEntry->Reserved = 0;
327  break;
328  case KSEVENTF_EVENT_OBJECT:
329  EventEntry->Object = EventData->EventObject.Event;
330  EventEntry->Reserved = EventData->EventObject.Increment;
331  break;
332  case KSEVENTF_SEMAPHORE_OBJECT:
333  EventEntry->Object = EventData->SemaphoreObject.Semaphore;
334  EventEntry->SemaphoreAdjustment = EventData->SemaphoreObject.Adjustment;
335  EventEntry->Reserved = EventData->SemaphoreObject.Increment;
336  break;
337  case KSEVENTF_DPC:
338  EventEntry->Object = EventData->Dpc.Dpc;
339  EventData->Dpc.ReferenceCount = 0;
340  break;
341  case KSEVENTF_WORKITEM:
342  EventEntry->Object = EventData->WorkItem.WorkQueueItem;
343  EventEntry->BufferItem = (PKSBUFFER_ITEM)UlongToPtr(EventData->WorkItem.WorkQueueType);
344  break;
345  case KSEVENTF_KSWORKITEM:
346  EventEntry->Object = EventData->KsWorkItem.KsWorkerObject;
347  EventEntry->DpcItem = (PKSDPC_ITEM)EventData->KsWorkItem.WorkQueueItem;
348  break;
349  default:
350  /* should not happen */
351  ASSERT(0);
352  }
353 
354  if (FoundEventItem->AddHandler)
355  {
356  /* now add the event */
357  Status = FoundEventItem->AddHandler(Irp, EventData, EventEntry);
358 
359  if (!NT_SUCCESS(Status))
360  {
361  /* discard event entry */
362  KsDiscardEvent(EventEntry);
363  }
364  }
365  else
366  {
367  /* setup context */
368  Ctx.List = EventsList;
369  Ctx.EventEntry = EventEntry;
370 
371  /* add the event */
372  (void)KspSynchronizedEventRoutine(EventsFlags, EventsLock, SyncAddEvent, &Ctx);
373 
375  }
376 
377  /* done */
378  return Status;
379 }
static PWSTR GuidString
Definition: apphelp.c:91
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
ULONG NotificationType
Definition: ks.h:1733
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
PVOID AllocateItem(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
Definition: misc.c:30
LONG NTSTATUS
Definition: precomp.h:26
PKSEVENT_ENTRY EventEntry
Definition: kstypes.h:138
#define SEMAPHORE_MODIFY_STATE
Definition: winbase.h:161
POBJECT_TYPE ExEventObjectType
Definition: event.c:22
static BOOL Set
Definition: pageheap.c:10
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:263
_SEH2_TRY
Definition: create.c:4250
#define IsEqualGUIDAligned(guid1, guid2)
Definition: wdm.template.h:233
BOOLEAN KspSynchronizedEventRoutine(IN KSEVENTS_LOCKTYPE EventsFlags, IN PVOID EventsLock, IN PKSEVENT_SYNCHRONIZED_ROUTINE SynchronizedRoutine, IN PKSEVENT_CTX Ctx)
Definition: event.c:15
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:496
struct KSEVENTDATA::@2890::@2892 EventHandle
LONG Adjustment
Definition: ks.h:1742
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:435
struct _KSEVENT_ENTRY KSEVENT_ENTRY
Definition: ks.h:2101
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
static GUID * Guid
Definition: apphelp.c:93
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define KSEVENTF_SEMAPHORE_HANDLE
Definition: ks.h:1779
#define UlongToPtr(u)
Definition: config.h:106
if(!(yy_init))
Definition: macro.lex.yy.c:714
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define KSEVENT_TYPE_SETSUPPORT
Definition: ks.h:1792
static const UCHAR Index[8]
Definition: usbohci.c:18
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
static IUnknown Object
Definition: main.c:512
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
unsigned char UCHAR
Definition: xmlstorage.h:181
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
#define GUID_NULL
Definition: ks.h:106
NTSYSAPI NTSTATUS WINAPI RtlStringFromGUID(REFGUID, PUNICODE_STRING)
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
#define STATUS_MORE_ENTRIES
Definition: udferr_usr.h:124
Status
Definition: gdiplustypes.h:24
#define STATUS_PROPSET_NOT_FOUND
Definition: ntstatus.h:678
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
struct _GUID GUID
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
_SEH2_END
Definition: create.c:4424
KSDDKAPI VOID NTAPI KsDiscardEvent(IN PKSEVENT_ENTRY EventEntry)
Definition: event.c:523
HANDLE Event
Definition: ks.h:1736
BOOLEAN NTAPI SyncAddEvent(PKSEVENT_CTX Context)
Definition: event.c:79
#define KSEVENTF_EVENT_HANDLE
Definition: ks.h:1778
#define DPRINT1
Definition: precomp.h:8
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
unsigned int ULONG
Definition: retypes.h:1
#define EVENT_MODIFY_STATE
Definition: winbase.h:163
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
struct _KSEVENT_ENTRY * PKSEVENT_ENTRY
Definition: ks.h:2101
struct KSEVENTDATA::@2890::@2893 SemaphoreHandle
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
HANDLE Semaphore
Definition: ks.h:1740
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:2966
PLIST_ENTRY List
Definition: kstypes.h:136
POBJECT_TYPE ExSemaphoreObjectType
Definition: sem.c:22
GUID * LPGUID
Definition: guiddef.h:81

Referenced by _IRQL_requires_max_(), IKsFilter_DispatchDeviceIoControl(), IKsPin_DispatchDeviceIoControl(), and KsEnableEvent().

◆ KspFreeEventList()

BOOLEAN NTAPI KspFreeEventList ( IN PKSEVENT_CTX  Ctx)

Definition at line 542 of file event.c.

544 {
546  PKSEVENT_ENTRY EventEntry;
547 
548  /* check valid input */
549  if (!Ctx || !Ctx->List)
550  return FALSE;
551 
552  if (IsListEmpty(Ctx->List))
553  return FALSE;
554 
555  /* remove first entry */
556  Entry = RemoveHeadList(Ctx->List);
557  if (!Entry)
558  {
559  /* list is empty, bye-bye */
560  return FALSE;
561  }
562 
563  /* get event entry */
564  EventEntry = (PKSEVENT_ENTRY)CONTAINING_RECORD(Entry, KSEVENT_ENTRY, ListEntry);
565 
566  /* store event entry */
567  Ctx->EventEntry = EventEntry;
568  /* return success */
569  return TRUE;
570 }
#define TRUE
Definition: types.h:120
struct _Entry Entry
Definition: kefuncs.h:640
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
struct _KSEVENT_ENTRY KSEVENT_ENTRY
Definition: ks.h:2101
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
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
Definition: typedefs.h:117
struct _KSEVENT_ENTRY * PKSEVENT_ENTRY
Definition: ks.h:2101
base of all file and directory entries
Definition: entries.h:82

Referenced by KsFreeEventList().

◆ KspSynchronizedEventRoutine()

BOOLEAN KspSynchronizedEventRoutine ( IN KSEVENTS_LOCKTYPE  EventsFlags,
IN PVOID  EventsLock,
IN PKSEVENT_SYNCHRONIZED_ROUTINE  SynchronizedRoutine,
IN PKSEVENT_CTX  Ctx 
)

Definition at line 15 of file event.c.

20 {
22  KIRQL OldLevel;
23 
24  if (EventsFlags == KSEVENTS_NONE)
25  {
26  /* no synchronization required */
27  Result = SynchronizedRoutine(Ctx);
28  }
29  else if (EventsFlags == KSEVENTS_SPINLOCK)
30  {
31  /* use spin lock */
32  KeAcquireSpinLock((PKSPIN_LOCK)EventsLock, &OldLevel);
33  Result = SynchronizedRoutine(Ctx);
34  KeReleaseSpinLock((PKSPIN_LOCK)EventsLock, OldLevel);
35  }
36  else if (EventsFlags == KSEVENTS_MUTEX)
37  {
38  /* use a mutex */
40  Result = SynchronizedRoutine(Ctx);
41  KeReleaseMutex((PRKMUTEX)EventsLock, FALSE);
42  }
43  else if (EventsFlags == KSEVENTS_FMUTEX)
44  {
45  /* use a fast mutex */
46  ExAcquireFastMutex((PFAST_MUTEX)EventsLock);
47  Result = SynchronizedRoutine(Ctx);
48  ExReleaseFastMutex((PFAST_MUTEX)EventsLock);
49  }
50  else if (EventsFlags == KSEVENTS_FMUTEXUNSAFE)
51  {
52  /* acquire fast mutex unsafe */
55  Result = SynchronizedRoutine(Ctx);
58  }
59  else if (EventsFlags == KSEVENTS_INTERRUPT)
60  {
61  /* use interrupt for locking */
62  Result = KeSynchronizeExecution((PKINTERRUPT)EventsLock, (PKSYNCHRONIZE_ROUTINE)SynchronizedRoutine, (PVOID)Ctx);
63  }
64  else if (EventsFlags == KSEVENTS_ERESOURCE)
65  {
66  /* use an eresource */
69  Result = SynchronizedRoutine(Ctx);
70  ExReleaseResourceLite((PERESOURCE)EventsLock);
72  }
73 
74  return Result;
75 }
#define TRUE
Definition: types.h:120
KSPIN_LOCK * PKSPIN_LOCK
Definition: env_spec_w32.h:73
LONG NTAPI KeReleaseMutex(IN PKMUTEX Mutex, IN BOOLEAN Wait)
Definition: mutex.c:189
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
VOID FASTCALL ExReleaseFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:31
VOID FASTCALL ExReleaseFastMutexUnsafe(IN OUT PFAST_MUTEX FastMutex)
Definition: fmutex.c:86
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
UCHAR KIRQL
Definition: env_spec_w32.h:591
ERESOURCE * PERESOURCE
Definition: env_spec_w32.h:595
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
KSYNCHRONIZE_ROUTINE * PKSYNCHRONIZE_ROUTINE
Definition: ketypes.h:863
_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
VOID FASTCALL ExAcquireFastMutexUnsafe(IN OUT PFAST_MUTEX FastMutex)
Definition: fmutex.c:75
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
#define KeEnterCriticalRegion()
Definition: ke_x.h:83
* PFAST_MUTEX
Definition: extypes.h:17
#define KeLeaveCriticalRegion()
Definition: ke_x.h:114
VOID FASTCALL ExAcquireFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:23
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
BOOLEAN NTAPI KeSynchronizeExecution(IN OUT PKINTERRUPT Interrupt, IN PKSYNCHRONIZE_ROUTINE SynchronizeRoutine, IN PVOID SynchronizeContext OPTIONAL)
Definition: interrupt.c:142

Referenced by KsDisableEvent(), KsFreeEventList(), and KspEnableEvent().

◆ SyncAddEvent()

BOOLEAN NTAPI SyncAddEvent ( PKSEVENT_CTX  Context)

Definition at line 79 of file event.c.

81 {
82  InsertTailList(Context->List, &Context->EventEntry->ListEntry);
83  return TRUE;
84 }
#define TRUE
Definition: types.h:120
#define InsertTailList(ListHead, Entry)

Referenced by KspEnableEvent().