]> 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)
committerMichael Pratt <mpratt@google.com>
Mon, 11 Sep 2023 14:46:41 +0000 (14:46 +0000)
commita46b1ad3573ae64964ffd736dc79291b58190281
tree0785a80eb03eb4767129784c31c6a39886f52cb7
parent5eb382fc08fb32592e9585f9cb99005696a38b49
runtime: allow update of system stack bounds on callback from C thread

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: I7841b056acea1111bdae3b718345a3bd3961b4a8
Reviewed-on: https://go-review.googlesource.com/c/go/+/525455
Run-TryBot: Michael Pratt <mpratt@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
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]