package runtime
import (
)
const (
_EACCES = 13
_EINVAL = 22
)
func ( uintptr) unsafe.Pointer {
, := mmap(nil, , _PROT_READ|_PROT_WRITE, _MAP_ANON|_MAP_PRIVATE, -1, 0)
if != 0 {
if == _EACCES {
print("runtime: mmap: access denied\n")
exit(2)
}
if == _EAGAIN {
print("runtime: mmap: too much locked memory (check 'ulimit -l').\n")
exit(2)
}
return nil
}
return
}
var adviseUnused = uint32(_MADV_FREE)
const madviseUnsupported = 0
func ( unsafe.Pointer, uintptr) {
if uintptr()&(physPageSize-1) != 0 || &(physPageSize-1) != 0 {
throw("unaligned sysUnused")
}
:= atomic.Load(&adviseUnused)
if debug.madvdontneed != 0 && != madviseUnsupported {
= _MADV_DONTNEED
}
switch {
case _MADV_FREE:
if madvise(, , _MADV_FREE) == 0 {
break
}
atomic.Store(&adviseUnused, _MADV_DONTNEED)
fallthrough
case _MADV_DONTNEED:
if madvise(, , _MADV_DONTNEED) == 0 {
break
}
atomic.Store(&adviseUnused, madviseUnsupported)
fallthrough
case madviseUnsupported:
mmap(, , _PROT_READ|_PROT_WRITE, _MAP_ANON|_MAP_FIXED|_MAP_PRIVATE, -1, 0)
}
if debug.harddecommit > 0 {
, := mmap(, , _PROT_NONE, _MAP_ANON|_MAP_FIXED|_MAP_PRIVATE, -1, 0)
if != || != 0 {
throw("runtime: cannot disable permissions in address space")
}
}
}
func ( unsafe.Pointer, uintptr) {
if debug.harddecommit > 0 {
, := mmap(, , _PROT_READ|_PROT_WRITE, _MAP_ANON|_MAP_FIXED|_MAP_PRIVATE, -1, 0)
if == _ENOMEM {
throw("runtime: out of memory")
}
if != || != 0 {
throw("runtime: cannot remap pages in address space")
}
return
}
}
func ( unsafe.Pointer, uintptr) {
if physHugePageSize != 0 {
:= alignUp(uintptr(), physHugePageSize)
:= alignDown(uintptr()+, physHugePageSize)
if < {
madvise(unsafe.Pointer(), -, _MADV_HUGEPAGE)
}
}
}
func ( unsafe.Pointer, uintptr) {
if uintptr()&(physPageSize-1) != 0 {
throw("unaligned sysNoHugePageOS")
}
madvise(, , _MADV_NOHUGEPAGE)
}
func ( unsafe.Pointer, uintptr) {
if uintptr()&(physPageSize-1) != 0 {
throw("unaligned sysHugePageCollapseOS")
}
if physHugePageSize == 0 {
return
}
madvise(, , _MADV_COLLAPSE)
}
func ( unsafe.Pointer, uintptr) {
munmap(, )
}
func ( unsafe.Pointer, uintptr) {
mprotect(, , _PROT_NONE)
madvise(, , _MADV_DONTNEED)
}
func ( unsafe.Pointer, uintptr) unsafe.Pointer {
, := mmap(, , _PROT_NONE, _MAP_ANON|_MAP_PRIVATE, -1, 0)
if != 0 {
return nil
}
return
}
func ( unsafe.Pointer, uintptr) {
, := mmap(, , _PROT_READ|_PROT_WRITE, _MAP_ANON|_MAP_FIXED|_MAP_PRIVATE, -1, 0)
if == _ENOMEM {
throw("runtime: out of memory")
}
if != || != 0 {
print("runtime: mmap(", , ", ", , ") returned ", , ", ", , "\n")
throw("runtime: cannot map pages in arena address space")
}
if debug.disablethp != 0 {
sysNoHugePageOS(, )
}
}