score: Simplify _Terminate()

In _Terminate(), everything after invoking the fatal extensions is essentially
dead code.  Simplify this code block and provide a reasonable safe fall-back
for badly configured applications.  Just disable masked interrupts and execute
an idle loop.

Update #5067.
This commit is contained in:
Sebastian Huber authored and Joel Sherrill committed 2024-08-23 14:54:37 +00:00
1 parent e2ce9d426a
commit e80883b406
13 files changed
+226 -306

No files matched your search

+52 -21
View File
@@ -238,37 +238,68 @@ typedef enum {
typedef CPU_Uint32ptr Internal_errors_t;
/**
* @brief Initiates system termination.
* @brief Initiates the system termination.
*
* This routine is invoked when the application or the executive itself
* determines that a fatal error has occurred or a final system state is
* reached (for example after exit()).
* This handler is invoked to terminate the system. It is called by all
* services which determine that a system termination is required. For
* example, it is called by all higher level directives which announce a fatal
* error like rtems_fatal() and exit().
*
* The first action of the system termination handler is to disable maskable
* interrupts. This ensures that interrupts on this processor do not interfere
* with the system termination procedure. This reduces the likelihood to end
* up in a recursive system termination procedure.
*
* The second action of the system termination handler is to call the fatal
* extensions of the user extensions.
*
* The fatal extensions are called with three parameters:
*
* - the fatal source,
*
* - a legacy parameter which is always set to false, and
*
* - an error code with a fatal source dependent content.
*
* The fatal extensions of the initial extension sets are invoked first. For
* them, the following execution environment is required
*
* The first action of this function is to call the fatal handler of the user
* extensions. For the initial extensions the following conditions are
* required
* - a valid stack pointer and enough stack space,
*
* - a valid code memory, and
*
* - valid read-only data.
*
* For the initial extensions the read-write data (including BSS segment) is
* not required on single processor configurations. On SMP configurations
* however the read-write data must be initialized since this function must
* determine the state of the other processors and request them to shut-down if
* necessary.
* In uniprocessor configurations, the read-write data (including ``.bss``
* segment) is not required. In SMP configurations, however, the read-write
* data must have been initialized to determine the state of the other
* processors and request them to shut-down if necessary. The board support
* package (BSP) may install an initial extension that performs a system reset.
* See the BSP documentation in the *RTEMS User Manual* for more information
* how the system reset is done. The BSP provided fatal extension can be
* disabled by the #CONFIGURE_DISABLE_BSP_SETTINGS application configuration
* option. It is recommended to provide an application-specific fatal
* extension using the #CONFIGURE_INITIAL_EXTENSIONS application configuration
* option.
*
* Non-initial extensions require in addition valid read-write data. The BSP
* may install an initial extension that performs a system reset. In this case
* the non-initial extensions will be not called.
* In certain error conditions, it may be unreliable to carry out the
* following steps of the termination procedure since the read-write data may
* be corrupt. One of the fatal extensions of the initial extension set should
* reset the system to stop the system termination procedure.
*
* Once all fatal handler executed the system state is set to
* SYSTEM_STATE_TERMINATED.
* After invoking the fatal extensions of the initial extension sets, the fatal
* extensions of the dynamic extension sets are invoked. For this procedure
* valid read-write data is required.
*
* The final step is to call the CPU specific _CPU_Fatal_halt().
* The last action of the system termination handler is to execute the CPU port
* provided idle loop _CPU_Thread_Idle_body() with maskable interrupts
* disabled. Please note, that properly configured applications should not
* reach this point.
*
* @param the_source The fatal source indicating the subsystem the fatal
* condition originated in.
* @param the_error The fatal error code. This value must be interpreted
* @param the_source is the fatal source indicating the subsystem the fatal
* condition originated in.
*
* @param the_error is the fatal error code. This value must be interpreted
* with respect to the source.
*
* @see rtems_fatal() and _Internal_error().
+15 -3
View File
@@ -41,6 +41,7 @@
#include <rtems/score/interr.h>
#include <rtems/score/cpuimpl.h>
#include <rtems/score/isrlevel.h>
#include <rtems/score/smpimpl.h>
#include <rtems/score/sysstate.h>
#include <rtems/score/userextimpl.h>
@@ -52,10 +53,21 @@ void _Terminate(
Internal_errors_t the_error
)
{
ISR_Level level;
_User_extensions_Fatal( the_source, the_error );
_System_state_Set( SYSTEM_STATE_TERMINATED );
_SMP_Request_shutdown();
_CPU_Fatal_halt( the_source, the_error );
/*
* Everything after invoking the fatal extensions is essentially dead code.
* At least one fatal extension of the initial extension sets should not
* return and for example reset the system. See section "System Termination
* Procedure" in the RTEMS Classic API Guide.
*
* The following code is only executed in badly configured applications.
*/
_ISR_Local_disable( level );
(void) level;
_CPU_Thread_Idle_body( 0 );
}
void _Internal_error( Internal_errors_Core_list core_error )
-1
View File
@@ -9,7 +9,6 @@ copyrights:
default:
- enabled-by: true
value:
- -Wl,--wrap=_CPU_Fatal_halt
- -Wl,--wrap=bsp_reset
- -Wl,--start-group
- -lrtemsbsp
@@ -0,0 +1,25 @@
SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
build-type: test-program
cflags: []
copyrights:
- Copyright (C) 2022, 2024 embedded brains GmbH & Co. KG
cppflags: []
cxxflags: []
enabled-by: true
features: c cprogram
includes: []
ldflags:
- -Wl,--wrap=bsp_reset
- -Wl,--wrap=_CPU_Thread_Idle_body
links:
- role: build-dependency
uid: objsmpshutdown
source:
- testsuites/validation/bsps/tc-fatal-extension-reset.c
- testsuites/validation/bsps/ts-fatal-extension.c
stlib: []
target: testsuites/validation/bsps/ts-fatal-extension.exe
type: build
use-after:
- validation
use-before: []
@@ -1,24 +0,0 @@
SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
build-type: test-program
cflags: []
copyrights:
- Copyright (C) 2022 embedded brains GmbH & Co. KG
cppflags: []
cxxflags: []
enabled-by: bsps/sparc/leon3
features: c cprogram
includes: []
ldflags:
- -Wl,--wrap=_CPU_Fatal_halt
links:
- role: build-dependency
uid: objsparcleon3shutdown
source:
- testsuites/validation/bsps/tc-fatal-sparc-leon3-shutdown-halt.c
- testsuites/validation/bsps/ts-fatal-sparc-leon3-shutdown.c
stlib: []
target: testsuites/validation/bsps/ts-fatal-sparc-leon3-shutdown.exe
type: build
use-after:
- validation
use-before: []
@@ -5,13 +5,10 @@ copyrights:
- Copyright (C) 2023 embedded brains GmbH & Co. KG
cppflags: []
cxxflags: []
enabled-by:
and:
- RTEMS_SMP
- bsps/sparc/leon3
enabled-by: RTEMS_SMP
includes: []
install: []
links: []
source:
- testsuites/validation/bsps/tc-fatal-sparc-leon3-shutdown-request.c
- testsuites/validation/bsps/tc-fatal-smp-shutdown.c
type: build
+2 -2
View File
@@ -80,14 +80,14 @@ links:
uid: validation-tls-1
- role: build-dependency
uid: bsps/fatal-clock-xil-ttc-irq-install
- role: build-dependency
uid: bsps/fatal-extension
- role: build-dependency
uid: bsps/fatal-sparc-leon3-cache-snooping-disabled-boot
- role: build-dependency
uid: bsps/fatal-sparc-leon3-cache-snooping-disabled-secondary
- role: build-dependency
uid: bsps/fatal-sparc-leon3-clock-initialization
- role: build-dependency
uid: bsps/fatal-sparc-leon3-shutdown
- role: build-dependency
uid: bsps/validation-bsp-0
type: build
@@ -9,7 +9,7 @@ enabled-by: true
features: c cprogram
includes: []
ldflags:
- -Wl,--wrap=_CPU_Fatal_halt
- -Wl,--wrap=_CPU_Thread_Idle_body
links: []
source:
- testsuites/validation/tc-terminate.c
@@ -3,11 +3,11 @@
/**
* @file
*
* @ingroup BspSparcLeon3ValFatalShutdownHalt
* @ingroup BspValFatalExtensionReset
*/
/*
* Copyright (C) 2021, 2022 embedded brains GmbH & Co. KG
* Copyright (C) 2021, 2024 embedded brains GmbH & Co. KG
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -59,20 +59,19 @@
#include <rtems/test.h>
/**
* @defgroup BspSparcLeon3ValFatalShutdownHalt \
* spec:/bsp/sparc/leon3/val/fatal-shutdown-halt
* @defgroup BspValFatalExtensionReset spec:/bsp/val/fatal-extension-reset
*
* @ingroup TestsuitesBspsFatalSparcLeon3Shutdown
* @ingroup TestsuitesBspsFatalExtension
*
* @brief Tests the leon3 BSP family shutdown procedure.
* @brief Tests the BSP-specific fatal extension.
*
* This test case performs the following actions:
*
* - Check the effects of the leon3 BSP family shutdown procedure.
* - Check the effects of the BSP-specific fatal extension.
*
* - Check that no dynamic fatal error extension was invoked. This shows
* that the leon3 BSP family shutdown procedure called the wrapped
* _CPU_Fatal_halt() function of the test suite.
* that the BSP-specific fatal extension called the wrapped bsp_reset()
* function of the test suite.
*
* @{
*/
@@ -98,7 +97,7 @@ static void DynamicFatalHandler(
(void) Add( &dynamic_fatal_extension_counter, 1 );
}
static void InitBspSparcLeon3ValFatalShutdownHalt( void )
static void InitBspValFatalExtensionReset( void )
{
rtems_extensions_table table = { .fatal = DynamicFatalHandler };
rtems_id id;
@@ -107,22 +106,22 @@ static void InitBspSparcLeon3ValFatalShutdownHalt( void )
}
RTEMS_SYSINIT_ITEM(
InitBspSparcLeon3ValFatalShutdownHalt,
InitBspValFatalExtensionReset,
RTEMS_SYSINIT_DEVICE_DRIVERS,
RTEMS_SYSINIT_ORDER_MIDDLE
);
/**
* @brief Check the effects of the leon3 BSP family shutdown procedure.
* @brief Check the effects of the BSP-specific fatal extension.
*/
static void BspSparcLeon3ValFatalShutdownHalt_Action_0( void )
static void BspValFatalExtensionReset_Action_0( void )
{
uint32_t counter;
/*
* Check that no dynamic fatal error extension was invoked. This shows that
* the leon3 BSP family shutdown procedure called the wrapped
* _CPU_Fatal_halt() function of the test suite.
* the BSP-specific fatal extension called the wrapped bsp_reset() function
* of the test suite.
*/
T_step_rsc_success( 0, status );
counter = Add( &dynamic_fatal_extension_counter, 0 );
@@ -130,13 +129,13 @@ static void BspSparcLeon3ValFatalShutdownHalt_Action_0( void )
}
/**
* @fn void T_case_body_BspSparcLeon3ValFatalShutdownHalt( void )
* @fn void T_case_body_BspValFatalExtensionReset( void )
*/
T_TEST_CASE( BspSparcLeon3ValFatalShutdownHalt )
T_TEST_CASE( BspValFatalExtensionReset )
{
T_plan( 2 );
BspSparcLeon3ValFatalShutdownHalt_Action_0();
BspValFatalExtensionReset_Action_0();
}
/** @} */
@@ -3,11 +3,11 @@
/**
* @file
*
* @ingroup BspSparcLeon3ValFatalShutdownRequest
* @ingroup BspValFatalSmpShutdown
*/
/*
* Copyright (C) 2021, 2022 embedded brains GmbH & Co. KG
* Copyright (C) 2021, 2024 embedded brains GmbH & Co. KG
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -52,7 +52,6 @@
#include "config.h"
#endif
#include <bsp/leon3.h>
#include <rtems/sysinit.h>
#include <rtems/score/smpimpl.h>
@@ -61,21 +60,17 @@
#include <rtems/test.h>
/**
* @defgroup BspSparcLeon3ValFatalShutdownRequest \
* spec:/bsp/sparc/leon3/val/fatal-shutdown-request
* @defgroup BspValFatalSmpShutdown spec:/bsp/val/fatal-smp-shutdown
*
* @ingroup TestsuitesBspsFatalSparcLeon3Shutdown
* @ingroup TestsuitesBspsFatalExtension
*
* @brief Tests the leon3 BSP family SMP-specific shutdown procedure.
* @brief Tests the BSP-specific fatal extension shutdown procedure.
*
* This test case performs the following actions:
*
* - Check the effects of the leon3 BSP family shutdown procedure.
* - Check the effects of the BSP-specific fatal extension.
*
* - Check that the second processor was not powered down during system
* initialization.
*
* - Wait until the second processor is powered down.
* - Wait until the second processor is idle.
*
* - Check that the RTEMS_FATAL_SOURCE_SMP with SMP_FATAL_SHUTDOWN_RESPONSE
* fatal error occurred exactly once.
@@ -86,8 +81,6 @@
* @{
*/
static uint32_t mpstat_during_sysinit;
static Atomic_Uint shutdown_response_counter;
static uint32_t shutdown_response_cpu_index = UINT32_MAX;
@@ -114,66 +107,65 @@ static void ShutdownFatalHandler(
}
}
static void InitBspSparcLeon3ValFatalShutdownRequest( void )
static void InitBspValFatalSmpShutdown( void )
{
irqamp *regs;
regs = LEON3_IrqCtrl_Regs;
mpstat_during_sysinit = grlib_load_32( &regs->mpstat );
SetFatalHandler( ShutdownFatalHandler, NULL );
}
RTEMS_SYSINIT_ITEM(
InitBspSparcLeon3ValFatalShutdownRequest,
InitBspValFatalSmpShutdown,
RTEMS_SYSINIT_DEVICE_DRIVERS,
RTEMS_SYSINIT_ORDER_MIDDLE
);
/**
* @brief Check the effects of the leon3 BSP family shutdown procedure.
*/
static void BspSparcLeon3ValFatalShutdownRequest_Action_0( void )
static Atomic_Uint idle_counter;
void *__real__CPU_Thread_Idle_body( void *arg );
void *__wrap__CPU_Thread_Idle_body( void *arg );
void *__wrap__CPU_Thread_Idle_body( void *arg )
{
irqamp *regs;
uint32_t counter;
(void) Add( &idle_counter, 1 );
return __real__CPU_Thread_Idle_body( arg );
}
regs = LEON3_IrqCtrl_Regs;
/**
* @brief Check the effects of the BSP-specific fatal extension.
*/
static void BspValFatalSmpShutdown_Action_0( void )
{
unsigned int counter;
/*
* Check that the second processor was not powered down during system
* initialization.
* Wait until the second processor is idle.
*/
T_step_eq_u32( 0, mpstat_during_sysinit & 0x2, 0 );
/*
* Wait until the second processor is powered down.
*/
while ( ( grlib_load_32( &regs->mpstat ) & 0x2 ) != 0x2U ) {
/* Wait */
}
do {
counter = _Atomic_Load_uint( &idle_counter, ATOMIC_ORDER_RELAXED );
} while ( counter != 2U );
/*
* Check that the RTEMS_FATAL_SOURCE_SMP with SMP_FATAL_SHUTDOWN_RESPONSE
* fatal error occurred exactly once.
*/
counter = Add( &shutdown_response_counter, 0 );
T_step_eq_uint( 1, counter, 1 );
T_step_eq_uint( 0, counter, 1 );
/*
* Check that the RTEMS_FATAL_SOURCE_SMP with SMP_FATAL_SHUTDOWN_RESPONSE
* fatal error occurred on the second processor.
*/
T_step_eq_u32( 2, shutdown_response_cpu_index, 1 );
T_step_eq_u32( 1, shutdown_response_cpu_index, 1 );
}
/**
* @fn void T_case_body_BspSparcLeon3ValFatalShutdownRequest( void )
* @fn void T_case_body_BspValFatalSmpShutdown( void )
*/
T_TEST_CASE( BspSparcLeon3ValFatalShutdownRequest )
T_TEST_CASE( BspValFatalSmpShutdown )
{
T_plan( 3 );
T_plan( 2 );
BspSparcLeon3ValFatalShutdownRequest_Action_0();
BspValFatalSmpShutdown_Action_0();
}
/** @} */
@@ -3,7 +3,7 @@
/**
* @file
*
* @ingroup TestsuitesBspsFatalSparcLeon3Shutdown
* @ingroup TestsuitesBspsFatalExtension
*/
/*
@@ -65,8 +65,7 @@
#include <rtems/test.h>
/**
* @defgroup TestsuitesBspsFatalSparcLeon3Shutdown \
* spec:/testsuites/bsps/fatal-sparc-leon3-shutdown
* @defgroup TestsuitesBspsFatalExtension spec:/testsuites/bsps/fatal-extension
*
* @ingroup RTEMSTestSuitesValidation
*
@@ -76,7 +75,7 @@
* @{
*/
const char rtems_test_name[] = "TestsuitesBspsFatalSparcLeon3Shutdown";
const char rtems_test_name[] = "TestsuitesBspsFatalExtension";
static char buffer[ 512 ];
@@ -97,11 +96,11 @@ static const T_config test_config = {
.actions = actions
};
void __real__CPU_Fatal_halt( uint32_t source, CPU_Uint32ptr code );
void __real_bsp_reset( rtems_fatal_source source, rtems_fatal_code code );
void __wrap__CPU_Fatal_halt( uint32_t source, CPU_Uint32ptr code );
void __wrap_bsp_reset( rtems_fatal_source source, rtems_fatal_code code );
void __wrap__CPU_Fatal_halt( uint32_t source, CPU_Uint32ptr code )
void __wrap_bsp_reset( rtems_fatal_source source, rtems_fatal_code code )
{
int exit_code;
@@ -115,9 +114,20 @@ void __wrap__CPU_Fatal_halt( uint32_t source, CPU_Uint32ptr code )
#if defined(RTEMS_GCOV_COVERAGE)
rtems_test_gcov_dump_info();
#endif
__real__CPU_Fatal_halt( source, code );
__real_bsp_reset( source, code );
}
#if !defined(RTEMS_SMP)
void *__real__CPU_Thread_Idle_body( void *arg );
void *__wrap__CPU_Thread_Idle_body( void *arg );
void *__wrap__CPU_Thread_Idle_body( void *arg )
{
return __real__CPU_Thread_Idle_body( arg );
}
#endif
#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
#if defined(RTEMS_SMP)
@@ -1,94 +0,0 @@
/* SPDX-License-Identifier: BSD-2-Clause */
/**
* @file
*
* @ingroup RTEMSTestSuiteTestsuitesFatalBspSparcLeon3ShutdownResponse
*/
/*
* Copyright (C) 2021 embedded brains GmbH & Co. KG
*
* 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.
*
* 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.
*/
/*
* This file is part of the RTEMS quality process and was automatically
* generated. If you find something that needs to be fixed or
* worded better please post a report or patch to an RTEMS mailing list
* or raise a bug report:
*
* https://www.rtems.org/bugs.html
*
* For information on updating and regenerating please refer to the How-To
* section in the Software Requirements Engineering chapter of the
* RTEMS Software Engineering manual. The manual is provided as a part of
* a release. For development sources please refer to the online
* documentation at:
*
* https://docs.rtems.org
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <rtems/score/smpimpl.h>
#include "tr-fatal-sparc-leon3-shutdown-response.h"
#include <rtems/test.h>
/**
* @defgroup RTEMSTestSuiteTestsuitesFatalBspSparcLeon3ShutdownResponse \
* spec:/testsuites/fatal-sparc-leon3-shutdown-response
*
* @ingroup RTEMSTestSuitesValidation
*
* @brief This validation test suite contains a test case which performs a
* system shutdown.
*
* @{
*/
const char rtems_test_name[] = "FatalBspSparcLeon3ShutdownResponse";
#define FATAL_SYSINIT_RUN BspSparcLeon3ValFatalShutdownResponse_Run
static void FatalSysinitExit( rtems_fatal_code exit_code )
{
if ( exit_code == 0 ) {
rtems_fatal( RTEMS_FATAL_SOURCE_SMP, SMP_FATAL_SHUTDOWN );
} else {
rtems_fatal( RTEMS_FATAL_SOURCE_EXIT, exit_code );
}
}
#define FATAL_SYSINIT_EXIT( exit_code ) FatalSysinitExit( exit_code )
#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
#define CONFIGURE_MAXIMUM_PROCESSORS 2
#include "ts-fatal-sysinit.h"
/** @} */
File diff suppressed because it is too large. Load diff