Message Passing
Aurora OS implements blocking message queues for process-to-process communication.SYS_MSGSND
Send a message to another process. Syscall Number: 19Parameters
PID of the receiving process
Pointer to message payload
Length of message in bytes (max 256)
Returns
- On success: 0
- On error: -1 (invalid PID, process not found, or message too large)
Behavior
If the target process’s message queue is full (32 messages), the sender blocks until space becomes available.
- Validates target PID and message length (≤ 256 bytes)
- Creates an
ipc_messagestructure:- Sets
sender_pidto current process - Sets
receiver_pidto target - Copies message data
- Sets
- Attempts to enqueue the message
- If queue full, blocks sender and reschedules
- Wakes receiver if it was blocked in
msgrcv
Message Structure
Example
SYS_MSGRCV
Receive a message from the process’s message queue. Syscall Number: 20Parameters
Buffer to store received message data
Maximum number of bytes to copy (buffer size)
Returns
- On success: number of bytes copied to buffer
- On error: -1
Behavior
If the message queue is empty, the caller blocks until a message arrives.
- Checks the process’s message queue
- If empty, blocks the process and reschedules
- Dequeues the oldest message (FIFO order)
- Copies
min(msg.len, max_len)bytes to user buffer - Returns the number of bytes copied
Example
Queue Limits
Shared Memory
Shared memory allows multiple processes to access the same physical memory region.SYS_SHMGET
Create a shared memory segment. Syscall Number: 21Parameters
Size of the shared memory segment in bytes (rounded up to pages)
Returns
- On success: shared memory ID (positive integer)
- On error: -1 (no free slots or allocation failure)
Behavior
- Rounds size up to page boundaries (4096-byte multiples)
- Allocates physical pages (simplified: may not be contiguous)
- Creates a
shm_regionstructure:- Assigns a unique ID
- Records physical base address and size
- Initializes refcount to 0
- Returns the shared memory ID
Limits
Aurora OS supports up to 16 concurrent shared memory segments system-wide.
Example
SYS_SHMAT
Attach a shared memory segment to the process’s address space. Syscall Number: 22Parameters
Shared memory ID returned by shmget
Suggested virtual address. If 0, kernel chooses the address automatically.
Returns
- On success: virtual address where segment is mapped
- On error: -1 (invalid ID)
Behavior
- Finds the shared memory region by ID
- Chooses virtual address:
- If
hint_addr == 0: Uses0x60000000 + shm_id * 0x100000 - Otherwise: Uses
hint_addr
- If
- Maps all pages of the segment with
PAGE_WRITABLE | PAGE_USER - Increments the segment’s reference count
- Returns the virtual address
Example
SYS_SHMDT
Detach a shared memory segment from the process’s address space. Syscall Number: 23Parameters
Virtual address where the segment is mapped
Shared memory ID
Returns
- On success: 0
- On error: -1 (invalid ID)
Behavior
- Finds the shared memory region by ID
- Unmaps all pages from the virtual address
- Decrements the reference count
- If refcount reaches 0: Frees all physical pages and marks the segment as unused
Example
Pipes
Pipes provide unidirectional byte streams between processes, typically used for parent-child communication.SYS_PIPE
Create a pipe and return two file descriptors. Syscall Number: 15Parameters
Array to store the two file descriptors:
pipefd[0]: read endpipefd[1]: write end
Returns
- On success: 0 (pipefd array is filled)
- On error: -1 (no free pipe slots or fd slots)
Behavior
- Allocates a
struct pipewith a 4096-byte circular buffer - Finds two free file descriptors in the current process
- Sets up the descriptors:
- Read end:
flags = 0,fs_priv = pipe pointer - Write end:
flags = 1,fs_priv = pipe pointer
- Read end:
- Returns 0 with
pipefd[0]andpipefd[1]set
Pipe Structure
Example
SYS_DUP2
Duplicate a file descriptor to a specific fd number. Syscall Number: 16Parameters
Existing file descriptor to duplicate
Target file descriptor number
Returns
- On success: newfd
- On error: -1 (invalid fd)
Behavior
- Validates that
oldfdis in use - If
newfdis already in use and differs fromoldfd, closes it - Copies the entire
fd_entryfromoldfdtonewfd - Returns
newfd
This is commonly used for I/O redirection, such as redirecting stdout to a pipe or file.
Example - Redirect stdout to Pipe
Comparison of IPC Mechanisms
| Mechanism | Use Case | Capacity | Blocking | Persistence |
|---|---|---|---|---|
| Messages | Command/control messages | 32 msgs × 256 bytes | Yes | Queue per process |
| Shared Memory | Large data transfer | Up to page multiples | No | Refcounted |
| Pipes | Streaming data | 4096 bytes | Yes | Lifetime of pipe |
Recommendations
- Use messages for simple RPC-style communication and event notifications
- Use shared memory for high-bandwidth data sharing (e.g., video frames, large buffers)
- Use pipes for traditional Unix-style process pipelines and I/O redirection