signal: signal handler may cause task's state error

For example, task is blocked by nxsem_wait(sem1), use nxsem_wait(sem2)
in signal handler, and take sem2 successfully, after exit from signal
handler to task, nxsem_wait(sem1) returns OK, but the correct result
should be -EINTR.

Signed-off-by: Zeng Zhaoxiu <zhaoxiu.zeng@gmail.com>
This commit is contained in:
Zeng Zhaoxiu 2021-12-29 20:02:09 +08:00 committed by Masayuki Ishikawa
parent 9aa69168e4
commit fb43fd73ed
26 changed files with 13 additions and 221 deletions

View File

@ -57,13 +57,6 @@ void arm_sigdeliver(void)
struct tcb_s *rtcb = this_task();
uint32_t regs[XCPTCONTEXT_REGS];
/* Save the errno. This must be preserved throughout the signal handling
* so that the user code final gets the correct errno value (probably
* EINTR).
*/
int saved_errno = get_errno();
board_autoled_on(LED_SIGNAL);
sinfo("rtcb=%p sigdeliver=%p sigpendactionq.head=%p\n",
@ -93,7 +86,6 @@ void arm_sigdeliver(void)
sinfo("Resuming\n");
up_irq_save();
set_errno(saved_errno);
/* Modify the saved return state with the actual saved values in the
* TCB. This depends on the fact that nested signal handling is

View File

@ -62,13 +62,6 @@ void arm_sigdeliver(void)
struct tcb_s *rtcb = this_task();
uint32_t regs[XCPTCONTEXT_REGS + 4];
/* Save the errno. This must be preserved throughout the signal handling
* so that the user code final gets the correct errno value (probably
* EINTR).
*/
int saved_errno = get_errno();
#ifdef CONFIG_SMP
/* In the SMP case, we must terminate the critical section while the signal
* handler executes, but we also need to restore the irqcount when the
@ -146,10 +139,6 @@ void arm_sigdeliver(void)
up_irq_save();
#endif
/* Restore the saved errno value */
set_errno(saved_errno);
/* Modify the saved return state with the actual saved values in the
* TCB. This depends on the fact that nested signal handling is
* not supported. Therefore, these values will persist throughout the

View File

@ -57,13 +57,6 @@ void arm_sigdeliver(void)
struct tcb_s *rtcb = this_task();
uint32_t regs[XCPTCONTEXT_REGS];
/* Save the errno. This must be preserved throughout the signal handling
* so that the user code final gets the correct errno value (probably
* EINTR).
*/
int saved_errno = get_errno();
#ifdef CONFIG_SMP
/* In the SMP case, we must terminate the critical section while the signal
* handler executes, but we also need to restore the irqcount when the
@ -141,10 +134,6 @@ void arm_sigdeliver(void)
up_irq_save();
#endif
/* Restore the saved errno value */
set_errno(saved_errno);
/* Modify the saved return state with the actual saved values in the
* TCB. This depends on the fact that nested signal handling is
* not supported. Therefore, these values will persist throughout the

View File

@ -57,13 +57,6 @@ void arm_sigdeliver(void)
struct tcb_s *rtcb = this_task();
uint32_t regs[XCPTCONTEXT_REGS];
/* Save the errno. This must be preserved throughout the signal handling
* so that the user code final gets the correct errno value (probably
* EINTR).
*/
int saved_errno = get_errno();
#ifdef CONFIG_SMP
/* In the SMP case, we must terminate the critical section while the signal
* handler executes, but we also need to restore the irqcount when the
@ -145,10 +138,6 @@ void arm_sigdeliver(void)
up_irq_save();
#endif
/* Restore the saved errno value */
set_errno(saved_errno);
/* Modify the saved return state with the actual saved values in the
* TCB. This depends on the fact that nested signal handling is
* not supported. Therefore, these values will persist throughout the

View File

@ -57,13 +57,6 @@ void arm_sigdeliver(void)
struct tcb_s *rtcb = this_task();
uint32_t regs[XCPTCONTEXT_REGS];
/* Save the errno. This must be preserved throughout the signal handling
* so that the user code final gets the correct errno value (probably
* EINTR).
*/
int saved_errno = get_errno();
board_autoled_on(LED_SIGNAL);
sinfo("rtcb=%p sigdeliver=%p sigpendactionq.head=%p\n",
@ -93,7 +86,6 @@ void arm_sigdeliver(void)
sinfo("Resuming\n");
up_irq_save();
set_errno(saved_errno);
/* Modify the saved return state with the actual saved values in the
* TCB. This depends on the fact that nested signal handling is

View File

@ -57,13 +57,6 @@ void arm_sigdeliver(void)
struct tcb_s *rtcb = this_task();
uint32_t regs[XCPTCONTEXT_REGS];
/* Save the errno. This must be preserved throughout the signal handling
* so that the user code final gets the correct errno value (probably
* EINTR).
*/
int saved_errno = get_errno();
#ifdef CONFIG_SMP
/* In the SMP case, we must terminate the critical section while the signal
* handler executes, but we also need to restore the irqcount when the
@ -145,10 +138,6 @@ void arm_sigdeliver(void)
up_irq_save();
#endif
/* Restore the saved errno value */
set_errno(saved_errno);
/* Modify the saved return state with the actual saved values in the
* TCB. This depends on the fact that nested signal handling is
* not supported. Therefore, these values will persist throughout the

View File

@ -57,13 +57,6 @@ void up_sigdeliver(void)
struct tcb_s *rtcb = this_task();
uint8_t regs[XCPTCONTEXT_REGS];
/* Save the errno. This must be preserved throughout the signal handling
* so that the user code final gets the correct errno value (probably
* EINTR).
*/
int saved_errno = get_errno();
board_autoled_on(LED_SIGNAL);
sinfo("rtcb=%p sigdeliver=%p sigpendactionq.head=%p\n",
@ -93,7 +86,6 @@ void up_sigdeliver(void)
sinfo("Resuming\n");
up_irq_save();
set_errno(saved_errno);
/* Modify the saved return state with the actual saved values in the
* TCB. This depends on the fact that nested signal handling is

View File

@ -61,13 +61,6 @@ void up_sigdeliver(void)
uint32_t regs[XCPTCONTEXT_REGS];
#endif
/* Save the errno. This must be preserved throughout the signal handling
* so that the user code final gets the correct errno value (probably
* EINTR).
*/
int saved_errno = get_errno();
board_autoled_on(LED_SIGNAL);
sinfo("rtcb=%p sigdeliver=%p sigpendactionq.head=%p\n",
@ -97,7 +90,6 @@ void up_sigdeliver(void)
sinfo("Resuming\n");
up_irq_save();
set_errno(saved_errno);
/* Modify the saved return state with the actual saved values in the
* TCB. This depends on the fact that nested signal handling is

View File

@ -59,13 +59,6 @@ void up_sigdeliver(void)
struct tcb_s *rtcb = this_task();
uint32_t regs[XCPTCONTEXT_REGS];
/* Save the errno. This must be preserved throughout the signal handling
* so that the user code final gets the correct errno value (probably
* EINTR).
*/
int saved_errno = get_errno();
board_autoled_on(LED_SIGNAL);
sinfo("rtcb=%p sigdeliver=%p sigpendactionq.head=%p\n",
@ -97,7 +90,6 @@ void up_sigdeliver(void)
regs[REG_EPC], regs[REG_STATUS]);
up_irq_save();
set_errno(saved_errno);
/* Modify the saved return state with the actual saved values in the
* TCB. This depends on the fact that nested signal handling is

View File

@ -57,13 +57,6 @@ void lm32_sigdeliver(void)
struct tcb_s *rtcb = this_task();
uint32_t regs[XCPTCONTEXT_REGS];
/* Save the errno. This must be preserved throughout the signal handling
* so that the user code final gets the correct errno value (probably
* EINTR).
*/
int saved_errno = get_errno();
board_autoled_on(LED_SIGNAL);
sinfo("rtcb=%p sigdeliver=%p sigpendactionq.head=%p\n",
@ -95,7 +88,6 @@ void lm32_sigdeliver(void)
regs[REG_EPC], regs[REG_INT_CTX]);
up_irq_save();
set_errno(saved_errno);
/* Modify the saved return state with the actual saved values in the
* TCB. This depends on the fact that nested signal handling is

View File

@ -59,13 +59,6 @@ void minerva_sigdeliver(void)
uint32_t regs[XCPTCONTEXT_REGS];
sig_deliver_t sigdeliver;
/* Save the errno. This must be preserved throughout the signal handling
* so that the user code final gets the correct errno value (probably
* EINTR).
*/
int saved_errno = get_errno();
board_autoled_on(LED_SIGNAL);
sinfo("rtcb=%p sigdeliver=%p sigpendactionq.head=%p\n",
@ -107,7 +100,6 @@ void minerva_sigdeliver(void)
regs[REG_CSR_MSTATUS]);
up_irq_save();
set_errno(saved_errno);
/* Then restore the correct state for this thread of execution. */

View File

@ -56,13 +56,6 @@ void up_sigdeliver(void)
struct tcb_s *rtcb = this_task();
uint8_t regs[XCPTCONTEXT_SIZE];
/* Save the errno. This must be preserved throughout the signal handling
* so that the user code final gets the correct errno value (probably
* EINTR).
*/
int saved_errno = get_errno();
board_autoled_on(LED_SIGNAL);
sinfo("rtcb=%p sigdeliver=%p sigpendactionq.head=%p\n",
@ -92,7 +85,6 @@ void up_sigdeliver(void)
sinfo("Resuming\n");
up_irq_save();
set_errno(saved_errno);
/* Modify the saved return state with the actual saved values in the
* TCB. This depends on the fact that nested signal handling is

View File

@ -57,13 +57,6 @@ void up_sigdeliver(void)
uint32_t regs[XCPTCONTEXT_REGS];
sig_deliver_t sigdeliver;
/* Save the errno. This must be preserved throughout the signal handling
* so that the user code final gets the correct errno value (probably
* EINTR).
*/
int saved_errno = get_errno();
board_autoled_on(LED_SIGNAL);
sinfo("rtcb=%p sigdeliver=%p sigpendactionq.head=%p\n",
@ -104,7 +97,6 @@ void up_sigdeliver(void)
sinfo("Resuming\n");
up_irq_save();
set_errno(saved_errno);
/* Then restore the correct state for this thread of
* execution.

View File

@ -56,13 +56,6 @@ void up_sigdeliver(void)
struct tcb_s *rtcb = this_task();
uint32_t regs[XCPTCONTEXT_REGS];
/* Save the errno. This must be preserved throughout the signal handling
* so that the user code final gets the correct errno value (probably
* EINTR).
*/
int saved_errno = get_errno();
board_autoled_on(LED_SIGNAL);
sinfo("rtcb=%p sigdeliver=%p sigpendactionq.head=%p\n",
@ -92,7 +85,6 @@ void up_sigdeliver(void)
sinfo("Resuming\n");
up_irq_save();
set_errno(saved_errno);
/* Modify the saved return state with the actual saved values in the
* TCB. This depends on the fact that nested signal handling is

View File

@ -59,13 +59,6 @@ void riscv_sigdeliver(void)
struct tcb_s *rtcb = this_task();
uint32_t regs[XCPTCONTEXT_REGS];
/* Save the errno. This must be preserved throughout the signal handling
* so that the user code final gets the correct errno value (probably
* EINTR).
*/
int saved_errno = get_errno();
board_autoled_on(LED_SIGNAL);
sinfo("rtcb=%p sigdeliver=%p sigpendactionq.head=%p\n",
@ -97,7 +90,6 @@ void riscv_sigdeliver(void)
regs[REG_EPC], regs[REG_INT_CTX]);
up_irq_save();
set_errno(saved_errno);
/* Modify the saved return state with the actual saved values in the
* TCB. This depends on the fact that nested signal handling is

View File

@ -59,13 +59,6 @@ void riscv_sigdeliver(void)
struct tcb_s *rtcb = this_task();
uint64_t regs[XCPTCONTEXT_REGS];
/* Save the errno. This must be preserved throughout the signal handling
* so that the user code final gets the correct errno value (probably
* EINTR).
*/
int saved_errno = get_errno();
#ifdef CONFIG_SMP
/* In the SMP case, we must terminate the critical section while the signal
* handler executes, but we also need to restore the irqcount when the
@ -141,10 +134,6 @@ void riscv_sigdeliver(void)
up_irq_save();
#endif
/* Restore the saved errno value */
set_errno(saved_errno);
/* Modify the saved return state with the actual saved values in the
* TCB. This depends on the fact that nested signal handling is
* not supported. Therefore, these values will persist throughout the

View File

@ -66,13 +66,6 @@ void sim_sigdeliver(void)
irqstate_t flags = enter_critical_section();
#endif
/* Save the errno. This must be preserved throughout the signal handling
* so that the user code final gets the correct errno value (probably
* EINTR).
*/
int saved_errno = get_errno();
#ifdef CONFIG_SMP
/* In the SMP case, we must terminate the critical section while the signal
* handler executes, but we also need to restore the irqcount when the
@ -134,10 +127,6 @@ void sim_sigdeliver(void)
}
#endif
/* Restore the saved errno value */
set_errno(saved_errno);
/* Allows next handler to be scheduled */
rtcb->xcp.sigdeliver = NULL;

View File

@ -57,13 +57,6 @@ void up_sigdeliver(void)
struct tcb_s *rtcb = this_task();
uint32_t regs[XCPTCONTEXT_REGS];
/* Save the errno. This must be preserved throughout the signal handling
* so that the user code final gets the correct errno value (probably
* EINTR).
*/
int saved_errno = get_errno();
board_autoled_on(LED_SIGNAL);
sinfo("rtcb=%p sigdeliver=%p sigpendactionq.head=%p\n",
@ -93,7 +86,6 @@ void up_sigdeliver(void)
sinfo("Resuming\n");
up_irq_save();
set_errno(saved_errno);
/* Modify the saved return state with the actual saved values in the
* TCB. This depends on the fact that nested signal handling is

View File

@ -63,13 +63,6 @@ void up_sigdeliver(void)
regs = (uint64_t *)(((uint64_t)(regs_area) + 15) & (~(uint64_t)15));
/* Save the errno. This must be preserved throughout the signal handling
* so that the user code final gets the correct errno value (probably
* EINTR).
*/
int saved_errno = get_errno();
/* Save the real return state on the stack ASAP before any chance we went
* sleeping and break the register profile. We entered this function with
* interrupt disabled, therefore we don't have to worried being preempted
@ -109,7 +102,6 @@ void up_sigdeliver(void)
sinfo("Resuming\n");
(void)up_irq_save();
set_errno(saved_errno);
/* Modify the saved return state with the actual saved values in the
* TCB. This depends on the fact that nested signal handling is

View File

@ -56,13 +56,6 @@ void xtensa_sig_deliver(void)
struct tcb_s *rtcb = this_task();
uint32_t regs[XCPTCONTEXT_REGS];
/* Save the errno. This must be preserved throughout the signal handling
* so that the user code final gets the correct errno value (probably
* EINTR).
*/
int saved_errno = get_errno();
#ifdef CONFIG_SMP
/* In the SMP case, we must terminate the critical section while the signal
* handler executes, but we also need to restore the irqcount when the
@ -138,10 +131,6 @@ void xtensa_sig_deliver(void)
up_irq_save();
#endif
/* Restore the saved errno value */
set_errno(saved_errno);
/* Modify the saved return state with the actual saved values in the
* TCB. This depends on the fact that nested signal handling is
* not supported. Therefore, these values will persist throughout the

View File

@ -57,13 +57,6 @@ void z16_sigdeliver(void)
chipreg_t regs[XCPTCONTEXT_REGS];
FAR uint32_t *regs32 = (FAR uint32_t *)regs;
/* Save the errno. This must be preserved throughout the signal handling
* so that the user code final gets the correct errno value (probably
* EINTR).
*/
int saved_errno = get_errno();
board_autoled_on(LED_SIGNAL);
sinfo("rtcb=%p sigdeliver=%p sigpendactionq.head=%p\n",
@ -93,7 +86,6 @@ void z16_sigdeliver(void)
sinfo("Resuming\n");
up_irq_save();
set_errno(saved_errno);
/* Modify the saved return state with the actual saved values in the
* TCB. This depends on the fact that nested signal handling is

View File

@ -58,13 +58,6 @@ void z80_sigdeliver(void)
FAR struct tcb_s *rtcb = this_task();
chipreg_t regs[XCPTCONTEXT_REGS];
/* Save the errno. This must be preserved throughout the signal handling
* so that the user code final gets the correct errno value (probably
* EINTR).
*/
int saved_errno = get_errno();
board_autoled_on(LED_SIGNAL);
sinfo("rtcb=%p sigdeliver=%p sigpendactionq.head=%p\n",
@ -94,7 +87,6 @@ void z80_sigdeliver(void)
sinfo("Resuming\n");
up_irq_save();
set_errno(saved_errno);
/* Modify the saved return state with the actual saved values in the
* TCB. This depends on the fact that nested signal handling is

View File

@ -55,13 +55,6 @@ void z80_sigdeliver(void)
FAR struct tcb_s *rtcb = this_task();
chipreg_t regs[XCPTCONTEXT_REGS];
/* Save the errno. This must be preserved throughout the signal handling
* so that the user code final gets the correct errno value (probably
* EINTR).
*/
int saved_errno = get_errno();
board_autoled_on(LED_SIGNAL);
sinfo("rtcb=%p sigdeliver=%p sigpendactionq.head=%p\n",
@ -91,7 +84,6 @@ void z80_sigdeliver(void)
sinfo("Resuming\n");
up_irq_save();
set_errno(saved_errno);
/* Modify the saved return state with the actual saved values in the
* TCB. This depends on the fact that nested signal handling is

View File

@ -74,13 +74,6 @@ void z80_sigdeliver(void)
FAR struct tcb_s *rtcb = this_task();
chipreg_t regs[XCPTCONTEXT_REGS];
/* Save the errno. This must be preserved throughout the signal handling
* so that the user code final gets the correct errno value (probably
* EINTR).
*/
int saved_errno = get_errno();
board_autoled_on(LED_SIGNAL);
sinfo("rtcb=%p sigdeliver=%p sigpendactionq.head=%p\n",
@ -110,7 +103,6 @@ void z80_sigdeliver(void)
sinfo("Resuming\n");
up_irq_save();
set_errno(saved_errno);
/* Modify the saved return state with the actual saved values in the
* TCB. This depends on the fact that nested signal handling is

View File

@ -55,13 +55,6 @@ void z80_sigdeliver(void)
FAR struct tcb_s *rtcb = this_task();
chipreg_t regs[XCPTCONTEXT_REGS];
/* Save the errno. This must be preserved throughout the signal handling
* so that the user code final gets the correct errno value (probably
* EINTR).
*/
int saved_errno = get_errno();
board_autoled_on(LED_SIGNAL);
sinfo("rtcb=%p sigdeliver=%p sigpendactionq.head=%p\n",
@ -91,7 +84,6 @@ void z80_sigdeliver(void)
sinfo("Resuming\n");
up_irq_save();
set_errno(saved_errno);
/* Modify the saved return state with the actual saved values in the
* TCB. This depends on the fact that nested signal handling is

View File

@ -51,6 +51,14 @@
void nxsig_deliver(FAR struct tcb_s *stcb)
{
/* Save the errno. This must be preserved throughout the signal handling
* so that the user code final gets the correct errno value (probably
* EINTR).
*/
int saved_errno = get_errno();
int16_t saved_errcode = stcb->errcode;
FAR sigq_t *sigq;
sigset_t savesigprocmask;
sigset_t newsigprocmask;
@ -194,4 +202,9 @@ void nxsig_deliver(FAR struct tcb_s *stcb)
nxsig_release_pendingsigaction(sigq);
}
/* Restore the saved errno value */
set_errno(saved_errno);
stcb->errcode = saved_errcode;
}