51f0aa
commit d8b778907e5270fdeb70459842ffbc20bd2ca5e1
51f0aa
Author: Florian Weimer <fweimer@redhat.com>
51f0aa
Date:   Thu Jan 11 13:13:14 2018 +0100
51f0aa
51f0aa
    nptl: Add tst-minstack-cancel, tst-minstack-exit [BZ #22636]
51f0aa
    
51f0aa
    I verified that without the guard accounting change in commit
51f0aa
    630f4cc3aa019ede55976ea561f1a7af2f068639 (Fix stack guard size
51f0aa
    accounting) and RTLD_NOW for libgcc_s introduced by commit
51f0aa
    f993b8754080ac7572b692870e926d8b493db16c (nptl: Open libgcc.so with
51f0aa
    RTLD_NOW during pthread_cancel), the tst-minstack-cancel test fails on
51f0aa
    an AVX-512F machine.  tst-minstack-exit still passes, and either of
51f0aa
    the mentioned commit by itself frees sufficient stack space to make
51f0aa
    tst-minstack-cancel pass, too.
51f0aa
    
51f0aa
    Reviewed-by: Carlos O'Donell <carlos@redhat.com>
51f0aa
51f0aa
Index: glibc-2.17-c758a686/nptl/Makefile
51f0aa
===================================================================
51f0aa
--- glibc-2.17-c758a686.orig/nptl/Makefile
51f0aa
+++ glibc-2.17-c758a686/nptl/Makefile
51f0aa
@@ -267,7 +267,8 @@ tests = tst-typesizes \
51f0aa
 	tst-vfork1 tst-vfork2 tst-vfork1x tst-vfork2x \
51f0aa
 	tst-getpid1 tst-getpid2 tst-getpid3 \
51f0aa
 	tst-initializers1 $(patsubst %,tst-initializers1-%,c89 gnu89 c99 gnu99) \
51f0aa
-	tst-mutex-errorcheck
51f0aa
+	tst-mutex-errorcheck \
51f0aa
+	tst-minstack-cancel tst-minstack-exit
51f0aa
 xtests = tst-setuid1 tst-setuid1-static tst-mutexpp1 tst-mutexpp6 tst-mutexpp10
51f0aa
 test-srcs = tst-oddstacklimit
51f0aa
 
51f0aa
Index: glibc-2.17-c758a686/nptl/tst-minstack-cancel.c
51f0aa
===================================================================
51f0aa
--- /dev/null
51f0aa
+++ glibc-2.17-c758a686/nptl/tst-minstack-cancel.c
51f0aa
@@ -0,0 +1,48 @@
51f0aa
+/* Test cancellation with a minimal stack size.
51f0aa
+   Copyright (C) 2018 Free Software Foundation, Inc.
51f0aa
+   This file is part of the GNU C Library.
51f0aa
+
51f0aa
+   The GNU C Library is free software; you can redistribute it and/or
51f0aa
+   modify it under the terms of the GNU Lesser General Public
51f0aa
+   License as published by the Free Software Foundation; either
51f0aa
+   version 2.1 of the License, or (at your option) any later version.
51f0aa
+
51f0aa
+   The GNU C Library is distributed in the hope that it will be useful,
51f0aa
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
51f0aa
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
51f0aa
+   Lesser General Public License for more details.
51f0aa
+
51f0aa
+   You should have received a copy of the GNU Lesser General Public
51f0aa
+   License along with the GNU C Library; if not, see
51f0aa
+   <http://www.gnu.org/licenses/>.  */
51f0aa
+
51f0aa
+/* Note: This test is similar to tst-minstack-exit, but is separate to
51f0aa
+   avoid spurious test passes due to warm-up effects.  */
51f0aa
+
51f0aa
+#include <limits.h>
51f0aa
+#include <unistd.h>
51f0aa
+#include <support/check.h>
51f0aa
+#include <support/xthread.h>
51f0aa
+
51f0aa
+static void *
51f0aa
+threadfunc (void *closure)
51f0aa
+{
51f0aa
+  while (1)
51f0aa
+    pause ();
51f0aa
+  return NULL;
51f0aa
+}
51f0aa
+
51f0aa
+static int
51f0aa
+do_test (void)
51f0aa
+{
51f0aa
+  pthread_attr_t attr;
51f0aa
+  xpthread_attr_init (&attr);
51f0aa
+  xpthread_attr_setstacksize (&attr, PTHREAD_STACK_MIN);
51f0aa
+  pthread_t thr = xpthread_create (&attr, threadfunc, NULL);
51f0aa
+  xpthread_cancel (thr);
51f0aa
+  TEST_VERIFY (xpthread_join (thr) == PTHREAD_CANCELED);
51f0aa
+  xpthread_attr_destroy (&attr);
51f0aa
+  return 0;
51f0aa
+}
51f0aa
+
51f0aa
+#include <support/test-driver.c>
51f0aa
Index: glibc-2.17-c758a686/nptl/tst-minstack-exit.c
51f0aa
===================================================================
51f0aa
--- /dev/null
51f0aa
+++ glibc-2.17-c758a686/nptl/tst-minstack-exit.c
51f0aa
@@ -0,0 +1,46 @@
51f0aa
+/* Test that pthread_exit works with the minimum stack size.
51f0aa
+   Copyright (C) 2018 Free Software Foundation, Inc.
51f0aa
+   This file is part of the GNU C Library.
51f0aa
+
51f0aa
+   The GNU C Library is free software; you can redistribute it and/or
51f0aa
+   modify it under the terms of the GNU Lesser General Public
51f0aa
+   License as published by the Free Software Foundation; either
51f0aa
+   version 2.1 of the License, or (at your option) any later version.
51f0aa
+
51f0aa
+   The GNU C Library is distributed in the hope that it will be useful,
51f0aa
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
51f0aa
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
51f0aa
+   Lesser General Public License for more details.
51f0aa
+
51f0aa
+   You should have received a copy of the GNU Lesser General Public
51f0aa
+   License along with the GNU C Library; if not, see
51f0aa
+   <http://www.gnu.org/licenses/>.  */
51f0aa
+
51f0aa
+/* Note: This test is similar to tst-minstack-cancel, but is separate
51f0aa
+   to avoid spurious test passes due to warm-up effects.  */
51f0aa
+
51f0aa
+#include <limits.h>
51f0aa
+#include <unistd.h>
51f0aa
+#include <support/check.h>
51f0aa
+#include <support/xthread.h>
51f0aa
+
51f0aa
+static void *
51f0aa
+threadfunc (void *closure)
51f0aa
+{
51f0aa
+  pthread_exit (threadfunc);
51f0aa
+  return NULL;
51f0aa
+}
51f0aa
+
51f0aa
+static int
51f0aa
+do_test (void)
51f0aa
+{
51f0aa
+  pthread_attr_t attr;
51f0aa
+  xpthread_attr_init (&attr);
51f0aa
+  xpthread_attr_setstacksize (&attr, PTHREAD_STACK_MIN);
51f0aa
+  pthread_t thr = xpthread_create (&attr, threadfunc, NULL);
51f0aa
+  TEST_VERIFY (xpthread_join (thr) == threadfunc);
51f0aa
+  xpthread_attr_destroy (&attr);
51f0aa
+  return 0;
51f0aa
+}
51f0aa
+
51f0aa
+#include <support/test-driver.c>