2013-02-05 20:50:37 +01:00
|
|
|
/****************************************************************************
|
2014-08-08 20:55:02 +02:00
|
|
|
* sched/signal/sig_dispatch.c
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2016-02-14 15:17:46 +01:00
|
|
|
* Copyright (C) 2007, 2009, 2011, 2016 Gregory Nutt. All rights reserved.
|
2011-12-26 17:24:43 +01:00
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
2009-12-14 19:39:29 +01:00
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
2007-02-18 00:21:28 +01:00
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
2013-02-05 20:50:37 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-02-05 20:50:37 +01:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Included Files
|
2013-02-05 20:50:37 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-11-07 21:55:25 +01:00
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2007-02-21 22:55:16 +01:00
|
|
|
#include <string.h>
|
2007-02-18 00:21:28 +01:00
|
|
|
#include <signal.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sched.h>
|
2011-07-20 15:19:07 +02:00
|
|
|
#include <errno.h>
|
2007-02-18 00:21:28 +01:00
|
|
|
#include <debug.h>
|
2011-07-20 15:19:07 +02:00
|
|
|
|
2016-02-14 15:17:46 +01:00
|
|
|
#include <nuttx/irq.h>
|
2007-02-18 00:21:28 +01:00
|
|
|
#include <nuttx/arch.h>
|
2008-11-07 21:55:25 +01:00
|
|
|
|
2014-08-09 01:53:55 +02:00
|
|
|
#include "sched/sched.h"
|
2014-08-08 22:06:42 +02:00
|
|
|
#include "group/group.h"
|
2014-08-08 21:53:29 +02:00
|
|
|
#include "semaphore/semaphore.h"
|
2014-08-08 20:44:44 +02:00
|
|
|
#include "signal/signal.h"
|
2014-08-08 20:31:23 +02:00
|
|
|
#include "mqueue/mqueue.h"
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-02-05 20:50:37 +01:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Private Functions
|
2013-02-05 20:50:37 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-02-05 20:50:37 +01:00
|
|
|
/****************************************************************************
|
2012-07-14 21:30:31 +02:00
|
|
|
* Name: sig_queueaction
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Queue a signal action for delivery to a task.
|
|
|
|
*
|
2013-02-05 20:50:37 +01:00
|
|
|
* Returned Value:
|
|
|
|
* Returns 0 (OK) on success or a negated errno value on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-02-04 19:46:28 +01:00
|
|
|
static int sig_queueaction(FAR struct tcb_s *stcb, siginfo_t *info)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2007-02-27 22:17:21 +01:00
|
|
|
FAR sigactq_t *sigact;
|
|
|
|
FAR sigq_t *sigq;
|
2016-02-14 15:17:46 +01:00
|
|
|
irqstate_t flags;
|
2007-02-27 22:17:21 +01:00
|
|
|
int ret = OK;
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
sched_lock();
|
2016-02-18 16:21:43 +01:00
|
|
|
DEBUGASSERT(stcb != NULL && stcb->group != NULL);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2016-02-18 15:34:11 +01:00
|
|
|
/* Find the group sigaction associated with this signal */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2016-02-18 16:21:43 +01:00
|
|
|
sigact = sig_findaction(stcb->group, info->si_signo);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
/* Check if a valid signal handler is available and if the signal is
|
|
|
|
* unblocked. NOTE: There is no default action.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ((sigact) && (sigact->act.sa_u._sa_sigaction))
|
|
|
|
{
|
2013-02-05 20:50:37 +01:00
|
|
|
/* Allocate a new element for the signal queue. NOTE:
|
|
|
|
* sig_allocatependingsigaction will force a system crash if it is
|
|
|
|
* unable to allocate memory for the signal data */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
sigq = sig_allocatependingsigaction();
|
2013-02-05 20:50:37 +01:00
|
|
|
if (!sigq)
|
|
|
|
{
|
|
|
|
ret = -ENOMEM;
|
|
|
|
}
|
2007-02-18 00:21:28 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Populate the new signal queue element */
|
|
|
|
|
2015-10-08 03:59:14 +02:00
|
|
|
sigq->action.sighandler = sigact->act.sa_u._sa_sigaction;
|
|
|
|
sigq->mask = sigact->act.sa_mask;
|
|
|
|
memcpy(&sigq->info, info, sizeof(siginfo_t));
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2015-10-08 03:59:14 +02:00
|
|
|
/* Put it at the end of the pending signals list */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2016-02-14 15:17:46 +01:00
|
|
|
flags = enter_critical_section();
|
2015-10-08 03:59:14 +02:00
|
|
|
sq_addlast((FAR sq_entry_t *)sigq, &(stcb->sigpendactionq));
|
2016-02-14 15:17:46 +01:00
|
|
|
leave_critical_section(flags);
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sched_unlock();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-02-05 20:50:37 +01:00
|
|
|
/****************************************************************************
|
2012-07-14 21:30:31 +02:00
|
|
|
* Name: sig_allocatependingsignal
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Allocate a pending signal list entry
|
|
|
|
*
|
2013-02-05 20:50:37 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-02-27 22:17:21 +01:00
|
|
|
static FAR sigpendq_t *sig_allocatependingsignal(void)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2007-02-27 22:17:21 +01:00
|
|
|
FAR sigpendq_t *sigpend;
|
2016-02-14 15:17:46 +01:00
|
|
|
irqstate_t flags;
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
/* Check if we were called from an interrupt handler. */
|
|
|
|
|
|
|
|
if (up_interrupt_context())
|
|
|
|
{
|
|
|
|
/* Try to get the pending signal structure from the free list */
|
|
|
|
|
2015-10-08 03:59:14 +02:00
|
|
|
sigpend = (FAR sigpendq_t *)sq_remfirst(&g_sigpendingsignal);
|
2011-08-07 14:58:54 +02:00
|
|
|
if (!sigpend)
|
|
|
|
{
|
|
|
|
/* If no pending signal structure is available in the free list,
|
|
|
|
* then try the special list of structures reserved for
|
|
|
|
* interrupt handlers
|
|
|
|
*/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2015-10-08 03:59:14 +02:00
|
|
|
sigpend = (FAR sigpendq_t *)sq_remfirst(&g_sigpendingirqsignal);
|
2011-08-07 14:58:54 +02:00
|
|
|
}
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If we were not called from an interrupt handler, then we are
|
2015-12-11 17:06:40 +01:00
|
|
|
* free to allocate pending action structures if necessary.
|
|
|
|
*/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Try to get the pending signal structure from the free list */
|
|
|
|
|
2016-02-14 15:17:46 +01:00
|
|
|
flags = enter_critical_section();
|
2015-10-08 03:59:14 +02:00
|
|
|
sigpend = (FAR sigpendq_t *)sq_remfirst(&g_sigpendingsignal);
|
2016-02-14 15:17:46 +01:00
|
|
|
leave_critical_section(flags);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
/* Check if we got one. */
|
|
|
|
|
|
|
|
if (!sigpend)
|
|
|
|
{
|
2007-02-27 22:17:21 +01:00
|
|
|
/* No... Allocate the pending signal */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
if (!sigpend)
|
|
|
|
{
|
2014-09-01 01:26:36 +02:00
|
|
|
sigpend = (FAR sigpendq_t *)kmm_malloc((sizeof (sigpendq_t)));
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if we got an allocated message */
|
|
|
|
|
|
|
|
if (sigpend)
|
|
|
|
{
|
|
|
|
sigpend->type = SIG_ALLOC_DYN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return sigpend;
|
|
|
|
}
|
|
|
|
|
2013-02-05 20:50:37 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: sig_findpendingsignal
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Find a specified element in the pending signal list
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static FAR sigpendq_t *sig_findpendingsignal(FAR struct task_group_s *group,
|
|
|
|
int signo)
|
|
|
|
{
|
|
|
|
FAR sigpendq_t *sigpend = NULL;
|
2016-02-14 15:17:46 +01:00
|
|
|
irqstate_t flags;
|
2013-02-05 20:50:37 +01:00
|
|
|
|
2016-02-18 16:21:43 +01:00
|
|
|
DEBUGASSERT(group != NULL);
|
2013-02-05 20:50:37 +01:00
|
|
|
|
|
|
|
/* Pending sigals can be added from interrupt level. */
|
|
|
|
|
2016-02-14 15:17:46 +01:00
|
|
|
flags = enter_critical_section();
|
2013-02-05 20:50:37 +01:00
|
|
|
|
|
|
|
/* Seach the list for a sigpendion on this signal */
|
|
|
|
|
2016-02-18 15:34:11 +01:00
|
|
|
for (sigpend = (FAR sigpendq_t *)group->tg_sigpendingq.head;
|
2014-04-12 21:28:22 +02:00
|
|
|
(sigpend && sigpend->info.si_signo != signo);
|
|
|
|
sigpend = sigpend->flink);
|
2013-02-05 20:50:37 +01:00
|
|
|
|
2016-02-14 15:17:46 +01:00
|
|
|
leave_critical_section(flags);
|
2013-02-05 20:50:37 +01:00
|
|
|
return sigpend;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2012-07-14 21:30:31 +02:00
|
|
|
* Name: sig_addpendingsignal
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2012-07-14 21:30:31 +02:00
|
|
|
* Add the specified signal to the signal pending list. NOTE: This
|
|
|
|
* function will queue only one entry for each pending signal. This
|
|
|
|
* was done intentionally so that a run-away sender cannot consume
|
|
|
|
* all of memory.
|
|
|
|
*
|
2013-02-05 20:50:37 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-02-04 19:46:28 +01:00
|
|
|
static FAR sigpendq_t *sig_addpendingsignal(FAR struct tcb_s *stcb,
|
2013-02-05 20:50:37 +01:00
|
|
|
FAR siginfo_t *info)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2016-02-18 16:21:43 +01:00
|
|
|
FAR struct task_group_s *group;
|
2007-02-27 22:17:21 +01:00
|
|
|
FAR sigpendq_t *sigpend;
|
2016-02-14 15:17:46 +01:00
|
|
|
irqstate_t flags;
|
2013-02-05 20:50:37 +01:00
|
|
|
|
2016-02-18 16:21:43 +01:00
|
|
|
DEBUGASSERT(stcb != NULL && stcb->group != NULL);
|
|
|
|
group = stcb->group;
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2016-02-18 16:21:43 +01:00
|
|
|
/* Check if the signal is already pending for the group */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-02-05 20:50:37 +01:00
|
|
|
sigpend = sig_findpendingsignal(group, info->si_signo);
|
2007-02-18 00:21:28 +01:00
|
|
|
if (sigpend)
|
|
|
|
{
|
|
|
|
/* The signal is already pending... retain only one copy */
|
|
|
|
|
2007-02-21 22:55:16 +01:00
|
|
|
memcpy(&sigpend->info, info, sizeof(siginfo_t));
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
|
|
|
|
2016-02-18 16:21:43 +01:00
|
|
|
/* No... There is nothing pending in the group for this signo */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Allocate a new pending signal entry */
|
|
|
|
|
|
|
|
sigpend = sig_allocatependingsignal();
|
|
|
|
if (sigpend)
|
|
|
|
{
|
|
|
|
/* Put the signal information into the allocated structure */
|
|
|
|
|
2007-02-21 22:55:16 +01:00
|
|
|
memcpy(&sigpend->info, info, sizeof(siginfo_t));
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2016-02-18 16:21:43 +01:00
|
|
|
/* Add the structure to the group pending signal list */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2016-02-14 15:17:46 +01:00
|
|
|
flags = enter_critical_section();
|
2016-02-18 15:34:11 +01:00
|
|
|
sq_addlast((FAR sq_entry_t *)sigpend, &group->tg_sigpendingq);
|
2016-02-14 15:17:46 +01:00
|
|
|
leave_critical_section(flags);
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return sigpend;
|
|
|
|
}
|
|
|
|
|
2013-02-05 20:50:37 +01:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Public Functions
|
2013-02-05 20:50:37 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-02-05 20:50:37 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: sig_tcbdispatch
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2012-07-14 21:30:31 +02:00
|
|
|
* All signals received the task (whatever the source) go through this
|
|
|
|
* function to be processed. This function is responsible for:
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
|
|
|
* - Determining if the signal is blocked.
|
|
|
|
* - Queuing and dispatching signal actions
|
|
|
|
* - Unblocking tasks that are waiting for signals
|
|
|
|
* - Queuing pending signals.
|
|
|
|
*
|
2013-02-05 20:50:37 +01:00
|
|
|
* This function will deliver the signal to the task associated with
|
|
|
|
* the specified TCB. This function should *not* typically be used
|
|
|
|
* to dispatch signals since it will *not* follow the group signal
|
|
|
|
* deliver algorithms.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Returns 0 (OK) on success or a negated errno value on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-02-05 20:50:37 +01:00
|
|
|
int sig_tcbdispatch(FAR struct tcb_s *stcb, siginfo_t *info)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2016-02-14 15:17:46 +01:00
|
|
|
irqstate_t flags;
|
2013-02-05 20:50:37 +01:00
|
|
|
int ret = OK;
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2016-06-12 00:42:42 +02:00
|
|
|
sinfo("TCB=0x%08x signo=%d code=%d value=%d mask=%08x\n",
|
|
|
|
stcb, info->si_signo, info->si_code,
|
|
|
|
info->si_value.sival_int, stcb->sigprocmask);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2016-02-18 21:56:48 +01:00
|
|
|
DEBUGASSERT(stcb != NULL && info != NULL);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-02-05 20:50:37 +01:00
|
|
|
/************************* MASKED SIGNAL HANDLING ************************/
|
|
|
|
|
|
|
|
/* Check if the signal is masked -- if it is, it will be added to the list
|
|
|
|
* of pending signals.
|
|
|
|
*/
|
2007-03-19 17:38:47 +01:00
|
|
|
|
2013-02-05 20:50:37 +01:00
|
|
|
if (sigismember(&stcb->sigprocmask, info->si_signo))
|
|
|
|
{
|
2017-06-14 21:42:56 +02:00
|
|
|
/* Check if the task is waiting for this pending signal. If so, then
|
|
|
|
* unblock it. This must be performed in a critical section because
|
|
|
|
* signals can be queued * from the interrupt level.
|
2007-02-18 00:21:28 +01:00
|
|
|
*/
|
|
|
|
|
2016-02-14 15:17:46 +01:00
|
|
|
flags = enter_critical_section();
|
2013-02-05 20:50:37 +01:00
|
|
|
if (stcb->task_state == TSTATE_WAIT_SIG &&
|
|
|
|
sigismember(&stcb->sigwaitmask, info->si_signo))
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2013-02-05 20:50:37 +01:00
|
|
|
memcpy(&stcb->sigunbinfo, info, sizeof(siginfo_t));
|
|
|
|
stcb->sigwaitmask = NULL_SIGNAL_SET;
|
|
|
|
up_unblock_task(stcb);
|
2016-02-14 15:17:46 +01:00
|
|
|
leave_critical_section(flags);
|
2013-02-05 20:50:37 +01:00
|
|
|
}
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-02-05 20:50:37 +01:00
|
|
|
/* Its not one we are waiting for... Add it to the list of pending
|
|
|
|
* signals.
|
|
|
|
*/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-02-05 20:50:37 +01:00
|
|
|
else
|
|
|
|
{
|
2016-02-14 15:17:46 +01:00
|
|
|
leave_critical_section(flags);
|
2013-04-25 23:19:59 +02:00
|
|
|
ASSERT(sig_addpendingsignal(stcb, info));
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
2013-02-05 20:50:37 +01:00
|
|
|
}
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-02-05 20:50:37 +01:00
|
|
|
/************************ UNMASKED SIGNAL HANDLING ***********************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-02-05 20:50:37 +01:00
|
|
|
else
|
|
|
|
{
|
2016-11-20 14:57:18 +01:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
int cpu;
|
|
|
|
#endif
|
2013-02-05 20:50:37 +01:00
|
|
|
/* Queue any sigaction's requested by this task. */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-02-05 20:50:37 +01:00
|
|
|
ret = sig_queueaction(stcb, info);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2016-11-20 14:57:18 +01:00
|
|
|
/* Deliver of the signal must be performed in a critical section */
|
|
|
|
|
|
|
|
flags = enter_critical_section();
|
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
/* If the thread is running on another CPU, then pause that CPU. We can
|
|
|
|
* then setup the for signal delivery on the running thread. When the
|
|
|
|
* CPU is resumed, the signal handler will then execute.
|
|
|
|
*/
|
|
|
|
|
|
|
|
cpu = sched_cpu_pause(stcb);
|
|
|
|
#endif /* CONFIG_SMP */
|
|
|
|
|
2013-02-05 20:50:37 +01:00
|
|
|
/* Then schedule execution of the signal handling action on the
|
|
|
|
* recipient's thread.
|
|
|
|
*/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-02-05 20:50:37 +01:00
|
|
|
up_schedule_sigaction(stcb, sig_deliver);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2016-11-20 14:57:18 +01:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
/* Resume the paused CPU (if any) */
|
|
|
|
|
|
|
|
if (cpu >= 0)
|
|
|
|
{
|
|
|
|
/* I am not yet sure how to handle a failure here. */
|
|
|
|
|
|
|
|
DEBUGVERIFY(up_cpu_resume(cpu));
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_SMP */
|
|
|
|
|
2013-02-05 20:50:37 +01:00
|
|
|
/* Check if the task is waiting for an unmasked signal. If so, then
|
|
|
|
* unblock it. This must be performed in a critical section because
|
|
|
|
* signals can be queued from the interrupt level.
|
|
|
|
*/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-02-05 20:50:37 +01:00
|
|
|
if (stcb->task_state == TSTATE_WAIT_SIG)
|
|
|
|
{
|
|
|
|
memcpy(&stcb->sigunbinfo, info, sizeof(siginfo_t));
|
|
|
|
stcb->sigwaitmask = NULL_SIGNAL_SET;
|
|
|
|
up_unblock_task(stcb);
|
|
|
|
}
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2016-02-14 15:17:46 +01:00
|
|
|
leave_critical_section(flags);
|
2013-02-05 20:50:37 +01:00
|
|
|
|
|
|
|
/* If the task neither was waiting for the signal nor had a signal
|
|
|
|
* handler attached to the signal, then the default action is
|
|
|
|
* simply to ignore the signal
|
|
|
|
*/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-02-05 20:50:37 +01:00
|
|
|
/*********************** OTHER SIGNAL HANDLING ***********************/
|
2007-03-19 17:38:47 +01:00
|
|
|
|
2013-02-05 20:50:37 +01:00
|
|
|
/* If the task is blocked waiting for a semaphore, then that task must
|
|
|
|
* be unblocked when a signal is received.
|
|
|
|
*/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-02-05 20:50:37 +01:00
|
|
|
if (stcb->task_state == TSTATE_WAIT_SEM)
|
|
|
|
{
|
2017-10-03 20:51:15 +02:00
|
|
|
nxsem_waitirq(stcb, EINTR);
|
2013-02-05 20:50:37 +01:00
|
|
|
}
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-02-05 20:50:37 +01:00
|
|
|
/* If the task is blocked waiting on a message queue, then that task
|
|
|
|
* must be unblocked when a signal is received.
|
|
|
|
*/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-03-28 16:48:42 +02:00
|
|
|
#ifndef CONFIG_DISABLE_MQUEUE
|
2013-02-05 20:50:37 +01:00
|
|
|
if (stcb->task_state == TSTATE_WAIT_MQNOTEMPTY ||
|
|
|
|
stcb->task_state == TSTATE_WAIT_MQNOTFULL)
|
|
|
|
{
|
|
|
|
mq_waitirq(stcb, EINTR);
|
|
|
|
}
|
2007-03-28 16:48:42 +02:00
|
|
|
#endif
|
2013-02-05 20:50:37 +01:00
|
|
|
}
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2013-02-05 20:50:37 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: sig_dispatch
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This is the front-end for sig_tcbdispatch that should be typically
|
|
|
|
* be used to dispatch a signal. If HAVE_GROUP_MEMBERS is defined,
|
|
|
|
* then function will follow the group signal delivery algorthrims:
|
|
|
|
*
|
|
|
|
* This front-end does the following things before calling
|
|
|
|
* sig_tcbdispatch.
|
|
|
|
*
|
|
|
|
* With HAVE_GROUP_MEMBERS defined:
|
|
|
|
* - Get the TCB associated with the pid.
|
|
|
|
* - If the TCB was found, get the group from the TCB.
|
|
|
|
* - If the PID has already exited, lookup the group that that was
|
|
|
|
* started by this task.
|
|
|
|
* - Use the group to pick the TCB to receive the signal
|
|
|
|
* - Call sig_tcbdispatch with the TCB
|
|
|
|
*
|
|
|
|
* With HAVE_GROUP_MEMBERS *not* defined
|
|
|
|
* - Get the TCB associated with the pid.
|
|
|
|
* - Call sig_tcbdispatch with the TCB
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Returns 0 (OK) on success or a negated errno value on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int sig_dispatch(pid_t pid, FAR siginfo_t *info)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_GROUP_MEMBERS
|
|
|
|
FAR struct tcb_s *stcb;
|
|
|
|
FAR struct task_group_s *group;
|
|
|
|
|
|
|
|
/* Get the TCB associated with the pid */
|
|
|
|
|
|
|
|
stcb = sched_gettcb(pid);
|
2016-02-18 21:56:48 +01:00
|
|
|
if (stcb != NULL)
|
2013-02-05 20:50:37 +01:00
|
|
|
{
|
|
|
|
/* The task/thread associated with this PID is still active. Get its
|
|
|
|
* task group.
|
|
|
|
*/
|
|
|
|
|
|
|
|
group = stcb->group;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* The task/thread associated with this PID has exited. In the normal
|
|
|
|
* usage model, the PID should correspond to the PID of the task that
|
|
|
|
* created the task group. Try looking it up.
|
|
|
|
*/
|
|
|
|
|
|
|
|
group = group_findbypid(pid);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Did we locate the group? */
|
|
|
|
|
2016-02-18 21:56:48 +01:00
|
|
|
if (group != NULL)
|
2013-02-05 20:50:37 +01:00
|
|
|
{
|
|
|
|
/* Yes.. call group_signal() to send the signal to the correct group
|
|
|
|
* member.
|
|
|
|
*/
|
|
|
|
|
|
|
|
return group_signal(group, info);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return -ESRCH;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
FAR struct tcb_s *stcb;
|
|
|
|
|
|
|
|
/* Get the TCB associated with the pid */
|
|
|
|
|
|
|
|
stcb = sched_gettcb(pid);
|
2016-02-18 21:56:48 +01:00
|
|
|
if (stcb == NULL)
|
2013-02-05 20:50:37 +01:00
|
|
|
{
|
|
|
|
return -ESRCH;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sig_tcbdispatch(stcb, info);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|