Blame src/regression/malloc-brk-fail.c
|
Szabolcs Nagy |
2b9639 |
// malloc should not fail if brk fails but mmap can still allocate
|
|
Szabolcs Nagy |
2b9639 |
#include <stdlib.h>
|
|
Szabolcs Nagy |
2b9639 |
#include <errno.h>
|
|
Szabolcs Nagy |
2b9639 |
#include <string.h>
|
|
Szabolcs Nagy |
46f33c |
#include <sys/mman.h>
|
|
Szabolcs Nagy |
2b9639 |
#include <sys/resource.h>
|
|
Szabolcs Nagy |
2b9639 |
#include "test.h"
|
|
Szabolcs Nagy |
2b9639 |
|
|
Szabolcs Nagy |
2b9639 |
#define T(f) ((f)==0 || (t_error(#f " failed: %s\n", strerror(errno)), 0))
|
|
Szabolcs Nagy |
2b9639 |
|
|
Szabolcs Nagy |
2b9639 |
int main(void)
|
|
Szabolcs Nagy |
2b9639 |
{
|
|
Szabolcs Nagy |
2b9639 |
void *p;
|
|
Szabolcs Nagy |
2b9639 |
void *q;
|
|
Szabolcs Nagy |
2b9639 |
size_t n;
|
|
Szabolcs Nagy |
2b9639 |
int r;
|
|
Szabolcs Nagy |
2b9639 |
|
|
Szabolcs Nagy |
2b9639 |
// fill memory, largest mmaped area is [p,p+n)
|
|
Szabolcs Nagy |
2b9639 |
if (t_vmfill(&p, &n, 1) < 1 || n < 2*65536) {
|
|
Szabolcs Nagy |
2b9639 |
t_error("vmfill failed\n");
|
|
Szabolcs Nagy |
2b9639 |
return 1;
|
|
Szabolcs Nagy |
2b9639 |
}
|
|
Szabolcs Nagy |
2b9639 |
errno = 0;
|
|
Szabolcs Nagy |
2b9639 |
T(t_setrlim(RLIMIT_DATA, 0));
|
|
Szabolcs Nagy |
2b9639 |
|
|
Szabolcs Nagy |
2b9639 |
// malloc should fail here
|
|
Szabolcs Nagy |
2b9639 |
errno = 0;
|
|
Szabolcs Nagy |
2b9639 |
q = malloc(10000);
|
|
Szabolcs Nagy |
2b9639 |
if (q)
|
|
Szabolcs Nagy |
2b9639 |
t_error("malloc(10000) succeeded after memory is filled\n");
|
|
Szabolcs Nagy |
2b9639 |
else if (errno != ENOMEM)
|
|
Szabolcs Nagy |
2b9639 |
t_error("malloc did not fail with ENOMEM, got %s\n", strerror(errno));
|
|
Szabolcs Nagy |
2b9639 |
|
|
Szabolcs Nagy |
2b9639 |
// make some space available for mmap
|
|
Szabolcs Nagy |
2b9639 |
T(munmap(p+65536, 65536));
|
|
Szabolcs Nagy |
2b9639 |
|
|
Szabolcs Nagy |
2b9639 |
// malloc should succeed now
|
|
Szabolcs Nagy |
2b9639 |
q = malloc(10000);
|
|
Szabolcs Nagy |
2b9639 |
if (!q)
|
|
Szabolcs Nagy |
2b9639 |
t_error("malloc(10000) failed (eventhough 64k is available to mmap): %s\n", strerror(errno));
|
|
Szabolcs Nagy |
2b9639 |
|
|
Szabolcs Nagy |
2b9639 |
return t_status;
|
|
Szabolcs Nagy |
2b9639 |
}
|