MirOS Manual: syscall(9)

SYSCALL(9)                    BSD Kernel Manual                     SYSCALL(9)


     syscall - system calls overview


     System calls in the kernel are implemented through a set of switch tables
     for each emulation type. Each table is generated from the "master" file
     by sys/kern/makesyscalls.sh through the appropriate rules in the

     The "master" file is a text file consisting of a list of lines for each
     system call. Lines may be split by the means of back slashing the end of
     the line. Each line is a set of fields separated by whitespace:

           number type ...

     number  is the system call number;
     type    is one of:
             STD         always included;
             OBSOL       obsolete, not included in the system;
             UNIMPL      unimplemented, not included in the system;
             NODEF       included, but don't define the syscall number;
             NOARGS      included, but don't define the syscall args struc-
             INDIR       included, but don't define the syscall args struc-
                         ture, and allow it to be "really" varargs;
             COMPAT_XX   a compatibility system call, only included if the
                         corresponding option is configured for the kernel
                         (see options(4)).

     The rest of the line for the STD, NODEF, NOARGS, and COMPAT_XX types is:

           { pseudo-proto } [alias]

     pseudo-proto is a C-like prototype used to generate the system call argu-
     ment list, and alias is an optional name alias for the call. The function
     in the prototype has to be defined somewhere in the kernel sources as it
     will be used as an entry point for the corresponding system call.

     For other types the rest of the line is a comment.

     To generate the header and code files from the "master" file a make(1)
     command has to be run from the directory containing the "master" file.


     Entry from the user space for the system call is machine dependent. Typi-
     cal code to invoke a system call from the machine dependent sources might
     look like this:

                   const struct sysent *callp;
                   register_t code, args[8], rval[2];
                   struct proc *p = curproc;
                   int code, nsys;


           /* ``code'' is the system call number passed from the user space */


           if (code < 0 || code >= nsys)
                   callp += p->p_emul->e_nosys;    /* illegal */
                   callp += code;

           /* copyin the arguments from the user space */

           #ifdef SYSCALL_DEBUG
                   scdebug_call(p, code, args);
           #ifdef KTRACE
                   if (KTRPOINT(p, KTR_SYSCALL))
                           ktrsyscall(p, code, argsize, args);
                   rval[0] = 0;
           #if NSYSTRACE > 0
                   if (ISSET(p->p_flag, P_SYSTRACE))
                           error = systrace_redirect(code, p, args, rval);
                           error = (*callp->sy_call)(p, args, rval);
                   switch (error) {
                   case 0:
                           /* normal return */
                   case ERESTART:
                            * adjust PC to point before the system call
                            * in the user space in order for the return
                            * back there we reenter the kernel to repeat
                            * the same system call
                   case EJUSTRETURN:
                           /* just return */
                            * an error returned:
                            *      call an optional emulation errno mapping
                            *      routine and return back to the user.
                           if (p->p_emul->e_errno)
                                   error = p->p_emul->e_errno[error];
           #ifdef SYSCALL_DEBUG
                   scdebug_ret(p, code, orig_error, rval);
                   userret(p, frame.tf_eip, sticks);
           #ifdef KTRACE
                   if (KTRPOINT(p, KTR_SYSRET))
                           ktrsysret(p, code, orig_error, rval[0]);

     The "SYSCALL_DEBUG" parts of the code are explained in the section
     Debugging later in the document. For the "KTRACE" portions of the code
     refer to the ktrace(9) document for further explanations. "NSYSTRACE" is
     a system call tracing facility and is explained in the systrace(9) and
     systrace(4) documents.


     For debugging purposes the line

           option SYSCALL_DEBUG

     should be included in the kernel configuration file (see options(4)).
     This allows tracing for calls, returns, and arguments for both implement-
     ed and non-implemented system calls. A global integer variable contains a
     mask for the desired logging events:

     SCDEBUG_CALLS       (0x0001) show calls;
     SCDEBUG_RETURNS     (0x0002) show returns;
     SCDEBUG_ALL         (0x0004) show even syscalls that are implemented;
     SCDEBUG_SHOWARGS    (0x0008) show arguments to calls.

     Use ddb(4) to set the "scdebug" to a value desired.


     sys/kern/makesyscalls.sh  a sh(1) script for generating C files out of
                               the syscall master file;
                               a configuration file for the shell script
                               master files describing names and numbers for
                               the system calls;
                               system call names lists;
                               system call switch tables;
                               system call argument lists;
                               system call numbers.


     ktrace(2), syscall(2), systrace(4), ktrace(9), systrace(9)


     The syscall section manual page appeared in OpenBSD 3.4.

MirOS BSD #10-current           July 21, 2003                                2

Generated on 2017-04-03 16:26:17 by $MirOS: src/scripts/roff2htm,v 1.88 2017/01/29 00:51:06 tg Exp $

These manual pages and other documentation are copyrighted by their respective writers; their source is available at our CVSweb, AnonCVS, and other mirrors. The rest is Copyright © 2002–2017 The MirOS Project, Germany.
This product includes material provided by mirabilos.

This manual page’s HTML representation is supposed to be valid XHTML/1.1; if not, please send a bug report — diffs preferred.