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