about summary refs log tree commit diff
path: root/REORG.TODO/setjmp
diff options
context:
space:
mode:
Diffstat (limited to 'REORG.TODO/setjmp')
-rw-r--r--REORG.TODO/setjmp/Makefile37
-rw-r--r--REORG.TODO/setjmp/Versions16
-rw-r--r--REORG.TODO/setjmp/__longjmp.c34
-rw-r--r--REORG.TODO/setjmp/bits/setjmp2.h40
-rw-r--r--REORG.TODO/setjmp/bsd-_setjmp.c34
-rw-r--r--REORG.TODO/setjmp/bsd-setjmp.c33
-rw-r--r--REORG.TODO/setjmp/bug269-setjmp.c106
-rw-r--r--REORG.TODO/setjmp/jmp-unwind.c28
-rw-r--r--REORG.TODO/setjmp/jmpbug.c41
-rw-r--r--REORG.TODO/setjmp/longjmp.c47
-rw-r--r--REORG.TODO/setjmp/setjmp.c35
-rw-r--r--REORG.TODO/setjmp/setjmp.h105
-rw-r--r--REORG.TODO/setjmp/sigjmp.c34
-rw-r--r--REORG.TODO/setjmp/tst-setjmp-fp.c105
-rw-r--r--REORG.TODO/setjmp/tst-setjmp-static.c1
-rw-r--r--REORG.TODO/setjmp/tst-setjmp.c120
-rw-r--r--REORG.TODO/setjmp/tst-sigsetjmp.c44
17 files changed, 860 insertions, 0 deletions
diff --git a/REORG.TODO/setjmp/Makefile b/REORG.TODO/setjmp/Makefile
new file mode 100644
index 0000000000..ca80b8ea13
--- /dev/null
+++ b/REORG.TODO/setjmp/Makefile
@@ -0,0 +1,37 @@
+# Copyright (C) 1991-2017 Free Software Foundation, Inc.
+# This file is part of the GNU C Library.
+
+# The GNU C Library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+
+# The GNU C Library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+
+# You should have received a copy of the GNU Lesser General Public
+# License along with the GNU C Library; if not, see
+# <http://www.gnu.org/licenses/>.
+
+#
+#	Makefile for setjmp/longjmp routines
+#
+subdir	:= setjmp
+
+include ../Makeconfig
+
+headers	:= setjmp.h bits/setjmp.h bits/setjmp2.h
+
+routines	:= setjmp sigjmp bsd-setjmp bsd-_setjmp \
+		   longjmp __longjmp jmp-unwind
+
+tests		:= tst-setjmp jmpbug bug269-setjmp tst-setjmp-fp \
+		   tst-sigsetjmp tst-setjmp-static
+tests-static	:= tst-setjmp-static
+
+
+include ../Rules
+
+$(objpfx)tst-setjmp-fp: $(libm)
diff --git a/REORG.TODO/setjmp/Versions b/REORG.TODO/setjmp/Versions
new file mode 100644
index 0000000000..2baa49ae8a
--- /dev/null
+++ b/REORG.TODO/setjmp/Versions
@@ -0,0 +1,16 @@
+libc {
+  GLIBC_2.0 {
+    # functions with special/multiple interfaces
+    _longjmp; __sigsetjmp; _setjmp;
+
+    # l*
+    longjmp;
+
+    # s*
+    setjmp;
+  }
+  GLIBC_PRIVATE {
+    # helper functions
+    __libc_longjmp; __libc_siglongjmp;
+  }
+}
diff --git a/REORG.TODO/setjmp/__longjmp.c b/REORG.TODO/setjmp/__longjmp.c
new file mode 100644
index 0000000000..72b27b6aa3
--- /dev/null
+++ b/REORG.TODO/setjmp/__longjmp.c
@@ -0,0 +1,34 @@
+/* Copyright (C) 1991-2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <setjmp.h>
+
+
+/* Jump to the position specified by ENV, causing the
+   setjmp call there to return VAL, or 1 if VAL is 0.  */
+void
+__longjmp (__jmp_buf env, int val)
+{
+  if (val == 0)
+    val = 1;
+
+  __set_errno (ENOSYS);
+  /* No way to signal failure.	*/
+}
+
+stub_warning (longjmp)
diff --git a/REORG.TODO/setjmp/bits/setjmp2.h b/REORG.TODO/setjmp/bits/setjmp2.h
new file mode 100644
index 0000000000..83dc006774
--- /dev/null
+++ b/REORG.TODO/setjmp/bits/setjmp2.h
@@ -0,0 +1,40 @@
+/* Checking macros for setjmp functions.
+   Copyright (C) 2009-2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef _SETJMP_H
+# error "Never include <bits/setjmp2.h> directly; use <setjmp.h> instead."
+#endif
+
+/* Variant of the longjmp functions which perform some sanity checking.  */
+#ifdef __REDIRECT_NTH
+extern void __REDIRECT_NTHNL (longjmp,
+			      (struct __jmp_buf_tag __env[1], int __val),
+			      __longjmp_chk) __attribute__ ((__noreturn__));
+extern void __REDIRECT_NTHNL (_longjmp,
+			      (struct __jmp_buf_tag __env[1], int __val),
+			      __longjmp_chk) __attribute__ ((__noreturn__));
+extern void __REDIRECT_NTHNL (siglongjmp,
+			      (struct __jmp_buf_tag __env[1], int __val),
+			      __longjmp_chk) __attribute__ ((__noreturn__));
+#else
+extern void __longjmp_chk (struct __jmp_buf_tag __env[1], int __val),
+     __THROWNL __attribute__ ((__noreturn__));
+# define longjmp __longjmp_chk
+# define _longjmp __longjmp_chk
+# define siglongjmp __longjmp_chk
+#endif
diff --git a/REORG.TODO/setjmp/bsd-_setjmp.c b/REORG.TODO/setjmp/bsd-_setjmp.c
new file mode 100644
index 0000000000..cf5963cf49
--- /dev/null
+++ b/REORG.TODO/setjmp/bsd-_setjmp.c
@@ -0,0 +1,34 @@
+/* BSD `_setjmp' entry point to `sigsetjmp (..., 0)'.  Stub version.
+   Copyright (C) 1994-2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sysdep.h>
+#include <setjmp.h>
+
+#undef _setjmp
+
+/* This implementation in C will not usually work, because the call
+   really needs to be a tail-call so __sigsetjmp saves the state of
+   the caller, not the state of this `setjmp' frame which then
+   immediate unwinds.  */
+
+int
+_setjmp (jmp_buf env)
+{
+  return __sigsetjmp (env, 0);
+}
+libc_hidden_def (_setjmp)
diff --git a/REORG.TODO/setjmp/bsd-setjmp.c b/REORG.TODO/setjmp/bsd-setjmp.c
new file mode 100644
index 0000000000..e2a6e51602
--- /dev/null
+++ b/REORG.TODO/setjmp/bsd-setjmp.c
@@ -0,0 +1,33 @@
+/* BSD `setjmp' entry point to `sigsetjmp (..., 1)'.  Stub version.
+   Copyright (C) 1994-2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sysdep.h>
+#include <setjmp.h>
+
+#undef setjmp
+
+/* This implementation in C will not usually work, because the call
+   really needs to be a tail-call so __sigsetjmp saves the state of
+   the caller, not the state of this `setjmp' frame which then
+   immediate unwinds.  */
+
+int
+setjmp (jmp_buf env)
+{
+  return __sigsetjmp (env, 1);
+}
diff --git a/REORG.TODO/setjmp/bug269-setjmp.c b/REORG.TODO/setjmp/bug269-setjmp.c
new file mode 100644
index 0000000000..3d1a73776c
--- /dev/null
+++ b/REORG.TODO/setjmp/bug269-setjmp.c
@@ -0,0 +1,106 @@
+/* Copyright (C) 2004-2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* Test case for Bugzilla # 269 */
+
+#include <stdio.h>
+#include <setjmp.h>
+#include <stdlib.h>
+
+jmp_buf buf1;
+jmp_buf buf2;
+int *p;
+int n_x = 6;
+
+static int g_counter = 0;
+
+int
+f (void)
+{
+  static int counter = 0;
+  static int way_point1 = 3;
+  static int way_point2 = 2;
+  int lose = 0;
+
+  if (setjmp (buf1) != 101)
+    {
+      int a[n_x];		/* reallocate stack space */
+      g_counter++;
+      p = &a[0];
+      if (g_counter < 5)
+	longjmp (buf1, 2);
+      else if (g_counter == 5)
+	longjmp (buf1, 101);
+      else
+	{
+	  _setjmp (buf2);
+	  _longjmp (buf1, 101);
+	}
+    }
+
+  way_point1--;
+
+  if (counter == 0)
+    {
+      counter++;
+      {
+	int a[n_x];		/* reallocate stack space */
+	g_counter++;
+	p = &a[0];
+	if (g_counter < 5)
+	  longjmp (buf1, 2);
+	else if (g_counter == 5)
+	  longjmp (buf1, 101);
+	else
+	  {
+	    _setjmp (buf2);
+	    _longjmp (buf1, 101);
+	  }
+      }
+    }
+
+  way_point2--;
+
+  if (counter == 1)
+    {
+      counter++;
+      longjmp (buf2, 2);
+    }
+
+  lose = !(way_point1 == 0 && way_point2 == 0
+	   && g_counter == 6 && counter == 2);
+
+  return lose;
+}
+
+static int
+do_test (void)
+{
+  int lose;
+
+  lose = f ();
+
+  if (lose)
+    puts ("Test FAILED!");
+  else
+    puts ("Test succeeded!");
+
+  return lose ? EXIT_FAILURE : EXIT_SUCCESS;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/REORG.TODO/setjmp/jmp-unwind.c b/REORG.TODO/setjmp/jmp-unwind.c
new file mode 100644
index 0000000000..a43db84b9d
--- /dev/null
+++ b/REORG.TODO/setjmp/jmp-unwind.c
@@ -0,0 +1,28 @@
+/* _longjmp_unwind -- Clean up stack frames unwound by longjmp.  Stub version.
+   Copyright (C) 1995-2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <setjmp.h>
+
+void
+_longjmp_unwind (jmp_buf env, int val)
+{
+
+  /* This function can perform any cleanups necessary to safely unwind the
+     stack frames around the current context which ENV unwinds past.  */
+
+}
diff --git a/REORG.TODO/setjmp/jmpbug.c b/REORG.TODO/setjmp/jmpbug.c
new file mode 100644
index 0000000000..8594c5a8a7
--- /dev/null
+++ b/REORG.TODO/setjmp/jmpbug.c
@@ -0,0 +1,41 @@
+/* setjmp vs alloca test case.  Exercised bug on sparc.  */
+
+#include <stdio.h>
+#include <setjmp.h>
+#include <alloca.h>
+
+static void
+sub5 (jmp_buf buf)
+{
+  longjmp (buf, 1);
+}
+
+static void
+test (int x)
+{
+  jmp_buf buf;
+  char *volatile foo;
+  int arr[100];
+
+  arr[77] = x;
+  if (setjmp (buf))
+    {
+      printf ("made it ok; %d\n", arr[77]);
+      return;
+    }
+
+  foo = (char *) alloca (128);
+  (void) foo;
+  sub5 (buf);
+}
+
+int
+main (void)
+{
+  int i;
+
+  for (i = 123; i < 345; ++i)
+    test (i);
+
+  return 0;
+}
diff --git a/REORG.TODO/setjmp/longjmp.c b/REORG.TODO/setjmp/longjmp.c
new file mode 100644
index 0000000000..2453c2c124
--- /dev/null
+++ b/REORG.TODO/setjmp/longjmp.c
@@ -0,0 +1,47 @@
+/* Copyright (C) 1991-2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <stddef.h>
+#include <setjmp.h>
+#include <signal.h>
+
+
+/* Set the signal mask to the one specified in ENV, and jump
+   to the position specified in ENV, causing the setjmp
+   call there to return VAL, or 1 if VAL is 0.  */
+void
+__libc_siglongjmp (sigjmp_buf env, int val)
+{
+  /* Perform any cleanups needed by the frames being unwound.  */
+  _longjmp_unwind (env, val);
+
+  if (env[0].__mask_was_saved)
+    /* Restore the saved signal mask.  */
+    (void) __sigprocmask (SIG_SETMASK, &env[0].__saved_mask,
+			  (sigset_t *) NULL);
+
+  /* Call the machine-dependent function to restore machine state.  */
+  __longjmp (env[0].__jmpbuf, val ?: 1);
+}
+
+#ifndef __libc_siglongjmp
+strong_alias (__libc_siglongjmp, __libc_longjmp)
+libc_hidden_def (__libc_longjmp)
+weak_alias (__libc_siglongjmp, _longjmp)
+weak_alias (__libc_siglongjmp, longjmp)
+weak_alias (__libc_siglongjmp, siglongjmp)
+#endif
diff --git a/REORG.TODO/setjmp/setjmp.c b/REORG.TODO/setjmp/setjmp.c
new file mode 100644
index 0000000000..375e10f375
--- /dev/null
+++ b/REORG.TODO/setjmp/setjmp.c
@@ -0,0 +1,35 @@
+/* Copyright (C) 1991-2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <setjmp.h>
+
+
+/* Save the current program position in ENV and return 0.  */
+int
+__libc_sigsetjmp (jmp_buf env, int savemask)
+{
+  /* Save the signal mask if requested.  */
+  __sigjmp_save (env, savemask);
+
+  __set_errno (ENOSYS);
+  /* No way to signal failure.	*/
+  return 0;
+}
+
+weak_alias (__libc_sigsetjmp, __sigsetjmp)
+stub_warning (__sigsetjmp)
diff --git a/REORG.TODO/setjmp/setjmp.h b/REORG.TODO/setjmp/setjmp.h
new file mode 100644
index 0000000000..86fb2edf6c
--- /dev/null
+++ b/REORG.TODO/setjmp/setjmp.h
@@ -0,0 +1,105 @@
+/* Copyright (C) 1991-2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/*
+ *	ISO C99 Standard: 7.13 Nonlocal jumps	<setjmp.h>
+ */
+
+#ifndef	_SETJMP_H
+#define	_SETJMP_H	1
+
+#include <features.h>
+
+__BEGIN_DECLS
+
+#include <bits/setjmp.h>		/* Get `__jmp_buf'.  */
+#include <bits/types/__sigset_t.h>
+
+/* Calling environment, plus possibly a saved signal mask.  */
+struct __jmp_buf_tag
+  {
+    /* NOTE: The machine-dependent definitions of `__sigsetjmp'
+       assume that a `jmp_buf' begins with a `__jmp_buf' and that
+       `__mask_was_saved' follows it.  Do not move these members
+       or add others before it.  */
+    __jmp_buf __jmpbuf;		/* Calling environment.  */
+    int __mask_was_saved;	/* Saved the signal mask?  */
+    __sigset_t __saved_mask;	/* Saved signal mask.  */
+  };
+
+
+typedef struct __jmp_buf_tag jmp_buf[1];
+
+/* Store the calling environment in ENV, also saving the signal mask.
+   Return 0.  */
+extern int setjmp (jmp_buf __env) __THROWNL;
+
+/* Store the calling environment in ENV, also saving the
+   signal mask if SAVEMASK is nonzero.  Return 0.
+   This is the internal name for `sigsetjmp'.  */
+extern int __sigsetjmp (struct __jmp_buf_tag __env[1], int __savemask) __THROWNL;
+
+/* Store the calling environment in ENV, not saving the signal mask.
+   Return 0.  */
+extern int _setjmp (struct __jmp_buf_tag __env[1]) __THROWNL;
+
+/* Do not save the signal mask.  This is equivalent to the `_setjmp'
+   BSD function.  */
+#define setjmp(env)	_setjmp (env)
+
+
+/* Jump to the environment saved in ENV, making the
+   `setjmp' call there return VAL, or 1 if VAL is 0.  */
+extern void longjmp (struct __jmp_buf_tag __env[1], int __val)
+     __THROWNL __attribute__ ((__noreturn__));
+
+#if defined __USE_MISC || defined __USE_XOPEN
+/* Same.  Usually `_longjmp' is used with `_setjmp', which does not save
+   the signal mask.  But it is how ENV was saved that determines whether
+   `longjmp' restores the mask; `_longjmp' is just an alias.  */
+extern void _longjmp (struct __jmp_buf_tag __env[1], int __val)
+     __THROWNL __attribute__ ((__noreturn__));
+#endif
+
+
+#ifdef	__USE_POSIX
+/* Use the same type for `jmp_buf' and `sigjmp_buf'.
+   The `__mask_was_saved' flag determines whether
+   or not `longjmp' will restore the signal mask.  */
+typedef struct __jmp_buf_tag sigjmp_buf[1];
+
+/* Store the calling environment in ENV, also saving the
+   signal mask if SAVEMASK is nonzero.  Return 0.  */
+# define sigsetjmp(env, savemask)	__sigsetjmp (env, savemask)
+
+/* Jump to the environment saved in ENV, making the
+   sigsetjmp call there return VAL, or 1 if VAL is 0.
+   Restore the signal mask if that sigsetjmp call saved it.
+   This is just an alias `longjmp'.  */
+extern void siglongjmp (sigjmp_buf __env, int __val)
+     __THROWNL __attribute__ ((__noreturn__));
+#endif /* Use POSIX.  */
+
+
+/* Define helper functions to catch unsafe code.  */
+#if __USE_FORTIFY_LEVEL > 0
+# include <bits/setjmp2.h>
+#endif
+
+__END_DECLS
+
+#endif /* setjmp.h  */
diff --git a/REORG.TODO/setjmp/sigjmp.c b/REORG.TODO/setjmp/sigjmp.c
new file mode 100644
index 0000000000..30839ae819
--- /dev/null
+++ b/REORG.TODO/setjmp/sigjmp.c
@@ -0,0 +1,34 @@
+/* Copyright (C) 1992-2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <stddef.h>
+#include <setjmp.h>
+#include <signal.h>
+
+/* This function is called by the `sigsetjmp' macro
+   before doing a `__setjmp' on ENV[0].__jmpbuf.
+   Always return zero.  */
+
+int
+__sigjmp_save (sigjmp_buf env, int savemask)
+{
+  env[0].__mask_was_saved = (savemask &&
+			     __sigprocmask (SIG_BLOCK, (sigset_t *) NULL,
+					    &env[0].__saved_mask) == 0);
+
+  return 0;
+}
diff --git a/REORG.TODO/setjmp/tst-setjmp-fp.c b/REORG.TODO/setjmp/tst-setjmp-fp.c
new file mode 100644
index 0000000000..99a9cbb5a3
--- /dev/null
+++ b/REORG.TODO/setjmp/tst-setjmp-fp.c
@@ -0,0 +1,105 @@
+/* Test that setjmp/longjmp do not save and restore floating-point
+   exceptions and rounding modes.
+   Copyright (C) 2013-2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <fenv.h>
+#include <setjmp.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+static jmp_buf __attribute__ ((unused)) env;
+static int result = 0;
+
+#if defined FE_TONEAREST && defined FE_TOWARDZERO
+static int expected_rounding_mode = FE_TONEAREST;
+
+static void
+change_rounding_mode (void)
+{
+  if (fesetround (FE_TOWARDZERO) == 0)
+    expected_rounding_mode = FE_TOWARDZERO;
+  else
+    puts ("fesetround (FE_TOWARDZERO) failed, continuing test");
+  longjmp (env, 1);
+}
+#endif
+
+#ifdef FE_INVALID
+static int expected_exceptions = 0;
+
+static void
+raise_exception (void)
+{
+  if (feraiseexcept (FE_INVALID) == 0)
+    expected_exceptions = FE_INVALID;
+  else
+    puts ("feraiseexcept (FE_INVALID) failed, continuing test");
+  longjmp (env, 1);
+}
+#endif
+
+static int
+do_test (void)
+{
+#if defined FE_TONEAREST && defined FE_TOWARDZERO
+  if (fesetround (FE_TONEAREST) == 0)
+    {
+      if (setjmp (env) == 0)
+	change_rounding_mode ();
+      else
+	{
+	  if (fegetround () == expected_rounding_mode)
+	    puts ("PASS: longjmp preserved rounding mode");
+	  else
+	    {
+	      puts ("FAIL: longjmp changed rounding mode");
+	      result = 1;
+	    }
+	}
+    }
+  else
+    puts ("fesetround (FE_TONEAREST) failed, not testing rounding modes");
+#else
+  puts ("rounding mode test not supported");
+#endif
+#ifdef FE_INVALID
+  if (feclearexcept (FE_ALL_EXCEPT) == 0)
+    {
+      if (setjmp (env) == 0)
+	raise_exception ();
+      else
+	{
+	  if (fetestexcept (FE_INVALID) == expected_exceptions)
+	    puts ("PASS: longjmp preserved exceptions");
+	  else
+	    {
+	      puts ("FAIL: longjmp changed exceptions");
+	      result = 1;
+	    }
+	}
+    }
+  else
+    puts ("feclearexcept (FE_ALL_EXCEPT) failed, not testing exceptions");
+#else
+  puts ("exception test not supported");
+#endif
+  return result;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/REORG.TODO/setjmp/tst-setjmp-static.c b/REORG.TODO/setjmp/tst-setjmp-static.c
new file mode 100644
index 0000000000..5ca5df8cb4
--- /dev/null
+++ b/REORG.TODO/setjmp/tst-setjmp-static.c
@@ -0,0 +1 @@
+#include "tst-setjmp.c"
diff --git a/REORG.TODO/setjmp/tst-setjmp.c b/REORG.TODO/setjmp/tst-setjmp.c
new file mode 100644
index 0000000000..2661f21a64
--- /dev/null
+++ b/REORG.TODO/setjmp/tst-setjmp.c
@@ -0,0 +1,120 @@
+/* Copyright (C) 1991-2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <stdio.h>
+#include <setjmp.h>
+#include <stdlib.h>
+
+static jmp_buf env;
+static int last_value = -1, lose = 0;
+
+static void
+jump (int val)
+{
+  longjmp (env, val);
+}
+
+static int
+do_test (void)
+{
+  int value;
+
+  value = setjmp (env);
+  if (value != last_value + 1)
+    {
+      fputs("Shouldn't have ", stdout);
+      lose = 1;
+    }
+  last_value = value;
+  switch (value)
+    {
+    case 0:
+      puts("Saved environment.");
+      jump (0);
+    default:
+      printf ("Jumped to %d.\n", value);
+      if (value < 10)
+	jump (value + 1);
+    }
+
+  if (!lose && value == 10)
+    {
+      /* Do a second test, this time without `setjmp' being a macro.
+         This is not required by ISO C but we have this for compatibility.  */
+#undef setjmp
+      extern int setjmp (jmp_buf);
+
+      last_value = -1;
+      lose = 0;
+
+      value = setjmp (env);
+      if (value != last_value + 1)
+	{
+	  fputs("Shouldn't have ", stdout);
+	  lose = 1;
+	}
+      last_value = value;
+      switch (value)
+	{
+	case 0:
+	  puts("Saved environment.");
+	  jump (0);
+	default:
+	  printf ("Jumped to %d.\n", value);
+	  if (value < 10)
+	    jump (value + 1);
+	}
+    }
+
+  if (!lose && value == 10)
+    {
+      /* And again for the `_setjmp' function.  */
+#ifndef _setjmp
+      extern int _setjmp (jmp_buf);
+#endif
+      last_value = -1;
+      lose = 0;
+
+      value = _setjmp (env);
+      if (value != last_value + 1)
+	{
+	  fputs("Shouldn't have ", stdout);
+	  lose = 1;
+	}
+      last_value = value;
+      switch (value)
+	{
+	case 0:
+	  puts("Saved environment.");
+	  jump (0);
+	default:
+	  printf ("Jumped to %d.\n", value);
+	  if (value < 10)
+	    jump (value + 1);
+	}
+    }
+
+  if (lose || value != 10)
+    puts ("Test FAILED!");
+  else
+    puts ("Test succeeded!");
+
+  return lose ? EXIT_FAILURE : EXIT_SUCCESS;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/REORG.TODO/setjmp/tst-sigsetjmp.c b/REORG.TODO/setjmp/tst-sigsetjmp.c
new file mode 100644
index 0000000000..6c6cdf4fca
--- /dev/null
+++ b/REORG.TODO/setjmp/tst-sigsetjmp.c
@@ -0,0 +1,44 @@
+/* Copyright (C) 2013-2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* Test case for BZ #15493 */
+
+#include <stdlib.h>
+#include <signal.h>
+#include <setjmp.h>
+
+static int
+do_test (void)
+{
+  sigjmp_buf sj;
+  sigset_t m;
+
+  sigemptyset (&m);
+  sigprocmask (SIG_SETMASK, &m, NULL);
+  if (sigsetjmp (sj, 0) == 0)
+    {
+      sigaddset (&m, SIGUSR1);
+      sigprocmask (SIG_SETMASK, &m, NULL);
+      siglongjmp (sj, 1);
+      return EXIT_FAILURE;
+    }
+  sigprocmask (SIG_SETMASK, NULL, &m);
+  return sigismember (&m, SIGUSR1) ? EXIT_SUCCESS : EXIT_FAILURE;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"