]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: take the callback return value from the stack
authorHector Chu <hectorchu@gmail.com>
Thu, 10 Feb 2011 12:02:27 +0000 (23:02 +1100)
committerAlex Brainman <alex.brainman@gmail.com>
Thu, 10 Feb 2011 12:02:27 +0000 (23:02 +1100)
R=brainman, lxn, rsc
CC=golang-dev
https://golang.org/cl/4126056

src/pkg/runtime/cgocall.c
src/pkg/runtime/cgocall.h
src/pkg/runtime/runtime.h
src/pkg/runtime/windows/386/sys.s

index e6ece954221048500d1f78bfe7a4fd4b1a68d568..74e5a3085732bc8b11ea9a5f1efe369734abf9a8 100644 (file)
@@ -53,13 +53,12 @@ runtime·cgocall(void (*fn)(void*), void *arg)
 // (arg/argsize) on to the stack, calls the function, copies the
 // arguments back where they came from, and finally returns to the old
 // stack.
-uintptr
+void
 runtime·cgocallback(void (*fn)(void), void *arg, int32 argsize)
 {
        Gobuf oldsched, oldg1sched;
        G *g1;
        void *sp;
-       uintptr ret;
 
        if(g != m->g0)
                runtime·throw("bad g in cgocallback");
@@ -71,11 +70,11 @@ runtime·cgocallback(void (*fn)(void), void *arg, int32 argsize)
        runtime·startcgocallback(g1);
 
        sp = g1->sched.sp - argsize;
-       if(sp < g1->stackguard - StackGuard + 4) // +4 for return address
+       if(sp < g1->stackguard - StackGuard + 8) // +8 for return address
                runtime·throw("g stack overflow in cgocallback");
        runtime·mcpy(sp, arg, argsize);
 
-       ret = runtime·runcgocallback(g1, sp, fn);
+       runtime·runcgocallback(g1, sp, fn);
 
        runtime·mcpy(arg, sp, argsize);
 
@@ -83,8 +82,6 @@ runtime·cgocallback(void (*fn)(void), void *arg, int32 argsize)
 
        m->sched = oldsched;
        g1->sched = oldg1sched;
-
-       return ret;
 }
 
 void
index 7c24e167b4a313b112055276148a44fea74d2419..1ad954eb120f08d0d7078ee5b2d6861b797e7788 100644 (file)
@@ -7,6 +7,6 @@
  */
 
 void runtime·cgocall(void (*fn)(void*), void*);
-uintptr runtime·cgocallback(void (*fn)(void), void*, int32);
+void runtime·cgocallback(void (*fn)(void), void*, int32);
 void *runtime·cmalloc(uintptr);
 void runtime·cfree(void*);
index b76632a2d4e802110c451ae6971be800c627ed46..cea07e4a70ada48c42946f33ecc96edd8664ec0d 100644 (file)
@@ -443,7 +443,7 @@ void        runtime·breakpoint(void);
 void   runtime·gosched(void);
 void   runtime·goexit(void);
 void   runtime·runcgo(void (*fn)(void*), void*);
-uintptr        runtime·runcgocallback(G*, void*, void (*fn)());
+void   runtime·runcgocallback(G*, void*, void (*fn)());
 void   runtime·entersyscall(void);
 void   runtime·exitsyscall(void);
 void   runtime·startcgocallback(G*);
index d1a8a49a9c321f8eb28bed691a774ea12e3832fa..26069d3912d83089f400e97515738ee50df0c047 100644 (file)
@@ -107,7 +107,11 @@ sigdone:
 // DX = total size of arguments
 //
 TEXT runtime·callbackasm+0(SB),7,$0
+       // preserve whatever's at the memory location that
+       // the callback will use to store the return value
        LEAL    8(SP), CX
+       PUSHL   0(CX)(DX*1)
+       ADDL    $4, DX                  // extend argsize by size of return value
 
        // save registers as required for windows callback
        PUSHL   0(FS)
@@ -129,7 +133,7 @@ TEXT runtime·callbackasm+0(SB),7,$0
        CALL    runtime·cgocallback(SB)
 
        // restore registers as required for windows callback
-       POPL    CX
+       POPL    AX
        POPL    CX
        POPL    DX
        POPL    BX
@@ -139,6 +143,8 @@ TEXT runtime·callbackasm+0(SB),7,$0
        POPL    0(FS)
        CLD
 
+       MOVL    -4(CX)(DX*1), AX
+       POPL    -4(CX)(DX*1)
        RET
 
 // void tstart(M *newm);