summaryrefslogtreecommitdiff
path: root/src/pkg/runtime/plan9/mem.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkg/runtime/plan9/mem.c')
-rw-r--r--src/pkg/runtime/plan9/mem.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/pkg/runtime/plan9/mem.c b/src/pkg/runtime/plan9/mem.c
new file mode 100644
index 000000000..651e6728e
--- /dev/null
+++ b/src/pkg/runtime/plan9/mem.c
@@ -0,0 +1,49 @@
+// 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.
+
+#include "runtime.h"
+#include "malloc.h"
+
+extern byte end[];
+static byte *bloc = { end };
+
+enum
+{
+ Round = 7
+};
+
+void*
+runtime·SysAlloc(uintptr ask)
+{
+ uintptr bl;
+
+ // Plan 9 sbrk from /sys/src/libc/9sys/sbrk.c
+ bl = ((uintptr)bloc + Round) & ~Round;
+ if(runtime·brk_((void*)(bl + ask)) < 0)
+ return (void*)-1;
+ bloc = (byte*)bl + ask;
+ return (void*)bl;
+}
+
+void
+runtime·SysFree(void *v, uintptr n)
+{
+ // from tiny/mem.c
+ // Push pointer back if this is a free
+ // of the most recent SysAlloc.
+ n += (n + Round) & ~Round;
+ if(bloc == (byte*)v+n)
+ bloc -= n;
+}
+
+void
+runtime·SysUnused(void *v, uintptr n)
+{
+ USED(v, n);
+}
+
+void
+runtime·SysMemInit(void)
+{
+}