Skip to content

Commit

Permalink
runtime: add crash stack support for s390x
Browse files Browse the repository at this point in the history
Change-Id: Ie923f7bbe5ef22e381ae4f421387fbd570622a28
GitHub-Last-Rev: f8f2163
GitHub-Pull-Request: #63908
Reviewed-on: https://go-review.googlesource.com/c/go/+/539296
Run-TryBot: Joel Sing <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Reviewed-by: Cherry Mui <[email protected]>
Reviewed-by: Carlos Amedee <[email protected]>
Run-TryBot: Mauri de Souza Meneguzzo <[email protected]>
Reviewed-by: Joel Sing <[email protected]>
  • Loading branch information
mauri870 authored and 4a6f656c committed Jan 25, 2024
1 parent 2c35def commit cad6629
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/runtime/asm.s
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ TEXT ·mapinitnoop<ABIInternal>(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<ABIInternal>(SB),NOSPLIT,$0-0
Expand All @@ -32,3 +33,4 @@ TEXT ·switchToCrashStack0<ABIInternal>(SB),NOSPLIT,$0-0
#endif
#endif
#endif
#endif
39 changes: 31 additions & 8 deletions src/runtime/asm_s390x.s
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,29 @@ noswitch:
ADD $8, R15
BR (R3)

// func switchToCrashStack0(fn func())
TEXT runtime·switchToCrashStack0<ABIInternal>(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
*/
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/proc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cad6629

Please sign in to comment.