2004-11-03 13:51:07 +00:00
|
|
|
.\" Copyright (c) 1980, 1991, 1993
|
|
|
|
.\" The Regents of the University of California. All rights reserved.
|
|
|
|
.\"
|
accept.2, bind.2, connect.2, getpeername.2, getpriority.2, getsockname.2, getsockopt.2, ioctl.2, killpg.2, listen.2, lseek.2, readlink.2, recv.2, send.2, setpgid.2, setreuid.2, shutdown.2, socket.2, socketpair.2, syscall.2, truncate.2, alloca.3, btree.3, daemon.3, dbopen.3, err.3, exec.3, fclose.3, ferror.3, fflush.3, fopen.3, fread.3, fseek.3, fts.3, hash.3, mpool.3, popen.3, queue.3, rcmd.3, recno.3, rexec.3, scanf.3, setbuf.3, stdarg.3, stdio.3, strtod.3, hostname.7, mdoc.7, mdoc.samples.7: srcfix: LICENSE: s/BSD_4_CLAUSE_FULL/BSD_4_CLAUSE_UCB/
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2013-03-10 16:41:19 +00:00
|
|
|
.\" %%%LICENSE_START(BSD_4_CLAUSE_UCB)
|
2004-11-03 13:51:07 +00:00
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
|
|
.\" 3. All advertising materials mentioning features or use of this software
|
|
|
|
.\" must display the following acknowledgement:
|
|
|
|
.\" This product includes software developed by the University of
|
|
|
|
.\" California, Berkeley and its contributors.
|
|
|
|
.\" 4. Neither the name of the University nor the names of its contributors
|
|
|
|
.\" may be used to endorse or promote products derived from this software
|
|
|
|
.\" without specific prior written permission.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
.\" SUCH DAMAGE.
|
accept.2, bind.2, connect.2, getpeername.2, getpriority.2, getsockname.2, getsockopt.2, ioctl.2, killpg.2, listen.2, lseek.2, readlink.2, recv.2, send.2, setpgid.2, setreuid.2, shutdown.2, socket.2, socketpair.2, syscall.2, truncate.2, alloca.3, btree.3, daemon.3, dbopen.3, err.3, exec.3, fclose.3, ferror.3, fflush.3, fopen.3, fread.3, fseek.3, fts.3, getloadavg.3, hash.3, mpool.3, openpty.3, popen.3, queue.3, rcmd.3, recno.3, rexec.3, scanf.3, setbuf.3, stdarg.3, stdio.3, strtod.3, hostname.7, mdoc.7, mdoc.samples.7, operator.7, symlink.7: Add LICENSE_START(BSD_[34]_CLAUSE_FULL)
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2013-03-10 09:28:48 +00:00
|
|
|
.\" %%%LICENSE_END
|
2004-11-03 13:51:07 +00:00
|
|
|
.\"
|
|
|
|
.\" @(#)syscall.2 8.1 (Berkeley) 6/16/93
|
|
|
|
.\"
|
|
|
|
.\"
|
|
|
|
.\" 2002-03-20 Christoph Hellwig <hch@infradead.org>
|
|
|
|
.\" - adopted for Linux
|
2015-01-18 07:22:04 +00:00
|
|
|
.\" 2015-01-17, Kees Cook <keescook@chromium.org>
|
|
|
|
.\" Added mips and arm64.
|
2004-11-03 13:51:07 +00:00
|
|
|
.\"
|
intro.1, ldd.1, clone.2, getgroups.2, getpid.2, getsockopt.2, ioctl_list.2, msgop.2, open.2, seccomp.2, setgid.2, setresuid.2, setreuid.2, setuid.2, sigaction.2, sigpending.2, sigprocmask.2, sigreturn.2, sigsuspend.2, sigwaitinfo.2, socket.2, syscall.2, syscalls.2, umount.2, clock.3, dlopen.3, fmemopen.3, fpathconf.3, fputwc.3, fputws.3, fseek.3, fseeko.3, gcvt.3, getline.3, getwchar.3, hypot.3, if_nameindex.3, initgroups.3, popen.3, resolver.3, strcoll.3, strdup.3, tzset.3, ulimit.3, wcstombs.3, wctob.3, xdr.3, console_codes.4, random.4, filesystems.5, host.conf.5, hosts.5, proc.5, resolv.conf.5, securetty.5, credentials.7, feature_test_macros.7, hier.7, ipv6.7, packet.7, pthreads.7, raw.7, signal.7, tcp.7, user_namespaces.7, ld.so.8, ldconfig.8: tstamp
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2015-03-29 16:52:05 +00:00
|
|
|
.TH SYSCALL 2 2015-03-29 "Linux" "Linux Programmer's Manual"
|
2007-05-26 14:10:51 +00:00
|
|
|
.SH NAME
|
|
|
|
syscall \- indirect system call
|
|
|
|
.SH SYNOPSIS
|
|
|
|
.nf
|
getresuid.2, mremap.2, poll.2, remap_file_pages.2, setresuid.2, splice.2, sync_file_range.2, syscall.2, tee.2, vmsplice.2, INFINITY.3, aio_init.3, asprintf.3, assert_perror.3, basename.3, bsd_signal.3, canonicalize_file_name.3, clog10.3, crypt.3, dl_iterate_phdr.3, dlopen.3, encrypt.3, exp10.3, fcloseall.3, fenv.3, fopencookie.3, ftw.3, getaddrinfo_a.3, getloadavg.3, getutent.3, grantpt.3, hsearch.3, lseek64.3, memmem.3, mempcpy.3, pow10.3, program_invocation_name.3, ptsname.3, putgrent.3, sched_getcpu.3, sincos.3, strchr.3, strfry.3, strnlen.3, strptime.3, strstr.3, strverscmp.3, swab.3, sysv_signal.3, tsearch.3, unlockpt.3, wcwidth.3: Add reference to feature_test_macros(7)
Some pages simply list feature test macro requirements in
the form:
#define #GNU_SOURCE
#include <someheader.h>
For these pages, add a "See feature_test_macros(7)" comment
on the "#define" line.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-10-31 04:31:47 +00:00
|
|
|
.BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
|
2007-05-26 14:10:51 +00:00
|
|
|
.B #include <unistd.h>
|
2007-07-08 12:11:40 +00:00
|
|
|
.BR "#include <sys/syscall.h> " "/* For SYS_xxx definitions */"
|
2007-05-26 14:10:51 +00:00
|
|
|
|
2014-04-30 19:42:42 +00:00
|
|
|
.BI "long syscall(long " number ", ...);"
|
2007-05-26 14:10:51 +00:00
|
|
|
.fi
|
|
|
|
.SH DESCRIPTION
|
|
|
|
.BR syscall ()
|
2012-07-13 06:07:19 +00:00
|
|
|
is a small library function that invokes
|
|
|
|
the system call whose assembly language
|
2004-11-03 13:51:07 +00:00
|
|
|
interface has the specified
|
2007-05-26 14:10:51 +00:00
|
|
|
.I number
|
2004-11-03 13:51:07 +00:00
|
|
|
with the specified arguments.
|
2012-07-13 06:07:19 +00:00
|
|
|
Employing
|
|
|
|
.BR syscall ()
|
|
|
|
is useful, for example,
|
|
|
|
when invoking a system call that has no wrapper function in the C library.
|
|
|
|
|
|
|
|
.BR syscall ()
|
|
|
|
saves CPU registers before making the system call,
|
|
|
|
restores the registers upon return from the system call,
|
|
|
|
and stores any error code returned by the system call in
|
|
|
|
.BR errno (3)
|
|
|
|
if an error occurs.
|
|
|
|
|
|
|
|
Symbolic constants for system call numbers can be found in the header file
|
2007-05-26 14:10:51 +00:00
|
|
|
.IR <sys/syscall.h> .
|
|
|
|
.SH RETURN VALUE
|
2004-11-03 13:51:07 +00:00
|
|
|
The return value is defined by the system call being invoked.
|
|
|
|
In general, a 0 return value indicates success.
|
2005-06-15 14:10:23 +00:00
|
|
|
A \-1 return value indicates an error,
|
2004-11-03 13:51:07 +00:00
|
|
|
and an error code is stored in
|
2007-05-26 14:10:51 +00:00
|
|
|
.IR errno .
|
|
|
|
.SH NOTES
|
|
|
|
.BR syscall ()
|
|
|
|
first appeared in
|
|
|
|
4BSD.
|
2013-04-01 09:09:33 +00:00
|
|
|
.SS Architecture-specific requirements
|
2013-04-01 06:24:53 +00:00
|
|
|
Each architecture ABI has its own requirements on how
|
|
|
|
system call arguments are passed to the kernel.
|
|
|
|
For system calls that have a glibc wrapper (e.g., most system calls),
|
2013-04-01 09:09:33 +00:00
|
|
|
glibc handles the details of copying arguments to the right registers
|
2013-04-01 06:24:53 +00:00
|
|
|
in a manner suitable for the architecture.
|
2013-04-01 06:08:37 +00:00
|
|
|
However, when using
|
|
|
|
.BR syscall ()
|
|
|
|
to make a system call,
|
2013-04-01 09:09:33 +00:00
|
|
|
the caller might need to handle architecture-dependent details;
|
|
|
|
this requirement is most commonly encountered on certain 32-bit architectures.
|
2013-04-01 06:08:37 +00:00
|
|
|
|
2013-04-01 09:09:33 +00:00
|
|
|
For example, on the ARM architecture Embedded ABI (EABI), a
|
|
|
|
64-bit value (e.g.,
|
|
|
|
.IR "long long" )
|
|
|
|
must be aligned to an even register pair.
|
|
|
|
Thus, using
|
|
|
|
.BR syscall ()
|
|
|
|
instead of the wrapper provided by glibc,
|
|
|
|
the
|
2013-04-01 06:08:37 +00:00
|
|
|
.BR readahead ()
|
2013-04-01 07:33:11 +00:00
|
|
|
system call would be invoked as follows on the ARM architecture with the EABI:
|
2013-04-01 06:08:37 +00:00
|
|
|
|
2013-04-01 06:24:53 +00:00
|
|
|
.in +4n
|
|
|
|
.nf
|
2013-04-01 09:09:33 +00:00
|
|
|
syscall(SYS_readahead, fd, 0,
|
|
|
|
(unsigned int) (offset >> 32),
|
|
|
|
(unsigned int) (offset & 0xFFFFFFFF),
|
|
|
|
count);
|
2013-04-01 06:24:53 +00:00
|
|
|
.fi
|
|
|
|
.in
|
|
|
|
.PP
|
2013-04-01 09:09:33 +00:00
|
|
|
Since the offset argument is 64 bits, and the first argument
|
|
|
|
.RI ( fd )
|
|
|
|
is passed in
|
|
|
|
.IR r0 ,
|
2013-04-02 07:08:21 +00:00
|
|
|
the caller must manually split and align the 64-bit value
|
|
|
|
so that it is passed in the
|
2013-04-01 09:09:33 +00:00
|
|
|
.IR r2 / r3
|
|
|
|
register pair.
|
|
|
|
That means inserting a dummy value into
|
|
|
|
.I r1
|
|
|
|
(the second argument of 0).
|
|
|
|
|
|
|
|
Similar issues can occur on MIPS with the O32 ABI,
|
|
|
|
on PowerPC with the 32-bit ABI, and on Xtensa.
|
|
|
|
.\" Mike Frysinger: this issue ends up forcing MIPS
|
|
|
|
.\" O32 to take 7 arguments to syscall()
|
|
|
|
|
2013-04-01 07:33:11 +00:00
|
|
|
The affected system calls are
|
2013-04-01 09:09:33 +00:00
|
|
|
.BR fadvise64_64 (2),
|
|
|
|
.BR ftruncate64 (2),
|
|
|
|
.BR posix_fadvise (2),
|
|
|
|
.BR pread64 (2),
|
|
|
|
.BR pwrite64 (2),
|
|
|
|
.BR readahead (2),
|
|
|
|
.BR sync_file_range (2),
|
2013-04-01 07:33:11 +00:00
|
|
|
and
|
|
|
|
.BR truncate64 (2).
|
2013-04-08 09:16:52 +00:00
|
|
|
.SS Architecture calling conventions
|
|
|
|
Every architecture has its own way of invoking and passing arguments to the
|
|
|
|
kernel.
|
|
|
|
The details for various architectures are listed in the two tables below.
|
|
|
|
|
|
|
|
The first table lists the instruction used to transition to kernel mode,
|
|
|
|
(which might not be the fastest or best way to transition to the kernel,
|
2014-01-01 08:29:53 +00:00
|
|
|
so you might have to refer to
|
|
|
|
.BR vdso (7)),
|
2013-04-08 09:16:52 +00:00
|
|
|
the register used to indicate the system call number,
|
2015-01-18 11:47:58 +00:00
|
|
|
and the register used to return the system call result.
|
2013-04-08 09:16:52 +00:00
|
|
|
.if t \{\
|
|
|
|
.ft CW
|
|
|
|
\}
|
|
|
|
.TS
|
2015-01-18 11:47:58 +00:00
|
|
|
l l1 l l1 l.
|
|
|
|
arch/ABI instruction syscall # retval Notes
|
2013-04-08 09:16:52 +00:00
|
|
|
_
|
2015-01-18 11:47:58 +00:00
|
|
|
arm/OABI swi NR - a1 NR is syscall #
|
|
|
|
arm/EABI swi 0x0 r7 r0
|
|
|
|
arm64 svc #0 x8 x0
|
|
|
|
blackfin excpt 0x0 P0 R0
|
|
|
|
i386 int $0x80 eax eax
|
|
|
|
ia64 break 0x100000 r15 r8 See below
|
|
|
|
mips syscall v0 v0 See below
|
|
|
|
parisc ble 0x100(%sr2, %r0) r20 r28
|
|
|
|
s390 svc 0 r1 r2 See below
|
|
|
|
s390x svc 0 r1 r2 See below
|
|
|
|
sparc/32 t 0x10 g1 o0
|
|
|
|
sparc/64 t 0x6d g1 o0
|
2015-03-24 18:40:43 +00:00
|
|
|
x86_64 syscall rax rax See below
|
|
|
|
x32 syscall rax rax See below
|
2013-04-08 09:16:52 +00:00
|
|
|
.TE
|
2014-03-19 16:03:44 +00:00
|
|
|
.PP
|
|
|
|
For s390 and s390x, NR (the system call number)
|
|
|
|
may be passed directly with "svc NR" if it is less than 256.
|
2015-01-18 11:47:58 +00:00
|
|
|
|
2015-03-24 18:40:43 +00:00
|
|
|
The x32 ABI uses the same instruction as the x86_64 ABI and is used on
|
2015-03-29 16:08:27 +00:00
|
|
|
the same processors.
|
|
|
|
To differentiate between them, the bit mask
|
2015-03-24 18:40:43 +00:00
|
|
|
.I __X32_SYSCALL_BIT
|
2015-03-29 16:08:27 +00:00
|
|
|
is bitwise-ORed into the system call number for system calls
|
|
|
|
under the x32 ABI.
|
2015-03-24 18:40:43 +00:00
|
|
|
|
2015-01-18 11:47:58 +00:00
|
|
|
On a few architectures,
|
|
|
|
a register is used to indicate simple boolean failure of the system call:
|
|
|
|
ia64 uses
|
|
|
|
.I r10
|
|
|
|
for this purpose,
|
|
|
|
and mips uses
|
|
|
|
.IR a3 .
|
2013-04-08 09:16:52 +00:00
|
|
|
.if t \{\
|
|
|
|
.in
|
|
|
|
.ft P
|
|
|
|
\}
|
|
|
|
.PP
|
|
|
|
The second table shows the registers used to pass the system call arguments.
|
|
|
|
.if t \{\
|
|
|
|
.ft CW
|
|
|
|
\}
|
|
|
|
.TS
|
2015-03-29 20:28:37 +00:00
|
|
|
l l2 l2 l2 l2 l2 l2 l2 l.
|
|
|
|
arch/ABI arg1 arg2 arg3 arg4 arg5 arg6 arg7 Notes
|
2013-04-08 09:16:52 +00:00
|
|
|
_
|
2015-03-29 20:28:37 +00:00
|
|
|
arm/OABI a1 a2 a3 a4 v1 v2 v3
|
|
|
|
arm/EABI r0 r1 r2 r3 r4 r5 r6
|
|
|
|
arm64 x0 x1 x2 x3 x4 x5 -
|
|
|
|
blackfin R0 R1 R2 R3 R4 R5 -
|
|
|
|
i386 ebx ecx edx esi edi ebp -
|
|
|
|
ia64 out0 out1 out2 out3 out4 out5 -
|
|
|
|
mips/o32 a0 a1 a2 a3 - - - See below
|
|
|
|
mips/n32,64 a0 a1 a2 a3 a4 a5 -
|
|
|
|
parisc r26 r25 r24 r23 r22 r21 -
|
|
|
|
s390 r2 r3 r4 r5 r6 r7 -
|
|
|
|
s390x r2 r3 r4 r5 r6 r7 -
|
|
|
|
sparc/32 o0 o1 o2 o3 o4 o5 -
|
|
|
|
sparc/64 o0 o1 o2 o3 o4 o5 -
|
|
|
|
x86_64 rdi rsi rdx r10 r8 r9 -
|
|
|
|
x32 rdi rsi rdx r10 r8 r9 -
|
2013-04-08 09:16:52 +00:00
|
|
|
.TE
|
2015-01-18 07:22:04 +00:00
|
|
|
.PP
|
2015-01-18 18:55:41 +00:00
|
|
|
The mips/o32 system call convention passes
|
|
|
|
arguments 5 through 8 on the user stack.
|
2013-04-08 09:16:52 +00:00
|
|
|
.if t \{\
|
|
|
|
.in
|
|
|
|
.ft P
|
|
|
|
\}
|
|
|
|
.PP
|
|
|
|
Note that these tables don't cover the entire calling convention\(emsome
|
|
|
|
architectures may indiscriminately clobber other registers not listed here.
|
2007-05-26 14:10:51 +00:00
|
|
|
.SH EXAMPLE
|
|
|
|
.nf
|
|
|
|
#define _GNU_SOURCE
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/syscall.h>
|
|
|
|
#include <sys/types.h>
|
2013-08-09 07:33:51 +00:00
|
|
|
#include <signal.h>
|
2007-05-26 14:10:51 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
pid_t tid;
|
2007-12-25 16:11:05 +00:00
|
|
|
|
2007-07-08 17:00:49 +00:00
|
|
|
tid = syscall(SYS_gettid);
|
2013-08-09 07:33:51 +00:00
|
|
|
tid = syscall(SYS_tgkill, getpid(), tid, SIGHUP);
|
2007-05-26 14:10:51 +00:00
|
|
|
}
|
|
|
|
.fi
|
2007-06-25 12:57:55 +00:00
|
|
|
.SH SEE ALSO
|
2007-12-17 11:24:18 +00:00
|
|
|
.BR _syscall (2),
|
2008-07-14 15:52:21 +00:00
|
|
|
.BR intro (2),
|
2014-01-01 08:29:53 +00:00
|
|
|
.BR syscalls (2),
|
2014-11-04 07:19:25 +00:00
|
|
|
.BR errno (3),
|
2014-01-01 08:29:53 +00:00
|
|
|
.BR vdso (7)
|