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