1 | /* |
1 | /* |
2 | * Copyright (c) 2001-2009 Marc Alexander Lehmann <schmorp@schmorp.de> |
2 | * Copyright (c) 2001-2011 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, |
… | |
… | |
85 | { |
85 | { |
86 | volatile coro_func func = coro_init_func; |
86 | volatile coro_func func = coro_init_func; |
87 | volatile void *arg = coro_init_arg; |
87 | volatile void *arg = coro_init_arg; |
88 | |
88 | |
89 | coro_transfer (new_coro, create_coro); |
89 | coro_transfer (new_coro, create_coro); |
|
|
90 | |
|
|
91 | #if __linux && __amd64 |
|
|
92 | /* we blindly assume on any __linux with __amd64 we have a new enough gas with .cfi_undefined support */ |
|
|
93 | asm (".cfi_undefined rip"); |
|
|
94 | #endif |
90 | |
95 | |
91 | func ((void *)arg); |
96 | func ((void *)arg); |
92 | |
97 | |
93 | /* the new coro returned. bad. just abort() for now */ |
98 | /* the new coro returned. bad. just abort() for now */ |
94 | abort (); |
99 | abort (); |
… | |
… | |
210 | perror ("sigaction"); |
215 | perror ("sigaction"); |
211 | abort (); |
216 | abort (); |
212 | } |
217 | } |
213 | |
218 | |
214 | /* set the new stack */ |
219 | /* set the new stack */ |
215 | nstk.ss_sp = STACK_ADJUST_PTR (sptr,ssize); /* yes, some platforms (IRIX) get this wrong. */ |
220 | nstk.ss_sp = STACK_ADJUST_PTR (sptr, ssize); /* yes, some platforms (IRIX) get this wrong. */ |
216 | nstk.ss_size = STACK_ADJUST_SIZE (sptr,ssize); |
221 | nstk.ss_size = STACK_ADJUST_SIZE (sptr, ssize); |
217 | nstk.ss_flags = 0; |
222 | nstk.ss_flags = 0; |
218 | |
223 | |
219 | if (sigaltstack (&nstk, &ostk) < 0) |
224 | if (sigaltstack (&nstk, &ostk) < 0) |
220 | { |
225 | { |
221 | perror ("sigaltstack"); |
226 | perror ("sigaltstack"); |
… | |
… | |
305 | *--ctx->sp = (char *)sptr + ssize; /* StackBase */ |
310 | *--ctx->sp = (char *)sptr + ssize; /* StackBase */ |
306 | *--ctx->sp = sptr; /* StackLimit */ |
311 | *--ctx->sp = sptr; /* StackLimit */ |
307 | #endif |
312 | #endif |
308 | |
313 | |
309 | ctx->sp -= NUM_SAVED; |
314 | ctx->sp -= NUM_SAVED; |
|
|
315 | memset (ctx->sp, 0, sizeof (*ctx->sp) * NUM_SAVED); |
310 | |
316 | |
311 | # elif CORO_UCONTEXT |
317 | # elif CORO_UCONTEXT |
312 | |
318 | |
313 | getcontext (&(ctx->uc)); |
319 | getcontext (&(ctx->uc)); |
314 | |
320 | |
… | |
… | |
403 | args.self = ctx; |
409 | args.self = ctx; |
404 | args.main = &nctx; |
410 | args.main = &nctx; |
405 | |
411 | |
406 | pthread_attr_init (&attr); |
412 | pthread_attr_init (&attr); |
407 | #if __UCLIBC__ |
413 | #if __UCLIBC__ |
|
|
414 | /* exists, but is borked */ |
408 | pthread_attr_setstacksize (&attr, (size_t)ssize); |
415 | /*pthread_attr_setstacksize (&attr, (size_t)ssize);*/ |
409 | #else |
416 | #else |
410 | pthread_attr_setstack (&attr, sptr, (size_t)ssize); |
417 | pthread_attr_setstack (&attr, sptr, (size_t)ssize); |
411 | #endif |
418 | #endif |
412 | pthread_attr_setscope (&attr, PTHREAD_SCOPE_PROCESS); |
419 | pthread_attr_setscope (&attr, PTHREAD_SCOPE_PROCESS); |
413 | pthread_create (&ctx->id, &attr, coro_init, &args); |
420 | pthread_create (&ctx->id, &attr, coro_init, &args); |