github.com/4ad/go@v0.0.0-20161219182952-69a12818b605/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  func mmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uint32) unsafe.Pointer {
    19  	if _cgo_mmap != nil {
    20  		// Make ret a uintptr so that writing to it in the
    21  		// function literal does not trigger a write barrier.
    22  		// A write barrier here could break because of the way
    23  		// that mmap uses the same value both as a pointer and
    24  		// an errno value.
    25  		// TODO: Fix mmap to return two values.
    26  		var ret uintptr
    27  		systemstack(func() {
    28  			ret = callCgoMmap(addr, n, prot, flags, fd, off)
    29  		})
    30  		return unsafe.Pointer(ret)
    31  	}
    32  	return sysMmap(addr, n, prot, flags, fd, off)
    33  }
    34  
    35  // sysMmap calls the mmap system call. It is implemented in assembly.
    36  func sysMmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uint32) unsafe.Pointer
    37  
    38  // cgoMmap calls the mmap function in the runtime/cgo package on the
    39  // callCgoMmap calls the mmap function in the runtime/cgo package
    40  // using the GCC calling convention. It is implemented in assembly.
    41  func callCgoMmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uint32) uintptr