Skip to content

Commit e293c4b

Browse files
4a6f656ccherrymui
authored andcommitted
runtime: allocate crash stack via stackalloc
On some platforms (notably OpenBSD), stacks must be specifically allocated and marked as being stack memory. Allocate the crash stack using stackalloc, which ensures these requirements are met, rather than using a global Go variable. Fixes #63794 Change-Id: I6513575797dd69ff0a36f3bfd4e5fc3bd95cbf50 Reviewed-on: https://go-review.googlesource.com/c/go/+/538457 Run-TryBot: Joel Sing <[email protected]> Reviewed-by: Bryan Mills <[email protected]> Reviewed-by: Mauri de Souza Meneguzzo <[email protected]> Reviewed-by: Cherry Mui <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent b7a66be commit e293c4b

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/runtime/proc.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -543,16 +543,9 @@ func badctxt() {
543543
throw("ctxt != 0")
544544
}
545545

546-
// crashstack is a space that can be used as the stack when it is
547-
// crashing on bad stack conditions, e.g. morestack on g0.
548-
// gcrash is the corresponding (fake) g.
549-
var crashstack [16384]byte
550-
551-
var gcrash = g{
552-
stack: stack{uintptr(unsafe.Pointer(&crashstack)), uintptr(unsafe.Pointer(&crashstack)) + unsafe.Sizeof(crashstack)},
553-
stackguard0: uintptr(unsafe.Pointer(&crashstack)) + 1000,
554-
stackguard1: uintptr(unsafe.Pointer(&crashstack)) + 1000,
555-
}
546+
// gcrash is a fake g that can be used when crashing due to bad
547+
// stack conditions.
548+
var gcrash g
556549

557550
var crashingG atomic.Pointer[g]
558551

@@ -803,6 +796,12 @@ func schedinit() {
803796
parsedebugvars()
804797
gcinit()
805798

799+
// Allocate stack space that can be used when crashing due to bad stack
800+
// conditions, e.g. morestack on g0.
801+
gcrash.stack = stackalloc(16384)
802+
gcrash.stackguard0 = gcrash.stack.lo + 1000
803+
gcrash.stackguard1 = gcrash.stack.lo + 1000
804+
806805
// if disableMemoryProfiling is set, update MemProfileRate to 0 to turn off memprofile.
807806
// Note: parsedebugvars may update MemProfileRate, but when disableMemoryProfiling is
808807
// set to true by the linker, it means that nothing is consuming the profile, it is

0 commit comments

Comments
 (0)