]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: add crash stack support for 386
authorMauri de Souza Meneguzzo <mauri870@gmail.com>
Sun, 25 Feb 2024 14:22:52 +0000 (14:22 +0000)
committerCherry Mui <cherryyz@google.com>
Fri, 15 Mar 2024 15:45:13 +0000 (15:45 +0000)
Change-Id: Ib787b27670ad0f10bcc94b3ce76e86746997af00
GitHub-Last-Rev: e5abb9a556ae709d30d6ffb5a13805923c215254
GitHub-Pull-Request: golang/go#65934
Reviewed-on: https://go-review.googlesource.com/c/go/+/566715
Reviewed-by: Michael Pratt <mpratt@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
src/runtime/asm.s
src/runtime/asm_386.s
src/runtime/proc.go

index 64b9e420b68d1014fdc62271cf695696265d24b7..75b3013f4b31713df0f45fce52b2ad72a69f2056 100644 (file)
@@ -13,6 +13,7 @@ TEXT ·sigpanic0(SB),NOSPLIT,$0-0
 TEXT ·mapinitnoop<ABIInternal>(SB),NOSPLIT,$0-0
        RET
 
+#ifndef GOARCH_386
 #ifndef GOARCH_arm
 #ifndef GOARCH_amd64
 #ifndef GOARCH_arm64
@@ -38,3 +39,4 @@ TEXT ·switchToCrashStack0<ABIInternal>(SB),NOSPLIT,$0-0
 #endif
 #endif
 #endif
+#endif
index 67ffc243539e984a11aa1cc3d0bea6e3d2b7c69f..5aafe14be9a107042c6188ecfd0e61bbe8c1fadb 100644 (file)
@@ -398,6 +398,35 @@ bad:
        CALL    AX
        INT     $3
 
+// func switchToCrashStack0(fn func())
+TEXT runtime·switchToCrashStack0(SB), NOSPLIT, $0-4
+       MOVL    fn+0(FP), AX
+
+       get_tls(CX)
+       MOVL    g(CX), BX       // BX = g
+       MOVL    g_m(BX), DX     // DX = curm
+
+       // set g to gcrash
+       LEAL    runtime·gcrash(SB), BX // g = &gcrash
+       MOVL    DX, g_m(BX)            // g.m = curm
+       MOVL    BX, m_g0(DX)           // curm.g0 = g
+       get_tls(CX)
+       MOVL    BX, g(CX)
+
+       // switch to crashstack
+       MOVL    (g_stack+stack_hi)(BX), DX
+       SUBL    $(4*8), DX
+       MOVL    DX, SP
+
+       // call target function
+       MOVL    AX, DX
+       MOVL    0(AX), AX
+       CALL    AX
+
+       // should never return
+       CALL    runtime·abort(SB)
+       UNDEF
+
 /*
  * support for morestack
  */
@@ -408,11 +437,19 @@ bad:
 // the top of a stack (for example, morestack calling newstack
 // calling the scheduler calling newm calling gc), so we must
 // record an argument size. For that purpose, it has no arguments.
-TEXT runtime·morestack(SB),NOSPLIT,$0-0
+TEXT runtime·morestack(SB),NOSPLIT|NOFRAME,$0-0
        // Cannot grow scheduler stack (m->g0).
        get_tls(CX)
-       MOVL    g(CX), BX
-       MOVL    g_m(BX), BX
+       MOVL    g(CX), DI
+       MOVL    g_m(DI), BX
+
+       // Set g->sched to context in f.
+       MOVL    0(SP), AX       // f's PC
+       MOVL    AX, (g_sched+gobuf_pc)(DI)
+       LEAL    4(SP), AX       // f's SP
+       MOVL    AX, (g_sched+gobuf_sp)(DI)
+       MOVL    DX, (g_sched+gobuf_ctxt)(DI)
+
        MOVL    m_g0(BX), SI
        CMPL    g(CX), SI
        JNE     3(PC)
@@ -437,13 +474,6 @@ TEXT runtime·morestack(SB),NOSPLIT,$0-0
        MOVL    g(CX), SI
        MOVL    SI, (m_morebuf+gobuf_g)(BX)
 
-       // Set g->sched to context in f.
-       MOVL    0(SP), AX       // f's PC
-       MOVL    AX, (g_sched+gobuf_pc)(SI)
-       LEAL    4(SP), AX       // f's SP
-       MOVL    AX, (g_sched+gobuf_sp)(SI)
-       MOVL    DX, (g_sched+gobuf_ctxt)(SI)
-
        // Call newstack on m->g0's stack.
        MOVL    m_g0(BX), BP
        MOVL    BP, g(CX)
index 36e895b8f047d71126487332da10766c15c63b4c..8e92a5ee8ed71eb139f99bb18877c9fae5d0dbaa 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 == "arm" || GOARCH == "arm64" || GOARCH == "loong64" || GOARCH == "mips64" || GOARCH == "mips64le" || GOARCH == "ppc64" || GOARCH == "ppc64le" || GOARCH == "riscv64" || GOARCH == "s390x" || GOARCH == "wasm") && GOOS != "windows"
+const crashStackImplemented = (GOARCH == "386" || 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