Skip to content

Commit 01aefad

Browse files
committed
[lwp][rv64] riscv: fix potential signal handler infinite loop
1 parent 95b1d69 commit 01aefad

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

components/lwp/arch/risc-v/rv64/lwp_gcc.S

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,29 @@ ret_to_user_exit:
9898
// `RESTORE_ALL` also reset sp to user sp, and setup sscratch
9999
sret
100100

101+
/**
102+
* Signal cleanup exit path - returns to user mode without checking pending signals.
103+
*
104+
* This is called after signal handler completion (via arch_signal_quit) to restore
105+
* user context. We intentionally skip pending signal checks here to prevent:
106+
* 1. Signal handler recursion (e.g. if handler uses sys_tkill to send itself signals)
107+
*
108+
* The primary purpose is to break potential infinite loops where a signal handler
109+
* keeps triggering new signals. Normal signal delivery will resume on the next
110+
* kernel-to-userspace transition.
111+
*/
112+
.global arch_signal_quit_to_user
113+
arch_signal_quit_to_user:
114+
call lwp_check_exit_request
115+
beqz a0, 1f
116+
mv a0, x0
117+
call sys_exit
118+
119+
1:
120+
mv a0, sp
121+
RESTORE_ALL
122+
sret
123+
101124
/**
102125
* Restore user context from exception frame stroraged in ustack
103126
* And handle pending signals;
@@ -119,7 +142,7 @@ arch_signal_quit:
119142

120143
RESTORE_ALL
121144
SAVE_ALL
122-
j arch_ret_to_user
145+
j arch_signal_quit_to_user
123146

124147
/**
125148
* rt_noreturn

0 commit comments

Comments
 (0)