]> Cypherpunks.ru repositories - gostls13.git/commit
runtime: allow update of system stack bounds on callback from C thread
authorMichael Pratt <mpratt@google.com>
Mon, 4 Sep 2023 13:55:01 +0000 (09:55 -0400)
committerGopher Robot <gobot@golang.org>
Tue, 12 Sep 2023 17:08:55 +0000 (17:08 +0000)
commit4f9fe6d50965020053ab80bf115f08070ce97f33
tree54afd47fc5f4313feba8cdc1af940f57cf514d52
parent2399302a251ef54e4669f2065f656b61d2f5c323
runtime: allow update of system stack bounds on callback from C thread

[This is a redo of CL 525455 with the test fixed on darwin by defining
_XOPEN_SOURCE, and disabled with android, musl, and openbsd, which do
not provide getcontext.]

Since CL 495855, Ms are cached for C threads calling into Go, including
the stack bounds of the system stack.

Some C libraries (e.g., coroutine libraries) do manual stack management
and may change stacks between calls to Go on the same thread.

Changing the stack if there is more Go up the stack would be
problematic. But if the calls are completely independent there is no
particular reason for Go to care about the changing stack boundary.

Thus, this CL allows the stack bounds to change in such cases. The
primary downside here (besides additional complexity) is that normal
systems that do not manipulate the stack may not notice unintentional
stack corruption as quickly as before.

Note that callbackUpdateSystemStack is written to be usable for the
initial setup in needm as well as updating the stack in cgocallbackg.

Fixes #62440.
For #62130.

Change-Id: I0fe0134f865932bbaff1fc0da377c35c013bd768
Reviewed-on: https://go-review.googlesource.com/c/go/+/527715
Run-TryBot: Michael Pratt <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Michael Pratt <mpratt@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
src/runtime/cgocall.go
src/runtime/crash_cgo_test.go
src/runtime/proc.go
src/runtime/testdata/testprogcgo/stackswitch.c [new file with mode: 0644]
src/runtime/testdata/testprogcgo/stackswitch.go [new file with mode: 0644]