mirror of
https://github.com/golang/go
synced 2024-11-21 18:04:40 -07:00
runtime: take the callback return value from the stack
R=brainman, lxn, rsc CC=golang-dev https://golang.org/cl/4126056
This commit is contained in:
parent
34fc17a820
commit
239ef63bf2
@ -53,13 +53,12 @@ runtime·cgocall(void (*fn)(void*), void *arg)
|
|||||||
// (arg/argsize) on to the stack, calls the function, copies the
|
// (arg/argsize) on to the stack, calls the function, copies the
|
||||||
// arguments back where they came from, and finally returns to the old
|
// arguments back where they came from, and finally returns to the old
|
||||||
// stack.
|
// stack.
|
||||||
uintptr
|
void
|
||||||
runtime·cgocallback(void (*fn)(void), void *arg, int32 argsize)
|
runtime·cgocallback(void (*fn)(void), void *arg, int32 argsize)
|
||||||
{
|
{
|
||||||
Gobuf oldsched, oldg1sched;
|
Gobuf oldsched, oldg1sched;
|
||||||
G *g1;
|
G *g1;
|
||||||
void *sp;
|
void *sp;
|
||||||
uintptr ret;
|
|
||||||
|
|
||||||
if(g != m->g0)
|
if(g != m->g0)
|
||||||
runtime·throw("bad g in cgocallback");
|
runtime·throw("bad g in cgocallback");
|
||||||
@ -71,11 +70,11 @@ runtime·cgocallback(void (*fn)(void), void *arg, int32 argsize)
|
|||||||
runtime·startcgocallback(g1);
|
runtime·startcgocallback(g1);
|
||||||
|
|
||||||
sp = g1->sched.sp - argsize;
|
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·throw("g stack overflow in cgocallback");
|
||||||
runtime·mcpy(sp, arg, argsize);
|
runtime·mcpy(sp, arg, argsize);
|
||||||
|
|
||||||
ret = runtime·runcgocallback(g1, sp, fn);
|
runtime·runcgocallback(g1, sp, fn);
|
||||||
|
|
||||||
runtime·mcpy(arg, sp, argsize);
|
runtime·mcpy(arg, sp, argsize);
|
||||||
|
|
||||||
@ -83,8 +82,6 @@ runtime·cgocallback(void (*fn)(void), void *arg, int32 argsize)
|
|||||||
|
|
||||||
m->sched = oldsched;
|
m->sched = oldsched;
|
||||||
g1->sched = oldg1sched;
|
g1->sched = oldg1sched;
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -7,6 +7,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
void runtime·cgocall(void (*fn)(void*), void*);
|
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·cmalloc(uintptr);
|
||||||
void runtime·cfree(void*);
|
void runtime·cfree(void*);
|
||||||
|
@ -443,7 +443,7 @@ void runtime·breakpoint(void);
|
|||||||
void runtime·gosched(void);
|
void runtime·gosched(void);
|
||||||
void runtime·goexit(void);
|
void runtime·goexit(void);
|
||||||
void runtime·runcgo(void (*fn)(void*), 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·entersyscall(void);
|
||||||
void runtime·exitsyscall(void);
|
void runtime·exitsyscall(void);
|
||||||
void runtime·startcgocallback(G*);
|
void runtime·startcgocallback(G*);
|
||||||
|
@ -107,7 +107,11 @@ sigdone:
|
|||||||
// DX = total size of arguments
|
// DX = total size of arguments
|
||||||
//
|
//
|
||||||
TEXT runtime·callbackasm+0(SB),7,$0
|
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
|
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
|
// save registers as required for windows callback
|
||||||
PUSHL 0(FS)
|
PUSHL 0(FS)
|
||||||
@ -129,7 +133,7 @@ TEXT runtime·callbackasm+0(SB),7,$0
|
|||||||
CALL runtime·cgocallback(SB)
|
CALL runtime·cgocallback(SB)
|
||||||
|
|
||||||
// restore registers as required for windows callback
|
// restore registers as required for windows callback
|
||||||
POPL CX
|
POPL AX
|
||||||
POPL CX
|
POPL CX
|
||||||
POPL DX
|
POPL DX
|
||||||
POPL BX
|
POPL BX
|
||||||
@ -139,6 +143,8 @@ TEXT runtime·callbackasm+0(SB),7,$0
|
|||||||
POPL 0(FS)
|
POPL 0(FS)
|
||||||
CLD
|
CLD
|
||||||
|
|
||||||
|
MOVL -4(CX)(DX*1), AX
|
||||||
|
POPL -4(CX)(DX*1)
|
||||||
RET
|
RET
|
||||||
|
|
||||||
// void tstart(M *newm);
|
// void tstart(M *newm);
|
||||||
|
Loading…
Reference in New Issue
Block a user