… | |
… | |
98 | # endif |
98 | # endif |
99 | |
99 | |
100 | #endif |
100 | #endif |
101 | |
101 | |
102 | /* initialize a machine state */ |
102 | /* initialize a machine state */ |
103 | void coro_create(coro_context *ctx, |
103 | void coro_create (coro_context *ctx, |
104 | coro_func coro, void *arg, |
104 | coro_func coro, void *arg, |
105 | void *sptr, long ssize) |
105 | void *sptr, long ssize) |
106 | { |
106 | { |
107 | #if CORO_UCONTEXT |
107 | #if CORO_UCONTEXT |
108 | |
108 | |
109 | getcontext (&(ctx->uc)); |
109 | getcontext (&(ctx->uc)); |
110 | |
110 | |
… | |
… | |
140 | nsa.sa_handler = trampoline; |
140 | nsa.sa_handler = trampoline; |
141 | sigemptyset (&nsa.sa_mask); |
141 | sigemptyset (&nsa.sa_mask); |
142 | nsa.sa_flags = SA_ONSTACK; |
142 | nsa.sa_flags = SA_ONSTACK; |
143 | |
143 | |
144 | if (sigaction (SIGUSR2, &nsa, &osa)) |
144 | if (sigaction (SIGUSR2, &nsa, &osa)) |
|
|
145 | { |
145 | perror ("sigaction"); |
146 | perror ("sigaction"); |
|
|
147 | abort (); |
|
|
148 | } |
146 | |
149 | |
147 | /* set the new stack */ |
150 | /* set the new stack */ |
148 | nstk.ss_sp = STACK_ADJUST_PTR (sptr,ssize); /* yes, some platforms (IRIX) get this wrong. */ |
151 | nstk.ss_sp = STACK_ADJUST_PTR (sptr,ssize); /* yes, some platforms (IRIX) get this wrong. */ |
149 | nstk.ss_size = STACK_ADJUST_SIZE (sptr,ssize); |
152 | nstk.ss_size = STACK_ADJUST_SIZE (sptr,ssize); |
150 | nstk.ss_flags = 0; |
153 | nstk.ss_flags = 0; |
151 | |
154 | |
152 | if (sigaltstack (&nstk, &ostk) < 0) |
155 | if (sigaltstack (&nstk, &ostk) < 0) |
|
|
156 | { |
153 | perror ("sigaltstack"); |
157 | perror ("sigaltstack"); |
|
|
158 | abort (); |
|
|
159 | } |
154 | |
160 | |
155 | trampoline_count = 0; |
161 | trampoline_count = 0; |
156 | kill (getpid (), SIGUSR2); |
162 | kill (getpid (), SIGUSR2); |
157 | sigfillset (&nsig); sigdelset (&nsig, SIGUSR2); |
163 | sigfillset (&nsig); sigdelset (&nsig, SIGUSR2); |
158 | |
164 | |
… | |
… | |
194 | #error "microsoft libc or architecture not supported" |
200 | #error "microsoft libc or architecture not supported" |
195 | #endif |
201 | #endif |
196 | |
202 | |
197 | # elif CORO_LINUX |
203 | # elif CORO_LINUX |
198 | |
204 | |
199 | setjmp (ctx->env); |
205 | _setjmp (ctx->env); |
200 | #if defined(__GLIBC__) && defined(__GLIBC_MINOR__) \ |
206 | #if defined(__GLIBC__) && defined(__GLIBC_MINOR__) \ |
201 | && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 0 && defined(JB_PC) && defined(JB_SP) |
207 | && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 0 && defined(JB_PC) && defined(JB_SP) |
202 | ctx->env[0].__jmpbuf[JB_PC] = (long)coro_init; |
208 | ctx->env[0].__jmpbuf[JB_PC] = (long)coro_init; |
203 | ctx->env[0].__jmpbuf[JB_SP] = (long)STACK_ADJUST_PTR (sptr,ssize); |
209 | ctx->env[0].__jmpbuf[JB_SP] = (long)STACK_ADJUST_PTR (sptr,ssize); |
204 | #elif defined(__GLIBC__) && defined(__GLIBC_MINOR__) \ |
210 | #elif defined(__GLIBC__) && defined(__GLIBC_MINOR__) \ |