2016-03-01 15:57:46 -07:00
|
|
|
// Copyright 2015 The Go Authors. All rights reserved.
|
2015-09-29 22:24:13 -06:00
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2016-03-01 16:21:55 -07:00
|
|
|
// Support for memory sanitizer. See runtime/cgo/mmap.go.
|
2015-09-29 22:24:13 -06:00
|
|
|
|
|
|
|
// +build linux,amd64
|
|
|
|
|
|
|
|
package runtime
|
|
|
|
|
|
|
|
import "unsafe"
|
|
|
|
|
|
|
|
// _cgo_mmap 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_mmap _cgo_mmap
|
|
|
|
var _cgo_mmap unsafe.Pointer
|
|
|
|
|
2017-06-06 16:08:59 -06:00
|
|
|
// _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
|
|
|
|
|
2016-01-29 16:43:24 -07:00
|
|
|
func mmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uint32) unsafe.Pointer {
|
2015-09-29 22:24:13 -06:00
|
|
|
if _cgo_mmap != nil {
|
2016-01-29 16:43:24 -07:00
|
|
|
// 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
|
2015-09-29 22:24:13 -06:00
|
|
|
systemstack(func() {
|
|
|
|
ret = callCgoMmap(addr, n, prot, flags, fd, off)
|
|
|
|
})
|
2016-01-29 16:43:24 -07:00
|
|
|
return unsafe.Pointer(ret)
|
2015-09-29 22:24:13 -06:00
|
|
|
}
|
|
|
|
return sysMmap(addr, n, prot, flags, fd, off)
|
|
|
|
}
|
|
|
|
|
2017-06-06 16:08:59 -06:00
|
|
|
func munmap(addr unsafe.Pointer, n uintptr) {
|
|
|
|
if _cgo_munmap != nil {
|
|
|
|
systemstack(func() { callCgoMunmap(addr, n) })
|
|
|
|
return
|
|
|
|
}
|
|
|
|
sysMunmap(addr, n)
|
|
|
|
}
|
|
|
|
|
2016-03-01 16:21:55 -07:00
|
|
|
// sysMmap calls the mmap system call. It is implemented in assembly.
|
2015-09-29 22:24:13 -06:00
|
|
|
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
|
2016-03-01 16:21:55 -07:00
|
|
|
// using the GCC calling convention. It is implemented in assembly.
|
2016-01-29 16:43:24 -07:00
|
|
|
func callCgoMmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uint32) uintptr
|
2017-06-06 16:08:59 -06:00
|
|
|
|
|
|
|
// 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)
|