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