1 .\" Copyright (C) 2001 Andries Brouwer (aeb@cwi.nl)
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date. The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein. The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" Japanese Version Copyright (c) 2001 NAKANO Takeo all rights reserved.
24 .\" Translated Sat Dec 15 2001 by NAKANO Takeo <nakano@apm.seikei.ac.jp>
25 .\" Updated 2009-04-13, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v3.20
27 .TH GETCONTEXT 2 2009-03-15 "Linux" "Linux Programmer's Manual"
29 getcontext, setcontext \- ユーザコンテキストを取得/設定する
31 .B #include <ucontext.h>
33 .BI "int getcontext(ucontext_t *" ucp );
35 .BI "int setcontext(const ucontext_t *" ucp );
38 \fImcontext_t\fP および \fIucontext_t\fP という 2 つの型と、
45 で定義されており、あるプロセス内部で制御下にある複数のスレッド間で、
46 ユーザレベルのコンテキスト切替えができるようになっている。
48 \fImcontext_t\fP 型はマシン依存で、外部からは隠蔽されている。
49 \fIucontext_t\fP 型は構造体で、少なくとも以下の 4 つのフィールドを持つ。
53 typedef struct ucontext {
54 struct ucontext *uc_link;
57 mcontext_t uc_mcontext;
63 \fIsigset_t\fP と \fIstack_t\fP は
68 続いて切り替わるコンテキストへのポインタである
72 \fIuc_sigmask\fP はこのコンテキストでブロックされている
76 \fIuc_stack\fP はこのコンテキストが用いているスタックである
79 \fIuc_mcontext\fP は保存されているコンテキストの
81 ここには呼び出したスレッドのマシンレジスタが格納される。
85 ポインタ \fIucp\fP が指す構造体を、
90 \fIucp\fP が指すユーザコンテキストをリストアする。
97 あるいはシグナルの第三引数として与えられたものになる。
101 の呼び出しによって得られていたものの場合は、
102 プログラムはこの呼び出しから返った直後からのように実行を継続する。
106 の呼び出しによって得られていたものの場合は、
109 呼び出しの第二引数で指定された関数 \fIfunc\fP
114 \fIucp\fP 構造体の \fIuc_link\fP メンバで継続する。
115 このメンバが NULL だった場合は、そのスレッドは終了する。
117 コンテキストがシグナルハンドラの呼び出しによって得られていたものの場合は、
119 「プログラムの実行はシグナルによって割り込まれた命令の次の命令から継続される」。
120 しかしこの文は SUSv2 で削除されたので、
121 現在の判断は「結果は定義されていない」である。
128 失敗すると、両者とも \-1 を返し、\fIerrno\fP をエラーに応じて設定する。
133 POSIX.1-2008 では、移植性の問題から
136 代わりに、アプリケーションを POSIX スレッドを使って書き直すことが
140 .BR setjmp (3)/ longjmp (3)
142 これらにはシグナルコンテキストの取り扱いが定義されていなかったので、
144 .BR sigsetjmp (3)/ siglongjmp (3)
155 ユーザは「しおり」機構を自分で作らなければならない。
156 レジスタ変数は (レジスタはリストアされてしまうので) これをやってくれない。
160 シグナルハンドラ用のコンテキストがカーネルによって生成される。
164 この関数のコンテキスト下での動作は定義されていない。