Kernel Message System

Overview

For an Operating Systems course, I modified the Linux kernel to include an inter-process messaging system.

Process Mailbox

The task_struct in the Linux Kernel was modified to include a mailbox structure that holds messages for processes. Whenever a new process is forked, a new mailbox structure is allocated for that process. All threads of a process share the same mailbox. The mailbox for a process is deleted once all of the threads in the thread group are dead. The mailboxes are synchronized using spinlocks.

Mailbox and Messages

This mailbox holds messages that the process has received in a linked list.
The API for the mailbox includes three system calls:
  1. int SendMsg(pid_t dest, void *body, int len, bool block)
    Sends a message to the process of the ID dest. The message is pointed to by the argument body. The length of the message len must not exceed MAX_MSG_SIZE. The block flag specifies whether or not the call should block and wait to send the message if the recipient's mailbox is full.

  2. int RcvMsg(pid_t *sender, void *msg, int *len, bool block)
    Retreives a message from this process's mailbox. The process ID of the sender is returned in the pid_t pointed to by sender. The message is returned to the memory pointed to by msg which must be of size MAX_MSG_SIZE. The length of the message is returned in the integer pointed to by len. The block flag specifies whether or not the call should block and wait for a message if this process's mailbox is empty.

  3. int ManageMailbox(bool stop, int *count)
    This system call allows a process to stop its mailbox and/or to query the number of messages in its mailbox. If the stop flag is TRUE, the mailbox will cease to receive any more messages. All messages left on a mailbox that has been stopped may still be retreived. All blocked calls to SendMsg or RcvMsg for this mailbox will return immediatly with an error.

Error Codes

The three mailbox system calls return a zero on success or one of the following error codes:

Installation

Download

Provided are two patches for Open Suse 10.3 - 2.6.22.13-0.3 that provide the implementation for the mailbox system. Also included are "mailbox.h" that defines the mailbox interface and "mailbox.cpp" which defines the user space system calls.