...

Source file src/pkg/runtime/mem_bsd.go

     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	func sysHugePage(v unsafe.Pointer, n uintptr) {
    33	}
    34	
    35	// Don't split the stack as this function may be invoked without a valid G,
    36	// which prevents us from allocating more stack.
    37	//go:nosplit
    38	func sysFree(v unsafe.Pointer, n uintptr, sysStat *uint64) {
    39		mSysStatDec(sysStat, n)
    40		munmap(v, n)
    41	}
    42	
    43	func sysFault(v unsafe.Pointer, n uintptr) {
    44		mmap(v, n, _PROT_NONE, _MAP_ANON|_MAP_PRIVATE|_MAP_FIXED, -1, 0)
    45	}
    46	
    47	func sysReserve(v unsafe.Pointer, n uintptr) unsafe.Pointer {
    48		p, err := mmap(v, n, _PROT_NONE, _MAP_ANON|_MAP_PRIVATE, -1, 0)
    49		if err != 0 {
    50			return nil
    51		}
    52		return p
    53	}
    54	
    55	const _sunosEAGAIN = 11
    56	const _ENOMEM = 12
    57	
    58	func sysMap(v unsafe.Pointer, n uintptr, sysStat *uint64) {
    59		mSysStatInc(sysStat, n)
    60	
    61		p, err := mmap(v, n, _PROT_READ|_PROT_WRITE, _MAP_ANON|_MAP_FIXED|_MAP_PRIVATE, -1, 0)
    62		if err == _ENOMEM || ((GOOS == "solaris" || GOOS == "illumos") && err == _sunosEAGAIN) {
    63			throw("runtime: out of memory")
    64		}
    65		if p != v || err != 0 {
    66			throw("runtime: cannot map pages in arena address space")
    67		}
    68	}
    69	

View as plain text