Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Local procedure calls in Windows
The Local Procedure Call (LPC) facility in Windows is a message-passing mechanism designed for communication between two processes on the same machine. LPC is optimized specifically for Windows and serves as an efficient alternative to standard Remote Procedure Call (RPC) mechanisms. Windows uses port objects to establish and maintain connections between processes, similar to the Mach operating system.
Types of Ports
Windows employs two types of ports for LPC communication:
Connection ports − Used for establishing initial connections between client and server processes
Communication ports − Used for actual message exchange after the connection is established
How LPC Communication Works
The LPC communication process follows these steps:
Server processes publish connection-port objects that are visible to all processes in the system.
Client opens a handle to the server's connection-port object and sends a connection request to that port.
Server creates a communication channel and returns a handle to the client. This channel consists of a pair of private communication ports: one for client-to-server messages and another for server-to-client messages.
Bidirectional communication begins through the established channel, which also supports a callback mechanism for handling unexpected requests.
Message-Passing Techniques
When an LPC channel is created, one of three message-passing techniques is chosen based on message size:
| Message Size | Technique | Method |
|---|---|---|
| Small (< 256 bytes) | Message Queue | Messages copied through port's message queue |
| Large | Section Object | Shared memory region associated with the channel |
| Very Large | Direct API | Server reads/writes directly into client's address space |
Section Object Usage
For large messages, the client determines when setting up the channel whether it will need to send large messages and requests a section object (shared memory region) to be created. Similarly, if the server expects to send large replies, it creates a section object. A small message containing pointer and size information about the section object is sent, avoiding expensive data copying operations.
LPC in the Windows Architecture
The LPC facility is not part of the Windows API and is therefore not directly visible to application programmers. Instead, applications using the Windows API invoke standard Remote Procedure Calls (RPC). When an RPC is invoked on a process within the same system, the RPC runtime handles it indirectly through LPC, providing transparency to the application.
Additionally, many kernel services use LPC to communicate with client processes, making it a fundamental component of Windows inter-process communication infrastructure.
Conclusion
Local Procedure Calls provide an efficient, optimized message-passing mechanism for Windows inter-process communication. By using connection and communication ports with multiple message-passing techniques, LPC ensures optimal performance for different message sizes while remaining transparent to application developers through the RPC abstraction layer.
