1 /* Restartable Sequences single-threaded tests.
2    Copyright (C) 2021-2022 Free Software Foundation, Inc.
3 
4    The GNU C Library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Lesser General Public
6    License as published by the Free Software Foundation; either
7    version 2.1 of the License, or (at your option) any later version.
8 
9    The GNU C Library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Lesser General Public License for more details.
13 
14    You should have received a copy of the GNU Lesser General Public
15    License along with the GNU C Library; if not, see
16    <https://www.gnu.org/licenses/>.  */
17 
18 /* These tests validate that rseq is registered from main in an executable
19    not linked against libpthread.  */
20 
21 #include <support/check.h>
22 #include <stdio.h>
23 #include <sys/rseq.h>
24 #include <unistd.h>
25 
26 #ifdef RSEQ_SIG
27 # include <errno.h>
28 # include <error.h>
29 # include <stdlib.h>
30 # include <string.h>
31 # include <syscall.h>
32 # include <thread_pointer.h>
33 # include <tls.h>
34 # include "tst-rseq.h"
35 
36 static void
do_rseq_main_test(void)37 do_rseq_main_test (void)
38 {
39   struct pthread *pd = THREAD_SELF;
40 
41   TEST_VERIFY_EXIT (rseq_thread_registered ());
42   TEST_COMPARE (__rseq_flags, 0);
43   TEST_VERIFY ((char *) __thread_pointer () + __rseq_offset
44                == (char *) &pd->rseq_area);
45   TEST_COMPARE (__rseq_size, sizeof (pd->rseq_area));
46 }
47 
48 static void
do_rseq_test(void)49 do_rseq_test (void)
50 {
51   if (!rseq_available ())
52     {
53       FAIL_UNSUPPORTED ("kernel does not support rseq, skipping test");
54     }
55   do_rseq_main_test ();
56 }
57 #else /* RSEQ_SIG */
58 static void
do_rseq_test(void)59 do_rseq_test (void)
60 {
61   FAIL_UNSUPPORTED ("glibc does not define RSEQ_SIG, skipping test");
62 }
63 #endif /* RSEQ_SIG */
64 
65 static int
do_test(void)66 do_test (void)
67 {
68   do_rseq_test ();
69   return 0;
70 }
71 
72 #include <support/test-driver.c>
73