… | |
… | |
115 | asm ( |
115 | asm ( |
116 | ".text\n" |
116 | ".text\n" |
117 | ".globl coro_transfer\n" |
117 | ".globl coro_transfer\n" |
118 | ".type coro_transfer, @function\n" |
118 | ".type coro_transfer, @function\n" |
119 | "coro_transfer:\n" |
119 | "coro_transfer:\n" |
|
|
120 | /* windows, of course, gives a shit on the amd64 ABI and uses different registers */ |
|
|
121 | /* http://blogs.msdn.com/freik/archive/2005/03/17/398200.aspx */ |
120 | #if __amd64 |
122 | #if __amd64 |
121 | #define NUM_SAVED 6 |
123 | #define NUM_SAVED 6 |
122 | "\tpush %rbp\n" |
124 | "\tpush %rbp\n" |
123 | "\tpush %rbx\n" |
125 | "\tpush %rbx\n" |
124 | "\tpush %r12\n" |
126 | "\tpush %r12\n" |
125 | "\tpush %r13\n" |
127 | "\tpush %r13\n" |
126 | "\tpush %r14\n" |
128 | "\tpush %r14\n" |
127 | "\tpush %r15\n" |
129 | "\tpush %r15\n" |
128 | #if CORO_WIN_TIB |
130 | #if CORO_WIN_TIB |
129 | "\tpush %fs:0x0\n" |
131 | "\tpush %gs:0x0\n" |
130 | "\tpush %fs:0x8\n" |
132 | "\tpush %gs:0x8\n" |
131 | "\tpush %fs:0xc\n" |
133 | "\tpush %gs:0xc\n" |
132 | #endif |
134 | #endif |
133 | "\tmov %rsp, (%rdi)\n" |
135 | "\tmov %rsp, (%rdi)\n" |
134 | "\tmov (%rsi), %rsp\n" |
136 | "\tmov (%rsi), %rsp\n" |
135 | #if CORO_WIN_TIB |
137 | #if CORO_WIN_TIB |
136 | "\tpop %fs:0xc\n" |
138 | "\tpop %gs:0xc\n" |
137 | "\tpop %fs:0x8\n" |
139 | "\tpop %gs:0x8\n" |
138 | "\tpop %fs:0x0\n" |
140 | "\tpop %gs:0x0\n" |
139 | #endif |
141 | #endif |
140 | "\tpop %r15\n" |
142 | "\tpop %r15\n" |
141 | "\tpop %r14\n" |
143 | "\tpop %r14\n" |
142 | "\tpop %r13\n" |
144 | "\tpop %r13\n" |
143 | "\tpop %r12\n" |
145 | "\tpop %r12\n" |
… | |
… | |
208 | perror ("sigaction"); |
210 | perror ("sigaction"); |
209 | abort (); |
211 | abort (); |
210 | } |
212 | } |
211 | |
213 | |
212 | /* set the new stack */ |
214 | /* set the new stack */ |
213 | nstk.ss_sp = STACK_ADJUST_PTR (sptr,ssize); /* yes, some platforms (IRIX) get this wrong. */ |
215 | nstk.ss_sp = STACK_ADJUST_PTR (sptr, ssize); /* yes, some platforms (IRIX) get this wrong. */ |
214 | nstk.ss_size = STACK_ADJUST_SIZE (sptr,ssize); |
216 | nstk.ss_size = STACK_ADJUST_SIZE (sptr, ssize); |
215 | nstk.ss_flags = 0; |
217 | nstk.ss_flags = 0; |
216 | |
218 | |
217 | if (sigaltstack (&nstk, &ostk) < 0) |
219 | if (sigaltstack (&nstk, &ostk) < 0) |
218 | { |
220 | { |
219 | perror ("sigaltstack"); |
221 | perror ("sigaltstack"); |
… | |
… | |
303 | *--ctx->sp = (char *)sptr + ssize; /* StackBase */ |
305 | *--ctx->sp = (char *)sptr + ssize; /* StackBase */ |
304 | *--ctx->sp = sptr; /* StackLimit */ |
306 | *--ctx->sp = sptr; /* StackLimit */ |
305 | #endif |
307 | #endif |
306 | |
308 | |
307 | ctx->sp -= NUM_SAVED; |
309 | ctx->sp -= NUM_SAVED; |
|
|
310 | memset (ctx->sp, 0, sizeof (*ctx->sp) * NUM_SAVED); |
308 | |
311 | |
309 | # elif CORO_UCONTEXT |
312 | # elif CORO_UCONTEXT |
310 | |
313 | |
311 | getcontext (&(ctx->uc)); |
314 | getcontext (&(ctx->uc)); |
312 | |
315 | |
… | |
… | |
400 | args.arg = arg; |
403 | args.arg = arg; |
401 | args.self = ctx; |
404 | args.self = ctx; |
402 | args.main = &nctx; |
405 | args.main = &nctx; |
403 | |
406 | |
404 | pthread_attr_init (&attr); |
407 | pthread_attr_init (&attr); |
|
|
408 | #if __UCLIBC__ |
|
|
409 | /* exists, but is borked */ |
|
|
410 | /*pthread_attr_setstacksize (&attr, (size_t)ssize);*/ |
|
|
411 | #else |
405 | pthread_attr_setstack (&attr, sptr, (size_t)ssize); |
412 | pthread_attr_setstack (&attr, sptr, (size_t)ssize); |
|
|
413 | #endif |
406 | pthread_attr_setscope (&attr, PTHREAD_SCOPE_PROCESS); |
414 | pthread_attr_setscope (&attr, PTHREAD_SCOPE_PROCESS); |
407 | pthread_create (&ctx->id, &attr, coro_init, &args); |
415 | pthread_create (&ctx->id, &attr, coro_init, &args); |
408 | |
416 | |
409 | coro_transfer (args.main, args.self); |
417 | coro_transfer (args.main, args.self); |
410 | } |
418 | } |