Source file
src/runtime/mem_bsd.go
1
2
3
4
5
6
7 package runtime
8
9 import (
10 "unsafe"
11 )
12
13
14
15
16 func sysAlloc(n uintptr, sysStat *sysMemStat) 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 sysStat.add(int64(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
36
37
38 func sysFree(v unsafe.Pointer, n uintptr, sysStat *sysMemStat) {
39 sysStat.add(-int64(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
48 const _sunosMAP_NORESERVE = 0x40
49
50 func sysReserve(v unsafe.Pointer, n uintptr) unsafe.Pointer {
51 flags := int32(_MAP_ANON | _MAP_PRIVATE)
52 if GOOS == "solaris" || GOOS == "illumos" {
53
54
55
56 flags |= _sunosMAP_NORESERVE
57 }
58 p, err := mmap(v, n, _PROT_NONE, flags, -1, 0)
59 if err != 0 {
60 return nil
61 }
62 return p
63 }
64
65 const _sunosEAGAIN = 11
66 const _ENOMEM = 12
67
68 func sysMap(v unsafe.Pointer, n uintptr, sysStat *sysMemStat) {
69 sysStat.add(int64(n))
70
71 p, err := mmap(v, n, _PROT_READ|_PROT_WRITE, _MAP_ANON|_MAP_FIXED|_MAP_PRIVATE, -1, 0)
72 if err == _ENOMEM || ((GOOS == "solaris" || GOOS == "illumos") && err == _sunosEAGAIN) {
73 throw("runtime: out of memory")
74 }
75 if p != v || err != 0 {
76 print("runtime: mmap(", v, ", ", n, ") returned ", p, ", ", err, "\n")
77 throw("runtime: cannot map pages in arena address space")
78 }
79 }
80
View as plain text