1
0
mirror of https://github.com/golang/go synced 2024-11-22 02:14:40 -07:00

runtime: make Walk webbrowser example work

R=rsc, brainman, lxn
CC=golang-dev
https://golang.org/cl/4005045
This commit is contained in:
Hector Chu 2011-01-25 17:56:33 +11:00 committed by Alex Brainman
parent 4e5e0b1d20
commit 90294a08c8
6 changed files with 29 additions and 26 deletions

View File

@ -95,7 +95,7 @@ func rungui() int {
} }
// Create callback // Create callback
wproc := syscall.NewCallback(WndProc, 4*4) wproc := syscall.NewCallback(WndProc, 4)
// RegisterClassEx // RegisterClassEx
wcname := syscall.StringToUTF16Ptr("myWindowClass") wcname := syscall.StringToUTF16Ptr("myWindowClass")

View File

@ -28,7 +28,7 @@ func getSysProcAddr(m uint32, pname string) uintptr {
type Wndclassex struct { type Wndclassex struct {
Size uint32 Size uint32
Style uint32 Style uint32
WndProc uint32 WndProc uintptr
ClsExtra int32 ClsExtra int32
WndExtra int32 WndExtra int32
Instance uint32 Instance uint32

View File

@ -47,7 +47,7 @@ ok:
MOVL CX, m_g0(AX) MOVL CX, m_g0(AX)
// create istack out of the OS stack // create istack out of the OS stack
LEAL (-16*1024+104)(SP), AX // TODO: 104? LEAL (-64*1024+104)(SP), AX // TODO: 104?
MOVL AX, g_stackguard(CX) MOVL AX, g_stackguard(CX)
MOVL SP, g_stackbase(CX) MOVL SP, g_stackbase(CX)
CALL runtime·emptyfunc(SB) // fault if stack check is wrong CALL runtime·emptyfunc(SB) // fault if stack check is wrong

View File

@ -84,9 +84,8 @@ TEXT runtime·sigtramp1(SB),0,$16-28
// call windows default handler early // call windows default handler early
MOVL 4(SP), BX // our SEH frame MOVL 4(SP), BX // our SEH frame
MOVL 0(BX), BX // SEH frame of default handler MOVL 0(BX), BX // SEH frame of default handler
MOVL 4(BX), AX // handler function pointer
MOVL BX, 4(SP) // set establisher frame MOVL BX, 4(SP) // set establisher frame
CALL AX CALL 4(BX)
sigdone: sigdone:
RET RET
@ -94,7 +93,7 @@ sigdone:
// Called from dynamic function created by ../thread.c compilecallback, // Called from dynamic function created by ../thread.c compilecallback,
// running on Windows stack (not Go stack). // running on Windows stack (not Go stack).
// Returns straight to DLL. // Returns straight to DLL.
// EBX, ESI, EDI registers and DF flag are preserved // EBX, EBP, ESI, EDI registers and DF flag are preserved
// as required by windows callback convention. // as required by windows callback convention.
// On entry to the function the stack looks like: // On entry to the function the stack looks like:
// //
@ -102,17 +101,19 @@ sigdone:
// 4(SP) - address of go func we need to call // 4(SP) - address of go func we need to call
// 8(SP) - total size of arguments // 8(SP) - total size of arguments
// 12(SP) - room to save BX register // 12(SP) - room to save BX register
// 16(SP) - room to save SI // 16(SP) - room to save BP
// 20(SP) - room to save DI // 20(SP) - room to save SI
// 24(SP) - return address to DLL // 24(SP) - room to save DI
// 28(SP) - beginning of arguments // 28(SP) - return address to DLL
// 32(SP) - beginning of arguments
// //
TEXT runtime·callbackasm+0(SB),7,$0 TEXT runtime·callbackasm+0(SB),7,$0
MOVL BX, 12(SP) // save registers as required for windows callback MOVL BX, 12(SP) // save registers as required for windows callback
MOVL SI, 16(SP) MOVL BP, 16(SP)
MOVL DI, 20(SP) MOVL SI, 20(SP)
MOVL DI, 24(SP)
LEAL args+28(SP), AX LEAL args+32(SP), AX
MOVL AX, 0(SP) MOVL AX, 0(SP)
CLD CLD
@ -120,13 +121,14 @@ TEXT runtime·callbackasm+0(SB),7,$0
CALL runtime·callback(SB) CALL runtime·callback(SB)
MOVL 12(SP), BX // restore registers as required for windows callback MOVL 12(SP), BX // restore registers as required for windows callback
MOVL 16(SP), SI MOVL 16(SP), BP
MOVL 20(SP), DI MOVL 20(SP), SI
MOVL 24(SP), DI
CLD CLD
MOVL ret+24(SP), CX MOVL ret+28(SP), CX
MOVL size+8(SP), DX MOVL size+8(SP), DX
ADDL $28, DX ADDL $32, DX
ADDL DX, SP ADDL DX, SP
JMP CX JMP CX
@ -144,7 +146,7 @@ TEXT runtime·tstart(SB),7,$0
MOVL SP, AX MOVL SP, AX
SUBL $256, AX // just some space for ourselves SUBL $256, AX // just some space for ourselves
MOVL AX, g_stackbase(DX) MOVL AX, g_stackbase(DX)
SUBL $(16*1024), AX // stack size SUBL $(64*1024), AX // stack size
MOVL AX, g_stackguard(DX) MOVL AX, g_stackguard(DX)
// Set up tls. // Set up tls.

View File

@ -276,13 +276,13 @@ runtime·compilecallback(byte *code, void *fn, uint32 argsize)
byte *p; byte *p;
p = code; p = code;
// SUBL $12, SP // SUBL $16, SP
*p++ = 0x83; *p++ = 0x83;
*p++ = 0xec; *p++ = 0xec;
*p++ = 0x0c; *p++ = 0x10;
// PUSH argsize // PUSH argsize * 4
*p++ = 0x68; *p++ = 0x68;
*(uint32*)p = argsize; *(uint32*)p = argsize << 2;
p += 4; p += 4;
// PUSH fn // PUSH fn
*p++ = 0x68; *p++ = 0x68;
@ -308,8 +308,8 @@ runtime·callback(void *arg, void (*fn)(void), int32 argsize)
G *g1; G *g1;
void *sp, *gostack; void *sp, *gostack;
void **p; void **p;
USED(argsize);
USED(argsize);
if(g != m->g0) if(g != m->g0)
runtime·throw("bad g in callback"); runtime·throw("bad g in callback");
@ -326,7 +326,7 @@ runtime·callback(void *arg, void (*fn)(void), int32 argsize)
if(sp < g1->stackguard - StackGuard + 4) // +4 for return address if(sp < g1->stackguard - StackGuard + 4) // +4 for return address
runtime·throw("g stack overflow in callback"); runtime·throw("g stack overflow in callback");
p = sp; p = sp;
p[0] = arg; p[0] = arg;

View File

@ -104,10 +104,11 @@ type Callback struct {
code [50]byte // have to be big enough to fit asm written in it by compileCallback code [50]byte // have to be big enough to fit asm written in it by compileCallback
} }
func (cb *Callback) ExtFnEntry() uint32 { func (cb *Callback) ExtFnEntry() uintptr {
return uint32(uintptr(unsafe.Pointer(&cb.code[0]))) return uintptr(unsafe.Pointer(&cb.code[0]))
} }
// argsize is in words
func NewCallback(fn CallbackFunc, argsize int) *Callback { func NewCallback(fn CallbackFunc, argsize int) *Callback {
cb := Callback{} cb := Callback{}
compileCallback(&cb.code[0], fn, argsize) compileCallback(&cb.code[0], fn, argsize)