From 4cecda6c347bd6902b960c6a35a967add7070b0d Mon Sep 17 00:00:00 2001 From: Ondřej Surý Date: Mon, 30 Jan 2012 15:38:19 +0100 Subject: Imported Upstream version 2012.01.27 --- src/pkg/runtime/mem_plan9.c | 68 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 src/pkg/runtime/mem_plan9.c (limited to 'src/pkg/runtime/mem_plan9.c') diff --git a/src/pkg/runtime/mem_plan9.c b/src/pkg/runtime/mem_plan9.c new file mode 100644 index 000000000..15cbc176b --- /dev/null +++ b/src/pkg/runtime/mem_plan9.c @@ -0,0 +1,68 @@ +// 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 "arch_GOARCH.h" +#include "malloc.h" +#include "os_GOOS.h" + +extern byte end[]; +static byte *bloc = { end }; +static Lock memlock; + +enum +{ + Round = 4095 +}; + +void* +runtime·SysAlloc(uintptr nbytes) +{ + uintptr bl; + + runtime·lock(&memlock); + mstats.sys += nbytes; + // Plan 9 sbrk from /sys/src/libc/9sys/sbrk.c + bl = ((uintptr)bloc + Round) & ~Round; + if(runtime·brk_((void*)(bl + nbytes)) < 0) { + runtime·unlock(&memlock); + return nil; + } + bloc = (byte*)bl + nbytes; + runtime·unlock(&memlock); + return (void*)bl; +} + +void +runtime·SysFree(void *v, uintptr nbytes) +{ + runtime·lock(&memlock); + mstats.sys -= nbytes; + // from tiny/mem.c + // Push pointer back if this is a free + // of the most recent SysAlloc. + nbytes += (nbytes + Round) & ~Round; + if(bloc == (byte*)v+nbytes) + bloc -= nbytes; + runtime·unlock(&memlock); +} + +void +runtime·SysUnused(void *v, uintptr nbytes) +{ + USED(v, nbytes); +} + +void +runtime·SysMap(void *v, uintptr nbytes) +{ + USED(v, nbytes); +} + +void* +runtime·SysReserve(void *v, uintptr nbytes) +{ + USED(v); + return runtime·SysAlloc(nbytes); +} -- cgit v1.2.3