From patchwork Tue Jul 6 23:49:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 470613 Delivered-To: patch@linaro.org Received: by 2002:a17:906:971a:0:0:0:0 with SMTP id k26csp5551942ejx; Tue, 6 Jul 2021 17:03:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzNjmGmYe7D0kLfF1F4niPquY2HACD9vavoerC2CfYt4khHXw2umJUmk2G0cJnzYbWMTC9c X-Received: by 2002:a05:6402:5114:: with SMTP id m20mr26599967edd.174.1625616190210; Tue, 06 Jul 2021 17:03:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625616190; cv=none; d=google.com; s=arc-20160816; b=giUrpT+iFyBN1MwopF0Yb+tJtbTmzaJFs5Jmy+Qy/Vy1RM/2EitTsPV+7RPkxE4rFP 44cAVbn+n0FfCLGdkMt429MqnmYiJ0KzV5y0QHNGNSymU5GGKsIVhgJ0Qo70oJD4+u0y Zjjz0hgx1Yqoj9WtZE2OXssiuHlA2S2qOQgGjWRO2HscLtWGnqMy4/i7TmXAWf+lVMIC 4jQiNdHWZXt78uSU1nKcRHOPnJ8gdq1twhCLZiIZxSuspwwj0gSlCO47tFYU/JQA7fuz pv3arFyDbY8hvyFKQ0ScteP0R3J25RBHlhHRTLi5vd6IFX19i22Cwlke1RXlETWlG0pg RnWA== 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=fJ2heq9/ybEPRov+oRcE6gMbBb+FglnKkmzlhd1SVGQ=; b=wGDNgjFMDEArzST9s/WR3QlMD1G2YMAaEdypsq+o6Fa1q3nPRkK+hbeONCmp35rbD8 mEgxObzdE38PpCwpzitAfwq+iWRUpvBpVYqH7t/uFfKaEE8ZN1M6VOijnZGv9EDLd8qH nuWB7mV5ThpJPs7FcaZRFpWcBM+RMGR9aOanFv/8f4M5AnxqkwXcXzhHl3OnkQSVffdj E1K4k20439iXxnqKPq+V53Vzq+WACiXzgzJ2U0z+6sJsOUrenT7db6oO/ADvzVZMsWsD xKe6AMR5r+G0ccAczjpWhJNPBY4GcB77JQDS/uh3x4OpAbofNTtoi8t/otGbQAxaCrq4 rnAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=E9K+SH4U; 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 eb13si19502674edb.245.2021.07.06.17.03.10 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Jul 2021 17:03:10 -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=E9K+SH4U; 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]:52948 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0v1x-0005bY-61 for patch@linaro.org; Tue, 06 Jul 2021 20:03:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53400) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0upD-0001hD-Ih for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:59 -0400 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]:37828) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m0up5-0006fz-SS for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:59 -0400 Received: by mail-pj1-x102d.google.com with SMTP id 22-20020a17090a0c16b0290164a5354ad0so2565252pjs.2 for ; Tue, 06 Jul 2021 16:49:51 -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=fJ2heq9/ybEPRov+oRcE6gMbBb+FglnKkmzlhd1SVGQ=; b=E9K+SH4Unbda+auBY33R347EmbKk1XZsC8gWxhGImBUvaDzupvIFTd6dJM95nUe22p wvyUmL5XKXQTfxYB9ugcD7YRohaAqfYGQt2nDl3OmUXSumWXEVlQzYXkeNwqFSlizpni D02NRXegqZIOiuAjzrwMIWWNKN6EeEWbuGeQs62fJkiRRNDuhqZBc2XIWFba+84frKM+ zNJor1SXm5HCvmoxYK06D4x9ibK7XJD7MOnxAjgs4XDan8DPeuA0pAwc/ten/kjZ8QDU 7Nb7da/eA9FbfKLimyuSXEVdyCvJ35sdxwfN9EMymhRXhE1b4ibUjxKuShEWNG1pzKvS vb+Q== 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=fJ2heq9/ybEPRov+oRcE6gMbBb+FglnKkmzlhd1SVGQ=; b=c+gxOys8Qvon7bSO8hQBg5q3N75zDCX3CD+4NNAsG8v32wnbCeipffRbgnCMc+PhYt ZkpYhgALrpafKyZ5K8QX85zwQfUABTQmlI2zkC/Zd1ww3RoZwUvN4AXBUN/ZoP72429t /SbJr9SM0/WzYQS53t0b0JxsY/wwywBAl4Pcb6K52GoETVYwgDxHt0lJhvyuPU6TOomU VMD8e5P08rSqQMomkqR9oKQA6Pto76/dLv6yNYIAyt/kL0k3eOXCsD9N6SnNvpdA+2if x/ojFp6P6q7ZncW/Nzmh4t/uHbi17ZdHSBg38y/1KZ2kf0QoaTVmx7HpIEVGC8VmEEs4 hu+Q== X-Gm-Message-State: AOAM533S4oECFTmexL3w3b/RXM/mKmOgL+TwMmHjCbBau7RR9qMeGCu4 Qxxk8ZK5r0Cz7dv3q9Gmk3VnEGtETuD8VQ== X-Received: by 2002:a17:90b:806:: with SMTP id bk6mr649448pjb.13.1625615390675; Tue, 06 Jul 2021 16:49:50 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id b3sm18058114pfi.179.2021.07.06.16.49.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 16:49:50 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 27/36] linux-user/mips: Implement setup_sigtramp Date: Tue, 6 Jul 2021 16:49:23 -0700 Message-Id: <20210706234932.356913-28-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210706234932.356913-1-richard.henderson@linaro.org> References: <20210706234932.356913-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: alex.bennee@linaro.org, laurent@vivier.eu, =?utf-8?q?Philippe_Mathieu-?= =?utf-8?b?RGF1ZMOp?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Create and record the two signal trampolines. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/mips/target_signal.h | 1 + linux-user/mips64/target_signal.h | 2 ++ linux-user/mips/signal.c | 34 ++++++++++++++++++++++--------- 3 files changed, 27 insertions(+), 10 deletions(-) -- 2.25.1 diff --git a/linux-user/mips/target_signal.h b/linux-user/mips/target_signal.h index d521765f6b..780a4ddf29 100644 --- a/linux-user/mips/target_signal.h +++ b/linux-user/mips/target_signal.h @@ -73,6 +73,7 @@ typedef struct target_sigaltstack { /* compare linux/arch/mips/kernel/signal.c:setup_frame() */ #define TARGET_ARCH_HAS_SETUP_FRAME #endif +#define TARGET_ARCH_HAS_SIGTRAMP_PAGE 1 /* bit-flags */ #define TARGET_SS_AUTODISARM (1U << 31) /* disable sas during sighandling */ diff --git a/linux-user/mips64/target_signal.h b/linux-user/mips64/target_signal.h index d857c55e4c..275e9b7f9a 100644 --- a/linux-user/mips64/target_signal.h +++ b/linux-user/mips64/target_signal.h @@ -76,4 +76,6 @@ typedef struct target_sigaltstack { /* compare linux/arch/mips/kernel/signal.c:setup_frame() */ #define TARGET_ARCH_HAS_SETUP_FRAME #endif +#define TARGET_ARCH_HAS_SIGTRAMP_PAGE 1 + #endif /* MIPS64_TARGET_SIGNAL_H */ diff --git a/linux-user/mips/signal.c b/linux-user/mips/signal.c index 7cad7526ea..a3db08bfec 100644 --- a/linux-user/mips/signal.c +++ b/linux-user/mips/signal.c @@ -208,8 +208,6 @@ void setup_frame(int sig, struct target_sigaction * ka, goto give_sigsegv; } - install_sigtramp(frame->sf_code, TARGET_NR_sigreturn); - setup_sigcontext(regs, &frame->sf_sc); for(i = 0; i < TARGET_NSIG_WORDS; i++) { @@ -230,7 +228,7 @@ void setup_frame(int sig, struct target_sigaction * ka, regs->active_tc.gpr[ 5] = 0; regs->active_tc.gpr[ 6] = frame_addr + offsetof(struct sigframe, sf_sc); regs->active_tc.gpr[29] = frame_addr; - regs->active_tc.gpr[31] = frame_addr + offsetof(struct sigframe, sf_code); + regs->active_tc.gpr[31] = default_sigreturn; /* The original kernel code sets CP0_EPC to the handler * since it returns to userland using eret * we cannot do this here, and we must set PC directly */ @@ -304,8 +302,6 @@ void setup_rt_frame(int sig, struct target_sigaction *ka, goto give_sigsegv; } - install_sigtramp(frame->rs_code, TARGET_NR_rt_sigreturn); - tswap_siginfo(&frame->rs_info, info); __put_user(0, &frame->rs_uc.tuc_flags); @@ -334,11 +330,13 @@ void setup_rt_frame(int sig, struct target_sigaction *ka, env->active_tc.gpr[ 6] = frame_addr + offsetof(struct target_rt_sigframe, rs_uc); env->active_tc.gpr[29] = frame_addr; - env->active_tc.gpr[31] = frame_addr - + offsetof(struct target_rt_sigframe, rs_code); - /* The original kernel code sets CP0_EPC to the handler - * since it returns to userland using eret - * we cannot do this here, and we must set PC directly */ + env->active_tc.gpr[31] = default_rt_sigreturn; + + /* + * The original kernel code sets CP0_EPC to the handler + * since it returns to userland using eret + * we cannot do this here, and we must set PC directly + */ env->active_tc.PC = env->active_tc.gpr[25] = ka->_sa_handler; mips_set_hflags_isa_mode_from_pc(env); unlock_user_struct(frame, frame_addr, 1); @@ -378,3 +376,19 @@ badframe: force_sig(TARGET_SIGSEGV); return -TARGET_QEMU_ESIGRETURN; } + +void setup_sigtramp(abi_ulong sigtramp_page) +{ + uint32_t *tramp = lock_user(VERIFY_WRITE, sigtramp_page, 2 * 8, 0); + assert(tramp != NULL); + +#ifdef TARGET_ARCH_HAS_SETUP_FRAME + default_sigreturn = sigtramp_page; + install_sigtramp(tramp, TARGET_NR_sigreturn); +#endif + + default_rt_sigreturn = sigtramp_page + 8; + install_sigtramp(tramp + 2, TARGET_NR_rt_sigreturn); + + unlock_user(tramp, sigtramp_page, 2 * 8); +}