OSDN Git Service

(split) LDP: Update original to LDP v3.50.
[linuxjm/LDP_man-pages.git] / original / man2 / syscall.2
1 .\" Copyright (c) 1980, 1991, 1993
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" %%%LICENSE_START(BSD_4_CLAUSE_UCB)
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
7 .\" are met:
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\"    notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\"    notice, this list of conditions and the following disclaimer in the
12 .\"    documentation and/or other materials provided with the distribution.
13 .\" 3. All advertising materials mentioning features or use of this software
14 .\"    must display the following acknowledgement:
15 .\"     This product includes software developed by the University of
16 .\"     California, Berkeley and its contributors.
17 .\" 4. Neither the name of the University nor the names of its contributors
18 .\"    may be used to endorse or promote products derived from this software
19 .\"    without specific prior written permission.
20 .\"
21 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 .\" SUCH DAMAGE.
32 .\" %%%LICENSE_END
33 .\"
34 .\"     @(#)syscall.2   8.1 (Berkeley) 6/16/93
35 .\"
36 .\"
37 .\" 2002-03-20  Christoph Hellwig <hch@infradead.org>
38 .\"     - adopted for Linux
39 .\"
40 .TH SYSCALL 2 2012-08-14 "Linux" "Linux Programmer's Manual"
41 .SH NAME
42 syscall \- indirect system call
43 .SH SYNOPSIS
44 .nf
45 .BR "#define _GNU_SOURCE" "         /* See feature_test_macros(7) */"
46 .B #include <unistd.h>
47 .BR "#include <sys/syscall.h>   "  "/* For SYS_xxx definitions */"
48
49 .BI "int syscall(int " number ", ...);"
50 .fi
51 .SH DESCRIPTION
52 .BR syscall ()
53 is a small library function that invokes
54 the system call whose assembly language
55 interface has the specified
56 .I number
57 with the specified arguments.
58 Employing
59 .BR syscall ()
60 is useful, for example,
61 when invoking a system call that has no wrapper function in the C library.
62
63 .BR syscall ()
64 saves CPU registers before making the system call,
65 restores the registers upon return from the system call,
66 and stores any error code returned by the system call in
67 .BR errno (3)
68 if an error occurs.
69
70 Symbolic constants for system call numbers can be found in the header file
71 .IR <sys/syscall.h> .
72 .SH RETURN VALUE
73 The return value is defined by the system call being invoked.
74 In general, a 0 return value indicates success.
75 A \-1 return value indicates an error,
76 and an error code is stored in
77 .IR errno .
78 .SH NOTES
79 .BR syscall ()
80 first appeared in
81 4BSD.
82 .SH EXAMPLE
83 .nf
84 #define _GNU_SOURCE
85 #include <unistd.h>
86 #include <sys/syscall.h>
87 #include <sys/types.h>
88
89 int
90 main(int argc, char *argv[])
91 {
92     pid_t tid;
93
94     tid = syscall(SYS_gettid);
95     tid = syscall(SYS_tgkill, getpid(), tid);
96 }
97 .fi
98 .SH SEE ALSO
99 .BR _syscall (2),
100 .BR intro (2),
101 .BR syscalls (2)