From a725673a6f186c60060f92abdf71314609de4a24 Mon Sep 17 00:00:00 2001 From: Yulong Wang <2302147681@qq.com> Date: Sun, 13 Jul 2025 04:04:20 +0000 Subject: [PATCH] [lwp][rv64] riscv: fix potential signal handler infinite loop --- components/lwp/arch/risc-v/rv64/lwp_gcc.S | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/components/lwp/arch/risc-v/rv64/lwp_gcc.S b/components/lwp/arch/risc-v/rv64/lwp_gcc.S index c207285c6fa..73573535f37 100644 --- a/components/lwp/arch/risc-v/rv64/lwp_gcc.S +++ b/components/lwp/arch/risc-v/rv64/lwp_gcc.S @@ -75,12 +75,20 @@ arch_crt_start_umode: * we handle following things here: * 1. restoring user mode debug state (not support yet) * 2. handling thread's exit request - * 3. handling POSIX signal + * 3. handling POSIX signal (skipped for signal quit path) * 4. restoring user context * 5. jump to user mode */ .global arch_ret_to_user arch_ret_to_user: + li s0, 1 // flag=1 (normal path) + j arch_ret_to_user_impl + +.global arch_signal_quit_ret_to_user +arch_signal_quit_ret_to_user: + li s0, 0 // flag=0 (signal quit path) + +arch_ret_to_user_impl: // TODO: we don't support kernel gdb server in risc-v yet // so we don't check debug state here and handle debugging bussiness @@ -90,6 +98,8 @@ arch_ret_to_user: call sys_exit 1: + // Skip signal handling if coming from arch_signal_quit + beqz s0, ret_to_user_exit mv a0, sp call lwp_thread_signal_catch @@ -119,7 +129,7 @@ arch_signal_quit: RESTORE_ALL SAVE_ALL - j arch_ret_to_user + j arch_signal_quit_ret_to_user /** * rt_noreturn