From patchwork Wed Jun 16 01:12:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 461318 Delivered-To: patch@linaro.org Received: by 2002:a02:735a:0:0:0:0:0 with SMTP id a26csp100743jae; Tue, 15 Jun 2021 18:22:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzA2634VOaR5tcYyr2rWXgxhtGw75hen6R0by4eXGY3sdO88UUWPK3p3dvj3+3Z1VhV7XaK X-Received: by 2002:ac8:7768:: with SMTP id h8mr2516300qtu.235.1623806538703; Tue, 15 Jun 2021 18:22:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623806538; cv=none; d=google.com; s=arc-20160816; b=dRC0Gy6otOAeeEJUawpBVpKWxmbLRoMelrNlgi5zzcQjhCE/V9S+cXJybgX68rQSLO mEFZztdcgd4lH/jopSXshzBFh3+vVvTB2Loa7vWiYFS9qMzMg3enxkI5lBmYnIi/PeF+ vgjlmIXbj4qS8TaaQ7Jc/P6peBC2nUK4e4MKwHNtGJQE0Lru70j8U2iI2Z7mgi/8HZj/ S/BXLwjrd0izEftc7J6RVeYjfaciOX3rS+m5B/pp0GBH4kwyypqN9Lvo3G/Pkgbnoy7t 8xw2t6L/T11xkMQWtADj6iKJSkouLzy0TZYLQrc08arSN28GR8DQkBtILW6z9g9cq81p D6TQ== 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=7P6aK0Xlt7Wqq1Vaq4hTczk8Q+yU+JFeTGVvn77Fon4=; b=TVqdQe+uuxGOuTRGQ7BPCTOkShBdhkN+Z2e/tnKkXr8jTXGGpOQO0pCnN0Z50aLuou o8kWAlGvGjADfzdQBqgBTl/wqmvdVKoXTR2GW5sDOcwxkDc9q04+QUG9vcv13rKP4Z/d 7xbycEjwKwRLYSZvDP7VqRM8i5cZJ/NRXrTttq7nZfEW2PpLrlSLnBOGIqdrlVu/t/je VIl5RONDgviPT0RE+Ad4RxQzEvgLwEV9fz0IshUqOpTIB/QQFEfj3ysCms+sKx/q/M1W VDPN0ZPPFDbr0VbPZo7St1KwPI6JZ12vahaoLc1Kcn73WKIJ7+BEdLxSvOgNg6j3F++c 9wBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=jfvOgkml; 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 ey1si473832qvb.213.2021.06.15.18.22.18 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 15 Jun 2021 18:22:18 -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=jfvOgkml; 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]:33622 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltKG1-0007tf-VT for patch@linaro.org; Tue, 15 Jun 2021 21:22:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52294) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltK6a-0005fi-MZ for qemu-devel@nongnu.org; Tue, 15 Jun 2021 21:12:34 -0400 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]:46009) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltK6Q-0008TR-Ac for qemu-devel@nongnu.org; Tue, 15 Jun 2021 21:12:32 -0400 Received: by mail-pj1-x102d.google.com with SMTP id z3-20020a17090a3983b029016bc232e40bso748667pjb.4 for ; Tue, 15 Jun 2021 18:12:21 -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=7P6aK0Xlt7Wqq1Vaq4hTczk8Q+yU+JFeTGVvn77Fon4=; b=jfvOgkmlTDRzoViZrZSiMCHBd/PCUZMjWLXHppbBIDAP8JsUvQyTN5q0yqGlvsKeJ7 88z2ViNQ9EBMDGT3Gv68KBnmyjmSVCem/JMJFQpsyuoWORqsLOdZ5P27U5LQH4kgPyDJ AkR1uVKqhifFD+mIlADbQkcXZoZ6Ktv9IuJhnucddp6wux3yQU9hQFwN2UwKy8RyWHoO XZeMhf4sjervF9v2dtA/1HXV9/9vkzd02SYp7qv6FkY5owYOdgwHP9gO8g2wfu5Aqr9h ExdmaMDuczlnoK7IpfBLYO9rwewxZ5d9rjGXkz0RlzBI7H7TBO8PwHLl6lVNHA3QJSEP /MRg== 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=7P6aK0Xlt7Wqq1Vaq4hTczk8Q+yU+JFeTGVvn77Fon4=; b=gF8UNzvseuBUp1MR8xpaWYwvGpJi5DmlJpfgZ+CVkdZHUokc0+U4ME442w76zC+wE/ is7c5Y32KlT4DiCeg5lwB1jEY2jl9I80NdsUaXQjcjLWwLqCmUSitOpIYTLLIut3BksI bFfgFnK/+LbIJsdzYKFAv/SzoR9vdRPEUnCupmJ9vVt4YUvflczv5KSjmyuRNdXVYJBa gUNEwVOE8XmtVofBH2iau0GvjW446K6KzXuCmrfofMbtSmAANIZFf27CgKgLlGXpGFFn SoowmBrf8dWvVrmRTPmnmknOLi3xpUGhaP2qYOJz1jKkgqVMxQND8V3kvKxpT7OqYiPs MnHg== X-Gm-Message-State: AOAM530jZowUiy4czQegGxo4yvxsfMcCXdZIYs/f6uIWRo744X3diyT3 qEM92BYu+sIEcdnLLUQhiZdAExlHiwGcWA== X-Received: by 2002:a17:902:d701:b029:115:d3d8:94d2 with SMTP id w1-20020a170902d701b0290115d3d894d2mr6634336ply.23.1623805941084; Tue, 15 Jun 2021 18:12:21 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id y18sm305297pgk.53.2021.06.15.18.12.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 18:12:20 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 16/21] linux-user/riscv: Implement setup_sigtramp Date: Tue, 15 Jun 2021 18:12:04 -0700 Message-Id: <20210616011209.1446045-17-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210616011209.1446045-1-richard.henderson@linaro.org> References: <20210616011209.1446045-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102d; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102d.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: qemu-riscv@nongnu.org, alex.bennee@linaro.org, laurent@vivier.eu 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. Cc: qemu-riscv@nongnu.org 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 Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Alistair Francis 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); +}