mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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>
This commit is contained in:
parent
285ac5a11e
commit
cfe36fd122
5 changed files with 37 additions and 9 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -181,13 +212,6 @@ TEXT runtime·morestack(SB),NOSPLIT|NOFRAME,$0-0
|
|||
CALL runtime·badmorestackgsignal(SB)
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -50,6 +50,8 @@ var MemclrNoHeapPointers = memclrNoHeapPointers
|
|||
|
||||
var CgoCheckPointer = cgoCheckPointer
|
||||
|
||||
const CrashStackImplemented = crashStackImplemented
|
||||
|
||||
const TracebackInnerFrames = tracebackInnerFrames
|
||||
const TracebackOuterFrames = tracebackOuterFrames
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue