From cad6629144ddb79401f90bd0388da14294f9131a Mon Sep 17 00:00:00 2001 From: Mauri de Souza Meneguzzo Date: Sat, 2 Dec 2023 15:04:52 +0000 Subject: [PATCH] runtime: add crash stack support for s390x Change-Id: Ie923f7bbe5ef22e381ae4f421387fbd570622a28 GitHub-Last-Rev: f8f21635025eb6e26c6994679995ade501e870cf GitHub-Pull-Request: golang/go#63908 Reviewed-on: https://go-review.googlesource.com/c/go/+/539296 Run-TryBot: Joel Sing TryBot-Result: Gopher Robot Reviewed-by: Cherry Mui Reviewed-by: Carlos Amedee Run-TryBot: Mauri de Souza Meneguzzo Reviewed-by: Joel Sing --- src/runtime/asm.s | 2 ++ src/runtime/asm_s390x.s | 39 +++++++++++++++++++++++++++++++-------- src/runtime/proc.go | 2 +- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/runtime/asm.s b/src/runtime/asm.s index 24cd0c95db6..74ae8789abc 100644 --- a/src/runtime/asm.s +++ b/src/runtime/asm.s @@ -20,6 +20,7 @@ TEXT ·mapinitnoop(SB),NOSPLIT,$0-0 #ifndef GOARCH_ppc64 #ifndef GOARCH_ppc64le #ifndef GOARCH_riscv64 +#ifndef GOARCH_s390x #ifndef GOARCH_wasm // stub to appease shared build mode. TEXT ·switchToCrashStack0(SB),NOSPLIT,$0-0 @@ -32,3 +33,4 @@ TEXT ·switchToCrashStack0(SB),NOSPLIT,$0-0 #endif #endif #endif +#endif diff --git a/src/runtime/asm_s390x.s b/src/runtime/asm_s390x.s index a8e1424bf18..f2354a6d536 100644 --- a/src/runtime/asm_s390x.s +++ b/src/runtime/asm_s390x.s @@ -292,6 +292,29 @@ noswitch: ADD $8, R15 BR (R3) +// func switchToCrashStack0(fn func()) +TEXT runtime·switchToCrashStack0(SB), NOSPLIT, $0-8 + MOVD fn+0(FP), R12 // context + MOVD g_m(g), R4 // curm + + // set g to gcrash + MOVD $runtime·gcrash(SB), g // g = &gcrash + BL runtime·save_g(SB) + MOVD R4, g_m(g) // g.m = curm + MOVD g, m_g0(R4) // curm.g0 = g + + // switch to crashstack + MOVD (g_stack+stack_hi)(g), R4 + ADD $(-4*8), R4, R15 + + // call target function + MOVD 0(R12), R3 // code pointer + BL (R3) + + // should never return + BL runtime·abort(SB) + UNDEF + /* * support for morestack */ @@ -305,6 +328,14 @@ noswitch: // 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|NOFRAME,$0-0 + // Called from f. + // Set g->sched to context in f. + MOVD R15, (g_sched+gobuf_sp)(g) + MOVD LR, R8 + MOVD R8, (g_sched+gobuf_pc)(g) + MOVD R5, (g_sched+gobuf_lr)(g) + MOVD R12, (g_sched+gobuf_ctxt)(g) + // Cannot grow scheduler stack (m->g0). MOVD g_m(g), R7 MOVD m_g0(R7), R8 @@ -319,14 +350,6 @@ TEXT runtime·morestack(SB),NOSPLIT|NOFRAME,$0-0 BL runtime·badmorestackgsignal(SB) BL runtime·abort(SB) - // Called from f. - // Set g->sched to context in f. - MOVD R15, (g_sched+gobuf_sp)(g) - MOVD LR, R8 - MOVD R8, (g_sched+gobuf_pc)(g) - MOVD R5, (g_sched+gobuf_lr)(g) - MOVD R12, (g_sched+gobuf_ctxt)(g) - // Called from f. // Set m->morebuf to f's caller. MOVD R5, (m_morebuf+gobuf_pc)(R7) // f's caller's PC diff --git a/src/runtime/proc.go b/src/runtime/proc.go index c2676c43b2c..b3caeb9a7c2 100644 --- a/src/runtime/proc.go +++ b/src/runtime/proc.go @@ -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 == "mips64" || GOARCH == "mips64le" || GOARCH == "ppc64" || GOARCH == "ppc64le" || GOARCH == "riscv64" || GOARCH == "wasm") && GOOS != "windows" +const crashStackImplemented = (GOARCH == "amd64" || GOARCH == "arm64" || GOARCH == "mips64" || GOARCH == "mips64le" || GOARCH == "ppc64" || GOARCH == "ppc64le" || GOARCH == "riscv64" || GOARCH == "s390x" || GOARCH == "wasm") && GOOS != "windows" //go:noescape func switchToCrashStack0(fn func()) // in assembly