PowerPC: Fix nearbyint/nearbyintf result for FE_DOWNWARD
[glibc.git] / debug / tst-longjmp_chk.c
blobe4e93d2a36b537d9b4e1e21d40c7d35eb71c02bb
1 /* Basic test to make sure doing a longjmp to a jmpbuf with an invalid sp
2 is caught by the fortification code. */
3 #include <errno.h>
4 #include <fcntl.h>
5 #include <paths.h>
6 #include <setjmp.h>
7 #include <signal.h>
8 #include <stdbool.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <unistd.h>
14 static int do_test(void);
15 #define TEST_FUNCTION do_test ()
16 #include "../test-skeleton.c"
19 static jmp_buf b;
22 static void
23 __attribute__ ((noinline))
24 f (void)
26 char buf[1000];
27 asm volatile ("" : "=m" (buf));
29 if (setjmp (b) != 0)
31 puts ("second longjmp succeeded");
32 exit (1);
37 static bool expected_to_fail;
40 static void
41 handler (int sig)
43 if (expected_to_fail)
44 _exit (0);
45 else
47 static const char msg[] = "unexpected longjmp failure\n";
48 TEMP_FAILURE_RETRY (write (STDOUT_FILENO, msg, sizeof (msg) - 1));
49 _exit (1);
54 static int
55 do_test (void)
57 set_fortify_handler (handler);
60 expected_to_fail = false;
62 if (setjmp (b) == 0)
64 longjmp (b, 1);
65 /* NOTREACHED */
66 printf ("first longjmp returned\n");
67 return 1;
71 expected_to_fail = true;
73 f ();
74 longjmp (b, 1);
76 puts ("second longjmp returned");
77 return 1;