Philippe Waroquiers 8c8cd6c9fc 324181 mmap does not handle MAP_32BIT (handle it now, rather than fail it)
324181 was previously closed with a solution to always make
MAP_32BIT fail. This is technically correct/according to the doc,
but is not very usable.
This patch ensures that MAP_32BIT mmap is succesful, as long as
aspacemgr gives a range in the first 2GB
(so, compared to a native run, MAP_32BIT will fail much more quickly
as aspacemgr does not reserve the address space below 2GB on a 64 bits).

Far to be perfect, but this is better than nothing.

Added a regression test that test succesful mmap 32 bits till
the 2GB limit is reached.




git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15341
2015-06-17 19:57:09 +00:00

44 lines
959 B
C

#include <stdio.h>
#include "tests/sys_mman.h"
#include <stdlib.h>
#include <unistd.h>
int main()
{
void *first = NULL;
void *last;
void *res;
while (1) {
res = mmap (NULL, 64 * 1024,
PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_32BIT,
-1, 0);
if (first == NULL) {
first = res;
if (first == (void *)-1) {
perror ("first mmap");
exit (1);
}
fprintf(stderr, "first mmap : %p\n", first);
}
if (res == (void *)-1) {
fprintf(stderr, "last mmap ok: %p\n", last);
break;
}
last = res;
}
/* And now, retry without MAP_32BIT */
res = mmap (NULL, 64 * 1024,
PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS,
-1, 0);
if (res == (void *)-1) {
perror ("retry mmap");
exit (1);
}
fprintf(stderr, "retry mmap ok: %p\n", res);
return 0;
}