mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime: use sigaltstack on macOS/ARM64
Currently we don't use sigaltstack on darwin/arm64, as is not supported on iOS. However, it is supported on macOS. Use it. (iOS remains unchanged.) Change-Id: Icc154c5e2edf2dbdc8ca68741ad9157fc15a72ee Reviewed-on: https://go-review.googlesource.com/c/go/+/256917 Trust: Cherry Zhang <cherryyz@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
04c7e32517
commit
28e549dec3
7 changed files with 27 additions and 19 deletions
|
|
@ -62,7 +62,7 @@ import (
|
||||||
|
|
||||||
func testSigaltstack(t *testing.T) {
|
func testSigaltstack(t *testing.T) {
|
||||||
switch {
|
switch {
|
||||||
case runtime.GOOS == "solaris", runtime.GOOS == "illumos", (runtime.GOOS == "darwin" || runtime.GOOS == "ios") && runtime.GOARCH == "arm64":
|
case runtime.GOOS == "solaris", runtime.GOOS == "illumos", runtime.GOOS == "ios" && runtime.GOARCH == "arm64":
|
||||||
t.Skipf("switching signal stack not implemented on %s/%s", runtime.GOOS, runtime.GOARCH)
|
t.Skipf("switching signal stack not implemented on %s/%s", runtime.GOOS, runtime.GOARCH)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -589,7 +589,7 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
|
||||||
q1.To.Reg = REGSP
|
q1.To.Reg = REGSP
|
||||||
q1.Spadj = c.autosize
|
q1.Spadj = c.autosize
|
||||||
|
|
||||||
if c.ctxt.Headtype == objabi.Hdarwin {
|
if objabi.GOOS == "ios" {
|
||||||
// iOS does not support SA_ONSTACK. We will run the signal handler
|
// iOS does not support SA_ONSTACK. We will run the signal handler
|
||||||
// on the G stack. If we write below SP, it may be clobbered by
|
// on the G stack. If we write below SP, it may be clobbered by
|
||||||
// the signal handler. So we save LR after decrementing SP.
|
// the signal handler. So we save LR after decrementing SP.
|
||||||
|
|
|
||||||
|
|
@ -340,12 +340,9 @@ func genARM64() {
|
||||||
p("MOVD R29, -8(RSP)") // save frame pointer (only used on Linux)
|
p("MOVD R29, -8(RSP)") // save frame pointer (only used on Linux)
|
||||||
p("SUB $8, RSP, R29") // set up new frame pointer
|
p("SUB $8, RSP, R29") // set up new frame pointer
|
||||||
p("#endif")
|
p("#endif")
|
||||||
// On darwin, save the LR again after decrementing SP. We run the
|
// On iOS, save the LR again after decrementing SP. We run the
|
||||||
// signal handler on the G stack (as it doesn't support SA_ONSTACK),
|
// signal handler on the G stack (as it doesn't support sigaltstack),
|
||||||
// so any writes below SP may be clobbered.
|
// so any writes below SP may be clobbered.
|
||||||
p("#ifdef GOOS_darwin")
|
|
||||||
p("MOVD R30, (RSP)")
|
|
||||||
p("#endif")
|
|
||||||
p("#ifdef GOOS_ios")
|
p("#ifdef GOOS_ios")
|
||||||
p("MOVD R30, (RSP)")
|
p("MOVD R30, (RSP)")
|
||||||
p("#endif")
|
p("#endif")
|
||||||
|
|
|
||||||
|
|
@ -289,9 +289,9 @@ func mpreinit(mp *m) {
|
||||||
// Called to initialize a new m (including the bootstrap m).
|
// Called to initialize a new m (including the bootstrap m).
|
||||||
// Called on the new thread, cannot allocate memory.
|
// Called on the new thread, cannot allocate memory.
|
||||||
func minit() {
|
func minit() {
|
||||||
// The alternate signal stack is buggy on arm64.
|
// iOS does not support alternate signal stack.
|
||||||
// The signal handler handles it directly.
|
// The signal handler handles it directly.
|
||||||
if GOARCH != "arm64" {
|
if !(GOOS == "ios" && GOARCH == "arm64") {
|
||||||
minitSignalStack()
|
minitSignalStack()
|
||||||
}
|
}
|
||||||
minitSignalMask()
|
minitSignalMask()
|
||||||
|
|
@ -301,9 +301,9 @@ func minit() {
|
||||||
// Called from dropm to undo the effect of an minit.
|
// Called from dropm to undo the effect of an minit.
|
||||||
//go:nosplit
|
//go:nosplit
|
||||||
func unminit() {
|
func unminit() {
|
||||||
// The alternate signal stack is buggy on arm64.
|
// iOS does not support alternate signal stack.
|
||||||
// See minit.
|
// See minit.
|
||||||
if GOARCH != "arm64" {
|
if !(GOOS == "ios" && GOARCH == "arm64") {
|
||||||
unminitSignals()
|
unminitSignals()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,9 +10,6 @@ TEXT ·asyncPreempt(SB),NOSPLIT|NOFRAME,$0-0
|
||||||
MOVD R29, -8(RSP)
|
MOVD R29, -8(RSP)
|
||||||
SUB $8, RSP, R29
|
SUB $8, RSP, R29
|
||||||
#endif
|
#endif
|
||||||
#ifdef GOOS_darwin
|
|
||||||
MOVD R30, (RSP)
|
|
||||||
#endif
|
|
||||||
#ifdef GOOS_ios
|
#ifdef GOOS_ios
|
||||||
MOVD R30, (RSP)
|
MOVD R30, (RSP)
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ const (
|
||||||
// to each stack below the usual guard area for OS-specific
|
// to each stack below the usual guard area for OS-specific
|
||||||
// purposes like signal handling. Used on Windows, Plan 9,
|
// purposes like signal handling. Used on Windows, Plan 9,
|
||||||
// and iOS because they do not use a separate stack.
|
// and iOS because they do not use a separate stack.
|
||||||
_StackSystem = sys.GoosWindows*512*sys.PtrSize + sys.GoosPlan9*512 + (sys.GoosDarwin+sys.GoosIos)*sys.GoarchArm64*1024
|
_StackSystem = sys.GoosWindows*512*sys.PtrSize + sys.GoosPlan9*512 + sys.GoosIos*sys.GoarchArm64*1024
|
||||||
|
|
||||||
// The minimum size of stack used by Go code
|
// The minimum size of stack used by Go code
|
||||||
_StackMin = 2048
|
_StackMin = 2048
|
||||||
|
|
|
||||||
|
|
@ -202,6 +202,7 @@ TEXT runtime·sigtramp(SB),NOSPLIT,$192
|
||||||
BEQ 2(PC)
|
BEQ 2(PC)
|
||||||
BL runtime·load_g(SB)
|
BL runtime·load_g(SB)
|
||||||
|
|
||||||
|
#ifdef GOOS_ios
|
||||||
MOVD RSP, R6
|
MOVD RSP, R6
|
||||||
CMP $0, g
|
CMP $0, g
|
||||||
BEQ nog
|
BEQ nog
|
||||||
|
|
@ -226,16 +227,21 @@ nog:
|
||||||
// Switch to gsignal stack.
|
// Switch to gsignal stack.
|
||||||
MOVD R6, RSP
|
MOVD R6, RSP
|
||||||
|
|
||||||
// Call sigtrampgo.
|
// Save arguments.
|
||||||
MOVW R0, (8*1)(RSP)
|
MOVW R0, (8*1)(RSP)
|
||||||
MOVD R1, (8*2)(RSP)
|
MOVD R1, (8*2)(RSP)
|
||||||
MOVD R2, (8*3)(RSP)
|
MOVD R2, (8*3)(RSP)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Call sigtrampgo.
|
||||||
MOVD $runtime·sigtrampgo(SB), R11
|
MOVD $runtime·sigtrampgo(SB), R11
|
||||||
BL (R11)
|
BL (R11)
|
||||||
|
|
||||||
|
#ifdef GOOS_ios
|
||||||
// Switch to old stack.
|
// Switch to old stack.
|
||||||
MOVD (8*4)(RSP), R5
|
MOVD (8*4)(RSP), R5
|
||||||
MOVD R5, RSP
|
MOVD R5, RSP
|
||||||
|
#endif
|
||||||
|
|
||||||
// Restore callee-save registers.
|
// Restore callee-save registers.
|
||||||
MOVD (8*4)(RSP), R19
|
MOVD (8*4)(RSP), R19
|
||||||
|
|
@ -329,12 +335,20 @@ TEXT runtime·fcntl_trampoline(SB),NOSPLIT,$0
|
||||||
ADD $16, RSP
|
ADD $16, RSP
|
||||||
RET
|
RET
|
||||||
|
|
||||||
// sigaltstack on iOS is not supported and will always
|
|
||||||
// run the signal handler on the main stack, so our sigtramp has
|
|
||||||
// to do the stack switch ourselves.
|
|
||||||
TEXT runtime·sigaltstack_trampoline(SB),NOSPLIT,$0
|
TEXT runtime·sigaltstack_trampoline(SB),NOSPLIT,$0
|
||||||
|
#ifdef GOOS_ios
|
||||||
|
// sigaltstack on iOS is not supported and will always
|
||||||
|
// run the signal handler on the main stack, so our sigtramp has
|
||||||
|
// to do the stack switch ourselves.
|
||||||
MOVW $43, R0
|
MOVW $43, R0
|
||||||
BL libc_exit(SB)
|
BL libc_exit(SB)
|
||||||
|
#else
|
||||||
|
MOVD 8(R0), R1 // arg 2 old
|
||||||
|
MOVD 0(R0), R0 // arg 1 new
|
||||||
|
CALL libc_sigaltstack(SB)
|
||||||
|
CBZ R0, 2(PC)
|
||||||
|
BL notok<>(SB)
|
||||||
|
#endif
|
||||||
RET
|
RET
|
||||||
|
|
||||||
// Thread related functions
|
// Thread related functions
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue