t64-bit nonsense - plan9port - [fork] Plan 9 from user space
 (HTM) git clone git://src.adamsgaard.dk/plan9port
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 86502504820d9626542a310fd48b50ff760ec279
 (DIR) parent ded42a6ea9fe737c4a6ce18f318086740401cc16
 (HTM) Author: rsc <devnull@localhost>
       Date:   Tue, 18 Jan 2005 05:57:35 +0000
       
       64-bit nonsense
       
       Diffstat:
         M src/libthread/thread.c              |      22 +++++++++++++++++++---
       
       1 file changed, 19 insertions(+), 3 deletions(-)
       ---
 (DIR) diff --git a/src/libthread/thread.c b/src/libthread/thread.c
       t@@ -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);
       t@@ -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);
       t@@ -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;
        }