* [FFmpeg-devel] [PATCH 1/2] checkasm: add helper to report a fatal signal
@ 2023-11-16 16:05 Rémi Denis-Courmont
2023-11-16 16:05 ` [FFmpeg-devel] [PATCH 2/2] checkasm/riscv: report an error upon SIGILL Rémi Denis-Courmont
0 siblings, 1 reply; 2+ messages in thread
From: Rémi Denis-Courmont @ 2023-11-16 16:05 UTC (permalink / raw)
To: ffmpeg-devel
---
tests/checkasm/checkasm.c | 15 +++++++++++----
tests/checkasm/checkasm.h | 1 +
2 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c
index 708119e7c6..c67cf58922 100644
--- a/tests/checkasm/checkasm.c
+++ b/tests/checkasm/checkasm.c
@@ -23,10 +23,8 @@
#include "config.h"
#include "config_components.h"
-#if CONFIG_LINUX_PERF
-# ifndef _GNU_SOURCE
-# define _GNU_SOURCE // for syscall (performance monitoring API)
-# endif
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE // for syscall (performance monitoring API), strsignal()
#endif
#include <stdarg.h>
@@ -863,6 +861,15 @@ void checkasm_fail_func(const char *msg, ...)
}
}
+void checkasm_fail_signal(int signum)
+{
+#ifdef __GLIBC__
+ checkasm_fail_func("fatal signal %d: %s", signum, strsignal(signum));
+#else
+ checkasm_fail_func("fatal signal %d", signum);
+#endif
+}
+
/* Get the benchmark context of the current function */
CheckasmPerf *checkasm_get_perf_context(void)
{
diff --git a/tests/checkasm/checkasm.h b/tests/checkasm/checkasm.h
index cfea868ff1..8a1df43ab6 100644
--- a/tests/checkasm/checkasm.h
+++ b/tests/checkasm/checkasm.h
@@ -102,6 +102,7 @@ struct CheckasmPerf;
void *checkasm_check_func(void *func, const char *name, ...) av_printf_format(2, 3);
int checkasm_bench_func(void);
void checkasm_fail_func(const char *msg, ...) av_printf_format(1, 2);
+void checkasm_fail_signal(int signum);
struct CheckasmPerf *checkasm_get_perf_context(void);
void checkasm_report(const char *name, ...) av_printf_format(1, 2);
--
2.42.0
_______________________________________________
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] 2+ messages in thread
* [FFmpeg-devel] [PATCH 2/2] checkasm/riscv: report an error upon SIGILL
2023-11-16 16:05 [FFmpeg-devel] [PATCH 1/2] checkasm: add helper to report a fatal signal Rémi Denis-Courmont
@ 2023-11-16 16:05 ` Rémi Denis-Courmont
0 siblings, 0 replies; 2+ messages in thread
From: Rémi Denis-Courmont @ 2023-11-16 16:05 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. This is a common occurrence whilst developping RISC-V
assembler, due to the compatibility between vector configuration and
instruction done at run-time.
---
tests/checkasm/checkasm.c | 9 +++++++++
tests/checkasm/checkasm.h | 11 +++++++++--
tests/checkasm/riscv/checkasm.S | 12 ++++++++++++
3 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c
index c67cf58922..a15e801caf 100644
--- a/tests/checkasm/checkasm.c
+++ b/tests/checkasm/checkasm.c
@@ -27,6 +27,7 @@
# define _GNU_SOURCE // for syscall (performance monitoring API), strsignal()
#endif
+#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
@@ -734,6 +735,14 @@ 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 = checkasm_handle_signal,
+ .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 8a1df43ab6..61734a8dbb 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"
@@ -211,14 +212,20 @@ void checkasm_checked_call(void *func, ...);
checked_call(func_new, 0, 0, 0, 0, 0, 0, 0, __VA_ARGS__,\
7, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0))
#elif ARCH_RISCV
-void checkasm_set_function(void *);
+void checkasm_set_function(void *, sigjmp_buf);
void *checkasm_get_wrapper(void);
+void checkasm_handle_signal(int signum);
#if (__riscv_xlen == 64) && defined (__riscv_d)
#define declare_new(ret, ...) \
+ int checked_call_signum = 0; \
+ sigjmp_buf checked_call_jb; \
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, checked_call_jb), \
+ (checked_call_signum = sigsetjmp(checked_call_jb, 1)) == 0 \
+ ? checked_call(__VA_ARGS__) \
+ : (checkasm_fail_signal(checked_call_signum), 0))
#endif
#else
#define declare_new(ret, ...)
diff --git a/tests/checkasm/riscv/checkasm.S b/tests/checkasm/riscv/checkasm.S
index b902ab1043..30d3f3d8bb 100644
--- a/tests/checkasm/riscv/checkasm.S
+++ b/tests/checkasm/riscv/checkasm.S
@@ -41,6 +41,7 @@ endconst
checked_func:
.quad 0
+ .quad 0
saved_regs:
/* Space to spill RA, SP, GP, TP, S0-S11 and FS0-FS11 */
@@ -52,6 +53,7 @@ func checkasm_set_function
la.tls.ie t0, checked_func
add t0, tp, t0
sd a0, (t0)
+ sd a1, 8(t0)
ret
endfunc
@@ -175,4 +177,14 @@ func checkasm_get_wrapper, v
call checkasm_fail_func
j 4b
endfunc
+
+func checkasm_handle_signal
+ mv a1, a0
+ la.tls.ie a0, checked_func
+ add a0, tp, a0
+ ld a0, 8(a0)
+ beqz a0, 8f
+ tail siglongjmp
+8: tail abort /* No jump buffer to go to */
+endfunc
#endif
--
2.42.0
_______________________________________________
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] 2+ messages in thread
end of thread, other threads:[~2023-11-16 16:05 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-16 16:05 [FFmpeg-devel] [PATCH 1/2] checkasm: add helper to report a fatal signal Rémi Denis-Courmont
2023-11-16 16:05 ` [FFmpeg-devel] [PATCH 2/2] 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