mirror of
https://github.com/golang/go
synced 2024-11-26 01:17:57 -07: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
@ -62,7 +62,7 @@ import (
|
||||
|
||||
func testSigaltstack(t *testing.T) {
|
||||
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)
|
||||
}
|
||||
|
||||
|
@ -589,7 +589,7 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
|
||||
q1.To.Reg = REGSP
|
||||
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
|
||||
// on the G stack. If we write below SP, it may be clobbered by
|
||||
// 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("SUB $8, RSP, R29") // set up new frame pointer
|
||||
p("#endif")
|
||||
// On darwin, save the LR again after decrementing SP. We run the
|
||||
// signal handler on the G stack (as it doesn't support SA_ONSTACK),
|
||||
// On iOS, save the LR again after decrementing SP. We run the
|
||||
// signal handler on the G stack (as it doesn't support sigaltstack),
|
||||
// so any writes below SP may be clobbered.
|
||||
p("#ifdef GOOS_darwin")
|
||||
p("MOVD R30, (RSP)")
|
||||
p("#endif")
|
||||
p("#ifdef GOOS_ios")
|
||||
p("MOVD R30, (RSP)")
|
||||
p("#endif")
|
||||
|
@ -289,9 +289,9 @@ func mpreinit(mp *m) {
|
||||
// Called to initialize a new m (including the bootstrap m).
|
||||
// Called on the new thread, cannot allocate memory.
|
||||
func minit() {
|
||||
// The alternate signal stack is buggy on arm64.
|
||||
// iOS does not support alternate signal stack.
|
||||
// The signal handler handles it directly.
|
||||
if GOARCH != "arm64" {
|
||||
if !(GOOS == "ios" && GOARCH == "arm64") {
|
||||
minitSignalStack()
|
||||
}
|
||||
minitSignalMask()
|
||||
@ -301,9 +301,9 @@ func minit() {
|
||||
// Called from dropm to undo the effect of an minit.
|
||||
//go:nosplit
|
||||
func unminit() {
|
||||
// The alternate signal stack is buggy on arm64.
|
||||
// iOS does not support alternate signal stack.
|
||||
// See minit.
|
||||
if GOARCH != "arm64" {
|
||||
if !(GOOS == "ios" && GOARCH == "arm64") {
|
||||
unminitSignals()
|
||||
}
|
||||
}
|
||||
|
@ -10,9 +10,6 @@ TEXT ·asyncPreempt(SB),NOSPLIT|NOFRAME,$0-0
|
||||
MOVD R29, -8(RSP)
|
||||
SUB $8, RSP, R29
|
||||
#endif
|
||||
#ifdef GOOS_darwin
|
||||
MOVD R30, (RSP)
|
||||
#endif
|
||||
#ifdef GOOS_ios
|
||||
MOVD R30, (RSP)
|
||||
#endif
|
||||
|
@ -66,7 +66,7 @@ const (
|
||||
// to each stack below the usual guard area for OS-specific
|
||||
// purposes like signal handling. Used on Windows, Plan 9,
|
||||
// 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
|
||||
_StackMin = 2048
|
||||
|
@ -202,6 +202,7 @@ TEXT runtime·sigtramp(SB),NOSPLIT,$192
|
||||
BEQ 2(PC)
|
||||
BL runtime·load_g(SB)
|
||||
|
||||
#ifdef GOOS_ios
|
||||
MOVD RSP, R6
|
||||
CMP $0, g
|
||||
BEQ nog
|
||||
@ -226,16 +227,21 @@ nog:
|
||||
// Switch to gsignal stack.
|
||||
MOVD R6, RSP
|
||||
|
||||
// Call sigtrampgo.
|
||||
// Save arguments.
|
||||
MOVW R0, (8*1)(RSP)
|
||||
MOVD R1, (8*2)(RSP)
|
||||
MOVD R2, (8*3)(RSP)
|
||||
#endif
|
||||
|
||||
// Call sigtrampgo.
|
||||
MOVD $runtime·sigtrampgo(SB), R11
|
||||
BL (R11)
|
||||
|
||||
#ifdef GOOS_ios
|
||||
// Switch to old stack.
|
||||
MOVD (8*4)(RSP), R5
|
||||
MOVD R5, RSP
|
||||
#endif
|
||||
|
||||
// Restore callee-save registers.
|
||||
MOVD (8*4)(RSP), R19
|
||||
@ -329,12 +335,20 @@ TEXT runtime·fcntl_trampoline(SB),NOSPLIT,$0
|
||||
ADD $16, RSP
|
||||
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
|
||||
#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
|
||||
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
|
||||
|
||||
// Thread related functions
|
||||
|
Loading…
Reference in New Issue
Block a user