OSDN Git Service

(split) LDP v3.30, v3.31 の定型的な変更内容を反映。
[linuxjm/LDP_man-pages.git] / draft / man2 / getcontext.2
1 .\" Copyright (C) 2001 Andries Brouwer (aeb@cwi.nl)
2 .\"
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.
6 .\"
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.
11 .\"
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
18 .\" professionally.
19 .\"
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
22 .\"
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
26 .\"
27 .TH GETCONTEXT 2 2009-03-15 "Linux" "Linux Programmer's Manual"
28 .\"O .SH NAME
29 .\"O getcontext, setcontext \- get or set the user context
30 .SH Ì¾Á°
31 getcontext, setcontext \- ¥æ¡¼¥¶¥³¥ó¥Æ¥­¥¹¥È¤ò¼èÆÀ/ÀßÄꤹ¤ë
32 .\"O .SH SYNOPSIS
33 .SH ½ñ¼°
34 .B #include <ucontext.h>
35 .sp
36 .BI "int getcontext(ucontext_t *" ucp );
37 .br
38 .BI "int setcontext(const ucontext_t *" ucp );
39 .\"O .SH DESCRIPTION
40 .SH ÀâÌÀ
41 .\"O In a System V-like environment, one has the two types
42 .\"O \fImcontext_t\fP and \fIucontext_t\fP defined in
43 .\"O .I <ucontext.h>
44 .\"O and the four functions
45 .\"O .BR getcontext (),
46 .\"O .BR setcontext (),
47 .\"O .BR makecontext (3)
48 .\"O and
49 .\"O .BR swapcontext (3)
50 .\"O that allow user-level context switching between multiple
51 .\"O threads of control within a process.
52 System V Åª¤Ê´Ä¶­¤Ç¤Ï¡¢
53 \fImcontext_t\fP ¤ª¤è¤Ó \fIucontext_t\fP ¤È¤¤¤¦ 2 ¤Ä¤Î·¿¤È¡¢
54 .BR getcontext (),
55 .BR setcontext (),
56 .BR makecontext (3),
57 .BR swapcontext (3)
58 ¤È¤¤¤¦ 4 ¤Ä¤Î´Ø¿ô¤¬
59 .I <ucontext.h>
60 ¤ÇÄêµÁ¤µ¤ì¤Æ¤ª¤ê¡¢¤¢¤ë¥×¥í¥»¥¹ÆâÉô¤ÇÀ©¸æ²¼¤Ë¤¢¤ëÊ£¿ô¤Î¥¹¥ì¥Ã¥É´Ö¤Ç¡¢
61 ¥æ¡¼¥¶¥ì¥Ù¥ë¤Î¥³¥ó¥Æ¥­¥¹¥ÈÀÚÂؤ¨¤¬¤Ç¤­¤ë¤è¤¦¤Ë¤Ê¤Ã¤Æ¤¤¤ë¡£
62 .LP
63 .\"O The \fImcontext_t\fP type is machine-dependent and opaque.
64 .\"O The \fIucontext_t\fP type is a structure that has at least
65 .\"O the following fields:
66 \fImcontext_t\fP ·¿¤Ï¥Þ¥·¥ó°Í¸¤Ç¡¢³°Éô¤«¤é¤Ï±£Ê䵤ì¤Æ¤¤¤ë¡£
67 \fIucontext_t\fP ·¿¤Ï¹½Â¤ÂΤǡ¢¾¯¤Ê¤¯¤È¤â°Ê²¼¤Î 4 ¤Ä¤Î¥Õ¥£¡¼¥ë¥É¤ò»ý¤Ä¡£
68 .in +4
69 .nf
70
71 typedef struct ucontext {
72     struct ucontext *uc_link;
73     sigset_t         uc_sigmask;
74     stack_t          uc_stack;
75     mcontext_t       uc_mcontext;
76     ...
77 } ucontext_t;
78
79 .fi
80 .in
81 .\"O with \fIsigset_t\fP and \fIstack_t\fP defined in
82 .\"O .IR <signal.h> .
83 .\"O Here \fIuc_link\fP points to the context that will be resumed
84 .\"O when the current context terminates (in case the current context
85 .\"O was created using
86 .\"O .BR makecontext (3)),
87 .\"O \fIuc_sigmask\fP is the
88 .\"O set of signals blocked in this context (see
89 .\"O .BR sigprocmask (2)),
90 .\"O \fIuc_stack\fP is the stack used by this context (see
91 .\"O .BR sigaltstack (2)),
92 .\"O and \fIuc_mcontext\fP is the
93 .\"O machine-specific representation of the saved context,
94 .\"O that includes the calling thread's machine registers.
95 \fIsigset_t\fP ¤È \fIstack_t\fP ¤Ï
96 .I <signal.h>
97 ¤ÇÄêµÁ¤µ¤ì¤Æ¤¤¤ë¡£
98 ¤³¤³¤Ç \fIuc_link\fP ¤Ï¡¢
99 ¸½ºß¤Î¥³¥ó¥Æ¥­¥¹¥È¤¬½ªÎ»¤·¤¿¤È¤­¡¢
100 ³¤¤¤ÆÀÚ¤êÂؤï¤ë¥³¥ó¥Æ¥­¥¹¥È¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë
101 (¸½ºß¤Î¥³¥ó¥Æ¥­¥¹¥È¤¬
102 .BR makecontext (3)
103 ¤ÇÀ¸À®¤µ¤ì¤¿¤â¤Î¤Î¾ì¹ç)¡£
104 \fIuc_sigmask\fP ¤Ï¤³¤Î¥³¥ó¥Æ¥­¥¹¥È¤Ç¥Ö¥í¥Ã¥¯¤µ¤ì¤Æ¤¤¤ë
105 ¥·¥°¥Ê¥ë·²¤Ç¤¢¤ë
106 .RB ( sigprocmask (2)
107 ¤ò¸«¤è)¡£
108 \fIuc_stack\fP ¤Ï¤³¤Î¥³¥ó¥Æ¥­¥¹¥È¤¬ÍѤ¤¤Æ¤¤¤ë¥¹¥¿¥Ã¥¯¤Ç¤¢¤ë
109 .RB ( signalstack (2)
110 ¤ò¸«¤è)¡£
111 \fIuc_mcontext\fP ¤ÏÊݸ¤µ¤ì¤Æ¤¤¤ë¥³¥ó¥Æ¥­¥¹¥È¤Î
112 ¥Þ¥·¥óÆÃÍ­¤Îɽ¸½·Á¼°¤Ç¤¢¤ê¡¢
113 ¤³¤³¤Ë¤Ï¸Æ¤Ó½Ð¤·¤¿¥¹¥ì¥Ã¥É¤Î¥Þ¥·¥ó¥ì¥¸¥¹¥¿¤¬³ÊǼ¤µ¤ì¤ë¡£
114 .LP
115 .\"O The function
116 .\"O .BR getcontext ()
117 .\"O initializes the structure
118 .\"O pointed at by \fIucp\fP to the currently active context.
119 .BR getcontext ()
120 ´Ø¿ô¤Ï¡¢
121 ¥Ý¥¤¥ó¥¿ \fIucp\fP ¤¬»Ø¤¹¹½Â¤ÂΤò¡¢
122 ¸½ºß¥¢¥¯¥Æ¥£¥Ö¤Ê¥³¥ó¥Æ¥­¥¹¥È¤Ë½é´ü²½¤¹¤ë¡£
123 .LP
124 .\"O The function
125 .\"O .BR setcontext ()
126 .\"O restores the user context
127 .\"O pointed at by \fIucp\fP.
128 .\"O A successful call does not return.
129 .\"O The context should have been obtained by a call of
130 .\"O .BR getcontext (),
131 .\"O or
132 .\"O .BR makecontext (3),
133 .\"O or passed as third argument to a signal
134 .\"O handler.
135 .BR setcontext ()
136 ´Ø¿ô¤Ï¡¢¥Ý¥¤¥ó¥¿
137 \fIucp\fP ¤¬»Ø¤¹¥æ¡¼¥¶¥³¥ó¥Æ¥­¥¹¥È¤ò¥ê¥¹¥È¥¢¤¹¤ë¡£
138 ¸Æ¤Ó½Ð¤·¤ËÀ®¸ù¤¹¤ë¤ÈÊÖ¤é¤Ê¤¤¡£
139 ¤³¤Î¥³¥ó¥Æ¥­¥¹¥È¤Ï¡¢°ÊÁ°¤Ë
140 .BR getcontext ()
141 ¤Þ¤¿¤Ï
142 .BR makecontext (3)
143 ¤ÇÆÀ¤é¤ì¤¿¤â¤Î¤«¡¢
144 ¤¢¤ë¤¤¤Ï¥·¥°¥Ê¥ë¤ÎÂè»°°ú¿ô¤È¤·¤ÆÍ¿¤¨¤é¤ì¤¿¤â¤Î¤Ë¤Ê¤ë¡£
145 .LP
146 .\"O If the context was obtained by a call of
147 .\"O .BR getcontext (),
148 .\"O program execution continues as if this call just returned.
149 ¥³¥ó¥Æ¥­¥¹¥È¤¬
150 .BR getcontext ()
151 ¤Î¸Æ¤Ó½Ð¤·¤Ë¤è¤Ã¤ÆÆÀ¤é¤ì¤Æ¤¤¤¿¤â¤Î¤Î¾ì¹ç¤Ï¡¢
152 ¥×¥í¥°¥é¥à¤Ï¤³¤Î¸Æ¤Ó½Ð¤·¤«¤éÊ֤ä¿Ä¾¸å¤«¤é¤Î¤è¤¦¤Ë¼Â¹Ô¤ò·Ñ³¤¹¤ë¡£
153 .LP
154 .\"O If the context was obtained by a call of
155 .\"O .BR makecontext 3(),
156 .\"O program execution continues by a call to the function \fIfunc\fP
157 .\"O specified as the second argument of that call to
158 .\"O .BR makecontext (3).
159 .\"O When the function \fIfunc\fP returns, we continue with the
160 .\"O \fIuc_link\fP member of the structure \fIucp\fP specified as the
161 .\"O first argument of that call to
162 .\"O .BR makecontext (3).
163 .\"O When this member is NULL, the thread exits.
164 ¥³¥ó¥Æ¥­¥¹¥È¤¬
165 .BR makecontext (3)
166 ¤Î¸Æ¤Ó½Ð¤·¤Ë¤è¤Ã¤ÆÆÀ¤é¤ì¤Æ¤¤¤¿¤â¤Î¤Î¾ì¹ç¤Ï¡¢
167 ¥×¥í¥°¥é¥à¤Î¼Â¹Ô¤Ï¤½¤Î
168 .BR makecontext (3)
169 ¸Æ¤Ó½Ð¤·¤ÎÂèÆó°ú¿ô¤Ç»ØÄꤵ¤ì¤¿´Ø¿ô \fIfunc\fP
170 ¤ò¸Æ¤Ó½Ð¤¹¤«¤¿¤Á¤Ç·Ñ³¤¹¤ë¡£
171 \fIfunc\fP ¤«¤éÊÖ¤ë¤È¡¢
172 .BR makecontext (3)
173 ¸Æ¤Ó½Ð¤·¤ÎÂè°ì°ú¿ô¤Ç»ØÄꤵ¤ì¤Æ¤¤¤¿
174 \fIucp\fP ¹½Â¤ÂΤΠ\fIuc_link\fP ¥á¥ó¥Ð¤Ç·Ñ³¤¹¤ë¡£
175 ¤³¤Î¥á¥ó¥Ð¤¬ NULL ¤À¤Ã¤¿¾ì¹ç¤Ï¡¢¤½¤Î¥¹¥ì¥Ã¥É¤Ï½ªÎ»¤¹¤ë¡£
176 .LP
177 .\"O If the context was obtained by a call to a signal handler,
178 .\"O then old standard text says that "program execution continues with the
179 .\"O program instruction following the instruction interrupted
180 .\"O by the signal".
181 .\"O However, this sentence was removed in SUSv2,
182 .\"O and the present verdict is "the result is unspecified".
183 ¥³¥ó¥Æ¥­¥¹¥È¤¬¥·¥°¥Ê¥ë¥Ï¥ó¥É¥é¤Î¸Æ¤Ó½Ð¤·¤Ë¤è¤Ã¤ÆÆÀ¤é¤ì¤Æ¤¤¤¿¤â¤Î¤Î¾ì¹ç¤Ï¡¢
184 ¸Å¤¤É¸½à¤Ë¤è¤ì¤Ð
185 ¡Ö¥×¥í¥°¥é¥à¤Î¼Â¹Ô¤Ï¥·¥°¥Ê¥ë¤Ë¤è¤Ã¤Æ³ä¤ê¹þ¤Þ¤ì¤¿Ì¿Îá¤Î¼¡¤ÎÌ¿Îᤫ¤é·Ñ³¤µ¤ì¤ë¡×¡£
186 ¤·¤«¤·¤³¤Îʸ¤Ï SUSv2 ¤Çºï½ü¤µ¤ì¤¿¤Î¤Ç¡¢
187 ¸½ºß¤ÎȽÃǤϡַë²Ì¤ÏÄêµÁ¤µ¤ì¤Æ¤¤¤Ê¤¤¡×¤Ç¤¢¤ë¡£
188 .\"O .SH "RETURN VALUE"
189 .SH ÊÖ¤êÃÍ
190 .\"O When successful,
191 .\"O .BR getcontext ()
192 .\"O returns 0 and
193 .\"O .BR setcontext ()
194 .\"O does not return.
195 .\"O On error, both return \-1 and set \fIerrno\fP
196 .\"O appropriately.
197 À®¸ù¤¹¤ë¤È¡¢
198 .BR getcontext ()
199 ¤Ï 0 ¤òÊÖ¤·¡¢
200 .BR setcontext ()
201 ¤ÏÊÖ¤é¤Ê¤¤¡£
202 ¼ºÇÔ¤¹¤ë¤È¡¢Î¾¼Ô¤È¤â \-1 ¤òÊÖ¤·¡¢\fIerrno\fP ¤ò¥¨¥é¡¼¤Ë±þ¤¸¤ÆÀßÄꤹ¤ë¡£
203 .\"O .SH ERRORS
204 .SH ¥¨¥é¡¼
205 .\"O None defined.
206 ÄêµÁ¤µ¤ì¤Æ¤¤¤Ê¤¤¡£
207 .\"O .SH "CONFORMING TO"
208 .SH ½àµò
209 SUSv2, POSIX.1-2001.
210 .\"O POSIX.1-2008 removes the specification of
211 .\"O .BR getcontext (),
212 .\"O citing portability issues, and
213 .\"O recommending that applications be rewritten to use POSIX threads instead.
214 POSIX.1-2008 ¤Ç¤Ï¡¢°Ü¿¢À­¤ÎÌäÂ꤫¤é
215 .BR getcontext ()
216 ¤Î»ÅÍͤ¬ºï½ü¤µ¤ì¤¿¡£
217 Âå¤ï¤ê¤Ë¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤ò POSIX ¥¹¥ì¥Ã¥É¤ò»È¤Ã¤Æ½ñ¤­Ä¾¤¹¤³¤È¤¬
218 ¿ä¾©¤µ¤ì¤Æ¤¤¤ë¡£
219 .\"O .SH NOTES
220 .SH Ãí°Õ
221 .\"O The earliest incarnation of this mechanism was the
222 .\"O .BR setjmp (3)/ longjmp (3)
223 .\"O mechanism.
224 .\"O Since that does not define
225 .\"O the handling of the signal context, the next stage was the
226 .\"O .BR sigsetjmp (3)/ siglongjmp (3)
227 .\"O pair.
228 .\"O The present mechanism gives much more control.
229 .\"O On the other hand,
230 .\"O there is no easy way to detect whether a return from
231 .\"O .BR getcontext ()
232 .\"O is from the first call, or via a
233 .\"O .BR setcontext ()
234 .\"O call.
235 .\"O The user has to invent her own bookkeeping device, and a register
236 .\"O variable won't do since registers are restored.
237 ¤³¤Î¥á¥«¥Ë¥º¥à¤ÎºÇ¸Å¤Î¼ÂÁõ¤Ï¡¢
238 .BR setjmp (3)/ longjmp (3)
239 µ¡¹½¤Ç¤¢¤Ã¤¿¡£
240 ¤³¤ì¤é¤Ë¤Ï¥·¥°¥Ê¥ë¥³¥ó¥Æ¥­¥¹¥È¤Î¼è¤ê°·¤¤¤¬ÄêµÁ¤µ¤ì¤Æ¤¤¤Ê¤«¤Ã¤¿¤Î¤Ç¡¢
241 ¼¡¤ÎÃʳ¬¤Ç¤Ï
242 .BR sigsetjmp (3)/ siglongjmp (3)
243 ¤Î¥Ú¥¢¤¬¸½¤ï¤ì¤¿¡£
244 ¸½ºß¤Îµ¡¹½¤Ç¤Ï¤º¤Ã¤ÈºÙ¤«¤ÊÀ©¸æ¤¬¤Ç¤­¤ë¡£
245 °ìÊý
246 .BR getcontext ()
247 ¤«¤éÊ֤俤Ȥ­¡¢
248 ¤³¤ì¤¬ºÇ½é¤Î¸Æ¤Ó½Ð¤·¤Ç¤¢¤Ã¤¿¤«¡¢
249 ¤½¤ì¤È¤â
250 .BR setcontext ()
251 ¸Æ¤Ó½Ð¤·¤«¤é¤Î¤â¤Î¤Ç¤¢¤ë¤«¤ò
252 ¶èÊ̤¹¤ëÍưפÊÊýË¡¤¬¤Ê¤¯¤Ê¤Ã¤Æ¤·¤Þ¤Ã¤¿¡£
253 ¥æ¡¼¥¶¤Ï¡Ö¤·¤ª¤ê¡×µ¡¹½¤ò¼«Ê¬¤Çºî¤é¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
254 ¥ì¥¸¥¹¥¿ÊÑ¿ô¤Ï (¥ì¥¸¥¹¥¿¤Ï¥ê¥¹¥È¥¢¤µ¤ì¤Æ¤·¤Þ¤¦¤Î¤Ç) ¤³¤ì¤ò¤ä¤Ã¤Æ¤¯¤ì¤Ê¤¤¡£
255 .LP
256 .\"O When a signal occurs, the current user context is saved and
257 .\"O a new context is created by the kernel for the signal handler.
258 .\"O Do not leave the handler using
259 .\"O .BR longjmp (3):
260 .\"O it is undefined what would happen with contexts.
261 .\"O Use
262 .\"O .BR siglongjmp (3)
263 .\"O or
264 .\"O .BR setcontext ()
265 .\"O instead.
266 ¥·¥°¥Ê¥ë¤¬È¯À¸¤¹¤ë¤È¡¢
267 ¸½ºß¤Î¥æ¡¼¥¶¥³¥ó¥Æ¥­¥¹¥È¤ÏÊݸ¤µ¤ì¡¢
268 ¥·¥°¥Ê¥ë¥Ï¥ó¥É¥éÍѤΥ³¥ó¥Æ¥­¥¹¥È¤¬¥«¡¼¥Í¥ë¤Ë¤è¤Ã¤ÆÀ¸À®¤µ¤ì¤ë¡£
269 º£¸å¤Ï¥Ï¥ó¥É¥é¤Ë
270 .BR longjmp (3)
271 ¤ò»È¤ï¤»¤Ê¤¤¤³¤È:
272 ¤³¤Î´Ø¿ô¤Î¥³¥ó¥Æ¥­¥¹¥È²¼¤Ç¤ÎÆ°ºî¤ÏÄêµÁ¤µ¤ì¤Æ¤¤¤Ê¤¤¡£
273 Âå¤ï¤ê¤Ë
274 .BR siglongjmp (3)
275 ¤«
276 .BR setcontext ()
277 ¤ò»È¤¦¤³¤È¡£
278 .\"O .SH "SEE ALSO"
279 .SH ´ØÏ¢¹àÌÜ
280 .BR sigaction (2),
281 .BR sigaltstack (2),
282 .BR sigprocmask (2),
283 .BR longjmp (3),
284 .BR makecontext (3),
285 .BR sigsetjmp (3)