Skip to content

Commit c764d56

Browse files
mauri870cherrymui
authored andcommitted
runtime: add crash stack support for 386
Change-Id: Ib787b27670ad0f10bcc94b3ce76e86746997af00 GitHub-Last-Rev: e5abb9a GitHub-Pull-Request: #65934 Reviewed-on: https://go-review.googlesource.com/c/go/+/566715 Reviewed-by: Michael Pratt <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Cherry Mui <[email protected]>
1 parent 83b2b47 commit c764d56

File tree

3 files changed

+43
-11
lines changed

3 files changed

+43
-11
lines changed

src/runtime/asm.s

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ TEXT ·sigpanic0(SB),NOSPLIT,$0-0
1313
TEXT ·mapinitnoop<ABIInternal>(SB),NOSPLIT,$0-0
1414
RET
1515

16+
#ifndef GOARCH_386
1617
#ifndef GOARCH_arm
1718
#ifndef GOARCH_amd64
1819
#ifndef GOARCH_arm64
@@ -38,3 +39,4 @@ TEXT ·switchToCrashStack0<ABIInternal>(SB),NOSPLIT,$0-0
3839
#endif
3940
#endif
4041
#endif
42+
#endif

src/runtime/asm_386.s

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,35 @@ bad:
398398
CALL AX
399399
INT $3
400400

401+
// func switchToCrashStack0(fn func())
402+
TEXT runtime·switchToCrashStack0(SB), NOSPLIT, $0-4
403+
MOVL fn+0(FP), AX
404+
405+
get_tls(CX)
406+
MOVL g(CX), BX // BX = g
407+
MOVL g_m(BX), DX // DX = curm
408+
409+
// set g to gcrash
410+
LEAL runtime·gcrash(SB), BX // g = &gcrash
411+
MOVL DX, g_m(BX) // g.m = curm
412+
MOVL BX, m_g0(DX) // curm.g0 = g
413+
get_tls(CX)
414+
MOVL BX, g(CX)
415+
416+
// switch to crashstack
417+
MOVL (g_stack+stack_hi)(BX), DX
418+
SUBL $(4*8), DX
419+
MOVL DX, SP
420+
421+
// call target function
422+
MOVL AX, DX
423+
MOVL 0(AX), AX
424+
CALL AX
425+
426+
// should never return
427+
CALL runtime·abort(SB)
428+
UNDEF
429+
401430
/*
402431
* support for morestack
403432
*/
@@ -408,11 +437,19 @@ bad:
408437
// the top of a stack (for example, morestack calling newstack
409438
// calling the scheduler calling newm calling gc), so we must
410439
// record an argument size. For that purpose, it has no arguments.
411-
TEXT runtime·morestack(SB),NOSPLIT,$0-0
440+
TEXT runtime·morestack(SB),NOSPLIT|NOFRAME,$0-0
412441
// Cannot grow scheduler stack (m->g0).
413442
get_tls(CX)
414-
MOVL g(CX), BX
415-
MOVL g_m(BX), BX
443+
MOVL g(CX), DI
444+
MOVL g_m(DI), BX
445+
446+
// Set g->sched to context in f.
447+
MOVL 0(SP), AX // f's PC
448+
MOVL AX, (g_sched+gobuf_pc)(DI)
449+
LEAL 4(SP), AX // f's SP
450+
MOVL AX, (g_sched+gobuf_sp)(DI)
451+
MOVL DX, (g_sched+gobuf_ctxt)(DI)
452+
416453
MOVL m_g0(BX), SI
417454
CMPL g(CX), SI
418455
JNE 3(PC)
@@ -437,13 +474,6 @@ TEXT runtime·morestack(SB),NOSPLIT,$0-0
437474
MOVL g(CX), SI
438475
MOVL SI, (m_morebuf+gobuf_g)(BX)
439476

440-
// Set g->sched to context in f.
441-
MOVL 0(SP), AX // f's PC
442-
MOVL AX, (g_sched+gobuf_pc)(SI)
443-
LEAL 4(SP), AX // f's SP
444-
MOVL AX, (g_sched+gobuf_sp)(SI)
445-
MOVL DX, (g_sched+gobuf_ctxt)(SI)
446-
447477
// Call newstack on m->g0's stack.
448478
MOVL m_g0(BX), BP
449479
MOVL BP, g(CX)

src/runtime/proc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ func switchToCrashStack(fn func()) {
579579
// Disable crash stack on Windows for now. Apparently, throwing an exception
580580
// on a non-system-allocated crash stack causes EXCEPTION_STACK_OVERFLOW and
581581
// hangs the process (see issue 63938).
582-
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"
582+
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"
583583

584584
//go:noescape
585585
func switchToCrashStack0(fn func()) // in assembly

0 commit comments

Comments
 (0)