github.com/mattn/go@v0.0.0-20171011075504-07f7db3ea99f/src/runtime/cgo_mmap.go (about) 1 // Copyright 2015 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Support for memory sanitizer. See runtime/cgo/mmap.go. 6 7 // +build linux,amd64 8 9 package runtime 10 11 import "unsafe" 12 13 // _cgo_mmap is filled in by runtime/cgo when it is linked into the 14 // program, so it is only non-nil when using cgo. 15 //go:linkname _cgo_mmap _cgo_mmap 16 var _cgo_mmap unsafe.Pointer 17 18 // _cgo_munmap is filled in by runtime/cgo when it is linked into the 19 // program, so it is only non-nil when using cgo. 20 //go:linkname _cgo_munmap _cgo_munmap 21 var _cgo_munmap unsafe.Pointer 22 23 func mmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uint32) unsafe.Pointer { 24 if _cgo_mmap != nil { 25 // Make ret a uintptr so that writing to it in the 26 // function literal does not trigger a write barrier. 27 // A write barrier here could break because of the way 28 // that mmap uses the same value both as a pointer and 29 // an errno value. 30 // TODO: Fix mmap to return two values. 31 var ret uintptr 32 systemstack(func() { 33 ret = callCgoMmap(addr, n, prot, flags, fd, off) 34 }) 35 return unsafe.Pointer(ret) 36 } 37 return sysMmap(addr, n, prot, flags, fd, off) 38 } 39 40 func munmap(addr unsafe.Pointer, n uintptr) { 41 if _cgo_munmap != nil { 42 systemstack(func() { callCgoMunmap(addr, n) }) 43 return 44 } 45 sysMunmap(addr, n) 46 } 47 48 // sysMmap calls the mmap system call. It is implemented in assembly. 49 func sysMmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uint32) unsafe.Pointer 50 51 // callCgoMmap calls the mmap function in the runtime/cgo package 52 // using the GCC calling convention. It is implemented in assembly. 53 func callCgoMmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uint32) uintptr 54 55 // sysMunmap calls the munmap system call. It is implemented in assembly. 56 func sysMunmap(addr unsafe.Pointer, n uintptr) 57 58 // callCgoMunmap calls the munmap function in the runtime/cgo package 59 // using the GCC calling convention. It is implemented in assembly. 60 func callCgoMunmap(addr unsafe.Pointer, n uintptr)