OSDN Git Service

fb5b90ac17f04474d8d65281892175387d64768a
[linuxjm/LDP_man-pages.git] / release / man3 / makecontext.3
1 .\" Copyright (C) 2001 Andries Brouwer (aeb@cwi.nl)
2 .\" and Copyright (C) 2006 Michael Kerrisk <mtk.manpages@gmail.com>
3 .\"
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 .\" 2006-08-02, mtk, Added example program
24 .\"
25 .\" Japanese Version Copyright (c) 2001 NAKANO Takeo all rights reserved.
26 .\" Translated Sat Dec 15 2001 by NAKANO Takeo <nakano@apm.seikei.ac.jp>
27 .\" Updated 2008-12-24, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v3.15
28 .\"
29 .TH MAKECONTEXT 3 2009-03-31 "GNU" "Linux Programmer's Manual"
30 .SH Ì¾Á°
31 makecontext, swapcontext \- ¥æ¡¼¥¶¥³¥ó¥Æ¥­¥¹¥È¤òÁàºî¤¹¤ë
32 .SH ½ñ¼°
33 .B #include <ucontext.h>
34 .sp
35 .BI "void makecontext(ucontext_t *" ucp ", void (*" func )(),
36 .BI "int " argc ", ...);"
37 .sp
38 .BI "int swapcontext(ucontext_t *" oucp ", ucontext_t *" ucp );
39 .SH ÀâÌÀ
40 System V Åª¤Ê´Ä¶­¤Ç¤Ï¡¢
41 \fBmcontext_t\fP ¤ª¤è¤Ó \fBucontext_t\fP ¤È¤¤¤¦ 2 ¤Ä¤Î·¿¤È¡¢
42 .BR getcontext (2),
43 .BR setcontext (2),
44 .BR makecontext (),
45 .BR swapcontext ()
46 ¤È¤¤¤¦ 4 ¤Ä¤Î´Ø¿ô¤¬
47 .I <ucontext.h>
48 ¤ÇÄêµÁ¤µ¤ì¤Æ¤ª¤ê¡¢¤¢¤ë¥×¥í¥»¥¹ÆâÉô¤ÇÀ©¸æ²¼¤Ë¤¢¤ëÊ£¿ô¤Î¥¹¥ì¥Ã¥É´Ö¤Ç¡¢
49 ¥æ¡¼¥¶¥ì¥Ù¥ë¤Î¥³¥ó¥Æ¥­¥¹¥ÈÀÚÂؤ¨¤¬¤Ç¤­¤ë¤è¤¦¤Ë¤Ê¤Ã¤Æ¤¤¤ë¡£
50 .LP
51 ¤³¤ì¤é¤Î·¿¤È¡¢ºÇ½é¤Î 2 ¤Ä¤Î´Ø¿ô¤Ë¤Ä¤¤¤Æ¤Ï¡¢
52 .BR getcontext (2)
53 ¤ò»²¾È¤Î¤³¤È¡£
54 .LP
55 .BR makecontext ()
56 ´Ø¿ô¤Ï¡¢¥Ý¥¤¥ó¥¿ \fIucp\fP ¤¬»Ø¤¹¥³¥ó¥Æ¥­¥¹¥È¤òÊѹ¹¤¹¤ë
57 (\fIucp\fP ¤Ï°ÊÁ°¤Î
58 .BR getcontext (2)
59 ¸Æ¤Ó½Ð¤·¤ÇÆÀ¤é¤ì¤¿¤â¤Î¤Ç¤¢¤ë)¡£
60 .BR makecontext ()
61 ¤òµ¯Æ°¤¹¤ëÁ°¤Ë¤Ï¡¢¸Æ¤Ó½Ð¤·¼Ô¤Ï¡¢¤³¤Î¥³¥ó¥Æ¥­¥¹¥ÈÍѤË
62 ¿·¤·¤¤¥¹¥¿¥Ã¥¯¤ò³ÎÊݤ·¡¢¤½¤Î¥¢¥É¥ì¥¹¤ò \fIucp\->uc_stack\fP ¤ËÂåÆþ¤·¡¢
63 ¤µ¤é¤Ë¸å·Ñ¤Î¥³¥ó¥Æ¥­¥¹¥È¤òÄêµÁ¤·¡¢¤½¤Î¥¢¥É¥ì¥¹¤ò \fIucp\->uc_link\fP ¤Ë
64 ÂåÆþ¤·¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
65
66 ¤³¤Î¥³¥ó¥Æ¥­¥¹¥È¤¬¾­Íè
67 .RB ( setcontext (2)
68 ¤Þ¤¿¤Ï
69 .BR swapcontext ()
70 ¤Ë¤è¤Ã¤Æ)
71 Í­¸ú¤Ë¤µ¤ì¤ë¤È¡¢´Ø¿ô \fIfunc\fP ¤¬¸Æ¤Ð¤ì¡¢
72 °ú¤­¿ô¤È¤·¤Æ
73 .I argc
74 °Ê¹ß¤ÎÀ°¿ô
75 .RI ( int )
76 °ú¤­¿ô¤ÎÎó¤¬ÅϤµ¤ì¤ë¡£
77 ¸Æ¤Ó½Ð¤·¼Ô¤Ï
78 .I argc
79 ¤Ë¤³¤ì¤é¤Î°ú¤­¿ô¤Î¸Ä¿ô¤ò»ØÄꤷ¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
80 ¤³¤Î´Ø¿ô¤¬Ìá¤ë¤È¡¢¸å·Ñ¤Î¥³¥ó¥Æ¥­¥¹¥È¤¬Í­¸ú¤Ë¤Ê¤ë¡£
81 ¸å·Ñ¥³¥ó¥Æ¥­¥¹¥È¤Î¥Ý¥¤¥ó¥¿¤¬ NULL ¤Î¾ì¹ç¡¢¤½¤Î¥¹¥ì¥Ã¥É¤¬½ªÎ»¤¹¤ë¡£
82 .LP
83 .BR swapcontext ()
84 ´Ø¿ô¤Ï¸½ºß¤Î¥³¥ó¥Æ¥­¥¹¥È¤ò
85 ¥Ý¥¤¥ó¥¿ \fIoucp\fP ¤¬»Ø¤¹¹½Â¤ÂΤËÊݸ¤·¡¢
86 ¥Ý¥¤¥ó¥¿ \fIucp\fP ¤¬»Ø¤¹¥³¥ó¥Æ¥­¥¹¥È¤òÍ­¸ú¤Ë¤¹¤ë¡£
87 .SH ÊÖ¤êÃÍ
88 À®¸ù¤¹¤ë¤È¡¢
89 .BR swapcontext ()
90 ¤ÏÊÖ¤é¤Ê¤¤
91 (¤·¤«¤·¸å¤Ë \fIoucp\fP ¤¬Í­¸ú¤Ë¤Ê¤Ã¤¿¾ì¹ç¤Ë¤ÏÊ֤뤳¤È¤¬¤¢¤ë¡£
92 ¤³¤Î¤È¤­¤Ë¤Ï
93 .BR swapcontext ()
94 ¤Ï 0 ¤òÊÖ¤¹¤è¤¦¤Ë¸«¤¨¤ë¡£)
95 ¼ºÇÔ¤¹¤ë¤È¡¢
96 .BR swapcontext ()
97 ¤Ï \-1 ¤òÊÖ¤·¡¢
98 \fIerrno\fP ¤ò¥¨¥é¡¼¤Ë±þ¤¸¤ÆÀßÄꤹ¤ë¡£
99 .SH ¥¨¥é¡¼
100 .TP
101 .B ENOMEM
102 ¥¹¥¿¥Ã¥¯¤Ë³ä¤êÅö¤Æ¤ë¶õ´Ö¤¬»Ä¤Ã¤Æ¤¤¤Ê¤¤¡£
103 .SH ¥Ð¡¼¥¸¥ç¥ó
104 .BR makecontext ()
105 ¤È
106 .BR swapcontext ()
107 ¤Ï¡¢¥Ð¡¼¥¸¥ç¥ó 2.1 °Ê¹ß¤Î glibc ¤ÇÄ󶡤µ¤ì¤Æ¤¤¤ë¡£
108 .SH ½àµò
109 SUSv2, POSIX.1-2001.
110 POSIX.1-2008 ¤Ç¤Ï¡¢°Ü¿¢À­¤ÎÌäÂ꤫¤é
111 .BR makecontext ()
112 ¤È
113 .BR swapcontext ()
114 ¤Î»ÅÍͤ¬ºï½ü¤µ¤ì¤Æ¤¤¤ë¡£
115 Âå¤ï¤ê¤Ë¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤ò POSIX ¥¹¥ì¥Ã¥É¤ò»È¤Ã¤Æ½ñ¤­Ä¾¤¹¤³¤È¤¬
116 ¿ä¾©¤µ¤ì¤Æ¤¤¤ë¡£
117 .SH Ãí°Õ
118 \fIucp\->uc_stack\fP ¤Î²ò¼á¤Ï
119 .BR sigaltstack (2)
120 ¤Î¾ì¹ç¤ÈƱ¤¸¤Ç¤¢¤ë¡£
121 ¤¹¤Ê¤ï¤Á¤³¤Î¹½Â¤ÂΤˤϡ¢
122 ¥¹¥¿¥Ã¥¯¤È¤·¤ÆÍѤ¤¤é¤ì¤ë¥á¥â¥êÎΰè¤Î³«»Ï¥¢¥É¥ì¥¹¤ÈŤµ¤¬´Þ¤Þ¤ì¡¢
123 ¤³¤ì¤Ï¥¹¥¿¥Ã¥¯¤¬¿­¤Ó¤ëÊý¸þ¤¬¤É¤Á¤é¤Ç¤¢¤ë¤«¤Ë¤Ï´Ø·¸¤·¤Ê¤¤¡£
124 ¤·¤¿¤¬¤Ã¤Æ¡¢¥æ¡¼¥¶¥×¥í¥°¥é¥à¤Ï¤³¤Î·ï¤Ë¤Ä¤¤¤Æ¤Ï¿´ÇÛ¤·¤Ê¤¯¤Æ¤è¤¤¡£
125
126 .I int
127 ¤È¥Ý¥¤¥ó¥¿·¿¤¬Æ±¤¸Â礭¤µ¤Ç¤¢¤ë¥¢¡¼¥­¥Æ¥¯¥Á¥ã¤Ç¤Ï
128 (x86-32 ¤Ï¤½¤ÎÎã¤Ç¤¢¤ê¡¢Î¾Êý¤Î·¿¤È¤â 32 ¥Ó¥Ã¥È¤Ç¤¢¤ë)¡¢
129 .BR makecontext ()
130 ¤Î
131 .I argc
132 °Ê¹ß¤Î°ú¤­¿ô¤È¤·¤Æ¥Ý¥¤¥ó¥¿¤òÅϤ·¤Æ¤â¤¦¤Þ¤¯Æ°¤¯¤«¤â¤·¤ì¤Ê¤¤¡£
133 ¤·¤«¤·¤Ê¤¬¤é¡¢¤³¤Î¤è¤¦¤Ë¤¹¤ë¤È¡¢°Ü¿¢À­¤ÏÊݾڤµ¤ì¤º¡¢
134 ɸ½à¤Ë½¾¤¨¤ÐÆ°ºî¤Ï̤ÄêµÁ¤Ç¤¢¤ê¡¢¥Ý¥¤¥ó¥¿¤¬
135 .I int
136 ¤è¤ê¤âÂ礭¤¤¥¢¡¼¥­¥Æ¥¯¥Á¥ã¤Ç¤ÏÀµ¤·¤¯Æ°ºî¤·¤Ê¤¤¤³¤È¤À¤í¤¦¡£
137 ¤½¤ì¤Ë¤â´Ø¤ï¤é¤º¡¢¥Ð¡¼¥¸¥ç¥ó 2.8 °Ê¹ß¤Î glibc ¤Ç¤Ï¡¢
138 .BR makecontext (3)
139 ¤ËÊѹ¹¤¬¹Ô¤ï¤ì¡¢(x86-64 ¤Ê¤É¤Î) ¤¤¤¯¤Ä¤«¤Î 64 ¥Ó¥Ã¥È¥¢¡¼¥­¥Æ¥¯¥Á¥ã¤Ç
140 °ú¤­¿ô¤È¤·¤Æ¥Ý¥¤¥ó¥¿¤òÅϤ¹¤³¤È¤¬¤Ç¤­¤ë¤è¤¦¤Ë¤Ê¤Ã¤Æ¤¤¤ë¡£
141 .SH Îã
142 .PP
143 °Ê²¼¤Î¥µ¥ó¥×¥ë¡¦¥×¥í¥°¥é¥à¤Ï¡¢
144 .BR getcontext (2),
145 .BR makecontext (),
146 .BR swapcontext ()
147 ¤Î»ÈÍÑÊýË¡¤ÎÎã¤ò¼¨¤¹¤â¤Î¤Ç¤¢¤ë¡£
148 ¤³¤Î¥×¥í¥°¥é¥à¤ò¼Â¹Ô¤¹¤ë¤È¡¢°Ê²¼¤Î¤è¤¦¤Ê½ÐÎϤ¬ÆÀ¤é¤ì¤ë:
149 .in +4n
150 .nf
151
152 .RB "$" " ./a.out"
153 main: swapcontext(&uctx_main, &uctx_func2)
154 func2: started
155 func2: swapcontext(&uctx_func2, &uctx_func1)
156 func1: started
157 func1: swapcontext(&uctx_func1, &uctx_func2)
158 func2: returning
159 func1: returning
160 main: exiting
161 .fi
162 .in
163 .SS ¥×¥í¥°¥é¥à¤Î¥½¡¼¥¹
164 \&
165 .nf
166 #include <ucontext.h>
167 #include <stdio.h>
168 #include <stdlib.h>
169
170 static ucontext_t uctx_main, uctx_func1, uctx_func2;
171
172 #define handle_error(msg) \\
173     do { perror(msg); exit(EXIT_FAILURE); } while (0)
174
175 static void
176 func1(void)
177 {
178     printf("func1: started\\n");
179     printf("func1: swapcontext(&uctx_func1, &uctx_func2)\\n");
180     if (swapcontext(&uctx_func1, &uctx_func2) == \-1)
181         handle_error("swapcontext");
182     printf("func1: returning\\n");
183 }
184
185 static void
186 func2(void)
187 {
188     printf("func2: started\\n");
189     printf("func2: swapcontext(&uctx_func2, &uctx_func1)\\n");
190     if (swapcontext(&uctx_func2, &uctx_func1) == \-1)
191         handle_error("swapcontext");
192     printf("func2: returning\\n");
193 }
194
195 int
196 main(int argc, char *argv[])
197 {
198     char func1_stack[16384];
199     char func2_stack[16384];
200
201     if (getcontext(&uctx_func1) == \-1)
202         handle_error("getcontext");
203     uctx_func1.uc_stack.ss_sp = func1_stack;
204     uctx_func1.uc_stack.ss_size = sizeof(func1_stack);
205     uctx_func1.uc_link = &uctx_main;
206     makecontext(&uctx_func1, func1, 0);
207
208     if (getcontext(&uctx_func2) == \-1)
209         handle_error("getcontext");
210     uctx_func2.uc_stack.ss_sp = func2_stack;
211     uctx_func2.uc_stack.ss_size = sizeof(func2_stack);
212     /* Successor context is f1(), unless argc > 1 */
213     uctx_func2.uc_link = (argc > 1) ? NULL : &uctx_func1;
214     makecontext(&uctx_func2, func2, 0);
215
216     printf("main: swapcontext(&uctx_main, &uctx_func2)\\n");
217     if (swapcontext(&uctx_main, &uctx_func2) == \-1)
218         handle_error("swapcontext");
219
220     printf("main: exiting\\n");
221     exit(EXIT_SUCCESS);
222 }
223 .fi
224 .SH ´ØÏ¢¹àÌÜ
225 .BR getcontext (2),
226 .BR sigaction (2),
227 .BR sigaltstack (2),
228 .BR sigprocmask (2),
229 .BR sigsetjmp (3)