diff options
| author | Joel Sing <joel@sing.id.au> | 2023-11-01 01:34:33 +1100 |
|---|---|---|
| committer | Joel Sing <joel@sing.id.au> | 2023-11-02 14:10:56 +0000 |
| commit | cfe36fd1224706389392e44bdddbc754f70b95bf (patch) | |
| tree | a2051710331bfd16266b8759b79b28a5f5364043 /src | |
| parent | 285ac5a11e36ca4d85a7e97c9040a1e3de0ecc11 (diff) | |
| download | go-cfe36fd1224706389392e44bdddbc754f70b95bf.tar.xz | |
runtime: add crash stack support for riscv64
Change-Id: Ib89a71e20f9c6b86c97814c75cb427e9bd7075e5
Reviewed-on: https://go-review.googlesource.com/c/go/+/538735
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Joel Sing <joel@sing.id.au>
Diffstat (limited to 'src')
| -rw-r--r-- | src/runtime/asm.s | 2 | ||||
| -rw-r--r-- | src/runtime/asm_riscv64.s | 38 | ||||
| -rw-r--r-- | src/runtime/crash_test.go | 2 | ||||
| -rw-r--r-- | src/runtime/export_test.go | 2 | ||||
| -rw-r--r-- | src/runtime/proc.go | 2 |
5 files changed, 37 insertions, 9 deletions
diff --git a/src/runtime/asm.s b/src/runtime/asm.s index 84e561fb43..81d3bfbb8a 100644 --- a/src/runtime/asm.s +++ b/src/runtime/asm.s @@ -15,8 +15,10 @@ TEXT ·mapinitnoop<ABIInternal>(SB),NOSPLIT,$0-0 #ifndef GOARCH_amd64 #ifndef GOARCH_arm64 +#ifndef GOARCH_riscv64 // stub to appease shared build mode. TEXT ·switchToCrashStack0<ABIInternal>(SB),NOSPLIT,$0-0 UNDEF #endif #endif +#endif diff --git a/src/runtime/asm_riscv64.s b/src/runtime/asm_riscv64.s index c2142f1dbb..8ded78437b 100644 --- a/src/runtime/asm_riscv64.s +++ b/src/runtime/asm_riscv64.s @@ -153,6 +153,30 @@ TEXT runtime·getcallerpc(SB),NOSPLIT|NOFRAME,$0-8 MOV T0, ret+0(FP) RET +// func switchToCrashStack0(fn func()) +TEXT runtime·switchToCrashStack0<ABIInternal>(SB), NOSPLIT, $0-8 + MOV X10, CTXT // context register + MOV g_m(g), X11 // curm + + // set g to gcrash + MOV $runtime·gcrash(SB), g // g = &gcrash + CALL runtime·save_g(SB) // clobbers X31 + MOV X11, g_m(g) // g.m = curm + MOV g, m_g0(X11) // curm.g0 = g + + // switch to crashstack + MOV (g_stack+stack_hi)(g), X11 + ADD $(-4*8), X11 + MOV X11, X2 + + // call target function + MOV 0(CTXT), X10 + JALR X1, X10 + + // should never return + CALL runtime·abort(SB) + UNDEF + /* * support for morestack */ @@ -168,6 +192,13 @@ TEXT runtime·getcallerpc(SB),NOSPLIT|NOFRAME,$0-8 // func morestack() TEXT runtime·morestack(SB),NOSPLIT|NOFRAME,$0-0 + // Called from f. + // Set g->sched to context in f. + MOV X2, (g_sched+gobuf_sp)(g) + MOV T0, (g_sched+gobuf_pc)(g) + MOV RA, (g_sched+gobuf_lr)(g) + MOV CTXT, (g_sched+gobuf_ctxt)(g) + // Cannot grow scheduler stack (m->g0). MOV g_m(g), A0 MOV m_g0(A0), A1 @@ -182,13 +213,6 @@ TEXT runtime·morestack(SB),NOSPLIT|NOFRAME,$0-0 CALL runtime·abort(SB) // Called from f. - // Set g->sched to context in f. - MOV X2, (g_sched+gobuf_sp)(g) - MOV T0, (g_sched+gobuf_pc)(g) - MOV RA, (g_sched+gobuf_lr)(g) - MOV CTXT, (g_sched+gobuf_ctxt)(g) - - // Called from f. // Set m->morebuf to f's caller. MOV RA, (m_morebuf+gobuf_pc)(A0) // f's caller's PC MOV X2, (m_morebuf+gobuf_sp)(A0) // f's caller's SP diff --git a/src/runtime/crash_test.go b/src/runtime/crash_test.go index 8aa01f724d..892a56355a 100644 --- a/src/runtime/crash_test.go +++ b/src/runtime/crash_test.go @@ -804,7 +804,7 @@ func TestG0StackOverflow(t *testing.T) { if n := strings.Count(string(out), "morestack on g0\n"); n != 1 { t.Fatalf("%s\n(exit status %v)", out, err) } - if runtime.GOARCH == "amd64" || runtime.GOARCH == "arm64" { + if runtime.CrashStackImplemented { // check for a stack trace want := "runtime.stackOverflow" if n := strings.Count(string(out), want); n < 5 { diff --git a/src/runtime/export_test.go b/src/runtime/export_test.go index 922794edd6..1d4a974871 100644 --- a/src/runtime/export_test.go +++ b/src/runtime/export_test.go @@ -50,6 +50,8 @@ var MemclrNoHeapPointers = memclrNoHeapPointers var CgoCheckPointer = cgoCheckPointer +const CrashStackImplemented = crashStackImplemented + const TracebackInnerFrames = tracebackInnerFrames const TracebackOuterFrames = tracebackOuterFrames diff --git a/src/runtime/proc.go b/src/runtime/proc.go index 7189a0650a..9b5f2e9a6d 100644 --- a/src/runtime/proc.go +++ b/src/runtime/proc.go @@ -574,7 +574,7 @@ func switchToCrashStack(fn func()) { abort() } -const crashStackImplemented = GOARCH == "amd64" || GOARCH == "arm64" +const crashStackImplemented = GOARCH == "amd64" || GOARCH == "arm64" || GOARCH == "riscv64" //go:noescape func switchToCrashStack0(func()) // in assembly |
