]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: use sigaltstack on macOS/ARM64
authorCherry Zhang <cherryyz@google.com>
Sat, 12 Sep 2020 16:33:24 +0000 (12:33 -0400)
committerCherry Zhang <cherryyz@google.com>
Tue, 6 Oct 2020 21:25:42 +0000 (21:25 +0000)
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>
misc/cgo/test/sigaltstack.go
src/cmd/internal/obj/arm64/obj7.go
src/runtime/mkpreempt.go
src/runtime/os_darwin.go
src/runtime/preempt_arm64.s
src/runtime/stack.go
src/runtime/sys_darwin_arm64.s

index 27b753a147a3228f39d5d15734280fc9657605c5..034cc4b3719150c379d97c0f1efa9bc7ce4747c9 100644 (file)
@@ -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)
        }
 
index 56da854f16ae32b1bd5feda299760e794a256239..f1bc2583cbe30aaa52e9b866d87f7f440dabf87d 100644 (file)
@@ -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.
index c5bfb0f20735e2b98d1e4ef37e5a4e60ed650224..40683bb9d9b36f3dbf38132def70f5c9ca3cbd3e 100644 (file)
@@ -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")
index 01c40b4813dffcc9ce8e647e4e5a851ee9a4c43c..394bd6fb0f79ca459043003e87e0c899cd13d58f 100644 (file)
@@ -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()
        }
 }
index d0e77659c36cf061f7b7a2a99cef38e81f63011e..36ee13282c777630eaa6e19310b236e7ada65634 100644 (file)
@@ -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
index 3802cd049e87ea35d82cdda09d1d16b6c3f2004d..2afc2635aab5d18c1b37b4d613c1f340609b889c 100644 (file)
@@ -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
index 585d4f2c6433fc286fbda546590ebfe951c2101b..427cb177812119c952d5ffa049f2cf14e56bdf1a 100644 (file)
@@ -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