@@ -87,6 +87,7 @@ void AlarmHandler(int Seconds) {
87
87
// Alternatively, Fuchsia may in future actually implement basic signal
88
88
// handling for the machine trap signals.
89
89
#if defined(__x86_64__)
90
+
90
91
#define FOREACH_REGISTER (OP_REG, OP_NUM ) \
91
92
OP_REG (rax) \
92
93
OP_REG(rbx) \
@@ -107,6 +108,7 @@ void AlarmHandler(int Seconds) {
107
108
OP_REG(rip)
108
109
109
110
#elif defined(__aarch64__)
111
+
110
112
#define FOREACH_REGISTER (OP_REG, OP_NUM ) \
111
113
OP_NUM (0 ) \
112
114
OP_NUM(1 ) \
@@ -140,6 +142,41 @@ void AlarmHandler(int Seconds) {
140
142
OP_NUM(29 ) \
141
143
OP_REG(sp)
142
144
145
+ #elif defined(__riscv)
146
+
147
+ #define FOREACH_REGISTER (OP_REG, OP_NUM ) \
148
+ OP_REG (ra) \
149
+ OP_REG(sp) \
150
+ OP_REG(gp) \
151
+ OP_REG(tp) \
152
+ OP_REG(t0) \
153
+ OP_REG(t1) \
154
+ OP_REG(t2) \
155
+ OP_REG(s0) \
156
+ OP_REG(s1) \
157
+ OP_REG(a0) \
158
+ OP_REG(a1) \
159
+ OP_REG(a2) \
160
+ OP_REG(a3) \
161
+ OP_REG(a4) \
162
+ OP_REG(a5) \
163
+ OP_REG(a6) \
164
+ OP_REG(a7) \
165
+ OP_REG(s2) \
166
+ OP_REG(s3) \
167
+ OP_REG(s4) \
168
+ OP_REG(s5) \
169
+ OP_REG(s6) \
170
+ OP_REG(s7) \
171
+ OP_REG(s8) \
172
+ OP_REG(s9) \
173
+ OP_REG(s10) \
174
+ OP_REG(s11) \
175
+ OP_REG(t3) \
176
+ OP_REG(t4) \
177
+ OP_REG(t5) \
178
+ OP_REG(t6) \
179
+
143
180
#else
144
181
#error "Unsupported architecture for fuzzing on Fuchsia"
145
182
#endif
@@ -200,6 +237,13 @@ void MakeTrampoline() {
200
237
" .cfi_offset 30, %c[lr]\n "
201
238
" bl %c[StaticCrashHandler]\n "
202
239
" brk 1\n "
240
+ #elif defined(__riscv)
241
+ " .cfi_return_column 64\n "
242
+ " .cfi_def_cfa sp, 0\n "
243
+ " .cfi_offset 64, %[pc]\n "
244
+ FOREACH_REGISTER (CFI_OFFSET_REG, CFI_OFFSET_NUM)
245
+ " call %c[StaticCrashHandler]\n "
246
+ " unimp\n "
203
247
#else
204
248
#error "Unsupported architecture for fuzzing on Fuchsia"
205
249
#endif
@@ -209,8 +253,11 @@ void MakeTrampoline() {
209
253
" .cfi_startproc\n "
210
254
: // No outputs
211
255
: FOREACH_REGISTER (ASM_OPERAND_REG, ASM_OPERAND_NUM)
256
+ #if defined(__aarch64__) || defined(__riscv)
257
+ ASM_OPERAND_REG (pc)
258
+ #endif
212
259
#if defined(__aarch64__)
213
- ASM_OPERAND_REG (pc) ASM_OPERAND_REG ( lr)
260
+ ASM_OPERAND_REG (lr)
214
261
#endif
215
262
[StaticCrashHandler] " i" (StaticCrashHandler));
216
263
}
@@ -294,6 +341,7 @@ void CrashHandler() {
294
341
// onto the stack and jump into a trampoline with CFI instructions on how
295
342
// to restore it.
296
343
#if defined(__x86_64__)
344
+
297
345
uintptr_t StackPtr =
298
346
(GeneralRegisters.rsp - (128 + sizeof (GeneralRegisters))) &
299
347
-(uintptr_t )16 ;
@@ -302,7 +350,8 @@ void CrashHandler() {
302
350
GeneralRegisters.rsp = StackPtr;
303
351
GeneralRegisters.rip = reinterpret_cast <zx_vaddr_t >(CrashTrampolineAsm);
304
352
305
- #elif defined(__aarch64__)
353
+ #elif defined(__aarch64__) || defined(__riscv)
354
+
306
355
uintptr_t StackPtr =
307
356
(GeneralRegisters.sp - sizeof (GeneralRegisters)) & -(uintptr_t )16 ;
308
357
__unsanitized_memcpy (reinterpret_cast <void *>(StackPtr), &GeneralRegisters,
0 commit comments