Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: "Rémi Denis-Courmont" <remi@remlab.net>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH] checkasm/riscv: report an error upon SIGILL
Date: Wed, 12 Jul 2023 22:52:47 +0300
Message-ID: <20230712195247.38674-1-remi@remlab.net> (raw)

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".

                 reply	other threads:[~2023-07-12 19:52 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230712195247.38674-1-remi@remlab.net \
    --to=remi@remlab.net \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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