aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoel Sing <joel@sing.id.au>2023-10-31 00:27:58 +1100
committerCherry Mui <cherryyz@google.com>2023-10-31 16:28:14 +0000
commite293c4b509de6e7ceaeabb0c8d9f2a4d3d3b4e6d (patch)
tree5e477f1ba37f71c405e69bc5578dafb2bf879e02 /src
parentb7a66be69c5857105c4b357d87bb76da87b1dbed (diff)
downloadgo-e293c4b509de6e7ceaeabb0c8d9f2a4d3d3b4e6d.tar.xz
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>
Diffstat (limited to 'src')
-rw-r--r--src/runtime/proc.go19
1 files changed, 9 insertions, 10 deletions
diff --git a/src/runtime/proc.go b/src/runtime/proc.go
index 408f26cf7a..7189a0650a 100644
--- a/src/runtime/proc.go
+++ b/src/runtime/proc.go
@@ -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