include/nuttx/sched.h: Add storage for a previous signal mask. arch/: In all syscall implemenations, block all signals before dispatching a system call; resotre signal mask when the system call returnes.

This commit is contained in:
Gregory Nutt 2019-11-28 10:51:29 -06:00
parent fe49dcf622
commit 344f7bc9f6
10 changed files with 111 additions and 11 deletions

View File

@ -1,7 +1,7 @@
/****************************************************************************
* arch/arm/src/armv6-m/up_svcall.c
*
* Copyright (C) 2013-2014 Gregory Nutt. All rights reserved.
* Copyright (C) 2013-2014, 2019 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -46,6 +46,7 @@
#include <arch/irq.h>
#include <nuttx/sched.h>
#include <nuttx/signal.h>
#ifdef CONFIG_LIB_SYSCALL
# include <syscall.h>
@ -269,6 +270,11 @@ int up_svcall(int irq, FAR void *context, FAR void *arg)
*/
regs[REG_R0] = regs[REG_R2];
/* Restore the signal mask when the syscall returns */
(void)nxsig_procmask(SIG_SETMASK, &rtcb->sigoldmask, NULL);
sigemptyset(rtcb->sigoldmask);
}
break;
#endif
@ -415,6 +421,7 @@ int up_svcall(int irq, FAR void *context, FAR void *arg)
#ifdef CONFIG_LIB_SYSCALL
FAR struct tcb_s *rtcb = sched_self();
int index = rtcb->xcp.nsyscalls;
sigset_t set;
/* Verify that the SYS call number is within range */
@ -438,6 +445,11 @@ int up_svcall(int irq, FAR void *context, FAR void *arg)
/* Offset R0 to account for the reserved values */
regs[REG_R0] -= CONFIG_SYS_RESERVED;
/* Block all signals while the system call runs */
sigfillset(&set);
(void)nxsig_procmask(SIG_BLOCK, &set, &rtcb->sigoldmask);
#else
svcerr("ERROR: Bad SYS call: %d\n", regs[REG_R0]);
#endif

View File

@ -1,7 +1,7 @@
/****************************************************************************
* arch/arm/src/armv7-a/arm_syscall.c
*
* Copyright (C) 2013-2014, 2016 Gregory Nutt. All rights reserved.
* Copyright (C) 2013-2014, 2016, 2019 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -47,6 +47,7 @@
#include <arch/irq.h>
#include <nuttx/sched.h>
#include <nuttx/signal.h>
#include <nuttx/addrenv.h>
#include "arm.h"
@ -219,6 +220,11 @@ uint32_t *arm_syscall(uint32_t *regs)
/* Save the new SYSCALL nesting level */
rtcb->xcp.nsyscalls = index;
/* Restore the signal mask when the syscall returns */
(void)nxsig_procmask(SIG_SETMASK, &rtcb->sigoldmask, NULL);
sigemptyset(rtcb->sigoldmask);
}
break;
@ -424,6 +430,7 @@ uint32_t *arm_syscall(uint32_t *regs)
#ifdef CONFIG_LIB_SYSCALL
FAR struct tcb_s *rtcb = sched_self();
int index = rtcb->xcp.nsyscalls;
sigset_t set;
/* Verify that the SYS call number is within range */
@ -450,6 +457,11 @@ uint32_t *arm_syscall(uint32_t *regs)
/* Offset R0 to account for the reserved values */
regs[REG_R0] -= CONFIG_SYS_RESERVED;
/* Block all signals while the system call runs */
sigfillset(&set);
(void)nxsig_procmask(SIG_BLOCK, &set, &rtcb->sigoldmask);
#else
svcerr("ERROR: Bad SYS call: %d\n", regs[REG_R0]);
#endif
@ -465,6 +477,7 @@ uint32_t *arm_syscall(uint32_t *regs)
regs[REG_SP] = (uint32_t)rtcb->xcp.kstack + ARCH_KERNEL_STACKSIZE;
}
#endif
/* Save the new SYSCALL nesting level */
rtcb->xcp.nsyscalls = index + 1;

View File

@ -1,7 +1,7 @@
/****************************************************************************
* arch/arm/src/armv7-m/up_svcall.c
*
* Copyright (C) 2009, 2011-2015 Gregory Nutt. All rights reserved.
* Copyright (C) 2009, 2011-2015, 2019 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -46,6 +46,7 @@
#include <arch/irq.h>
#include <nuttx/sched.h>
#include <nuttx/signal.h>
#include <nuttx/userspace.h>
#ifdef CONFIG_LIB_SYSCALL
@ -269,6 +270,11 @@ int up_svcall(int irq, FAR void *context, FAR void *arg)
*/
regs[REG_R0] = regs[REG_R2];
/* Restore the signal mask when the syscall returns */
(void)nxsig_procmask(SIG_SETMASK, &rtcb->sigoldmask, NULL);
sigemptyset(rtcb->sigoldmask);
}
break;
#endif
@ -415,6 +421,7 @@ int up_svcall(int irq, FAR void *context, FAR void *arg)
#ifdef CONFIG_LIB_SYSCALL
FAR struct tcb_s *rtcb = sched_self();
int index = rtcb->xcp.nsyscalls;
sigset_t set;
/* Verify that the SYS call number is within range */
@ -438,6 +445,11 @@ int up_svcall(int irq, FAR void *context, FAR void *arg)
/* Offset R0 to account for the reserved values */
regs[REG_R0] -= CONFIG_SYS_RESERVED;
/* Block all signals while the system call runs */
sigfillset(&set);
(void)nxsig_procmask(SIG_BLOCK, &set, &rtcb->sigoldmask);
#else
svcerr("ERROR: Bad SYS call: %d\n", regs[REG_R0]);
#endif

View File

@ -1,7 +1,7 @@
/****************************************************************************
* arch/arm/src/armv7-r/arm_syscall.c
*
* Copyright (C) 2015 Gregory Nutt. All rights reserved.
* Copyright (C) 2015, 2019 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -47,6 +47,7 @@
#include <arch/irq.h>
#include <nuttx/sched.h>
#include <nuttx/signal.h>
#include "arm.h"
#include "svcall.h"
@ -217,6 +218,11 @@ uint32_t *arm_syscall(uint32_t *regs)
/* Save the new SYSCALL nesting level */
rtcb->xcp.nsyscalls = index;
/* Restore the signal mask when the syscall returns */
(void)nxsig_procmask(SIG_SETMASK, &rtcb->sigoldmask, NULL);
sigemptyset(rtcb->sigoldmask);
}
break;
@ -351,7 +357,7 @@ uint32_t *arm_syscall(uint32_t *regs)
regs[REG_R3] = regs[REG_R4]; /* ucontext */
#ifdef CONFIG_ARCH_KERNEL_STACK
/* If we are signalling a user process, then we must be operating
/* If we are signaling a user process, then we must be operating
* on the kernel stack now. We need to switch back to the user
* stack before dispatching the signal handler to the user code.
* The existence of an allocated kernel stack is sufficient
@ -422,6 +428,7 @@ uint32_t *arm_syscall(uint32_t *regs)
#ifdef CONFIG_LIB_SYSCALL
FAR struct tcb_s *rtcb = sched_self();
int index = rtcb->xcp.nsyscalls;
sigset_t set;
/* Verify that the SYS call number is within range */
@ -448,6 +455,11 @@ uint32_t *arm_syscall(uint32_t *regs)
/* Offset R0 to account for the reserved values */
regs[REG_R0] -= CONFIG_SYS_RESERVED;
/* Block all signals while the system call runs */
sigfillset(&set);
(void)nxsig_procmask(SIG_BLOCK, &set, &rtcb->sigoldmask);
#else
svcerr("ERROR: Bad SYS call: %d\n", regs[REG_R0]);
#endif

View File

@ -1,7 +1,7 @@
/****************************************************************************
* arch/mips/src/mips32/up_swint0.c
*
* Copyright (C) 2011-2012, 2015 Gregory Nutt. All rights reserved.
* Copyright (C) 2011-2012, 2015, 2019 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -46,6 +46,7 @@
#include <debug.h>
#include <nuttx/sched.h>
#include <nuttx/signal.h>
#include <arch/irq.h>
#include <arch/mips32/cp0.h>
@ -225,6 +226,11 @@ int up_swint0(int irq, FAR void *context, FAR void *arg)
g_current_regs[REG_EPC] = rtcb->xcp.syscall[index].sysreturn;
#error "Missing logic -- need to restore the original mode"
rtcb->xcp.nsyscalls = index;
/* Restore the signal mask when the syscall returns */
(void)nxsig_procmask(SIG_SETMASK, &rtcb->sigoldmask, NULL);
sigemptyset(rtcb->sigoldmask);
}
break;
#endif
@ -239,6 +245,7 @@ int up_swint0(int irq, FAR void *context, FAR void *arg)
#ifdef CONFIG_BUILD_KERNEL
FAR struct tcb_s *rtcb = sched_self();
int index = rtcb->xcp.nsyscalls;
sigset_t set;
/* Verify that the SYS call number is within range */
@ -262,6 +269,11 @@ int up_swint0(int irq, FAR void *context, FAR void *arg)
/* Offset R0 to account for the reserved values */
g_current_regs[REG_R0] -= CONFIG_SYS_RESERVED;
/* Block all signals while the system call runs */
sigfillset(&set);
(void)nxsig_procmask(SIG_BLOCK, &set, &rtcb->sigoldmask);
#else
svcerr("ERROR: Bad SYS call: %d\n", regs[REG_A0]);
#endif

View File

@ -1,7 +1,7 @@
/****************************************************************************
* arch/misoc/src/lm32/lm32_swint.c
*
* Copyright (C) 2016 Gregory Nutt. All rights reserved.
* Copyright (C) 2016. 2019 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
* Ramtin Amin <keytwo@gmail.com>
*
@ -47,6 +47,7 @@
#include <debug.h>
#include <nuttx/sched.h>
#include <nuttx/signal.h>
#include <arch/irq.h>
#include "lm32.h"
@ -226,6 +227,11 @@ int lm32_swint(int irq, FAR void *context, FAR void *arg)
g_current_regs[REG_EPC] = rtcb->xcp.syscall[index].sysreturn;
#error "Missing logic -- need to restore the original mode"
rtcb->xcp.nsyscalls = index;
/* Restore the signal mask when the syscall returns */
(void)nxsig_procmask(SIG_SETMASK, &rtcb->sigoldmask, NULL);
sigemptyset(rtcb->sigoldmask);
}
break;
#endif
@ -240,6 +246,7 @@ int lm32_swint(int irq, FAR void *context, FAR void *arg)
#ifdef CONFIG_BUILD_KERNEL
FAR struct tcb_s *rtcb = sched_self();
int index = rtcb->xcp.nsyscalls;
sigset_t set;
/* Verify that the SYS call number is within range */
@ -263,6 +270,11 @@ int lm32_swint(int irq, FAR void *context, FAR void *arg)
/* Offset R0 to account for the reserved values */
g_current_regs[REG_A0] -= CONFIG_SYS_RESERVED;
/* Block all signals while the system call runs */
sigfillset(&set);
(void)nxsig_procmask(SIG_BLOCK, &set, &rtcb->sigoldmask);
#else
svcerr("ERROR: Bad SYS call: %d\n", regs[REG_A0]);
#endif

View File

@ -47,6 +47,7 @@
#include <debug.h>
#include <nuttx/sched.h>
#include <nuttx/signal.h>
#include <arch/irq.h>
#include "minerva.h"
@ -213,6 +214,11 @@ int minerva_swint(int irq, FAR void *context, FAR void *arg)
g_current_regs[REG_CSR_MEPC] = rtcb->xcp.syscall[index].sysreturn;
#error "Missing logic -- need to restore the original mode"
rtcb->xcp.nsyscalls = index;
/* Restore the signal mask when the syscall returns */
(void)nxsig_procmask(SIG_SETMASK, &rtcb->sigoldmask, NULL);
sigemptyset(rtcb->sigoldmask);
}
break;
#endif
@ -227,6 +233,7 @@ int minerva_swint(int irq, FAR void *context, FAR void *arg)
#ifdef CONFIG_BUILD_KERNEL
FAR struct tcb_s *rtcb = sched_self();
int index = rtcb->xcp.nsyscalls;
sigset_t set;
/* Verify that the SYS call number is within range */
@ -251,6 +258,11 @@ int minerva_swint(int irq, FAR void *context, FAR void *arg)
/* Offset R0 to account for the reserved values */
g_current_regs[REG_A0] -= CONFIG_SYS_RESERVED;
/* Block all signals while the system call runs */
sigfillset(&set);
(void)nxsig_procmask(SIG_BLOCK, &set, &rtcb->sigoldmask);
#else
svcerr("ERROR: Bad SYS call: %d\n", regs[REG_A0]);
#endif

View File

@ -1,7 +1,7 @@
/****************************************************************************
* arch/riscv/src/rv32im/up_swint.c
*
* Copyright (C) 2011-2012, 2015 Gregory Nutt. All rights reserved.
* Copyright (C) 2011-2012, 2015, 2019 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -46,6 +46,7 @@
#include <debug.h>
#include <nuttx/sched.h>
#include <nuttx/signal.h>
#include <arch/irq.h>
@ -223,6 +224,11 @@ int up_swint(int irq, FAR void *context, FAR void *arg)
g_current_regs[REG_EPC] = rtcb->xcp.syscall[index].sysreturn;
#error "Missing logic -- need to restore the original mode"
rtcb->xcp.nsyscalls = index;
/* Restore the signal mask when the syscall returns */
(void)nxsig_procmask(SIG_SETMASK, &rtcb->sigoldmask, NULL);
sigemptyset(rtcb->sigoldmask);
}
break;
#endif
@ -237,6 +243,7 @@ int up_swint(int irq, FAR void *context, FAR void *arg)
#ifdef CONFIG_BUILD_KERNEL
FAR struct tcb_s *rtcb = sched_self();
int index = rtcb->xcp.nsyscalls;
sigset_t set;
/* Verify that the SYS call number is within range */
@ -262,6 +269,11 @@ int up_swint(int irq, FAR void *context, FAR void *arg)
g_current_regs[REG_A0] -= CONFIG_SYS_RESERVED;
#else
svcerr("ERROR: Bad SYS call: %d\n", regs[REG_A0]);
/* Block all signals while the system call runs */
sigfillset(&set);
(void)nxsig_procmask(SIG_BLOCK, &set, &rtcb->sigoldmask);
#endif
}
break;

View File

@ -675,11 +675,14 @@ struct tcb_s
/* POSIX Semaphore Control Fields *********************************************/
sem_t *waitsem; /* Semaphore ID waiting on */
FAR sem_t *waitsem; /* Semaphore ID waiting on */
/* POSIX Signal Control Fields ************************************************/
sigset_t sigprocmask; /* Signals that are blocked */
#ifdef CONFIG_LIB_SYSCALL
sigset_t sigoldmask; /* Signals previously blocked */
#endif
sigset_t sigwaitmask; /* Waiting for pending signals */
sq_queue_t sigpendactionq; /* List of pending signal actions */
sq_queue_t sigpostedq; /* List of posted signals */

View File

@ -127,8 +127,8 @@ static void netlink_notify_waiters(FAR struct netlink_conn_s *conn)
int i;
/* Notify every pending thread. Lock the scheduler while we do this so
* there there is no thrashing: All waiters will be restarted, but only
* the highest priority waiter will get to run and will receive the
* that there is no thrashing: All waiters will be restarted, but only
* the highest priority waiter will get to run and it will receive the
* response.
*/