From patchwork Fri Sep 24 16:59:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 514601 Delivered-To: patch@linaro.org Received: by 2002:a02:c816:0:0:0:0:0 with SMTP id p22csp1689390jao; Fri, 24 Sep 2021 10:16:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyj3UfcdQ3/adcvrPoTGqBO2nj5ydxrlcRvjgv/7VBXx1JmZX4/xQou7b8TamgcmLKR2Eg6 X-Received: by 2002:a37:62ca:: with SMTP id w193mr11817987qkb.137.1632503784870; Fri, 24 Sep 2021 10:16:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632503784; cv=none; d=google.com; s=arc-20160816; b=ae8QjSJvTNj3AQh3fzugJFsThcahCEOzuXqoggH4Icy5VzDuh6XeMUotigEBAMqD3s OV3q514Vy/XWMfpXbmOh0XFdxxBjvwiI9WOe8EuZHgKF0FA4EgF/nHTzPVwV2OkqqA+u H76h3hhPilCwrDWB+eDYvhfwnN37pJssvy+NHTpfo/+l3Hmhgpm6F/6ZCQ0SYu8XCf7p /HyY0JWomWzTwZlFeSZKO31zm2absfPd2m/lARKla/ZC3cIlKJN+C7BXaDImDgV6+ECW fLNzy8ZANyGBvL+BxLqFpuV9lKkYmOzaubdqkb2PhuTH8t30oWOWKHFuAapNqgY++zv3 AfDw== 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=TpDW54Nw8YhHP+9jPj0cxZwWHyAWvFzhUjsYMPCYrAg=; b=KReTgZfyto8C8BueJtBbW7h2/ts3/0IRigJek3QAjAhSK3tMOQX0mAOIjwcQ49YdUT JC6gordItkMLAbtZXlCHurNUHk1VgEmmLbsYzonN3Ygm8mMZIf553ve7TTeZkPOZfv6o HMAvnaQb476mh6HLg/cxwmPXTe9U15jhidb5VFvG/ChccgGs6H1ege8GxfgvbbRw/PLa qDSMp3JVj/glFzALNeLCzF7RJEqtAioIVaqPbee2X8fZv+6cyFEcDqEOfiDXo5asi79z TKoEVwEIwFNySbAjZ9Od5lmQIln1f5ilscb3PxUePAyaTQhgFuJiAr78FkdkkcFBm+v6 cfzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=xIMJ5M1D; 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 f15si958743qtg.186.2021.09.24.10.16.24 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 24 Sep 2021 10:16:24 -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=xIMJ5M1D; 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]:41160 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mTooC-0006Pt-3I for patch@linaro.org; Fri, 24 Sep 2021 13:16:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48612) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mToYA-00031g-S3 for qemu-devel@nongnu.org; Fri, 24 Sep 2021 12:59:50 -0400 Received: from mail-qk1-x733.google.com ([2607:f8b0:4864:20::733]:34472) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mToY8-00076p-Q1 for qemu-devel@nongnu.org; Fri, 24 Sep 2021 12:59:50 -0400 Received: by mail-qk1-x733.google.com with SMTP id i132so29018409qke.1 for ; Fri, 24 Sep 2021 09:59:48 -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=TpDW54Nw8YhHP+9jPj0cxZwWHyAWvFzhUjsYMPCYrAg=; b=xIMJ5M1DSDv0410bZB+xxE1p8qx9lod20d293kf53rxCA5EjFT3njJJ95x8bvOHK2A xN3BbstZM5SxiHB11evg/HZoLjt1Kpvi0zjEdVFrW7D2qyVzfc7atyWLpvbefPq5g13K 4HAdMCEZyKGwVhzsFZtowPkzJ11cgviLwdHGvkOa9A3YsWVHRbg5JOhNBQk7UP71+cfh C9yLZ+Mio/Iy9Q+t74rf9LkTNxE7cAeiCdcxtm1TJn5cGeB44VeRLzKNvswjHP2oyjp8 V81I//bgL0v96XaDVV8VrsdjvIAkv4Okwyro/IdIRhrEvgLiyGb3p9h1Q+J9oH6palB2 d4eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TpDW54Nw8YhHP+9jPj0cxZwWHyAWvFzhUjsYMPCYrAg=; b=MfuP75aw2rSNhLPWB4K1umNJw9vle2b2REmh11WwNL1dyOwsfXzD8igd34TY9Bl+7u SoT2GgPmjo01WUACW1o+42+uVNHxzcKKe7SeQBBk1VmyAU5TBW4nKn2OrTs8OAPaWuH5 VWw66wqUFSRbDB0glJcxhr6LoSjGhT1EQvbd0aYViVdCrTobQSAQH0dWfwxMI+tVGy28 8YDlrBbavgqfl2nNjdpa9GjV2euMSwt5B/zaJw4FtELoh0jBz4OrHJRi9ETqUdvkQtON ov9fhNiRX5IJAgt92AmXdienghuYlLHDPcAASSwsFsTKOSFs6BTd3sgKLaVTuGND2T/c v/Lw== X-Gm-Message-State: AOAM530IRy5OLygDolUywo2ohZLHQarPsdrdqkw/JdPhnMYj8m1OV9dJ MfOoJW4FFzzZT/qZVBuqqQoIEIywqDw2HA== X-Received: by 2002:a37:f613:: with SMTP id y19mr11365789qkj.524.1632502787902; Fri, 24 Sep 2021 09:59:47 -0700 (PDT) Received: from localhost.localdomain (cpe-24-74-129-96.carolina.res.rr.com. [24.74.129.96]) by smtp.gmail.com with ESMTPSA id r13sm7141104qkk.73.2021.09.24.09.59.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Sep 2021 09:59:47 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 26/27] linux-user/xtensa: Implement setup_sigtramp Date: Fri, 24 Sep 2021 12:59:25 -0400 Message-Id: <20210924165926.752809-27-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210924165926.752809-1-richard.henderson@linaro.org> References: <20210924165926.752809-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::733; envelope-from=richard.henderson@linaro.org; helo=mail-qk1-x733.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: peter.maydell@linaro.org, laurent@vivier.eu, Max Filippov Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Create and record the rt signal trampoline. Use it when the guest does not use SA_RESTORER. Reviewed-by: Max Filippov Signed-off-by: Richard Henderson --- linux-user/xtensa/target_signal.h | 2 ++ linux-user/xtensa/signal.c | 56 ++++++++++++++++++++----------- 2 files changed, 38 insertions(+), 20 deletions(-) -- 2.25.1 Reviewed-by: Philippe Mathieu-Daudé diff --git a/linux-user/xtensa/target_signal.h b/linux-user/xtensa/target_signal.h index c60bf656f6..1c7ee73154 100644 --- a/linux-user/xtensa/target_signal.h +++ b/linux-user/xtensa/target_signal.h @@ -20,4 +20,6 @@ typedef struct target_sigaltstack { #include "../generic/signal.h" +#define TARGET_ARCH_HAS_SIGTRAMP_PAGE 1 + #endif diff --git a/linux-user/xtensa/signal.c b/linux-user/xtensa/signal.c index 7a3bfb92ca..81572a5fc7 100644 --- a/linux-user/xtensa/signal.c +++ b/linux-user/xtensa/signal.c @@ -128,6 +128,29 @@ static int setup_sigcontext(struct target_rt_sigframe *frame, return 1; } +static void install_sigtramp(uint8_t *tramp) +{ +#ifdef TARGET_WORDS_BIGENDIAN + /* Generate instruction: MOVI a2, __NR_rt_sigreturn */ + __put_user(0x22, &tramp[0]); + __put_user(0x0a, &tramp[1]); + __put_user(TARGET_NR_rt_sigreturn, &tramp[2]); + /* Generate instruction: SYSCALL */ + __put_user(0x00, &tramp[3]); + __put_user(0x05, &tramp[4]); + __put_user(0x00, &tramp[5]); +#else + /* Generate instruction: MOVI a2, __NR_rt_sigreturn */ + __put_user(0x22, &tramp[0]); + __put_user(0xa0, &tramp[1]); + __put_user(TARGET_NR_rt_sigreturn, &tramp[2]); + /* Generate instruction: SYSCALL */ + __put_user(0x00, &tramp[3]); + __put_user(0x50, &tramp[4]); + __put_user(0x00, &tramp[5]); +#endif +} + void setup_rt_frame(int sig, struct target_sigaction *ka, target_siginfo_t *info, target_sigset_t *set, CPUXtensaState *env) @@ -164,26 +187,9 @@ void setup_rt_frame(int sig, struct target_sigaction *ka, if (ka->sa_flags & TARGET_SA_RESTORER) { ra = ka->sa_restorer; } else { - ra = frame_addr + offsetof(struct target_rt_sigframe, retcode); -#ifdef TARGET_WORDS_BIGENDIAN - /* Generate instruction: MOVI a2, __NR_rt_sigreturn */ - __put_user(0x22, &frame->retcode[0]); - __put_user(0x0a, &frame->retcode[1]); - __put_user(TARGET_NR_rt_sigreturn, &frame->retcode[2]); - /* Generate instruction: SYSCALL */ - __put_user(0x00, &frame->retcode[3]); - __put_user(0x05, &frame->retcode[4]); - __put_user(0x00, &frame->retcode[5]); -#else - /* Generate instruction: MOVI a2, __NR_rt_sigreturn */ - __put_user(0x22, &frame->retcode[0]); - __put_user(0xa0, &frame->retcode[1]); - __put_user(TARGET_NR_rt_sigreturn, &frame->retcode[2]); - /* Generate instruction: SYSCALL */ - __put_user(0x00, &frame->retcode[3]); - __put_user(0x50, &frame->retcode[4]); - __put_user(0x00, &frame->retcode[5]); -#endif + /* Not used, but retain for ABI compatibility. */ + install_sigtramp(frame->retcode); + ra = default_rt_sigreturn; } memset(env->regs, 0, sizeof(env->regs)); env->pc = ka->_sa_handler; @@ -264,3 +270,13 @@ badframe: force_sig(TARGET_SIGSEGV); return -TARGET_QEMU_ESIGRETURN; } + +void setup_sigtramp(abi_ulong sigtramp_page) +{ + uint8_t *tramp = lock_user(VERIFY_WRITE, sigtramp_page, 6, 0); + assert(tramp != NULL); + + default_rt_sigreturn = sigtramp_page; + install_sigtramp(tramp); + unlock_user(tramp, sigtramp_page, 6); +}