From patchwork Fri Jun 18 19:29:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 463076 Delivered-To: patch@linaro.org Received: by 2002:a05:6638:102:0:0:0:0 with SMTP id x2csp173830jao; Fri, 18 Jun 2021 12:35:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyAbQH+h30Fg2sz8KsQcTGuWqcKHYLMreOfJw1j2rIYYGvxZ6niisGB+EfEIsAK+ISJD3l+ X-Received: by 2002:ab0:1e04:: with SMTP id m4mr14632119uak.15.1624044952946; Fri, 18 Jun 2021 12:35:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624044952; cv=none; d=google.com; s=arc-20160816; b=fHJntyOSiRToY8ioxZR8qnDNNM3vGolXM8s6hLIayi5RfgUOpR458jGyR726Y3P4FF 5cJ89Cooh21iZeiy2HPFmCN2azi81V2R+E2OTeQjPvJpV4kG6mvpLQr+xkKGBhADCKiB maQPazXZmZRl7AD8QOSBWtdRjLF39881zWcPFIUGRCDUjCF6dCjKsVyzugYd98hzVwpw x3nEpgASfZqR8qfB+qmw2EUVje9kj9T1mYTaBjPLizpKHdoz6j89Ia6kUEHnEEu9nbeZ RiEydOXmI8EFTv68LpxvfSIZcswETRYKYYixSvo8v4P5Ac9tubbT6tAk9blUAagxDuRz PBJg== 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=VPJAD2cXCabdkR4Ic6xpvnirr8GBcqri8kXuO3V0cnNrcNPS4zAv/tR5wD+mZwEqPF mGEp3NeCMA9QoGwmBc3HNMtrw4VR/rAK2o6dOyABsTs2T/tZZ5kK/vyq6RpDMUQPEaOh RntEEZlWIJZDdla2cRfFmKWsJxBccpuaUqiRN45DsV4bwaR9L25soemhBRzMdqN+InKa f1G9TfoF/N5MIPtluf+lcPUl9AxsMX4aTtzT8I3E3v7WNFm3DnTsOpnZVDPth/SAXYjt FNboikAuwWXOVvyOCmZGf8GD8sHbl8RaxC0DZb0JevhtFzvMF2JuDuO45W9hbKuM3Gdi U4Tw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=LnRmyAUR; 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 j13si7545448vsq.188.2021.06.18.12.35.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 18 Jun 2021 12:35:52 -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=LnRmyAUR; 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]:44690 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1luKHQ-0004eH-90 for patch@linaro.org; Fri, 18 Jun 2021 15:35:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58364) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1luKBq-0001ft-S9 for qemu-devel@nongnu.org; Fri, 18 Jun 2021 15:30:06 -0400 Received: from mail-pg1-x532.google.com ([2607:f8b0:4864:20::532]:36375) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1luKBl-0001Uj-Ta for qemu-devel@nongnu.org; Fri, 18 Jun 2021 15:30:06 -0400 Received: by mail-pg1-x532.google.com with SMTP id e33so8601786pgm.3 for ; Fri, 18 Jun 2021 12:30:01 -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=LnRmyAURUgstMs0u6vFLf8pOF4ImJsOJVCdptoR6PQTaDAmTGV7ncGfPRKn3qZdiRy 4aZXJyULOaQGJF27u06N2zasbJeolcS+U5PaanD8twwLI4BQkAM6242NeF/91awL3Wli 15wL7FYBGMc2nPbsX8Yx8mWc11JSmbvAH5XUdtDMgK+Zz1I3Qaj0OMxOMZVx33MObR1N H7cveWFE4tvzo/twU6nVgp2Dq+voquJXiuJ5eTeXn1AO9nIY7eXvi8Jjp9S9kV8rNNCw uCgRRvwhzmD6Gwk+il1wZ3dHNomezY/xjU4RnREHf5MMyzp0Mh9wdAe8I5n34iBz+47/ uBqg== 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=SxhGiH0sXxFLFuFJ2AZQYEKsM7iTYeY2MXn0MhFvI0alXq3GZs7wezqhrvDbHl3Cug g2cocxVy8xEtmgP9bGl4OZh55ytdZV+k0jusLL2f/y97b9w9RE+sJ6HN2+TBlBgEljRf eTiQJLZ2kJn1ruH8AtbnfAEoCYjeALT7tSXwFG7uaxMaKANevAoTFnG93QSRM70KnB6Z 5CyLqg4XpAyEBnYFVeBnLhxQLyGY2MWhFi1W8V79144E6Xa1mG/dlvm+bkPSHCMuOvPT XOV9kGawWeVFy/VIdI7COl43biGaRTszyx2uveZGeq4/64b5JVxWL2jew/ZrLjBLcexS PhnQ== X-Gm-Message-State: AOAM531k8O+sTxqWxLVrIRTLHLWVk3ZtKhs4Ed/S7Y1ng+54ORcHggdq Uj3DvVam3V3ycqxHofxPad7tQ0FHtSZoKw== X-Received: by 2002:aa7:808b:0:b029:2ef:cdd4:8297 with SMTP id v11-20020aa7808b0000b02902efcdd48297mr6748058pff.27.1624044600621; Fri, 18 Jun 2021 12:30:00 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id 92sm11938234pjv.29.2021.06.18.12.29.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Jun 2021 12:30:00 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 14/23] linux-user/mips: Implement setup_sigtramp Date: Fri, 18 Jun 2021 12:29:42 -0700 Message-Id: <20210618192951.125651-15-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::532; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x532.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); +}