]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: add crash stack support for arm
authorMauri de Souza Meneguzzo <mauri870@gmail.com>
Fri, 23 Feb 2024 01:06:40 +0000 (01:06 +0000)
committerMichael Pratt <mpratt@google.com>
Fri, 23 Feb 2024 21:00:52 +0000 (21:00 +0000)
Change-Id: Ide4002d1cf82f2daaf7261b367c391dedbbf7719
GitHub-Last-Rev: 80ee248c3e34529e7a522acc97db9fb69c82dffb
GitHub-Pull-Request: golang/go#65308
Reviewed-on: https://go-review.googlesource.com/c/go/+/558699
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/runtime/asm.s
src/runtime/asm_arm.s
src/runtime/proc.go

index 4833fae5e964900b09bc8660b893d64cfdf4a0f3..64b9e420b68d1014fdc62271cf695696265d24b7 100644 (file)
@@ -13,6 +13,7 @@ TEXT ·sigpanic0(SB),NOSPLIT,$0-0
 TEXT ·mapinitnoop<ABIInternal>(SB),NOSPLIT,$0-0
        RET
 
+#ifndef GOARCH_arm
 #ifndef GOARCH_amd64
 #ifndef GOARCH_arm64
 #ifndef GOARCH_loong64
@@ -36,3 +37,4 @@ TEXT ·switchToCrashStack0<ABIInternal>(SB),NOSPLIT,$0-0
 #endif
 #endif
 #endif
+#endif
index 31a0584fb5d8ca9806fb88a543629a43fea946f3..4d57ec6062ce14252136a986d761d10654c690c6 100644 (file)
@@ -333,6 +333,30 @@ noswitch:
        MOVW.P  4(R13), R14     // restore LR
        B       (R0)
 
+// func switchToCrashStack0(fn func())
+TEXT runtime·switchToCrashStack0(SB), NOSPLIT, $0-4
+       MOVW    fn+0(FP), R7 // context register
+       MOVW    g_m(g), R1 // curm
+
+       // set g to gcrash
+       MOVW    $runtime·gcrash(SB), R0
+       BL      setg<>(SB)      // g = &gcrash
+       MOVW    R1, g_m(g)      // g.m = curm
+       MOVW    g, m_g0(R1)     // curm.g0 = g
+
+       // switch to crashstack
+       MOVW    (g_stack+stack_hi)(g), R1
+       SUB     $(4*8), R1
+       MOVW    R1, R13
+
+       // call target function
+       MOVW    0(R7), R0
+       BL      (R0)
+
+       // should never return
+       CALL    runtime·abort(SB)
+       UNDEF
+
 /*
  * support for morestack
  */
@@ -349,6 +373,14 @@ TEXT runtime·morestack(SB),NOSPLIT|NOFRAME,$0-0
        // Cannot grow scheduler stack (m->g0).
        MOVW    g_m(g), R8
        MOVW    m_g0(R8), R4
+
+       // Called from f.
+       // Set g->sched to context in f.
+       MOVW    R13, (g_sched+gobuf_sp)(g)
+       MOVW    LR, (g_sched+gobuf_pc)(g)
+       MOVW    R3, (g_sched+gobuf_lr)(g)
+       MOVW    R7, (g_sched+gobuf_ctxt)(g)
+
        CMP     g, R4
        BNE     3(PC)
        BL      runtime·badmorestackg0(SB)
@@ -361,13 +393,6 @@ TEXT runtime·morestack(SB),NOSPLIT|NOFRAME,$0-0
        BL      runtime·badmorestackgsignal(SB)
        B       runtime·abort(SB)
 
-       // Called from f.
-       // Set g->sched to context in f.
-       MOVW    R13, (g_sched+gobuf_sp)(g)
-       MOVW    LR, (g_sched+gobuf_pc)(g)
-       MOVW    R3, (g_sched+gobuf_lr)(g)
-       MOVW    R7, (g_sched+gobuf_ctxt)(g)
-
        // Called from f.
        // Set m->morebuf to f's caller.
        MOVW    R3, (m_morebuf+gobuf_pc)(R8)    // f's caller's PC
index 538ed0a282ae01c4333ffea5649ec1bd216f9c52..dc26cda9926db565e1891841634740e732fe0040 100644 (file)
@@ -579,7 +579,7 @@ func switchToCrashStack(fn func()) {
 // Disable crash stack on Windows for now. Apparently, throwing an exception
 // on a non-system-allocated crash stack causes EXCEPTION_STACK_OVERFLOW and
 // hangs the process (see issue 63938).
-const crashStackImplemented = (GOARCH == "amd64" || GOARCH == "arm64" || GOARCH == "loong64" || GOARCH == "mips64" || GOARCH == "mips64le" || GOARCH == "ppc64" || GOARCH == "ppc64le" || GOARCH == "riscv64" || GOARCH == "s390x" || GOARCH == "wasm") && GOOS != "windows"
+const crashStackImplemented = (GOARCH == "amd64" || GOARCH == "arm" || GOARCH == "arm64" || GOARCH == "loong64" || GOARCH == "mips64" || GOARCH == "mips64le" || GOARCH == "ppc64" || GOARCH == "ppc64le" || GOARCH == "riscv64" || GOARCH == "s390x" || GOARCH == "wasm") && GOOS != "windows"
 
 //go:noescape
 func switchToCrashStack0(fn func()) // in assembly