aboutsummaryrefslogtreecommitdiff
path: root/src/runtime
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2015-06-07 22:14:04 -0400
committerRuss Cox <rsc@golang.org>2015-06-15 17:39:53 +0000
commit2c2770c3d4dea11ce96f63d8fcb40ca5dd230e33 (patch)
treefdb5f7bd97e61e9da4cc40e8c32329e61f520b70 /src/runtime
parenta3b9797baa487224c5d5e1878057ec31e1f0df88 (diff)
downloadgo-2c2770c3d4dea11ce96f63d8fcb40ca5dd230e33.tar.xz
cmd/cgo: make sure pointers passed to C escape to heap
Fixes #10303. Change-Id: Ia68d3566ba3ebeea6e18e388446bd9b8c431e156 Reviewed-on: https://go-review.googlesource.com/10814 Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/runtime')
-rw-r--r--src/runtime/cgo.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/runtime/cgo.go b/src/runtime/cgo.go
index d8ae6ec94b..169a31d4c6 100644
--- a/src/runtime/cgo.go
+++ b/src/runtime/cgo.go
@@ -32,3 +32,19 @@ var iscgo bool
// cgoHasExtraM is set on startup when an extra M is created for cgo.
// The extra M must be created before any C/C++ code calls cgocallback.
var cgoHasExtraM bool
+
+// cgoUse is called by cgo-generated code (using go:linkname to get at
+// an unexported name). The calls serve two purposes:
+// 1) they are opaque to escape analysis, so the argument is considered to
+// escape to the heap.
+// 2) they keep the argument alive until the call site; the call is emitted after
+// the end of the (presumed) use of the argument by C.
+// cgoUse should not actually be called (see cgoAlwaysFalse).
+func cgoUse(interface{}) { throw("cgoUse should not be called") }
+
+// cgoAlwaysFalse is a boolean value that is always false.
+// The cgo-generated code says if cgoAlwaysFalse { cgoUse(p) }.
+// The compiler cannot see that cgoAlwaysFalse is always false,
+// so it emits the test and keeps the call, giving the desired
+// escape analysis result. The test is cheaper than the call.
+var cgoAlwaysFalse bool