From 603d80c28d72c5eae4a0f6a4a8054caf62c5d228 Mon Sep 17 00:00:00 2001 From: Alex Brainman Date: Mon, 7 Nov 2011 11:00:14 +1100 Subject: [PATCH] runtime: windows_386 sighandler to use correct g Fixes #2403. R=hectorchu CC=golang-dev https://golang.org/cl/5309071 --- src/pkg/runtime/windows/386/signal.c | 7 ++-- src/pkg/runtime/windows/386/sys.s | 52 +++++++++------------------- 2 files changed, 19 insertions(+), 40 deletions(-) diff --git a/src/pkg/runtime/windows/386/signal.c b/src/pkg/runtime/windows/386/signal.c index 9c912ede49..8d049c9f32 100644 --- a/src/pkg/runtime/windows/386/signal.c +++ b/src/pkg/runtime/windows/386/signal.c @@ -31,12 +31,9 @@ runtime·initsig(int32) } uint32 -runtime·sighandler(ExceptionRecord *info, void *frame, Context *r) +runtime·sighandler(ExceptionRecord *info, Context *r, G *gp) { uintptr *sp; - G *gp; - - USED(frame); switch(info->ExceptionCode) { case EXCEPTION_BREAKPOINT: @@ -44,7 +41,7 @@ runtime·sighandler(ExceptionRecord *info, void *frame, Context *r) return 1; } - if((gp = m->curg) != nil && runtime·issigpanic(info->ExceptionCode)) { + if(gp != nil && runtime·issigpanic(info->ExceptionCode)) { // Make it look like a call to the signal func. // Have to pass arguments out of band since // augmenting the stack frame would break diff --git a/src/pkg/runtime/windows/386/sys.s b/src/pkg/runtime/windows/386/sys.s index 95ae5336bf..69b9b82e82 100644 --- a/src/pkg/runtime/windows/386/sys.s +++ b/src/pkg/runtime/windows/386/sys.s @@ -48,51 +48,33 @@ TEXT runtime·setlasterror(SB),7,$0 MOVL AX, 0x34(FS) RET -TEXT runtime·sigtramp(SB),7,$0 - PUSHL BP // cdecl - PUSHL BX - PUSHL SI - PUSHL DI - PUSHL 0(FS) - CALL runtime·sigtramp1(SB) - POPL 0(FS) - POPL DI - POPL SI - POPL BX - POPL BP - RET - -TEXT runtime·sigtramp1(SB),0,$16-40 +TEXT runtime·sigtramp(SB),7,$28 // unwinding? - MOVL info+24(FP), BX - MOVL 4(BX), CX // exception flags - ANDL $6, CX + MOVL info+0(FP), CX + TESTL $6, 4(CX) // exception flags MOVL $1, AX JNZ sigdone - // place ourselves at the top of the SEH chain to - // ensure SEH frames lie within thread stack bounds - MOVL frame+28(FP), CX // our SEH frame - MOVL CX, 0(FS) - // copy arguments for call to sighandler - MOVL BX, 0(SP) + MOVL CX, 0(SP) + MOVL context+8(FP), CX MOVL CX, 4(SP) - MOVL context+32(FP), BX - MOVL BX, 8(SP) - MOVL dispatcher+36(FP), BX + get_tls(CX) + MOVL g(CX), CX + MOVL CX, 8(SP) + MOVL BX, 12(SP) + MOVL BP, 16(SP) + MOVL SI, 20(SP) + MOVL DI, 24(SP) CALL runtime·sighandler(SB) - TESTL AX, AX - JZ sigdone - - // call windows default handler early - MOVL 4(SP), BX // our SEH frame - MOVL 0(BX), BX // SEH frame of default handler - MOVL BX, 4(SP) // set establisher frame - CALL 4(BX) + // AX is set to report result back to Windows + MOVL 24(SP), DI + MOVL 20(SP), SI + MOVL 16(SP), BP + MOVL 12(SP), BX sigdone: RET