Add build system
[zfs.git] / config / user-nptl_guard_within_stack.m4
1 dnl #
2 dnl # Check if the glibc NPTL threading implementation includes the guard area
3 dnl # within the stack size allocation, rather than allocating extra space at
4 dnl # the end of the stack, as POSIX.1 requires.
5 dnl #
6 AC_DEFUN([ZFS_AC_CONFIG_USER_STACK_GUARD], [
7
8         AC_MSG_CHECKING([whether pthread stack includes guard])
9
10         saved_CFLAGS="$CFLAGS"
11         CFLAGS="-fstack-check"
12         saved_LDFLAGS="$LDFLAGS"
13         LDFLAGS="-lpthread"
14
15         AC_RUN_IFELSE(AC_LANG_PROGRAM(
16         [
17                 #include <pthread.h>
18                 #include <sys/resource.h>
19                 #include <unistd.h>
20                 #include <bits/local_lim.h>
21
22                 #define PAGESIZE (sysconf(_SC_PAGESIZE))
23                 #define STACK_SIZE 8192
24                 #define BUFSIZE 4096
25
26                 void * func(void *arg)
27                 {
28                         char buf[[[BUFSIZE]]];
29                 }
30         ],
31         [
32                 pthread_t tid;
33                 pthread_attr_t attr;
34                 struct rlimit l;
35
36                 l.rlim_cur = 0;
37                 l.rlim_max = 0;
38                 setrlimit(RLIMIT_CORE, &l);
39                 pthread_attr_init(&attr);
40                 pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN + STACK_SIZE);
41                 pthread_attr_setguardsize(&attr, PAGESIZE);
42                 pthread_create(&tid, &attr, func, NULL);
43                 pthread_join(tid, NULL);
44         ]),
45         [
46                 AC_MSG_RESULT([no])
47         ],
48         [
49                 AC_DEFINE([NPTL_GUARD_WITHIN_STACK], 1,
50                         [Define to 1 if NPTL threading implementation includes
51                         guard area in stack allocation])
52                 AC_MSG_RESULT([yes])
53         ])
54         CFLAGS="$saved_CFLAGS"
55         LDFLAGS="$saved_LDFLAGS"
56 ])