Commit | Line | Data |
---|---|---|
01bd794d MJ |
1 | // SPDX-License-Identifier: MIT |
2 | // SPDX-FileCopyrightText: 2024 Michael Jeanson <mjeanson@efficios.com> | |
3 | ||
4 | #ifndef _GNU_SOURCE | |
5 | #define _GNU_SOURCE | |
6 | #endif | |
7 | #include <stdint.h> | |
8 | ||
9 | #include <rseq/rseq.h> | |
10 | ||
11 | #include "tap.h" | |
12 | ||
c7b45750 | 13 | #define NR_TESTS 4 |
01bd794d | 14 | |
21e41336 MJ |
15 | /* |
16 | * Ensure the main executable has at least one TLS variable which will be | |
17 | * allocated before the rseq area, making sure the rseq_offset is not 0. This | |
18 | * allows testing that the rseq_offset variable is properly initialized by | |
19 | * checking it is not 0. | |
20 | * | |
21 | * Most toolchains will add at least one main exec TLS variable but it's | |
22 | * currently not the case on RISC-V. | |
23 | */ | |
24 | __thread int dummy_tls = -1; | |
25 | ||
01bd794d MJ |
26 | /* |
27 | * Check the state of the public symbols when the rseq syscall is available but | |
28 | * no thread has registered. | |
29 | */ | |
30 | ||
31 | int main(void) | |
32 | { | |
33 | struct rseq_abi *rseq_abi; | |
34 | ||
35 | plan_tests(NR_TESTS); | |
36 | ||
37 | if (!rseq_available(RSEQ_AVAILABLE_QUERY_KERNEL)) { | |
38 | skip(NR_TESTS, "rseq syscall unavailable"); | |
39 | goto end; | |
40 | } | |
41 | ||
42 | /* The syscall is available but the current thread is not registered. */ | |
43 | ||
44 | ok(rseq_flags == 0, "rseq_flags prior to registration is 0 (%d)", rseq_flags); | |
c67d1986 | 45 | ok(rseq_size == 0, "rseq_size prior to registration is 0 (%d)", rseq_size); |
01bd794d MJ |
46 | ok(rseq_offset != 0, "rseq_offset prior to registration is not 0 (%td)", rseq_offset); |
47 | ||
48 | rseq_abi = rseq_get_abi(); | |
49 | ok((int32_t) rseq_abi->cpu_id == RSEQ_ABI_CPU_ID_UNINITIALIZED, | |
50 | "rseq->cpu_id is set to RSEQ_ABI_CPU_ID_UNINITIALIZED (%d)", | |
51 | (int32_t) rseq_abi->cpu_id); | |
52 | ||
53 | end: | |
54 | exit(exit_status()); | |
55 | } |