]> Cypherpunks.ru repositories - gostls13.git/commit
runtime: get a better g0 stack bound in needm
authorCherry Mui <cherryyz@google.com>
Tue, 28 Mar 2023 18:48:59 +0000 (14:48 -0400)
committerCherry Mui <cherryyz@google.com>
Thu, 30 Mar 2023 23:23:55 +0000 (23:23 +0000)
commit443eb9757cd09ada43ceb9ee80f33bc84e892645
tree504ba70bd45461dbc739137dcc4237839e16393a
parentc5ccff405ee9ef6ae30ba2ac900feae4f5abbfd6
runtime: get a better g0 stack bound in needm

Currently, when C calls into Go the first time, we grab an M
using needm, which sets m.g0's stack bounds using the SP. We don't
know how big the stack is, so we simply assume 32K. Previously,
when the Go function returns to C, we drop the M, and the next
time C calls into Go, we put a new stack bound on the g0 based on
the current SP. After CL 392854, we don't drop the M, and the next
time C calls into Go, we reuse the same g0, without recomputing
the stack bounds. If the C code uses quite a bit of stack space
before calling into Go, the SP may be well below the 32K stack
bound we assumed, so the runtime thinks the g0 stack overflows.

This CL makes needm get a more accurate stack bound from
pthread. (In some platforms this may still be a guess as we don't
know exactly where we are in the C stack), but it is probably
better than simply assuming 32K.

For #59294.

Change-Id: Ie52a8f931e0648d8753e4c1dbe45468b8748b527
Reviewed-on: https://go-review.googlesource.com/c/go/+/479915
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
misc/cgo/testcarchive/carchive_test.go
misc/cgo/testcarchive/testdata/libgo9/a.go [new file with mode: 0644]
misc/cgo/testcarchive/testdata/main9.c [new file with mode: 0644]
src/runtime/cgo.go
src/runtime/cgo/callbacks.go
src/runtime/cgo/gcc_stack_darwin.c [new file with mode: 0644]
src/runtime/cgo/gcc_stack_unix.c [new file with mode: 0644]
src/runtime/cgo/gcc_stack_windows.c [new file with mode: 0644]
src/runtime/proc.go
src/runtime/signal_unix.go