]> Cypherpunks repositories - gostls13.git/commit
runtime: only set isExtraInC if there are no Go frames left
authorMichael Pratt <mpratt@google.com>
Fri, 14 Mar 2025 14:50:25 +0000 (10:50 -0400)
committerGopher Robot <gobot@golang.org>
Fri, 14 Mar 2025 19:54:11 +0000 (12:54 -0700)
commit577bb3d0ce576b2ca311e58dd942f189838b80fc
treef08c176d4ae7587b393bdebcbd5a3df64a638115
parent7e3d2aa69f0ad7dc0cb78ff9e5ee8fdd819a541a
runtime: only set isExtraInC if there are no Go frames left

mp.isExtraInC is intended to indicate that this M has no Go frames at
all; it is entirely executing in C.

If there was a cgocallback to Go and then a cgocall to C, such that the
leaf frames are C, that is fine. e.g., traceback can handle this fine
with SetCgoTraceback (or by simply skipping the C frames).

However, we currently mismanage isExtraInC, unconditionally setting it
on return from cgocallback. This means that if there are two levels of
cgocallback, we end up running Go code with isExtraInC set.

1. C-created thread calls into Go function 1 (via cgocallback).
2. Go function 1 calls into C function 1 (via cgocall).
3. C function 1 calls into Go function 2 (via cgocallback).
4. Go function 2 returns back to C function 1 (returning via the remainder of cgocallback).
5. C function 1 returns back to Go function 1 (returning via the remainder of cgocall).
6. Go function 1 is now running with mp.isExtraInC == true.

The fix is simple; only set isExtraInC on return from cgocallback if
there are no more Go frames. There can't be more Go frames unless there
is an active cgocall out of the Go frames.

Fixes #72870.

Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest
Change-Id: I6a6a636c4e7ba75a29639d7036c5af3738033467
Reviewed-on: https://go-review.googlesource.com/c/go/+/658035
Reviewed-by: Cherry Mui <cherryyz@google.com>
Commit-Queue: Michael Pratt <mpratt@google.com>
Auto-Submit: Michael Pratt <mpratt@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
src/runtime/cgocall.go
src/runtime/crash_cgo_test.go
src/runtime/runtime2.go
src/runtime/testdata/testprogcgo/callback_pprof.go [new file with mode: 0644]