2013-07-19 19:43:04 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* arch/arm/src/armv7-a/arm_sigdeliver.c
|
|
|
|
*
|
2020-05-07 22:15:09 +02: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
|
2013-07-19 19:43:04 +02:00
|
|
|
*
|
2020-05-07 22:15:09 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2013-07-19 19:43:04 +02:00
|
|
|
*
|
2020-05-07 22:15:09 +02: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.
|
2013-07-19 19:43:04 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <sched.h>
|
2021-05-18 08:59:14 +02:00
|
|
|
#include <assert.h>
|
2013-07-19 19:43:04 +02:00
|
|
|
#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"
|
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
|
|
|
{
|
2022-02-28 18:06:24 +01:00
|
|
|
struct tcb_s *rtcb = this_task();
|
|
|
|
uint32_t *regs = rtcb->xcp.saved_regs;
|
2013-07-19 19:43:04 +02:00
|
|
|
|
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
|
|
|
|
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
|
|
|
|
2021-01-20 14:26:28 +01:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
/* Restore the saved 'irqcount' and recover the critical section
|
|
|
|
* spinlocks.
|
2019-10-04 15:17:35 +02:00
|
|
|
*/
|
|
|
|
|
2021-01-20 14:26:28 +01:00
|
|
|
DEBUGASSERT(rtcb->irqcount == 0);
|
|
|
|
while (rtcb->irqcount < saved_irqcount)
|
|
|
|
{
|
|
|
|
enter_critical_section();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_SUPPRESS_INTERRUPTS
|
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
|
|
|
|
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
|
|
|
rtcb->xcp.sigdeliver = NULL; /* Allows next handler to be scheduled */
|
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
|
|
|
}
|