1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
// Copyright 2010 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package runtime
import "unsafe"
var bloc uintptr
var memlock mutex
const memRound = _PAGESIZE - 1
func initBloc() {
bloc = uintptr(unsafe.Pointer(&end))
}
func sbrk(n uintptr) unsafe.Pointer {
lock(&memlock)
// Plan 9 sbrk from /sys/src/libc/9sys/sbrk.c
bl := (bloc + memRound) &^ memRound
if brk_(unsafe.Pointer(bl+n)) < 0 {
unlock(&memlock)
return nil
}
bloc = bl + n
unlock(&memlock)
return unsafe.Pointer(bl)
}
func sysAlloc(n uintptr, stat *uint64) unsafe.Pointer {
p := sbrk(n)
if p != nil {
xadd64(stat, int64(n))
}
return p
}
func sysFree(v unsafe.Pointer, n uintptr, stat *uint64) {
xadd64(stat, -int64(n))
lock(&memlock)
// from tiny/mem.c
// Push pointer back if this is a free
// of the most recent sysAlloc.
n += (n + memRound) &^ memRound
if bloc == uintptr(v)+n {
bloc -= n
}
unlock(&memlock)
}
func sysUnused(v unsafe.Pointer, n uintptr) {
}
func sysUsed(v unsafe.Pointer, n uintptr) {
}
func sysMap(v unsafe.Pointer, n uintptr, reserved bool, stat *uint64) {
// sysReserve has already allocated all heap memory,
// but has not adjusted stats.
xadd64(stat, int64(n))
}
func sysFault(v unsafe.Pointer, n uintptr) {
}
func sysReserve(v unsafe.Pointer, n uintptr, reserved *bool) unsafe.Pointer {
*reserved = true
return sbrk(n)
}
|