From patchwork Fri Jun 18 19:29:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 463090 Delivered-To: patch@linaro.org Received: by 2002:a05:6638:102:0:0:0:0 with SMTP id x2csp182076jao; Fri, 18 Jun 2021 12:48:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxgSyaG4WIHykZhpSFXZ1Qt4T1/ghrtb+UZfXgO1nG5G9hOXRqJ2uEqWrp++tUSnnpjDvLP X-Received: by 2002:a92:d9c1:: with SMTP id n1mr8213321ilq.70.1624045737017; Fri, 18 Jun 2021 12:48:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624045737; cv=none; d=google.com; s=arc-20160816; b=YXoojUHjf2inV6+ZV2SBLzPRTlqu+wEOPiosR59+hOw/GU6hVj1IL3aO0iIi7pUeRw mM71jvTndjT7CyZCTIBVORSBb14AwT6dM8n+B+IqJkuxcB09oaAmCFLWZ09QUu7RJbAR cM7oye0GnIRlLPbEI42sA2bqGSgdF92gdI5CLk8mJmfGIveR1d+qDrplS1VbUWxiHsFD yeFo1JPzPq/7qFuHZ/88tuEgaoGh7Xcxim1lp2OLJDzfPi2sCwyMb0BchlgczHPXLoiK 6FKxLTdNn1vsvBh6MbjNQM4vPnPenI802wJjU5XrIALLP5xX2kSbCQuTEZ1y5cOjViXB GIKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=MOtcx8UXoEPFGOBT2e/rKGCkRm/dpzMLp9SnX27LvpM=; b=f9MWq969mTdGsULy1tk4WTthDKjETBJ9C8uCPIVHnKdgV6Pbx2T3jNCaE0BSeUh018 cJtnUqYLz11Md4UQy4+PmcEHKgv2rro4s4MlUYd2sxwJIJQLGAWVrE73BJbh1Tm3QeP2 4AYVJsboiwyecf+PnqNisCVHp3Q9VjiS/QBN6ujMcnzA1Hk85Z5rDefJtLulpzLioQwq ME9DJz8pU2ySU+5ezunFEhIcTwWSWbH/Zk/I/ln1ZlMi2dLq6ZPpK62M6osWNR+migPC 9sZZFD+8U/cd/wVk8tYZWSupSmfjlfLlrFQFysgw03NcttFPD9BI9LHTaSGY6W2ivkdD v2Xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=mcv4VK8f; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id v6si9581598iom.67.2021.06.18.12.48.56 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 18 Jun 2021 12:48:57 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=mcv4VK8f; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:50682 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1luKU4-0002qz-Es for patch@linaro.org; Fri, 18 Jun 2021 15:48:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58468) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1luKC1-0001jb-Cz for qemu-devel@nongnu.org; Fri, 18 Jun 2021 15:30:19 -0400 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]:33679) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1luKBo-0001Z0-9s for qemu-devel@nongnu.org; Fri, 18 Jun 2021 15:30:16 -0400 Received: by mail-pl1-x636.google.com with SMTP id f10so3071784plg.0 for ; Fri, 18 Jun 2021 12:30:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MOtcx8UXoEPFGOBT2e/rKGCkRm/dpzMLp9SnX27LvpM=; b=mcv4VK8fN8UZJ7lFtjj5B8HbT/akpiVAya9R9vyr5G1Xw0Md17FvMBF8mFcUox2lwc jPgun0nlsWZ7FUWhjrvPYrfxkNJ9pUG+1QJUawjHBA9PaGKdV3jfuFgQ1OD2w3w+rDD7 kSWxi2NgzF+K+ruUv8sItoBBE6KtA8FahQe9uEGEifLNnn9WVf5wRb/u61F8gCy5/gbq QhCyGEvXOflGGQ9rvPrcqinhEyrSLtE0+wrkm5AKLeYZNLhUE3EBMuli2ywiVrggZ+xv yJrxrl8UqgW5o3yQh+co+DezTeVacWQhwxPRgwE/pk1qxyvYApGrMeRvS0Rd9jbOQ/uK s46g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MOtcx8UXoEPFGOBT2e/rKGCkRm/dpzMLp9SnX27LvpM=; b=TgQPXiQfWHZuUpr84HoBqpJ76P2qRkIDm/W/R/YsptTBB4NPIqLRe3F9m6MVLQp2gY oOm7vJghbEIEbhLwpTdu368JvCFEpBSG7IayyAvPWjG/p9WVmlsSK0HTcTT2C7nRj3wH a+FBhqlHoHMdDS8YegQHHdGs6btaPTv1HmjMGfeVE37CqaJRMwk46yOeTmifbbB7be+B Xogh+lAH3V2xvc8bOAvkvamJLu7BOPVFQrHELaBuPCmkXnpXehCv080jMTOrBluSSFye BARjieQ29jp1gCmjWBnjw7MmruAKCW5DVRooiDn8zKh3R10iPhmggEcBEkFn3EZmBiao F+Kg== X-Gm-Message-State: AOAM5317N6kzAU3GTCTScj++lNwluVmrq/4SnrhpUngz2nsxO1/5chj2 nVxbfylAkE+6QVs2QLs/OQSjVd3g/aBQQQ== X-Received: by 2002:a17:902:d4c8:b029:102:715b:e3a5 with SMTP id o8-20020a170902d4c8b0290102715be3a5mr6103064plg.83.1624044603042; Fri, 18 Jun 2021 12:30:03 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id 92sm11938234pjv.29.2021.06.18.12.30.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Jun 2021 12:30:02 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 18/23] linux-user/riscv: Implement setup_sigtramp Date: Fri, 18 Jun 2021 12:29:46 -0700 Message-Id: <20210618192951.125651-19-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210618192951.125651-1-richard.henderson@linaro.org> References: <20210618192951.125651-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::636; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x636.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alistair Francis , alex.bennee@linaro.org, laurent@vivier.eu, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Create and record the rt signal trampoline. This fixes a bug wrt libgcc fallback unwinding. It expects the stack pointer to point to the siginfo_t, whereas we had inexplicably placed our private signal trampoline at the start of the signal frame instead of the end. Now moot because we have removed it from the stack frame entirely. Reviewed-by: Alistair Francis Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/riscv/target_signal.h | 2 ++ linux-user/riscv/signal.c | 22 +++++++++++++--------- 2 files changed, 15 insertions(+), 9 deletions(-) -- 2.25.1 diff --git a/linux-user/riscv/target_signal.h b/linux-user/riscv/target_signal.h index f113ba9a55..3e36fddc9d 100644 --- a/linux-user/riscv/target_signal.h +++ b/linux-user/riscv/target_signal.h @@ -15,4 +15,6 @@ typedef struct target_sigaltstack { #include "../generic/signal.h" +#define TARGET_ARCH_HAS_SIGTRAMP_PAGE 1 + #endif /* RISCV_TARGET_SIGNAL_H */ diff --git a/linux-user/riscv/signal.c b/linux-user/riscv/signal.c index 9405c7fd9a..4086dfa5d5 100644 --- a/linux-user/riscv/signal.c +++ b/linux-user/riscv/signal.c @@ -46,7 +46,6 @@ struct target_ucontext { }; struct target_rt_sigframe { - uint32_t tramp[2]; /* not in kernel, which uses VDSO instead */ struct target_siginfo info; struct target_ucontext uc; }; @@ -104,12 +103,6 @@ static void setup_ucontext(struct target_ucontext *uc, setup_sigcontext(&uc->uc_mcontext, env); } -static inline void install_sigtramp(uint32_t *tramp) -{ - __put_user(0x08b00893, tramp + 0); /* li a7, 139 = __NR_rt_sigreturn */ - __put_user(0x00000073, tramp + 1); /* ecall */ -} - void setup_rt_frame(int sig, struct target_sigaction *ka, target_siginfo_t *info, target_sigset_t *set, CPURISCVState *env) @@ -126,14 +119,13 @@ void setup_rt_frame(int sig, struct target_sigaction *ka, setup_ucontext(&frame->uc, env, set); tswap_siginfo(&frame->info, info); - install_sigtramp(frame->tramp); env->pc = ka->_sa_handler; env->gpr[xSP] = frame_addr; env->gpr[xA0] = sig; env->gpr[xA1] = frame_addr + offsetof(struct target_rt_sigframe, info); env->gpr[xA2] = frame_addr + offsetof(struct target_rt_sigframe, uc); - env->gpr[xRA] = frame_addr + offsetof(struct target_rt_sigframe, tramp); + env->gpr[xRA] = default_rt_sigreturn; return; @@ -202,3 +194,15 @@ badframe: force_sig(TARGET_SIGSEGV); return 0; } + +void setup_sigtramp(abi_ulong sigtramp_page) +{ + uint32_t *tramp = lock_user(VERIFY_WRITE, sigtramp_page, 8, 0); + assert(tramp != NULL); + + __put_user(0x08b00893, tramp + 0); /* li a7, 139 = __NR_rt_sigreturn */ + __put_user(0x00000073, tramp + 1); /* ecall */ + + default_rt_sigreturn = sigtramp_page; + unlock_user(tramp, sigtramp_page, 8); +}