...
Run Format

Source file src/runtime/mem_bsd.go

Documentation: runtime

     1  // Copyright 2010 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  // +build dragonfly freebsd nacl netbsd openbsd solaris
     6  
     7  package runtime
     8  
     9  import (
    10  	"unsafe"
    11  )
    12  
    13  // Don't split the stack as this function may be invoked without a valid G,
    14  // which prevents us from allocating more stack.
    15  //go:nosplit
    16  func sysAlloc(n uintptr, sysStat *uint64) unsafe.Pointer {
    17  	v, err := mmap(nil, n, _PROT_READ|_PROT_WRITE, _MAP_ANON|_MAP_PRIVATE, -1, 0)
    18  	if err != 0 {
    19  		return nil
    20  	}
    21  	mSysStatInc(sysStat, n)
    22  	return v
    23  }
    24  
    25  func sysUnused(v unsafe.Pointer, n uintptr) {
    26  	madvise(v, n, _MADV_FREE)
    27  }
    28  
    29  func sysUsed(v unsafe.Pointer, n uintptr) {
    30  }
    31  
    32  // Don't split the stack as this function may be invoked without a valid G,
    33  // which prevents us from allocating more stack.
    34  //go:nosplit
    35  func sysFree(v unsafe.Pointer, n uintptr, sysStat *uint64) {
    36  	mSysStatDec(sysStat, n)
    37  	munmap(v, n)
    38  }
    39  
    40  func sysFault(v unsafe.Pointer, n uintptr) {
    41  	mmap(v, n, _PROT_NONE, _MAP_ANON|_MAP_PRIVATE|_MAP_FIXED, -1, 0)
    42  }
    43  
    44  func sysReserve(v unsafe.Pointer, n uintptr) unsafe.Pointer {
    45  	p, err := mmap(v, n, _PROT_NONE, _MAP_ANON|_MAP_PRIVATE, -1, 0)
    46  	if err != 0 {
    47  		return nil
    48  	}
    49  	return p
    50  }
    51  
    52  const _sunosEAGAIN = 11
    53  const _ENOMEM = 12
    54  
    55  func sysMap(v unsafe.Pointer, n uintptr, sysStat *uint64) {
    56  	mSysStatInc(sysStat, n)
    57  
    58  	p, err := mmap(v, n, _PROT_READ|_PROT_WRITE, _MAP_ANON|_MAP_FIXED|_MAP_PRIVATE, -1, 0)
    59  	if err == _ENOMEM || (GOOS == "solaris" && err == _sunosEAGAIN) {
    60  		throw("runtime: out of memory")
    61  	}
    62  	if p != v || err != 0 {
    63  		throw("runtime: cannot map pages in arena address space")
    64  	}
    65  }
    66  

View as plain text