Local Procedure Call - Implementation

Implementation

(A)LPC is implemented using kernel "port" objects, which are securable (with ACLs, allowing e.g. only specific SIDs to use them) and allow identification of the process on the other side of the connection. Individual messages are also securable: applications can set per-message SIDs, and also test for changes of the security context in the token associated with the (A)LPC message.

The typical communication scenario between the server and the client is as follows:

  1. A server process first creates a named server connection port object, and waits for clients to connect.
  2. A client requests a connection to that named port by sending a connect message.
  3. If the server accepts the connection, two unnamed ports are created:
    • client communication port - used by client threads to communicate with a particular server
    • server communication port - used by the server to communicate with a particular client; one such port per client is created
  4. The client receives a handle to the client communication port, and server receives a handle to the server communication port, and the inter-process communication channel is established.

(A)LPC supports the following three modes of message exchange between the server and client:

  • For short messages (fewer than 256 bytes) the kernel copies the message buffers between processes, from the address space of the sending process to the system address space, and from there to the receiving process' address space.
  • For messages longer than 256 bytes a shared memory section must be used to transfer data, which the (A)LPC service maps between the sending and receiving processes. First the sender places data into the shared memory, and then sends a notification (e.g. a small message, using the first method of (A)LPC) to the receiving process pointing to the sent data in the shared memory section.
  • Server can directly read and write data from the client's address space, when the amount of data is too large to fit in a shared section.

ALPC has a performance advantage over the former LPC interface, as it can be configured to use I/O completion ports instead of synchronous request/reply mechanism that LPC exclusively uses. This enables ALPC ports high-speed communication which automatically balances the number of messages and threads. Additionally, ALPC messages can be batched together so as to minimize user-mode/kernel-mode switches.

Read more about this topic:  Local Procedure Call