From 28ff8bb8f72f9ad8da5979c49a2c6c6ef1276a90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=9A=E6=9C=A8=20=E9=89=89?= Date: Sat, 27 Jul 2024 14:14:42 +0800 Subject: [PATCH] catch SIGSEGV in sig caught (#119) In the RISC-V extension instruction set, there are cases where cores from different manufacturers and different functional extension instructions share the same op. In such situations, it is necessary to add SIGSEGV handling to prevent program termination. --- ruapu.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/ruapu.h b/ruapu.h index 2b5993e..e48d448 100644 --- a/ruapu.h +++ b/ruapu.h @@ -82,28 +82,29 @@ static int ruapu_detect_isa(ruapu_some_inst some_inst) #include #include -static int g_ruapu_sigill_caught = 0; +static int g_ruapu_sig_caught = 0; static sigjmp_buf g_ruapu_jmpbuf; -static void ruapu_catch_sigill(int signo, siginfo_t* si, void* data) +static void ruapu_catch_sig(int signo, siginfo_t* si, void* data) { (void)signo; (void)si; (void)data; - g_ruapu_sigill_caught = 1; + g_ruapu_sig_caught = 1; siglongjmp(g_ruapu_jmpbuf, -1); } static int ruapu_detect_isa(ruapu_some_inst some_inst) { - g_ruapu_sigill_caught = 0; + g_ruapu_sig_caught = 0; struct sigaction sa = { 0 }; struct sigaction old_sa; sa.sa_flags = SA_ONSTACK | SA_RESTART | SA_SIGINFO; - sa.sa_sigaction = ruapu_catch_sigill; + sa.sa_sigaction = ruapu_catch_sig; sigaction(SIGILL, &sa, &old_sa); + sigaction(SIGSEGV, &sa, &old_sa); if (sigsetjmp(g_ruapu_jmpbuf, 1) == 0) { @@ -111,8 +112,9 @@ static int ruapu_detect_isa(ruapu_some_inst some_inst) } sigaction(SIGILL, &old_sa, NULL); + sigaction(SIGSEGV, &old_sa, NULL); - return g_ruapu_sigill_caught ? 0 : 1; + return g_ruapu_sig_caught ? 0 : 1; } #elif defined __SYTERKIT__