...
Run Format

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

View as plain text