1 | /* |
1 | /* |
2 | * Copyright (c) 2001-2008 Marc Alexander Lehmann <schmorp@schmorp.de> |
2 | * Copyright (c) 2001-2009 Marc Alexander Lehmann <schmorp@schmorp.de> |
3 | * |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without modifica- |
4 | * Redistribution and use in source and binary forms, with or without modifica- |
5 | * tion, are permitted provided that the following conditions are met: |
5 | * tion, are permitted provided that the following conditions are met: |
6 | * |
6 | * |
7 | * 1. Redistributions of source code must retain the above copyright notice, |
7 | * 1. Redistributions of source code must retain the above copyright notice, |
… | |
… | |
100 | |
100 | |
101 | /* trampoline signal handler */ |
101 | /* trampoline signal handler */ |
102 | static void |
102 | static void |
103 | trampoline (int sig) |
103 | trampoline (int sig) |
104 | { |
104 | { |
105 | if ( |
|
|
106 | #if _XOPEN_UNIX > 0 |
|
|
107 | _setjmp (new_coro->env) |
105 | if (coro_setjmp (new_coro->env)) |
108 | #else |
|
|
109 | sigsetjmp (new_coro->env, 0) |
|
|
110 | #endif |
|
|
111 | ) { |
|
|
112 | coro_init (); /* start it */ |
106 | coro_init (); /* start it */ |
113 | } |
|
|
114 | else |
107 | else |
115 | trampoline_done = 1; |
108 | trampoline_done = 1; |
116 | } |
109 | } |
117 | |
110 | |
118 | # endif |
111 | # endif |
… | |
… | |
229 | sigaction (SIGUSR2, &osa, 0); |
222 | sigaction (SIGUSR2, &osa, 0); |
230 | sigprocmask (SIG_SETMASK, &osig, 0); |
223 | sigprocmask (SIG_SETMASK, &osig, 0); |
231 | |
224 | |
232 | # elif CORO_LOSER |
225 | # elif CORO_LOSER |
233 | |
226 | |
234 | setjmp (ctx->env); |
227 | coro_setjmp (ctx->env); |
235 | #if __CYGWIN__ |
228 | #if __CYGWIN__ && __i386 |
|
|
229 | ctx->env[8] = (long) coro_init; |
236 | ctx->env[7] = (long)((char *)sptr + ssize) - sizeof (long); |
230 | ctx->env[7] = (long) ((char *)sptr + ssize) - sizeof (long); |
237 | ctx->env[8] = (long)coro_init; |
231 | #elif __CYGWIN__ && __x86_64 |
|
|
232 | ctx->env[7] = (long) coro_init; |
|
|
233 | ctx->env[6] = (long) ((char *)sptr + ssize) - sizeof (long); |
|
|
234 | #elif defined(__MINGW32__) |
|
|
235 | ctx->env[5] = (long) coro_init; |
|
|
236 | ctx->env[4] = (long) ((char *)sptr + ssize) - sizeof (long); |
238 | #elif defined(_M_IX86) |
237 | #elif defined(_M_IX86) |
239 | ((_JUMP_BUFFER *)&ctx->env)->Eip = (long)coro_init; |
238 | ((_JUMP_BUFFER *)&ctx->env)->Eip = (long) coro_init; |
240 | ((_JUMP_BUFFER *)&ctx->env)->Esp = (long)STACK_ADJUST_PTR (sptr, ssize) - sizeof (long); |
239 | ((_JUMP_BUFFER *)&ctx->env)->Esp = (long) STACK_ADJUST_PTR (sptr, ssize) - sizeof (long); |
241 | #elif defined(_M_AMD64) |
240 | #elif defined(_M_AMD64) |
242 | ((_JUMP_BUFFER *)&ctx->env)->Rip = (__int64)coro_init; |
241 | ((_JUMP_BUFFER *)&ctx->env)->Rip = (__int64) coro_init; |
243 | ((_JUMP_BUFFER *)&ctx->env)->Rsp = (__int64)STACK_ADJUST_PTR (sptr, ssize) - sizeof (long); |
242 | ((_JUMP_BUFFER *)&ctx->env)->Rsp = (__int64) STACK_ADJUST_PTR (sptr, ssize) - sizeof (__int64); |
244 | #elif defined(_M_IA64) |
243 | #elif defined(_M_IA64) |
245 | ((_JUMP_BUFFER *)&ctx->env)->StIIP = (__int64)coro_init; |
244 | ((_JUMP_BUFFER *)&ctx->env)->StIIP = (__int64) coro_init; |
246 | ((_JUMP_BUFFER *)&ctx->env)->IntSp = (__int64)STACK_ADJUST_PTR (sptr, ssize) - sizeof (long); |
245 | ((_JUMP_BUFFER *)&ctx->env)->IntSp = (__int64) STACK_ADJUST_PTR (sptr, ssize) - sizeof (__int64); |
247 | #else |
246 | #else |
248 | #error "microsoft libc or architecture not supported" |
247 | #error "microsoft libc or architecture not supported" |
249 | #endif |
248 | #endif |
250 | |
249 | |
251 | # elif CORO_LINUX |
250 | # elif CORO_LINUX |
252 | |
251 | |
253 | _setjmp (ctx->env); |
252 | coro_setjmp (ctx->env); |
254 | #if __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 0 && defined (JB_PC) && defined (JB_SP) |
253 | #if __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 0 && defined (JB_PC) && defined (JB_SP) |
255 | ctx->env[0].__jmpbuf[JB_PC] = (long)coro_init; |
254 | ctx->env[0].__jmpbuf[JB_PC] = (long) coro_init; |
256 | ctx->env[0].__jmpbuf[JB_SP] = (long)STACK_ADJUST_PTR (sptr, ssize) - sizeof (long); |
255 | ctx->env[0].__jmpbuf[JB_SP] = (long) STACK_ADJUST_PTR (sptr, ssize) - sizeof (long); |
257 | #elif __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 0 && defined (__mc68000__) |
256 | #elif __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 0 && defined (__mc68000__) |
258 | ctx->env[0].__jmpbuf[0].__aregs[0] = (long int)coro_init; |
257 | ctx->env[0].__jmpbuf[0].__aregs[0] = (long int)coro_init; |
259 | ctx->env[0].__jmpbuf[0].__sp = (int *)((char *)sptr + ssize) - sizeof (long); |
258 | ctx->env[0].__jmpbuf[0].__sp = (int *) ((char *)sptr + ssize) - sizeof (long); |
260 | #elif defined (__GNU_LIBRARY__) && defined (__i386__) |
259 | #elif defined (__GNU_LIBRARY__) && defined (__i386__) |
261 | ctx->env[0].__jmpbuf[0].__pc = (char *)coro_init; |
260 | ctx->env[0].__jmpbuf[0].__pc = (char *) coro_init; |
262 | ctx->env[0].__jmpbuf[0].__sp = (void *)((char *)sptr + ssize) - sizeof (long); |
261 | ctx->env[0].__jmpbuf[0].__sp = (void *) ((char *)sptr + ssize) - sizeof (long); |
263 | #elif defined (__GNU_LIBRARY__) && defined (__amd64__) |
262 | #elif defined (__GNU_LIBRARY__) && defined (__amd64__) |
264 | ctx->env[0].__jmpbuf[JB_PC] = (long)coro_init; |
263 | ctx->env[0].__jmpbuf[JB_PC] = (long) coro_init; |
265 | ctx->env[0].__jmpbuf[0].__sp = (void *)((char *)sptr + ssize) - sizeof (long); |
264 | ctx->env[0].__jmpbuf[0].__sp = (void *) ((char *)sptr + ssize) - sizeof (long); |
266 | #else |
265 | #else |
267 | #error "linux libc or architecture not supported" |
266 | #error "linux libc or architecture not supported" |
268 | #endif |
267 | #endif |
269 | |
268 | |
270 | # elif CORO_IRIX |
269 | # elif CORO_IRIX |
271 | |
270 | |
272 | sigsetjmp (ctx->env, 0); |
271 | coro_setjmp (ctx->env, 0); |
273 | ctx->env[JB_PC] = (__uint64_t)coro_init; |
272 | ctx->env[JB_PC] = (__uint64_t)coro_init; |
274 | ctx->env[JB_SP] = (__uint64_t)STACK_ADJUST_PTR (sptr, ssize) - sizeof (long); |
273 | ctx->env[JB_SP] = (__uint64_t)STACK_ADJUST_PTR (sptr, ssize) - sizeof (long); |
275 | |
274 | |
276 | # elif CORO_ASM |
275 | # elif CORO_ASM |
277 | |
276 | |
278 | ctx->sp = (void **)(ssize + (char *)sptr); |
277 | ctx->sp = (void **)(ssize + (char *)sptr); |
279 | *--ctx->sp = (void *)abort; /* needed for alignment only */ |
278 | *--ctx->sp = (void *)abort; /* needed for alignment only */ |