2018-08-27 19:40:09 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* sched/signal/sig_default.c
|
|
|
|
*
|
2021-02-08 16:33:58 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2018-08-27 19:40:09 +02:00
|
|
|
*
|
2021-02-08 16:33:58 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2018-08-27 19:40:09 +02:00
|
|
|
*
|
2021-02-08 16:33:58 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2018-08-27 19:40:09 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2018-09-02 23:36:25 +02:00
|
|
|
#include <sys/wait.h>
|
2018-08-29 15:33:28 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
2018-08-27 19:40:09 +02:00
|
|
|
#include <string.h>
|
2018-08-29 15:33:28 +02:00
|
|
|
#include <pthread.h>
|
2018-08-27 19:40:09 +02:00
|
|
|
#include <signal.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include <nuttx/sched.h>
|
2021-05-14 04:03:23 +02:00
|
|
|
#include <nuttx/spinlock.h>
|
2018-08-30 18:27:18 +02:00
|
|
|
#include <nuttx/signal.h>
|
2018-08-27 19:40:09 +02:00
|
|
|
|
2018-08-29 13:49:42 +02:00
|
|
|
#include "group/group.h"
|
|
|
|
#include "sched/sched.h"
|
2019-05-17 15:39:04 +02:00
|
|
|
#include "task/task.h"
|
2018-08-27 19:40:09 +02:00
|
|
|
#include "signal/signal.h"
|
|
|
|
|
2018-08-28 20:39:03 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-10-04 13:51:14 +02:00
|
|
|
#if defined(CONFIG_SIG_SIGUSR1_ACTION) || defined(CONFIG_SIG_SIGUSR2_ACTION) || \
|
|
|
|
defined(CONFIG_SIG_SIGALRM_ACTION) || defined(CONFIG_SIG_SIGPOLL_ACTION) || \
|
2020-01-15 14:42:32 +01:00
|
|
|
defined(CONFIG_SIG_SIGKILL_ACTION) || defined(CONFIG_SIG_SIGPIPE_ACTION)
|
2019-10-04 13:51:14 +02:00
|
|
|
# define HAVE_NXSIG_ABNORMAL_TERMINANTION 1
|
|
|
|
#endif
|
|
|
|
|
2018-08-28 20:39:03 +02:00
|
|
|
/* Bit definitions for the struct nxsig_defaction_s 'flags' field */
|
|
|
|
|
|
|
|
#define SIG_FLAG_NOCATCH (1 << 0) /* Signal cannot be caught or ignored */
|
|
|
|
|
2018-08-27 23:37:43 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* This type provides the default action associated with a signal */
|
|
|
|
|
|
|
|
struct nxsig_defaction_s
|
|
|
|
{
|
|
|
|
uint8_t signo; /* Signal number. Range 1..MAX_SIGNO */
|
2018-08-28 20:39:03 +02:00
|
|
|
uint8_t flags; /* See SIG_FLAG_ definitions */
|
2018-08-27 23:37:43 +02:00
|
|
|
_sa_handler_t action; /* Default signal action */
|
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* Default actions */
|
|
|
|
|
2019-10-04 13:51:14 +02:00
|
|
|
#ifdef HAVE_NXSIG_ABNORMAL_TERMINANTION
|
2018-08-27 23:37:43 +02:00
|
|
|
static void nxsig_abnormal_termination(int signo);
|
2019-10-04 13:51:14 +02:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_SIG_SIGSTOP_ACTION
|
|
|
|
static void nxsig_null_action(int signo);
|
2018-08-30 18:27:18 +02:00
|
|
|
static void nxsig_stop_task(int signo);
|
2019-10-04 13:51:14 +02:00
|
|
|
#endif
|
2018-08-27 23:37:43 +02:00
|
|
|
|
|
|
|
/* Helpers */
|
|
|
|
|
|
|
|
static _sa_handler_t nxsig_default_action(int signo);
|
|
|
|
static void nxsig_setup_default_action(FAR struct task_group_s *group,
|
2020-03-10 05:50:49 +01:00
|
|
|
FAR const struct nxsig_defaction_s *
|
|
|
|
info);
|
2018-08-27 23:37:43 +02:00
|
|
|
|
2018-08-27 19:40:09 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-08-27 23:37:43 +02:00
|
|
|
/* NOTE: Default actions are not currently supported for very many signals.
|
|
|
|
* However, this array is set up to support an indefinite number of default
|
|
|
|
* signal actions.
|
|
|
|
*/
|
|
|
|
|
2018-08-27 19:40:09 +02:00
|
|
|
/* This table is used to make the default action for a signal to the correct
|
2018-08-27 23:37:43 +02:00
|
|
|
* signal handler. Signals whose default action is be ignored do not need
|
|
|
|
* to be in this table (e.g., SIGCHLD).
|
2018-08-27 19:40:09 +02:00
|
|
|
*/
|
|
|
|
|
2018-08-27 23:37:43 +02:00
|
|
|
static const struct nxsig_defaction_s g_defactions[] =
|
2018-08-27 19:40:09 +02:00
|
|
|
{
|
2023-02-01 10:17:43 +01:00
|
|
|
#ifdef CONFIG_SIG_SIGKILL_ACTION
|
|
|
|
{ SIGHUP, 0, nxsig_abnormal_termination },
|
|
|
|
{ SIGINT, 0, nxsig_abnormal_termination },
|
|
|
|
{ SIGQUIT, 0, nxsig_abnormal_termination },
|
|
|
|
{ SIGILL, 0, nxsig_abnormal_termination },
|
|
|
|
{ SIGTRAP, 0, nxsig_abnormal_termination },
|
|
|
|
{ SIGABRT, 0, nxsig_abnormal_termination },
|
|
|
|
{ SIGBUS, 0, nxsig_abnormal_termination },
|
|
|
|
{ SIGFPE, 0, nxsig_abnormal_termination },
|
|
|
|
{ SIGKILL, SIG_FLAG_NOCATCH, nxsig_abnormal_termination },
|
|
|
|
{ SIGSEGV, 0, nxsig_abnormal_termination },
|
|
|
|
{ SIGTERM, 0, nxsig_abnormal_termination },
|
|
|
|
{ SIGXCPU, 0, nxsig_abnormal_termination },
|
|
|
|
{ SIGXFSZ, 0, nxsig_abnormal_termination },
|
|
|
|
#endif
|
2018-08-27 23:37:43 +02:00
|
|
|
#ifdef CONFIG_SIG_SIGUSR1_ACTION
|
2023-02-01 10:17:43 +01:00
|
|
|
{ SIGUSR1, 0, nxsig_abnormal_termination },
|
2018-08-27 23:37:43 +02:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_SIG_SIGUSR2_ACTION
|
2023-02-01 10:17:43 +01:00
|
|
|
{ SIGUSR2, 0, nxsig_abnormal_termination },
|
2018-08-27 23:37:43 +02:00
|
|
|
#endif
|
2023-02-01 10:17:43 +01:00
|
|
|
#ifdef CONFIG_SIG_SIGPIPE_ACTION
|
|
|
|
{ SIGPIPE, 0, nxsig_abnormal_termination },
|
2018-08-27 19:40:09 +02:00
|
|
|
#endif
|
2023-02-01 10:17:43 +01:00
|
|
|
#ifdef CONFIG_SIG_SIGALRM_ACTION
|
|
|
|
{ SIGALRM, 0, nxsig_abnormal_termination },
|
|
|
|
{ SIGVTALRM, 0, nxsig_abnormal_termination },
|
2018-08-27 23:37:43 +02:00
|
|
|
#endif
|
2018-08-30 18:27:18 +02:00
|
|
|
#ifdef CONFIG_SIG_SIGSTOP_ACTION
|
2023-02-01 10:17:43 +01:00
|
|
|
{ SIGCONT, SIG_FLAG_NOCATCH, nxsig_null_action },
|
|
|
|
{ SIGSTOP, SIG_FLAG_NOCATCH, nxsig_stop_task },
|
|
|
|
{ SIGTSTP, 0, nxsig_stop_task },
|
|
|
|
{ SIGTTIN, 0, nxsig_stop_task },
|
|
|
|
{ SIGTTOU, 0, nxsig_stop_task },
|
2018-08-30 18:27:18 +02:00
|
|
|
#endif
|
2023-02-01 10:17:43 +01:00
|
|
|
#ifdef CONFIG_SIG_SIGPROF_ACTION
|
|
|
|
{ SIGPROF, 0, nxsig_abnormal_termination },
|
2019-10-17 19:29:39 +02:00
|
|
|
#endif
|
2023-02-01 10:17:43 +01:00
|
|
|
#ifdef CONFIG_SIG_SIGPOLL_ACTION
|
|
|
|
{ SIGPOLL, 0, nxsig_abnormal_termination },
|
2018-08-30 18:27:18 +02:00
|
|
|
#endif
|
2018-08-27 23:37:43 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#define NACTIONS (sizeof(g_defactions) / sizeof(struct nxsig_defaction_s))
|
2018-08-27 19:40:09 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* TODO: Take into account pthread-specific signal behaviors */
|
|
|
|
|
|
|
|
/* Default Actions:
|
|
|
|
*
|
|
|
|
* - Abnormal termination of the process. The process is terminated with
|
|
|
|
* all the consequences of _exit() except that the status made available
|
|
|
|
* to wait() and waitpid() indicates abnormal termination by the
|
|
|
|
* specified signal.
|
|
|
|
* - Abnormal termination of the process. Additionally with the XSI
|
|
|
|
* extension, implementation-defined abnormal termination actions, such
|
|
|
|
* as creation of a core file, may occur.
|
|
|
|
* - Ignore the signal.
|
|
|
|
* - Stop the process.
|
|
|
|
* - Continue the process, if it is stopped; otherwise, ignore the signal.
|
|
|
|
*/
|
|
|
|
|
2018-08-30 18:27:18 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxsig_null_action
|
|
|
|
*
|
|
|
|
* Description:
|
2018-09-02 21:51:52 +02:00
|
|
|
* The do-nothing default signal action handler.
|
2018-08-30 18:27:18 +02:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* Standard signal handler parameters
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-10-04 13:51:14 +02:00
|
|
|
#ifdef CONFIG_SIG_SIGSTOP_ACTION
|
2018-08-30 18:27:18 +02:00
|
|
|
static void nxsig_null_action(int signo)
|
|
|
|
{
|
|
|
|
}
|
2019-10-04 13:51:14 +02:00
|
|
|
#endif
|
2018-08-30 18:27:18 +02:00
|
|
|
|
2018-08-27 19:40:09 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxsig_abnormal_termination
|
|
|
|
*
|
|
|
|
* Description:
|
2018-08-28 06:32:57 +02:00
|
|
|
* This is the handler for the abnormal termination default action.
|
2018-08-27 19:40:09 +02:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* Standard signal handler parameters
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-10-04 13:51:14 +02:00
|
|
|
#ifdef HAVE_NXSIG_ABNORMAL_TERMINANTION
|
2018-08-27 23:37:43 +02:00
|
|
|
static void nxsig_abnormal_termination(int signo)
|
2018-08-27 19:40:09 +02:00
|
|
|
{
|
2022-12-15 00:02:44 +01:00
|
|
|
FAR struct tcb_s *rtcb = this_task();
|
2018-08-29 15:33:28 +02:00
|
|
|
|
|
|
|
/* Careful: In the multi-threaded task, the signal may be handled on a
|
|
|
|
* child pthread.
|
|
|
|
*/
|
2018-08-27 19:40:09 +02:00
|
|
|
|
2018-08-29 15:33:28 +02:00
|
|
|
#ifdef HAVE_GROUP_MEMBERS
|
2020-03-16 20:42:34 +01:00
|
|
|
/* Kill all of the children of the task. This will not kill the currently
|
2018-08-29 23:50:01 +02:00
|
|
|
* running task/pthread (this_task). It will kill the main thread of the
|
2020-03-16 20:42:34 +01:00
|
|
|
* task group if this_task is a pthread.
|
2018-08-29 15:33:28 +02:00
|
|
|
*/
|
2018-08-27 19:40:09 +02:00
|
|
|
|
2020-06-03 13:33:56 +02:00
|
|
|
group_kill_children(rtcb);
|
2018-08-27 19:40:09 +02:00
|
|
|
#endif
|
|
|
|
|
2018-08-29 15:33:28 +02:00
|
|
|
#ifndef CONFIG_DISABLE_PTHREAD
|
|
|
|
/* Check if the currently running task is actually a pthread */
|
|
|
|
|
|
|
|
if ((rtcb->flags & TCB_FLAG_TTYPE_MASK) == TCB_FLAG_TTYPE_PTHREAD)
|
|
|
|
{
|
|
|
|
/* Exit the final thread of the task group.
|
|
|
|
*
|
|
|
|
* REVISIT: This will not work if HAVE_GROUP_MEMBERS is not set.
|
|
|
|
*/
|
|
|
|
|
2022-01-25 10:22:17 +01:00
|
|
|
pthread_exit(NULL);
|
2018-08-29 15:33:28 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
2022-02-05 16:30:38 +01:00
|
|
|
UNUSED(rtcb);
|
|
|
|
|
2023-02-16 15:57:24 +01:00
|
|
|
/* Exit to terminate the task. */
|
2018-08-27 19:40:09 +02:00
|
|
|
|
2023-02-16 15:57:24 +01:00
|
|
|
_exit(EXIT_FAILURE);
|
2018-08-29 15:33:28 +02:00
|
|
|
}
|
2018-08-27 19:40:09 +02:00
|
|
|
}
|
2019-10-04 13:51:14 +02:00
|
|
|
#endif
|
2018-08-27 19:40:09 +02:00
|
|
|
|
2018-08-30 18:27:18 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxsig_stop_task
|
|
|
|
*
|
|
|
|
* Description:
|
2020-10-31 01:27:02 +01:00
|
|
|
* This is the handler for the stop default action.
|
2018-08-30 18:27:18 +02:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* Standard signal handler parameters
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-10-04 13:51:14 +02:00
|
|
|
#ifdef CONFIG_SIG_SIGSTOP_ACTION
|
2018-08-30 18:27:18 +02:00
|
|
|
static void nxsig_stop_task(int signo)
|
|
|
|
{
|
2022-12-15 00:02:44 +01:00
|
|
|
FAR struct tcb_s *rtcb = this_task();
|
2018-09-02 23:36:25 +02:00
|
|
|
#if defined(CONFIG_SCHED_WAITPID) && !defined(CONFIG_SCHED_HAVE_PARENT)
|
|
|
|
FAR struct task_group_s *group;
|
|
|
|
|
|
|
|
DEBUGASSERT(rtcb != NULL && rtcb->group != NULL);
|
|
|
|
group = rtcb->group;
|
|
|
|
#endif
|
2018-08-30 18:27:18 +02:00
|
|
|
|
|
|
|
/* Careful: In the multi-threaded task, the signal may be handled on a
|
|
|
|
* child pthread.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_GROUP_MEMBERS
|
2020-03-16 20:42:34 +01:00
|
|
|
/* Suspend all of the children of the task. This will not suspend the
|
2018-08-30 18:27:18 +02:00
|
|
|
* currently running task/pthread (this_task). It will suspend the
|
2020-03-16 20:42:34 +01:00
|
|
|
* main thread of the task group if this_task is a pthread.
|
2018-08-30 18:27:18 +02:00
|
|
|
*/
|
|
|
|
|
2020-05-16 17:06:29 +02:00
|
|
|
group_suspend_children(rtcb);
|
2018-08-30 18:27:18 +02:00
|
|
|
#endif
|
|
|
|
|
2018-09-02 23:36:25 +02:00
|
|
|
/* Lock the scheduler so this thread is not pre-empted until after we
|
2020-05-09 20:40:14 +02:00
|
|
|
* call nxsched_suspend().
|
2018-09-02 21:51:52 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
sched_lock();
|
|
|
|
|
|
|
|
#if defined(CONFIG_SCHED_WAITPID) && !defined(CONFIG_SCHED_HAVE_PARENT)
|
|
|
|
/* Notify via waitpid if any parent is waiting for this task to EXIT
|
|
|
|
* or STOP. This action is only performed if WUNTRACED is set in the
|
|
|
|
* waitpid flags.
|
|
|
|
*/
|
|
|
|
|
2018-09-02 23:36:25 +02:00
|
|
|
if ((group->tg_waitflags & WUNTRACED) != 0)
|
2018-09-02 21:51:52 +02:00
|
|
|
{
|
|
|
|
/* Return zero for exit status (we are not exiting, however) */
|
|
|
|
|
|
|
|
if (group->tg_statloc != NULL)
|
|
|
|
{
|
|
|
|
*group->tg_statloc = 0;
|
|
|
|
group->tg_statloc = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* tg_waitflags == 0 means that the flags are available to another
|
|
|
|
* caller of waitpid().
|
|
|
|
*/
|
|
|
|
|
|
|
|
group->tg_waitflags = 0;
|
|
|
|
|
2020-10-31 00:32:37 +01:00
|
|
|
/* Wakeup any tasks waiting for this task to exit or stop. */
|
2018-09-02 21:51:52 +02:00
|
|
|
|
|
|
|
while (group->tg_exitsem.semcount < 0)
|
|
|
|
{
|
|
|
|
/* Wake up the thread */
|
|
|
|
|
|
|
|
nxsem_post(&group->tg_exitsem);
|
2019-06-30 18:35:10 +02:00
|
|
|
}
|
2018-09-02 21:51:52 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Then, finally, suspend this the final thread of the task group */
|
2018-08-30 18:27:18 +02:00
|
|
|
|
2020-05-09 20:40:14 +02:00
|
|
|
nxsched_suspend(rtcb);
|
2018-09-02 21:51:52 +02:00
|
|
|
sched_unlock();
|
2018-08-30 18:27:18 +02:00
|
|
|
}
|
2019-10-04 13:51:14 +02:00
|
|
|
#endif
|
2018-08-30 18:27:18 +02:00
|
|
|
|
2018-08-27 19:40:09 +02:00
|
|
|
/****************************************************************************
|
2018-08-27 21:13:23 +02:00
|
|
|
* Name: nxsig_default_action
|
2018-08-27 19:40:09 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2018-08-27 21:13:23 +02:00
|
|
|
* Look up the default action associated with this signal
|
2018-08-27 19:40:09 +02:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
2018-08-27 21:13:23 +02:00
|
|
|
* signo - The signal number to use in the query
|
2018-08-27 19:40:09 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
2018-08-27 21:13:23 +02:00
|
|
|
* The default handler associated with this signal
|
2018-08-27 19:40:09 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-08-27 23:37:43 +02:00
|
|
|
static _sa_handler_t nxsig_default_action(int signo)
|
2018-08-27 19:40:09 +02:00
|
|
|
{
|
2018-08-27 23:37:43 +02:00
|
|
|
int i;
|
2018-08-27 19:40:09 +02:00
|
|
|
|
2018-08-27 23:37:43 +02:00
|
|
|
/* Search the default action table for the entry associated with this
|
|
|
|
* signal.
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (i = 0; i < NACTIONS; i++)
|
|
|
|
{
|
|
|
|
if (g_defactions[i].signo == signo)
|
|
|
|
{
|
|
|
|
return g_defactions[i].action;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No default action */
|
|
|
|
|
|
|
|
return SIG_IGN;
|
2018-08-27 19:40:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxsig_setup_default_action
|
|
|
|
*
|
|
|
|
* Description:
|
2018-08-28 06:32:57 +02:00
|
|
|
* Setup the default action for a signal.
|
|
|
|
*
|
|
|
|
* This function is called early in task setup, prior to the creation of
|
|
|
|
* any pthreads so we should have exclusive access to the group structure.
|
2018-08-27 19:40:09 +02:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
2018-08-27 21:13:23 +02:00
|
|
|
* group - The group that the task belongs in.
|
|
|
|
* action - The new default signal action
|
|
|
|
* signo - The signal that will produce this default action
|
2018-08-27 19:40:09 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-08-27 21:13:23 +02:00
|
|
|
static void nxsig_setup_default_action(FAR struct task_group_s *group,
|
2020-03-10 05:50:49 +01:00
|
|
|
FAR const struct nxsig_defaction_s *
|
|
|
|
info)
|
2018-08-27 19:40:09 +02:00
|
|
|
{
|
2018-08-27 21:13:23 +02:00
|
|
|
/* Get the address of the handler for this signals default action. */
|
2018-08-27 19:40:09 +02:00
|
|
|
|
2018-08-27 23:37:43 +02:00
|
|
|
if (info->action != SIG_IGN)
|
2018-08-27 21:13:23 +02:00
|
|
|
{
|
2018-08-27 23:37:43 +02:00
|
|
|
struct sigaction sa;
|
|
|
|
|
|
|
|
/* Attach the signal handler.
|
|
|
|
*
|
2018-08-30 18:27:18 +02:00
|
|
|
* NOTE: nxsig_action will call nxsig_default(tcb, action, false).
|
|
|
|
* Don't be surprised.
|
2018-08-27 23:37:43 +02:00
|
|
|
*/
|
2018-08-27 19:40:09 +02:00
|
|
|
|
2018-08-27 21:13:23 +02:00
|
|
|
memset(&sa, 0, sizeof(sa));
|
2018-08-27 23:37:43 +02:00
|
|
|
sa.sa_handler = info->action;
|
|
|
|
sa.sa_flags = SA_SIGINFO;
|
2020-01-02 17:49:34 +01:00
|
|
|
nxsig_action(info->signo, &sa, NULL, true);
|
2018-08-27 19:40:09 +02:00
|
|
|
|
2018-08-27 21:13:23 +02:00
|
|
|
/* Indicate that the default signal handler has been attached */
|
2018-08-27 19:40:09 +02:00
|
|
|
|
2020-04-29 18:53:36 +02:00
|
|
|
nxsig_addset(&group->tg_sigdefault, (int)info->signo);
|
2018-08-27 21:13:23 +02:00
|
|
|
}
|
2018-08-27 19:40:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxsig_isdefault
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Return true if the specified signal is set to the default action.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* tcb - Identifies the thread associated with the default handler
|
|
|
|
* signo - The signal number to be queried
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero (OK) is returned on success; A negated errno value is returned
|
|
|
|
* on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
bool nxsig_isdefault(FAR struct tcb_s *tcb, int signo)
|
|
|
|
{
|
|
|
|
FAR struct task_group_s *group;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
DEBUGASSERT(tcb != NULL && tcb->group != NULL && GOOD_SIGNO(signo));
|
|
|
|
group = tcb->group;
|
|
|
|
|
|
|
|
/* Return true if the signo is marked as using the default action. Return
|
|
|
|
* false in all other cases.
|
|
|
|
*/
|
|
|
|
|
2020-04-29 18:53:36 +02:00
|
|
|
ret = nxsig_ismember(&group->tg_sigdefault, signo);
|
2018-08-27 19:40:09 +02:00
|
|
|
return ret < 0 ? false : (bool)ret;
|
|
|
|
}
|
|
|
|
|
2018-08-28 20:39:03 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxsig_iscatchable
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Return true if the specified signal can be caught or ignored.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* signo - The signal number to be queried
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero (OK) is returned on success; A negated errno value is returned
|
|
|
|
* on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
bool nxsig_iscatchable(int signo)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Search the default action table for the entry associated with this
|
|
|
|
* signal.
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (i = 0; i < NACTIONS; i++)
|
|
|
|
{
|
|
|
|
if (g_defactions[i].signo == signo)
|
|
|
|
{
|
|
|
|
return (g_defactions[i].flags & SIG_FLAG_NOCATCH) == 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If it is not in the table, then it is catchable */
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-08-27 19:40:09 +02:00
|
|
|
/****************************************************************************
|
2018-08-27 21:13:23 +02:00
|
|
|
* Name: nxsig_default
|
2018-08-27 19:40:09 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2018-08-27 21:13:23 +02:00
|
|
|
* If 'defaction' is true, then return the default signal handler action
|
2020-02-23 09:50:23 +01:00
|
|
|
* for the specified signal and mark that the default signal handler is
|
2018-08-27 21:13:23 +02:00
|
|
|
* in place (it is not yet).
|
|
|
|
*
|
|
|
|
* If 'defaction' is false, then mark that the default signal handler is
|
|
|
|
* NOT in place and return SIG_IGN.
|
|
|
|
*
|
|
|
|
* This function is called form sigaction() to handle actions = SIG_DFL.
|
2018-08-27 19:40:09 +02:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* tcb - Identifies the thread associated with the default handler
|
|
|
|
* signo - The signal number whose behavior will be modified.
|
|
|
|
* defaction - True: the default action is in place
|
|
|
|
*
|
|
|
|
* Returned Value:
|
2018-08-27 21:13:23 +02:00
|
|
|
* The address of the default signal action handler is returne on success.
|
|
|
|
* SIG_IGN is returned if there is no default action.
|
2018-08-27 19:40:09 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-06-30 18:35:10 +02:00
|
|
|
_sa_handler_t nxsig_default(FAR struct tcb_s *tcb, int signo, bool defaction)
|
2018-08-27 19:40:09 +02:00
|
|
|
{
|
2018-08-27 21:13:23 +02:00
|
|
|
FAR struct task_group_s *group;
|
2018-08-27 23:37:43 +02:00
|
|
|
_sa_handler_t handler = SIG_IGN;
|
2018-08-28 06:32:57 +02:00
|
|
|
irqstate_t flags;
|
2018-08-27 21:13:23 +02:00
|
|
|
|
|
|
|
DEBUGASSERT(tcb != NULL && tcb->group != NULL);
|
|
|
|
group = tcb->group;
|
|
|
|
|
2018-08-27 19:40:09 +02:00
|
|
|
/* Are we setting or unsetting the default action? */
|
|
|
|
|
|
|
|
if (defaction)
|
|
|
|
{
|
|
|
|
/* We are setting the default action. Look up the default action
|
|
|
|
* associated with signo.
|
|
|
|
*/
|
|
|
|
|
2018-08-27 21:13:23 +02:00
|
|
|
handler = nxsig_default_action(signo);
|
2018-08-27 23:37:43 +02:00
|
|
|
if (handler != SIG_IGN)
|
2018-08-27 19:40:09 +02:00
|
|
|
{
|
2020-04-29 18:53:36 +02:00
|
|
|
/* nxsig_addset() is not atomic (but neither is sigaction()) */
|
2018-08-28 06:32:57 +02:00
|
|
|
|
arch, boards, drivers, include, sched, wireless: Change spinlock APIs.
Summary:
- This commit changes spinlock APIs (spin_lock_irqsave/spin_unlock_irqrestore)
- In the previous implementation, the global spinlock (i.e. g_irq_spin) was used.
- This commit allows to use caller specific spinlock but also supports to use
g_irq_spin for backword compatibility (In this case, NULL must be specified)
Impact:
- None
Testing:
- Tested with the following configurations
- spresnse:wifi, spresense:wifi_smp
- esp32-devkitc:smp (QEMU), sabre6-quad:smp (QEMU)
- maxi-bit:smp (QEMU), sim:smp
- stm32f4discovery:wifi
Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2021-02-08 01:21:26 +01:00
|
|
|
flags = spin_lock_irqsave(NULL);
|
2020-04-29 18:53:36 +02:00
|
|
|
nxsig_addset(&group->tg_sigdefault, signo);
|
arch, boards, drivers, include, sched, wireless: Change spinlock APIs.
Summary:
- This commit changes spinlock APIs (spin_lock_irqsave/spin_unlock_irqrestore)
- In the previous implementation, the global spinlock (i.e. g_irq_spin) was used.
- This commit allows to use caller specific spinlock but also supports to use
g_irq_spin for backword compatibility (In this case, NULL must be specified)
Impact:
- None
Testing:
- Tested with the following configurations
- spresnse:wifi, spresense:wifi_smp
- esp32-devkitc:smp (QEMU), sabre6-quad:smp (QEMU)
- maxi-bit:smp (QEMU), sim:smp
- stm32f4discovery:wifi
Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2021-02-08 01:21:26 +01:00
|
|
|
spin_unlock_irqrestore(NULL, flags);
|
2018-08-27 19:40:09 +02:00
|
|
|
}
|
|
|
|
}
|
2018-08-27 21:13:23 +02:00
|
|
|
|
2018-08-27 23:37:43 +02:00
|
|
|
if (handler == SIG_IGN)
|
2018-08-27 19:40:09 +02:00
|
|
|
{
|
2020-04-29 18:53:36 +02:00
|
|
|
/* We are unsetting the default action. NOTE that nxsig_delset() is not
|
2019-03-01 17:50:02 +01:00
|
|
|
* atomic (but neither is sigaction()).
|
|
|
|
*/
|
2018-08-27 19:40:09 +02:00
|
|
|
|
arch, boards, drivers, include, sched, wireless: Change spinlock APIs.
Summary:
- This commit changes spinlock APIs (spin_lock_irqsave/spin_unlock_irqrestore)
- In the previous implementation, the global spinlock (i.e. g_irq_spin) was used.
- This commit allows to use caller specific spinlock but also supports to use
g_irq_spin for backword compatibility (In this case, NULL must be specified)
Impact:
- None
Testing:
- Tested with the following configurations
- spresnse:wifi, spresense:wifi_smp
- esp32-devkitc:smp (QEMU), sabre6-quad:smp (QEMU)
- maxi-bit:smp (QEMU), sim:smp
- stm32f4discovery:wifi
Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2021-02-08 01:21:26 +01:00
|
|
|
flags = spin_lock_irqsave(NULL);
|
2020-04-29 18:53:36 +02:00
|
|
|
nxsig_delset(&group->tg_sigdefault, signo);
|
arch, boards, drivers, include, sched, wireless: Change spinlock APIs.
Summary:
- This commit changes spinlock APIs (spin_lock_irqsave/spin_unlock_irqrestore)
- In the previous implementation, the global spinlock (i.e. g_irq_spin) was used.
- This commit allows to use caller specific spinlock but also supports to use
g_irq_spin for backword compatibility (In this case, NULL must be specified)
Impact:
- None
Testing:
- Tested with the following configurations
- spresnse:wifi, spresense:wifi_smp
- esp32-devkitc:smp (QEMU), sabre6-quad:smp (QEMU)
- maxi-bit:smp (QEMU), sim:smp
- stm32f4discovery:wifi
Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2021-02-08 01:21:26 +01:00
|
|
|
spin_unlock_irqrestore(NULL, flags);
|
2018-08-27 19:40:09 +02:00
|
|
|
}
|
|
|
|
|
2018-08-27 21:13:23 +02:00
|
|
|
return handler;
|
2018-08-27 19:40:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxsig_default_initialize
|
|
|
|
*
|
|
|
|
* Description:
|
2019-06-30 18:35:10 +02:00
|
|
|
* Set all signals to their default action. This is called from
|
|
|
|
* nxtask_start() to configure the newly started task.
|
2018-08-27 19:40:09 +02:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* tcb - Identifies the thread associated with the default handlers
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero (OK) is returned on success; A negated errno value is returned
|
|
|
|
* on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int nxsig_default_initialize(FAR struct tcb_s *tcb)
|
|
|
|
{
|
2018-08-27 21:13:23 +02:00
|
|
|
FAR struct task_group_s *group;
|
2018-08-27 23:37:43 +02:00
|
|
|
int i;
|
2018-08-27 19:40:09 +02:00
|
|
|
|
2018-08-27 21:13:23 +02:00
|
|
|
DEBUGASSERT(tcb != NULL && tcb->group != NULL);
|
|
|
|
group = tcb->group;
|
|
|
|
|
|
|
|
/* Initialize the set of default signal handlers */
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
sigemptyset(&group->tg_sigdefault);
|
2018-08-27 21:13:23 +02:00
|
|
|
|
2018-08-28 06:32:57 +02:00
|
|
|
/* Setup the default action for each signal in g_defactions[] */
|
2018-08-27 21:13:23 +02:00
|
|
|
|
2018-08-27 23:37:43 +02:00
|
|
|
for (i = 0; i < NACTIONS; i++)
|
2018-08-27 21:13:23 +02:00
|
|
|
{
|
2018-08-27 23:37:43 +02:00
|
|
|
nxsig_setup_default_action(group, &g_defactions[i]);
|
2018-08-27 21:13:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
2018-08-27 19:40:09 +02:00
|
|
|
}
|