1 // commit 5446303328adf4b4e36d9fba21848e6feb55fab4 2014-04-02
2 // malloc should not fail if brk fails but mmap can still allocate
7 #include <sys/resource.h>
10 #define T(f) ((f)==0 || (t_error(#f " failed: %s\n", strerror(errno)), 0))
19 // fill memory, largest mmaped area is [p,p+n)
20 if (t_vmfill(&p
, &n
, 1) < 1 || n
< 2*65536) {
21 t_error("vmfill failed\n");
25 // malloc should fail here
29 t_error("malloc(10000) succeeded after memory is filled\n");
30 else if (errno
!= ENOMEM
)
31 t_error("malloc did not fail with ENOMEM, got %s\n", strerror(errno
));
33 // make space available for mmap, but ensure it's not contiguous with brk
34 T(munmap((char*)p
+65536, n
-65536));
36 // malloc should succeed now
39 t_error("malloc(10000) failed (eventhough 64k is available to mmap): %s\n", strerror(errno
));