Source file
src/runtime/mem_js.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 p := sysReserve(nil, n)
18 sysMap(p, n, sysStat)
19 return p
20 }
21
22 func sysUnused(v unsafe.Pointer, n uintptr) {
23 }
24
25 func sysUsed(v unsafe.Pointer, n uintptr) {
26 }
27
28 func sysHugePage(v unsafe.Pointer, n uintptr) {
29 }
30
31
32
33
34 func sysFree(v unsafe.Pointer, n uintptr, sysStat *sysMemStat) {
35 sysStat.add(-int64(n))
36 }
37
38 func sysFault(v unsafe.Pointer, n uintptr) {
39 }
40
41 var reserveEnd uintptr
42
43 func sysReserve(v unsafe.Pointer, n uintptr) unsafe.Pointer {
44
45
46 if v != nil {
47
48
49
50
51 return nil
52 }
53
54
55
56 initReserveEnd := alignUp(lastmoduledatap.end, physPageSize)
57 if reserveEnd < initReserveEnd {
58 reserveEnd = initReserveEnd
59 }
60 v = unsafe.Pointer(reserveEnd)
61 reserveEnd += alignUp(n, physPageSize)
62
63 current := currentMemory()
64
65 needed := int32(reserveEnd / physPageSize)
66 if current < needed {
67 if growMemory(needed-current) == -1 {
68 return nil
69 }
70 resetMemoryDataView()
71 }
72
73 return v
74 }
75
76 func currentMemory() int32
77 func growMemory(pages int32) int32
78
79
80
81 func resetMemoryDataView()
82
83 func sysMap(v unsafe.Pointer, n uintptr, sysStat *sysMemStat) {
84 sysStat.add(int64(n))
85 }
86
View as plain text