Source file
src/runtime/mem_darwin.go
1
2
3
4
5 package runtime
6
7 import (
8 "unsafe"
9 )
10
11
12
13
14 func sysAlloc(n uintptr, sysStat *sysMemStat) unsafe.Pointer {
15 v, err := mmap(nil, n, _PROT_READ|_PROT_WRITE, _MAP_ANON|_MAP_PRIVATE, -1, 0)
16 if err != 0 {
17 return nil
18 }
19 sysStat.add(int64(n))
20 return v
21 }
22
23 func sysUnused(v unsafe.Pointer, n uintptr) {
24
25
26 madvise(v, n, _MADV_FREE_REUSABLE)
27 }
28
29 func sysUsed(v unsafe.Pointer, n uintptr) {
30
31
32
33 madvise(v, n, _MADV_FREE_REUSE)
34 }
35
36 func sysHugePage(v unsafe.Pointer, n uintptr) {
37 }
38
39
40
41
42 func sysFree(v unsafe.Pointer, n uintptr, sysStat *sysMemStat) {
43 sysStat.add(-int64(n))
44 munmap(v, n)
45 }
46
47 func sysFault(v unsafe.Pointer, n uintptr) {
48 mmap(v, n, _PROT_NONE, _MAP_ANON|_MAP_PRIVATE|_MAP_FIXED, -1, 0)
49 }
50
51 func sysReserve(v unsafe.Pointer, n uintptr) unsafe.Pointer {
52 p, err := mmap(v, n, _PROT_NONE, _MAP_ANON|_MAP_PRIVATE, -1, 0)
53 if err != 0 {
54 return nil
55 }
56 return p
57 }
58
59 const _ENOMEM = 12
60
61 func sysMap(v unsafe.Pointer, n uintptr, sysStat *sysMemStat) {
62 sysStat.add(int64(n))
63
64 p, err := mmap(v, n, _PROT_READ|_PROT_WRITE, _MAP_ANON|_MAP_FIXED|_MAP_PRIVATE, -1, 0)
65 if err == _ENOMEM {
66 throw("runtime: out of memory")
67 }
68 if p != v || err != 0 {
69 print("runtime: mmap(", v, ", ", n, ") returned ", p, ", ", err, "\n")
70 throw("runtime: cannot map pages in arena address space")
71 }
72 }
73
View as plain text