ReactOS  0.4.14-dev-50-g13bb5e2
Messaging.c
Go to the documentation of this file.
1 /*
2 * PROJECT: Filesystem Filter Manager
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: drivers/filters/fltmgr/Messaging.c
5 * PURPOSE: Contains the routines to handle the comms layer
6 * PROGRAMMERS: Ged Murphy (gedmurphy@reactos.org)
7 */
8 
9 /* INCLUDES ******************************************************************/
10 
11 #include "fltmgr.h"
12 #include "fltmgrint.h"
13 #include <fltmgr_shared.h>
14 
15 #define NDEBUG
16 #include <debug.h>
17 
18 
19 /* DATA *********************************************************************/
20 
21 UNICODE_STRING CommsDeviceName = RTL_CONSTANT_STRING(L"\\FileSystem\\Filters\\FltMgrMsg");
23 
26 
27 static
28 BOOLEAN
30  _In_ PFLT_PORT_OBJECT PortObject
31 );
32 
33 static
38 );
39 
40 static
45 );
46 
47 static
50  _Inout_ PFLT_MESSAGE_WAITER_QUEUE MsgWaiterQueue
51 );
52 
53 static
56  _In_ PFLT_PORT_OBJECT PortObject
57 );
58 
59 
60 
61 /* EXPORTED FUNCTIONS ******************************************************/
62 
66 FLTAPI
67 FltCreateCommunicationPort(_In_ PFLT_FILTER Filter,
75 {
76  PFLT_SERVER_PORT_OBJECT PortObject;
78 
79  /* The caller must allow at least one connection */
80  if (MaxConnections == 0)
81  {
83  }
84 
85  /* The request must be for a kernel handle */
86  if (!(ObjectAttributes->Attributes & OBJ_KERNEL_HANDLE))
87  {
89  }
90 
91  /*
92  * Get rundown protection on the target to stop the owner
93  * from unloading whilst this port object is open. It gets
94  * removed in the FltpServerPortClose callback
95  */
97  if (!NT_SUCCESS(Status))
98  {
99  return Status;
100  }
101 
102  /* Create the server port object for this filter */
106  KernelMode,
107  NULL,
108  sizeof(FLT_SERVER_PORT_OBJECT),
109  0,
110  0,
111  (PVOID *)&PortObject);
112  if (NT_SUCCESS(Status))
113  {
114  /* Zero out the struct */
115  RtlZeroMemory(PortObject, sizeof(FLT_SERVER_PORT_OBJECT));
116 
117  /* Increment the ref count on the target filter */
119 
120  /* Setup the filter port object */
121  PortObject->Filter = Filter;
122  PortObject->ConnectNotify = ConnectNotifyCallback;
123  PortObject->DisconnectNotify = DisconnectNotifyCallback;
124  PortObject->MessageNotify = MessageNotifyCallback;
125  PortObject->Cookie = ServerPortCookie;
126  PortObject->MaxConnections = MaxConnections;
127 
128  /* Insert the object */
129  Status = ObInsertObject(PortObject,
130  NULL,
132  0,
133  NULL,
135  if (NT_SUCCESS(Status))
136  {
137  /* Lock the connection list */
139 
140  /* Add the new port object to the connection list and increment the count */
141  InsertTailList(&Filter->ConnectionList.mList, &PortObject->FilterLink);
143 
144  /* Unlock the connection list*/
146  }
147  }
148 
149  if (!NT_SUCCESS(Status))
150  {
151  /* Allow the filter to be cleaned up */
153  }
154 
155  return Status;
156 }
157 
159 VOID
160 FLTAPI
161 FltCloseCommunicationPort(_In_ PFLT_PORT ServerPort)
162 {
163  /* Just close the handle to initiate the cleanup callbacks */
165 }
166 
168 VOID
169 FLTAPI
170 FltCloseClientPort(_In_ PFLT_FILTER Filter,
172 {
173  PFLT_PORT Port;
174 
175  /* Protect against the handle being used whilst we're closing it */
176  FltAcquirePushLockShared(&Filter->PortLock);
177 
178  /* Store the port handle while we have the lock held */
179  Port = *ClientPort;
180 
181  if (*ClientPort)
182  {
183  /* Set the hadle to null */
184  *ClientPort = NULL;
185  }
186 
187  /* Unlock the port */
188  FltReleasePushLock(&Filter->PortLock);
189 
190  if (Port)
191  {
192  /* Close the safe handle */
193  ZwClose(Port);
194  }
195 }
196 
199 NTSTATUS
200 FLTAPI
201 FltSendMessage(_In_ PFLT_FILTER Filter,
208 {
211  UNREFERENCED_PARAMETER(SenderBuffer);
216  return STATUS_NOT_IMPLEMENTED;
217 }
218 
219 /* INTERNAL FUNCTIONS ******************************************************/
220 
221 
222 NTSTATUS
224  _Inout_ PIRP Irp)
225 {
226  PIO_STACK_LOCATION StackPtr;
228 
229  /* Get the stack location */
230  StackPtr = IoGetCurrentIrpStackLocation(Irp);
231 
232  FLT_ASSERT(StackPtr->MajorFunction == IRP_MJ_CREATE);
233 
234  /* Check if this is a caller wanting to connect */
235  if (StackPtr->MajorFunction == IRP_MJ_CREATE)
236  {
237  /* Create the client port for this connection and exit */
238  Status = CreateClientPort(StackPtr->FileObject, Irp);
239  }
240  else
241  {
243  }
244 
245  if (Status != STATUS_PENDING)
246  {
247  Irp->IoStatus.Status = Status;
248  Irp->IoStatus.Information = 0;
250  }
251 
252  return Status;
253 }
254 
255 NTSTATUS
257  _Inout_ PIRP Irp)
258 {
259  PIO_STACK_LOCATION StackPtr;
261 
262  /* Get the stack location */
263  StackPtr = IoGetCurrentIrpStackLocation(Irp);
264 
265  /* Check if this is a caller wanting to connect */
266  if (StackPtr->MajorFunction == IRP_MJ_CLOSE)
267  {
268  /* Create the client port for this connection and exit */
269  Status = CloseClientPort(StackPtr->FileObject, Irp);
270  }
271  else
272  {
273  // We don't support anything else yet
275  }
276 
277  if (Status != STATUS_PENDING)
278  {
279  Irp->IoStatus.Status = Status;
280  Irp->IoStatus.Information = 0;
282  }
283 
284  return Status;
285 }
286 
287 VOID
288 NTAPI
290  _In_ PVOID Object,
293  _In_ ULONG SystemHandleCount)
294 {
295  PFLT_SERVER_PORT_OBJECT PortObject;
297 
298  /* Cast the object to a server port object */
299  PortObject = (PFLT_SERVER_PORT_OBJECT)Object;
300 
301  /* Lock the connection list */
302  Lock = &PortObject->Filter->ConnectionList.mLock;
304 
305  /* Remove the server port object from the list */
306  RemoveEntryList(&PortObject->FilterLink);
307 
308  /* Unlock the connection list */
310 
311  /* Remove the rundown protection we added to stop the owner from tearing us down */
312  FltObjectDereference(PortObject->Filter);
313 }
314 
315 VOID
316 NTAPI
318 {
319  /* Decrement the filter count we added in the create routine */
322 
323 }
324 
325 VOID
326 NTAPI
328  _In_ PVOID Object,
331  _In_ ULONG SystemHandleCount)
332 {
334 
335  if (FltpDisconnectPort(PortObject))
336  {
338  }
339 }
340 
341 BOOLEAN
343 {
344  BOOLEAN Disconnected = FALSE;
345 
346  /* Lock the port object while we disconnect it */
347  ExAcquireFastMutex(&PortObject->Lock);
348 
349  /* Make sure we have a valid connection */
350  if (PortObject->Disconnected == FALSE)
351  {
352  /* Let any waiters know we're dusconnecing */
353  KeSetEvent(&PortObject->DisconnectEvent, 0, 0);
354 
355  // cleanup everything in the message queue (PortObject->MsgQ.Csq)
356 
357  /* Set the disconnected state to true */
358  PortObject->Disconnected = TRUE;
359  Disconnected = TRUE;
360  }
361 
362  /* Unlock and exit*/
363  ExReleaseFastMutex(&PortObject->Lock);
364  return Disconnected;
365 }
366 
367 VOID
368 NTAPI
370 {
372  ObDereferenceObject(PortObject->ServerPort);
373 }
374 
375 
376 NTSTATUS
378 {
379  OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;
380  UNICODE_STRING SymLinkName;
383 
385  {
390  };
391 
392  /* Create the server comms object type */
393  RtlZeroMemory(&ObjectTypeInitializer, sizeof(OBJECT_TYPE_INITIALIZER));
394  RtlInitUnicodeString(&Name, L"FilterConnectionPort");
395  ObjectTypeInitializer.Length = sizeof(OBJECT_TYPE_INITIALIZER);
396  ObjectTypeInitializer.InvalidAttributes = OBJ_OPENLINK;
397  ObjectTypeInitializer.GenericMapping = Mapping;
398  ObjectTypeInitializer.PoolType = NonPagedPool;
399  ObjectTypeInitializer.DefaultNonPagedPoolCharge = sizeof(FLT_SERVER_PORT_OBJECT);
400  ObjectTypeInitializer.ValidAccessMask = GENERIC_ALL;
401  ObjectTypeInitializer.CloseProcedure = FltpServerPortClose;
402  ObjectTypeInitializer.DeleteProcedure = FltpServerPortDelete;
403  Status = ObCreateObjectType(&Name, &ObjectTypeInitializer, NULL, &ServerPortObjectType);
404  if (!NT_SUCCESS(Status)) return Status;
405 
406  /* Create the client comms object type */
407  RtlZeroMemory(&ObjectTypeInitializer, sizeof(OBJECT_TYPE_INITIALIZER));
408  RtlInitUnicodeString(&Name, L"FilterCommunicationPort");
409  ObjectTypeInitializer.Length = sizeof(OBJECT_TYPE_INITIALIZER);
410  ObjectTypeInitializer.InvalidAttributes = OBJ_OPENLINK;
411  ObjectTypeInitializer.GenericMapping = Mapping;
412  ObjectTypeInitializer.PoolType = NonPagedPool;
413  ObjectTypeInitializer.DefaultNonPagedPoolCharge = sizeof(FLT_PORT_OBJECT);
414  ObjectTypeInitializer.ValidAccessMask = GENERIC_ALL;
415  ObjectTypeInitializer.CloseProcedure = FltpClientPortClose;
416  ObjectTypeInitializer.DeleteProcedure = FltpClientPortDelete;
417  Status = ObCreateObjectType(&Name, &ObjectTypeInitializer, NULL, &ClientPortObjectType);
418  if (!NT_SUCCESS(Status))
419  {
420  goto Quit;
421  }
422 
423  /* Create the device object */
425  0,
428  0,
429  0,
431  if (NT_SUCCESS(Status))
432  {
433  /* Setup a symbolic link for the device */
434  RtlInitUnicodeString(&SymLinkName, L"\\DosDevices\\FltMgrMsg");
435  Status = IoCreateSymbolicLink(&SymLinkName, &CommsDeviceName);
436  }
437 
438 Quit:
439  if (!NT_SUCCESS(Status))
440  {
441  /* Something went wrong, undo */
442  if (CommsDeviceObject)
443  {
446  }
448  {
452  }
453 
455  {
459  }
460  }
461 
462  return Status;
463 }
464 
465 /* CSQ IRP CALLBACKS *******************************************************/
466 
467 
468 NTSTATUS
469 NTAPI
471  _In_ PIRP Irp,
473 {
474  PFLT_MESSAGE_WAITER_QUEUE MessageWaiterQueue;
475 
476  /* Get the start of the waiter queue struct */
477  MessageWaiterQueue = CONTAINING_RECORD(Csq,
479  Csq);
480 
481  /* Insert the IRP at the end of the queue */
482  InsertTailList(&MessageWaiterQueue->WaiterQ.mList,
483  &Irp->Tail.Overlay.ListEntry);
484 
485  /* return success */
486  return STATUS_SUCCESS;
487 }
488 
489 VOID
490 NTAPI
492  _In_ PIRP Irp)
493 {
494  /* Remove the IRP from the queue */
495  RemoveEntryList(&Irp->Tail.Overlay.ListEntry);
496 }
497 
498 PIRP
499 NTAPI
501  _In_ PIRP Irp,
503 {
504  PFLT_MESSAGE_WAITER_QUEUE MessageWaiterQueue;
505  PIRP NextIrp = NULL;
506  PLIST_ENTRY NextEntry;
507  PIO_STACK_LOCATION IrpStack;
508 
509  /* Get the start of the waiter queue struct */
510  MessageWaiterQueue = CONTAINING_RECORD(Csq,
512  Csq);
513 
514  /* Is the IRP valid? */
515  if (Irp == NULL)
516  {
517  /* Start peeking from the listhead */
518  NextEntry = MessageWaiterQueue->WaiterQ.mList.Flink;
519  }
520  else
521  {
522  /* Start peeking from that IRP onwards */
523  NextEntry = Irp->Tail.Overlay.ListEntry.Flink;
524  }
525 
526  /* Loop through the queue */
527  while (NextEntry != &MessageWaiterQueue->WaiterQ.mList)
528  {
529  /* Store the next IRP in the list */
530  NextIrp = CONTAINING_RECORD(NextEntry, IRP, Tail.Overlay.ListEntry);
531 
532  /* Did we supply a PeekContext on insert? */
533  if (!PeekContext)
534  {
535  /* We already have the next IRP */
536  break;
537  }
538  else
539  {
540  /* Get the stack of the next IRP */
541  IrpStack = IoGetCurrentIrpStackLocation(NextIrp);
542 
543  /* Does the PeekContext match the object? */
544  if (IrpStack->FileObject == (PFILE_OBJECT)PeekContext)
545  {
546  /* We have a match */
547  break;
548  }
549 
550  /* Move to the next IRP */
551  NextIrp = NULL;
552  NextEntry = NextEntry->Flink;
553  }
554  }
555 
556  return NextIrp;
557 }
558 
562 VOID
563 NTAPI
564 FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq,
565  _Out_ PKIRQL Irql)
566 {
567  PFLT_MESSAGE_WAITER_QUEUE MessageWaiterQueue;
568 
570 
571  /* Get the start of the waiter queue struct */
572  MessageWaiterQueue = CONTAINING_RECORD(Csq,
574  Csq);
575 
576  /* Acquire the IRP queue lock */
577  ExAcquireFastMutex(&MessageWaiterQueue->WaiterQ.mLock);
578 }
579 
583 VOID
584 NTAPI
585 FltpReleaseMessageWaiterLock(_In_ PIO_CSQ Csq,
586  _In_ KIRQL Irql)
587 {
588  PFLT_MESSAGE_WAITER_QUEUE MessageWaiterQueue;
589 
591 
592  /* Get the start of the waiter queue struct */
593  MessageWaiterQueue = CONTAINING_RECORD(Csq,
595  Csq);
596 
597  /* Release the IRP queue lock */
598  ExReleaseFastMutex(&MessageWaiterQueue->WaiterQ.mLock);
599 }
600 
601 VOID
602 NTAPI
604  _In_ PIRP Irp)
605 {
606  /* Cancel the IRP */
607  Irp->IoStatus.Status = STATUS_CANCELLED;
608  Irp->IoStatus.Information = 0;
610 }
611 
612 
613 /* PRIVATE FUNCTIONS ******************************************************/
614 
615 static
616 NTSTATUS
618  _Inout_ PIRP Irp)
619 {
620  PFLT_SERVER_PORT_OBJECT ServerPortObject = NULL;
622  PFILTER_PORT_DATA FilterPortData;
623  PFLT_PORT_OBJECT ClientPortObject = NULL;
624  PFLT_PORT PortHandle = NULL;
625  PPORT_CCB PortCCB = NULL;
626  //ULONG BufferLength;
627  LONG NumConns;
629 
630  /* We received the buffer via FilterConnectCommunicationPort, cast it back to its original form */
631  FilterPortData = Irp->AssociatedIrp.SystemBuffer;
632 
633  /* Get a reference to the server port the filter created */
634  Status = ObReferenceObjectByName(&FilterPortData->PortName,
635  0,
636  0,
640  0,
641  (PVOID *)&ServerPortObject);
642  if (!NT_SUCCESS(Status))
643  {
644  return Status;
645  }
646 
647  /* Increment the number of connections on the server port */
648  NumConns = InterlockedIncrement(&ServerPortObject->NumberOfConnections);
649  if (NumConns > ServerPortObject->MaxConnections)
650  {
652  goto Quit;
653  }
654 
655  /* Initialize a basic kernel handle request */
657  NULL,
659  NULL,
660  NULL);
661 
662  /* Now create the new client port object */
666  KernelMode,
667  NULL,
668  sizeof(FLT_PORT_OBJECT),
669  0,
670  0,
671  (PVOID *)&ClientPortObject);
672  if (!NT_SUCCESS(Status))
673  {
674  goto Quit;
675  }
676 
677  /* Clear out the buffer */
678  RtlZeroMemory(ClientPortObject, sizeof(FLT_PORT_OBJECT));
679 
680  /* Initialize the locks */
681  ExInitializeRundownProtection(&ClientPortObject->MsgNotifRundownRef);
682  ExInitializeFastMutex(&ClientPortObject->Lock);
683 
684  /* Set the server port object this belongs to */
685  ClientPortObject->ServerPort = ServerPortObject;
686 
687  /* Setup the message queue */
688  Status = InitializeMessageWaiterQueue(&ClientPortObject->MsgQ);
689  if (!NT_SUCCESS(Status))
690  {
691  goto Quit;
692  }
693 
694  /* Create the CCB which we'll attach to the file object */
695  PortCCB = CreatePortCCB(ClientPortObject);
696  if (PortCCB == NULL)
697  {
699  goto Quit;
700  }
701 
702  /* Now insert the new client port into the object manager*/
703  Status = ObInsertObject(ClientPortObject, 0, FLT_PORT_ALL_ACCESS, 1, 0, (PHANDLE)&PortHandle);
704  if (!NT_SUCCESS(Status))
705  {
706  goto Quit;
707  }
708 
709  /* Add a reference to the filter to keep it alive while we do some work with it */
710  Status = FltObjectReference(ServerPortObject->Filter);
711  if (NT_SUCCESS(Status))
712  {
713  /* Invoke the callback to let the filter know we have a connection */
714  Status = ServerPortObject->ConnectNotify(PortHandle,
715  ServerPortObject->Cookie,
716  NULL, //ConnectionContext
717  0, //SizeOfContext
718  &ClientPortObject->Cookie);
719  if (NT_SUCCESS(Status))
720  {
721  /* Add the client port CCB to the file object */
722  FileObject->FsContext2 = PortCCB;
723 
724  /* Lock the port list on the filter and add this new port object to the list */
725  ExAcquireFastMutex(&ServerPortObject->Filter->PortList.mLock);
726  InsertTailList(&ServerPortObject->Filter->PortList.mList, &ClientPortObject->FilterLink);
727  ExReleaseFastMutex(&ServerPortObject->Filter->PortList.mLock);
728  }
729 
730  /* We're done with the filter object, decremement the count */
731  FltObjectDereference(ServerPortObject->Filter);
732  }
733 
734 
735 Quit:
736  if (!NT_SUCCESS(Status))
737  {
738  if (ClientPortObject)
739  {
740  ObDereferenceObject(ClientPortObject);
741  }
742 
743  if (PortHandle)
744  {
745  ZwClose(PortHandle);
746  }
747  else if (ServerPortObject)
748  {
749  InterlockedDecrement(&ServerPortObject->NumberOfConnections);
750  ObDereferenceObject(ServerPortObject);
751  }
752 
753  if (PortCCB)
754  {
755  ExFreePoolWithTag(PortCCB, FM_TAG_CCB);
756  }
757  }
758 
759  return Status;
760 }
761 
762 static
763 NTSTATUS
765  _Inout_ PIRP Irp)
766 {
767  PFLT_CCB Ccb;
768 
769  Ccb = (PFLT_CCB)FileObject->FsContext2;
770 
771  /* Remove the reference on the filter we added when we opened the port */
772  ObDereferenceObject(Ccb->Data.Port.Port);
773 
774  // FIXME: Free the CCB
775 
776  return STATUS_SUCCESS;
777 }
778 
779 static
780 NTSTATUS
782 {
784 
785  /* Setup the IRP queue */
786  Status = IoCsqInitializeEx(&MsgWaiterQueue->Csq,
790  FltpAcquireMessageWaiterLock,
791  FltpReleaseMessageWaiterLock,
793  if (!NT_SUCCESS(Status))
794  {
795  return Status;
796  }
797 
798  /* Initialize the waiter queue */
799  ExInitializeFastMutex(&MsgWaiterQueue->WaiterQ.mLock);
800  InitializeListHead(&MsgWaiterQueue->WaiterQ.mList);
801  MsgWaiterQueue->WaiterQ.mCount = 0;
802 
803  /* We don't have a minimum waiter length */
804  MsgWaiterQueue->MinimumWaiterLength = (ULONG)-1;
805 
806  /* Init the semaphore and event used for counting and signaling available IRPs */
807  KeInitializeSemaphore(&MsgWaiterQueue->Semaphore, 0, MAXLONG);
808  KeInitializeEvent(&MsgWaiterQueue->Event, NotificationEvent, FALSE);
809 
810  return STATUS_SUCCESS;
811 }
812 
813 static
814 PPORT_CCB
816 {
817  PPORT_CCB PortCCB;
818 
819  /* Allocate a CCB struct to hold the client port object info */
821  if (PortCCB)
822  {
823  /* Initialize the structure */
824  PortCCB->Port = PortObject;
825  PortCCB->ReplyWaiterList.mCount = 0;
828  }
829 
830  return PortCCB;
831 }
#define STATUS_CONNECTION_COUNT_LIMIT
Definition: ntstatus.h:700
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
CPPORT Port[4]
Definition: headless.c:34
#define FLT_PORT_ALL_ACCESS
Definition: fltkernel.h:836
NTSTATUS NTAPI ObCreateObjectType(IN PUNICODE_STRING TypeName, IN POBJECT_TYPE_INITIALIZER ObjectTypeInitializer, IN PVOID Reserved, OUT POBJECT_TYPE *ObjectType)
Definition: oblife.c:1048
#define GENERIC_ALL
Definition: nt_native.h:92
#define _Must_inspect_result_
Definition: no_sal2.h:314
#define TRUE
Definition: types.h:120
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
static BOOLEAN FltpDisconnectPort(_In_ PFLT_PORT_OBJECT PortObject)
Definition: Messaging.c:342
PIRP NTAPI FltpGetNextMessageWaiter(_In_ PIO_CSQ Csq, _In_ PIRP Irp, _In_ PVOID PeekContext)
Definition: Messaging.c:500
static NTSTATUS InitializeMessageWaiterQueue(_Inout_ PFLT_MESSAGE_WAITER_QUEUE MsgWaiterQueue)
Definition: Messaging.c:781
#define STANDARD_RIGHTS_WRITE
Definition: nt_native.h:66
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define MAXLONG
Definition: umtypes.h:116
VOID NTAPI FltpClientPortDelete(PVOID Object)
Definition: Messaging.c:369
_In_ PIRP Irp
Definition: csq.h:116
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
_Must_inspect_result_ _Outptr_ PFLT_PORT * ServerPort
Definition: fltkernel.h:1873
static PVOID Mapping[EMS_PHYSICAL_PAGES]
Definition: emsdrv.c:41
struct _FLT_PORT_OBJECT FLT_PORT_OBJECT
VOID FLTAPI FltObjectDereference(_Inout_ PVOID Object)
Definition: Object.c:53
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI FltpServerPortDelete(PVOID Object)
Definition: Messaging.c:317
PDEVICE_OBJECT CommsDeviceObject
Definition: Messaging.c:22
#define _Outptr_
Definition: no_sal2.h:396
#define OBJ_OPENLINK
Definition: winternl.h:230
LIST_ENTRY IrpQueue
Definition: csqrtns.c:49
_Outptr_ PFLT_PORT * ClientPort
Definition: fltkernel.h:1892
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:3066
NTSTATUS FltpMsgDispatch(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: Messaging.c:256
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
IRP
Definition: iotypes.h:2463
#define InsertTailList(ListHead, Entry)
#define STANDARD_RIGHTS_EXECUTE
Definition: nt_native.h:67
NTKERNELAPI VOID FASTCALL ExInitializeRundownProtection(_Out_ PEX_RUNDOWN_REF RunRef)
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
struct _OBJECT_TYPE_INITIALIZER OBJECT_TYPE_INITIALIZER
PFLT_PORT_OBJECT Port
Definition: fltmgrint.h:356
_Out_ PKIRQL Irql
Definition: csq.h:179
VOID FASTCALL ExReleaseFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:31
UNICODE_STRING CommsDeviceName
Definition: Messaging.c:21
NTSTATUS FltpMsgCreate(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: Messaging.c:223
#define _In_opt_
Definition: no_sal2.h:213
struct _FLT_PORT * PFLT_PORT
Definition: fltkernel.h:87
ULONG FltpObjectPointerReference(_In_ PFLT_OBJECT Object)
Definition: Object.c:322
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
_Must_inspect_result_ _In_ PFLT_PORT _In_ ULONG _Out_writes_bytes_opt_ ReplyLength PVOID _Inout_opt_ PULONG ReplyLength
Definition: fltkernel.h:1903
POBJECT_TYPE ClientPortObjectType
Definition: Messaging.c:25
UCHAR KIRQL
Definition: env_spec_w32.h:591
LIST_ENTRY mList
Definition: fltmgrint.h:56
VOID NTAPI FltpRemoveMessageWaiter(_In_ PIO_CSQ Csq, _In_ PIRP Irp)
Definition: Messaging.c:491
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
struct _FLT_PORT_OBJECT * PFLT_PORT_OBJECT
long LONG
Definition: pedump.c:60
_Must_inspect_result_ _In_opt_ PFLT_FILTER Filter
Definition: fltkernel.h:1802
#define FILE_READ_DATA
Definition: nt_native.h:628
struct _FLT_SERVER_PORT_OBJECT * PFLT_SERVER_PORT_OBJECT
struct NameRec_ * Name
Definition: cdprocs.h:464
unsigned char BOOLEAN
#define _Out_writes_bytes_opt_(a)
Definition: btrfs_drv.h:187
smooth NULL
Definition: ftsmooth.c:416
#define _Out_
Definition: no_sal2.h:323
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
#define IoCompleteRequest
Definition: irp.c:1240
VOID NTAPI FltpServerPortClose(_In_opt_ PEPROCESS Process, _In_ PVOID Object, _In_ ACCESS_MASK GrantedAccess, _In_ ULONG ProcessHandleCount, _In_ ULONG SystemHandleCount)
Definition: Messaging.c:289
OB_CLOSE_METHOD CloseProcedure
Definition: obtypes.h:368
VOID NTAPI FltpClientPortClose(_In_opt_ PEPROCESS Process, _In_ PVOID Object, _In_ ACCESS_MASK GrantedAccess, _In_ ULONG ProcessHandleCount, _In_ ULONG SystemHandleCount)
Definition: Messaging.c:327
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
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
NTSTATUS NTAPI ObCreateObject(IN KPROCESSOR_MODE ProbeMode OPTIONAL, IN POBJECT_TYPE Type, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN KPROCESSOR_MODE AccessMode, IN OUT PVOID ParseContext OPTIONAL, IN ULONG ObjectSize, IN ULONG PagedPoolCharge OPTIONAL, IN ULONG NonPagedPoolCharge OPTIONAL, OUT PVOID *Object)
Definition: oblife.c:952
_In_ PIRP _In_ PVOID InsertContext
Definition: csq.h:257
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
VOID NTAPI KeInitializeSemaphore(IN PKSEMAPHORE Semaphore, IN LONG Count, IN LONG Limit)
Definition: semphobj.c:22
#define _IRQL_requires_(irql)
Definition: no_sal2.h:649
POBJECT_TYPE ServerPortObjectType
Definition: Messaging.c:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
_Must_inspect_result_ _Outptr_ PFLT_PORT _In_ POBJECT_ATTRIBUTES _In_opt_ PVOID _In_ PFLT_CONNECT_NOTIFY _In_ PFLT_DISCONNECT_NOTIFY DisconnectNotifyCallback
Definition: fltkernel.h:1873
NTKERNELAPI NTSTATUS NTAPI IoCsqInitializeEx(_Out_ PIO_CSQ Csq, _In_ PIO_CSQ_INSERT_IRP_EX CsqInsertIrpEx, _In_ PIO_CSQ_REMOVE_IRP CsqRemoveIrp, _In_ PIO_CSQ_PEEK_NEXT_IRP CsqPeekNextIrp, _In_ PIO_CSQ_ACQUIRE_LOCK CsqAcquireLock, _In_ PIO_CSQ_RELEASE_LOCK CsqReleaseLock, _In_ PIO_CSQ_COMPLETE_CANCELED_IRP CsqCompleteCanceledIrp)
Set up a CSQ struct to initialize the queue (extended version)
Definition: csq.c:143
#define FM_TAG_CCB
Definition: fltmgr.h:21
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274
VOID NTAPI FltpCancelMessageWaiter(_In_ PIO_CSQ Csq, _In_ PIRP Irp)
Definition: Messaging.c:603
#define STATUS_CANCELLED
Definition: udferr_usr.h:170
NTSTATUS(FLTAPI * PFLT_MESSAGE_NOTIFY)(_In_opt_ PVOID PortCookie, _In_reads_bytes_opt_(InputBufferLength) PVOID InputBuffer, _In_ ULONG InputBufferLength, _Out_writes_bytes_to_opt_(OutputBufferLength, *ReturnOutputBufferLength) PVOID OutputBuffer, _In_ ULONG OutputBufferLength, _Out_ PULONG ReturnOutputBufferLength)
Definition: fltkernel.h:839
#define _Inout_
Definition: no_sal2.h:244
VOID FltpObjectPointerDereference(_In_ PFLT_OBJECT Object)
Definition: Object.c:335
* PFILE_OBJECT
Definition: iotypes.h:1955
struct _FLT_CCB * PFLT_CCB
static IUnknown Object
Definition: main.c:512
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
_Must_inspect_result_ _In_ PFLT_PORT _In_ ULONG _Out_writes_bytes_opt_ ReplyLength PVOID ReplyBuffer
Definition: fltkernel.h:1903
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
static const WCHAR L[]
Definition: oid.c:1250
#define InterlockedDecrement
Definition: armddk.h:52
static PPORT_CCB CreatePortCCB(_In_ PFLT_PORT_OBJECT PortObject)
Definition: Messaging.c:815
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:414
KIRQL * PKIRQL
Definition: env_spec_w32.h:592
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:593
Definition: typedefs.h:117
#define FILE_DEVICE_WPD
IN OUT PLONG IN OUT PLONG Addend IN OUT PLONG IN LONG IN OUT PLONG IN LONG Increment IN PNDIS_RW_LOCK Lock
Definition: CrNtStubs.h:75
FLT_MUTEX_LIST_HEAD ReplyWaiterList
Definition: fltmgrint.h:357
#define STANDARD_RIGHTS_READ
Definition: nt_native.h:65
_Must_inspect_result_ _IRQL_requires_max_(PASSIVE_LEVEL)
Definition: Messaging.c:64
#define SYNCHRONIZE
Definition: nt_native.h:61
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
_Must_inspect_result_ _Outptr_ PFLT_PORT _In_ POBJECT_ATTRIBUTES _In_opt_ PVOID _In_ PFLT_CONNECT_NOTIFY ConnectNotifyCallback
Definition: fltkernel.h:1873
#define _In_reads_bytes_(size)
Definition: no_sal2.h:229
Status
Definition: gdiplustypes.h:24
FLT_MUTEX_LIST_HEAD WaiterQ
Definition: fltmgrint.h:206
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
NTSTATUS(FLTAPI * PFLT_CONNECT_NOTIFY)(_In_ PFLT_PORT ClientPort, _In_opt_ PVOID ServerPortCookie, _In_reads_bytes_opt_(SizeOfContext) PVOID ConnectionContext, _In_ ULONG SizeOfContext, _Outptr_result_maybenull_ PVOID *ConnectionPortCookie)
Definition: fltkernel.h:848
#define _In_
Definition: no_sal2.h:204
Definition: csq.h:222
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
#define _IRQL_restores_global_(kind, param)
Definition: no_sal2.h:654
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
* PFAST_MUTEX
Definition: extypes.h:17
NTSTATUS NTAPI ObInsertObject(IN PVOID Object, IN PACCESS_STATE AccessState OPTIONAL, IN ACCESS_MASK DesiredAccess, IN ULONG ObjectPointerBias, OUT PVOID *NewObject OPTIONAL, OUT PHANDLE Handle)
Definition: obhandle.c:2932
static ULONG Timeout
Definition: ping.c:61
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
GENERIC_MAPPING GenericMapping
Definition: obtypes.h:358
NTSTATUS FltpSetupCommunicationObjects(_In_ PDRIVER_OBJECT DriverObject)
Definition: Messaging.c:377
#define InterlockedIncrement
Definition: armddk.h:53
#define STANDARD_RIGHTS_ALL
Definition: nt_native.h:69
VOID FASTCALL ExAcquireFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:23
NTSTATUS FLTAPI FltObjectReference(_Inout_ PVOID Object)
Definition: Object.c:41
#define _IRQL_saves_global_(kind, param)
Definition: no_sal2.h:656
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
_Must_inspect_result_ _In_ PFLT_PORT _In_ ULONG SenderBufferLength
Definition: fltkernel.h:1902
_Must_inspect_result_ _Outptr_ PFLT_PORT _In_ POBJECT_ATTRIBUTES _In_opt_ PVOID ServerPortCookie
Definition: fltkernel.h:1873
unsigned int * PULONG
Definition: retypes.h:1
VOID(FLTAPI * PFLT_DISCONNECT_NOTIFY)(_In_opt_ PVOID ConnectionCookie)
Definition: fltkernel.h:856
_In_opt_ PIRP _In_opt_ PVOID PeekContext
Definition: csq.h:159
_Acquires_lock_(((PFLT_MESSAGE_WAITER_QUEUE) CONTAINING_RECORD(Csq, FLT_MESSAGE_WAITER_QUEUE, Csq)) ->WaiterQ.mLock) _IRQL_saves_global_(Irql
IO_CSQ Csq
Definition: csqrtns.c:46
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
FAST_MUTEX mLock
Definition: fltmgrint.h:55
struct _FLT_SERVER_PORT_OBJECT FLT_SERVER_PORT_OBJECT
UNICODE_STRING PortName
Definition: fltmgr_shared.h:28
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:566
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
_Must_inspect_result_ _Outptr_ PFLT_PORT _In_ POBJECT_ATTRIBUTES _In_opt_ PVOID _In_ PFLT_CONNECT_NOTIFY _In_ PFLT_DISCONNECT_NOTIFY _In_opt_ PFLT_MESSAGE_NOTIFY _In_ LONG MaxConnections
Definition: fltkernel.h:1873
static NTSTATUS CloseClientPort(_In_ PFILE_OBJECT FileObject, _Inout_ PIRP Irp)
Definition: Messaging.c:764
static NTSTATUS CreateClientPort(_In_ PFILE_OBJECT FileObject, _Inout_ PIRP Irp)
Definition: Messaging.c:617
#define _IRQL_raises_(irql)
Definition: no_sal2.h:648
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
_Releases_lock_(((PFLT_MESSAGE_WAITER_QUEUE) CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) ->WaiterQ.mLock) _IRQL_restores_global_(Irql
_In_ PSECURITY_SUBJECT_CONTEXT _In_ BOOLEAN _In_ ACCESS_MASK _In_ ACCESS_MASK _Outptr_opt_ PPRIVILEGE_SET _In_ PGENERIC_MAPPING _In_ KPROCESSOR_MODE _Out_ PACCESS_MASK GrantedAccess
Definition: sefuncs.h:13
return STATUS_SUCCESS
Definition: btrfs.c:2966
OB_DELETE_METHOD DeleteProcedure
Definition: obtypes.h:369
NTSTATUS NTAPI ObReferenceObjectByName(IN PUNICODE_STRING ObjectPath, IN ULONG Attributes, IN PACCESS_STATE PassedAccessState, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, IN OUT PVOID ParseContext, OUT PVOID *ObjectPtr)
Definition: obref.c:411
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define APC_LEVEL
Definition: env_spec_w32.h:695
_Must_inspect_result_ _Outptr_ PFLT_PORT _In_ POBJECT_ATTRIBUTES _In_opt_ PVOID _In_ PFLT_CONNECT_NOTIFY _In_ PFLT_DISCONNECT_NOTIFY _In_opt_ PFLT_MESSAGE_NOTIFY MessageNotifyCallback
Definition: fltkernel.h:1873
ULONG DefaultNonPagedPoolCharge
Definition: obtypes.h:365
ULONG ACCESS_MASK
Definition: nt_native.h:40
EX_PUSH_LOCK PortLock
Definition: fltmgrint.h:123
NTSTATUS NTAPI FltpAddMessageWaiter(_In_ PIO_CSQ Csq, _In_ PIRP Irp, _In_ PVOID InsertContext)
Definition: Messaging.c:470
PFLT_SERVER_PORT_OBJECT ServerPort
Definition: fltmgrint.h:217
FLT_MUTEX_LIST_HEAD ConnectionList
Definition: fltmgrint.h:121
#define _Inout_opt_
Definition: no_sal2.h:258
#define FLT_ASSERT(_e)
Definition: fltkernel.h:49
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
VOID NTAPI ObMakeTemporaryObject(IN PVOID ObjectBody)
Definition: oblife.c:1361