01a Mach Concepts
01a Mach Concepts
AP 9/01
The Mach Operating System
AP 9/01
History of Mach
AP 9/01
History of Mach (contd.)
• Mach 2 was released
– VAX 11/784 version (4 CPU multiprocessor) in 1986
– Ports to IBM PC/RT and Sun3 in 1987
– Versions for Encore and Sequent multiprocessors available in 1987
• OSF/1
– Open Software Foundation (consortium of vendors; IBM, DEC, HP,...)
selected Mach 2.5 as basis for OSF/1
– Alliance against AT&T and Sun Microsystem‘s UNIX System V.4
– Large and monolithic kernel
• Mach 3 microkernel OS
– CMU removed all BSD code from kernel and put it in user space
– User-level OS emulator for BSD UNIX in 1988.
AP 9/01
Mach Components
AP 9/01
Mach provides features not found in
UNIX 4.3BSD:
• Multiple tasks, each with a large, paged virtual memory space
• Multiple threads of execution within each task, with a flexible
scheduling facility
• Flexible sharing of memory between tasks
• Efficient and consistent message-based interprocess
communication
• Memory-mapped files
• Transparent network extensibility
• A flexible, capability-based approach to security and protection
• Support for multiprocessor scheduling
AP 9/01
Tasks and Threads
AP 9/01
Tasks and Threads (contd.)
• Thread
– basic unit of execution
– lightweight process executing within a task – defined by processor
state
– executes within the context of a single task
– each task may contain more than one thread
– All threads within a task share
• the virtual memory address space and
• communication rights of that task.
– basic unit of scheduling
– multiple threads from one task may be executing simultaneously.
AP 9/01
Task and Thread Ports
AP 9/01
Task and Thread Ports (contd.)
AP 9/01
A Mach Task
Suspend counter
Other task‘s properties Scheduling parameters
Emulation address
Statistics
Task
Address
space
Thread
AP 9/01
Mach Ports and Messages
AP 9/01
Mach Ports and Messages (contd.)
• Port set
– group of ports, combining the message queues of the constituent ports.
– may be used to receive a message sent to any of several ports.
• Messages
– Used to communicate between objects;
– data stream consisting of two parts:
• fixed-length header
• variable-length message body -- typed data objects
– header contains information about:
• size of the message, its type, and its destination
– body contains the content (or a pointer to the content) of the message
– Messages may be of any size, may contain:
– in-line data, pointers to data, and capabilities for ports.
• A single message may transfer the entire address space of a task.
AP 9/01
Port Access Rights
• Communication between objects is protected by a system of port
access rights (Capabilities).
• Send access to a port
– Implies that a message can be sent to that port.
• Receive access to a port
– Allows a message to be de-queued from that port.
– Only one task may have receive access for a given port at a time;
– more than one thread within that task may concurrently attempt to receive
messages
– receive access implies send rights.
• Multiple tasks may hold send rights to the same port, but
– only one task at a time may hold receive rights to a port.
• Port access rights can be passed in messages.
AP 9/01
Port Sets
AP 9/01
Port Names
• Every task has its own port name space, used for port
and port set names.
– For example, one task with receive rights for a port may know the port
by the name 13,
– while another task with send rights for the same port may know it by
the name 17.
• A task has only one name for a port.
• Typically, these names are small integers, but this is
implementation dependent.
– port_rename() call can be used to change a task's name for a port.
AP 9/01
Port Queues
• Messages that are sent to a port are held there until removed by a
thread.
– The queue associated with a port is of finite length and may become full.
• A thread sending to a filled queue has a choice of three
alternatives:
– By default, the sender is suspended until it can successfully transmit the
message.
– The sender can have the kernel hold the message for later transmission.
– If the sender selects this action, it can't transmit further messages to the port
until the kernel notifies it that the port has received the initial message.
• The attempt to send a message to a full port can be reported to the
sender as an error.
AP 9/01
Client/Server Setup
AP 9/01
Programming with Ports (IPC)
• Allocating a port
# include <mach/mach.h>
# include <mach/port.h>
AP 9/01
Registering with the Name Service
# include <mach/mach.h>
# include <servers/netname.h>
# include <mach/message.h>
# include <mach/port.h>
AP 9/01
Programming with Mach IPC
# include <mach/mach_types.defs>
routine send_packet(
RequestPort server: mach_port_t;
in count: int
);
simpleroutine server_exit(
RequestPort server: mach_port_t
);
AP 9/01
Mach Interface Generator (MIG)
AP 9/01
MIG Operations
AP 9/01
MIG Declarations - EBNF
AP 9/01