IPC System
Overview
The IPC (Inter-Process Communication) System provides core-level communication infrastructure for FreeWorld OS. It enables all services, daemons, and applications to communicate efficiently using channels, message queues, Unix domain sockets, and named pipes.
Architecture
The IPC system operates at the kernel level, providing:
- Channel Management: Named channels for service communication
- Message Queues: Reliable message passing between processes
- Unix Domain Sockets: Fast local communication
- Named Pipes: Stream-based communication
- Message Types: Structured messages with type, size, sender, receiver, priority
Channel Types
| Type | Value | Description | Use Case |
|---|---|---|---|
IPC_TYPE_SOCKET |
0 | Unix domain socket | Service daemons (logd, networkd, csrss) |
IPC_TYPE_PIPE |
1 | Named pipe | Stream-based communication |
IPC_TYPE_QUEUE |
2 | Message queue | Reliable message passing |
API Reference
Channel Management
// Create IPC channel
int ipc_create_channel(const char* name, uint32_t type, uint32_t buffer_size);
// Open existing IPC channel
int ipc_open_channel(const char* name, uint32_t mode);
// Close IPC channel
int ipc_close_channel(uint32_t channel_id);
Message Passing
// Send message via IPC
int ipc_send(uint32_t channel_id, const void* buffer, uint32_t size, uint32_t type);
// Receive message via IPC
int ipc_receive(uint32_t channel_id, void* buffer, uint32_t size);
Message Structure
typedef struct {
uint32_t type; // Message type
uint32_t size; // Payload size (max 512 bytes)
uint32_t sender; // Sender PID
uint32_t receiver; // Receiver PID (0 = broadcast)
uint32_t priority; // Message priority
char payload[512]; // Message data
} IPC_MESSAGE;
Service Integration
logd (Logging Daemon)
- Socket:
/var/run/logd.sock - Purpose: Receive log messages from all system components
- Client Library:
services/logd/logd_ipc.c - Node.js Client:
system/logd-client.js
networkd (Network Daemon)
- Socket:
/var/run/networkd.sock - Purpose: Network configuration and management
- Client Library:
services/networkd/networkd_ipc.c - Messages: Configure static IP, enable DHCP, set DNS, manage routes
csrss (Client/Server Runtime)
- Socket:
/var/run/csrss.sock - Purpose: Console and window management
- Messages: Create console, create window, console I/O
Usage Examples
C Client Example
#include "logd_ipc.h"
// Send log message
logd_info("myapp", "Application started");
// Configure network
networkd_configure_static("eth0", "192.168.1.100",
"255.255.255.0", "192.168.1.1");
Node.js Client Example
const { getLogdClient } = require('./system/logd-client');
const logd = getLogdClient();
logd.init(eventManager, eventBus);
// Send log
logd.info('myapp', 'Application started');
// EventBus integration (automatic)
eventBus.emit('security.user.login', { username: 'user' });
// Automatically logged to logd via EventBus subscription
Performance
- Unix Domain Sockets: Very fast local communication (no network overhead)
- Message Queues: Reliable, ordered message delivery
- Non-blocking: Uses poll() for efficient I/O
- Kernel-level: Direct kernel support for maximum performance
File Structure
kernel/ipc/
├── ipc.asm # Core IPC implementation (ASM)
└── ipc.h # C API header
services/logd/
├── logd.c # Daemon with IPC
└── logd_ipc.c # Client library
services/networkd/
├── networkd.c # Daemon with IPC
├── networkd_ipc.c # Client library
└── networkd_ipc.h # Client header
services/csrss/
└── csrss.c # Daemon with IPC
system/
└── logd-client.js # Node.js client
Integration with Event System
The IPC system integrates with the Event System:
- logd ↔ EventBus: logd subscribes to EventBus for automatic audit logging
- EventManager: Security/system/error events automatically sent to logd
- Decoupled Architecture: Components communicate via events, not direct IPC calls
Status
Core IPC System
✅ Complete
✅ Complete
logd IPC
✅ Complete
✅ Complete
networkd IPC
✅ Complete
✅ Complete
csrss IPC
✅ Complete
✅ Complete
Event System Integration
✅ Complete
✅ Complete