]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: avoid write barrier in cgo mmap code
authorIan Lance Taylor <iant@golang.org>
Fri, 29 Jan 2016 23:43:24 +0000 (15:43 -0800)
committerIan Lance Taylor <iant@golang.org>
Mon, 1 Feb 2016 20:38:07 +0000 (20:38 +0000)
Tested by hand with a runtime/cgo modified to return an mmap failure
after 10 calls.

This is an interim patch.  For 1.7 we should fix mmap properly to avoid
using the same value as both a pointer and an errno value.

Fixes #14149.

Change-Id: I8f2bbd47d711e283001ba73296f1c34a26c59241
Reviewed-on: https://go-review.googlesource.com/19084
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
src/runtime/cgo_mmap.go

index ef5501ca5f7ad5ea3d93c341400ff10b62eda8e9..c0396bdde51b84ad4eecd410345d84bd2b4e47e9 100644 (file)
@@ -15,12 +15,19 @@ import "unsafe"
 //go:linkname _cgo_mmap _cgo_mmap
 var _cgo_mmap unsafe.Pointer
 
-func mmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uint32) (ret 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
+               // function literal does not trigger a write barrier.
+               // A write barrier here could break because of the way
+               // that mmap uses the same value both as a pointer and
+               // an errno value.
+               // TODO: Fix mmap to return two values.
+               var ret uintptr
                systemstack(func() {
                        ret = callCgoMmap(addr, n, prot, flags, fd, off)
                })
-               return
+               return unsafe.Pointer(ret)
        }
        return sysMmap(addr, n, prot, flags, fd, off)
 }
@@ -31,4 +38,4 @@ func sysMmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uint32)
 // cgoMmap calls the mmap function in the runtime/cgo package on the
 // 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) unsafe.Pointer
+func callCgoMmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uint32) uintptr