github.com/twelsh-aw/go/src@v0.0.0-20230516233729-a56fe86a7c81/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  //
    14  //go:nosplit
    15  func sysAllocOS(n uintptr) unsafe.Pointer {
    16  	p, err := mmap(nil, n, _PROT_READ|_PROT_WRITE, _MAP_ANON|_MAP_PRIVATE, -1, 0)
    17  	if err != 0 {
    18  		if err == _EACCES {
    19  			print("runtime: mmap: access denied\n")
    20  			exit(2)
    21  		}
    22  		if err == _EAGAIN {
    23  			print("runtime: mmap: too much locked memory (check 'ulimit -l').\n")
    24  			exit(2)
    25  		}
    26  		return nil
    27  	}
    28  	return p
    29  }
    30  
    31  func sysUnusedOS(v unsafe.Pointer, n uintptr) {
    32  	madvise(v, n, _MADV_DONTNEED)
    33  }
    34  
    35  func sysUsedOS(v unsafe.Pointer, n uintptr) {
    36  }
    37  
    38  func sysHugePageOS(v unsafe.Pointer, n uintptr) {
    39  }
    40  
    41  func sysNoHugePageOS(v unsafe.Pointer, n uintptr) {
    42  }
    43  
    44  // Don't split the stack as this function may be invoked without a valid G,
    45  // which prevents us from allocating more stack.
    46  //
    47  //go:nosplit
    48  func sysFreeOS(v unsafe.Pointer, n uintptr) {
    49  	munmap(v, n)
    50  }
    51  
    52  func sysFaultOS(v unsafe.Pointer, n uintptr) {
    53  	mmap(v, n, _PROT_NONE, _MAP_ANON|_MAP_PRIVATE|_MAP_FIXED, -1, 0)
    54  }
    55  
    56  func sysReserveOS(v unsafe.Pointer, n uintptr) unsafe.Pointer {
    57  	p, err := mmap(v, n, _PROT_NONE, _MAP_ANON|_MAP_PRIVATE, -1, 0)
    58  	if err != 0 {
    59  		return nil
    60  	}
    61  	return p
    62  }
    63  
    64  func sysMapOS(v unsafe.Pointer, n uintptr) {
    65  	// AIX does not allow mapping a range that is already mapped.
    66  	// So, call mprotect to change permissions.
    67  	// Note that sysMap is always called with a non-nil pointer
    68  	// since it transitions a Reserved memory region to Prepared,
    69  	// so mprotect is always possible.
    70  	_, err := mprotect(v, n, _PROT_READ|_PROT_WRITE)
    71  	if err == _ENOMEM {
    72  		throw("runtime: out of memory")
    73  	}
    74  	if err != 0 {
    75  		print("runtime: mprotect(", v, ", ", n, ") returned ", err, "\n")
    76  		throw("runtime: cannot map pages in arena address space")
    77  	}
    78  }