From 86502504820d9626542a310fd48b50ff760ec279 Mon Sep 17 00:00:00 2001 From: rsc Date: Tue, 18 Jan 2005 05:57:35 +0000 Subject: 64-bit nonsense --- src/libthread/thread.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'src/libthread/thread.c') diff --git a/src/libthread/thread.c b/src/libthread/thread.c index 6c31cb76..dfc0acdf 100644 --- a/src/libthread/thread.c +++ b/src/libthread/thread.c @@ -77,11 +77,16 @@ procalloc(void) } static void -threadstart(void *v) +threadstart(uint y, uint x) { _Thread *t; + ulong z; + + z = x<<16; /* hide undefined 32-bit shift from 32-bit compilers */ + z <<= 16; + z |= y; + t = (_Thread*)z; - t = v; //print("threadstart %p\n", v); t->startfn(t->startarg); //print("threadexits %p\n", v); @@ -94,6 +99,8 @@ threadalloc(void (*fn)(void*), void *arg, uint stack) { _Thread *t; sigset_t zero; + uint x, y; + ulong z; /* allocate the task and stack together */ t = malloc(sizeof *t+stack); @@ -125,7 +132,16 @@ threadalloc(void (*fn)(void*), void *arg, uint stack) (char*)t->context.uc.uc_stack.ss_sp +t->context.uc.uc_stack.ss_size; #endif - makecontext(&t->context.uc, (void(*)())threadstart, 1, t); + /* + * All this magic is because you have to pass makecontext a + * function that takes some number of word-sized variables, + * and on 64-bit machines pointers are bigger than words. + */ + z = (ulong)t; + y = z; + z >>= 16; /* hide undefined 32-bit shift from 32-bit compilers */ + x = z>>16; + makecontext(&t->context.uc, (void(*)())threadstart, 2, y, x); return t; } -- cgit v1.2.3