Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] checkasm/riscv: report an error upon SIGILL
@ 2023-07-12 19:52 Rémi Denis-Courmont
  0 siblings, 0 replies; only message in thread
From: Rémi Denis-Courmont @ 2023-07-12 19:52 UTC (permalink / raw)
  To: ffmpeg-devel

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

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-07-12 19:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-12 19:52 [FFmpeg-devel] [PATCH] checkasm/riscv: report an error upon SIGILL Rémi Denis-Courmont

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git