[PATCH v2 5/6] cpukit: Add signal mapping support
Kinsey Moore
kinsey.moore at oarcorp.com
Thu Sep 23 00:16:53 UTC 2021
This adds a confdef option allowing an application to request mapping
machine exceptions to POSIX signals. This is required for some languages
such as Ada.
---
cpukit/doxygen/appl-config.h | 25 ++++-
cpukit/include/rtems/confdefs/extensions.h | 7 ++
cpukit/include/rtems/exception.h | 12 +++
cpukit/score/src/exceptionmapping.c | 106 +++++++++++++++++++++
spec/build/cpukit/librtemscpu.yml | 2 +
spec/build/cpukit/objexceptionmapping.yml | 15 +++
6 files changed, 166 insertions(+), 1 deletion(-)
create mode 100644 cpukit/score/src/exceptionmapping.c
create mode 100644 spec/build/cpukit/objexceptionmapping.yml
diff --git a/cpukit/doxygen/appl-config.h b/cpukit/doxygen/appl-config.h
index bbeb438bec..8ad3a3c70e 100644
--- a/cpukit/doxygen/appl-config.h
+++ b/cpukit/doxygen/appl-config.h
@@ -3,7 +3,7 @@
/*
* Copyright (C) 2019, 2021 embedded brains GmbH (http://www.embedded-brains.de)
* Copyright (C) 2010 Gedare Bloom
- * Copyright (C) 1988, 2008 On-Line Applications Research Corporation (OAR)
+ * Copyright (C) 1988, 2021 On-Line Applications Research Corporation (OAR)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -1773,6 +1773,29 @@
*/
#define CONFIGURE_ATA_DRIVER_TASK_PRIORITY
+/* Generated from spec:/acfg/if/exception-to-signal-mapping */
+
+/**
+ * @brief This configuration option is a boolean feature define.
+ *
+ * In case this configuration option is defined, then the machine exception to
+ * POSIX signal mapping is configured during system initialization.
+ *
+ * @par Default Configuration
+ * If this configuration option is undefined, then the described feature is not
+ * enabled.
+ *
+ * @par Notes
+ * @parblock
+ * This device driver is responsible for setting up a mapping from machine
+ * exceptions to POSIX signals so that applications may consume them and alter
+ * task execution as necessary.
+ *
+ * This is especially useful for applications written in Ada or C++.
+ * @endparblock
+ */
+#define CONFIGURE_EXCEPTION_TO_SIGNAL_MAPPING
+
/* Generated from spec:/acfg/if/max-drivers */
/**
diff --git a/cpukit/include/rtems/confdefs/extensions.h b/cpukit/include/rtems/confdefs/extensions.h
index 83d690d50a..767c9028d1 100644
--- a/cpukit/include/rtems/confdefs/extensions.h
+++ b/cpukit/include/rtems/confdefs/extensions.h
@@ -93,6 +93,10 @@
#include <rtems/stackchk.h>
#endif
+#ifdef CONFIGURE_EXCEPTION_TO_SIGNAL_MAPPING
+ #include <rtems/exception.h>
+#endif
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -103,6 +107,9 @@ extern "C" {
|| defined(CONFIGURE_INITIAL_EXTENSIONS) \
|| defined(BSP_INITIAL_EXTENSION)
const User_extensions_Table _User_extensions_Initial_extensions[] = {
+ #ifdef CONFIGURE_EXCEPTION_TO_SIGNAL_MAPPING
+ { .fatal = _Exception_map_signal },
+ #endif
#ifdef _CONFIGURE_RECORD_NEED_EXTENSION
{
#ifdef CONFIGURE_RECORD_EXTENSIONS_ENABLED
diff --git a/cpukit/include/rtems/exception.h b/cpukit/include/rtems/exception.h
index 89edfd02b4..547d7c42c2 100644
--- a/cpukit/include/rtems/exception.h
+++ b/cpukit/include/rtems/exception.h
@@ -159,6 +159,18 @@ void Exception_Manager_Copy_CPU_Exception_frame(
CPU_Exception_frame *old_ef
);
+/**
+ * @brief Handle an exception frame for mapping signals
+ *
+ * See CONFIGURE_EXCEPTION_TO_SIGNAL_MAPPING documentation in the
+ * "RTEMS Classic API Guide".
+ */
+void _Exception_map_signal(
+ Internal_errors_Source source,
+ bool always_set_to_false,
+ Internal_errors_t code
+);
+
#ifdef __cplusplus
}
#endif
diff --git a/cpukit/score/src/exceptionmapping.c b/cpukit/score/src/exceptionmapping.c
new file mode 100644
index 0000000000..a1b1146d1c
--- /dev/null
+++ b/cpukit/score/src/exceptionmapping.c
@@ -0,0 +1,106 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+
+/**
+ * @file
+ *
+ * @ingroup RTEMSScoreExceptionMapping
+ *
+ * @brief AArch64 machine exception to POSIX signal mapping.
+ */
+
+/*
+ * Copyright (C) 2021 On-Line Applications Research Corporation (OAR)
+ * Written by Kinsey Moore <kinsey.moore at oarcorp.com>
+ *
+ * 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.
+ */
+
+#include <pthread.h>
+#include <signal.h>
+#include <rtems/exception.h>
+
+/*
+ * Exception handler. Map the exception class to SIGFPE, SIGSEGV
+ * or SIGILL for Ada or other runtimes.
+ */
+void _Exception_map_signal(
+ Internal_errors_Source source,
+ bool always_set_to_false,
+ Internal_errors_t code
+)
+{
+ CPU_Exception_frame *ef;
+ uint32_t signal;
+ Exception_Class eClass;
+
+ if ( source != RTEMS_FATAL_SOURCE_EXCEPTION ) {
+ return;
+ }
+
+ ef = (rtems_exception_frame *) code;
+ eClass = Exception_Manager_Get_class( ef );
+
+ switch ( eClass ) {
+ /* Don't handle exceptions other handlers are likely to be interested in */
+ case EXCEPTION_SUPERVISOR:
+ case EXCEPTION_TRAPPED_INSTRUCTION:
+ case EXCEPTION_BREAKPOINT:
+ case EXCEPTION_BREAK_INSTRUCTION:
+ case EXCEPTION_STEP:
+ case EXCEPTION_WATCHPOINT:
+ /* SP alignment can't be handled via signals alone */
+ case EXCEPTION_SP_ALIGNMENT:
+ return;
+
+ case EXCEPTION_FPU:
+ case EXCEPTION_TAGGED_OVERFLOW:
+ case EXCEPTION_DIV_ZERO:
+ signal = SIGFPE;
+ break;
+
+ case EXCEPTION_DATA_ABORT_READ:
+ case EXCEPTION_DATA_ABORT_WRITE:
+ case EXCEPTION_DATA_ABORT_UNSPECIFIED:
+ case EXCEPTION_INSTRUCTION_ABORT:
+ case EXCEPTION_MMU_UNSPECIFIED:
+ case EXCEPTION_ACCESS_ALIGNMENT:
+ signal = SIGSEGV;
+ break;
+
+ default:
+ /*
+ * Covers unknown, PC alignment, illegal execution state, and any new
+ * exception classes that get added.
+ */
+ signal = SIGILL;
+ break;
+ }
+
+ /* Disable thread dispatch */
+ Exception_Manager_disable_thread_dispatch();
+
+ /* Send the signal. The handler will run during thread dispatch. */
+ pthread_kill( pthread_self(), signal );
+
+ /* Perform dispatch and resume execution */
+ Exception_Manager_dispatch_and_resume( ef );
+}
diff --git a/spec/build/cpukit/librtemscpu.yml b/spec/build/cpukit/librtemscpu.yml
index 6f8d223f1e..5847bdecbf 100644
--- a/spec/build/cpukit/librtemscpu.yml
+++ b/spec/build/cpukit/librtemscpu.yml
@@ -496,6 +496,8 @@ links:
uid: objdl
- role: build-dependency
uid: objdrvmgr
+- role: build-dependency
+ uid: objexceptionmapping
- role: build-dependency
uid: objgnat
- role: build-dependency
diff --git a/spec/build/cpukit/objexceptionmapping.yml b/spec/build/cpukit/objexceptionmapping.yml
new file mode 100644
index 0000000000..028cc237bd
--- /dev/null
+++ b/spec/build/cpukit/objexceptionmapping.yml
@@ -0,0 +1,15 @@
+SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
+build-type: objects
+cflags: []
+copyrights:
+- Copyright (C) 2021 On-Line Applications Research (OAR)
+cppflags: []
+cxxflags: []
+enabled-by:
+- RTEMS_EXCEPTION_MANAGER
+includes: []
+install: []
+links: []
+source:
+- cpukit/score/src/exceptionmapping.c
+type: build
--
2.30.2
More information about the devel
mailing list