2013-02-16 16:32:19 +00:00
|
|
|
/****************************************************************************
|
2020-04-30 15:19:35 -06:00
|
|
|
* arch/arm/src/armv6-m/arm_sigdeliver.c
|
2013-02-16 16:32:19 +00:00
|
|
|
*
|
2021-01-20 21:26:28 +08: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-02-16 16:32:19 +00:00
|
|
|
*
|
2021-01-20 21:26:28 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2013-02-16 16:32:19 +00:00
|
|
|
*
|
2021-01-20 21:26:28 +08: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-02-16 16:32:19 +00:00
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Included Files
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <sched.h>
|
2021-05-18 14:59:14 +08:00
|
|
|
#include <assert.h>
|
2013-02-16 16:32:19 +00:00
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
|
|
#include <nuttx/irq.h>
|
|
|
|
|
#include <nuttx/arch.h>
|
2015-02-27 17:19:38 -06:00
|
|
|
#include <nuttx/board.h>
|
2013-02-16 16:32:19 +00:00
|
|
|
#include <arch/board/board.h>
|
|
|
|
|
|
2014-08-08 17:53:55 -06:00
|
|
|
#include "sched/sched.h"
|
2020-04-30 19:20:29 -06:00
|
|
|
#include "arm_internal.h"
|
2013-02-16 16:32:19 +00:00
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Public Functions
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
2020-05-01 08:50:23 -06:00
|
|
|
* Name: arm_sigdeliver
|
2013-02-16 16:32:19 +00: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 08:50:23 -06:00
|
|
|
void arm_sigdeliver(void)
|
2013-02-16 16:32:19 +00:00
|
|
|
{
|
2016-02-06 13:41:28 -06:00
|
|
|
struct tcb_s *rtcb = this_task();
|
2022-03-01 01:06:24 +08:00
|
|
|
uint32_t *regs = rtcb->xcp.saved_regs;
|
2013-02-16 16:32:19 +00:00
|
|
|
|
2021-02-26 21:35:03 +09: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 09:07:06 -06:00
|
|
|
board_autoled_on(LED_SIGNAL);
|
2013-02-16 16:32:19 +00:00
|
|
|
|
2016-06-17 16:44:50 -06:00
|
|
|
sinfo("rtcb=%p sigdeliver=%p sigpendactionq.head=%p\n",
|
2013-02-16 16:32:19 +00:00
|
|
|
rtcb, rtcb->xcp.sigdeliver, rtcb->sigpendactionq.head);
|
2018-08-24 06:58:30 -06:00
|
|
|
DEBUGASSERT(rtcb->xcp.sigdeliver != NULL);
|
2013-02-16 16:32:19 +00:00
|
|
|
|
2021-02-26 21:35:03 +09:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
|
/* In the SMP case, up_schedule_sigaction(0) will have incremented
|
|
|
|
|
* 'irqcount' in order to force us into a critical section. Save the
|
|
|
|
|
* pre-incremented irqcount.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
saved_irqcount = rtcb->irqcount - 1;
|
|
|
|
|
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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
leave_critical_section((uint16_t)regs[REG_PRIMASK]);
|
|
|
|
|
}
|
|
|
|
|
while (rtcb->irqcount > 0);
|
|
|
|
|
#endif /* CONFIG_SMP */
|
|
|
|
|
|
2018-06-06 09:54:30 -06:00
|
|
|
#ifndef CONFIG_SUPPRESS_INTERRUPTS
|
|
|
|
|
/* Then make sure that interrupts are enabled. Signal handlers must always
|
|
|
|
|
* run with interrupts enabled.
|
|
|
|
|
*/
|
2013-02-16 16:32:19 +00:00
|
|
|
|
2018-06-06 09:54:30 -06:00
|
|
|
up_irq_enable();
|
|
|
|
|
#endif
|
2013-02-16 16:32:19 +00:00
|
|
|
|
2013-03-17 00:40:49 +00:00
|
|
|
/* Deliver the signal */
|
2013-02-16 16:32:19 +00:00
|
|
|
|
2019-02-03 17:14:32 -06:00
|
|
|
((sig_deliver_t)rtcb->xcp.sigdeliver)(rtcb);
|
2013-02-16 16:32:19 +00: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).
|
2021-02-26 21:35:03 +09:00
|
|
|
*
|
|
|
|
|
* I would prefer that all interrupts are disabled when
|
|
|
|
|
* arm_fullcontextrestore() is called, but that may not be necessary.
|
2013-02-16 16:32:19 +00:00
|
|
|
*/
|
|
|
|
|
|
2016-06-17 16:44:50 -06:00
|
|
|
sinfo("Resuming\n");
|
2021-02-26 21:35:03 +09:00
|
|
|
|
2021-01-20 21:26:28 +08:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
|
/* Restore the saved 'irqcount' and recover the critical section
|
|
|
|
|
* spinlocks.
|
2021-02-26 21:35:03 +09:00
|
|
|
*/
|
|
|
|
|
|
2021-01-20 21:26:28 +08:00
|
|
|
DEBUGASSERT(rtcb->irqcount == 0);
|
|
|
|
|
while (rtcb->irqcount < saved_irqcount)
|
|
|
|
|
{
|
|
|
|
|
enter_critical_section();
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef CONFIG_SUPPRESS_INTERRUPTS
|
2020-01-02 10:49:34 -06:00
|
|
|
up_irq_save();
|
2021-02-26 21:35:03 +09:00
|
|
|
#endif
|
|
|
|
|
|
2019-02-03 15:29:47 -06: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-03 17:14:32 -06:00
|
|
|
rtcb->xcp.sigdeliver = NULL; /* Allows next handler to be scheduled */
|
2019-02-03 15:29:47 -06:00
|
|
|
|
2013-02-16 16:32:19 +00:00
|
|
|
/* Then restore the correct state for this thread of
|
|
|
|
|
* execution.
|
|
|
|
|
*/
|
|
|
|
|
|
2015-11-01 09:09:36 -06:00
|
|
|
board_autoled_off(LED_SIGNAL);
|
2020-04-30 10:40:03 -06:00
|
|
|
arm_fullcontextrestore(regs);
|
2013-02-16 16:32:19 +00:00
|
|
|
}
|