summaryrefslogtreecommitdiff
path: root/src/pkg/runtime/plan9/mem.c
blob: 651e6728eddc188fd39b7496706a9e6ab31c6bf9 (plain)
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
// 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)
{
}