… | |
… | |
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 | |
… | |
… | |
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__) \ |
|
|
201 | && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 0 && defined(JB_PC) && defined(JB_SP) |
206 | #if __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 0 && defined (JB_PC) && defined (JB_SP) |
202 | ctx->env[0].__jmpbuf[JB_PC] = (long)coro_init; |
207 | ctx->env[0].__jmpbuf[JB_PC] = (long)coro_init; |
203 | ctx->env[0].__jmpbuf[JB_SP] = (long)STACK_ADJUST_PTR (sptr,ssize); |
208 | ctx->env[0].__jmpbuf[JB_SP] = (long)STACK_ADJUST_PTR (sptr, ssize); |
204 | #elif defined(__GLIBC__) && defined(__GLIBC_MINOR__) \ |
|
|
205 | && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 0 && defined(__mc68000__) |
209 | #elif __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 0 && defined (__mc68000__) |
206 | ctx->env[0].__jmpbuf[0].__aregs[0] = (long int)coro_init; |
210 | ctx->env[0].__jmpbuf[0].__aregs[0] = (long int)coro_init; |
207 | ctx->env[0].__jmpbuf[0].__sp = (int *)((char *)sptr + ssize); |
211 | ctx->env[0].__jmpbuf[0].__sp = (int *)((char *)sptr + ssize); |
208 | #elif defined(__GNU_LIBRARY__) && defined(__i386__) |
212 | #elif defined (__GNU_LIBRARY__) && defined (__i386__) |
209 | ctx->env[0].__jmpbuf[0].__pc = (char *)coro_init; |
213 | ctx->env[0].__jmpbuf[0].__pc = (char *)coro_init; |
210 | ctx->env[0].__jmpbuf[0].__sp = (void *)((char *)sptr + ssize); |
214 | ctx->env[0].__jmpbuf[0].__sp = (void *)((char *)sptr + ssize); |
211 | #elif defined(__GNU_LIBRARY__) && defined(__amd64__) |
215 | #elif defined (__GNU_LIBRARY__) && defined (__amd64__) |
212 | ctx->env[0].__jmpbuf[JB_PC] = (long)coro_init; |
216 | ctx->env[0].__jmpbuf[JB_PC] = (long)coro_init; |
213 | ctx->env[0].__jmpbuf[JB_RSP] = (long)STACK_ADJUST_PTR (sptr,ssize); |
217 | ctx->env[0].__jmpbuf[JB_RSP] = (long)STACK_ADJUST_PTR (sptr, ssize); |
214 | #else |
218 | #else |
215 | #error "linux libc or architecture not supported" |
219 | #error "linux libc or architecture not supported" |
216 | #endif |
220 | #endif |
217 | |
221 | |
218 | # elif CORO_IRIX |
222 | # elif CORO_IRIX |
219 | |
223 | |
220 | setjmp (ctx->env); |
224 | setjmp (ctx->env); |
221 | ctx->env[JB_PC] = (__uint64_t)coro_init; |
225 | ctx->env[JB_PC] = (__uint64_t)coro_init; |
222 | ctx->env[JB_SP] = (__uint64_t)STACK_ADJUST_PTR (sptr,ssize); |
226 | ctx->env[JB_SP] = (__uint64_t)STACK_ADJUST_PTR (sptr, ssize); |
223 | |
227 | |
224 | # endif |
228 | # endif |
225 | |
229 | |
226 | coro_transfer ((coro_context *)create_coro, (coro_context *)new_coro); |
230 | coro_transfer ((coro_context *)create_coro, (coro_context *)new_coro); |
227 | |
231 | |