1 #include <errno.h>
2 
3 #include "runtime.h"
4 #include "arch.h"
5 #include "malloc.h"
6 
7 void*
runtime_SysAlloc(uintptr n)8 runtime_SysAlloc(uintptr n)
9 {
10 	void *p;
11 
12 	mstats.sys += n;
13 	errno = posix_memalign(&p, PageSize, n);
14 	if (errno > 0) {
15 		perror("posix_memalign");
16 		exit(2);
17 	}
18 	return p;
19 }
20 
21 void
runtime_SysUnused(void * v,uintptr n)22 runtime_SysUnused(void *v, uintptr n)
23 {
24 	USED(v);
25 	USED(n);
26 	// TODO(rsc): call madvise MADV_DONTNEED
27 }
28 
29 void
runtime_SysFree(void * v,uintptr n)30 runtime_SysFree(void *v, uintptr n)
31 {
32 	mstats.sys -= n;
33 	free(v);
34 }
35 
36 void*
runtime_SysReserve(void * v,uintptr n)37 runtime_SysReserve(void *v, uintptr n)
38 {
39 	USED(v);
40 	return runtime_SysAlloc(n);
41 }
42 
43 void
runtime_SysMap(void * v,uintptr n)44 runtime_SysMap(void *v, uintptr n)
45 {
46 	USED(v);
47 	USED(n);
48 }
49