Kernel API
Kernel API
Jorrit N. Herder
<[email protected]>
Abstract
In general, kernel calls allow system processes to request kernel
services, for example, to perform for privileged operations. This docu-
ment briefly discusses the organization of kernel calls in MINIX 3 and
provides an overview of all kernel calls.
1
2
Figure 1: This figure provides an overview of the kernel calls in MINIX 3. The
legenda for the status is: to be New or Updated (i.e., fully revised—all calls got
minor updates) since MINIX 2.
3
MINIX’ kernel call interface is detailed below. For each kernel call the mes-
sage type, the purpose, message type, request and/ or response parameters,
and return value are specified. The shorthand Additional remarks about
the future status of the call also may be provided.
Legenda
CONSTANT: defined constant; a number indicating the request type or status
PARAMETER: message parameter; a field in the request or response message
void sys call(arguments): system library function; shorthand to make a kernel call
Alphabetical overview
SYS ABORT: Shutdown MINIX and return to the boot monitor—if possible. This is used
by PM, FS and TTY. Normal aborts usually are initiated by the user, for example,
by means of the ‘shutdown’ command or typing a ‘Ctrl-Alt-Del’. MINIX will
also be taken down if a fatal error occurs in the PM or FS.
request parameters
ABRT HOW : How to abort. One of the values defined in src/include/unistd.h:
ABRT MON PROC : Process to get the boot monitor parameters from.
ABRT MON LEN : Length of the boot monitor parameters.
ABRT MON ADDR: Virtual address of the parameters.
return value
OK: The shutdown sequence was started.
ENIVAL: Invalid process number.
EFAULT: Illegal monitor parameters address.
E2BIG: Monitor parameters exceed maximum length.
library functions
int sys abort(int shutdown status, ...);
SYS DEVIO: Perform device I/O on behalf of a user-space device driver. The driver can
request a single port to be read or written with this call. Also see the SYS SDEVIO
and SYS VDEVIO kernel calls.
request parameters
DIO REQUEST : Input or output.
SYS ENDKSIG: Finish a kernel signal. The PM uses this call to indicate it has processed
the kernel signals in the map obtained through a SYS GETKSIG kernel call.
response parameters
SIG PROC : The process that it concerns.
return value
EINVAL: The process had no pending signals or already exited.
OK: The kernel cleared all pending signals.
library functions
int sys endksig(int proc nr);
SYS EXEC: Update a process’ registers after a successfull exec() POSIX-call. After the FS
has copied the binary image into memory, the PM informs the kernel about the
new register details.
request parameters
PR PROC NR: Process that executed a program.
PR STACK PTR: New stack pointer.
PR IP PTR: New program counter.
PR NAME PTR: Pointer to name of program.
return value
OK: This call always succeeds.
5
library functions
int sys exec(int proc, char *stack ptr, char *prog name, vir bytes pc);
SYS EXIT: Clear a process slot. This is usually called by the PM to clean up after a
user process exited. System processes, including the PM, can also directly call this
function to exit themselves.
request parameters
PR PROC NR: Slot number of exiting process if caller is PM. Use SELF to exit the
PM.
return value
OK: The cleanup succeeded.
EINVAL: Incorrect process number.
EDONTREPLY: This call does not return if a system process exited.
library functions
int sys exit(int proc nr);
SYS FORK: Allocate a new (child) process in the kernel process table and initialize it based
on the prototype (parent) process. The PM has found a free process slot for the
child process in its own process table and now requests the kernel to update the
kernel’s process table.
request parameters
PR PROC NR: Child’s process table slot.
PR PPROC NR: Parent, the process that forked.
return value
OK: A new process slot was successfully assigned.
EINVAL: Invalid parent process number or child slot in use.
library functions
int sys fork(int parent proc nr, int child proc nr);
SYS GETINFO: Obtain a copy of a kernel data structure. This call supports user-space
device drivers and servers that need certain system information.
request parameters
I REQUEST : The type of system information that is requested.
SYS GETKSIG: Checks whether there is a process that must be signaled. This is repeatedly
done by the PM after receiving a notification that there are kernel signals pending.
response parameters
SIG PROC : Return next process with pending signals or NONE.
SIG MAP : Bit map with pending kernel signals.
return value
OK: This call always succeeds.
library functions
int sys getksig(int *proc nr, sigset t *sig map);
SYS INT86: Make a real-mode BIOS on behalf of a user-space device driver. This tem-
porarily switches from 32-bit protected mode to 16-bit real-mode to access the
BIOS calls. It is here to support the BIOS WINI device driver.
request parameters
INT86 REG86 : Address of request at the caller.
return value
OK: BIOS call successfully done.
EFAULT: Invalid request address.
library functions
-
7
SYS IOPENABLE: Enable the CPU’s I/O privilege level bits for to the given process, so
that is is allowed to directly perform I/O in user space.
request parameters
PROC NR: The process to give I/O privileges.
return value
OK: Always succeeds.
library functions
-
SYS IRQCTL: Set or reset a hardware interrupt policy for a given IRQ line and enable or
disable interrupts for this line. This call allows user-space device drivers to grab
a hook for use with the kernel’s generic interrupt handler. The kernel’s interrupt
handler merely notifies the driver about the interrupt with a HARD INT message and
reenables the IRQ line if the policy says so. The notification message will contain
the ’id’ provided by the caller as an argument. Once a policy is in place, drivers
can enable and disable interrupts.
request parameters
IRQ REQUEST : Interrupt control request to perform.
• IRQ SETPOLICY Set interrupt policy for the generic interrupt handler.
• IRQ RMPOLICY Remove a previously set interrupt policy.
• IRQ ENABLE Enable IRQs for the given IRQ line.
• IRQ DISABLE Disable IRQs for the given IRQ line.
SYS KILL: Signal a process on behalf of a system server. A system process can signal
another process with this call. The kernel notifies the PM about the pending
signal for further processing. (Note that the kill() POSIX-call is directly handled
at the PM.) The PM uses this call to indirectly send a signal message to a system
process. This happens when a signal arrives for a system process that set the special
SIG MESS signal handler with the sigaction() POSIX-call.
8
request parameters
SIG PROC NR: Process to be signaled.
SIG NUMBER: Signal number. Range from 0 to NSIG.
return value
OK: Call succeeded.
EINVAL: Illegal process or signal number.
EPERM: Cannot send a signal to a kernel task. PM cannot signal a user process
with a notification message.
library functions
int sys kill(int proc nr, int sig nr);
SYS MEMSET: Write a 4-byte pattern into the indicated memory area. The call is used
by the PM to zero the BSS segment on an exec() POSIX-call. The kernel is ask to
do the work for performance reasons.
request parameters
MEM PTR: Physical base address of the memory area.
MEM COUNT : Length in bytes of the memory area.
MEM PATTERN : The 4-byte pattern to be written.
return value
OK: Call always succeeds.
library functions
int sys memset(long pattern, phys bytes base, phys bytes length);
SYS NEWMAP: Install a new memory map for a newly forked process or if a process’
memory map is changed. The kernel fetches the new memory map from PM and
updates its data structures.
request parameters
PR PROC NR: Install new map for this process.
PR MEM PTR: Pointer to memory map at PM.
return value
OK: New map was successfully installed.
EFAULT: Incorrect address for new memory map.
EINVAL: Invalid process number.
library functions
int sys newmap(int proc nr, struct mem map *ptr);
SYS NICE: Change a process’ priority. This is done by passing a nice values between
PRIO MIN (negative) and PRIO MAX (positive). A nice value of zero resets the priority
to the default.
request parameters
PR PROC NR: Process who’s priority should be changed
PR PRIORITY : New nice value for process’ priority
9
return value
OK: New priority was successfully set.
EINVAL: Invalid process number or priority.
EPERM: Cannot change priority of kernel task.
library functions
int sys nice(int proc nr, int priority);
SYS PHYSCOPY: Copy data using physical addressing. The source and/ or destination
address can be virtual like with SYS VIRCOPY, but in addition an arbitrary physical
address is accepted with PHYS SEG.
request parameters
CP SRC SPACE : Source segment.
CP SRC ADDR: Virtual source address
CP SRC PROC NR: Process number of the source process.
CP DST SPACE : Destination segment.
CP DST ADDR: Virtual destination address
CP DST PROC NR: Process number of the destination process.
CP NR BYTES : Number of bytes to copy.
return value
OK: The copying was done.
EDOM: Invalid copy count.
EFAULT: Virtual to physical mapping failed.
EINVAL: Incorrect segment type or process number.
EPERM: Only owner of REMOTE SEG can copy to or from it.
library functions
int sys abscopy(phys bytes src phys, phys bytes dst phys, phys bytes count);
int sys physcopy(int src proc, int src seg, vir bytes src vir, int dst proc, int dst seg, vir bytes
dst vir, phys bytes count);
SYS PHYSVCOPY: Copy multiple block of data using physical addressing. The request vec-
tor is fetched from the caller, and each element is handled like a regular SYS PHYSCOPY
request. Copying continues until all elements have been processed or an error oc-
curs.
request parameters
VCP VEC SIZE : Number of elements in request vector.
VCP VEC ADDR: Virtual address of request vector at caller.
response parameters
VCP NR OK : Number of elements successfully copied.
return value
OK: The copying was done.
EDOM: Invalid copy count.
EFAULT: Virtual to physical mapping failed.
EINVAL: Copy vector too large, incorrect segment or invalid process.
EPERM: Only owner of REMOTE SEG can copy to or from it.
10
library functions
int sys physvcopy(phys cp req *copy vec, int vec size, int *nr ok);
SYS PRIVCTL: Get a private privilege structure and update a process’ privileges. This is
used to dynamically start system services.
request parameters
CTL PROC NR: Process who’s privileges should be updated.
return value
OK: The calls succeeded.
EINVAL: Invalid process number.
ENOSPC: No free privilege structure found.
remarks
This system call will be extended to provide both better support and security checks
for servers or device drivers that must be dynamically loaded. This is future work.
library functions
-
SYS SDEVIO: Perform device I/O on behalf of a user-space device driver. Note that this
call supports only byte and word granularity. The driver can request input or
output of an entire buffer. Also see the SYS DEVIO and SYS VDEVIO kernel calls.
request parameters
DIO REQUEST : Input or output.
SYS SEGCTL: Add a memory segment to the process’ LDT and its remote memory map.
The call returns a selector and offset that can be used to directly reach the remote
segment, as well as an index into the remote memory map that can be used with
the SYS VIRCOPY kernel call.
request parameters
SEG PHYS : Physical base address of segment.
SEG SIZE : Size of segment.
response parameters
SEG INDEX : Index into remote memory map.
SEG SELECT : Segment selector for LDT entry.
SEG OFFSET : Offset within segment. Zero, unless 4K granularity is used.
return value
ENOSPC: No free slot in remote memory map and LDT.
OK: Segment descriptor successfully added.
library functions
int sys segctl(int *index, u16 t *seg, vir bytes *off, phys bytes phys, vir bytes size);
SYS SIGRETURN: Return from a POSIX-style signal handler. The PM requests the kernel
to put things in order before the signalled process can resume execution. Also see
the SYS SIGSEND kernel call that pushes a signal context frame onto the stack.
request parameters
SIG PROC : Indicates the process that was signaled.
SIG CTXT PTR: Pointer to context structure for POSIX-style signal handling.
response parameters
SIG PROC : Return next process with pending signals or NONE.
return value
OK: Signal handling action successfully performed.
EINVAL: Invalid process number or context structure.
EFAULT: Invalid context structure address, or could not copy signal frame.
library functions
int sys sigreturn(int proc nr, struct sigmsg *sig context);
SYS SIGSEND: Signal a process on behalf of the PM by placing the context structure onto
the stack. The kernel fetches the structure, initializes it, and copies it to the user’s
stack.
request parameters
SIG PROC : Indicates the process that was signaled.
SIG CTXT PTR: Pointer to context structure for POSIX-style signal handling.
response parameters
SIG PROC : Return next process with pending signals or NONE.
12
return value
OK: Signal handling action successfully performed.
EINVAL: Invalid process number.
EPERM: Cannot signal kernel tasks.
EFAULT: Invalid context structure address, or could not copy signal frame.
library functions
int sys sigsend(int proc nr, struct sigmsg *sig context);
SYS SETALARM : Set or reset a synchronous alarm timer. When the timer expires it causes
a SYN ALARM notification message with the current uptime as an argument to be
sent to the caller. Only system processes can request synchronous alarms.
request parameters
ALRM EXP TIME : Absolute or relative expiration time in ticks for this alarm.
ALRM ABS TIME : Zero if expire time is relative to the current uptime.
response parameters
ALRM TIME LEFT : Ticks left on the previous alarm.
return value
OK: The alarm was successfully set.
EPERM: User processes cannot request alarms.
library functions
int sys setalarm(clock t expire time, int abs flag);
SYS TIMES: Get the kernel’s uptime since boot and process execution times.
request parameters
T PROC NR: The process to get the time information for, or NONE.
response parameters
T USER TIME : Process’ user time in ticks, if valid number.
T SYSTEM TIME : Process’ system time in ticks, if valid number.
T BOOT TICKS : Number of ticks since MINIX boot.
return value
OK: Always succeeds.
library functions
int sys times(int proc nr, clock t *ptr);
SYS TRACE: Monitor or control execution of the given process. Handle the debugging
commands supported by the ptrace() system call.
request parameters
CTL REQUEST : The tracing request.
SYS UMAP: Map a virtual address to a physical address and return the physical address.
The virtual address can be in LOCAL SEG, REMOTE SEG, or BIOS SEG. An offset in
bytes can be passed to verify whether this also falls within the segment.
request parameters
CP SRC PROC NR: Process number of the address relates to.
CP SRC SPACE : Segment identifier.
CP SRC ADDR: Offset within segment.
CP NR BYTES : Number of bytes from start.
response parameters
CP DST ADDR: Physical address if mapping succeeded.
return value
OK: The copying was done.
EFAULT: Virtual to physical mapping failed.
EINVAL: Incorrect segment type or process number.
remarks
Address zero within BIOS SEG returns EFAULT, while it the zeroth BIOS interrupt
vector in fact is a valid address.
library functions
int sys umap(int proc nr, int seg, vir bytes vir addr, vir bytes count, phys bytes *phys addr);
SYS VDEVIO: Perform a series of device I/O on behalf of a user process. The call accepts
a pointer to an array of (port,value)-pairs that is to be handeld at once. Hardware
interrupts are temporarily disabled to prevented the bactch of I/O calls to be
interrupted. Also see SYS DEVIO and SYS SDEVIO.
request parameters
DIO REQUEST : Input or output.
14
SYS VIRCOPY: Copy data using virtual addressing. The virtual can be in three segments:
LOCAL SEG (text, stack, data segments), REMOTE SEG (e.g., RAM disk, video mem-
ory), and the BIOS SEG (BIOS interrupt vectors, BIOS data area). This is the most
common system call relating to copying.
request parameters
CP SRC SPACE : Source segment.
CP SRC ADDR: Virtual source address
CP SRC PROC NR: Process number of the source process.
CP DST SPACE : Destination segment.
CP DST ADDR: Virtual destination address
CP DST PROC NR: Process number of the destination process.
CP NR BYTES : Number of bytes to copy.
return value
OK: The copying was done.
EDOM: Invalid copy count.
EFAULT: Virtual to physical mapping failed.
EPERM: No permission to use PHYS SEG.
EINVAL: Incorrect segment type or process number.
EPERM: Only owner of REMOTE SEG can copy to or from it.
library functions
int sys biosin(vir bytes bios vir, vir bytes dst vir, vir bytes bytes);
int sys biosout(vir bytes src vir, vir bytes bios vir, vir bytes bytes);
int sys datacopy(vir bytes src proc, vir bytes src vir, dst proc, dst vir, vir bytes bytes);
int sys textcopy(vir bytes src proc, vir bytes src vir, dst proc, dst vir, vir bytes bytes);
15
int sys stackcopy(vir bytes src proc, vir bytes src vir, dst proc, dst vir, vir bytes bytes);
int sys vircopy(int src proc, int src seg, vir bytes src vir, int dst proc, int dst seg, vir bytes dst vir,
phys bytes bytes);
SYS VIRVCOPY: Copy multiple blocks of data using virtual addressing. The request vector
is fetched from the caller, and each element is handled like a regular SYS VIRCOPY
request. Copying continues until all elements have been processed or an error
occurs.
request parameters
VCP VEC SIZE : Number of elements in request vector.
VCP VEC ADDR: Virtual address of request vector at caller.
response parameters
VCP VEC OK : Number of elements successfully copied.
return value
OK: The copying was done.
EDOM: Invalid copy count.
EFAULT: Virtual to physical mapping failed.
EPERM: No permission to use PHYS SEG.
EINVAL: Copy vector too large, incorrect segment or invalid process.
EPERM: Only owner of REMOTE SEG can copy to or from it.
library functions
int sys virvcopy(vir cp req *copy vec, int vec size, int *nr ok);