public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-5668] [Ada] Add signal to exception mapping for RTEMS
@ 2021-12-01 10:26 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2021-12-01 10:26 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:ff46a531c52c25272038fefbfeb858feeb943a51

commit r12-5668-gff46a531c52c25272038fefbfeb858feeb943a51
Author: Patrick Bernardi <bernardi@adacore.com>
Date:   Fri Nov 12 17:55:57 2021 -0500

    [Ada] Add signal to exception mapping for RTEMS
    
    gcc/ada/
    
            * init.c: Add __gnat_error_handler and __gnat_install_handler
            for RTEMS.

Diff:
---
 gcc/ada/init.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)

diff --git a/gcc/ada/init.c b/gcc/ada/init.c
index dbd85169f9c..6c260fe7187 100644
--- a/gcc/ada/init.c
+++ b/gcc/ada/init.c
@@ -2645,6 +2645,68 @@ __gnat_install_handler (void)
   __gnat_handler_installed = 1;
 }
 
+/*****************/
+/* RTEMS Section */
+/*****************/
+
+#elif defined(__rtems__)
+
+#include <signal.h>
+#include <unistd.h>
+
+static void
+__gnat_error_handler (int sig)
+{
+  struct Exception_Data *exception;
+  const char *msg;
+
+  switch(sig)
+  {
+    case SIGFPE:
+      exception = &constraint_error;
+      msg = "SIGFPE";
+      break;
+    case SIGILL:
+      exception = &constraint_error;
+      msg = "SIGILL";
+      break;
+    case SIGSEGV:
+      exception = &storage_error;
+      msg = "erroneous memory access";
+      break;
+    case SIGBUS:
+      exception = &constraint_error;
+      msg = "SIGBUS";
+      break;
+    default:
+      exception = &program_error;
+      msg = "unhandled signal";
+    }
+
+    Raise_From_Signal_Handler (exception, msg);
+}
+
+void
+__gnat_install_handler (void)
+{
+  struct sigaction act;
+
+  act.sa_handler = __gnat_error_handler;
+  sigemptyset (&act.sa_mask);
+
+  /* Do not install handlers if interrupt state is "System".  */
+  if (__gnat_get_interrupt_state (SIGFPE) != 's')
+    sigaction (SIGFPE,  &act, NULL);
+  if (__gnat_get_interrupt_state (SIGILL) != 's')
+    sigaction (SIGILL,  &act, NULL);
+  if (__gnat_get_interrupt_state (SIGSEGV) != 's')
+    sigaction (SIGSEGV, &act, NULL);
+  if (__gnat_get_interrupt_state (SIGBUS) != 's')
+    sigaction (SIGBUS,  &act, NULL);
+
+  __gnat_handler_installed = 1;
+}
+
 #elif defined (__DJGPP__)
 
 void


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-12-01 10:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-01 10:26 [gcc r12-5668] [Ada] Add signal to exception mapping for RTEMS Pierre-Marie de Rodat

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).