summaryrefslogtreecommitdiff
path: root/src/runtime/mem_plan9.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/runtime/mem_plan9.go')
-rw-r--r--src/runtime/mem_plan9.go70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/runtime/mem_plan9.go b/src/runtime/mem_plan9.go
new file mode 100644
index 000000000..a5d7c1a4c
--- /dev/null
+++ b/src/runtime/mem_plan9.go
@@ -0,0 +1,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)
+}