mirror of https://github.com/golang/go.git
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 <joel@sing.id.au> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Mauri de Souza Meneguzzo <mauri870@gmail.com> Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
parent
b7a66be69c
commit
e293c4b509
|
|
@ -543,16 +543,9 @@ func badctxt() {
|
|||
throw("ctxt != 0")
|
||||
}
|
||||
|
||||
// crashstack is a space that can be used as the stack when it is
|
||||
// crashing on bad stack conditions, e.g. morestack on g0.
|
||||
// gcrash is the corresponding (fake) g.
|
||||
var crashstack [16384]byte
|
||||
|
||||
var gcrash = g{
|
||||
stack: stack{uintptr(unsafe.Pointer(&crashstack)), uintptr(unsafe.Pointer(&crashstack)) + unsafe.Sizeof(crashstack)},
|
||||
stackguard0: uintptr(unsafe.Pointer(&crashstack)) + 1000,
|
||||
stackguard1: uintptr(unsafe.Pointer(&crashstack)) + 1000,
|
||||
}
|
||||
// gcrash is a fake g that can be used when crashing due to bad
|
||||
// stack conditions.
|
||||
var gcrash g
|
||||
|
||||
var crashingG atomic.Pointer[g]
|
||||
|
||||
|
|
@ -803,6 +796,12 @@ func schedinit() {
|
|||
parsedebugvars()
|
||||
gcinit()
|
||||
|
||||
// Allocate stack space that can be used when crashing due to bad stack
|
||||
// conditions, e.g. morestack on g0.
|
||||
gcrash.stack = stackalloc(16384)
|
||||
gcrash.stackguard0 = gcrash.stack.lo + 1000
|
||||
gcrash.stackguard1 = gcrash.stack.lo + 1000
|
||||
|
||||
// if disableMemoryProfiling is set, update MemProfileRate to 0 to turn off memprofile.
|
||||
// Note: parsedebugvars may update MemProfileRate, but when disableMemoryProfiling is
|
||||
// set to true by the linker, it means that nothing is consuming the profile, it is
|
||||
|
|
|
|||
Loading…
Reference in New Issue