github.com/zxy12/go_duplicate_112_new@v0.0.0-20200807091221-747231827200/src/runtime/mem_aix.go (about)

     1  // Copyright 2018 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 (
     8  	"unsafe"
     9  )
    10  
    11  // Don't split the stack as this method may be invoked without a valid G, which
    12  // prevents us from allocating more stack.
    13  //go:nosplit
    14  func sysAlloc(n uintptr, sysStat *uint64) unsafe.Pointer {
    15  	p, err := mmap(nil, n, _PROT_READ|_PROT_WRITE, _MAP_ANONYMOUS|_MAP_PRIVATE, -1, 0)
    16  	if err != 0 {
    17  		if err == _EACCES {
    18  			print("runtime: mmap: access denied\n")
    19  			exit(2)
    20  		}
    21  		if err == _EAGAIN {
    22  			print("runtime: mmap: too much locked memory (check 'ulimit -l').\n")
    23  			exit(2)
    24  		}
    25  		//println("sysAlloc failed: ", err)
    26  		return nil
    27  	}
    28  	mSysStatInc(sysStat, n)
    29  	return p
    30  }
    31  
    32  func sysUnused(v unsafe.Pointer, n uintptr) {
    33  	madvise(v, n, _MADV_DONTNEED)
    34  }
    35  
    36  func sysUsed(v unsafe.Pointer, n uintptr) {
    37  }
    38  
    39  // Don't split the stack as this function may be invoked without a valid G,
    40  // which prevents us from allocating more stack.
    41  //go:nosplit
    42  func sysFree(v unsafe.Pointer, n uintptr, sysStat *uint64) {
    43  	mSysStatDec(sysStat, n)
    44  	munmap(v, n)
    45  
    46  }
    47  
    48  func sysFault(v unsafe.Pointer, n uintptr) {
    49  	mmap(v, n, _PROT_NONE, _MAP_ANONYMOUS|_MAP_PRIVATE|_MAP_FIXED, -1, 0)
    50  }
    51  
    52  func sysReserve(v unsafe.Pointer, n uintptr) unsafe.Pointer {
    53  	p, err := mmap(v, n, _PROT_NONE, _MAP_ANONYMOUS|_MAP_PRIVATE, -1, 0)
    54  	if err != 0 {
    55  		return nil
    56  	}
    57  	return p
    58  }
    59  
    60  func sysMap(v unsafe.Pointer, n uintptr, sysStat *uint64) {
    61  	mSysStatInc(sysStat, n)
    62  
    63  	// AIX does not allow mapping a range that is already mapped.
    64  	// So always unmap first even if it is already unmapped.
    65  	munmap(v, n)
    66  	p, err := mmap(v, n, _PROT_READ|_PROT_WRITE, _MAP_ANONYMOUS|_MAP_FIXED|_MAP_PRIVATE, -1, 0)
    67  
    68  	if err == _ENOMEM {
    69  		throw("runtime: out of memory")
    70  	}
    71  	if p != v || err != 0 {
    72  		throw("runtime: cannot map pages in arena address space")
    73  	}
    74  }