Note that mprotect has this behaviour even if the mprotect range covers the
area before it, so unless the heap is allocated without PROT_NONE initially
with mprotect calls later, there isn't anything glibc can do to avoid this.
The program below creates 3 times 10 new vma areas:
#include <sys/mman.h>
#include <unistd.h>
#include <stdio.h>
int main(void)
{
void *p, *q, *r;
p = mmap(NULL, 10*4096, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0);
printf ("p %p\n", p);
mprotect(p+1*4096, 4096, PROT_READ|PROT_WRITE);
mprotect(p+2*4096, 4096, PROT_READ|PROT_WRITE);
mprotect(p+3*4096, 4096, PROT_READ|PROT_WRITE);
mprotect(p+4*4096, 4096, PROT_READ|PROT_WRITE);
mprotect(p+5*4096, 4096, PROT_READ|PROT_WRITE);
mprotect(p+6*4096, 4096, PROT_READ|PROT_WRITE);
mprotect(p+7*4096, 4096, PROT_READ|PROT_WRITE);
mprotect(p+8*4096, 4096, PROT_READ|PROT_WRITE);
q = mmap(NULL, 10*4096, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0);
printf ("q %p\n", q);
mprotect(q+1*4096, 4096, PROT_READ|PROT_WRITE);
mprotect(q+1*4096, 8192, PROT_READ|PROT_WRITE);
mprotect(q+2*4096, 8192, PROT_READ|PROT_WRITE);
mprotect(q+3*4096, 8192, PROT_READ|PROT_WRITE);
mprotect(q+4*4096, 8192, PROT_READ|PROT_WRITE);
mprotect(q+5*4096, 8192, PROT_READ|PROT_WRITE);
mprotect(q+6*4096, 8192, PROT_READ|PROT_WRITE);
mprotect(q+7*4096, 8192, PROT_READ|PROT_WRITE);
r = mmap(NULL, 10*4096, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0);
printf ("r %p\n", r);
mprotect(r+4096, 1*4096, PROT_READ|PROT_WRITE);
mprotect(r+4096, 2*4096, PROT_READ|PROT_WRITE);
mprotect(r+4096, 3*4096, PROT_READ|PROT_WRITE);
mprotect(r+4096, 4*4096, PROT_READ|PROT_WRITE);
mprotect(r+4096, 5*4096, PROT_READ|PROT_WRITE);
mprotect(r+4096, 6*4096, PROT_READ|PROT_WRITE);
mprotect(r+4096, 7*4096, PROT_READ|PROT_WRITE);
mprotect(r+4096, 8*4096, PROT_READ|PROT_WRITE);
fflush(stdout);
pause();
return 0;
}
Jakub
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/