ReactOS 0.4.15-dev-7788-g1ad9096
Messaging.c File Reference
#include "fltmgr.h"
#include "fltmgrint.h"
#include <fltmgr_shared.h>
#include <debug.h>
Include dependency graph for Messaging.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

static BOOLEAN FltpDisconnectPort (_In_ PFLT_PORT_OBJECT PortObject)
 
static NTSTATUS CreateClientPort (_In_ PFILE_OBJECT FileObject, _Inout_ PIRP Irp)
 
static NTSTATUS CloseClientPort (_In_ PFILE_OBJECT FileObject, _Inout_ PIRP Irp)
 
static NTSTATUS InitializeMessageWaiterQueue (_Inout_ PFLT_MESSAGE_WAITER_QUEUE MsgWaiterQueue)
 
static PPORT_CCB CreatePortCCB (_In_ PFLT_PORT_OBJECT PortObject)
 
_Must_inspect_result_ _IRQL_requires_max_ (PASSIVE_LEVEL)
 
_Must_inspect_result_ _IRQL_requires_max_ (APC_LEVEL)
 
NTSTATUS FltpMsgCreate (_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
 
NTSTATUS FltpMsgDispatch (_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
 
VOID NTAPI FltpServerPortClose (_In_opt_ PEPROCESS Process, _In_ PVOID Object, _In_ ACCESS_MASK GrantedAccess, _In_ ULONG ProcessHandleCount, _In_ ULONG SystemHandleCount)
 
VOID NTAPI FltpServerPortDelete (PVOID Object)
 
VOID NTAPI FltpClientPortClose (_In_opt_ PEPROCESS Process, _In_ PVOID Object, _In_ ACCESS_MASK GrantedAccess, _In_ ULONG ProcessHandleCount, _In_ ULONG SystemHandleCount)
 
VOID NTAPI FltpClientPortDelete (PVOID Object)
 
NTSTATUS FltpSetupCommunicationObjects (_In_ PDRIVER_OBJECT DriverObject)
 
NTSTATUS NTAPI FltpAddMessageWaiter (_In_ PIO_CSQ Csq, _In_ PIRP Irp, _In_ PVOID InsertContext)
 
VOID NTAPI FltpRemoveMessageWaiter (_In_ PIO_CSQ Csq, _In_ PIRP Irp)
 
PIRP NTAPI FltpGetNextMessageWaiter (_In_ PIO_CSQ Csq, _In_ PIRP Irp, _In_ PVOID PeekContext)
 
 _Acquires_lock_ (((PFLT_MESSAGE_WAITER_QUEUE) CONTAINING_RECORD(Csq, FLT_MESSAGE_WAITER_QUEUE, Csq)) ->WaiterQ.mLock) _IRQL_saves_global_(Irql
 
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)
 
 _Releases_lock_ (((PFLT_MESSAGE_WAITER_QUEUE) CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) ->WaiterQ.mLock) _IRQL_restores_global_(Irql
 
VOID NTAPI FltpCancelMessageWaiter (_In_ PIO_CSQ Csq, _In_ PIRP Irp)
 

Variables

UNICODE_STRING CommsDeviceName = RTL_CONSTANT_STRING(L"\\FileSystem\\Filters\\FltMgrMsg")
 
PDEVICE_OBJECT CommsDeviceObject
 
POBJECT_TYPE ServerPortObjectType
 
POBJECT_TYPE ClientPortObjectType
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 15 of file Messaging.c.

Function Documentation

◆ _Acquires_lock_()

_Acquires_lock_ ( ((PFLT_MESSAGE_WAITER_QUEUE) CONTAINING_RECORD(Csq, FLT_MESSAGE_WAITER_QUEUE, Csq)) ->WaiterQ.  mLock)

◆ _IRQL_requires_max_() [1/2]

_Must_inspect_result_ _IRQL_requires_max_ ( APC_LEVEL  )

Definition at line 198 of file Messaging.c.

208{
211 UNREFERENCED_PARAMETER(SenderBuffer);
217}
_Must_inspect_result_ _In_ PFLT_PORT _In_ ULONG SenderBufferLength
Definition: fltkernel.h:1901
_Outptr_ PFLT_PORT * ClientPort
Definition: fltkernel.h:1891
_Must_inspect_result_ _In_ PFLT_PORT _In_ ULONG _Out_writes_bytes_opt_ ReplyLength PVOID ReplyBuffer
Definition: fltkernel.h:1902
_Must_inspect_result_ _In_opt_ PFLT_FILTER Filter
Definition: fltkernel.h:1801
_Must_inspect_result_ _In_ PFLT_PORT _In_ ULONG _Out_writes_bytes_opt_ ReplyLength PVOID _Inout_opt_ PULONG ReplyLength
Definition: fltkernel.h:1903
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:239
static ULONG Timeout
Definition: ping.c:61

◆ _IRQL_requires_max_() [2/2]

_Must_inspect_result_ _IRQL_requires_max_ ( PASSIVE_LEVEL  )

Definition at line 64 of file Messaging.c.

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 */
107 NULL,
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;
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 */
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}
static const INTERNET_PORT ServerPort
Definition: CWebService.cpp:11
POBJECT_TYPE ServerPortObjectType
Definition: Messaging.c:24
VOID FLTAPI FltObjectDereference(_Inout_ PVOID Object)
Definition: Object.c:53
NTSTATUS FLTAPI FltObjectReference(_Inout_ PVOID Object)
Definition: Object.c:41
LONG NTSTATUS
Definition: precomp.h:26
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define InsertTailList(ListHead, Entry)
_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:1877
_Must_inspect_result_ _Outptr_ PFLT_PORT _In_ POBJECT_ATTRIBUTES _In_opt_ PVOID _In_ PFLT_CONNECT_NOTIFY ConnectNotifyCallback
Definition: fltkernel.h:1875
_Must_inspect_result_ _Outptr_ PFLT_PORT _In_ POBJECT_ATTRIBUTES _In_opt_ PVOID ServerPortCookie
Definition: fltkernel.h:1874
_Must_inspect_result_ _Outptr_ PFLT_PORT _In_ POBJECT_ATTRIBUTES _In_opt_ PVOID _In_ PFLT_CONNECT_NOTIFY _In_ PFLT_DISCONNECT_NOTIFY DisconnectNotifyCallback
Definition: fltkernel.h:1876
ULONG FltpObjectPointerReference(_In_ PFLT_OBJECT Object)
Definition: Object.c:322
Status
Definition: gdiplustypes.h:25
VOID FASTCALL ExAcquireFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:23
VOID FASTCALL ExReleaseFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:31
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
static LONG MaxConnections
#define KernelMode
Definition: asm.h:34
#define FILE_READ_DATA
Definition: nt_native.h:628
#define STANDARD_RIGHTS_ALL
Definition: nt_native.h:69
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:455
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:2935
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:1039
FLT_MUTEX_LIST_HEAD ConnectionList
Definition: fltmgrint.h:121
LIST_ENTRY mList
Definition: fltmgrint.h:56
FAST_MUTEX mLock
Definition: fltmgrint.h:55
PFLT_DISCONNECT_NOTIFY DisconnectNotify
Definition: fltmgrint.h:192
PFLT_MESSAGE_NOTIFY MessageNotify
Definition: fltmgrint.h:193
PFLT_CONNECT_NOTIFY ConnectNotify
Definition: fltmgrint.h:191
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135

◆ _Releases_lock_()

_Releases_lock_ ( ((PFLT_MESSAGE_WAITER_QUEUE) CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) ->WaiterQ.  mLock)

◆ CloseClientPort()

static NTSTATUS CloseClientPort ( _In_ PFILE_OBJECT  FileObject,
_Inout_ PIRP  Irp 
)
static

Definition at line 766 of file Messaging.c.

768{
770
771 Ccb = (PFLT_CCB)FileObject->FsContext2;
772
773 /* Remove the reference on the filter we added when we opened the port */
774 ObDereferenceObject(Ccb->Data.Port.Port);
775
776 // FIXME: Free the CCB
777
778 return STATUS_SUCCESS;
779}
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:592
struct _FLT_CCB * PFLT_CCB
#define STATUS_SUCCESS
Definition: shellext.h:65
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:550
#define ObDereferenceObject
Definition: obfuncs.h:203

Referenced by FltpMsgDispatch().

◆ CONTAINING_RECORD()

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 at line 560 of file Messaging.c.

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}
_Out_ PKIRQL Irql
Definition: csq.h:179
IO_CSQ Csq
Definition: csqrtns.c:46
FLT_MUTEX_LIST_HEAD WaiterQ
Definition: fltmgrint.h:206
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260

◆ CreateClientPort()

static NTSTATUS CreateClientPort ( _In_ PFILE_OBJECT  FileObject,
_Inout_ PIRP  Irp 
)
static

Definition at line 617 of file Messaging.c.

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 */
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 */
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, NULL, FLT_PORT_ALL_ACCESS, 1, NULL, (PHANDLE)&PortHandle);
704 if (!NT_SUCCESS(Status))
705 {
706 /* ObInsertObject() failed and already dereferenced ClientPortObject */
707 ClientPortObject = NULL;
708 goto Quit;
709 }
710
711 /* Add a reference to the filter to keep it alive while we do some work with it */
712 Status = FltObjectReference(ServerPortObject->Filter);
713 if (NT_SUCCESS(Status))
714 {
715 /* Invoke the callback to let the filter know we have a connection */
716 Status = ServerPortObject->ConnectNotify(PortHandle,
717 ServerPortObject->Cookie,
718 NULL, //ConnectionContext
719 0, //SizeOfContext
720 &ClientPortObject->Cookie);
721 if (NT_SUCCESS(Status))
722 {
723 /* Add the client port CCB to the file object */
724 FileObject->FsContext2 = PortCCB;
725
726 /* Lock the port list on the filter and add this new port object to the list */
727 ExAcquireFastMutex(&ServerPortObject->Filter->PortList.mLock);
728 InsertTailList(&ServerPortObject->Filter->PortList.mList, &ClientPortObject->FilterLink);
729 ExReleaseFastMutex(&ServerPortObject->Filter->PortList.mLock);
730 }
731
732 /* We're done with the filter object, decremement the count */
733 FltObjectDereference(ServerPortObject->Filter);
734 }
735
736
737Quit:
738 if (!NT_SUCCESS(Status))
739 {
740 if (ClientPortObject)
741 {
742 ObDereferenceObject(ClientPortObject);
743 }
744
745 if (PortHandle)
746 {
747 ZwClose(PortHandle);
748 }
749 else if (ServerPortObject)
750 {
751 InterlockedDecrement(&ServerPortObject->NumberOfConnections);
752 ObDereferenceObject(ServerPortObject);
753 }
754
755 if (PortCCB)
756 {
758 }
759 }
760
761 return Status;
762}
POBJECT_TYPE ClientPortObjectType
Definition: Messaging.c:25
static PPORT_CCB CreatePortCCB(_In_ PFLT_PORT_OBJECT PortObject)
Definition: Messaging.c:817
static NTSTATUS InitializeMessageWaiterQueue(_Inout_ PFLT_MESSAGE_WAITER_QUEUE MsgWaiterQueue)
Definition: Messaging.c:783
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
_In_ PIRP Irp
Definition: csq.h:116
#define ExGetPreviousMode
Definition: ex.h:140
#define ExInitializeRundownProtection
Definition: ex.h:137
#define FLT_PORT_ALL_ACCESS
Definition: fltkernel.h:836
struct _FLT_PORT * PFLT_PORT
Definition: fltkernel.h:87
#define FM_TAG_CCB
Definition: fltmgr.h:23
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
#define STATUS_CONNECTION_COUNT_LIMIT
Definition: ntstatus.h:714
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:409
long LONG
Definition: pedump.c:60
UNICODE_STRING PortName
Definition: fltmgr_shared.h:28
FLT_MUTEX_LIST_HEAD PortList
Definition: fltmgrint.h:122
EX_RUNDOWN_REF MsgNotifRundownRef
Definition: fltmgrint.h:219
PFLT_SERVER_PORT_OBJECT ServerPort
Definition: fltmgrint.h:217
FLT_MESSAGE_WAITER_QUEUE MsgQ
Definition: fltmgrint.h:221
LIST_ENTRY FilterLink
Definition: fltmgrint.h:216
FAST_MUTEX Lock
Definition: fltmgrint.h:220
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274

Referenced by FltpMsgCreate().

◆ CreatePortCCB()

static PPORT_CCB CreatePortCCB ( _In_ PFLT_PORT_OBJECT  PortObject)
static

Definition at line 817 of file Messaging.c.

818{
819 PPORT_CCB PortCCB;
820
821 /* Allocate a CCB struct to hold the client port object info */
823 if (PortCCB)
824 {
825 /* Initialize the structure */
826 PortCCB->Port = PortObject;
827 PortCCB->ReplyWaiterList.mCount = 0;
830 }
831
832 return PortCCB;
833}
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define NonPagedPool
Definition: env_spec_w32.h:307
@ SynchronizationEvent
PFLT_PORT_OBJECT Port
Definition: fltmgrint.h:356
FLT_MUTEX_LIST_HEAD ReplyWaiterList
Definition: fltmgrint.h:357

Referenced by CreateClientPort().

◆ FltpAddMessageWaiter()

NTSTATUS NTAPI FltpAddMessageWaiter ( _In_ PIO_CSQ  Csq,
_In_ PIRP  Irp,
_In_ PVOID  InsertContext 
)

Definition at line 470 of file Messaging.c.

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}

Referenced by InitializeMessageWaiterQueue().

◆ FltpCancelMessageWaiter()

VOID NTAPI FltpCancelMessageWaiter ( _In_ PIO_CSQ  Csq,
_In_ PIRP  Irp 
)

Definition at line 603 of file Messaging.c.

605{
606 /* Cancel the IRP */
607 Irp->IoStatus.Status = STATUS_CANCELLED;
608 Irp->IoStatus.Information = 0;
610}
#define IoCompleteRequest
Definition: irp.c:1240
#define STATUS_CANCELLED
Definition: udferr_usr.h:170
#define IO_NO_INCREMENT
Definition: iotypes.h:598

Referenced by InitializeMessageWaiterQueue().

◆ FltpClientPortClose()

VOID NTAPI FltpClientPortClose ( _In_opt_ PEPROCESS  Process,
_In_ PVOID  Object,
_In_ ACCESS_MASK  GrantedAccess,
_In_ ULONG  ProcessHandleCount,
_In_ ULONG  SystemHandleCount 
)

Definition at line 327 of file Messaging.c.

332{
334
335 if (FltpDisconnectPort(PortObject))
336 {
338 }
339}
static BOOLEAN FltpDisconnectPort(_In_ PFLT_PORT_OBJECT PortObject)
Definition: Messaging.c:342
struct _FLT_PORT_OBJECT * PFLT_PORT_OBJECT
_Must_inspect_result_ _In_ WDFCOLLECTION _In_ WDFOBJECT Object

Referenced by FltpSetupCommunicationObjects().

◆ FltpClientPortDelete()

VOID NTAPI FltpClientPortDelete ( PVOID  Object)

Definition at line 369 of file Messaging.c.

370{
372 ObDereferenceObject(PortObject->ServerPort);
373}

Referenced by FltpSetupCommunicationObjects().

◆ FltpDisconnectPort()

BOOLEAN FltpDisconnectPort ( _In_ PFLT_PORT_OBJECT  PortObject)
static

Definition at line 342 of file Messaging.c.

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}
unsigned char BOOLEAN
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476

Referenced by FltpClientPortClose().

◆ FltpGetNextMessageWaiter()

PIRP NTAPI FltpGetNextMessageWaiter ( _In_ PIO_CSQ  Csq,
_In_ PIRP  Irp,
_In_ PVOID  PeekContext 
)

Definition at line 500 of file Messaging.c.

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}
_In_opt_ PIRP _In_opt_ PVOID PeekContext
Definition: csq.h:160
PFILE_OBJECT FileObject
Definition: iotypes.h:3169
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2793
* PFILE_OBJECT
Definition: iotypes.h:1998

Referenced by InitializeMessageWaiterQueue().

◆ FltpMsgCreate()

NTSTATUS FltpMsgCreate ( _In_ PDEVICE_OBJECT  DeviceObject,
_Inout_ PIRP  Irp 
)

Definition at line 223 of file Messaging.c.

225{
226 PIO_STACK_LOCATION StackPtr;
228
229 /* Get the stack location */
231
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 */
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}
static NTSTATUS CreateClientPort(_In_ PFILE_OBJECT FileObject, _Inout_ PIRP Irp)
Definition: Messaging.c:617
#define FLT_ASSERT(_e)
Definition: fltkernel.h:49
#define STATUS_PENDING
Definition: ntstatus.h:82
#define IRP_MJ_CREATE
Definition: rdpdr.c:44

Referenced by FltpCreate().

◆ FltpMsgDispatch()

NTSTATUS FltpMsgDispatch ( _In_ PDEVICE_OBJECT  DeviceObject,
_Inout_ PIRP  Irp 
)

Definition at line 256 of file Messaging.c.

258{
259 PIO_STACK_LOCATION StackPtr;
261
262 /* Get the stack location */
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}
static NTSTATUS CloseClientPort(_In_ PFILE_OBJECT FileObject, _Inout_ PIRP Irp)
Definition: Messaging.c:766
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45

Referenced by FltpDispatch().

◆ FltpRemoveMessageWaiter()

VOID NTAPI FltpRemoveMessageWaiter ( _In_ PIO_CSQ  Csq,
_In_ PIRP  Irp 
)

Definition at line 491 of file Messaging.c.

493{
494 /* Remove the IRP from the queue */
495 RemoveEntryList(&Irp->Tail.Overlay.ListEntry);
496}
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986

Referenced by InitializeMessageWaiterQueue().

◆ FltpServerPortClose()

VOID NTAPI FltpServerPortClose ( _In_opt_ PEPROCESS  Process,
_In_ PVOID  Object,
_In_ ACCESS_MASK  GrantedAccess,
_In_ ULONG  ProcessHandleCount,
_In_ ULONG  SystemHandleCount 
)

Definition at line 289 of file Messaging.c.

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}
struct _FLT_SERVER_PORT_OBJECT * PFLT_SERVER_PORT_OBJECT
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWAITLOCK * Lock
Definition: wdfsync.h:127
* PFAST_MUTEX
Definition: extypes.h:17

Referenced by FltpSetupCommunicationObjects().

◆ FltpServerPortDelete()

VOID NTAPI FltpServerPortDelete ( PVOID  Object)

Definition at line 317 of file Messaging.c.

318{
319 /* Decrement the filter count we added in the create routine */
322
323}
VOID FltpObjectPointerDereference(_In_ PFLT_OBJECT Object)
Definition: Object.c:335

Referenced by FltpSetupCommunicationObjects().

◆ FltpSetupCommunicationObjects()

NTSTATUS FltpSetupCommunicationObjects ( _In_ PDRIVER_OBJECT  DriverObject)

Definition at line 377 of file Messaging.c.

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");
436 }
437
438Quit:
439 if (!NT_SUCCESS(Status))
440 {
441 /* Something went wrong, undo */
443 {
446 }
448 {
452 }
453
455 {
459 }
460 }
461
462 return Status;
463}
VOID NTAPI FltpServerPortDelete(PVOID Object)
Definition: Messaging.c:317
UNICODE_STRING CommsDeviceName
Definition: Messaging.c:21
PDEVICE_OBJECT CommsDeviceObject
Definition: Messaging.c:22
VOID NTAPI FltpClientPortDelete(PVOID Object)
Definition: Messaging.c:369
VOID NTAPI FltpServerPortClose(_In_opt_ PEPROCESS Process, _In_ PVOID Object, _In_ ACCESS_MASK GrantedAccess, _In_ ULONG ProcessHandleCount, _In_ ULONG SystemHandleCount)
Definition: Messaging.c:289
VOID NTAPI FltpClientPortClose(_In_opt_ PEPROCESS Process, _In_ PVOID Object, _In_ ACCESS_MASK GrantedAccess, _In_ ULONG ProcessHandleCount, _In_ ULONG SystemHandleCount)
Definition: Messaging.c:327
struct NameRec_ * Name
Definition: cdprocs.h:460
static PVOID Mapping[EMS_PHYSICAL_PAGES]
Definition: emsdrv.c:41
struct _FLT_SERVER_PORT_OBJECT FLT_SERVER_PORT_OBJECT
struct _FLT_PORT_OBJECT FLT_PORT_OBJECT
#define OBJ_OPENLINK
Definition: winternl.h:230
struct _OBJECT_TYPE_INITIALIZER OBJECT_TYPE_INITIALIZER
#define SYNCHRONIZE
Definition: nt_native.h:61
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define STANDARD_RIGHTS_READ
Definition: nt_native.h:65
#define STANDARD_RIGHTS_WRITE
Definition: nt_native.h:66
#define GENERIC_ALL
Definition: nt_native.h:92
#define STANDARD_RIGHTS_EXECUTE
Definition: nt_native.h:67
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
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
#define L(x)
Definition: ntvdm.h:50
NTSTATUS NTAPI ObCreateObjectType(IN PUNICODE_STRING TypeName, IN POBJECT_TYPE_INITIALIZER ObjectTypeInitializer, IN PVOID Reserved, OUT POBJECT_TYPE *ObjectType)
Definition: oblife.c:1136
VOID NTAPI ObMakeTemporaryObject(IN PVOID ObjectBody)
Definition: oblife.c:1449
#define FILE_DEVICE_WPD
Definition: winioctl.h:168
OB_CLOSE_METHOD CloseProcedure
Definition: obtypes.h:368
GENERIC_MAPPING GenericMapping
Definition: obtypes.h:358
OB_DELETE_METHOD DeleteProcedure
Definition: obtypes.h:369
ULONG DefaultNonPagedPoolCharge
Definition: obtypes.h:365
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213

Referenced by CODE_SEG().

◆ InitializeMessageWaiterQueue()

static NTSTATUS InitializeMessageWaiterQueue ( _Inout_ PFLT_MESSAGE_WAITER_QUEUE  MsgWaiterQueue)
static

Definition at line 783 of file Messaging.c.

784{
786
787 /* Setup the IRP queue */
788 Status = IoCsqInitializeEx(&MsgWaiterQueue->Csq,
792 FltpAcquireMessageWaiterLock,
793 FltpReleaseMessageWaiterLock,
795 if (!NT_SUCCESS(Status))
796 {
797 return Status;
798 }
799
800 /* Initialize the waiter queue */
801 ExInitializeFastMutex(&MsgWaiterQueue->WaiterQ.mLock);
802 InitializeListHead(&MsgWaiterQueue->WaiterQ.mList);
803 MsgWaiterQueue->WaiterQ.mCount = 0;
804
805 /* We don't have a minimum waiter length */
806 MsgWaiterQueue->MinimumWaiterLength = (ULONG)-1;
807
808 /* Init the semaphore and event used for counting and signaling available IRPs */
809 KeInitializeSemaphore(&MsgWaiterQueue->Semaphore, 0, MAXLONG);
810 KeInitializeEvent(&MsgWaiterQueue->Event, NotificationEvent, FALSE);
811
812 return STATUS_SUCCESS;
813}
NTSTATUS NTAPI FltpAddMessageWaiter(_In_ PIO_CSQ Csq, _In_ PIRP Irp, _In_ PVOID InsertContext)
Definition: Messaging.c:470
PIRP NTAPI FltpGetNextMessageWaiter(_In_ PIO_CSQ Csq, _In_ PIRP Irp, _In_ PVOID PeekContext)
Definition: Messaging.c:500
VOID NTAPI FltpRemoveMessageWaiter(_In_ PIO_CSQ Csq, _In_ PIRP Irp)
Definition: Messaging.c:491
VOID NTAPI FltpCancelMessageWaiter(_In_ PIO_CSQ Csq, _In_ PIRP Irp)
Definition: Messaging.c:603
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 InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
@ NotificationEvent
VOID NTAPI KeInitializeSemaphore(IN PKSEMAPHORE Semaphore, IN LONG Count, IN LONG Limit)
Definition: semphobj.c:22
uint32_t ULONG
Definition: typedefs.h:59
#define MAXLONG
Definition: umtypes.h:116

Referenced by CreateClientPort().

Variable Documentation

◆ ClientPortObjectType

POBJECT_TYPE ClientPortObjectType

Definition at line 25 of file Messaging.c.

Referenced by CreateClientPort(), and FltpSetupCommunicationObjects().

◆ CommsDeviceName

UNICODE_STRING CommsDeviceName = RTL_CONSTANT_STRING(L"\\FileSystem\\Filters\\FltMgrMsg")

Definition at line 21 of file Messaging.c.

Referenced by FltpSetupCommunicationObjects().

◆ CommsDeviceObject

PDEVICE_OBJECT CommsDeviceObject

Definition at line 22 of file Messaging.c.

Referenced by FltpCreate(), FltpDispatch(), and FltpSetupCommunicationObjects().

◆ ServerPortObjectType

POBJECT_TYPE ServerPortObjectType