public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Pierre-Marie de Rodat <pmderodat@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-611] [Ada] arm-qnx-7.1: stack-checking and sigtramp implementation
Date: Wed, 18 May 2022 08:45:09 +0000 (GMT)	[thread overview]
Message-ID: <20220518084509.8DA263857830@sourceware.org> (raw)

https://gcc.gnu.org/g:6999173410bac7ed473dcb0261a24bb5d50aeea6

commit r13-611-g6999173410bac7ed473dcb0261a24bb5d50aeea6
Author: Doug Rupp <rupp@adacore.com>
Date:   Fri Apr 8 11:28:48 2022 -0700

    [Ada] arm-qnx-7.1: stack-checking and sigtramp implementation
    
    Rewrite and base on VxWorks RTP implementation.
    
    gcc/ada/
    
            * sigtramp-arm-qnx.c: Rewrite.

Diff:
---
 gcc/ada/sigtramp-arm-qnx.c | 79 +++++++++++++++++++++-------------------------
 1 file changed, 36 insertions(+), 43 deletions(-)

diff --git a/gcc/ada/sigtramp-arm-qnx.c b/gcc/ada/sigtramp-arm-qnx.c
index 4d359d7b290..24a3b64dbf1 100644
--- a/gcc/ada/sigtramp-arm-qnx.c
+++ b/gcc/ada/sigtramp-arm-qnx.c
@@ -6,7 +6,7 @@
  *                                                                          *
  *                         Asm Implementation File                          *
  *                                                                          *
- *           Copyright (C) 2015-2022, Free Software Foundation, Inc.        *
+ *         Copyright (C) 2011-2022, Free Software Foundation, Inc.          *
  *                                                                          *
  * GNAT is free software;  you can  redistribute it  and/or modify it under *
  * terms of the  GNU General Public License as published  by the Free Soft- *
@@ -33,49 +33,44 @@
  * ARM-QNX version of the __gnat_sigtramp service *
  **************************************************/
 
+#include <signal.h>
 #include <ucontext.h>
 
 #include "sigtramp.h"
 /* See sigtramp.h for a general explanation of functionality.  */
 
-/* ----------------------
-   -- General comments --
-   ----------------------
+/* -------------------------------------------
+   -- Prototypes for our internal asm stubs --
+   -------------------------------------------
 
-   Stubs are generated from toplevel asms,
-   The general idea is to establish CFA as the sigcontext
-   and state where to find the registers as offsets from there.
+   Eventhough our symbols will remain local, the prototype claims "extern"
+   and not "static" to prevent compiler complaints about a symbol used but
+   never defined.  */
 
-   Note that the registers we "restore" here are those to which we have
-   direct access through the system sigcontext structure, which includes
-   only a partial set of the non-volatiles ABI-wise.  */
+/* sigtramp stub providing ARM unwinding info for common registers.  */
 
-/* -----------------------------------------
-   -- Protypes for our internal asm stubs --
-   -----------------------------------------
-
-   The registers are expected to be at SIGCONTEXT + 12 (reference the
-   sicontext structure in asm/sigcontext.h which describes the first
-   3 * 4byte fields.)  Even though our symbols will remain local, the
-   prototype claims "extern" and not "static" to prevent compiler complaints
-   about a symbol used but never defined.  */
+extern void __gnat_sigtramp_common
+(int signo, void *siginfo, void *sigcontext,
+ __sigtramphandler_t * handler, void * sc_pregs);
 
-/* sigtramp stub providing unwind info for common registers.  */
+/* -------------------------------------
+   -- Common interface implementation --
+   -------------------------------------
 
-extern void __gnat_sigtramp_common
-  (int signo, void *siginfo, void *sigcontext,
-   __sigtramphandler_t * handler);
+   We enforce optimization to minimize the overhead of the extra layer.  */
 
 void __gnat_sigtramp (int signo, void *si, void *sc,
-                      __sigtramphandler_t * handler)
+		      __sigtramphandler_t * handler)
      __attribute__((optimize(2)));
 
-void __gnat_sigtramp (int signo, void *si, void *ucontext,
-                      __sigtramphandler_t * handler)
+void __gnat_sigtramp (int signo, void *si, void *sc,
+		      __sigtramphandler_t * handler)
 {
-  struct sigcontext *mcontext = &((ucontext_t *) ucontext)->uc_mcontext;
+  mcontext_t *mcontext = &((ucontext_t *) sc)->uc_mcontext;
 
-  __gnat_sigtramp_common (signo, si, mcontext, handler);
+  /* Pass MCONTEXT in the fifth position so that the assembly code can find
+     it at the same stack location as SC_PREGS.  */
+  __gnat_sigtramp_common (signo, si, mcontext, handler, &mcontext->cpu);
 }
 
 /* asm string construction helpers.  */
@@ -98,27 +93,25 @@ void __gnat_sigtramp (int signo, void *si, void *ucontext,
 /* Trampoline body block
    ---------------------  */
 
+/* The 5 arguments passed to __gnat_sigtramp_common are located in:
+   - r0-r2: arguments to pass on to the actual handler
+   - r3: the actual handler
+   - sp: the address of the reg set to restore
+   All we have to do then is to instruct the unwinder to restore the registers
+   from the value in VSP. Unwinder instructions are executed backwards, so we
+   1- instruct to pop r2 from the VSP (.save {r2})
+   2- move the VSP to the address pointed to by r2 (.movsp r2)
+   3- restore all registers from there. (.save {r0-r15})
+   Once the unwinding instructions are set, we just need to call the handler
+   as r0-r2 are already properly set.
+*/
 #define SIGTRAMP_BODY \
 CR("") \
-TCR("# Allocate frame and also save r2 which is the argument register") \
-TCR("# containing the sigcontext, so that we can restore it during") \
-TCR("# unwinding and thereby load the rest of the desired context.") \
-TCR("stmfd	sp!, {r2, r3, lr}") \
-TCR("# The unwinder undo's these operations in reverse order so starting") \
-TCR("# from bottom, restore r2 from the current vsp location, move r2 into") \
-TCR("# the vsp, add 12 bytes to get the start of the register save area") \
-TCR("# then restore the 15 general purpose registers of the frame which") \
-TCR("# raised the signal.") \
 TCR(".save {r0-r15}") \
-TCR(".pad #12") \
 TCR(".movsp r2") \
 TCR(".save {r2}") \
-TCR("# Call the real handler. The signo, siginfo and sigcontext") \
-TCR("# arguments are the same as those we received in r0, r1 and r2.") \
 TCR("blx	r3") \
-TCR("# Restore our callee-saved items, release our frame and return") \
-TCR("# (should never get here!).") \
-TCR("ldmfd	sp, {r2, r3, pc}")
+TCR("# No return here.")
 
 /* Symbol definition block
    -----------------------  */


                 reply	other threads:[~2022-05-18  8:45 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220518084509.8DA263857830@sourceware.org \
    --to=pmderodat@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).