1ccab178bSStathis Kamperis.\" $OpenBSD: syscall.9,v 1.7 2007/05/31 19:20:01 jmc Exp $ 2ccab178bSStathis Kamperis.\" 3ccab178bSStathis Kamperis.\" Copyright (c) 2003 Michael Shalayeff 4ccab178bSStathis Kamperis.\" 5ccab178bSStathis Kamperis.\" Redistribution and use in source and binary forms, with or without 6ccab178bSStathis Kamperis.\" modification, are permitted provided that the following conditions 7ccab178bSStathis Kamperis.\" are met: 8ccab178bSStathis Kamperis.\" 1. Redistributions of source code must retain the above copyright 9ccab178bSStathis Kamperis.\" notice, this list of conditions and the following disclaimer. 10ccab178bSStathis Kamperis.\" 2. Redistributions in binary form must reproduce the above copyright 11ccab178bSStathis Kamperis.\" notice, this list of conditions and the following disclaimer in the 12ccab178bSStathis Kamperis.\" documentation and/or other materials provided with the distribution. 13ccab178bSStathis Kamperis.\" 14ccab178bSStathis Kamperis.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 15ccab178bSStathis Kamperis.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16ccab178bSStathis Kamperis.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17ccab178bSStathis Kamperis.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 18ccab178bSStathis Kamperis.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19ccab178bSStathis Kamperis.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20ccab178bSStathis Kamperis.\" OR SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21ccab178bSStathis Kamperis.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22ccab178bSStathis Kamperis.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23ccab178bSStathis Kamperis.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24ccab178bSStathis Kamperis.\" SUCH DAMAGE. 25ccab178bSStathis Kamperis.\" 26ccab178bSStathis Kamperis.Dd May 25, 2009 27ccab178bSStathis Kamperis.Dt SYSCALL 9 28ccab178bSStathis Kamperis.Os 29ccab178bSStathis Kamperis.Sh NAME 30ccab178bSStathis Kamperis.Nm syscall 31ccab178bSStathis Kamperis.Nd "system calls overview" 32ccab178bSStathis Kamperis.Sh DESCRIPTION 33ccab178bSStathis KamperisA system call is an explicit request to the kernel made via a software 34ccab178bSStathis Kamperisinterrupt by some program. 35ccab178bSStathis KamperisFor example, 36ccab178bSStathis Kamperis.Fn open 37ccab178bSStathis Kamperisis a system call that is used when access to a file stored in filesystem 38ccab178bSStathis Kamperisis needed. 39ccab178bSStathis KamperisIn this sense, system calls provide the interface between a process and the 40ccab178bSStathis Kamperisoperating system. 41ccab178bSStathis Kamperis.Pp 42ccab178bSStathis KamperisThe kernel implements system calls through a set of switch tables 43ccab178bSStathis Kamperisfor each emulation type. 44ccab178bSStathis KamperisThe list of currently supported system calls along with their codes resides in 45ccab178bSStathis Kamperis.Pa sys/sys/syscall.h . 46ccab178bSStathis KamperisThis file, and a couple others which will be examined later, are 47ccab178bSStathis Kamperisautomatically generated and should not be edited manually. 48ccab178bSStathis Kamperis.Pp 49ccab178bSStathis KamperisThe first step in adding a new system call is to edit the 50a263c9acSSascha Wildner.Pa sys/kern/syscalls.master 51ccab178bSStathis Kamperisfile. 52ccab178bSStathis KamperisThe 53ccab178bSStathis Kamperis.Dq master 54ccab178bSStathis Kamperisfile is a text file consisting of a list of lines for each 55ccab178bSStathis Kamperissystem call. 56ccab178bSStathis KamperisLines may be split by the means of back slashing the end of the line. 57ccab178bSStathis KamperisEach line is a set of fields separated by whitespace: 58ccab178bSStathis Kamperis.Pp 59ccab178bSStathis Kamperis.D1 Cd number type namespace ... 60ccab178bSStathis Kamperis.Pp 61ccab178bSStathis KamperisWhere: 62ccab178bSStathis Kamperis.Bl -tag -width namespace -compact 63ccab178bSStathis Kamperis.It number 64ccab178bSStathis Kamperisis the system call number; 65ccab178bSStathis Kamperis.It namespace 66ccab178bSStathis Kamperisis one of POSIX, BSD, NOHIDE; 67ccab178bSStathis Kamperis.It type 68ccab178bSStathis Kamperisis one of: 69ccab178bSStathis Kamperis.Bl -tag -width NOPROTO -compact 70ccab178bSStathis Kamperis.It STD 71ccab178bSStathis Kamperisstandard system call with full prototype and implementation; 72ccab178bSStathis Kamperis.It OBSOL 73ccab178bSStathis Kamperisobsolete, not included in the system; 74ccab178bSStathis Kamperis.It UNIMPL 75ccab178bSStathis Kamperisunimplemented, not included in the system, placeholder only; 76ccab178bSStathis Kamperis.It NODEF 77ccab178bSStathis Kamperisincluded, but don't define the syscall number; 78ccab178bSStathis Kamperis.It NOARGS 79ccab178bSStathis Kamperisincluded, but don't define the syscall args structure; 80ccab178bSStathis Kamperis.It NOPROTO 81ccab178bSStathis Kamperisimplemented elsewhere; 82ccab178bSStathis Kamperis.It COMPAT 83ccab178bSStathis Kamperisa compatibility system call, only included if the corresponding 84ccab178bSStathis Kamperisoption is configured for the kernel. 85ccab178bSStathis Kamperis.El 86ccab178bSStathis Kamperis.El 87ccab178bSStathis Kamperis.Pp 88ccab178bSStathis KamperisThe rest of the line for the STD, NODEF, NOARGS, and COMPAT 89ccab178bSStathis Kamperistypes is: 90ccab178bSStathis Kamperis.Pp 91ccab178bSStathis Kamperis.D1 Cd { pseudo-proto } [alias] 92ccab178bSStathis Kamperis.Pp 93ccab178bSStathis Kamperis.Nm pseudo-proto 94ccab178bSStathis Kamperisis a C-like prototype used to generate the system call argument list, 95ccab178bSStathis Kamperisand alias is an optional name alias for the call. 96ccab178bSStathis KamperisThe function in the prototype has to be defined somewhere in 97ccab178bSStathis Kamperisthe kernel sources as it will be used as an entry point for 98ccab178bSStathis Kamperisthe corresponding system call. 99ccab178bSStathis Kamperis.Pp 100ccab178bSStathis KamperisFor other types the rest of the line is a comment. 101ccab178bSStathis Kamperis.Pp 102ccab178bSStathis KamperisTo generate the header and code files from the 103ccab178bSStathis Kamperis.Dq master 104ccab178bSStathis Kamperisfile, 105ccab178bSStathis Kamperis.Li make sysent 106ccab178bSStathis Kamperishas to be run from the directory containing the 107ccab178bSStathis Kamperis.Dq master 108ccab178bSStathis Kamperisfile. 109ccab178bSStathis KamperisPlease mind that the string 110ccab178bSStathis Kamperis.Li sys_ 111ccab178bSStathis Kamperisis prepended to all system call names, but not to the structures 112ccab178bSStathis Kamperisholding the arguments. 113ccab178bSStathis KamperisSo, if one has added the line: 114ccab178bSStathis Kamperis.Bd -literal 115ccab178bSStathis Kamperis503 STD BSD { int mycall(int x, int y); } 116ccab178bSStathis Kamperis.Ed 117ccab178bSStathis Kamperis.Pp 118ccab178bSStathis Kamperisto the system call master file, the generated prototype would be: 119*bc5a8594SSascha Wildner.Pp 120*bc5a8594SSascha Wildner.Ft int 121*bc5a8594SSascha Wildner.Fn sys_mycall "struct mycall_args *uap" ; 122ccab178bSStathis Kamperis.Pp 123ccab178bSStathis KamperisIt is customary to extract system call arguments with the 124*bc5a8594SSascha Wildner.Fn SCARG uap member 125ccab178bSStathis Kamperismacro, which is defined in 126ccab178bSStathis Kamperis.Pa sys/sys/sysent.h 127ccab178bSStathis Kamperisfile. 128ccab178bSStathis KamperisLast, in order to return a value to userland, the 129*bc5a8594SSascha Wildner.Fa uap->sysmsg_result 130ccab178bSStathis Kamperisvariable and friends of it are used, as defined in 131ccab178bSStathis Kamperis.Pa sys/sys/sysmsg.h . 132ccab178bSStathis Kamperis.Sh FILES 133ccab178bSStathis Kamperis.Bl -tag -width sys/kern/syscalls.master -compact 134ccab178bSStathis Kamperis.It Pa sys/kern/makesyscalls.sh 135ccab178bSStathis Kamperisa 136ccab178bSStathis Kamperis.Xr sh 1 137ccab178bSStathis Kamperisscript for generating C files out of the syscall master file; 138ccab178bSStathis Kamperis.It Pa sys/kern/syscalls.conf 139ccab178bSStathis Kamperisa configuration file for the shell script above; 140ccab178bSStathis Kamperis.It Pa sys/kern/syscalls.master 141ccab178bSStathis Kamperismaster files describing names and numbers for the system calls; 142ccab178bSStathis Kamperis.It Pa sys/kern/syscalls.c 143ccab178bSStathis Kamperissystem call names lists; 144ccab178bSStathis Kamperis.It Pa sys/kern/init_sysent.c 145ccab178bSStathis Kamperissystem call switch tables; 146ccab178bSStathis Kamperis.It Pa sys/sys/sysproto.h 147ccab178bSStathis Kamperissystem call argument lists; 148ccab178bSStathis Kamperis.It Pa sys/sys/syscall.h 149ccab178bSStathis Kamperissystem call numbers. 150ccab178bSStathis Kamperis.It Pa sys/emulation/linux/i386 151ccab178bSStathis KamperisLinux emulation system calls. 152ccab178bSStathis Kamperis.El 153ccab178bSStathis Kamperis.Sh SEE ALSO 154ccab178bSStathis Kamperis.Xr ktrace 2 , 155ccab178bSStathis Kamperis.Xr syscall 2 , 156ccab178bSStathis Kamperis.Xr SYSCALL_MODULE 9 157ccab178bSStathis Kamperis.Sh HISTORY 158ccab178bSStathis KamperisThe 159ccab178bSStathis Kamperis.Nm 160ccab178bSStathis Kamperissection manual page appeared in 161ccab178bSStathis Kamperis.Dx 2.3 . 162