@@ -258,14 +258,48 @@ struct signal_ucontext
258258 struct rt_hw_stack_frame frame ;
259259};
260260
261- void * arch_signal_ucontext_restore (rt_base_t user_sp )
261+ void arch_syscall_restart (void * sp , void * ksp );
262+
263+ void arch_signal_check_erestart (void * eframe , void * ksp )
264+ {
265+ struct rt_hw_stack_frame * exp_frame = eframe ;
266+ long rc = exp_frame -> a0 ;
267+ long sys_id = exp_frame -> a7 ;
268+
269+ (void )sys_id ;
270+
271+ if (rc == - ERESTART )
272+ {
273+ LOG_D ("%s(rc=%ld,sys_id=%ld,pid=%d)" , __func__ , rc , sys_id , lwp_self ()-> pid );
274+ LOG_D ("%s: restart rc = %ld" , lwp_get_syscall_name (sys_id ), rc );
275+
276+ /* t0 stores the copy of user's first syscall argument */
277+ exp_frame -> a0 = exp_frame -> t0 ;
278+ /* adjust for epc auto-increment in syscall_handler */
279+ exp_frame -> epc -= 4 ;
280+ /* copy exception frame from user stack to kernel stack */
281+ lwp_memcpy (ksp - sizeof (* exp_frame ), exp_frame , sizeof (* exp_frame ));
282+
283+ arch_syscall_restart (exp_frame , ksp );
284+ }
285+
286+ return ;
287+ }
288+
289+ static void arch_signal_post_action (struct signal_ucontext * new_sp , rt_base_t kernel_sp )
290+ {
291+ arch_signal_check_erestart (& new_sp -> frame , (void * )kernel_sp );
292+ }
293+
294+ void * arch_signal_ucontext_restore (rt_base_t user_sp , rt_base_t kernel_sp )
262295{
263296 struct signal_ucontext * new_sp ;
264297 new_sp = (void * )user_sp ;
265298
266299 if (lwp_user_accessable (new_sp , sizeof (* new_sp )))
267300 {
268301 lwp_thread_signal_mask (rt_thread_self (), LWP_SIG_MASK_CMD_SET_MASK , & new_sp -> save_sigmask , RT_NULL );
302+ arch_signal_post_action (new_sp , kernel_sp );
269303 }
270304 else
271305 {
@@ -320,8 +354,12 @@ void *arch_signal_ucontext_save(int signo, siginfo_t *psiginfo,
320354
321355void arch_syscall_set_errno (void * eframe , int expected , int code )
322356{
323- /* NO support */
324- return ;
357+ struct rt_hw_stack_frame * exp_frame = eframe ;
358+
359+ if (exp_frame -> a0 == - expected )
360+ {
361+ exp_frame -> a0 = - code ;
362+ }
325363}
326364
327365/**
@@ -354,4 +392,4 @@ int arch_backtrace_uthread(rt_thread_t thread)
354392 return -1 ;
355393 }
356394 return -1 ;
357- }
395+ }
0 commit comments