[FFmpeg-devel] [PATCH] checkasm/riscv: report an error upon SIGILL

Rémi Denis-Courmont remi at remlab.net
Wed Jul 12 22:52:47 EEST 2023


Terminating the whole checkasm process is not very helpful. This will
report if an illegal instruction occurs while executing a tested
function.
---
 tests/checkasm/checkasm.c | 20 ++++++++++++++++++++
 tests/checkasm/checkasm.h |  8 +++++++-
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c
index 4311a8ffcb..53cf6c48bb 100644
--- a/tests/checkasm/checkasm.c
+++ b/tests/checkasm/checkasm.c
@@ -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");
diff --git a/tests/checkasm/checkasm.h b/tests/checkasm/checkasm.h
index 117d4dd35c..5a58ee19d0 100644
--- a/tests/checkasm/checkasm.h
+++ b/tests/checkasm/checkasm.h
@@ -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, ...)
-- 
2.40.1



More information about the ffmpeg-devel mailing list