...
Source file src/pkg/runtime/mem_js.go
1
2
3
4
5
6
7 package runtime
8
9 import (
10 "runtime/internal/sys"
11 "unsafe"
12 )
13
14
15
16
17 func sysAlloc(n uintptr, sysStat *uint64) unsafe.Pointer {
18 p := sysReserve(nil, n)
19 sysMap(p, n, sysStat)
20 return p
21 }
22
23 func sysUnused(v unsafe.Pointer, n uintptr) {
24 }
25
26 func sysUsed(v unsafe.Pointer, n uintptr) {
27 }
28
29 func sysHugePage(v unsafe.Pointer, n uintptr) {
30 }
31
32
33
34
35 func sysFree(v unsafe.Pointer, n uintptr, sysStat *uint64) {
36 mSysStatDec(sysStat, n)
37 }
38
39 func sysFault(v unsafe.Pointer, n uintptr) {
40 }
41
42 var reserveEnd uintptr
43
44 func sysReserve(v unsafe.Pointer, n uintptr) unsafe.Pointer {
45
46
47 if v != nil {
48
49
50
51
52 return nil
53 }
54
55 if reserveEnd < lastmoduledatap.end {
56 reserveEnd = lastmoduledatap.end
57 }
58 v = unsafe.Pointer(reserveEnd)
59 reserveEnd += n
60
61 current := currentMemory()
62 needed := int32(reserveEnd/sys.DefaultPhysPageSize + 1)
63 if current < needed {
64 if growMemory(needed-current) == -1 {
65 return nil
66 }
67 }
68
69 return v
70 }
71
72 func currentMemory() int32
73 func growMemory(pages int32) int32
74
75 func sysMap(v unsafe.Pointer, n uintptr, sysStat *uint64) {
76 mSysStatInc(sysStat, n)
77 }
78
View as plain text