OSDN Git Service

571a290522b37779aac022f3138aa9871e260622
[linuxjm/LDP_man-pages.git] / release / 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 .\"*******************************************************************
41 .\"
42 .\" This file was generated with po4a. Translate the source file.
43 .\"
44 .\"*******************************************************************
45 .TH SYSCALL 2 2013\-04\-07 Linux "Linux Programmer's Manual"
46 .SH 名前
47 syscall \- 間接システムコール
48 .SH 書式
49 .nf
50 \fB#define _GNU_SOURCE\fP         /* feature_test_macros(7) 参照 */
51 \fB#include <unistd.h>\fP
52 \fB#include <sys/syscall.h>   \fP/* SYS_xxx の定義用 */
53
54 \fBint syscall(int \fP\fInumber\fP\fB, ...);\fP
55 .fi
56 .SH 説明
57 \fBsyscall\fP() は、システムコールを起動する小さなライブラリ関数で、 \fInumber\fP
58 で指定されたアセンブリ言語インターフェースのシステムコールを、指定された引き数をつけて実行する。 \fBsyscall\fP() が役に立つのは、例えば C
59 ライブラリにラッパー関数が存在しないシステムコールを呼び出したい場合である。
60
61 \fBsyscall\fP() は、システムコールを行う前に CPU
62 レジスタを保存し、システムコールから返った際にレジスタを復元し、エラーが発生した場合はシステムコールが返したエラーコードを \fBerrno\fP(3)
63 に格納する。
64
65 システムコールのシンボル定数は、ヘッダファイル \fI<sys/syscall.h>\fP に書かれている。
66 .SH 返り値
67 返り値は呼び出されたシステムコールによって定義される。 一般に、返り値 0 は成功を表す。 \-1 はエラーを表し、エラーコードは \fIerrno\fP
68 に入れられる。
69 .SH 注意
70 \fBsyscall\fP()  は 4BSD で最初に登場した。
71 .SS アーキテクチャ固有の要件
72 Each architecture ABI has its own requirements on how system call arguments
73 are passed to the kernel.  For system calls that have a glibc wrapper (e.g.,
74 most system calls), glibc handles the details of copying arguments to the
75 right registers in a manner suitable for the architecture.  However, when
76 using \fBsyscall\fP()  to make a system call, the caller might need to handle
77 architecture\-dependent details; this requirement is most commonly
78 encountered on certain 32\-bit architectures.
79
80 例えば、ARM アーキテクチャの Embedded ABI (EABI) では、 (\fIlong long\fP などの) 64
81 ビット値は偶数番地のレジスタのペアに境界があっていなければならない。したがって、 glibc が提供するラッパー関数ではなく \fBsyscall\fP()
82 を使う場合には、 \fBreadahead\fP() システムコールは ARM アーキテクチャの EABI では以下のようにして起動されることになる。
83
84 .in +4n
85 .nf
86 syscall(SYS_readahead, fd, 0,
87         (unsigned int) (offset >> 32),
88         (unsigned int) (offset & 0xFFFFFFFF),
89         count);
90 .fi
91 .in
92 .PP
93 オフセット引き数は 64 ビットで、最初の引き数 (\fIfd\fP) は \fIr0\fP で渡されるので、呼び出し側では手動で 64
94 ビット値を分割して境界を合わせて、 64 ビット値が \fIr2\fP/\fIr3\fP レジスタペアで渡されるようにしなければならない。このため、 \fIr1\fP
95 (2 番目の引数 0) としてダミー値を挿入している。
96
97 .\" Mike Frysinger: this issue ends up forcing MIPS
98 .\" O32 to take 7 arguments to syscall()
99 同様のことが、 MIPS の O32 ABI、 PowerPC の 32 ビット ABI や Xtensa でも起こりうる。
100
101 次のシステムコールに影響がある: \fBfadvise64_64\fP(2), \fBftruncate64\fP(2), \fBposix_fadvise\fP(2),
102 \fBpread64\fP(2), \fBpwrite64\fP(2), \fBreadahead\fP(2), \fBsync_file_range\fP(2),
103 \fBtruncate64\fP(2)
104 .SS "Architecture calling conventions"
105 Every architecture has its own way of invoking and passing arguments to the
106 kernel.  The details for various architectures are listed in the two tables
107 below.
108
109 The first table lists the instruction used to transition to kernel mode,
110 (which might not be the fastest or best way to transition to the kernel, so
111 you might have to refer to the VDSO), the register used to indicate the
112 system call number, and the register used to return the system call result.
113 .if  t \{\
114 .ft CW
115 \}
116 .TS
117 l l1 l l1 l.
118 arch/ABI        instruction     syscall #       retval  Notes
119 _
120 arm/OABI        swi NR  \-      a1      NR is syscall #
121 arm/EABI        swi 0x0 r7      r1
122 blackfin        excpt 0x0       P0      R0
123 i386    int $0x80       eax     eax
124 ia64    break 0x100000  r15     r10/r8
125 parisc  ble 0x100(%sr2, %r0)    r20     r28
126 sparc/32        t 0x10  g1      o0
127 sparc/64        t 0x6d  g1      o0      
128 x86_64  syscall rax     rax
129 .TE
130 .if  t \{\
131 .in
132 .ft P
133 \}
134 .PP
135 The second table shows the registers used to pass the system call arguments.
136 .if  t \{\
137 .ft CW
138 \}
139 .TS
140 l l l l l l l l.
141 arch/ABI        arg1    arg2    arg3    arg4    arg5    arg6    arg7
142 _
143 arm/OABI        a1      a2      a3      a4      v1      v2      v3
144 arm/EABI        r1      r2      r3      r4      r5      r6      r7
145 blackfin        R0      R1      R2      R3      R4      R5      \-
146 i386    ebx     ecx     edx     esi     edi     ebp     \-
147 ia64    r11     r9      r10     r14     r15     r13     \-
148 parisc  r26     r25     r24     r23     r22     r21     \-
149 sparc/32        o0      o1      o2      o3      o4      o5      \-
150 sparc/64        o0      o1      o2      o3      o4      o5      \-
151 x86_64  rdi     rsi     rdx     r10     r8      r9      \-
152 .TE
153 .if  t \{\
154 .in
155 .ft P
156 \}
157 .PP
158 Note that these tables don't cover the entire calling convention\(emsome
159 architectures may indiscriminately clobber other registers not listed here.
160 .SH 例
161 .nf
162 #define _GNU_SOURCE
163 #include <unistd.h>
164 #include <sys/syscall.h>
165 #include <sys/types.h>
166
167 int
168 main(int argc, char *argv[])
169 {
170     pid_t tid;
171
172     tid = syscall(SYS_gettid);
173     tid = syscall(SYS_tgkill, getpid(), tid);
174 }
175 .fi
176 .SH 関連項目
177 \fB_syscall\fP(2), \fBintro\fP(2), \fBsyscalls\fP(2)
178 .SH この文書について
179 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.51 の一部
180 である。プロジェクトの説明とバグ報告に関する情報は
181 http://www.kernel.org/doc/man\-pages/ に書かれている。