IPC - MirSiv/exyde GitHub Wiki

IPC

Inter-process communication is built on channels — fixed-message FIFO queues with bounded capacity. Channels are kernel objects accessed through handles.

Creating a channel

IPC_CREATE(msg_size, capacity) -> handle
  • msg_size is fixed for the channel's lifetime. Every send and every receive must use exactly that size (send) or >= that size (receive). Maximum 1024 bytes.
  • capacity is the number of messages the ring can hold. Maximum 64.
  • The returned handle carries READ | WRITE | TRANSFER.

Sending and receiving

IPC_SEND(ch, buf, len)       -> 0
IPC_RECV(ch, buf, max)       -> msg_size
IPC_TRY_SEND(ch, buf, len)   -> 0 / -EAGAIN
IPC_TRY_RECV(ch, buf, max)   -> msg_size / -EAGAIN

IPC_SEND blocks when the channel is full. IPC_RECV blocks when it is empty. The TRY_* variants return -EAGAIN instead.

len must equal the channel's msg_size. max must be >= it.

Passing a capability

IPC_SEND_CAP(ch, buf, len, cap, action) -> 0
IPC_RECV_CAP(ch, buf, max, &out_cap)    -> msg_size

Each message slot has room for exactly one capability. See Handles and Capabilities for the semantics of TRANSFER and DUPLICATE.

The two-channel pattern

A request/reply service typically uses two channels:

  • ch_req — client → server. Requests.
  • ch_resp — server → client. Replies.

The client creates both, sends the reply channel to the server as a capability (action DUPLICATE) with an ATTACH request, then loops sending requests on ch_req and receiving replies on ch_resp.

Do not use a single channel for a request/reply protocol. The sender enqueues a request and then tries to receive the reply — but the request is still in the same queue, so the client reads back its own request. This bug was hit during development of the VFS server; the two-channel split is the fix.

Blocking behaviour

IPC_RECV blocks on the current thread. The scheduler runs other threads. When a message arrives, the blocked thread is woken.

IPC_SEND blocks when the channel is full. Capacity is bounded, so a slow consumer eventually stalls a fast producer. IPC_TRY_SEND lets a producer drop or defer work instead.

Message format

Channels are byte-oriented. The kernel does not look inside a message. In this project, the VFS and console RPC protocols use fixed-size C structs (vfs_req, vfs_rsp, console_req, console_rsp) copied into the channel as bytes.

Wake ordering

FIFO within a channel. Multiple senders and multiple receivers on the same channel are ordered by arrival; the kernel does not prioritise.