Source file
src/runtime/mem_bsd.go
Documentation: runtime
1
2
3
4
5
6
7 package runtime
8
9 import (
10 "unsafe"
11 )
12
13
14
15
16
17 func sysAllocOS(n uintptr) unsafe.Pointer {
18 v, err := mmap(nil, n, _PROT_READ|_PROT_WRITE, _MAP_ANON|_MAP_PRIVATE, -1, 0)
19 if err != 0 {
20 return nil
21 }
22 return v
23 }
24
25 func sysUnusedOS(v unsafe.Pointer, n uintptr) {
26 if debug.madvdontneed != 0 {
27 madvise(v, n, _MADV_DONTNEED)
28 } else {
29 madvise(v, n, _MADV_FREE)
30 }
31 }
32
33 func sysUsedOS(v unsafe.Pointer, n uintptr) {
34 }
35
36 func sysHugePageOS(v unsafe.Pointer, n uintptr) {
37 }
38
39 func sysNoHugePageOS(v unsafe.Pointer, n uintptr) {
40 }
41
42 func sysHugePageCollapseOS(v unsafe.Pointer, n uintptr) {
43 }
44
45
46
47
48
49 func sysFreeOS(v unsafe.Pointer, n uintptr) {
50 munmap(v, n)
51 }
52
53 func sysFaultOS(v unsafe.Pointer, n uintptr) {
54 mmap(v, n, _PROT_NONE, _MAP_ANON|_MAP_PRIVATE|_MAP_FIXED, -1, 0)
55 }
56
57
58 const _sunosMAP_NORESERVE = 0x40
59
60 func sysReserveOS(v unsafe.Pointer, n uintptr) unsafe.Pointer {
61 flags := int32(_MAP_ANON | _MAP_PRIVATE)
62 if GOOS == "solaris" || GOOS == "illumos" {
63
64
65
66 flags |= _sunosMAP_NORESERVE
67 }
68 p, err := mmap(v, n, _PROT_NONE, flags, -1, 0)
69 if err != 0 {
70 return nil
71 }
72 return p
73 }
74
75 const _sunosEAGAIN = 11
76 const _ENOMEM = 12
77
78 func sysMapOS(v unsafe.Pointer, n uintptr) {
79 p, err := mmap(v, n, _PROT_READ|_PROT_WRITE, _MAP_ANON|_MAP_FIXED|_MAP_PRIVATE, -1, 0)
80 if err == _ENOMEM || ((GOOS == "solaris" || GOOS == "illumos") && err == _sunosEAGAIN) {
81 throw("runtime: out of memory")
82 }
83 if p != v || err != 0 {
84 print("runtime: mmap(", v, ", ", n, ") returned ", p, ", ", err, "\n")
85 throw("runtime: cannot map pages in arena address space")
86 }
87 }
88
View as plain text