This source file includes following definitions.
- rseq_current_cpu_raw
- rseq_cpu_start
- rseq_current_cpu
- rseq_clear_rseq_cs
- rseq_prepare_unload
1
2
3
4
5
6
7
8 #ifndef RSEQ_H
9 #define RSEQ_H
10
11 #include <stdint.h>
12 #include <stdbool.h>
13 #include <pthread.h>
14 #include <signal.h>
15 #include <sched.h>
16 #include <errno.h>
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <linux/rseq.h>
20
21
22
23
24
25
26 #ifndef RSEQ_INJECT_ASM
27 #define RSEQ_INJECT_ASM(n)
28 #endif
29
30 #ifndef RSEQ_INJECT_C
31 #define RSEQ_INJECT_C(n)
32 #endif
33
34 #ifndef RSEQ_INJECT_INPUT
35 #define RSEQ_INJECT_INPUT
36 #endif
37
38 #ifndef RSEQ_INJECT_CLOBBER
39 #define RSEQ_INJECT_CLOBBER
40 #endif
41
42 #ifndef RSEQ_INJECT_FAILED
43 #define RSEQ_INJECT_FAILED
44 #endif
45
46 extern __thread volatile struct rseq __rseq_abi;
47 extern int __rseq_handled;
48
49 #define rseq_likely(x) __builtin_expect(!!(x), 1)
50 #define rseq_unlikely(x) __builtin_expect(!!(x), 0)
51 #define rseq_barrier() __asm__ __volatile__("" : : : "memory")
52
53 #define RSEQ_ACCESS_ONCE(x) (*(__volatile__ __typeof__(x) *)&(x))
54 #define RSEQ_WRITE_ONCE(x, v) __extension__ ({ RSEQ_ACCESS_ONCE(x) = (v); })
55 #define RSEQ_READ_ONCE(x) RSEQ_ACCESS_ONCE(x)
56
57 #define __rseq_str_1(x) #x
58 #define __rseq_str(x) __rseq_str_1(x)
59
60 #define rseq_log(fmt, args...) \
61 fprintf(stderr, fmt "(in %s() at " __FILE__ ":" __rseq_str(__LINE__)"\n", \
62 ## args, __func__)
63
64 #define rseq_bug(fmt, args...) \
65 do { \
66 rseq_log(fmt, ##args); \
67 abort(); \
68 } while (0)
69
70 #if defined(__x86_64__) || defined(__i386__)
71 #include <rseq-x86.h>
72 #elif defined(__ARMEL__)
73 #include <rseq-arm.h>
74 #elif defined (__AARCH64EL__)
75 #include <rseq-arm64.h>
76 #elif defined(__PPC__)
77 #include <rseq-ppc.h>
78 #elif defined(__mips__)
79 #include <rseq-mips.h>
80 #elif defined(__s390__)
81 #include <rseq-s390.h>
82 #else
83 #error unsupported target
84 #endif
85
86
87
88
89
90
91
92
93 int rseq_register_current_thread(void);
94
95
96
97
98 int rseq_unregister_current_thread(void);
99
100
101
102
103 int32_t rseq_fallback_current_cpu(void);
104
105
106
107
108
109 static inline int32_t rseq_current_cpu_raw(void)
110 {
111 return RSEQ_ACCESS_ONCE(__rseq_abi.cpu_id);
112 }
113
114
115
116
117
118
119
120
121
122
123
124
125 static inline uint32_t rseq_cpu_start(void)
126 {
127 return RSEQ_ACCESS_ONCE(__rseq_abi.cpu_id_start);
128 }
129
130 static inline uint32_t rseq_current_cpu(void)
131 {
132 int32_t cpu;
133
134 cpu = rseq_current_cpu_raw();
135 if (rseq_unlikely(cpu < 0))
136 cpu = rseq_fallback_current_cpu();
137 return cpu;
138 }
139
140 static inline void rseq_clear_rseq_cs(void)
141 {
142 #ifdef __LP64__
143 __rseq_abi.rseq_cs.ptr = 0;
144 #else
145 __rseq_abi.rseq_cs.ptr.ptr32 = 0;
146 #endif
147 }
148
149
150
151
152
153
154
155
156
157
158 static inline void rseq_prepare_unload(void)
159 {
160 rseq_clear_rseq_cs();
161 }
162
163 #endif