ReactOS  0.4.13-dev-92-gf251225
lpc.h File Reference
#include "lpc_x.h"
Include dependency graph for lpc.h:

Go to the source code of this file.

Classes

struct  _LPCP_DATA_INFO
 

Macros

#define _LPC_DEBUG_   0x00
 
#define LPC_CREATE_DEBUG   0x01
 
#define LPC_CLOSE_DEBUG   0x02
 
#define LPC_CONNECT_DEBUG   0x04
 
#define LPC_LISTEN_DEBUG   0x08
 
#define LPC_REPLY_DEBUG   0x10
 
#define LPC_COMPLETE_DEBUG   0x20
 
#define LPC_SEND_DEBUG   0x40
 
#define LPCTRACE(x, fmt, ...)   DPRINT(fmt, ##__VA_ARGS__)
 
#define LPCP_THREAD_FLAG_IS_PORT   1
 
#define LPCP_THREAD_FLAG_NO_IMPERSONATION   2
 
#define LPCP_THREAD_FLAGS
 
#define LPCP_LOCK_HELD   1
 
#define LPCP_LOCK_RELEASE   2
 

Typedefs

typedef struct _LPCP_DATA_INFO LPCP_DATA_INFO
 
typedef struct _LPCP_DATA_INFOPLPCP_DATA_INFO
 

Functions

VOID NTAPI LpcpClosePort (IN PEPROCESS Process OPTIONAL, IN PVOID Object, IN ACCESS_MASK GrantedAccess, IN ULONG ProcessHandleCount, IN ULONG SystemHandleCount)
 
VOID NTAPI LpcpDeletePort (IN PVOID ObjectBody)
 
NTSTATUS NTAPI LpcpInitializePortQueue (IN PLPCP_PORT_OBJECT Port)
 
VOID NTAPI LpcpFreeToPortZone (IN PLPCP_MESSAGE Message, IN ULONG LockFlags)
 
VOID NTAPI LpcpMoveMessage (IN PPORT_MESSAGE Destination, IN PPORT_MESSAGE Origin, IN PVOID Data, IN ULONG MessageType, IN PCLIENT_ID ClientId)
 
VOID NTAPI LpcpSaveDataInfoMessage (IN PLPCP_PORT_OBJECT Port, IN PLPCP_MESSAGE Message, IN ULONG LockFlags)
 
VOID NTAPI LpcExitThread (IN PETHREAD Thread)
 
INIT_FUNCTION BOOLEAN NTAPI LpcInitSystem (VOID)
 
BOOLEAN NTAPI LpcpValidateClientPort (PETHREAD ClientThread, PLPCP_PORT_OBJECT Port)
 

Variables

POBJECT_TYPE LpcPortObjectType
 
ULONG LpcpNextMessageId
 
ULONG LpcpNextCallbackId
 
KGUARDED_MUTEX LpcpLock
 
PAGED_LOOKASIDE_LIST LpcpMessagesLookaside
 
ULONG LpcpMaxMessageSize
 
ULONG LpcpTraceLevel
 

Macro Definition Documentation

◆ _LPC_DEBUG_

#define _LPC_DEBUG_   0x00

Definition at line 12 of file lpc.h.

◆ LPC_CLOSE_DEBUG

#define LPC_CLOSE_DEBUG   0x02

Definition at line 18 of file lpc.h.

◆ LPC_COMPLETE_DEBUG

#define LPC_COMPLETE_DEBUG   0x20

Definition at line 22 of file lpc.h.

◆ LPC_CONNECT_DEBUG

#define LPC_CONNECT_DEBUG   0x04

Definition at line 19 of file lpc.h.

◆ LPC_CREATE_DEBUG

#define LPC_CREATE_DEBUG   0x01

Definition at line 17 of file lpc.h.

◆ LPC_LISTEN_DEBUG

#define LPC_LISTEN_DEBUG   0x08

Definition at line 20 of file lpc.h.

◆ LPC_REPLY_DEBUG

#define LPC_REPLY_DEBUG   0x10

Definition at line 21 of file lpc.h.

◆ LPC_SEND_DEBUG

#define LPC_SEND_DEBUG   0x40

Definition at line 23 of file lpc.h.

◆ LPCP_LOCK_HELD

#define LPCP_LOCK_HELD   1

Definition at line 63 of file lpc.h.

◆ LPCP_LOCK_RELEASE

#define LPCP_LOCK_RELEASE   2

Definition at line 64 of file lpc.h.

◆ LPCP_THREAD_FLAG_IS_PORT

#define LPCP_THREAD_FLAG_IS_PORT   1

Definition at line 55 of file lpc.h.

◆ LPCP_THREAD_FLAG_NO_IMPERSONATION

#define LPCP_THREAD_FLAG_NO_IMPERSONATION   2

Definition at line 56 of file lpc.h.

◆ LPCP_THREAD_FLAGS

#define LPCP_THREAD_FLAGS
Value:
LPCP_THREAD_FLAG_NO_IMPERSONATION)
#define LPCP_THREAD_FLAG_IS_PORT
Definition: lpc.h:55

Definition at line 57 of file lpc.h.

◆ LPCTRACE

#define LPCTRACE (   x,
  fmt,
  ... 
)    DPRINT(fmt, ##__VA_ARGS__)

Definition at line 49 of file lpc.h.

Typedef Documentation

◆ LPCP_DATA_INFO

◆ PLPCP_DATA_INFO

Function Documentation

◆ LpcExitThread()

VOID NTAPI LpcExitThread ( IN PETHREAD  Thread)

Definition at line 19 of file close.c.

20 {
23 
24  /* Acquire the lock */
26 
27  /* Make sure that the Reply Chain is empty */
29  {
30  /* It's not, remove the entry */
32  }
33 
34  /* Set the thread in exit mode */
36  Thread->LpcReplyMessageId = 0;
37 
38  /* Check if there's a reply message */
40  if (Message)
41  {
42  /* FIXME: TODO */
43  ASSERT(FALSE);
44  }
45 
46  /* Release the lock */
48 }
#define TRUE
Definition: types.h:120
KGUARDED_MUTEX LpcpLock
Definition: port.c:20
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
VOID FASTCALL KeAcquireGuardedMutex(IN PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:42
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
FORCEINLINE PLPCP_MESSAGE LpcpGetMessageFromThread(IN PETHREAD Thread)
Definition: lpc_x.h:129
LIST_ENTRY LpcReplyChain
Definition: pstypes.h:1039
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
CHAR Message[80]
Definition: alive.c:5
ULONG LpcExitThreadCalled
Definition: pstypes.h:1146
VOID FASTCALL KeReleaseGuardedMutex(IN OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:53

Referenced by PspExitThread().

◆ LpcInitSystem()

INIT_FUNCTION BOOLEAN NTAPI LpcInitSystem ( VOID  )

Definition at line 37 of file port.c.

38 {
39  OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;
41 
42  /* Setup the LPC Lock */
44 
45  /* Create the Port Object Type */
46  RtlZeroMemory(&ObjectTypeInitializer, sizeof(ObjectTypeInitializer));
47  RtlInitUnicodeString(&Name, L"Port");
48  ObjectTypeInitializer.Length = sizeof(ObjectTypeInitializer);
49  ObjectTypeInitializer.DefaultNonPagedPoolCharge = sizeof(LPCP_NONPAGED_PORT_QUEUE);
50  ObjectTypeInitializer.DefaultPagedPoolCharge = FIELD_OFFSET(LPCP_PORT_OBJECT, WaitEvent);
51  ObjectTypeInitializer.GenericMapping = LpcpPortMapping;
52  ObjectTypeInitializer.PoolType = PagedPool;
53  ObjectTypeInitializer.UseDefaultObject = TRUE;
54  ObjectTypeInitializer.CloseProcedure = LpcpClosePort;
55  ObjectTypeInitializer.DeleteProcedure = LpcpDeletePort;
56  ObjectTypeInitializer.ValidAccessMask = PORT_ALL_ACCESS;
59  &ObjectTypeInitializer,
60  NULL,
62 
63  /* Create the Waitable Port Object Type */
64  RtlInitUnicodeString(&Name, L"WaitablePort");
65  ObjectTypeInitializer.PoolType = NonPagedPool;
66  ObjectTypeInitializer.DefaultNonPagedPoolCharge += sizeof(LPCP_PORT_OBJECT);
67  ObjectTypeInitializer.DefaultPagedPoolCharge = 0;
68  ObjectTypeInitializer.UseDefaultObject = FALSE;
70  &ObjectTypeInitializer,
71  NULL,
73 
74  /* Allocate the LPC lookaside list */
77  NULL,
78  NULL,
79  0,
81  'McpL',
82  32);
83 
84  /* We're done */
85  return TRUE;
86 }
NTSTATUS NTAPI ObCreateObjectType(IN PUNICODE_STRING TypeName, IN POBJECT_TYPE_INITIALIZER ObjectTypeInitializer, IN PVOID Reserved, OUT POBJECT_TYPE *ObjectType)
Definition: oblife.c:1048
#define TRUE
Definition: types.h:120
POBJECT_TYPE LpcPortObjectType
Definition: port.c:17
VOID NTAPI ExInitializePagedLookasideList(IN PPAGED_LOOKASIDE_LIST Lookaside, IN PALLOCATE_FUNCTION Allocate OPTIONAL, IN PFREE_FUNCTION Free OPTIONAL, IN ULONG Flags, IN SIZE_T Size, IN ULONG Tag, IN USHORT Depth)
Definition: lookas.c:274
static GENERIC_MAPPING LpcpPortMapping
Definition: port.c:24
#define LPCP_MAX_MESSAGE_SIZE
Definition: lpctypes.h:276
struct _LPCP_NONPAGED_PORT_QUEUE LPCP_NONPAGED_PORT_QUEUE
struct NameRec_ * Name
Definition: cdprocs.h:464
POBJECT_TYPE LpcWaitablePortObjectType
Definition: port.c:17
smooth NULL
Definition: ftsmooth.c:416
OB_CLOSE_METHOD CloseProcedure
Definition: obtypes.h:368
VOID NTAPI LpcpDeletePort(IN PVOID ObjectBody)
Definition: close.c:302
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
static const WCHAR L[]
Definition: oid.c:1250
ULONG LpcpMaxMessageSize
Definition: port.c:18
VOID FASTCALL KeInitializeGuardedMutex(OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:31
GENERIC_MAPPING GenericMapping
Definition: obtypes.h:358
KGUARDED_MUTEX LpcpLock
Definition: port.c:20
struct _LPCP_PORT_OBJECT LPCP_PORT_OBJECT
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
#define OBJ_VALID_ATTRIBUTES
Definition: winternl.h:233
#define PORT_ALL_ACCESS
Definition: lpctypes.h:47
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
PAGED_LOOKASIDE_LIST LpcpMessagesLookaside
Definition: port.c:19
VOID NTAPI LpcpClosePort(IN PEPROCESS Process OPTIONAL, IN PVOID Object, IN ACCESS_MASK GrantedAccess, IN ULONG ProcessHandleCount, IN ULONG SystemHandleCount)
Definition: close.c:244
OB_DELETE_METHOD DeleteProcedure
Definition: obtypes.h:369
ULONG DefaultNonPagedPoolCharge
Definition: obtypes.h:365

Referenced by Phase1InitializationDiscard().

◆ LpcpClosePort()

VOID NTAPI LpcpClosePort ( IN PEPROCESS Process  OPTIONAL,
IN PVOID  Object,
IN ACCESS_MASK  GrantedAccess,
IN ULONG  ProcessHandleCount,
IN ULONG  SystemHandleCount 
)

Definition at line 244 of file close.c.

249 {
251 
252  LPCTRACE(LPC_CLOSE_DEBUG, "Port: %p. Flags: %lx\n", Port, Port->Flags);
253 
254  /* Only Server-side Connection Ports need clean up*/
256  {
257  /* Check the handle count */
258  switch (SystemHandleCount)
259  {
260  /* No handles left */
261  case 0:
262 
263  /* Destroy the port queue */
265  break;
266 
267  /* Last handle remaining */
268  case 1:
269 
270  /* Reset the queue only */
272 
273  /* More handles remain, do nothing */
274  default:
275  break;
276  }
277  }
278 }
CPPORT Port[4]
Definition: headless.c:34
#define TRUE
Definition: types.h:120
struct _LPCP_PORT_OBJECT * PLPCP_PORT_OBJECT
#define LPCP_PORT_TYPE_MASK
Definition: lpctypes.h:58
#define LPCP_CONNECTION_PORT
Definition: lpctypes.h:54
USHORT Flags
Definition: cportlib.h:31
#define LPC_CLOSE_DEBUG
Definition: lpc.h:18
static IUnknown Object
Definition: main.c:512
VOID NTAPI LpcpDestroyPortQueue(IN PLPCP_PORT_OBJECT Port, IN BOOLEAN Destroy)
Definition: close.c:111
#define LPCTRACE(x, fmt,...)
Definition: lpc.h:49

Referenced by LpcInitSystem().

◆ LpcpDeletePort()

VOID NTAPI LpcpDeletePort ( IN PVOID  ObjectBody)

Definition at line 302 of file close.c.

303 {
307  PLPCP_PORT_OBJECT ConnectionPort;
309  PLIST_ENTRY ListHead, NextEntry;
310  HANDLE Pid;
311  CLIENT_DIED_MSG ClientDiedMsg;
312 
313  PAGED_CODE();
314  LPCTRACE(LPC_CLOSE_DEBUG, "Port: %p. Flags: %lx\n", Port, Port->Flags);
315 
316  Timeout.QuadPart = -1000000;
317 
318  /* Check if this is a communication port */
320  {
321  /* Acquire the lock */
323 
324  /* Get the thread */
325  Thread = Port->ClientThread;
326  if (Thread)
327  {
328  /* Clear it */
329  Port->ClientThread = NULL;
330 
331  /* Release the lock and dereference */
334  }
335  else
336  {
337  /* Release the lock */
339  }
340  }
341 
342  /* Check if this is a client-side port */
344  {
345  /* Setup the client died message */
346  ClientDiedMsg.h.u1.s1.TotalLength = sizeof(ClientDiedMsg);
347  ClientDiedMsg.h.u1.s1.DataLength = sizeof(ClientDiedMsg.CreateTime);
348  ClientDiedMsg.h.u2.ZeroInit = 0;
349  ClientDiedMsg.h.u2.s2.Type = LPC_PORT_CLOSED;
350  ClientDiedMsg.CreateTime = PsGetCurrentProcess()->CreateTime;
351 
352  /* Send it */
353  for (;;)
354  {
355  /* Send the message */
356  if (LpcRequestPort(Port, &ClientDiedMsg.h) != STATUS_NO_MEMORY)
357  break;
358 
359  /* Wait until trying again */
361  }
362  }
363 
364  /* Destroy the port queue */
366 
367  /* Check if we had views */
368  if ((Port->ClientSectionBase) || (Port->ServerSectionBase))
369  {
370  /* Check if we had a client view */
371  if (Port->ClientSectionBase)
372  {
373  /* Unmap it */
374  MmUnmapViewOfSection(Port->MappingProcess,
375  Port->ClientSectionBase);
376  }
377 
378  /* Check for a server view */
379  if (Port->ServerSectionBase)
380  {
381  /* Unmap it */
382  MmUnmapViewOfSection(Port->MappingProcess,
383  Port->ServerSectionBase);
384  }
385 
386  /* Dereference the mapping process */
387  ObDereferenceObject(Port->MappingProcess);
388  Port->MappingProcess = NULL;
389  }
390 
391  /* Acquire the lock */
393 
394  /* Get the connection port */
395  ConnectionPort = Port->ConnectionPort;
396  if (ConnectionPort)
397  {
398  /* Get the PID */
399  Pid = PsGetCurrentProcessId();
400 
401  /* Loop the data lists */
402  ListHead = &ConnectionPort->LpcDataInfoChainHead;
403  NextEntry = ListHead->Flink;
404  while (NextEntry != ListHead)
405  {
406  /* Get the message */
408  NextEntry = NextEntry->Flink;
409 
410  /* Check if this is the connection port */
411  if (Port == ConnectionPort)
412  {
413  /* Free queued messages */
414  RemoveEntryList(&Message->Entry);
415  InitializeListHead(&Message->Entry);
417 
418  /* Restart at the head */
419  NextEntry = ListHead->Flink;
420  }
421  else if ((Message->Request.ClientId.UniqueProcess == Pid) &&
422  ((Message->SenderPort == Port) ||
423  (Message->SenderPort == Port->ConnectedPort) ||
424  (Message->SenderPort == ConnectionPort)))
425  {
426  /* Remove it */
427  RemoveEntryList(&Message->Entry);
428  InitializeListHead(&Message->Entry);
430 
431  /* Restart at the head */
432  NextEntry = ListHead->Flink;
433  }
434  }
435 
436  /* Release the lock */
438 
439  /* Dereference the object unless it's the same port */
440  if (ConnectionPort != Port) ObDereferenceObject(ConnectionPort);
441 
442  /* Check if this is a connection port with a server process */
444  (ConnectionPort->ServerProcess))
445  {
446  /* Dereference the server process */
447  ObDereferenceObject(ConnectionPort->ServerProcess);
448  ConnectionPort->ServerProcess = NULL;
449  }
450  }
451  else
452  {
453  /* Release the lock */
455  }
456 
457  /* Free client security */
459  LPCTRACE(LPC_CLOSE_DEBUG, "Port: %p deleted\n", Port);
460 }
CPPORT Port[4]
Definition: headless.c:34
#define TRUE
Definition: types.h:120
KGUARDED_MUTEX LpcpLock
Definition: port.c:20
VOID FASTCALL KeAcquireGuardedMutex(IN PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:42
LARGE_INTEGER CreateTime
Definition: lpctypes.h:270
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
VOID NTAPI LpcpFreePortClientSecurity(IN PLPCP_PORT_OBJECT Port)
Definition: close.c:282
struct _LPCP_PORT_OBJECT * PLPCP_PORT_OBJECT
#define LPCP_PORT_TYPE_MASK
Definition: lpctypes.h:58
PEPROCESS ServerProcess
Definition: lpctypes.h:225
#define PAGED_CODE()
Definition: video.h:57
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
#define LPCP_CONNECTION_PORT
Definition: lpctypes.h:54
USHORT Flags
Definition: cportlib.h:31
NTSTATUS NTAPI KeDelayExecutionThread(IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Interval OPTIONAL)
Definition: wait.c:283
#define PsGetCurrentProcess
Definition: psfuncs.h:17
smooth NULL
Definition: ftsmooth.c:416
LIST_ENTRY LpcDataInfoChainHead
Definition: lpctypes.h:222
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 LpcRequestPort(IN PVOID PortObject, IN PPORT_MESSAGE LpcMessage)
Definition: send.c:22
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
NTSTATUS NTAPI MmUnmapViewOfSection(IN PEPROCESS Process, IN PVOID BaseAddress)
Definition: section.c:3051
#define LPC_CLOSE_DEBUG
Definition: lpc.h:18
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
CHAR Message[80]
Definition: alive.c:5
#define LPCP_LOCK_HELD
Definition: lpc.h:63
PORT_MESSAGE h
Definition: lpctypes.h:269
Definition: typedefs.h:117
VOID NTAPI LpcpDestroyPortQueue(IN PLPCP_PORT_OBJECT Port, IN BOOLEAN Destroy)
Definition: close.c:111
static ULONG Timeout
Definition: ping.c:61
VOID NTAPI LpcpFreeToPortZone(IN PLPCP_MESSAGE Message, IN ULONG LockFlags)
Definition: close.c:52
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
HANDLE NTAPI PsGetCurrentProcessId(VOID)
Definition: process.c:1123
VOID FASTCALL KeReleaseGuardedMutex(IN OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:53
#define LPCP_COMMUNICATION_PORT
Definition: lpctypes.h:56
#define LPCTRACE(x, fmt,...)
Definition: lpc.h:49
#define LPCP_CLIENT_PORT
Definition: lpctypes.h:57
base of all file and directory entries
Definition: entries.h:82

Referenced by LpcInitSystem().

◆ LpcpFreeToPortZone()

VOID NTAPI LpcpFreeToPortZone ( IN PLPCP_MESSAGE  Message,
IN ULONG  LockFlags 
)

Definition at line 52 of file close.c.

54 {
55  PLPCP_CONNECTION_MESSAGE ConnectMessage;
58  BOOLEAN LockHeld = (LockFlags & LPCP_LOCK_HELD);
59  BOOLEAN ReleaseLock = (LockFlags & LPCP_LOCK_RELEASE);
60 
61  PAGED_CODE();
62 
63  LPCTRACE(LPC_CLOSE_DEBUG, "Message: %p. LockFlags: %lx\n", Message, LockFlags);
64 
65  /* Acquire the lock if not already */
66  if (!LockHeld) KeAcquireGuardedMutex(&LpcpLock);
67 
68  /* Check if the queue list is empty */
69  if (!IsListEmpty(&Message->Entry))
70  {
71  /* Remove and re-initialize */
72  RemoveEntryList(&Message->Entry);
73  InitializeListHead(&Message->Entry);
74  }
75 
76  /* Check if we've already replied */
77  if (Message->RepliedToThread)
78  {
79  /* Set thread to dereference and clean up */
80  Thread = Message->RepliedToThread;
81  Message->RepliedToThread = NULL;
82  }
83 
84  /* Check if this is a connection request */
85  if (Message->Request.u2.s2.Type == LPC_CONNECTION_REQUEST)
86  {
87  /* Get the connection message */
88  ConnectMessage = (PLPCP_CONNECTION_MESSAGE)(Message + 1);
89 
90  /* Clear the client port */
91  ClientPort = ConnectMessage->ClientPort;
92  if (ClientPort) ConnectMessage->ClientPort = NULL;
93  }
94 
95  /* Release the lock */
97 
98  /* Check if we had anything to dereference */
101 
102  /* Free the entry */
103  ExFreeToPagedLookasideList(&LpcpMessagesLookaside, Message);
104 
105  /* Reacquire the lock if needed */
106  if ((LockHeld) && !(ReleaseLock)) KeAcquireGuardedMutex(&LpcpLock);
107 }
struct _LPCP_CONNECTION_MESSAGE * PLPCP_CONNECTION_MESSAGE
KGUARDED_MUTEX LpcpLock
Definition: port.c:20
PAGED_LOOKASIDE_LIST LpcpMessagesLookaside
Definition: port.c:19
VOID FASTCALL KeAcquireGuardedMutex(IN PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:42
_Outptr_ PFLT_PORT * ClientPort
Definition: fltkernel.h:1892
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
#define LPCP_LOCK_RELEASE
Definition: lpc.h:64
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
#define PAGED_CODE()
Definition: video.h:57
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define LPC_CLOSE_DEBUG
Definition: lpc.h:18
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
CHAR Message[80]
Definition: alive.c:5
#define LPCP_LOCK_HELD
Definition: lpc.h:63
PLPCP_PORT_OBJECT ClientPort
Definition: lpctypes.h:257
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
VOID FASTCALL KeReleaseGuardedMutex(IN OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:53
#define LPCTRACE(x, fmt,...)
Definition: lpc.h:49

Referenced by LpcpDeletePort(), LpcpDestroyPortQueue(), LpcpFreeDataInfoMessage(), LpcRequestPort(), LpcRequestWaitReplyPort(), NtReplyPort(), NtReplyWaitReceivePortEx(), NtRequestPort(), NtRequestWaitReplyPort(), and NtSecureConnectPort().

◆ LpcpInitializePortQueue()

NTSTATUS NTAPI LpcpInitializePortQueue ( IN PLPCP_PORT_OBJECT  Port)

Definition at line 19 of file create.c.

20 {
21  PLPCP_NONPAGED_PORT_QUEUE MessageQueue;
22 
23  PAGED_CODE();
24 
25  /* Allocate the queue */
26  MessageQueue = ExAllocatePoolWithTag(NonPagedPool,
27  sizeof(*MessageQueue),
28  'troP');
29  if (!MessageQueue) return STATUS_INSUFFICIENT_RESOURCES;
30 
31  /* Set it up */
32  KeInitializeSemaphore(&MessageQueue->Semaphore, 0, MAXLONG);
33  MessageQueue->BackPointer = Port;
34 
35  /* And link it with the Paged Pool part */
36  Port->MsgQueue.Semaphore = &MessageQueue->Semaphore;
37  InitializeListHead(&Port->MsgQueue.ReceiveHead);
38  return STATUS_SUCCESS;
39 }
CPPORT Port[4]
Definition: headless.c:34
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define MAXLONG
Definition: umtypes.h:116
struct _LPCP_PORT_OBJECT * BackPointer
Definition: lpctypes.h:196
PAGED_CODE()
VOID NTAPI KeInitializeSemaphore(IN PKSEMAPHORE Semaphore, IN LONG Count, IN LONG Limit)
Definition: semphobj.c:22
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
return STATUS_SUCCESS
Definition: btrfs.c:2725

Referenced by LpcpCreatePort(), and NtSecureConnectPort().

◆ LpcpMoveMessage()

VOID NTAPI LpcpMoveMessage ( IN PPORT_MESSAGE  Destination,
IN PPORT_MESSAGE  Origin,
IN PVOID  Data,
IN ULONG  MessageType,
IN PCLIENT_ID  ClientId 
)

Definition at line 139 of file reply.c.

144 {
146  "Destination/Origin: %p/%p. Data: %p. Length: %lx\n",
147  Destination,
148  Origin,
149  Data,
150  Origin->u1.Length);
151 
152  /* Set the Message size */
153  Destination->u1.Length = Origin->u1.Length;
154 
155  /* Set the Message Type */
156  Destination->u2.s2.Type = !MessageType ?
157  Origin->u2.s2.Type : MessageType & 0xFFFF;
158 
159  /* Check if we have a Client ID */
160  if (ClientId)
161  {
162  /* Set the Client ID */
163  Destination->ClientId.UniqueProcess = ClientId->UniqueProcess;
164  Destination->ClientId.UniqueThread = ClientId->UniqueThread;
165  }
166  else
167  {
168  /* Otherwise, copy it */
169  Destination->ClientId.UniqueProcess = Origin->ClientId.UniqueProcess;
170  Destination->ClientId.UniqueThread = Origin->ClientId.UniqueThread;
171  }
172 
173  /* Copy the MessageId and ClientViewSize */
174  Destination->MessageId = Origin->MessageId;
175  Destination->ClientViewSize = Origin->ClientViewSize;
176 
177  /* Copy the Message Data */
179  Data,
180  ALIGN_UP_BY(Destination->u1.s1.DataLength, sizeof(ULONG)));
181 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define LPC_SEND_DEBUG
Definition: lpc.h:23
HANDLE UniqueProcess
Definition: compat.h:474
#define LPC_REPLY_DEBUG
Definition: lpc.h:21
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1176
_In_ PUNICODE_STRING _Inout_ PUNICODE_STRING Destination
Definition: rtlfuncs.h:2875
HANDLE UniqueThread
Definition: compat.h:475
unsigned int ULONG
Definition: retypes.h:1
#define ALIGN_UP_BY(size, align)
#define LPCTRACE(x, fmt,...)
Definition: lpc.h:49

Referenced by LpcRequestPort(), LpcRequestWaitReplyPort(), NtReplyPort(), NtReplyWaitReceivePortEx(), NtRequestPort(), and NtRequestWaitReplyPort().

◆ LpcpSaveDataInfoMessage()

VOID NTAPI LpcpSaveDataInfoMessage ( IN PLPCP_PORT_OBJECT  Port,
IN PLPCP_MESSAGE  Message,
IN ULONG  LockFlags 
)

Definition at line 62 of file reply.c.

65 {
66  BOOLEAN LockHeld = (LockFlags & LPCP_LOCK_HELD);
67 
68  PAGED_CODE();
69 
70  /* Acquire the lock */
71  if (!LockHeld) KeAcquireGuardedMutex(&LpcpLock);
72 
73  /* Check if the port we want is the connection port */
75  {
76  /* Use it */
77  Port = Port->ConnectionPort;
78  if (!Port)
79  {
80  /* Release the lock and return */
81  if (!LockHeld) KeReleaseGuardedMutex(&LpcpLock);
82  return;
83  }
84  }
85 
86  /* Link the message */
87  InsertTailList(&Port->LpcDataInfoChainHead, &Message->Entry);
88 
89  /* Release the lock */
90  if (!LockHeld) KeReleaseGuardedMutex(&LpcpLock);
91 }
CPPORT Port[4]
Definition: headless.c:34
KGUARDED_MUTEX LpcpLock
Definition: port.c:20
VOID FASTCALL KeAcquireGuardedMutex(IN PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:42
#define InsertTailList(ListHead, Entry)
#define LPCP_PORT_TYPE_MASK
Definition: lpctypes.h:58
#define PAGED_CODE()
Definition: video.h:57
USHORT Flags
Definition: cportlib.h:31
#define LPCP_UNCONNECTED_PORT
Definition: lpctypes.h:55
unsigned char BOOLEAN
CHAR Message[80]
Definition: alive.c:5
#define LPCP_LOCK_HELD
Definition: lpc.h:63
VOID FASTCALL KeReleaseGuardedMutex(IN OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:53

Referenced by NtReplyWaitReceivePortEx(), and NtRequestWaitReplyPort().

◆ LpcpValidateClientPort()

BOOLEAN NTAPI LpcpValidateClientPort ( PETHREAD  ClientThread,
PLPCP_PORT_OBJECT  Port 
)

Definition at line 90 of file port.c.

93 {
94  PLPCP_PORT_OBJECT ThreadPort;
95 
96  /* Get the thread's port */
97  ThreadPort = LpcpGetPortFromThread(ClientThread);
98  if (ThreadPort == NULL)
99  {
100  return FALSE;
101  }
102 
103  /* Check if the port matches directly */
104  if ((Port == ThreadPort) ||
105  (Port == ThreadPort->ConnectionPort) ||
106  (Port == ThreadPort->ConnectedPort))
107  {
108  return TRUE;
109  }
110 
111  /* Check if this is a communication port and the connection port matches */
113  (Port->ConnectionPort == ThreadPort))
114  {
115  return TRUE;
116  }
117 
118  return FALSE;
119 }
CPPORT Port[4]
Definition: headless.c:34
#define TRUE
Definition: types.h:120
struct _LPCP_PORT_OBJECT * ConnectedPort
Definition: lpctypes.h:212
#define LPCP_PORT_TYPE_MASK
Definition: lpctypes.h:58
USHORT Flags
Definition: cportlib.h:31
smooth NULL
Definition: ftsmooth.c:416
UINT CALLBACK ClientThread(_Inout_ PVOID Parameter)
FORCEINLINE PLPCP_PORT_OBJECT LpcpGetPortFromThread(IN PETHREAD Thread)
Definition: lpc_x.h:144
struct _LPCP_PORT_OBJECT * ConnectionPort
Definition: lpctypes.h:211
#define LPCP_COMMUNICATION_PORT
Definition: lpctypes.h:56

Referenced by LpcpCopyRequestData(), and NtImpersonateClientOfPort().

Variable Documentation

◆ LpcpLock

◆ LpcpMaxMessageSize

ULONG LpcpMaxMessageSize

Definition at line 18 of file port.c.

Referenced by LpcInitSystem(), and LpcpCreatePort().

◆ LpcpMessagesLookaside

PAGED_LOOKASIDE_LIST LpcpMessagesLookaside

Definition at line 19 of file port.c.

Referenced by LpcInitSystem(), LpcpAllocateFromPortZone(), and LpcpFreeToPortZone().

◆ LpcpNextCallbackId

ULONG LpcpNextCallbackId

Definition at line 22 of file port.c.

◆ LpcpNextMessageId

ULONG LpcpNextMessageId

◆ LpcPortObjectType

◆ LpcpTraceLevel

ULONG LpcpTraceLevel

Definition at line 21 of file port.c.