Autoconf check for buggy stack guard region

Some buggy NPTL threading implementations include the guard area within
the stack size allocations.  In this case we need to allocate an extra
page to account for the guard area since we only have two pages of usable
stack on Linux.  Added an autoconf test that detects such implementations
by running a test program designed to segfault if the bug is present.
Set a flag NPTL_GUARD_WITHIN_STACK that is tested to decide if extra
stack space must be allocated for the guard area.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
This commit is contained in:
Ned Bass 2010-07-21 18:53:14 -07:00 committed by Brian Behlendorf
parent 7fa6f8b93a
commit 16a9f68137
2 changed files with 57 additions and 0 deletions

View File

@ -0,0 +1,56 @@
dnl #
dnl # Check if the glibc NPTL threading implementation includes the guard area
dnl # within the stack size allocation, rather than allocating extra space at
dnl # the end of the stack, as POSIX.1 requires.
dnl #
AC_DEFUN([ZFS_AC_CONFIG_USER_STACK_GUARD], [
AC_MSG_CHECKING([whether pthread stack includes guard])
saved_CFLAGS="$CFLAGS"
CFLAGS="-fstack-check"
saved_LDFLAGS="$LDFLAGS"
LDFLAGS="-lpthread"
AC_RUN_IFELSE(AC_LANG_PROGRAM(
[
#include <pthread.h>
#include <sys/resource.h>
#include <unistd.h>
#include <bits/local_lim.h>
#define PAGESIZE (sysconf(_SC_PAGESIZE))
#define STACK_SIZE 8192
#define BUFSIZE 4096
void * func(void *arg)
{
char buf[[[BUFSIZE]]];
}
],
[
pthread_t tid;
pthread_attr_t attr;
struct rlimit l;
l.rlim_cur = 0;
l.rlim_max = 0;
setrlimit(RLIMIT_CORE, &l);
pthread_attr_init(&attr);
pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN + STACK_SIZE);
pthread_attr_setguardsize(&attr, PAGESIZE);
pthread_create(&tid, &attr, func, NULL);
pthread_join(tid, NULL);
]),
[
AC_MSG_RESULT([no])
],
[
AC_DEFINE([NPTL_GUARD_WITHIN_STACK], 1,
[Define to 1 if NPTL threading implementation includes
guard area in stack allocation])
AC_MSG_RESULT([yes])
])
CFLAGS="$saved_CFLAGS"
LDFLAGS="$saved_LDFLAGS"
])

View File

@ -9,4 +9,5 @@ AC_DEFUN([ZFS_AC_CONFIG_USER], [
ZFS_AC_CONFIG_USER_LIBUUID
ZFS_AC_CONFIG_USER_LIBBLKID
ZFS_AC_CONFIG_USER_FRAME_LARGER_THAN
ZFS_AC_CONFIG_USER_STACK_GUARD
])