From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1914) id 340983858416; Wed, 1 Dec 2021 10:26:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 340983858416 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Pierre-Marie de Rodat To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-5668] [Ada] Add signal to exception mapping for RTEMS X-Act-Checkin: gcc X-Git-Author: Patrick Bernardi X-Git-Refname: refs/heads/master X-Git-Oldrev: 38df84ae8aaa0c9e753218f5b1d087e95b13c546 X-Git-Newrev: ff46a531c52c25272038fefbfeb858feeb943a51 Message-Id: <20211201102620.340983858416@sourceware.org> Date: Wed, 1 Dec 2021 10:26:20 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Dec 2021 10:26:20 -0000 https://gcc.gnu.org/g:ff46a531c52c25272038fefbfeb858feeb943a51 commit r12-5668-gff46a531c52c25272038fefbfeb858feeb943a51 Author: Patrick Bernardi 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 +#include + +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