summaryrefslogtreecommitdiff
path: root/src/pkg/runtime/linux/mem.c
blob: e750f97ea2387d969d1e04e1aec9380f14b2fb17 (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
#include "runtime.h"
#include "defs.h"
#include "os.h"
#include "malloc.h"

void*
runtime·SysAlloc(uintptr n)
{
	void *p;

	mstats.sys += n;
	p = runtime·mmap(nil, n, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON|MAP_PRIVATE, -1, 0);
	if(p < (void*)4096) {
		if(p == (void*)EACCES) {
			runtime·printf("mmap: access denied\n");
			runtime·printf("If you're running SELinux, enable execmem for this process.\n");
			runtime·exit(2);
		}
		runtime·printf("mmap: errno=%p\n", p);
		runtime·throw("mmap");
	}
	return p;
}

void
runtime·SysUnused(void *v, uintptr n)
{
	USED(v);
	USED(n);
	// TODO(rsc): call madvise MADV_DONTNEED
}

void
runtime·SysFree(void *v, uintptr n)
{
	mstats.sys -= n;
	runtime·munmap(v, n);
}

void
runtime·SysMemInit(void)
{
}