Skip to content
This repository has been archived by the owner on May 2, 2018. It is now read-only.

Commit

Permalink
runtime: fix 386 signal handler bug
Browse files Browse the repository at this point in the history
Cannot assume that g == m->curg at time of signal.
Must save actual g and restore.

Fixes flaky crashes with messages like

throw: malloc mlookup
throw: malloc/free - deadlock
throw: unwindstack on self
throw: free mlookup

(and probably others) when running cgo.

R=iant
CC=golang-dev
https://golang.org/cl/1648043
  • Loading branch information
rsc committed Jun 12, 2010
1 parent 9d72aaa commit 53a529a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 15 deletions.
12 changes: 8 additions & 4 deletions src/pkg/runtime/darwin/386/sys.s
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,13 @@ TEXT sigaction(SB),7,$0
// 16(FP) siginfo
// 20(FP) context
TEXT sigtramp(SB),7,$40
// g = m->gsignal
get_tls(CX)

// save g
MOVL g(CX), BP
MOVL BP, 20(SP)

// g = m->gsignal
MOVL m(CX), BP
MOVL m_gsignal(BP), BP
MOVL BP, g(CX)
Expand All @@ -91,10 +96,9 @@ TEXT sigtramp(SB),7,$40
MOVL CX, 8(SP)
CALL DI

// g = m->curg
// restore g
get_tls(CX)
MOVL m(CX), BP
MOVL m_curg(BP), BP
MOVL 20(SP), BP
MOVL BP, g(CX)

MOVL context+16(FP), CX
Expand Down
38 changes: 27 additions & 11 deletions src/pkg/runtime/linux/386/sys.s
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,39 @@ TEXT rt_sigaction(SB),7,$0
INT $0x80
RET

TEXT sigtramp(SB),7,$0
TEXT sigtramp(SB),7,$40
get_tls(CX)
MOVL m(CX), BP
MOVL m_gsignal(BP), AX
MOVL AX, g(CX)
JMP sighandler(SB)

// save g
MOVL g(CX), BX
MOVL BX, 20(SP)

// g = m->gsignal
MOVL m(CX), BX
MOVL m_gsignal(BX), BX
MOVL BX, g(CX)

// copy arguments for call to sighandler
MOVL sig+0(FP), BX
MOVL BX, 0(SP)
MOVL info+4(FP), BX
MOVL BX, 4(SP)
MOVL context+8(FP), BX
MOVL BX, 8(SP)

CALL sighandler(SB)

// restore g
get_tls(CX)
MOVL 20(SP), BX
MOVL BX, g(CX)

RET

TEXT sigignore(SB),7,$0
RET

TEXT sigreturn(SB),7,$0
// g = m->curg
get_tls(CX)
MOVL m(CX), BP
MOVL m_curg(BP), BP
MOVL BP, g(CX)
MOVL $173, AX // rt_sigreturn
INT $0x80
INT $3 // not reached
Expand Down Expand Up @@ -259,4 +276,3 @@ TEXT setldt(SB),7,$32
MOVW AX, GS

RET

0 comments on commit 53a529a

Please sign in to comment.