1 // SPDX-License-Identifier: GPL-2.0
2 #ifndef _GNU_SOURCE
3 #define _GNU_SOURCE
4 #endif
5
6 #include <errno.h>
7 #include <signal.h>
8 #include <stdint.h>
9 #include <unistd.h>
10
11 #include "rseq.h"
12
13 #include "../kselftest_harness.h"
14
FIXTURE(legacy)15 FIXTURE(legacy)
16 {
17 };
18
19 static int cpu_id_in_sigfn = -1;
20
sigfn(int sig)21 static void sigfn(int sig)
22 {
23 struct rseq_abi *rs = rseq_get_abi();
24
25 cpu_id_in_sigfn = rs->cpu_id_start;
26 }
27
FIXTURE_SETUP(legacy)28 FIXTURE_SETUP(legacy)
29 {
30 int res = __rseq_register_current_thread(true, true);
31
32 switch (res) {
33 case -ENOSYS:
34 SKIP(return, "RSEQ not enabled\n");
35 case -EBUSY:
36 SKIP(return, "GLIBC owns RSEQ. Disable GLIBC RSEQ registration\n");
37 default:
38 ASSERT_EQ(res, 0);
39 }
40
41 ASSERT_NE(signal(SIGUSR1, sigfn), SIG_ERR);
42 }
43
FIXTURE_TEARDOWN(legacy)44 FIXTURE_TEARDOWN(legacy)
45 {
46 }
47
TEST_F(legacy,legacy_test)48 TEST_F(legacy, legacy_test)
49 {
50 struct rseq_abi *rs = rseq_get_abi();
51
52 ASSERT_NE(rs, NULL);
53
54 /* Overwrite rs::cpu_id_start */
55 rs->cpu_id_start = -1;
56 sleep(1);
57 ASSERT_NE(rs->cpu_id_start, -1);
58
59 rs->cpu_id_start = -1;
60 ASSERT_EQ(raise(SIGUSR1), 0);
61 ASSERT_NE(rs->cpu_id_start, -1);
62 ASSERT_NE(cpu_id_in_sigfn, -1);
63 }
64
65 TEST_HARNESS_MAIN
66