xref: /dflybsd-src/share/man/man9/syscall.9 (revision a80d996eb7f40dcdc03cc43e6ac44a810659156d)
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.\"
26*a80d996eSSascha Wildner.Dd September 17, 2015
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
59948bb6a2SSascha Wildner.D1 Cd number type ...
60ccab178bSStathis Kamperis.Pp
61ccab178bSStathis KamperisWhere:
62948bb6a2SSascha Wildner.Bl -tag -width number -compact
63ccab178bSStathis Kamperis.It number
64ccab178bSStathis Kamperisis the system call number;
65ccab178bSStathis Kamperis.It type
66ccab178bSStathis Kamperisis one of:
67ccab178bSStathis Kamperis.Bl -tag -width NOPROTO -compact
68ccab178bSStathis Kamperis.It STD
69ccab178bSStathis Kamperisstandard system call with full prototype and implementation;
70ccab178bSStathis Kamperis.It OBSOL
71ccab178bSStathis Kamperisobsolete, not included in the system;
72ccab178bSStathis Kamperis.It UNIMPL
73ccab178bSStathis Kamperisunimplemented, not included in the system, placeholder only;
74ccab178bSStathis Kamperis.It NODEF
75ccab178bSStathis Kamperisincluded, but don't define the syscall number;
76ccab178bSStathis Kamperis.It NOARGS
77ccab178bSStathis Kamperisincluded, but don't define the syscall args structure;
78ccab178bSStathis Kamperis.It NOPROTO
79ccab178bSStathis Kamperisimplemented elsewhere;
80ccab178bSStathis Kamperis.It COMPAT
81ccab178bSStathis Kamperisa compatibility system call, only included if the corresponding
82ccab178bSStathis Kamperisoption is configured for the kernel.
83ccab178bSStathis Kamperis.El
84ccab178bSStathis Kamperis.El
85ccab178bSStathis Kamperis.Pp
86ccab178bSStathis KamperisThe rest of the line for the STD, NODEF, NOARGS, and COMPAT
87ccab178bSStathis Kamperistypes is:
88ccab178bSStathis Kamperis.Pp
89ccab178bSStathis Kamperis.D1 Cd { pseudo-proto } [alias]
90ccab178bSStathis Kamperis.Pp
91ccab178bSStathis Kamperis.Nm pseudo-proto
92ccab178bSStathis Kamperisis a C-like prototype used to generate the system call argument list,
93ccab178bSStathis Kamperisand alias is an optional name alias for the call.
94ccab178bSStathis KamperisThe function in the prototype has to be defined somewhere in
95ccab178bSStathis Kamperisthe kernel sources as it will be used as an entry point for
96ccab178bSStathis Kamperisthe corresponding system call.
97ccab178bSStathis Kamperis.Pp
98ccab178bSStathis KamperisFor other types the rest of the line is a comment.
99ccab178bSStathis Kamperis.Pp
100ccab178bSStathis KamperisTo generate the header and code files from the
101ccab178bSStathis Kamperis.Dq master
102ccab178bSStathis Kamperisfile,
103ccab178bSStathis Kamperis.Li make sysent
104ccab178bSStathis Kamperishas to be run from the directory containing the
105ccab178bSStathis Kamperis.Dq master
106ccab178bSStathis Kamperisfile.
107ccab178bSStathis KamperisPlease mind that the string
108ccab178bSStathis Kamperis.Li sys_
109ccab178bSStathis Kamperisis prepended to all system call names, but not to the structures
110ccab178bSStathis Kamperisholding the arguments.
111ccab178bSStathis KamperisSo, if one has added the line:
112ccab178bSStathis Kamperis.Bd -literal
113ccab178bSStathis Kamperis503	STD	BSD	{ int mycall(int x, int y); }
114ccab178bSStathis Kamperis.Ed
115ccab178bSStathis Kamperis.Pp
116ccab178bSStathis Kamperisto the system call master file, the generated prototype would be:
117bc5a8594SSascha Wildner.Pp
118bc5a8594SSascha Wildner.Ft int
119bc5a8594SSascha Wildner.Fn sys_mycall "struct mycall_args *uap" ;
120ccab178bSStathis Kamperis.Pp
121ccab178bSStathis KamperisIt is customary to extract system call arguments with the
122bc5a8594SSascha Wildner.Fn SCARG uap member
123ccab178bSStathis Kamperismacro, which is defined in
124ccab178bSStathis Kamperis.Pa sys/sys/sysent.h
125ccab178bSStathis Kamperisfile.
126ccab178bSStathis KamperisLast, in order to return a value to userland, the
127bc5a8594SSascha Wildner.Fa uap->sysmsg_result
128ccab178bSStathis Kamperisvariable and friends of it are used, as defined in
129ccab178bSStathis Kamperis.Pa sys/sys/sysmsg.h .
130f2589c6cSSascha Wildner.Sh IMPLEMENTATION NOTES
131f2589c6cSSascha WildnerIn the kernel, a syscall is implemented by a
132f2589c6cSSascha Wildner.Fn sys_syscallname
133f2589c6cSSascha Wildnerfunction.
134f2589c6cSSascha WildnerIn userspace, the function that executes a syscall is automatically generated
135f2589c6cSSascha Wildnerusing the description in
136f2589c6cSSascha Wildner.Pa syscalls.master .
137f2589c6cSSascha WildnerThe symbols in the
138f2589c6cSSascha Wildner.Lb libc
139f2589c6cSSascha Wildnerare assembly wrappers generated in
140*a80d996eSSascha Wildner.Pa lib/libc/${MACHINE_ARCH} Pq e.g.\& x86_64 ,
141f2589c6cSSascha Wildneragain using the description in
142f2589c6cSSascha Wildner.Pa syscalls.master .
143f2589c6cSSascha WildnerThese wrappers use macros provided by the platform-dependent
144f2589c6cSSascha Wildner.In SYS.h
145f2589c6cSSascha Wildnerheader file which take care of putting the syscall arguments into registers
146*a80d996eSSascha Wildner(per the ABI specification) and inserting a
147f2589c6cSSascha Wildner.Li syscall
148f2589c6cSSascha Wildnerinstruction (on x86_64).
149ccab178bSStathis Kamperis.Sh FILES
150ccab178bSStathis Kamperis.Bl -tag -width sys/kern/syscalls.master -compact
151ccab178bSStathis Kamperis.It Pa sys/kern/makesyscalls.sh
152ccab178bSStathis Kamperisa
153ccab178bSStathis Kamperis.Xr sh 1
154ccab178bSStathis Kamperisscript for generating C files out of the syscall master file;
155ccab178bSStathis Kamperis.It Pa sys/kern/syscalls.conf
156ccab178bSStathis Kamperisa configuration file for the shell script above;
157ccab178bSStathis Kamperis.It Pa sys/kern/syscalls.master
158ccab178bSStathis Kamperismaster files describing names and numbers for the system calls;
159ccab178bSStathis Kamperis.It Pa sys/kern/syscalls.c
160ccab178bSStathis Kamperissystem call names lists;
161ccab178bSStathis Kamperis.It Pa sys/kern/init_sysent.c
162ccab178bSStathis Kamperissystem call switch tables;
163ccab178bSStathis Kamperis.It Pa sys/sys/sysproto.h
164ccab178bSStathis Kamperissystem call argument lists;
165ccab178bSStathis Kamperis.It Pa sys/sys/syscall.h
166ccab178bSStathis Kamperissystem call numbers.
167*a80d996eSSascha Wildner.\".It Pa sys/emulation/linux/i386
168*a80d996eSSascha Wildner.\"Linux emulation system calls.
169ccab178bSStathis Kamperis.El
170ccab178bSStathis Kamperis.Sh SEE ALSO
171ccab178bSStathis Kamperis.Xr ktrace 2 ,
172ccab178bSStathis Kamperis.Xr syscall 2 ,
173ccab178bSStathis Kamperis.Xr SYSCALL_MODULE 9
174ccab178bSStathis Kamperis.Sh HISTORY
175ccab178bSStathis KamperisThe
176ccab178bSStathis Kamperis.Nm
177ccab178bSStathis Kamperissection manual page appeared in
178ccab178bSStathis Kamperis.Dx 2.3 .
179