1
0
mirror of https://github.com/golang/go synced 2024-10-07 22:31:21 -06:00
go/misc/cgo
Hector Martin Cantero 7283e08cbf runtime: keep g->syscallsp consistent after cgo->Go callbacks
Normally, the caller to runtime.entersyscall() must not return before
calling runtime.exitsyscall(), lest g->syscallsp become a dangling
pointer. runtime.cgocallbackg() violates this constraint. To work around
this, save g->syscallsp and g->syscallpc around cgo->Go callbacks, then
restore them after calling runtime.entersyscall(), which restores the
syscall stack frame pointer saved by cgocall. This allows the GC to
correctly trace a goroutine that is currently returning from a
Go->cgo->Go chain.

This also adds a check to proc.c that panics if g->syscallsp is clearly
invalid. It is not 100% foolproof, as it will not catch a case where the
stack was popped then pushed back beyond g->syscallsp, but it does catch
the present cgo issue and makes existing tests fail without the bugfix.

Fixes #7978.

LGTM=dvyukov, rsc
R=golang-codereviews, dvyukov, minux, bradfitz, iant, gobot, rsc
CC=golang-codereviews, rsc
https://golang.org/cl/131910043
2014-09-24 13:20:25 -04:00
..
errors cmd/cgo: check for compiler errors in the C preamble 2014-08-14 09:21:58 -07:00
gmp misc/cgo/gmp: fix typo. 2013-03-30 19:02:14 +08:00
life misc/cgo: prepare for 64-bit ints 2012-09-24 14:58:45 -04:00
nocgo cmd/ld: really import runtime/cgo for external link 2014-05-20 21:36:50 -07:00
stdio misc/cgo/stdio: make it work on Windows and also test it 2012-09-20 00:27:23 +08:00
test runtime: keep g->syscallsp consistent after cgo->Go callbacks 2014-09-24 13:20:25 -04:00
testasan runtime: more flexible heap memory mapping on 64-bits 2013-06-12 18:47:16 +04:00
testcdefs misc/cgo/testcdefs: comment out test of packed structs 2014-08-31 22:59:43 -04:00
testgodefs cmd/cgo: consistently map void* to *byte under -{c,go}defs 2014-08-06 10:28:19 -07:00
testso misc/cgo/testso: don't use TLS variables on Darwin and OpenBSD. 2014-02-23 20:37:43 -05:00
testtls misc/cgo/testtls: make test less flaky 2014-01-21 19:44:51 -05:00