9 #include <sys/resource.h>
11 static void use_stack (size_t needed
);
13 void (*use_stack_ptr
) (size_t) = use_stack
;
16 use_stack (size_t needed
)
18 size_t sz
= sysconf (_SC_PAGESIZE
);
19 char *buf
= alloca (sz
);
20 memset (buf
, '\0', sz
);
23 use_stack_ptr (needed
- sz
);
30 getrlimit (RLIMIT_AS
, &rl
);
31 rl
.rlim_cur
= 10 * 1024 * 1024;
32 setrlimit (RLIMIT_AS
, &rl
);
35 int PAGESIZE
= getpagesize ();
38 c
= mmap (NULL
, PAGESIZE
, PROT_NONE
, MAP_ANON
| MAP_PRIVATE
, -1, 0);
57 /* Allocate the memory needed for the stack. */
58 use_stack_ptr (PTHREAD_STACK_MIN
);
62 err
= pthread_create (&tid
, NULL
, child
, NULL
);
65 printf ("pthread_create returns %d: %s\n", err
,
66 err
== EAGAIN
? "OK" : "FAIL");
70 /* We did not fail to allocate memory despite the preparation. Oh well. */
74 #define TEST_FUNCTION do_test ()
75 #include "../test-skeleton.c"