blob: da461e43df3718e0b0dece52ec003c3a7eec6bb1 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
#include <errno.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/resource.h>
static void
use_up_memory (void)
{
struct rlimit rl;
getrlimit (RLIMIT_AS, &rl);
rl.rlim_cur = 10 * 1024 * 1024;
setrlimit (RLIMIT_AS, &rl);
char *c;
int PAGESIZE = getpagesize ();
while (1)
{
c = mmap (NULL, PAGESIZE, PROT_NONE, MAP_ANON | MAP_PRIVATE, -1, 0);
if (c == MAP_FAILED)
break;
}
}
static void *
child (void *arg)
{
sleep (1);
return arg;
}
static int
do_test (void)
{
int err;
pthread_t tid;
use_up_memory ();
err = pthread_create (&tid, NULL, child, NULL);
if (err != 0)
{
printf ("pthread_create returns %d: %s\n", err,
err == EAGAIN ? "OK" : "FAIL");
return err != EAGAIN;
}
/* We did not fail to allocate memory despite the preparation. Oh well. */
return 0;
}
#define TEST_FUNCTION do_test ()
#include "../test-skeleton.c"
|