@@ -29,6 +29,7 @@
# endif
#endif
+#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
@@ -68,6 +69,15 @@
void (*checkasm_checked_call)(void *func, int dummy, ...) = checkasm_checked_call_novfp;
#endif
+#if ARCH_RISCV
+_Thread_local sigjmp_buf checkasm_fail_sig_jmpbuf;
+
+static void fail_sig_handler(int signum)
+{
+ siglongjmp(checkasm_fail_sig_jmpbuf, signum);
+}
+#endif
+
/* List of tests to invoke */
static const struct {
const char *name;
@@ -724,6 +734,16 @@ int main(int argc, char *argv[])
if (have_vfp(av_get_cpu_flags()) || have_neon(av_get_cpu_flags()))
checkasm_checked_call = checkasm_checked_call_vfp;
#endif
+#if ARCH_RISCV
+ {
+ struct sigaction act = {
+ .sa_handler = fail_sig_handler,
+ .sa_flags = 0,
+ };
+
+ sigaction(SIGILL, &act, NULL);
+ }
+#endif
if (!tests[0].func || !cpus[0].flag) {
fprintf(stderr, "checkasm: no tests to perform\n");
@@ -23,6 +23,7 @@
#ifndef TESTS_CHECKASM_CHECKASM_H
#define TESTS_CHECKASM_CHECKASM_H
+#include <setjmp.h>
#include <stdint.h>
#include "config.h"
@@ -210,12 +211,17 @@ void checkasm_checked_call(void *func, ...);
#elif ARCH_RISCV
void checkasm_set_function(void *);
void *checkasm_get_wrapper(void);
+extern _Thread_local sigjmp_buf checkasm_fail_sig_jmpbuf;
#if (__riscv_xlen == 64) && defined (__riscv_d)
#define declare_new(ret, ...) \
+ int __signum; \
ret (*checked_call)(__VA_ARGS__) = checkasm_get_wrapper();
#define call_new(...) \
- (checkasm_set_function(func_new), checked_call(__VA_ARGS__))
+ (checkasm_set_function(func_new), \
+ (__signum = sigsetjmp(checkasm_fail_sig_jmpbuf, 1)) == 0 \
+ ? checked_call(__VA_ARGS__) \
+ : (checkasm_fail_func("Crash signal: %d", __signum), 0))
#endif
#else
#define declare_new(ret, ...)