OSDN Git Service

Add Go frontend, libgo library, and Go testsuite.
[pf3gnuchains/gcc-fork.git] / libgo / runtime / mem.c
1 #include <errno.h>
2
3 #include "runtime.h"
4 #include "malloc.h"
5
6 void*
7 runtime_SysAlloc(uintptr n)
8 {
9         void *p;
10
11         mstats.sys += n;
12         p = runtime_mmap(nil, n, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON|MAP_PRIVATE, -1, 0);
13         if (p == MAP_FAILED) {
14                 if(errno == EACCES) {
15                         printf("mmap: access denied\n");
16                         printf("If you're running SELinux, enable execmem for this process.\n");
17                 } else {
18                         printf("mmap: errno=%d\n", errno);
19                 }
20                 exit(2);
21         }
22         return p;
23 }
24
25 void
26 runtime_SysUnused(void *v, uintptr n)
27 {
28         USED(v);
29         USED(n);
30         // TODO(rsc): call madvise MADV_DONTNEED
31 }
32
33 void
34 runtime_SysFree(void *v, uintptr n)
35 {
36         mstats.sys -= n;
37         runtime_munmap(v, n);
38 }
39
40 void
41 runtime_SysMemInit(void)
42 {
43         // Code generators assume that references to addresses
44         // on the first page will fault.  Map the page explicitly with
45         // no permissions, to head off possible bugs like the system
46         // allocating that page as the virtual address space fills.
47         // Ignore any error, since other systems might be smart
48         // enough to never allow anything there.
49         runtime_mmap(nil, 4096, PROT_NONE, MAP_FIXED|MAP_ANON|MAP_PRIVATE, -1, 0);
50 }