8 #define MAP_ANON MAP_ANONYMOUS
16 static int dev_zero = -1;
20 runtime_SysAlloc(uintptr n)
29 dev_zero = open("/dev/zero", O_RDONLY);
31 printf("open /dev/zero: errno=%d\n", errno);
38 p = runtime_mmap(nil, n, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON|MAP_PRIVATE, fd, 0);
39 if (p == MAP_FAILED) {
41 printf("runtime: mmap: access denied\n");
42 printf("if you're running SELinux, enable execmem for this process.\n");
51 runtime_SysUnused(void *v, uintptr n)
55 // TODO(rsc): call madvise MADV_DONTNEED
59 runtime_SysFree(void *v, uintptr n)
66 runtime_SysReserve(void *v, uintptr n)
70 // On 64-bit, people with ulimit -v set complain if we reserve too
71 // much address space. Instead, assume that the reservation is okay
72 // and check the assumption in SysMap.
73 if(sizeof(void*) == 8)
78 dev_zero = open("/dev/zero", O_RDONLY);
80 printf("open /dev/zero: errno=%d\n", errno);
87 return runtime_mmap(v, n, PROT_NONE, MAP_ANON|MAP_PRIVATE, fd, 0);
91 runtime_SysMap(void *v, uintptr n)
100 dev_zero = open("/dev/zero", O_RDONLY);
102 printf("open /dev/zero: errno=%d\n", errno);
109 // On 64-bit, we don't actually have v reserved, so tread carefully.
110 if(sizeof(void*) == 8) {
111 p = runtime_mmap(v, n, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON|MAP_PRIVATE, fd, 0);
113 runtime_printf("runtime: address space conflict: map(%p) = %p\n", v, p);
114 runtime_throw("runtime: address space conflict");
119 p = runtime_mmap(v, n, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON|MAP_FIXED|MAP_PRIVATE, fd, 0);
121 runtime_throw("runtime: cannot map pages in arena address space");