From patchwork Wed May 18 08:43:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Marie de Rodat X-Patchwork-Id: 54148 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B212E385780C for ; Wed, 18 May 2022 09:10:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B212E385780C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1652865051; bh=zE30DYYFb+62zeEaxxMaRbpw/KUp9FBFfBhTxKYM9y4=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=sc5s95xYOh4iOvQUmdFIyrsMo7M60coPEV3MbvnRIxQ2ET90cTasWlccsaM5awmZe 818l7Pq4OwiGhwOhE+fxAmTVn7QlzbCFAL0YsFKgtN1O3k7N36tt3DDEypgql2xfZx NA/x5tIy1j/6y+aPNXKjM9xXGjLTzVGidD06imEo= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by sourceware.org (Postfix) with ESMTPS id 97B033857C48 for ; Wed, 18 May 2022 08:43:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 97B033857C48 Received: by mail-wr1-x42c.google.com with SMTP id e28so1052406wra.10 for ; Wed, 18 May 2022 01:43:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=zE30DYYFb+62zeEaxxMaRbpw/KUp9FBFfBhTxKYM9y4=; b=U9ESzTJx5irLvv0n2dDtyrn1V1ae6W0OUv2XdimPHT3X/N3fUP7qGKiquzqu0hoWzx Nb7Vzy2qeoc9klcsGhrqgl1C7yzLujnDzWtv2yrqSvkeJ3HX21D0n/vBQAax4/F//58a Pdbp7OLYCqbbGJ2xoFuaxEBQCGLOLKuuJtLUOSf1ZHl8Bl8Y+2QBJEFVpyv4wpyc/P6N 9zWG3f7nDZNESV+x0Vr6by2PNp9y7LAawbIxFq1LomakAXPU2dqtPYv4o7Bxlnhtl+QM O3EQ3TgwDVGtNb1vYzUg4SMmJBMmJsLxf+X+xZc+w3jv2uCtrGnjKWEvTDGQRqnb4s/n DAFw== X-Gm-Message-State: AOAM530JaghnBSzN1vgK+V3NuRppZqLeSPPC4Mx63JmbYhAj68TAQRSI 0nRnKuwa5rG0Uz1wIjuEF49y2MxVaV5EhQ== X-Google-Smtp-Source: ABdhPJwqe6dzo7DcuFgqJ0qrgOrAIMufshTqlZpbgmLSp6IlQejigqFF08IKGvlNkN3EG62pKszFIw== X-Received: by 2002:a5d:618f:0:b0:20c:ffa0:95a8 with SMTP id j15-20020a5d618f000000b0020cffa095a8mr15495914wru.306.1652863409870; Wed, 18 May 2022 01:43:29 -0700 (PDT) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id u8-20020a5d6da8000000b0020c5253d8e5sm1405559wrs.49.2022.05.18.01.43.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 May 2022 01:43:29 -0700 (PDT) Date: Wed, 18 May 2022 08:43:28 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] arm-qnx-7.1: stack-checking and sigtramp implementation Message-ID: <20220518084328.GA3382952@adacore.com> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Pierre-Marie de Rodat via Gcc-patches From: Pierre-Marie de Rodat Reply-To: Pierre-Marie de Rodat Cc: Doug Rupp Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Rewrite and base on VxWorks RTP implementation. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sigtramp-arm-qnx.c: Rewrite. diff --git a/gcc/ada/sigtramp-arm-qnx.c b/gcc/ada/sigtramp-arm-qnx.c --- 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 #include #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 ----------------------- */