runtime: warn about SELinux based mmap failures on Linux.

SELinux will cause mmap to fail when we request w+x memory unless the
user has configured their policies. We have a warning in make.bash,
but it's quite likely that the policy will be reset at some point and
then all their binaries start failing.

This patch prints a warning on Linux when mmap fails with EACCES.

R=rsc
CC=golang-dev
https://golang.org/cl/152086
This commit is contained in:
Adam Langley 2009-11-13 10:08:51 -08:00
parent 593ccd1d44
commit 3f7a32405d
5 changed files with 32 additions and 5 deletions

View file

@ -208,8 +208,19 @@ mallocinit(void)
void*
SysAlloc(uintptr n)
{
void *p;
mstats.sys += n;
return runtime_mmap(nil, n, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON|MAP_PRIVATE, -1, 0);
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) {
printf("mmap: access denied\n");
printf("If you're running SELinux, enable execmem for this process.\n");
} else {
printf("mmap: errno=%p\n", p);
}
exit(2);
}
return p;
}
void