Skip to content

Commit

Permalink
sim: only abort sim in assertion if in interrupt context/IDLE task
Browse files Browse the repository at this point in the history
This fixes the problem that an assertion in sim build aborted NuttX
even when the assertion was generated from userspace (in which case
simpy the task needs to exit). This required moving the relevant code
into the sim blob.
  • Loading branch information
protobits authored and patacongo committed Mar 29, 2021
1 parent 0c068ed commit 1b8a690
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 26 deletions.
2 changes: 1 addition & 1 deletion arch/sim/src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ CSRCS = up_initialize.c up_idle.c up_interruptcontext.c up_initialstate.c
CSRCS += up_createstack.c up_usestack.c up_releasestack.c up_stackframe.c
CSRCS += up_unblocktask.c up_blocktask.c up_releasepending.c
CSRCS += up_reprioritizertr.c up_exit.c up_schedulesigaction.c
CSRCS += up_heap.c up_uart.c
CSRCS += up_heap.c up_uart.c up_assert.c
CSRCS += up_copyfullstate.c

ifeq ($(CONFIG_ARCH_HAVE_VFORK),y)
Expand Down
92 changes: 92 additions & 0 deletions arch/sim/src/sim/up_assert.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/****************************************************************************
* arch/sim/src/sim/up_assert.c
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*
****************************************************************************/

/****************************************************************************
* Included Files
****************************************************************************/

#include <nuttx/config.h>
#include <sched/sched.h>
#include <stdlib.h>
#include <nuttx/board.h>
#include "up_internal.h"

/****************************************************************************
* Pre-processor Definitions
****************************************************************************/

/****************************************************************************
* Private Types
****************************************************************************/

/****************************************************************************
* Private Function Prototypes
****************************************************************************/

/****************************************************************************
* Private Data
****************************************************************************/

/****************************************************************************
* Public Data
****************************************************************************/

/****************************************************************************
* Private Functions
****************************************************************************/

/****************************************************************************
* Public Functions
****************************************************************************/

/****************************************************************************
* Name: up_assert
*
* Description:
* Called to terminate the simulation abnormally in the event of a failed
* assertion.
*
****************************************************************************/

void up_assert(const char *filename, int line)
{
/* Show the location of the failed assertion */

#ifdef CONFIG_SMP
syslog(LOG_ERR, "CPU%d: Assertion failed at file:%s line: %d\n",
up_cpu_index(), filename, line);
#else
syslog(LOG_ERR, "Assertion failed at file:%s line: %d\n",
filename, line);
#endif

/* Allow for any board/configuration specific crash information */

#ifdef CONFIG_BOARD_CRASHDUMP
board_crashdump(sim_getsp(), this_task(), filename, line);
#endif

if (CURRENT_REGS || (running_task())->flink == NULL)
{
/* Exit the simulation */

host_abort(EXIT_FAILURE);
}
}
38 changes: 13 additions & 25 deletions arch/sim/src/sim/up_head.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,35 +100,20 @@ int main(int argc, char **argv, char **envp)
}

/****************************************************************************
* Name: up_assert
* Name: host_abort
*
* Description:
* Called to terminate the simulation abnormally in the event of a failed
* assertion.
* Abort the simulation
*
* Input Parameters:
* status - Exit status to set
****************************************************************************/

void up_assert(const char *filename, int line)
void host_abort(int status)
{
/* Show the location of the failed assertion */

#ifdef CONFIG_SMP
syslog(LOG_ERR, "CPU%d: Assertion failed at file:%s line: %d\n",
up_cpu_index(), filename, line);
#else
syslog(LOG_ERR, "Assertion failed at file:%s line: %d\n",
filename, line);
#endif

/* Allow for any board/configuration specific crash information */

#ifdef CONFIG_BOARD_CRASHDUMP
board_crashdump(sim_getsp(), this_task(), filename, line);
#endif

/* Exit the simulation */
/* Save the return code and exit the simulation */

g_exitcode = EXIT_FAILURE;
g_exitcode = status;
longjmp(g_simabort, 1);
}

Expand All @@ -152,9 +137,12 @@ void up_assert(const char *filename, int line)
#ifdef CONFIG_BOARDCTL_POWEROFF
int board_power_off(int status)
{
/* Save the return code and exit the simulation */
/* Abort simulator */

g_exitcode = status;
longjmp(g_simabort, 1);
host_abort(status);

/* Does not really return */

return 0;
}
#endif
4 changes: 4 additions & 0 deletions arch/sim/src/sim/up_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ void up_copyfullstate(uint32_t *dest, uint32_t *src);

void *up_doirq(int irq, void *regs);

/* up_head.c ****************************************************************/

void host_abort(int status);

/* up_setjmp32.S ************************************************************/

int up_setjmp(void *jb);
Expand Down

0 comments on commit 1b8a690

Please sign in to comment.