From ae3709819cf17fee597ce3e1cb2e9b8ea11c5ec7 Mon Sep 17 00:00:00 2001 From: buyuer Date: Fri, 30 Jul 2021 12:16:51 +0800 Subject: [PATCH] Use exit func iml host_abort. When use poweroff command,host_abort will be called,but may be make __stack_chk_fail irq, and host_abort be called in PANIC(), so bring infinite loop, in turn it can not exit SIM. Signed-off-by: buyuer --- arch/sim/src/Makefile | 2 +- arch/sim/src/sim/up_head.c | 34 ++++------------------ arch/sim/src/sim/up_host_abort.c | 49 ++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 30 deletions(-) create mode 100644 arch/sim/src/sim/up_host_abort.c diff --git a/arch/sim/src/Makefile b/arch/sim/src/Makefile index 48663a62fe7..175ad484114 100644 --- a/arch/sim/src/Makefile +++ b/arch/sim/src/Makefile @@ -75,7 +75,7 @@ ifeq ($(CONFIG_HOST_MACOS),y) HOSTCFLAGS += -Wno-deprecated-declarations endif -HOSTSRCS = up_hostirq.c up_hostmemory.c up_hosttime.c up_simuart.c +HOSTSRCS = up_hostirq.c up_hostmemory.c up_hosttime.c up_simuart.c up_host_abort.c STDLIBS += -lpthread ifeq ($(CONFIG_HOST_MACOS),y) ifeq ($(CONFIG_LIBCXX),y) diff --git a/arch/sim/src/sim/up_head.c b/arch/sim/src/sim/up_head.c index 1784be50ba1..6d4e9f960ef 100644 --- a/arch/sim/src/sim/up_head.c +++ b/arch/sim/src/sim/up_head.c @@ -48,9 +48,6 @@ char **g_argv; * Private Data ****************************************************************************/ -static jmp_buf g_simabort; -static int g_exitcode = EXIT_SUCCESS; - #ifdef CONFIG_SYSLOG_RPMSG static char g_logbuffer[4096]; #endif @@ -78,37 +75,16 @@ int main(int argc, char **argv, char **envp) /* Start NuttX */ - if (setjmp(g_simabort) == 0) - { #ifdef CONFIG_SMP - /* Start the CPU0 emulation. This should not return. */ + /* Start the CPU0 emulation. This should not return. */ - sim_cpu0_start(); + sim_cpu0_start(); #endif - /* Start the NuttX emulation. This should not return. */ + /* Start the NuttX emulation. This should not return. */ - nx_start(); - } + nx_start(); - return g_exitcode; -} - -/**************************************************************************** - * Name: host_abort - * - * Description: - * Abort the simulation - * - * Input Parameters: - * status - Exit status to set - ****************************************************************************/ - -void host_abort(int status) -{ - /* Save the return code and exit the simulation */ - - g_exitcode = status; - longjmp(g_simabort, 1); + return EXIT_FAILURE; } /**************************************************************************** diff --git a/arch/sim/src/sim/up_host_abort.c b/arch/sim/src/sim/up_host_abort.c new file mode 100644 index 00000000000..db288d388d1 --- /dev/null +++ b/arch/sim/src/sim/up_host_abort.c @@ -0,0 +1,49 @@ +/**************************************************************************** + * arch/sim/src/sim/up_host_abort.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 + +#include "up_internal.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: host_abort + * + * Description: + * Abort the simulation + * + * Input Parameters: + * status - Exit status to set + ****************************************************************************/ + +void host_abort(int status) +{ + /* exit the simulation */ + + exit(status); +} +