2013-07-19 19:43:04 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* arch/arm/src/armv7-a/arm_sigdeliver.c
|
|
|
|
*
|
2019-02-03 22:29:47 +01:00
|
|
|
* Copyright (C) 2013, 2015-2016, 2018-2019 Gregory Nutt. All rights
|
|
|
|
* reserved.
|
2013-07-19 19:43:04 +02:00
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <sched.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
#include <nuttx/irq.h>
|
|
|
|
#include <nuttx/arch.h>
|
2015-02-28 00:19:38 +01:00
|
|
|
#include <nuttx/board.h>
|
2013-07-19 19:43:04 +02:00
|
|
|
#include <arch/board/board.h>
|
|
|
|
|
2014-08-09 01:53:55 +02:00
|
|
|
#include "sched/sched.h"
|
2020-05-01 03:20:29 +02:00
|
|
|
#include "arm_internal.h"
|
|
|
|
#include "arm_arch.h"
|
2013-07-19 19:43:04 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2020-05-01 16:50:23 +02:00
|
|
|
* Name: arm_sigdeliver
|
2013-07-19 19:43:04 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This is the a signal handling trampoline. When a signal action was
|
|
|
|
* posted. The task context was mucked with and forced to branch to this
|
|
|
|
* location with interrupts disabled.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-05-01 16:50:23 +02:00
|
|
|
void arm_sigdeliver(void)
|
2013-07-19 19:43:04 +02:00
|
|
|
{
|
2016-02-06 20:41:28 +01:00
|
|
|
struct tcb_s *rtcb = this_task();
|
2013-07-19 19:43:04 +02:00
|
|
|
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 = rtcb->pterrno;
|
|
|
|
|
2018-06-07 01:39:10 +02:00
|
|
|
#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
|
|
|
|
* we resume the main thread of the task.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int16_t saved_irqcount;
|
|
|
|
#endif
|
|
|
|
|
2015-11-01 16:07:06 +01:00
|
|
|
board_autoled_on(LED_SIGNAL);
|
2013-07-19 19:43:04 +02:00
|
|
|
|
2016-06-18 00:44:50 +02:00
|
|
|
sinfo("rtcb=%p sigdeliver=%p sigpendactionq.head=%p\n",
|
2013-07-19 19:43:04 +02:00
|
|
|
rtcb, rtcb->xcp.sigdeliver, rtcb->sigpendactionq.head);
|
2018-08-24 14:58:30 +02:00
|
|
|
DEBUGASSERT(rtcb->xcp.sigdeliver != NULL);
|
2013-07-19 19:43:04 +02:00
|
|
|
|
2019-02-03 22:29:47 +01:00
|
|
|
/* Save the return state on the stack. */
|
2013-07-19 19:43:04 +02:00
|
|
|
|
2020-04-30 20:19:27 +02:00
|
|
|
arm_copyfullstate(regs, rtcb->xcp.regs);
|
2013-07-19 19:43:04 +02:00
|
|
|
|
2018-06-07 01:03:42 +02:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
/* In the SMP case, up_schedule_sigaction(0) will have incremented
|
2018-06-07 01:39:10 +02:00
|
|
|
* 'irqcount' in order to force us into a critical section. Save the
|
|
|
|
* pre-incremented irqcount.
|
|
|
|
*/
|
|
|
|
|
2019-10-04 15:17:35 +02:00
|
|
|
saved_irqcount = rtcb->irqcount - 1;
|
2018-06-07 01:39:10 +02:00
|
|
|
DEBUGASSERT(saved_irqcount >= 0);
|
|
|
|
|
|
|
|
/* Now we need call leave_critical_section() repeatedly to get the irqcount
|
|
|
|
* to zero, freeing all global spinlocks that enforce the critical section.
|
2018-06-07 01:03:42 +02:00
|
|
|
*/
|
|
|
|
|
2018-06-07 01:39:10 +02:00
|
|
|
do
|
|
|
|
{
|
|
|
|
leave_critical_section(regs[REG_CPSR]);
|
|
|
|
}
|
|
|
|
while (rtcb->irqcount > 0);
|
2018-06-07 01:03:42 +02:00
|
|
|
#endif /* CONFIG_SMP */
|
|
|
|
|
2018-06-06 17:54:30 +02:00
|
|
|
#ifndef CONFIG_SUPPRESS_INTERRUPTS
|
|
|
|
/* Then make sure that interrupts are enabled. Signal handlers must always
|
|
|
|
* run with interrupts enabled.
|
|
|
|
*/
|
2013-07-19 19:43:04 +02:00
|
|
|
|
2018-06-06 17:54:30 +02:00
|
|
|
up_irq_enable();
|
|
|
|
#endif
|
2013-07-19 19:43:04 +02:00
|
|
|
|
2016-11-24 18:45:05 +01:00
|
|
|
/* Deliver the signal */
|
2013-07-19 19:43:04 +02:00
|
|
|
|
2019-02-04 00:14:32 +01:00
|
|
|
((sig_deliver_t)rtcb->xcp.sigdeliver)(rtcb);
|
2013-07-19 19:43:04 +02:00
|
|
|
|
|
|
|
/* Output any debug messages BEFORE restoring errno (because they may
|
|
|
|
* alter errno), then disable interrupts again and restore the original
|
|
|
|
* errno that is needed by the user logic (it is probably EINTR).
|
2016-11-24 18:45:05 +01:00
|
|
|
*
|
2016-11-24 20:33:43 +01:00
|
|
|
* I would prefer that all interrupts are disabled when
|
2020-04-30 18:40:03 +02:00
|
|
|
* arm_fullcontextrestore() is called, but that may not be necessary.
|
2013-07-19 19:43:04 +02:00
|
|
|
*/
|
|
|
|
|
2016-06-18 00:44:50 +02:00
|
|
|
sinfo("Resuming\n");
|
2016-11-24 18:45:05 +01:00
|
|
|
|
2019-10-04 15:17:35 +02:00
|
|
|
/* Call enter_critical_section() to disable local interrupts before
|
|
|
|
* restoring local context.
|
|
|
|
*
|
|
|
|
* Here, we should not use up_irq_save() in SMP mode.
|
|
|
|
* For example, if we call up_irq_save() here and another CPU might
|
|
|
|
* have called up_cpu_pause() to this cpu, hence g_cpu_irqlock has
|
|
|
|
* been locked by the cpu, in this case, we would see a deadlock in
|
|
|
|
* later call of enter_critical_section() to restore irqcount.
|
|
|
|
* To avoid this situation, we need to call enter_critical_section().
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
2020-01-02 17:49:34 +01:00
|
|
|
enter_critical_section();
|
2019-10-04 15:17:35 +02:00
|
|
|
#else
|
2020-01-02 17:49:34 +01:00
|
|
|
up_irq_save();
|
2019-10-04 15:17:35 +02:00
|
|
|
#endif
|
2018-06-07 01:39:10 +02:00
|
|
|
|
|
|
|
/* Restore the saved errno value */
|
|
|
|
|
2019-02-04 00:14:32 +01:00
|
|
|
rtcb->pterrno = saved_errno;
|
2019-02-03 22:29:47 +01:00
|
|
|
|
|
|
|
/* 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
|
|
|
|
* signal handling action.
|
|
|
|
*
|
|
|
|
* Keeping this data in the TCB resolves a security problem in protected
|
|
|
|
* and kernel mode: The regs[] array is visible on the user stack and
|
|
|
|
* could be modified by a hostile program.
|
|
|
|
*/
|
|
|
|
|
2019-02-04 00:14:32 +01:00
|
|
|
regs[REG_PC] = rtcb->xcp.saved_pc;
|
|
|
|
regs[REG_CPSR] = rtcb->xcp.saved_cpsr;
|
|
|
|
rtcb->xcp.sigdeliver = NULL; /* Allows next handler to be scheduled */
|
2013-07-19 19:43:04 +02:00
|
|
|
|
2018-06-07 01:39:10 +02:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
/* Restore the saved 'irqcount' and recover the critical section
|
|
|
|
* spinlocks.
|
2019-10-04 15:17:35 +02:00
|
|
|
*
|
|
|
|
* REVISIT: irqcount should be one from the above call to
|
|
|
|
* enter_critical_section(). Could the saved_irqcount be zero? That
|
|
|
|
* would be a problem.
|
2018-06-07 01:39:10 +02:00
|
|
|
*/
|
|
|
|
|
2019-10-04 15:17:35 +02:00
|
|
|
DEBUGASSERT(rtcb->irqcount == 1);
|
2018-06-07 01:39:10 +02:00
|
|
|
while (rtcb->irqcount < saved_irqcount)
|
|
|
|
{
|
2020-01-02 17:49:34 +01:00
|
|
|
enter_critical_section();
|
2018-06-07 01:39:10 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-07-19 19:43:04 +02:00
|
|
|
/* Then restore the correct state for this thread of execution. */
|
|
|
|
|
2015-11-01 16:09:36 +01:00
|
|
|
board_autoled_off(LED_SIGNAL);
|
2020-04-30 18:40:03 +02:00
|
|
|
arm_fullcontextrestore(regs);
|
2013-07-19 19:43:04 +02:00
|
|
|
}
|