1 .\" Copyright (c) 1980, 1991, 1993
2 .\" The Regents of the University of California. All rights reserved.
4 .\" SPDX-License-Identifier: BSD-4-Clause-UC
6 .\" @(#)syscall.2 8.1 (Berkeley) 6/16/93
9 .\" 2002-03-20 Christoph Hellwig <hch@infradead.org>
10 .\" - adopted for Linux
11 .\" 2015-01-17, Kees Cook <keescook@chromium.org>
12 .\" Added mips and arm64.
14 .TH SYSCALL 2 2021-03-22 "Linux" "Linux Programmer's Manual"
16 syscall \- indirect system call
19 .RI ( libc ", " \-lc )
22 .BR "#include <sys/syscall.h>" " /* Definition of " SYS_* " constants */"
23 .B #include <unistd.h>
25 .BI "long syscall(long " number ", ...);"
29 Feature Test Macro Requirements for glibc (see
30 .BR feature_test_macros (7)):
38 _BSD_SOURCE || _SVID_SOURCE
42 is a small library function that invokes
43 the system call whose assembly language
44 interface has the specified
46 with the specified arguments.
49 is useful, for example,
50 when invoking a system call that has no wrapper function in the C library.
53 saves CPU registers before making the system call,
54 restores the registers upon return from the system call,
55 and stores any error returned by the system call in
58 Symbolic constants for system call numbers can be found in the header file
61 The return value is defined by the system call being invoked.
62 In general, a 0 return value indicates success.
63 A \-1 return value indicates an error,
64 and an error number is stored in
70 .SS Architecture-specific requirements
71 Each architecture ABI has its own requirements on how
72 system call arguments are passed to the kernel.
73 For system calls that have a glibc wrapper (e.g., most system calls),
74 glibc handles the details of copying arguments to the right registers
75 in a manner suitable for the architecture.
78 to make a system call,
79 the caller might need to handle architecture-dependent details;
80 this requirement is most commonly encountered on certain 32-bit architectures.
82 For example, on the ARM architecture Embedded ABI (EABI), a
85 must be aligned to an even register pair.
88 instead of the wrapper provided by glibc,
91 system call would be invoked as follows on the ARM architecture with the EABI
92 in little endian mode:
96 syscall(SYS_readahead, fd, 0,
97 (unsigned int) (offset & 0xFFFFFFFF),
98 (unsigned int) (offset >> 32),
103 Since the offset argument is 64 bits, and the first argument
107 the caller must manually split and align the 64-bit value
108 so that it is passed in the
111 That means inserting a dummy value into
113 (the second argument of 0).
114 Care also must be taken so that the split follows endian conventions
115 (according to the C ABI for the platform).
117 Similar issues can occur on MIPS with the O32 ABI,
118 on PowerPC and parisc with the 32-bit ABI, and on Xtensa.
119 .\" Mike Frysinger: this issue ends up forcing MIPS
120 .\" O32 to take 7 arguments to syscall()
122 .\" See arch/parisc/kernel/sys_parisc.c.
123 Note that while the parisc C ABI also uses aligned register pairs,
124 it uses a shim layer to hide the issue from user space.
126 The affected system calls are
127 .BR fadvise64_64 (2),
129 .BR posix_fadvise (2),
133 .BR sync_file_range (2),
137 .\" You need to look up the syscalls directly in the kernel source to see if
138 .\" they should be in this list. For example, look at fs/read_write.c and
139 .\" the function signatures that do:
140 .\" ..., unsigned long, pos_l, unsigned long, pos_h, ...
141 .\" If they use off_t, then they most likely do not belong in this list.
142 This does not affect syscalls that manually split and assemble 64-bit values
150 Welcome to the wonderful world of historical baggage.
151 .SS Architecture calling conventions
152 Every architecture has its own way of invoking and passing arguments to the
154 The details for various architectures are listed in the two tables below.
156 The first table lists the instruction used to transition to kernel mode
157 (which might not be the fastest or best way to transition to the kernel,
158 so you might have to refer to
160 the register used to indicate the system call number,
161 the register(s) used to return the system call result,
162 and the register used to signal an error.
168 Arch/ABI Instruction System Ret Ret Error Notes
171 alpha callsys v0 v0 a4 a3 1, 6
173 arm/OABI swi NR - r0 - - 2
174 arm/EABI swi 0x0 r7 r0 r1 -
175 arm64 svc #0 w8 x0 x1 -
176 blackfin excpt 0x0 P0 R0 - -
177 i386 int $0x80 eax eax edx -
178 ia64 break 0x100000 r15 r8 r9 r10 1, 6
179 m68k trap #0 d0 d0 - -
180 microblaze brki r14,8 r12 r3 - -
181 mips syscall v0 v0 v1 a3 1, 6
182 nios2 trap r2 r2 - r7
183 parisc ble 0x100(%sr2, %r0) r20 r28 - -
184 powerpc sc r0 r3 - r0 1
185 powerpc64 sc r0 r3 - cr0.SO 1
186 riscv ecall a7 a0 a1 -
187 s390 svc 0 r1 r2 r3 - 3
188 s390x svc 0 r1 r2 r3 - 3
189 superh trapa #31 r3 r0 r1 - 4, 6
190 sparc/32 t 0x10 g1 o0 o1 psr/csr 1, 6
191 sparc/64 t 0x6d g1 o0 o1 psr/csr 1, 6
192 tile swint1 R10 R00 - R01 1
193 x86-64 syscall rax rax rdx - 5
194 x32 syscall rax rax rdx - 5
195 xtensa syscall a2 a2 - -
200 On a few architectures,
201 a register is used as a boolean
202 (0 indicating no error, and \-1 indicating an error) to signal that the
204 The actual error value is still contained in the return register.
205 On sparc, the carry bit
207 in the processor status register
209 is used instead of a full register.
210 On powerpc64, the summary overflow bit
212 in field 0 of the condition register
217 is the system call number.
221 (the system call number) may be passed directly with
223 if it is less than 256.
225 On SuperH additional trap numbers are supported for historic reasons, but
227 is the recommended "unified" ABI.
229 The x32 ABI shares syscall table with x86-64 ABI, but there are some
233 In order to indicate that a system call is called under the x32 ABI,
235 .BR __X32_SYSCALL_BIT ,
236 is bitwise-ORed with the system call number.
237 The ABI used by a process affects some process behaviors,
238 including signal handling or system call restarting.
240 Since x32 has different sizes for
242 and pointer types, layouts of some (but not all;
246 are 64-bit, for example) structures are different.
247 In order to handle this,
248 additional system calls are added to the system call table,
249 starting from number 512
251 .BR __X32_SYSCALL_BIT ).
254 is defined as 19 for the x86-64 ABI and as
255 .IR __X32_SYSCALL_BIT " | " \fB515\fP
257 Most of these additional system calls are actually identical
258 to the system calls used for providing i386 compat.
259 There are some notable exceptions, however, such as
263 entities with 4-byte pointers and sizes ("compat_iovec" in kernel terms),
266 argument in a single register and not two, as is done in every other ABI.
270 (namely, Alpha, IA-64, MIPS, SuperH, sparc/32, and sparc/64)
271 use an additional register ("Retval2" in the above table)
272 to pass back a second return value from the
275 Alpha uses this technique in the architecture-specific
280 system calls as well.
281 Other architectures do not use the second return value register
282 in the system call interface, even if it is defined in the System V ABI.
288 The second table shows the registers used to pass the system call arguments.
293 l l2 l2 l2 l2 l2 l2 l2 l.
294 Arch/ABI arg1 arg2 arg3 arg4 arg5 arg6 arg7 Notes
296 alpha a0 a1 a2 a3 a4 a5 -
297 arc r0 r1 r2 r3 r4 r5 -
298 arm/OABI r0 r1 r2 r3 r4 r5 r6
299 arm/EABI r0 r1 r2 r3 r4 r5 r6
300 arm64 x0 x1 x2 x3 x4 x5 -
301 blackfin R0 R1 R2 R3 R4 R5 -
302 i386 ebx ecx edx esi edi ebp -
303 ia64 out0 out1 out2 out3 out4 out5 -
304 m68k d1 d2 d3 d4 d5 a0 -
305 microblaze r5 r6 r7 r8 r9 r10 -
306 mips/o32 a0 a1 a2 a3 - - - 1
307 mips/n32,64 a0 a1 a2 a3 a4 a5 -
308 nios2 r4 r5 r6 r7 r8 r9 -
309 parisc r26 r25 r24 r23 r22 r21 -
310 powerpc r3 r4 r5 r6 r7 r8 r9
311 powerpc64 r3 r4 r5 r6 r7 r8 -
312 riscv a0 a1 a2 a3 a4 a5 -
313 s390 r2 r3 r4 r5 r6 r7 -
314 s390x r2 r3 r4 r5 r6 r7 -
315 superh r4 r5 r6 r7 r0 r1 r2
316 sparc/32 o0 o1 o2 o3 o4 o5 -
317 sparc/64 o0 o1 o2 o3 o4 o5 -
318 tile R00 R01 R02 R03 R04 R05 -
319 x86-64 rdi rsi rdx r10 r8 r9 -
320 x32 rdi rsi rdx r10 r8 r9 -
321 xtensa a6 a3 a4 a5 a8 a9 -
326 The mips/o32 system call convention passes
327 arguments 5 through 8 on the user stack.
333 Note that these tables don't cover the entire calling convention\(emsome
334 architectures may indiscriminately clobber other registers not listed here.
336 .\" SRC BEGIN (syscall.c)
340 #include <sys/syscall.h>
348 tid = syscall(SYS_gettid);
349 syscall(SYS_tgkill, getpid(), tid, SIGHUP);