aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/cgo_mmap.go
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2017-06-06 15:08:59 -0700
committerIan Lance Taylor <iant@golang.org>2017-06-06 23:26:55 +0000
commitf425f549573e5017861216d62ccb22ee37b68004 (patch)
treea5dc94df90194f08092676258a4079650564b4f5 /src/runtime/cgo_mmap.go
parent557f6a13beb9e2da58d439d228e7f8f838c61159 (diff)
downloadgo-f425f549573e5017861216d62ccb22ee37b68004.tar.gz
go-f425f549573e5017861216d62ccb22ee37b68004.zip
runtime: intercept munmap as we do mmap
For cgo programs on linux-amd64 we call the C function mmap. This supports programs such as the C memory sanitizer that need to intercept all calls to mmap. It turns out that there are programs that intercept both mmap and munmap, or that at least expect that if they intercept mmap, they also intercept munmap. So, if we permit mmap to be intercepted, also permit munmap to be intercepted. No test, as it requires two odd things: a C program that intercepts mmap and munmap, and a Go program that calls munmap. Change-Id: Iec33f47d59f70dbb7463fd12d30728c24cd4face Reviewed-on: https://go-review.googlesource.com/45016 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'src/runtime/cgo_mmap.go')
-rw-r--r--src/runtime/cgo_mmap.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/runtime/cgo_mmap.go b/src/runtime/cgo_mmap.go
index 5a2a1a2c37..aa531b9020 100644
--- a/src/runtime/cgo_mmap.go
+++ b/src/runtime/cgo_mmap.go
@@ -15,6 +15,11 @@ import "unsafe"
//go:linkname _cgo_mmap _cgo_mmap
var _cgo_mmap unsafe.Pointer
+// _cgo_munmap is filled in by runtime/cgo when it is linked into the
+// program, so it is only non-nil when using cgo.
+//go:linkname _cgo_munmap _cgo_munmap
+var _cgo_munmap unsafe.Pointer
+
func mmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uint32) unsafe.Pointer {
if _cgo_mmap != nil {
// Make ret a uintptr so that writing to it in the
@@ -32,9 +37,24 @@ func mmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uint32) uns
return sysMmap(addr, n, prot, flags, fd, off)
}
+func munmap(addr unsafe.Pointer, n uintptr) {
+ if _cgo_munmap != nil {
+ systemstack(func() { callCgoMunmap(addr, n) })
+ return
+ }
+ sysMunmap(addr, n)
+}
+
// sysMmap calls the mmap system call. It is implemented in assembly.
func sysMmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uint32) unsafe.Pointer
// callCgoMmap calls the mmap function in the runtime/cgo package
// using the GCC calling convention. It is implemented in assembly.
func callCgoMmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uint32) uintptr
+
+// sysMunmap calls the munmap system call. It is implemented in assembly.
+func sysMunmap(addr unsafe.Pointer, n uintptr)
+
+// callCgoMunmap calls the munmap function in the runtime/cgo package
+// using the GCC calling convention. It is implemented in assembly.
+func callCgoMunmap(addr unsafe.Pointer, n uintptr)