Commit 90294a08 authored by Hector Chu's avatar Hector Chu Committed by Alex Brainman

runtime: make Walk webbrowser example work

R=rsc, brainman, lxn
CC=golang-dev
https://golang.org/cl/4005045
parent 4e5e0b1d
......@@ -95,7 +95,7 @@ func rungui() int {
}
// Create callback
wproc := syscall.NewCallback(WndProc, 4*4)
wproc := syscall.NewCallback(WndProc, 4)
// RegisterClassEx
wcname := syscall.StringToUTF16Ptr("myWindowClass")
......
......@@ -28,7 +28,7 @@ func getSysProcAddr(m uint32, pname string) uintptr {
type Wndclassex struct {
Size uint32
Style uint32
WndProc uint32
WndProc uintptr
ClsExtra int32
WndExtra int32
Instance uint32
......
......@@ -47,7 +47,7 @@ ok:
MOVL CX, m_g0(AX)
// 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 SP, g_stackbase(CX)
CALL runtime·emptyfunc(SB) // fault if stack check is wrong
......
......@@ -84,9 +84,8 @@ TEXT runtime·sigtramp1(SB),0,$16-28
// call windows default handler early
MOVL 4(SP), BX // our SEH frame
MOVL 0(BX), BX // SEH frame of default handler
MOVL 4(BX), AX // handler function pointer
MOVL BX, 4(SP) // set establisher frame
CALL AX
CALL 4(BX)
sigdone:
RET
......@@ -94,7 +93,7 @@ sigdone:
// Called from dynamic function created by ../thread.c compilecallback,
// running on Windows stack (not Go stack).
// 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.
// On entry to the function the stack looks like:
//
......@@ -102,17 +101,19 @@ sigdone:
// 4(SP) - address of go func we need to call
// 8(SP) - total size of arguments
// 12(SP) - room to save BX register
// 16(SP) - room to save SI
// 20(SP) - room to save DI
// 24(SP) - return address to DLL
// 28(SP) - beginning of arguments
// 16(SP) - room to save BP
// 20(SP) - room to save SI
// 24(SP) - room to save DI
// 28(SP) - return address to DLL
// 32(SP) - beginning of arguments
//
TEXT runtime·callbackasm+0(SB),7,$0
MOVL BX, 12(SP) // save registers as required for windows callback
MOVL SI, 16(SP)
MOVL DI, 20(SP)
MOVL BP, 16(SP)
MOVL SI, 20(SP)
MOVL DI, 24(SP)
LEAL args+28(SP), AX
LEAL args+32(SP), AX
MOVL AX, 0(SP)
CLD
......@@ -120,13 +121,14 @@ TEXT runtime·callbackasm+0(SB),7,$0
CALL runtime·callback(SB)
MOVL 12(SP), BX // restore registers as required for windows callback
MOVL 16(SP), SI
MOVL 20(SP), DI
MOVL 16(SP), BP
MOVL 20(SP), SI
MOVL 24(SP), DI
CLD
MOVL ret+24(SP), CX
MOVL ret+28(SP), CX
MOVL size+8(SP), DX
ADDL $28, DX
ADDL $32, DX
ADDL DX, SP
JMP CX
......@@ -144,7 +146,7 @@ TEXT runtime·tstart(SB),7,$0
MOVL SP, AX
SUBL $256, AX // just some space for ourselves
MOVL AX, g_stackbase(DX)
SUBL $(16*1024), AX // stack size
SUBL $(64*1024), AX // stack size
MOVL AX, g_stackguard(DX)
// Set up tls.
......
......@@ -276,13 +276,13 @@ runtime·compilecallback(byte *code, void *fn, uint32 argsize)
byte *p;
p = code;
// SUBL $12, SP
// SUBL $16, SP
*p++ = 0x83;
*p++ = 0xec;
*p++ = 0x0c;
// PUSH argsize
*p++ = 0x10;
// PUSH argsize * 4
*p++ = 0x68;
*(uint32*)p = argsize;
*(uint32*)p = argsize << 2;
p += 4;
// PUSH fn
*p++ = 0x68;
......@@ -308,8 +308,8 @@ runtime·callback(void *arg, void (*fn)(void), int32 argsize)
G *g1;
void *sp, *gostack;
void **p;
USED(argsize);
USED(argsize);
if(g != m->g0)
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
runtime·throw("g stack overflow in callback");
p = sp;
p[0] = arg;
......
......@@ -104,10 +104,11 @@ type Callback struct {
code [50]byte // have to be big enough to fit asm written in it by compileCallback
}
func (cb *Callback) ExtFnEntry() uint32 {
return uint32(uintptr(unsafe.Pointer(&cb.code[0])))
func (cb *Callback) ExtFnEntry() uintptr {
return uintptr(unsafe.Pointer(&cb.code[0]))
}
// argsize is in words
func NewCallback(fn CallbackFunc, argsize int) *Callback {
cb := Callback{}
compileCallback(&cb.code[0], fn, argsize)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment