OSDN Git Service

83856f7c4a0b5752390fa6a94f72611b5494dba1
[linuxjm/LDP_man-pages.git] / draft / man3 / getcontext.3
1 .\" Copyright (C) 2001 Andries Brouwer (aeb@cwi.nl)
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .\"*******************************************************************
26 .\"
27 .\" This file was generated with po4a. Translate the source file.
28 .\"
29 .\"*******************************************************************
30 .TH GETCONTEXT 3 2009\-03\-15 Linux "Linux Programmer's Manual"
31 .SH 名前
32 getcontext, setcontext \- ユーザコンテキストを取得/設定する
33 .SH 書式
34 \fB#include <ucontext.h>\fP
35 .sp
36 \fBint getcontext(ucontext_t *\fP\fIucp\fP\fB);\fP
37 .br
38 \fBint setcontext(const ucontext_t *\fP\fIucp\fP\fB);\fP
39 .SH 説明
40 System V 的な環境では、 \fImcontext_t\fP および \fIucontext_t\fP という 2 つの型と、
41 \fBgetcontext\fP(), \fBsetcontext\fP(), \fBmakecontext\fP(3), \fBswapcontext\fP(3)  という
42 4 つの関数が \fI<ucontext.h>\fP で定義されており、あるプロセス内部で制御下にある複数のスレッド間で、
43 ユーザレベルのコンテキスト切替えができるようになっている。
44 .LP
45 \fImcontext_t\fP 型はマシン依存で、外部からは隠蔽されている。 \fIucontext_t\fP 型は構造体で、少なくとも以下の 4
46 つのフィールドを持つ。
47 .in +4
48 .nf
49
50 typedef struct ucontext {
51     struct ucontext *uc_link;
52     sigset_t         uc_sigmask;
53     stack_t          uc_stack;
54     mcontext_t       uc_mcontext;
55     ...
56 } ucontext_t;
57
58 .fi
59 .in
60 \fIsigset_t\fP と \fIstack_t\fP は \fI<signal.h>\fP で定義されている。 ここで \fIuc_link\fP は、
61 現在のコンテキストが終了したとき、 続いて切り替わるコンテキストへのポインタである (現在のコンテキストが \fBmakecontext\fP(3)
62 で生成されたものの場合)。 \fIuc_sigmask\fP はこのコンテキストでブロックされている シグナル群である (\fBsigprocmask\fP(2)
63 を見よ)。 \fIuc_stack\fP はこのコンテキストが用いているスタックである (\fBsignalstack\fP(2)  を見よ)。
64 \fIuc_mcontext\fP は保存されているコンテキストの マシン特有の表現形式であり、 ここには呼び出したスレッドのマシンレジスタが格納される。
65 .LP
66 \fBgetcontext\fP()  関数は、 ポインタ \fIucp\fP が指す構造体を、 現在アクティブなコンテキストに初期化する。
67 .LP
68 \fBsetcontext\fP()  関数は、ポインタ \fIucp\fP が指すユーザコンテキストをリストアする。 呼び出しに成功すると返らない。
69 このコンテキストは、以前に \fBgetcontext\fP()  または \fBmakecontext\fP(3)  で得られたものか、
70 あるいはシグナルの第三引数として与えられたものになる。
71 .LP
72 コンテキストが \fBgetcontext\fP()  の呼び出しによって得られていたものの場合は、
73 プログラムはこの呼び出しから返った直後からのように実行を継続する。
74 .LP
75 コンテキストが \fBmakecontext\fP(3)  の呼び出しによって得られていたものの場合は、 プログラムの実行はその
76 \fBmakecontext\fP(3)  呼び出しの第二引数で指定された関数 \fIfunc\fP を呼び出すかたちで継続する。 \fIfunc\fP から返ると、
77 \fBmakecontext\fP(3)  呼び出しの第一引数で指定されていた \fIucp\fP 構造体の \fIuc_link\fP メンバで継続する。 このメンバが
78 NULL だった場合は、そのスレッドは終了する。
79 .LP
80 コンテキストがシグナルハンドラの呼び出しによって得られていたものの場合は、 古い標準によれば
81 「プログラムの実行はシグナルによって割り込まれた命令の次の命令から継続される」。 しかしこの文は SUSv2 で削除されたので、
82 現在の判断は「結果は定義されていない」である。
83 .SH 返り値
84 成功すると、 \fBgetcontext\fP()  は 0 を返し、 \fBsetcontext\fP()  は返らない。 失敗すると、両者とも \-1
85 を返し、\fIerrno\fP をエラーに応じて設定する。
86 .SH エラー
87 定義されていない。
88 .SH 準拠
89 SUSv2, POSIX.1\-2001.  POSIX.1\-2008 では、移植性の問題から \fBgetcontext\fP()  の仕様が削除された。
90 代わりに、アプリケーションを POSIX スレッドを使って書き直すことが 推奨されている。
91 .SH 注意
92 このメカニズムの最古の実装は、 \fBsetjmp\fP(3)/\fBlongjmp\fP(3)  機構であった。
93 これらにはシグナルコンテキストの取り扱いが定義されていなかったので、 次の段階では \fBsigsetjmp\fP(3)/\fBsiglongjmp\fP(3)
94 のペアが現われた。 現在の機構ではずっと細かな制御ができる。 一方 \fBgetcontext\fP()  から返ったとき、 これが最初の呼び出しであったか、
95 それとも \fBsetcontext\fP()  呼び出しからのものであるかを 区別する容易な方法がなくなってしまった。
96 ユーザは「しおり」機構を自分で作らなければならない。 レジスタ変数は (レジスタはリストアされてしまうので) これをやってくれない。
97 .LP
98 シグナルが発生すると、 現在のユーザコンテキストは保存され、 シグナルハンドラ用のコンテキストがカーネルによって生成される。 今後はハンドラに
99 \fBlongjmp\fP(3)  を使わせないこと: この関数のコンテキスト下での動作は定義されていない。 代わりに \fBsiglongjmp\fP(3)  か
100 \fBsetcontext\fP()  を使うこと。
101 .SH 関連項目
102 \fBsigaction\fP(2), \fBsigaltstack\fP(2), \fBsigprocmask\fP(2), \fBlongjmp\fP(3),
103 \fBmakecontext\fP(3), \fBsigsetjmp\fP(3)
104 .SH この文書について
105 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.52 の一部
106 である。プロジェクトの説明とバグ報告に関する情報は
107 http://www.kernel.org/doc/man\-pages/ に書かれている。