From nobody Mon Feb 9 15:42:53 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1619366349; cv=none; d=zohomail.com; s=zohoarc; b=Bt7FN3WrjRbm2ZtqBrwY9LxSO9nFCAe0eSnWNAsBT9O9B9DiEm4K/SO/+sx7durWgo1u+n6wfKtBW2anBrlCHQdXjwTZhS6Gi2RFr3+UhXMBLSQFwpyZ82gUacjqJH9lOueQiqjWf+QUK8B4jaMlKce4m83Ky8k1UekLg998aSs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619366349; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=m1XPgsGFLSBeMhD9gxrYKvEpAYHWWlmlzUSgBmaIZRg=; b=LCvnKS726ZmHNS7qUPZOfUUKyaPLjNebYexkZntVxLtpJRyxHZDJSMWwi/jB+wGqD+j3LUa2ggLjvCQTK7CsCVPlrHUp9Sfr5GtyKqQ16fY1T26KVXjuKUU570cxkt21F0BESj0Mr1SWEie6Lwiwo3w9eBh5DAWjnlq9B38yGHA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1619366349151167.94630815504547; Sun, 25 Apr 2021 08:59:09 -0700 (PDT) Received: from localhost ([::1]:49390 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lahA4-0000p2-3O for importer@patchew.org; Sun, 25 Apr 2021 11:59:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48470) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lah8v-0007qx-Ot for qemu-devel@nongnu.org; Sun, 25 Apr 2021 11:57:57 -0400 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]:39505) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lah8q-00039o-P6 for qemu-devel@nongnu.org; Sun, 25 Apr 2021 11:57:57 -0400 Received: by mail-pj1-x1036.google.com with SMTP id gq23-20020a17090b1057b0290151869af68bso3743370pjb.4 for ; Sun, 25 Apr 2021 08:57:52 -0700 (PDT) Received: from localhost.localdomain ([71.212.144.24]) by smtp.gmail.com with ESMTPSA id u21sm8594717pfm.89.2021.04.25.08.57.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Apr 2021 08:57:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=m1XPgsGFLSBeMhD9gxrYKvEpAYHWWlmlzUSgBmaIZRg=; b=qguwD2UtgcGxcKg8kqD3Vxq96DRc1jEMFm2hNGZRma9Vx1BARHi78swrHbA1z3GOl2 SvE5auHnnyxcLw6MhSxzbZdo8oEAYv+o0e12rfkqCDlhULp2B63PpLIxgpP8ybceTgGq dKRhf4cHN0Th5WlgoENfpgF3SZe6/FCkG4rZZFnxrp+BT52rw86RN7Dpf4bt2q6uTUYg XzjDis/rXJQFxh5tJP6DIzmWxQPBG0rzAr+GYCK+uixx2/FOxjv2V5j0OraFZlOh7FIR MFbrhlcmOrkyGzxsIRUNW5MEFPDk69C/Rg8nHQQidS8DZHKJEfJ7M8VhoiKE2lrfv7sb FSww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=m1XPgsGFLSBeMhD9gxrYKvEpAYHWWlmlzUSgBmaIZRg=; b=N8DjElZu/SFDN54lKiQJO9lW0QxyHWrRl3rigex+WJbFD8w35F3tKazy3BgqRAgpQ2 e2KZiXLR4d14brxbJOGRjOp/emQGtUViUwb7PDnw3L4uHeoSRlCoKplOTj1F50dJ92eo 10Bu5AqLf4IMPFZU1PkGFke2xueidZZNDlyTUQGQVhei/+ZG08oXj6wfFD5BVLsInkZc gFrla3GR9Yq4dp0XnAt5/DrS89CGzJJcoklAgYPtPeOtAT4EJNjy1qbCepFY+xPuT6H/ HFJqmogv/oW/cF4tuR0QNJYyTxjF7jMhfKDRUGkD/9t2eKaQC6VgxNwgUVTD4/0Q8fev M6nw== X-Gm-Message-State: AOAM533j/ipGYl1z+lAZ6IeVmZ6b53xMl2KPqnE0ODylfX7S8aOMd5oI oVCx8TwxLS1eIO1o8lTH0rdYhXCaxQdRTg== X-Google-Smtp-Source: ABdhPJz5HNMMfBtYjwzBsL8y+f7ytyNUj6FClh3q354U+qTLTL1QnYVDPyS4tHkdpC2s40mRtI+0Mg== X-Received: by 2002:a17:902:6946:b029:e9:4dcc:9966 with SMTP id k6-20020a1709026946b02900e94dcc9966mr13940772plt.6.1619366271420; Sun, 25 Apr 2021 08:57:51 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 1/8] linux-user: Split out target_restore_altstack Date: Sun, 25 Apr 2021 08:57:42 -0700 Message-Id: <20210425155749.896330-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210425155749.896330-1-richard.henderson@linaro.org> References: <20210425155749.896330-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1036; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1036.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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Content-Type: text/plain; charset="utf-8" Create a function to match target_save_altstack. Fix some style and unlock issues in do_sigaltstack. Signed-off-by: Richard Henderson --- linux-user/signal-common.h | 1 + linux-user/signal.c | 115 +++++++++++++++++++++---------------- 2 files changed, 66 insertions(+), 50 deletions(-) diff --git a/linux-user/signal-common.h b/linux-user/signal-common.h index 1df1068552..34b963af9a 100644 --- a/linux-user/signal-common.h +++ b/linux-user/signal-common.h @@ -24,6 +24,7 @@ int on_sig_stack(unsigned long sp); int sas_ss_flags(unsigned long sp); abi_ulong target_sigsp(abi_ulong sp, struct target_sigaction *ka); void target_save_altstack(target_stack_t *uss, CPUArchState *env); +abi_long target_restore_altstack(target_stack_t *uss, abi_ulong sp); =20 static inline void target_sigemptyset(target_sigset_t *set) { diff --git a/linux-user/signal.c b/linux-user/signal.c index 44a5012930..306f3edec5 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -297,6 +297,50 @@ void target_save_altstack(target_stack_t *uss, CPUArch= State *env) __put_user(ts->sigaltstack_used.ss_size, &uss->ss_size); } =20 +abi_long target_restore_altstack(target_stack_t *uss, abi_ulong sp) +{ + TaskState *ts =3D (TaskState *)thread_cpu->opaque; + size_t minstacksize =3D TARGET_MINSIGSTKSZ; + target_stack_t ss; + +#if defined(TARGET_PPC64) + /* ELF V2 for PPC64 has a 4K minimum stack size for signal handlers */ + struct image_info *image =3D ts->info; + if (get_ppc64_abi(image) > 1) { + minstacksize =3D 4096; + } +#endif + + __get_user(ss.ss_sp, &uss->ss_sp); + __get_user(ss.ss_size, &uss->ss_size); + __get_user(ss.ss_flags, &uss->ss_flags); + + if (on_sig_stack(sp)) { + return -TARGET_EPERM; + } + + switch (ss.ss_flags) { + default: + return -TARGET_EINVAL; + + case TARGET_SS_DISABLE: + ss.ss_size =3D 0; + ss.ss_sp =3D 0; + break; + + case TARGET_SS_ONSTACK: + case 0: + if (ss.ss_size < minstacksize) { + return -TARGET_ENOMEM; + } + break; + } + + ts->sigaltstack_used.ss_sp =3D ss.ss_sp; + ts->sigaltstack_used.ss_size =3D ss.ss_size; + return 0; +} + /* siginfo conversion */ =20 static inline void host_to_target_siginfo_noswap(target_siginfo_t *tinfo, @@ -758,73 +802,44 @@ static void host_signal_handler(int host_signum, sigi= nfo_t *info, /* compare linux/kernel/signal.c:do_sigaltstack() */ abi_long do_sigaltstack(abi_ulong uss_addr, abi_ulong uoss_addr, abi_ulong= sp) { - int ret; - struct target_sigaltstack oss; - TaskState *ts =3D (TaskState *)thread_cpu->opaque; + target_stack_t oss, *uoss =3D NULL; + abi_long ret =3D -TARGET_EFAULT; =20 - /* XXX: test errors */ - if(uoss_addr) - { + if (uoss_addr) { + TaskState *ts =3D (TaskState *)thread_cpu->opaque; + + /* Verify writability now, but do not alter user memory yet. */ + if (!lock_user_struct(VERIFY_WRITE, uoss, uoss_addr, 0)) { + goto out; + } __put_user(ts->sigaltstack_used.ss_sp, &oss.ss_sp); __put_user(ts->sigaltstack_used.ss_size, &oss.ss_size); __put_user(sas_ss_flags(sp), &oss.ss_flags); } =20 - if(uss_addr) - { - struct target_sigaltstack *uss; - struct target_sigaltstack ss; - size_t minstacksize =3D TARGET_MINSIGSTKSZ; + if (uss_addr) { + target_stack_t *uss; =20 -#if defined(TARGET_PPC64) - /* ELF V2 for PPC64 has a 4K minimum stack size for signal handler= s */ - struct image_info *image =3D ((TaskState *)thread_cpu->opaque)->in= fo; - if (get_ppc64_abi(image) > 1) { - minstacksize =3D 4096; - } -#endif - - ret =3D -TARGET_EFAULT; if (!lock_user_struct(VERIFY_READ, uss, uss_addr, 1)) { goto out; } - __get_user(ss.ss_sp, &uss->ss_sp); - __get_user(ss.ss_size, &uss->ss_size); - __get_user(ss.ss_flags, &uss->ss_flags); - unlock_user_struct(uss, uss_addr, 0); - - ret =3D -TARGET_EPERM; - if (on_sig_stack(sp)) + ret =3D target_restore_altstack(uss, sp); + if (ret) { goto out; - - ret =3D -TARGET_EINVAL; - if (ss.ss_flags !=3D TARGET_SS_DISABLE - && ss.ss_flags !=3D TARGET_SS_ONSTACK - && ss.ss_flags !=3D 0) - goto out; - - if (ss.ss_flags =3D=3D TARGET_SS_DISABLE) { - ss.ss_size =3D 0; - ss.ss_sp =3D 0; - } else { - ret =3D -TARGET_ENOMEM; - if (ss.ss_size < minstacksize) { - goto out; - } } - - ts->sigaltstack_used.ss_sp =3D ss.ss_sp; - ts->sigaltstack_used.ss_size =3D ss.ss_size; } =20 if (uoss_addr) { - ret =3D -TARGET_EFAULT; - if (copy_to_user(uoss_addr, &oss, sizeof(oss))) - goto out; + memcpy(uoss, &oss, sizeof(oss)); + unlock_user_struct(uoss, uoss_addr, 1); + uoss =3D NULL; } - ret =3D 0; -out: + + out: + if (uoss) { + unlock_user_struct(uoss, uoss_addr, 0); + } return ret; } =20 --=20 2.25.1 From nobody Mon Feb 9 15:42:53 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1619366594; cv=none; d=zohomail.com; s=zohoarc; b=ht3SX4YYjiLaMdPkM2M5l/wI0tCZxOUikdd5OwcECc8wLem7nTHmTIsJQU8JP66Rs4isxCX5YNRF/tfbbUt3ggJ+MDp7CJo0hfFBnf774sh7EK0k5tji9tmToZQeIP3ojSutgslRITEEdp0VUKCBe8u/1p0VIny4WRdJMQJ5zjE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619366594; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=I/QSpFJojVKD9zlGg6U9x9sUX8bwKBgn7ApEGuKeRY8=; b=oINII6N9IMpqVFIw8CZW+BCFxP+lL/HCM1TfsMLwxWN/iYzC8oVT9qsvpWbk/FBiRGh9746ekslwOpFmYstpRw3k9zwEHigttd9EPxHSo3QMYkmJlJj2way4r5xuN7E4QLUDse7kcgebBcrrSDliMdadQaKftKpiPQH+gtkGHN8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1619366594183186.20573711026668; Sun, 25 Apr 2021 09:03:14 -0700 (PDT) Received: from localhost ([::1]:56528 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lahE0-0004ER-T8 for importer@patchew.org; Sun, 25 Apr 2021 12:03:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48524) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lah8x-0007s9-8m for qemu-devel@nongnu.org; Sun, 25 Apr 2021 11:57:59 -0400 Received: from mail-pg1-x52c.google.com ([2607:f8b0:4864:20::52c]:47015) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lah8r-0003AF-EO for qemu-devel@nongnu.org; Sun, 25 Apr 2021 11:57:59 -0400 Received: by mail-pg1-x52c.google.com with SMTP id 31so6562661pgn.13 for ; Sun, 25 Apr 2021 08:57:52 -0700 (PDT) Received: from localhost.localdomain ([71.212.144.24]) by smtp.gmail.com with ESMTPSA id u21sm8594717pfm.89.2021.04.25.08.57.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Apr 2021 08:57:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=I/QSpFJojVKD9zlGg6U9x9sUX8bwKBgn7ApEGuKeRY8=; b=FTPqJv8vRnySxsYyn4LMKtD/S53jeay05YLnEBHoC22yoTBwZ2nrWdNpcrffT+diOo 676unh6QwP+qo9VsmxIWibZ++7tnj/no4tDWDrAjfFUL6cjSRttk5mQQ/hsW1m1Zq9Pa xmvZjddG4NE55YWyCHkDj97zmDGgy/rl6CDLchHcVVlEhLMbVCryYpaKXJNEFh0lCcjh rm1XhdiZPYaNtt8tkl7TEVW/BqT9PrSHjoyoIRnj2HSohj9r7zVgDRuc9yaZa87RGuxD hqB38WZuQz6+8PB5X2F5+Mz3WxBeV/jamto/uVbmntORpcdUNVVtuKtg+iEL+YkG2SSQ C13g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=I/QSpFJojVKD9zlGg6U9x9sUX8bwKBgn7ApEGuKeRY8=; b=huAO3yX2SwoWMxi7Pz1W1kB576BBOwrkKCavL0mmldqZ5GEirEdoPGNNZUGqTLXDAd wDY58f9Dg8wy1RLHAq+6q7UAMY/lxEqU0tbwYOZf4aItmwLDoR98tPVFi11gxRoMAE9w Hetn0tSIXST+ewedSpt9wxe4oJRAj0CiI9dalRDAUBctR+jtTjAaUwobxNzFpstoCy/Z CwoslMJRljNsMaNiTLtWLn98Sls94CNZNV17BlWoMdmx0MsCUwDJyUpcKaG9dEQM4ueS +7HI/8AMY+QoIypXvy2uV8f/4MdhxYRpQkhgUiVrcwyc05hvqEiF0ireabLLl7dbqBwK 9kxw== X-Gm-Message-State: AOAM533BZnRwK+MVrowG2fkM2sYNFRAnoYovT8Wrc718F83ArVCVxeiS G5ajmuSkNYaANRDv9UGiVg3rtERNzl5r7Q== X-Google-Smtp-Source: ABdhPJws4J9u6qQDDa6LCD++F8le4dKqlmmYF2rH0ThGLcei7dOqZgMKMbYWBa6KRoAWj5pP8v0NmQ== X-Received: by 2002:a62:7d07:0:b029:21b:d1bc:f6c8 with SMTP id y7-20020a627d070000b029021bd1bcf6c8mr13604322pfc.45.1619366272051; Sun, 25 Apr 2021 08:57:52 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 2/8] linux-user: Use target_restore_altstack in all sigreturn Date: Sun, 25 Apr 2021 08:57:43 -0700 Message-Id: <20210425155749.896330-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210425155749.896330-1-richard.henderson@linaro.org> References: <20210425155749.896330-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::52c; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52c.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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Content-Type: text/plain; charset="utf-8" Note that target_restore_altstack uses the host memory pointer that we have already verified, so TARGET_EFAULT is not a possible return value. Note that using -EFAULT was a bug. Signed-off-by: Richard Henderson --- linux-user/aarch64/signal.c | 6 +----- linux-user/alpha/signal.c | 6 +----- linux-user/arm/signal.c | 9 ++------- linux-user/hexagon/signal.c | 6 +----- linux-user/hppa/signal.c | 8 +------- linux-user/i386/signal.c | 5 +---- linux-user/m68k/signal.c | 5 +---- linux-user/microblaze/signal.c | 6 +----- linux-user/mips/signal.c | 6 +----- linux-user/nios2/signal.c | 8 +------- linux-user/openrisc/signal.c | 5 +---- linux-user/ppc/signal.c | 4 +--- linux-user/riscv/signal.c | 6 +----- linux-user/s390x/signal.c | 6 ++---- linux-user/sh4/signal.c | 7 +------ linux-user/xtensa/signal.c | 6 +----- 16 files changed, 18 insertions(+), 81 deletions(-) diff --git a/linux-user/aarch64/signal.c b/linux-user/aarch64/signal.c index b591790c22..2a1b7dbcdc 100644 --- a/linux-user/aarch64/signal.c +++ b/linux-user/aarch64/signal.c @@ -561,11 +561,7 @@ long do_rt_sigreturn(CPUARMState *env) goto badframe; } =20 - if (do_sigaltstack(frame_addr + - offsetof(struct target_rt_sigframe, uc.tuc_stack), - 0, get_sp_from_cpustate(env)) =3D=3D -EFAULT) { - goto badframe; - } + target_restore_altstack(&frame->uc.tuc_stack, get_sp_from_cpustate(env= )); =20 unlock_user_struct(frame, frame_addr, 0); return -TARGET_QEMU_ESIGRETURN; diff --git a/linux-user/alpha/signal.c b/linux-user/alpha/signal.c index 3aa4b339a4..011da0a53b 100644 --- a/linux-user/alpha/signal.c +++ b/linux-user/alpha/signal.c @@ -257,11 +257,7 @@ long do_rt_sigreturn(CPUAlphaState *env) set_sigmask(&set); =20 restore_sigcontext(env, &frame->uc.tuc_mcontext); - if (do_sigaltstack(frame_addr + offsetof(struct target_rt_sigframe, - uc.tuc_stack), - 0, env->ir[IR_SP]) =3D=3D -EFAULT) { - goto badframe; - } + target_restore_altstack(&frame->uc.tuc_stack, env->ir[IR_SP]); =20 unlock_user_struct(frame, frame_addr, 0); return -TARGET_QEMU_ESIGRETURN; diff --git a/linux-user/arm/signal.c b/linux-user/arm/signal.c index f21d1535e4..b7a772302f 100644 --- a/linux-user/arm/signal.c +++ b/linux-user/arm/signal.c @@ -685,11 +685,7 @@ static int do_sigframe_return_v2(CPUARMState *env, } } =20 - if (do_sigaltstack(context_addr - + offsetof(struct target_ucontext_v2, tuc_stack), - 0, get_sp_from_cpustate(env)) =3D=3D -EFAULT) { - return 1; - } + target_restore_altstack(&uc->tuc_stack, get_sp_from_cpustate(env)); =20 #if 0 /* Send SIGTRAP if we're single-stepping */ @@ -773,8 +769,7 @@ static long do_rt_sigreturn_v1(CPUARMState *env) goto badframe; } =20 - if (do_sigaltstack(frame_addr + offsetof(struct rt_sigframe_v1, uc.tuc= _stack), 0, get_sp_from_cpustate(env)) =3D=3D -EFAULT) - goto badframe; + target_restore_altstack(&frame->uc.tuc_stack, get_sp_from_cpustate(env= )); =20 #if 0 /* Send SIGTRAP if we're single-stepping */ diff --git a/linux-user/hexagon/signal.c b/linux-user/hexagon/signal.c index fde8dc93b7..3854eb4709 100644 --- a/linux-user/hexagon/signal.c +++ b/linux-user/hexagon/signal.c @@ -260,11 +260,7 @@ long do_rt_sigreturn(CPUHexagonState *env) } =20 restore_ucontext(env, &frame->uc); - - if (do_sigaltstack(frame_addr + offsetof(struct target_rt_sigframe, - uc.uc_stack), 0, get_sp_from_cpustate(env)) =3D=3D -EFAULT) { - goto badframe; - } + target_restore_altstack(&frame->uc.uc_stack, get_sp_from_cpustate(env)= ); =20 unlock_user_struct(frame, frame_addr, 0); return -TARGET_QEMU_ESIGRETURN; diff --git a/linux-user/hppa/signal.c b/linux-user/hppa/signal.c index d1a58feeb3..578874cf27 100644 --- a/linux-user/hppa/signal.c +++ b/linux-user/hppa/signal.c @@ -187,13 +187,7 @@ long do_rt_sigreturn(CPUArchState *env) set_sigmask(&set); =20 restore_sigcontext(env, &frame->uc.tuc_mcontext); - unlock_user_struct(frame, frame_addr, 0); - - if (do_sigaltstack(frame_addr + offsetof(struct target_rt_sigframe, - uc.tuc_stack), - 0, env->gr[30]) =3D=3D -EFAULT) { - goto badframe; - } + target_restore_altstack(&frame->uc.tuc_stack, env->gr[30]); =20 unlock_user_struct(frame, frame_addr, 0); return -TARGET_QEMU_ESIGRETURN; diff --git a/linux-user/i386/signal.c b/linux-user/i386/signal.c index 9320e1d472..3a0a1546a6 100644 --- a/linux-user/i386/signal.c +++ b/linux-user/i386/signal.c @@ -581,10 +581,7 @@ long do_rt_sigreturn(CPUX86State *env) goto badframe; } =20 - if (do_sigaltstack(frame_addr + offsetof(struct rt_sigframe, uc.tuc_st= ack), 0, - get_sp_from_cpustate(env)) =3D=3D -EFAULT) { - goto badframe; - } + target_restore_altstack(&frame->uc.tuc_stack, get_sp_from_cpustate(env= )); =20 unlock_user_struct(frame, frame_addr, 0); return -TARGET_QEMU_ESIGRETURN; diff --git a/linux-user/m68k/signal.c b/linux-user/m68k/signal.c index 49ff87c77b..004b59fb61 100644 --- a/linux-user/m68k/signal.c +++ b/linux-user/m68k/signal.c @@ -400,10 +400,7 @@ long do_rt_sigreturn(CPUM68KState *env) if (target_rt_restore_ucontext(env, &frame->uc)) goto badframe; =20 - if (do_sigaltstack(frame_addr + - offsetof(struct target_rt_sigframe, uc.tuc_stack), - 0, get_sp_from_cpustate(env)) =3D=3D -EFAULT) - goto badframe; + target_restore_altstack(&frame->uc.tuc_stack, get_sp_from_cpustate(env= )); =20 unlock_user_struct(frame, frame_addr, 0); return -TARGET_QEMU_ESIGRETURN; diff --git a/linux-user/microblaze/signal.c b/linux-user/microblaze/signal.c index cf0707b556..f59a1faf47 100644 --- a/linux-user/microblaze/signal.c +++ b/linux-user/microblaze/signal.c @@ -209,11 +209,7 @@ long do_rt_sigreturn(CPUMBState *env) =20 restore_sigcontext(&frame->uc.tuc_mcontext, env); =20 - if (do_sigaltstack(frame_addr + - offsetof(struct target_rt_sigframe, uc.tuc_stack), - 0, get_sp_from_cpustate(env)) =3D=3D -EFAULT) { - goto badframe; - } + target_restore_altstack(&frame->uc.tuc_stack, get_sp_from_cpustate(env= )); =20 unlock_user_struct(frame, frame_addr, 0); return -TARGET_QEMU_ESIGRETURN; diff --git a/linux-user/mips/signal.c b/linux-user/mips/signal.c index 455a8a229a..456fa64f41 100644 --- a/linux-user/mips/signal.c +++ b/linux-user/mips/signal.c @@ -368,11 +368,7 @@ long do_rt_sigreturn(CPUMIPSState *env) set_sigmask(&blocked); =20 restore_sigcontext(env, &frame->rs_uc.tuc_mcontext); - - if (do_sigaltstack(frame_addr + - offsetof(struct target_rt_sigframe, rs_uc.tuc_stack= ), - 0, get_sp_from_cpustate(env)) =3D=3D -EFAULT) - goto badframe; + target_restore_altstack(&frame->rs_uc.tuc_stack, get_sp_from_cpustate(= env)); =20 env->active_tc.PC =3D env->CP0_EPC; mips_set_hflags_isa_mode_from_pc(env); diff --git a/linux-user/nios2/signal.c b/linux-user/nios2/signal.c index 7d535065ed..751ea88811 100644 --- a/linux-user/nios2/signal.c +++ b/linux-user/nios2/signal.c @@ -82,9 +82,7 @@ static int rt_restore_ucontext(CPUNios2State *env, struct= target_ucontext *uc, int *pr2) { int temp; - abi_ulong off, frame_addr =3D env->regs[R_SP]; unsigned long *gregs =3D uc->tuc_mcontext.gregs; - int err; =20 /* Always make any pending restarted system calls return -EINTR */ /* current->restart_block.fn =3D do_no_restart_syscall; */ @@ -130,11 +128,7 @@ static int rt_restore_ucontext(CPUNios2State *env, str= uct target_ucontext *uc, __get_user(env->regs[R_RA], &gregs[23]); __get_user(env->regs[R_SP], &gregs[28]); =20 - off =3D offsetof(struct target_rt_sigframe, uc.tuc_stack); - err =3D do_sigaltstack(frame_addr + off, 0, get_sp_from_cpustate(env)); - if (err =3D=3D -EFAULT) { - return 1; - } + target_restore_altstack(&uc->tuc_stack, get_sp_from_cpustate(env)); =20 *pr2 =3D env->regs[2]; return 0; diff --git a/linux-user/openrisc/signal.c b/linux-user/openrisc/signal.c index 232ad82b98..86f94d7f76 100644 --- a/linux-user/openrisc/signal.c +++ b/linux-user/openrisc/signal.c @@ -158,10 +158,7 @@ long do_rt_sigreturn(CPUOpenRISCState *env) set_sigmask(&set); =20 restore_sigcontext(env, &frame->uc.tuc_mcontext); - if (do_sigaltstack(frame_addr + offsetof(target_rt_sigframe, uc.tuc_st= ack), - 0, frame_addr) =3D=3D -EFAULT) { - goto badframe; - } + target_restore_altstack(&frame->uc.tuc_stack, frame_addr); =20 unlock_user_struct(frame, frame_addr, 0); return cpu_get_gpr(env, 11); diff --git a/linux-user/ppc/signal.c b/linux-user/ppc/signal.c index b78613f7c8..79f265f82e 100644 --- a/linux-user/ppc/signal.c +++ b/linux-user/ppc/signal.c @@ -656,9 +656,7 @@ long do_rt_sigreturn(CPUPPCState *env) if (do_setcontext(&rt_sf->uc, env, 1)) goto sigsegv; =20 - do_sigaltstack(rt_sf_addr - + offsetof(struct target_rt_sigframe, uc.tuc_stack), - 0, env->gpr[1]); + target_restore_altstack(&rt_sf->uc.tuc_stack, env->gpr[1]); =20 unlock_user_struct(rt_sf, rt_sf_addr, 1); return -TARGET_QEMU_ESIGRETURN; diff --git a/linux-user/riscv/signal.c b/linux-user/riscv/signal.c index 67a95dbc7b..81d1129da3 100644 --- a/linux-user/riscv/signal.c +++ b/linux-user/riscv/signal.c @@ -192,11 +192,7 @@ long do_rt_sigreturn(CPURISCVState *env) } =20 restore_ucontext(env, &frame->uc); - - if (do_sigaltstack(frame_addr + offsetof(struct target_rt_sigframe, - uc.uc_stack), 0, get_sp_from_cpustate(env)) =3D=3D -EFAULT) { - goto badframe; - } + target_restore_altstack(&frame->uc.uc_stack, get_sp_from_cpustate(env)= ); =20 unlock_user_struct(frame, frame_addr, 0); return -TARGET_QEMU_ESIGRETURN; diff --git a/linux-user/s390x/signal.c b/linux-user/s390x/signal.c index 7107c5fb53..73806f5472 100644 --- a/linux-user/s390x/signal.c +++ b/linux-user/s390x/signal.c @@ -307,10 +307,8 @@ long do_rt_sigreturn(CPUS390XState *env) goto badframe; } =20 - if (do_sigaltstack(frame_addr + offsetof(rt_sigframe, uc.tuc_stack), 0, - get_sp_from_cpustate(env)) =3D=3D -EFAULT) { - goto badframe; - } + target_restore_altstack(&frame->uc.tuc_stack, get_sp_from_cpustate(env= )); + unlock_user_struct(frame, frame_addr, 0); return -TARGET_QEMU_ESIGRETURN; =20 diff --git a/linux-user/sh4/signal.c b/linux-user/sh4/signal.c index 29c1ee30e6..684f18da58 100644 --- a/linux-user/sh4/signal.c +++ b/linux-user/sh4/signal.c @@ -323,12 +323,7 @@ long do_rt_sigreturn(CPUSH4State *regs) set_sigmask(&blocked); =20 restore_sigcontext(regs, &frame->uc.tuc_mcontext); - - if (do_sigaltstack(frame_addr + - offsetof(struct target_rt_sigframe, uc.tuc_stack), - 0, get_sp_from_cpustate(regs)) =3D=3D -EFAULT) { - goto badframe; - } + target_restore_altstack(&frame->uc.tuc_stack, get_sp_from_cpustate(reg= s)); =20 unlock_user_struct(frame, frame_addr, 0); return -TARGET_QEMU_ESIGRETURN; diff --git a/linux-user/xtensa/signal.c b/linux-user/xtensa/signal.c index 590f0313ff..22ec6cdeb9 100644 --- a/linux-user/xtensa/signal.c +++ b/linux-user/xtensa/signal.c @@ -253,12 +253,8 @@ long do_rt_sigreturn(CPUXtensaState *env) set_sigmask(&set); =20 restore_sigcontext(env, frame); + target_restore_altstack(&frame->uc.tuc_stack, get_sp_from_cpustate(env= )); =20 - if (do_sigaltstack(frame_addr + - offsetof(struct target_rt_sigframe, uc.tuc_stack), - 0, get_sp_from_cpustate(env)) =3D=3D -TARGET_EFAULT= ) { - goto badframe; - } unlock_user_struct(frame, frame_addr, 0); return -TARGET_QEMU_ESIGRETURN; =20 --=20 2.25.1 From nobody Mon Feb 9 15:42:53 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1619366349; cv=none; d=zohomail.com; s=zohoarc; b=H8oKbJ8oe8XMq4BZaI4YOULzGDZuZsPk0o2GK1fdClUIom6sidj0A/R6KJa8sfdF1MRA99Zv0+e9AaSV3vaYy3wkj2pouhVF5Gv1qAl0gHhIjOHA5mIS7Jhrz+p6pNl0gqnqocMgC6LZ4Z4sKYQMbMqAFQV968LGb0QRxfHOLzY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619366349; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=IgvkexELK5GJ0O4GQCm7etvF50WdinqYZI5Hh6LxDP8=; b=gJeu4Y7dZpRIb+MxiQ3Mez0fuievLFJWATdGOtX98YcnxrouG5eTLKHPiMTl8ECC+VgSDvNi3bqHeU1jBNe2EJfcP/2Hp4pJEOUNPJzHB9xb/Gdn3igRtqAWMgvKzfBhw8skjzoXeZ+yLUvOBdcjeXm0Z45uP3V4RQEwsmCijKM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1619366349322539.7347306745734; Sun, 25 Apr 2021 08:59:09 -0700 (PDT) Received: from localhost ([::1]:49374 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lahA4-0000oj-8d for importer@patchew.org; Sun, 25 Apr 2021 11:59:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48504) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lah8w-0007re-LO for qemu-devel@nongnu.org; Sun, 25 Apr 2021 11:57:58 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]:46666) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lah8r-0003AM-UP for qemu-devel@nongnu.org; Sun, 25 Apr 2021 11:57:58 -0400 Received: by mail-pl1-x634.google.com with SMTP id s20so11791073plr.13 for ; Sun, 25 Apr 2021 08:57:53 -0700 (PDT) Received: from localhost.localdomain ([71.212.144.24]) by smtp.gmail.com with ESMTPSA id u21sm8594717pfm.89.2021.04.25.08.57.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Apr 2021 08:57:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=IgvkexELK5GJ0O4GQCm7etvF50WdinqYZI5Hh6LxDP8=; b=jPPreAgjHdgMos9T0ha5KnqW+/CZp2iVeATt9rtPLncqW1SEb6p9v7zD4rj1H46cgW LvRKAAOAEDB8lgDPS/sJPCDT43P8PvZ5AoIn/WmuM3a+gJvpOfNLW4U/vQr0taqD2b1c BOXkLkwqXkDRjB0ZcQ5nA+JvTHc9z77CSAoTZctOd/UCk1X2ZufpDY9n9bkmr8mK4ph1 JvddAcxhNavI16/nQhQAq32SbNsDUXoMq39P2sNt/Ka1swOjKqrH5xxCBZ8iGH5xSVC4 7guDA9kA2USLbANDfRZOp8kg7FBMY9ec0Rr/jZ3kvOT4uyekILghcT9eNeYQdB3TMO9C KnIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IgvkexELK5GJ0O4GQCm7etvF50WdinqYZI5Hh6LxDP8=; b=T+zjpkJ067AfOvyg2hptyZ482/OAZQvN8lV8WJEJKLDdFoDMLu5xa+cvwvslDr8C6i QVIo0BrBsj1+LojsHzMHz3hSXH1I6KK84jPfrfmr/YmCdgG7mxwzjcTKPe3krp5z7xkZ Yb7oTUDyOGsKOFY+cJ+c2PAX9IWlcKwDiDd5+g7odiwTJdkfpNCCPw5HkDVlI2yPXJNA v4Aoi7z563RSvLFHTF+s/sWIaS8QRvr/C7nBRe89U1gy18FOWGHjrhLEv4u8p4FppaQ6 8d/CLvo4X7QLO7GxBSXLllsapNo8/cz3Z9kBvvqH4Ynj2hDdf2JSsv/rDe1XKFvFa101 WfCw== X-Gm-Message-State: AOAM533CBxOhzg62cWQkTBouhCzjJ06kAbc/W/itH/n5/eDWyKJdnPJQ M+7l7bGw5LgLBqxyVlGRtJk4/x1iF1xAAg== X-Google-Smtp-Source: ABdhPJyKByADHyOTgl4UePN4ApkDQ6gero1mz6CalA2m614BcdLePlOAvQNwETxbPjV2fccnwQft3g== X-Received: by 2002:a17:90b:88d:: with SMTP id bj13mr9555545pjb.192.1619366272598; Sun, 25 Apr 2021 08:57:52 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 3/8] linux-user: Pass CPUArchState to do_sigaltstack Date: Sun, 25 Apr 2021 08:57:44 -0700 Message-Id: <20210425155749.896330-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210425155749.896330-1-richard.henderson@linaro.org> References: <20210425155749.896330-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x634.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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Content-Type: text/plain; charset="utf-8" Now that we have exactly one call, it's easy to pass in env instead of passing in the sp value. Use target_save_altstack, which required env. Signed-off-by: Richard Henderson --- linux-user/qemu.h | 3 ++- linux-user/signal.c | 11 ++++------- linux-user/syscall.c | 3 +-- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/linux-user/qemu.h b/linux-user/qemu.h index 74e06e7121..3b0b6b75fe 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -432,7 +432,8 @@ int target_to_host_signal(int sig); int host_to_target_signal(int sig); long do_sigreturn(CPUArchState *env); long do_rt_sigreturn(CPUArchState *env); -abi_long do_sigaltstack(abi_ulong uss_addr, abi_ulong uoss_addr, abi_ulong= sp); +abi_long do_sigaltstack(abi_ulong uss_addr, abi_ulong uoss_addr, + CPUArchState *env); int do_sigprocmask(int how, const sigset_t *set, sigset_t *oldset); abi_long do_swapcontext(CPUArchState *env, abi_ulong uold_ctx, abi_ulong unew_ctx, abi_long ctx_size); diff --git a/linux-user/signal.c b/linux-user/signal.c index 306f3edec5..83891f7c47 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -800,21 +800,18 @@ static void host_signal_handler(int host_signum, sigi= nfo_t *info, =20 /* do_sigaltstack() returns target values and errnos. */ /* compare linux/kernel/signal.c:do_sigaltstack() */ -abi_long do_sigaltstack(abi_ulong uss_addr, abi_ulong uoss_addr, abi_ulong= sp) +abi_long do_sigaltstack(abi_ulong uss_addr, abi_ulong uoss_addr, + CPUArchState *env) { target_stack_t oss, *uoss =3D NULL; abi_long ret =3D -TARGET_EFAULT; =20 if (uoss_addr) { - TaskState *ts =3D (TaskState *)thread_cpu->opaque; - /* Verify writability now, but do not alter user memory yet. */ if (!lock_user_struct(VERIFY_WRITE, uoss, uoss_addr, 0)) { goto out; } - __put_user(ts->sigaltstack_used.ss_sp, &oss.ss_sp); - __put_user(ts->sigaltstack_used.ss_size, &oss.ss_size); - __put_user(sas_ss_flags(sp), &oss.ss_flags); + target_save_altstack(&oss, env); } =20 if (uss_addr) { @@ -823,7 +820,7 @@ abi_long do_sigaltstack(abi_ulong uss_addr, abi_ulong u= oss_addr, abi_ulong sp) if (!lock_user_struct(VERIFY_READ, uss, uss_addr, 1)) { goto out; } - ret =3D target_restore_altstack(uss, sp); + ret =3D target_restore_altstack(uss, get_sp_from_cpustate(env)); if (ret) { goto out; } diff --git a/linux-user/syscall.c b/linux-user/syscall.c index c7c3257f40..32a41c1387 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -11140,8 +11140,7 @@ static abi_long do_syscall1(void *cpu_env, int num,= abi_long arg1, return ret; } case TARGET_NR_sigaltstack: - return do_sigaltstack(arg1, arg2, - get_sp_from_cpustate((CPUArchState *)cpu_env= )); + return do_sigaltstack(arg1, arg2, cpu_env); =20 #ifdef CONFIG_SENDFILE #ifdef TARGET_NR_sendfile --=20 2.25.1 From nobody Mon Feb 9 15:42:53 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1619366951; cv=none; d=zohomail.com; s=zohoarc; b=LLq2xut01jL4tM/IEyzyLQgaTIL2YuR2mFCs6YThmjGMXgyBPMzE0R9LV8mswqSX7V8sAPAVs62KEdV+i4PNcR86DruHrGpHnO55wxs9uqbrpVnKphxfWII4cSo0hzZliE878K8sGxCYTK7uIVXe53dF7g2hF/n4navS8+cFLOo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619366951; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/U/fXqVt3lh/pIHwlJV9yBNaNzKgC/XqrDdH1ymUOvA=; b=Gvng2sSqODF12oC5m12edKXOSGs0BCafOmCd2C5iB8rdJh9bSPZvmMl9PqCeJIOgc3sIGF4JgPqO9Tf75fn+EsR5vBXV/76S1hzb+lIl4c3HKvfH0N6DOaXKSiZhOsCog3MLmW4EJ+JpaQpSb63+bKEWFf2jZdb0rTyJPUlnxm8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1619366951904151.04216264786248; Sun, 25 Apr 2021 09:09:11 -0700 (PDT) Received: from localhost ([::1]:43006 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lahJm-0002qL-Ba for importer@patchew.org; Sun, 25 Apr 2021 12:09:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48574) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lah8y-0007vN-Q4 for qemu-devel@nongnu.org; Sun, 25 Apr 2021 11:58:00 -0400 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]:41620) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lah8s-0003Ak-No for qemu-devel@nongnu.org; Sun, 25 Apr 2021 11:58:00 -0400 Received: by mail-pj1-x102d.google.com with SMTP id y22-20020a17090a8b16b0290150ae1a6d2bso3882730pjn.0 for ; Sun, 25 Apr 2021 08:57:54 -0700 (PDT) Received: from localhost.localdomain ([71.212.144.24]) by smtp.gmail.com with ESMTPSA id u21sm8594717pfm.89.2021.04.25.08.57.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Apr 2021 08:57:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=/U/fXqVt3lh/pIHwlJV9yBNaNzKgC/XqrDdH1ymUOvA=; b=x3DpYWSFJr4hFwUQpecPe/5b9OGjwr0dzfn5nx5z1MmmxtJBND1FfTl0hEHeJhO5GA QC4Te0znF0FDxumd8st4N516bHmQcWHvX23+U+pMMb/gUgdvqJ2fetupGU3jX2iPCocl vZOm7sgfTSvbXySg6dcCQ9JHUSnc2+RE+PUMDwwpNTi8/mPuKIfd+onuJ9QC/Eds8OPT RadZSp7vlZCPBBQtenXMvLtTc1XBp93QmvofdyOKC8os3AmlpTix+XHSLzdxu8cb/K3b nMnOlrJlWfWkfXbqPiyw3jwC9hNbnz+i019urWfWPAgOxY//P3vtKi48YqB7H/pe+TKI JHRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/U/fXqVt3lh/pIHwlJV9yBNaNzKgC/XqrDdH1ymUOvA=; b=XzN+D/npekGgSpFxcjaXW/UT/2zTzIj+dXRVvS15TKZRKNFU5S/GmvrHwVqxoyh1xn GzgR3X+uMbGp7mRkYcsdBvzJ9qHcAKTj8y75GJZZVLtGl0rd7rLzanGWpr1zjKaiSTMB igQirLeUCpddbLCAcDTwLyIQdL3QF+qHu6Ri6OwEF8dtg+9R7s+K//xROssbM7tcttIc /5IqIG7v/vr8qKrMlZJgNttdvoQCD0fYMrXLwt20XameJBj0XVY2NvW89j5Bc8oR0+2J GSQbckJr9qbuVro64+aupjP7F5aS085lj+0/f+6H/Nj2Q0Q/oLCzcMfCQCU7ZRyByaiz 63nQ== X-Gm-Message-State: AOAM532BspVcqN/stJFuYLLsXWmJHU3jzRk38qdwpUN5G4+vQk4zKXx+ /dwnmDrapKJiRweK79IifQzNNVl2thMkcw== X-Google-Smtp-Source: ABdhPJy8GlNdY8TJbqTPG8hgHX9yuE8jz8iBUL6fvu540fJtMzzdmmxy1rkzSWOc3kme3IHCf6fyTA== X-Received: by 2002:a17:902:b601:b029:eb:1207:86ec with SMTP id b1-20020a170902b601b02900eb120786ecmr14128011pls.3.1619366273262; Sun, 25 Apr 2021 08:57:53 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 4/8] linux-user: Pass CPUArchState to target_restore_altstack Date: Sun, 25 Apr 2021 08:57:45 -0700 Message-Id: <20210425155749.896330-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210425155749.896330-1-richard.henderson@linaro.org> References: <20210425155749.896330-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Content-Type: text/plain; charset="utf-8" In most cases we were already passing get_sp_from_cpustate directly to the function. In other cases, we were passing a local variable which already contained the same value. In the rest of the cases, we were passing the stack pointer out of env directly. Signed-off-by: Richard Henderson --- linux-user/signal-common.h | 2 +- linux-user/aarch64/signal.c | 2 +- linux-user/alpha/signal.c | 2 +- linux-user/arm/signal.c | 4 ++-- linux-user/hexagon/signal.c | 2 +- linux-user/hppa/signal.c | 2 +- linux-user/i386/signal.c | 2 +- linux-user/m68k/signal.c | 2 +- linux-user/microblaze/signal.c | 2 +- linux-user/mips/signal.c | 2 +- linux-user/nios2/signal.c | 2 +- linux-user/openrisc/signal.c | 2 +- linux-user/ppc/signal.c | 2 +- linux-user/riscv/signal.c | 2 +- linux-user/s390x/signal.c | 2 +- linux-user/sh4/signal.c | 2 +- linux-user/signal.c | 6 +++--- linux-user/xtensa/signal.c | 2 +- 18 files changed, 21 insertions(+), 21 deletions(-) diff --git a/linux-user/signal-common.h b/linux-user/signal-common.h index 34b963af9a..ea86328b28 100644 --- a/linux-user/signal-common.h +++ b/linux-user/signal-common.h @@ -24,7 +24,7 @@ int on_sig_stack(unsigned long sp); int sas_ss_flags(unsigned long sp); abi_ulong target_sigsp(abi_ulong sp, struct target_sigaction *ka); void target_save_altstack(target_stack_t *uss, CPUArchState *env); -abi_long target_restore_altstack(target_stack_t *uss, abi_ulong sp); +abi_long target_restore_altstack(target_stack_t *uss, CPUArchState *env); =20 static inline void target_sigemptyset(target_sigset_t *set) { diff --git a/linux-user/aarch64/signal.c b/linux-user/aarch64/signal.c index 2a1b7dbcdc..662bcd1c4e 100644 --- a/linux-user/aarch64/signal.c +++ b/linux-user/aarch64/signal.c @@ -561,7 +561,7 @@ long do_rt_sigreturn(CPUARMState *env) goto badframe; } =20 - target_restore_altstack(&frame->uc.tuc_stack, get_sp_from_cpustate(env= )); + target_restore_altstack(&frame->uc.tuc_stack, env); =20 unlock_user_struct(frame, frame_addr, 0); return -TARGET_QEMU_ESIGRETURN; diff --git a/linux-user/alpha/signal.c b/linux-user/alpha/signal.c index 011da0a53b..1129ffeea1 100644 --- a/linux-user/alpha/signal.c +++ b/linux-user/alpha/signal.c @@ -257,7 +257,7 @@ long do_rt_sigreturn(CPUAlphaState *env) set_sigmask(&set); =20 restore_sigcontext(env, &frame->uc.tuc_mcontext); - target_restore_altstack(&frame->uc.tuc_stack, env->ir[IR_SP]); + target_restore_altstack(&frame->uc.tuc_stack, env); =20 unlock_user_struct(frame, frame_addr, 0); return -TARGET_QEMU_ESIGRETURN; diff --git a/linux-user/arm/signal.c b/linux-user/arm/signal.c index b7a772302f..32b68ee302 100644 --- a/linux-user/arm/signal.c +++ b/linux-user/arm/signal.c @@ -685,7 +685,7 @@ static int do_sigframe_return_v2(CPUARMState *env, } } =20 - target_restore_altstack(&uc->tuc_stack, get_sp_from_cpustate(env)); + target_restore_altstack(&uc->tuc_stack, env); =20 #if 0 /* Send SIGTRAP if we're single-stepping */ @@ -769,7 +769,7 @@ static long do_rt_sigreturn_v1(CPUARMState *env) goto badframe; } =20 - target_restore_altstack(&frame->uc.tuc_stack, get_sp_from_cpustate(env= )); + target_restore_altstack(&frame->uc.tuc_stack, env); =20 #if 0 /* Send SIGTRAP if we're single-stepping */ diff --git a/linux-user/hexagon/signal.c b/linux-user/hexagon/signal.c index 3854eb4709..85eab5e943 100644 --- a/linux-user/hexagon/signal.c +++ b/linux-user/hexagon/signal.c @@ -260,7 +260,7 @@ long do_rt_sigreturn(CPUHexagonState *env) } =20 restore_ucontext(env, &frame->uc); - target_restore_altstack(&frame->uc.uc_stack, get_sp_from_cpustate(env)= ); + target_restore_altstack(&frame->uc.uc_stack, env); =20 unlock_user_struct(frame, frame_addr, 0); return -TARGET_QEMU_ESIGRETURN; diff --git a/linux-user/hppa/signal.c b/linux-user/hppa/signal.c index 578874cf27..0e266f472d 100644 --- a/linux-user/hppa/signal.c +++ b/linux-user/hppa/signal.c @@ -187,7 +187,7 @@ long do_rt_sigreturn(CPUArchState *env) set_sigmask(&set); =20 restore_sigcontext(env, &frame->uc.tuc_mcontext); - target_restore_altstack(&frame->uc.tuc_stack, env->gr[30]); + target_restore_altstack(&frame->uc.tuc_stack, env); =20 unlock_user_struct(frame, frame_addr, 0); return -TARGET_QEMU_ESIGRETURN; diff --git a/linux-user/i386/signal.c b/linux-user/i386/signal.c index 3a0a1546a6..8701774e37 100644 --- a/linux-user/i386/signal.c +++ b/linux-user/i386/signal.c @@ -581,7 +581,7 @@ long do_rt_sigreturn(CPUX86State *env) goto badframe; } =20 - target_restore_altstack(&frame->uc.tuc_stack, get_sp_from_cpustate(env= )); + target_restore_altstack(&frame->uc.tuc_stack, env); =20 unlock_user_struct(frame, frame_addr, 0); return -TARGET_QEMU_ESIGRETURN; diff --git a/linux-user/m68k/signal.c b/linux-user/m68k/signal.c index 004b59fb61..d06230655e 100644 --- a/linux-user/m68k/signal.c +++ b/linux-user/m68k/signal.c @@ -400,7 +400,7 @@ long do_rt_sigreturn(CPUM68KState *env) if (target_rt_restore_ucontext(env, &frame->uc)) goto badframe; =20 - target_restore_altstack(&frame->uc.tuc_stack, get_sp_from_cpustate(env= )); + target_restore_altstack(&frame->uc.tuc_stack, env); =20 unlock_user_struct(frame, frame_addr, 0); return -TARGET_QEMU_ESIGRETURN; diff --git a/linux-user/microblaze/signal.c b/linux-user/microblaze/signal.c index f59a1faf47..4c483bd8c6 100644 --- a/linux-user/microblaze/signal.c +++ b/linux-user/microblaze/signal.c @@ -209,7 +209,7 @@ long do_rt_sigreturn(CPUMBState *env) =20 restore_sigcontext(&frame->uc.tuc_mcontext, env); =20 - target_restore_altstack(&frame->uc.tuc_stack, get_sp_from_cpustate(env= )); + target_restore_altstack(&frame->uc.tuc_stack, env); =20 unlock_user_struct(frame, frame_addr, 0); return -TARGET_QEMU_ESIGRETURN; diff --git a/linux-user/mips/signal.c b/linux-user/mips/signal.c index 456fa64f41..e6be807a81 100644 --- a/linux-user/mips/signal.c +++ b/linux-user/mips/signal.c @@ -368,7 +368,7 @@ long do_rt_sigreturn(CPUMIPSState *env) set_sigmask(&blocked); =20 restore_sigcontext(env, &frame->rs_uc.tuc_mcontext); - target_restore_altstack(&frame->rs_uc.tuc_stack, get_sp_from_cpustate(= env)); + target_restore_altstack(&frame->rs_uc.tuc_stack, env); =20 env->active_tc.PC =3D env->CP0_EPC; mips_set_hflags_isa_mode_from_pc(env); diff --git a/linux-user/nios2/signal.c b/linux-user/nios2/signal.c index 751ea88811..cc3872f11d 100644 --- a/linux-user/nios2/signal.c +++ b/linux-user/nios2/signal.c @@ -128,7 +128,7 @@ static int rt_restore_ucontext(CPUNios2State *env, stru= ct target_ucontext *uc, __get_user(env->regs[R_RA], &gregs[23]); __get_user(env->regs[R_SP], &gregs[28]); =20 - target_restore_altstack(&uc->tuc_stack, get_sp_from_cpustate(env)); + target_restore_altstack(&uc->tuc_stack, env); =20 *pr2 =3D env->regs[2]; return 0; diff --git a/linux-user/openrisc/signal.c b/linux-user/openrisc/signal.c index 86f94d7f76..5c5640a284 100644 --- a/linux-user/openrisc/signal.c +++ b/linux-user/openrisc/signal.c @@ -158,7 +158,7 @@ long do_rt_sigreturn(CPUOpenRISCState *env) set_sigmask(&set); =20 restore_sigcontext(env, &frame->uc.tuc_mcontext); - target_restore_altstack(&frame->uc.tuc_stack, frame_addr); + target_restore_altstack(&frame->uc.tuc_stack, env); =20 unlock_user_struct(frame, frame_addr, 0); return cpu_get_gpr(env, 11); diff --git a/linux-user/ppc/signal.c b/linux-user/ppc/signal.c index 79f265f82e..8e1e642807 100644 --- a/linux-user/ppc/signal.c +++ b/linux-user/ppc/signal.c @@ -656,7 +656,7 @@ long do_rt_sigreturn(CPUPPCState *env) if (do_setcontext(&rt_sf->uc, env, 1)) goto sigsegv; =20 - target_restore_altstack(&rt_sf->uc.tuc_stack, env->gpr[1]); + target_restore_altstack(&rt_sf->uc.tuc_stack, env); =20 unlock_user_struct(rt_sf, rt_sf_addr, 1); return -TARGET_QEMU_ESIGRETURN; diff --git a/linux-user/riscv/signal.c b/linux-user/riscv/signal.c index 81d1129da3..9405c7fd9a 100644 --- a/linux-user/riscv/signal.c +++ b/linux-user/riscv/signal.c @@ -192,7 +192,7 @@ long do_rt_sigreturn(CPURISCVState *env) } =20 restore_ucontext(env, &frame->uc); - target_restore_altstack(&frame->uc.uc_stack, get_sp_from_cpustate(env)= ); + target_restore_altstack(&frame->uc.uc_stack, env); =20 unlock_user_struct(frame, frame_addr, 0); return -TARGET_QEMU_ESIGRETURN; diff --git a/linux-user/s390x/signal.c b/linux-user/s390x/signal.c index 73806f5472..b68b44ae7e 100644 --- a/linux-user/s390x/signal.c +++ b/linux-user/s390x/signal.c @@ -307,7 +307,7 @@ long do_rt_sigreturn(CPUS390XState *env) goto badframe; } =20 - target_restore_altstack(&frame->uc.tuc_stack, get_sp_from_cpustate(env= )); + target_restore_altstack(&frame->uc.tuc_stack, env); =20 unlock_user_struct(frame, frame_addr, 0); return -TARGET_QEMU_ESIGRETURN; diff --git a/linux-user/sh4/signal.c b/linux-user/sh4/signal.c index 684f18da58..0451e65806 100644 --- a/linux-user/sh4/signal.c +++ b/linux-user/sh4/signal.c @@ -323,7 +323,7 @@ long do_rt_sigreturn(CPUSH4State *regs) set_sigmask(&blocked); =20 restore_sigcontext(regs, &frame->uc.tuc_mcontext); - target_restore_altstack(&frame->uc.tuc_stack, get_sp_from_cpustate(reg= s)); + target_restore_altstack(&frame->uc.tuc_stack, regs); =20 unlock_user_struct(frame, frame_addr, 0); return -TARGET_QEMU_ESIGRETURN; diff --git a/linux-user/signal.c b/linux-user/signal.c index 83891f7c47..9016896dcd 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -297,7 +297,7 @@ void target_save_altstack(target_stack_t *uss, CPUArchS= tate *env) __put_user(ts->sigaltstack_used.ss_size, &uss->ss_size); } =20 -abi_long target_restore_altstack(target_stack_t *uss, abi_ulong sp) +abi_long target_restore_altstack(target_stack_t *uss, CPUArchState *env) { TaskState *ts =3D (TaskState *)thread_cpu->opaque; size_t minstacksize =3D TARGET_MINSIGSTKSZ; @@ -315,7 +315,7 @@ abi_long target_restore_altstack(target_stack_t *uss, a= bi_ulong sp) __get_user(ss.ss_size, &uss->ss_size); __get_user(ss.ss_flags, &uss->ss_flags); =20 - if (on_sig_stack(sp)) { + if (on_sig_stack(get_sp_from_cpustate(env))) { return -TARGET_EPERM; } =20 @@ -820,7 +820,7 @@ abi_long do_sigaltstack(abi_ulong uss_addr, abi_ulong u= oss_addr, if (!lock_user_struct(VERIFY_READ, uss, uss_addr, 1)) { goto out; } - ret =3D target_restore_altstack(uss, get_sp_from_cpustate(env)); + ret =3D target_restore_altstack(uss, env); if (ret) { goto out; } diff --git a/linux-user/xtensa/signal.c b/linux-user/xtensa/signal.c index 22ec6cdeb9..72771e1294 100644 --- a/linux-user/xtensa/signal.c +++ b/linux-user/xtensa/signal.c @@ -253,7 +253,7 @@ long do_rt_sigreturn(CPUXtensaState *env) set_sigmask(&set); =20 restore_sigcontext(env, frame); - target_restore_altstack(&frame->uc.tuc_stack, get_sp_from_cpustate(env= )); + target_restore_altstack(&frame->uc.tuc_stack, env); =20 unlock_user_struct(frame, frame_addr, 0); return -TARGET_QEMU_ESIGRETURN; --=20 2.25.1 From nobody Mon Feb 9 15:42:53 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1619366668; cv=none; d=zohomail.com; s=zohoarc; b=P8i0Squ8obTC556JRYaQdywnk9Y1+y+4kIMnPoXBNcAYGxiAu/1LR2gM5Qg8LyupWjv9aTGg5IvjCkOOywNpZ9MM+W1wZ48YIIgmSmR9Y3jHzMyOCooXFbFtg9bl5uEl4pH5WDM8FNoGdKm1Z8xguHU3mKLG/i0y23WeNBdmkCE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619366668; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=mKuRfL1+RzVTvK6FRkv9AXoAH3HIKU24PAMWq7TOkX8=; b=O/2hBltyODgUXWxqoAkaEg8dIjxyXilkyxe5mfeumcOdoPSbEjBhIWYJBCSwo9NpKwKeL3+8opxUOtinuJfIucxVEu86Tg56PC6tc5X/Zkz4c5gfqsqABKuPN94Ve56xqj3sUWNafkbk1p8RjLz3tpayYUq8+7EVgtC21+GlYy0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1619366668563515.6819332735365; Sun, 25 Apr 2021 09:04:28 -0700 (PDT) Received: from localhost ([::1]:59562 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lahFC-0005b0-CQ for importer@patchew.org; Sun, 25 Apr 2021 12:04:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48568) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lah8y-0007up-J3 for qemu-devel@nongnu.org; Sun, 25 Apr 2021 11:58:00 -0400 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]:33572) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lah8t-0003Bn-Hj for qemu-devel@nongnu.org; Sun, 25 Apr 2021 11:58:00 -0400 Received: by mail-pj1-x1031.google.com with SMTP id kb13-20020a17090ae7cdb02901503d67f0beso6545817pjb.0 for ; Sun, 25 Apr 2021 08:57:55 -0700 (PDT) Received: from localhost.localdomain ([71.212.144.24]) by smtp.gmail.com with ESMTPSA id u21sm8594717pfm.89.2021.04.25.08.57.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Apr 2021 08:57:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=mKuRfL1+RzVTvK6FRkv9AXoAH3HIKU24PAMWq7TOkX8=; b=Z+pcVd8XOPhkFaDZSISJhRCYYvuOlZRAio5PQkuX1TtqMIHYs8o2FD0RKpQc3JIYZy k23NoqJLbdnuAI6PjvPW3VdzwW/wub4x0zoFU3dUN3l9mBeMN+OovUOV2v12qJvggjlI d50WgqTthkDKyL3wCgBgoZ+2iCBSKuEimXn8Vb2MF6/7rbbUl4ZYzOkKoNCHInOHBMFy CjIjQlsQudqcKzBv3yt+oK+ym9i8152Z/C3yz7dTiM+CxN6nkKdcGarBUOmLj9VInoMH ohtObDuvapk5XRvyQt0kSmrglUtvF+fcRDaAO9Yw3LyIjIRk19zpNknLdn5cFg2fILPI 6FbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mKuRfL1+RzVTvK6FRkv9AXoAH3HIKU24PAMWq7TOkX8=; b=NH2uwNmNSoYoWx6QeQzX3ilDgpb3ZWx6vXW2k1itTm9/7rnvnUjZyzTG8QApfsqjLO MqSlUUdISaekCw3pLwlPmS9lKQFFcF+qWkrRoWjEi42bkl3Asx3Tp/wgGca6kQ85ubki jZI4NiBmUgCoPiyqiG8wSKUO8aAiAre0CLw+sknIqoqNDN8QqaeUN9XM8I2q951jg8tZ ITn0l0l2uEFJyqExGH3LBoXix0d3VVw2/k6ApcOrpTGdgV21GdNbJ6J5YGRuULrvXnNO 8BGyHPMVpytq/51ftHfV2fKfno5Zlnd/IFWGf6ycG5UrKhPuXQEoQYfrtHa1rjT742rq hMFg== X-Gm-Message-State: AOAM532BUr35jMDMdZHztZebLvJgiA1QkO4bZ1sjEEUQyvz7ZL4bkfLq Mh0RJYOEYHb2n16KIwlfG4eIQ2mWG6zGxQ== X-Google-Smtp-Source: ABdhPJxjS6Dr+n9sVxcqc6NsysrfxlqNhTwA/KT9D65z6vtAnOlt+jifSj+p5D8Cd83QTTsy3XvjhA== X-Received: by 2002:a17:90b:2394:: with SMTP id mr20mr7283866pjb.167.1619366273921; Sun, 25 Apr 2021 08:57:53 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 5/8] linux-user/sparc64: Move sparc64 code out of sparc32 signal.c Date: Sun, 25 Apr 2021 08:57:46 -0700 Message-Id: <20210425155749.896330-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210425155749.896330-1-richard.henderson@linaro.org> References: <20210425155749.896330-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1031; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1031.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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Content-Type: text/plain; charset="utf-8" The bulk of the code goes to sparc64/signal.c, with TARGET_SPARC_BIAS going to target_cpu.h, as we will shortly need this define beyond signal.c. Signed-off-by: Richard Henderson Reviewed-by: Warner Losh --- linux-user/sparc/target_cpu.h | 6 + linux-user/sparc/signal.c | 280 ---------------------------------- linux-user/sparc64/signal.c | 278 +++++++++++++++++++++++++++++++++ 3 files changed, 284 insertions(+), 280 deletions(-) diff --git a/linux-user/sparc/target_cpu.h b/linux-user/sparc/target_cpu.h index 1fa1011775..37f6a1d62b 100644 --- a/linux-user/sparc/target_cpu.h +++ b/linux-user/sparc/target_cpu.h @@ -20,6 +20,12 @@ #ifndef SPARC_TARGET_CPU_H #define SPARC_TARGET_CPU_H =20 +#if defined(TARGET_SPARC64) && !defined(TARGET_ABI32) +# define TARGET_STACK_BIAS 2047 +#else +# define TARGET_STACK_BIAS 0 +#endif + static inline void cpu_clone_regs_child(CPUSPARCState *env, target_ulong n= ewsp, unsigned flags) { diff --git a/linux-user/sparc/signal.c b/linux-user/sparc/signal.c index d27b7a3af7..756d983af2 100644 --- a/linux-user/sparc/signal.c +++ b/linux-user/sparc/signal.c @@ -322,283 +322,3 @@ long do_rt_sigreturn(CPUSPARCState *env) qemu_log_mask(LOG_UNIMP, "do_rt_sigreturn: not implemented\n"); return -TARGET_ENOSYS; } - -#if defined(TARGET_SPARC64) && !defined(TARGET_ABI32) -#define SPARC_MC_TSTATE 0 -#define SPARC_MC_PC 1 -#define SPARC_MC_NPC 2 -#define SPARC_MC_Y 3 -#define SPARC_MC_G1 4 -#define SPARC_MC_G2 5 -#define SPARC_MC_G3 6 -#define SPARC_MC_G4 7 -#define SPARC_MC_G5 8 -#define SPARC_MC_G6 9 -#define SPARC_MC_G7 10 -#define SPARC_MC_O0 11 -#define SPARC_MC_O1 12 -#define SPARC_MC_O2 13 -#define SPARC_MC_O3 14 -#define SPARC_MC_O4 15 -#define SPARC_MC_O5 16 -#define SPARC_MC_O6 17 -#define SPARC_MC_O7 18 -#define SPARC_MC_NGREG 19 - -typedef abi_ulong target_mc_greg_t; -typedef target_mc_greg_t target_mc_gregset_t[SPARC_MC_NGREG]; - -struct target_mc_fq { - abi_ulong mcfq_addr; - uint32_t mcfq_insn; -}; - -/* - * Note the manual 16-alignment; the kernel gets this because it - * includes a "long double qregs[16]" in the mcpu_fregs union, - * which we can't do. - */ -struct target_mc_fpu { - union { - uint32_t sregs[32]; - uint64_t dregs[32]; - //uint128_t qregs[16]; - } mcfpu_fregs; - abi_ulong mcfpu_fsr; - abi_ulong mcfpu_fprs; - abi_ulong mcfpu_gsr; - abi_ulong mcfpu_fq; - unsigned char mcfpu_qcnt; - unsigned char mcfpu_qentsz; - unsigned char mcfpu_enab; -} __attribute__((aligned(16))); -typedef struct target_mc_fpu target_mc_fpu_t; - -typedef struct { - target_mc_gregset_t mc_gregs; - target_mc_greg_t mc_fp; - target_mc_greg_t mc_i7; - target_mc_fpu_t mc_fpregs; -} target_mcontext_t; - -struct target_ucontext { - abi_ulong tuc_link; - abi_ulong tuc_flags; - target_sigset_t tuc_sigmask; - target_mcontext_t tuc_mcontext; -}; - -/* A V9 register window */ -struct target_reg_window { - abi_ulong locals[8]; - abi_ulong ins[8]; -}; - -#define TARGET_STACK_BIAS 2047 - -/* {set, get}context() needed for 64-bit SparcLinux userland. */ -void sparc64_set_context(CPUSPARCState *env) -{ - abi_ulong ucp_addr; - struct target_ucontext *ucp; - target_mc_gregset_t *grp; - target_mc_fpu_t *fpup; - abi_ulong pc, npc, tstate; - unsigned int i; - unsigned char fenab; - - ucp_addr =3D env->regwptr[WREG_O0]; - if (!lock_user_struct(VERIFY_READ, ucp, ucp_addr, 1)) { - goto do_sigsegv; - } - grp =3D &ucp->tuc_mcontext.mc_gregs; - __get_user(pc, &((*grp)[SPARC_MC_PC])); - __get_user(npc, &((*grp)[SPARC_MC_NPC])); - if ((pc | npc) & 3) { - goto do_sigsegv; - } - if (env->regwptr[WREG_O1]) { - target_sigset_t target_set; - sigset_t set; - - if (TARGET_NSIG_WORDS =3D=3D 1) { - __get_user(target_set.sig[0], &ucp->tuc_sigmask.sig[0]); - } else { - abi_ulong *src, *dst; - src =3D ucp->tuc_sigmask.sig; - dst =3D target_set.sig; - for (i =3D 0; i < TARGET_NSIG_WORDS; i++, dst++, src++) { - __get_user(*dst, src); - } - } - target_to_host_sigset_internal(&set, &target_set); - set_sigmask(&set); - } - env->pc =3D pc; - env->npc =3D npc; - __get_user(env->y, &((*grp)[SPARC_MC_Y])); - __get_user(tstate, &((*grp)[SPARC_MC_TSTATE])); - /* Honour TSTATE_ASI, TSTATE_ICC and TSTATE_XCC only */ - env->asi =3D (tstate >> 24) & 0xff; - cpu_put_ccr(env, (tstate >> 32) & 0xff); - __get_user(env->gregs[1], (&(*grp)[SPARC_MC_G1])); - __get_user(env->gregs[2], (&(*grp)[SPARC_MC_G2])); - __get_user(env->gregs[3], (&(*grp)[SPARC_MC_G3])); - __get_user(env->gregs[4], (&(*grp)[SPARC_MC_G4])); - __get_user(env->gregs[5], (&(*grp)[SPARC_MC_G5])); - __get_user(env->gregs[6], (&(*grp)[SPARC_MC_G6])); - /* Skip g7 as that's the thread register in userspace */ - - /* - * Note that unlike the kernel, we didn't need to mess with the - * guest register window state to save it into a pt_regs to run - * the kernel. So for us the guest's O regs are still in WREG_O* - * (unlike the kernel which has put them in UREG_I* in a pt_regs) - * and the fp and i7 are still in WREG_I6 and WREG_I7 and don't - * need to be written back to userspace memory. - */ - __get_user(env->regwptr[WREG_O0], (&(*grp)[SPARC_MC_O0])); - __get_user(env->regwptr[WREG_O1], (&(*grp)[SPARC_MC_O1])); - __get_user(env->regwptr[WREG_O2], (&(*grp)[SPARC_MC_O2])); - __get_user(env->regwptr[WREG_O3], (&(*grp)[SPARC_MC_O3])); - __get_user(env->regwptr[WREG_O4], (&(*grp)[SPARC_MC_O4])); - __get_user(env->regwptr[WREG_O5], (&(*grp)[SPARC_MC_O5])); - __get_user(env->regwptr[WREG_O6], (&(*grp)[SPARC_MC_O6])); - __get_user(env->regwptr[WREG_O7], (&(*grp)[SPARC_MC_O7])); - - __get_user(env->regwptr[WREG_FP], &(ucp->tuc_mcontext.mc_fp)); - __get_user(env->regwptr[WREG_I7], &(ucp->tuc_mcontext.mc_i7)); - - fpup =3D &ucp->tuc_mcontext.mc_fpregs; - - __get_user(fenab, &(fpup->mcfpu_enab)); - if (fenab) { - abi_ulong fprs; - - /* - * We use the FPRS from the guest only in deciding whether - * to restore the upper, lower, or both banks of the FPU regs. - * The kernel here writes the FPU register data into the - * process's current_thread_info state and unconditionally - * clears FPRS and TSTATE_PEF: this disables the FPU so that the - * next FPU-disabled trap will copy the data out of - * current_thread_info and into the real FPU registers. - * QEMU doesn't need to handle lazy-FPU-state-restoring like that, - * so we always load the data directly into the FPU registers - * and leave FPRS and TSTATE_PEF alone (so the FPU stays enabled). - * Note that because we (and the kernel) always write zeroes for - * the fenab and fprs in sparc64_get_context() none of this code - * will execute unless the guest manually constructed or changed - * the context structure. - */ - __get_user(fprs, &(fpup->mcfpu_fprs)); - if (fprs & FPRS_DL) { - for (i =3D 0; i < 16; i++) { - __get_user(env->fpr[i].ll, &(fpup->mcfpu_fregs.dregs[i])); - } - } - if (fprs & FPRS_DU) { - for (i =3D 16; i < 32; i++) { - __get_user(env->fpr[i].ll, &(fpup->mcfpu_fregs.dregs[i])); - } - } - __get_user(env->fsr, &(fpup->mcfpu_fsr)); - __get_user(env->gsr, &(fpup->mcfpu_gsr)); - } - unlock_user_struct(ucp, ucp_addr, 0); - return; -do_sigsegv: - unlock_user_struct(ucp, ucp_addr, 0); - force_sig(TARGET_SIGSEGV); -} - -void sparc64_get_context(CPUSPARCState *env) -{ - abi_ulong ucp_addr; - struct target_ucontext *ucp; - target_mc_gregset_t *grp; - target_mcontext_t *mcp; - int err; - unsigned int i; - target_sigset_t target_set; - sigset_t set; - - ucp_addr =3D env->regwptr[WREG_O0]; - if (!lock_user_struct(VERIFY_WRITE, ucp, ucp_addr, 0)) { - goto do_sigsegv; - } - - memset(ucp, 0, sizeof(*ucp)); - - mcp =3D &ucp->tuc_mcontext; - grp =3D &mcp->mc_gregs; - - /* Skip over the trap instruction, first. */ - env->pc =3D env->npc; - env->npc +=3D 4; - - /* If we're only reading the signal mask then do_sigprocmask() - * is guaranteed not to fail, which is important because we don't - * have any way to signal a failure or restart this operation since - * this is not a normal syscall. - */ - err =3D do_sigprocmask(0, NULL, &set); - assert(err =3D=3D 0); - host_to_target_sigset_internal(&target_set, &set); - if (TARGET_NSIG_WORDS =3D=3D 1) { - __put_user(target_set.sig[0], - (abi_ulong *)&ucp->tuc_sigmask); - } else { - abi_ulong *src, *dst; - src =3D target_set.sig; - dst =3D ucp->tuc_sigmask.sig; - for (i =3D 0; i < TARGET_NSIG_WORDS; i++, dst++, src++) { - __put_user(*src, dst); - } - } - - __put_user(sparc64_tstate(env), &((*grp)[SPARC_MC_TSTATE])); - __put_user(env->pc, &((*grp)[SPARC_MC_PC])); - __put_user(env->npc, &((*grp)[SPARC_MC_NPC])); - __put_user(env->y, &((*grp)[SPARC_MC_Y])); - __put_user(env->gregs[1], &((*grp)[SPARC_MC_G1])); - __put_user(env->gregs[2], &((*grp)[SPARC_MC_G2])); - __put_user(env->gregs[3], &((*grp)[SPARC_MC_G3])); - __put_user(env->gregs[4], &((*grp)[SPARC_MC_G4])); - __put_user(env->gregs[5], &((*grp)[SPARC_MC_G5])); - __put_user(env->gregs[6], &((*grp)[SPARC_MC_G6])); - __put_user(env->gregs[7], &((*grp)[SPARC_MC_G7])); - - /* - * Note that unlike the kernel, we didn't need to mess with the - * guest register window state to save it into a pt_regs to run - * the kernel. So for us the guest's O regs are still in WREG_O* - * (unlike the kernel which has put them in UREG_I* in a pt_regs) - * and the fp and i7 are still in WREG_I6 and WREG_I7 and don't - * need to be fished out of userspace memory. - */ - __put_user(env->regwptr[WREG_O0], &((*grp)[SPARC_MC_O0])); - __put_user(env->regwptr[WREG_O1], &((*grp)[SPARC_MC_O1])); - __put_user(env->regwptr[WREG_O2], &((*grp)[SPARC_MC_O2])); - __put_user(env->regwptr[WREG_O3], &((*grp)[SPARC_MC_O3])); - __put_user(env->regwptr[WREG_O4], &((*grp)[SPARC_MC_O4])); - __put_user(env->regwptr[WREG_O5], &((*grp)[SPARC_MC_O5])); - __put_user(env->regwptr[WREG_O6], &((*grp)[SPARC_MC_O6])); - __put_user(env->regwptr[WREG_O7], &((*grp)[SPARC_MC_O7])); - - __put_user(env->regwptr[WREG_FP], &(mcp->mc_fp)); - __put_user(env->regwptr[WREG_I7], &(mcp->mc_i7)); - - /* - * We don't write out the FPU state. This matches the kernel's - * implementation (which has the code for doing this but - * hidden behind an "if (fenab)" where fenab is always 0). - */ - - unlock_user_struct(ucp, ucp_addr, 1); - return; -do_sigsegv: - unlock_user_struct(ucp, ucp_addr, 1); - force_sig(TARGET_SIGSEGV); -} -#endif diff --git a/linux-user/sparc64/signal.c b/linux-user/sparc64/signal.c index 170ebac232..d27e049c2a 100644 --- a/linux-user/sparc64/signal.c +++ b/linux-user/sparc64/signal.c @@ -16,4 +16,282 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, see . */ + #include "../sparc/signal.c" + +#define SPARC_MC_TSTATE 0 +#define SPARC_MC_PC 1 +#define SPARC_MC_NPC 2 +#define SPARC_MC_Y 3 +#define SPARC_MC_G1 4 +#define SPARC_MC_G2 5 +#define SPARC_MC_G3 6 +#define SPARC_MC_G4 7 +#define SPARC_MC_G5 8 +#define SPARC_MC_G6 9 +#define SPARC_MC_G7 10 +#define SPARC_MC_O0 11 +#define SPARC_MC_O1 12 +#define SPARC_MC_O2 13 +#define SPARC_MC_O3 14 +#define SPARC_MC_O4 15 +#define SPARC_MC_O5 16 +#define SPARC_MC_O6 17 +#define SPARC_MC_O7 18 +#define SPARC_MC_NGREG 19 + +typedef abi_ulong target_mc_greg_t; +typedef target_mc_greg_t target_mc_gregset_t[SPARC_MC_NGREG]; + +struct target_mc_fq { + abi_ulong mcfq_addr; + uint32_t mcfq_insn; +}; + +/* + * Note the manual 16-alignment; the kernel gets this because it + * includes a "long double qregs[16]" in the mcpu_fregs union, + * which we can't do. + */ +struct target_mc_fpu { + union { + uint32_t sregs[32]; + uint64_t dregs[32]; + } mcfpu_fregs; + abi_ulong mcfpu_fsr; + abi_ulong mcfpu_fprs; + abi_ulong mcfpu_gsr; + abi_ulong mcfpu_fq; + unsigned char mcfpu_qcnt; + unsigned char mcfpu_qentsz; + unsigned char mcfpu_enab; +} __attribute__((aligned(16))); +typedef struct target_mc_fpu target_mc_fpu_t; + +typedef struct { + target_mc_gregset_t mc_gregs; + target_mc_greg_t mc_fp; + target_mc_greg_t mc_i7; + target_mc_fpu_t mc_fpregs; +} target_mcontext_t; + +struct target_ucontext { + abi_ulong tuc_link; + abi_ulong tuc_flags; + target_sigset_t tuc_sigmask; + target_mcontext_t tuc_mcontext; +}; + +/* A V9 register window */ +struct target_reg_window { + abi_ulong locals[8]; + abi_ulong ins[8]; +}; + +/* {set, get}context() needed for 64-bit SparcLinux userland. */ +void sparc64_set_context(CPUSPARCState *env) +{ + abi_ulong ucp_addr; + struct target_ucontext *ucp; + target_mc_gregset_t *grp; + target_mc_fpu_t *fpup; + abi_ulong pc, npc, tstate; + unsigned int i; + unsigned char fenab; + + ucp_addr =3D env->regwptr[WREG_O0]; + if (!lock_user_struct(VERIFY_READ, ucp, ucp_addr, 1)) { + goto do_sigsegv; + } + grp =3D &ucp->tuc_mcontext.mc_gregs; + __get_user(pc, &((*grp)[SPARC_MC_PC])); + __get_user(npc, &((*grp)[SPARC_MC_NPC])); + if ((pc | npc) & 3) { + goto do_sigsegv; + } + if (env->regwptr[WREG_O1]) { + target_sigset_t target_set; + sigset_t set; + + if (TARGET_NSIG_WORDS =3D=3D 1) { + __get_user(target_set.sig[0], &ucp->tuc_sigmask.sig[0]); + } else { + abi_ulong *src, *dst; + src =3D ucp->tuc_sigmask.sig; + dst =3D target_set.sig; + for (i =3D 0; i < TARGET_NSIG_WORDS; i++, dst++, src++) { + __get_user(*dst, src); + } + } + target_to_host_sigset_internal(&set, &target_set); + set_sigmask(&set); + } + env->pc =3D pc; + env->npc =3D npc; + __get_user(env->y, &((*grp)[SPARC_MC_Y])); + __get_user(tstate, &((*grp)[SPARC_MC_TSTATE])); + /* Honour TSTATE_ASI, TSTATE_ICC and TSTATE_XCC only */ + env->asi =3D (tstate >> 24) & 0xff; + cpu_put_ccr(env, (tstate >> 32) & 0xff); + __get_user(env->gregs[1], (&(*grp)[SPARC_MC_G1])); + __get_user(env->gregs[2], (&(*grp)[SPARC_MC_G2])); + __get_user(env->gregs[3], (&(*grp)[SPARC_MC_G3])); + __get_user(env->gregs[4], (&(*grp)[SPARC_MC_G4])); + __get_user(env->gregs[5], (&(*grp)[SPARC_MC_G5])); + __get_user(env->gregs[6], (&(*grp)[SPARC_MC_G6])); + /* Skip g7 as that's the thread register in userspace */ + + /* + * Note that unlike the kernel, we didn't need to mess with the + * guest register window state to save it into a pt_regs to run + * the kernel. So for us the guest's O regs are still in WREG_O* + * (unlike the kernel which has put them in UREG_I* in a pt_regs) + * and the fp and i7 are still in WREG_I6 and WREG_I7 and don't + * need to be written back to userspace memory. + */ + __get_user(env->regwptr[WREG_O0], (&(*grp)[SPARC_MC_O0])); + __get_user(env->regwptr[WREG_O1], (&(*grp)[SPARC_MC_O1])); + __get_user(env->regwptr[WREG_O2], (&(*grp)[SPARC_MC_O2])); + __get_user(env->regwptr[WREG_O3], (&(*grp)[SPARC_MC_O3])); + __get_user(env->regwptr[WREG_O4], (&(*grp)[SPARC_MC_O4])); + __get_user(env->regwptr[WREG_O5], (&(*grp)[SPARC_MC_O5])); + __get_user(env->regwptr[WREG_O6], (&(*grp)[SPARC_MC_O6])); + __get_user(env->regwptr[WREG_O7], (&(*grp)[SPARC_MC_O7])); + + __get_user(env->regwptr[WREG_FP], &(ucp->tuc_mcontext.mc_fp)); + __get_user(env->regwptr[WREG_I7], &(ucp->tuc_mcontext.mc_i7)); + + fpup =3D &ucp->tuc_mcontext.mc_fpregs; + + __get_user(fenab, &(fpup->mcfpu_enab)); + if (fenab) { + abi_ulong fprs; + + /* + * We use the FPRS from the guest only in deciding whether + * to restore the upper, lower, or both banks of the FPU regs. + * The kernel here writes the FPU register data into the + * process's current_thread_info state and unconditionally + * clears FPRS and TSTATE_PEF: this disables the FPU so that the + * next FPU-disabled trap will copy the data out of + * current_thread_info and into the real FPU registers. + * QEMU doesn't need to handle lazy-FPU-state-restoring like that, + * so we always load the data directly into the FPU registers + * and leave FPRS and TSTATE_PEF alone (so the FPU stays enabled). + * Note that because we (and the kernel) always write zeroes for + * the fenab and fprs in sparc64_get_context() none of this code + * will execute unless the guest manually constructed or changed + * the context structure. + */ + __get_user(fprs, &(fpup->mcfpu_fprs)); + if (fprs & FPRS_DL) { + for (i =3D 0; i < 16; i++) { + __get_user(env->fpr[i].ll, &(fpup->mcfpu_fregs.dregs[i])); + } + } + if (fprs & FPRS_DU) { + for (i =3D 16; i < 32; i++) { + __get_user(env->fpr[i].ll, &(fpup->mcfpu_fregs.dregs[i])); + } + } + __get_user(env->fsr, &(fpup->mcfpu_fsr)); + __get_user(env->gsr, &(fpup->mcfpu_gsr)); + } + unlock_user_struct(ucp, ucp_addr, 0); + return; + + do_sigsegv: + unlock_user_struct(ucp, ucp_addr, 0); + force_sig(TARGET_SIGSEGV); +} + +void sparc64_get_context(CPUSPARCState *env) +{ + abi_ulong ucp_addr; + struct target_ucontext *ucp; + target_mc_gregset_t *grp; + target_mcontext_t *mcp; + int err; + unsigned int i; + target_sigset_t target_set; + sigset_t set; + + ucp_addr =3D env->regwptr[WREG_O0]; + if (!lock_user_struct(VERIFY_WRITE, ucp, ucp_addr, 0)) { + goto do_sigsegv; + } + + memset(ucp, 0, sizeof(*ucp)); + + mcp =3D &ucp->tuc_mcontext; + grp =3D &mcp->mc_gregs; + + /* Skip over the trap instruction, first. */ + env->pc =3D env->npc; + env->npc +=3D 4; + + /* + * If we're only reading the signal mask then do_sigprocmask() + * is guaranteed not to fail, which is important because we don't + * have any way to signal a failure or restart this operation since + * this is not a normal syscall. + */ + err =3D do_sigprocmask(0, NULL, &set); + assert(err =3D=3D 0); + host_to_target_sigset_internal(&target_set, &set); + if (TARGET_NSIG_WORDS =3D=3D 1) { + __put_user(target_set.sig[0], (abi_ulong *)&ucp->tuc_sigmask); + } else { + abi_ulong *src, *dst; + src =3D target_set.sig; + dst =3D ucp->tuc_sigmask.sig; + for (i =3D 0; i < TARGET_NSIG_WORDS; i++, dst++, src++) { + __put_user(*src, dst); + } + } + + __put_user(sparc64_tstate(env), &((*grp)[SPARC_MC_TSTATE])); + __put_user(env->pc, &((*grp)[SPARC_MC_PC])); + __put_user(env->npc, &((*grp)[SPARC_MC_NPC])); + __put_user(env->y, &((*grp)[SPARC_MC_Y])); + __put_user(env->gregs[1], &((*grp)[SPARC_MC_G1])); + __put_user(env->gregs[2], &((*grp)[SPARC_MC_G2])); + __put_user(env->gregs[3], &((*grp)[SPARC_MC_G3])); + __put_user(env->gregs[4], &((*grp)[SPARC_MC_G4])); + __put_user(env->gregs[5], &((*grp)[SPARC_MC_G5])); + __put_user(env->gregs[6], &((*grp)[SPARC_MC_G6])); + __put_user(env->gregs[7], &((*grp)[SPARC_MC_G7])); + + /* + * Note that unlike the kernel, we didn't need to mess with the + * guest register window state to save it into a pt_regs to run + * the kernel. So for us the guest's O regs are still in WREG_O* + * (unlike the kernel which has put them in UREG_I* in a pt_regs) + * and the fp and i7 are still in WREG_I6 and WREG_I7 and don't + * need to be fished out of userspace memory. + */ + __put_user(env->regwptr[WREG_O0], &((*grp)[SPARC_MC_O0])); + __put_user(env->regwptr[WREG_O1], &((*grp)[SPARC_MC_O1])); + __put_user(env->regwptr[WREG_O2], &((*grp)[SPARC_MC_O2])); + __put_user(env->regwptr[WREG_O3], &((*grp)[SPARC_MC_O3])); + __put_user(env->regwptr[WREG_O4], &((*grp)[SPARC_MC_O4])); + __put_user(env->regwptr[WREG_O5], &((*grp)[SPARC_MC_O5])); + __put_user(env->regwptr[WREG_O6], &((*grp)[SPARC_MC_O6])); + __put_user(env->regwptr[WREG_O7], &((*grp)[SPARC_MC_O7])); + + __put_user(env->regwptr[WREG_FP], &(mcp->mc_fp)); + __put_user(env->regwptr[WREG_I7], &(mcp->mc_i7)); + + /* + * We don't write out the FPU state. This matches the kernel's + * implementation (which has the code for doing this but + * hidden behind an "if (fenab)" where fenab is always 0). + */ + + unlock_user_struct(ucp, ucp_addr, 1); + return; + + do_sigsegv: + unlock_user_struct(ucp, ucp_addr, 1); + force_sig(TARGET_SIGSEGV); +} --=20 2.25.1 From nobody Mon Feb 9 15:42:53 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1619366592; cv=none; d=zohomail.com; s=zohoarc; b=Xy2oKQOidPpVIu6aEOo2LqvSgD+0l7Q7YmZMhMPR6beMTtY/eHioUamVNEn+Jpsxz1zJUM8+YsIjAT7LsTyyWjelT3XmRIYM/Qnz0tH7ETZTh3HxWjw2xmR/kI5S/MVEJ3MrtlJEHPv8LO//6mzUSyKlZTgeRmL+NY+k1YUDHss= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619366592; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=KAt4KJIdZ2Rn7oZ7gMKlRXoCjHm7a4NbLhrIC4Pyqtg=; b=nVkBD+pvmeBihI5iOfjZ57QBD5DQWeopMeBznuHibUAKhQCDjn56DoTZyxTEPrXjrt71E1/GZmw92WzSrdPp0IIVywc3ctuTZZ0sFRvJXT/l1ShJgGjPLKKyfYbi2nWnFk1cq35JZx731U4KOsqARledASLWe8eHx14TIH/zwL8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1619366592196728.7821721128519; Sun, 25 Apr 2021 09:03:12 -0700 (PDT) Received: from localhost ([::1]:56374 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lahDy-00049j-Rl for importer@patchew.org; Sun, 25 Apr 2021 12:03:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48534) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lah8x-0007sL-Df for qemu-devel@nongnu.org; Sun, 25 Apr 2021 11:57:59 -0400 Received: from mail-pg1-x52f.google.com ([2607:f8b0:4864:20::52f]:40651) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lah8t-0003C2-NT for qemu-devel@nongnu.org; Sun, 25 Apr 2021 11:57:59 -0400 Received: by mail-pg1-x52f.google.com with SMTP id b17so1471167pgh.7 for ; Sun, 25 Apr 2021 08:57:55 -0700 (PDT) Received: from localhost.localdomain ([71.212.144.24]) by smtp.gmail.com with ESMTPSA id u21sm8594717pfm.89.2021.04.25.08.57.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Apr 2021 08:57:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=KAt4KJIdZ2Rn7oZ7gMKlRXoCjHm7a4NbLhrIC4Pyqtg=; b=UWxhOvA8OCBF5EmNxAuMWGwQDQxgPCUd5EoGG1vWuagNKaGnDWH7/79qc4ilClffV+ 1y+U/XAQ5SMP4XuwQL7KxanOgyud/ouPu8y15ku47SlBhuLNgxHKz4yNJ44T8n0hR3ZL VWaJNBgvioRk17mHkXXu5nuagJG7jH/mgEHhBVKJ3i5cC0F8TzNoqV5J0+ZLdrVlU9cc W6KXwPViqyZwCFr7nukf2QmlRhYglXlFguQ1eAU5RvGFsNgu8ZryK4dgjwuNlMOMKvVM ItcmG4iyhUN5Z247gPFeRcgqwpPlJbgCWg3qHcCcrUg2EqwIcU+yRb4RtSK275waYqX6 2b8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KAt4KJIdZ2Rn7oZ7gMKlRXoCjHm7a4NbLhrIC4Pyqtg=; b=ZsSY/UKeNNRP4JPTWWsPgUHxLYQGk+CY9rEwuH0QIbU+xZ3LVXl1olPCIQgiZDPjGE 7pw2zQ2jUKrg4adZoP2cvBAkaWtLQyyCF87Z7yjbs75TBRZ1bcX18U1/mxtr+woZV24P k4MfUbB9pids8l6yhe16dkv4FLmOYC5/fy0MQDYb4SFJxFmZiagsr3ZVq5kRJvjaaOah /WnbpTY1PmTHwZJ5mgguRFQuQ0xaQjLe16kXiSfc0c+CNQHGYQdE3G/Y3Jl1VHegwT/Z zAIY7C7uFlZqCiMPd+deWlvfcNo3iXsdSMfSO6xSq77Hb/MsJzzntY73qZp05egU6mb+ rmYQ== X-Gm-Message-State: AOAM533DjLGL6EtPFg1sJr8vXXnTKQvz8DHRMvK8on6dsVGNN0v/nOKe 4XguUsNLNinDwpN0A1i/nvnmkNyM9CVk7w== X-Google-Smtp-Source: ABdhPJy5vbwrhlqQ2Y/Ahu8523zg7ku3u6eIBgvETi/S3fHG7aSkdInLTgRxj/I3bz3i1l7acAevEQ== X-Received: by 2002:a63:344:: with SMTP id 65mr12948598pgd.24.1619366274508; Sun, 25 Apr 2021 08:57:54 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 6/8] linux-user/sparc: Clean up init_thread Date: Sun, 25 Apr 2021 08:57:47 -0700 Message-Id: <20210425155749.896330-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210425155749.896330-1-richard.henderson@linaro.org> References: <20210425155749.896330-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::52f; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52f.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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Content-Type: text/plain; charset="utf-8" Share code between sparc32 and sparc64, removing a bit of pointless difference wrt psr/tstate. Use sizeof(abi_ulong) for allocating initial register window. Use TARGET_STACK_BIAS. Signed-off-by: Richard Henderson --- linux-user/elfload.c | 33 +++++---------------------------- 1 file changed, 5 insertions(+), 28 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index c6731013fd..cd8b81103f 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -663,48 +663,25 @@ static uint32_t get_elf_hwcap2(void) =20 #define ELF_CLASS ELFCLASS64 #define ELF_ARCH EM_SPARCV9 - -#define STACK_BIAS 2047 - -static inline void init_thread(struct target_pt_regs *regs, - struct image_info *infop) -{ -#ifndef TARGET_ABI32 - regs->tstate =3D 0; -#endif - regs->pc =3D infop->entry; - regs->npc =3D regs->pc + 4; - regs->y =3D 0; -#ifdef TARGET_ABI32 - regs->u_regs[14] =3D infop->start_stack - 16 * 4; -#else - if (personality(infop->personality) =3D=3D PER_LINUX32) - regs->u_regs[14] =3D infop->start_stack - 16 * 4; - else - regs->u_regs[14] =3D infop->start_stack - 16 * 8 - STACK_BIAS; -#endif -} - #else #define ELF_START_MMAP 0x80000000 #define ELF_HWCAP (HWCAP_SPARC_FLUSH | HWCAP_SPARC_STBAR | HWCAP_SPARC_SW= AP \ | HWCAP_SPARC_MULDIV) - #define ELF_CLASS ELFCLASS32 #define ELF_ARCH EM_SPARC +#endif /* TARGET_SPARC64 */ =20 static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop) { - regs->psr =3D 0; + /* Note that target_cpu_copy_regs does not read psr/tstate. */ regs->pc =3D infop->entry; regs->npc =3D regs->pc + 4; regs->y =3D 0; - regs->u_regs[14] =3D infop->start_stack - 16 * 4; + regs->u_regs[14] =3D (infop->start_stack - 16 * sizeof(abi_ulong) + - TARGET_STACK_BIAS); } - -#endif -#endif +#endif /* TARGET_SPARC */ =20 #ifdef TARGET_PPC =20 --=20 2.25.1 From nobody Mon Feb 9 15:42:53 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1619366769; cv=none; d=zohomail.com; s=zohoarc; b=lepx/VzHNJnzdJuKCzM/kD5k97RYKy7AI0ItrSOnuUvs0534tN4IFrUamfk6JWeK7WQEjfncAkCgQCvXUZ5dWWZ8mZT5MBA9fW6sizfe4UciHwqtmxAdPUnoQ1y67huCOqTcX73Oxp/dy/Xktkx4hwMJRydwiZgNVrAGbU93Gg0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619366769; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=u30xwcxCy80ZK6dyM8pP2MsdoEwOxGc5lWNn0kKyZ7Y=; b=GsTSTyRqO9TtUVmEDlnwVhIa6m13YrAoA+3Gdjce0u7KfOwOk3jpHhsaiOcNoCYcpHIt2ZWgthxt6ZLXssbCqCe1Npnuhfh2lL7IX1cdf7GQcgBDvhHr77Zq3tb6Z5ndUU+gnycmlSjJcL7D7gXCjBbNAzF274XbBXVR3VHDTyY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1619366769600738.4013245449785; Sun, 25 Apr 2021 09:06:09 -0700 (PDT) Received: from localhost ([::1]:35728 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lahGq-0007cj-KA for importer@patchew.org; Sun, 25 Apr 2021 12:06:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48550) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lah8x-0007tY-Vw for qemu-devel@nongnu.org; Sun, 25 Apr 2021 11:58:00 -0400 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]:54824) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lah8u-0003CD-6L for qemu-devel@nongnu.org; Sun, 25 Apr 2021 11:57:59 -0400 Received: by mail-pj1-x1031.google.com with SMTP id t13so1533769pji.4 for ; Sun, 25 Apr 2021 08:57:55 -0700 (PDT) Received: from localhost.localdomain ([71.212.144.24]) by smtp.gmail.com with ESMTPSA id u21sm8594717pfm.89.2021.04.25.08.57.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Apr 2021 08:57:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=u30xwcxCy80ZK6dyM8pP2MsdoEwOxGc5lWNn0kKyZ7Y=; b=m9CQoiLD4uDA4FJghKpyCBIm7sBX73p8hx43Wu56hgU2Joz607/5W8YwUC6uP2tYTU cnMKTGjZjdvWctkFta1b6e39DzqFwhyQxcBSVjNtUPWPx7dVh0+o7Yhr2JZcgEYez5+L ICcSYCT8fy/EukgcdqzcYbIRPT6ij8ukbmL6NV40qvbt2eJmrmvDRL7E9besB3FBjXzp tSZEUl+9hsZTDF8xZAdP3eKPgagcobGzW2f0rgZYJSvTKcaSuVRGgtEUuIozT6VbEsRD FPY8Hjc5M3bC/q72B3UU4Gw17atKS36Ef+ipfXrtJ8mlSg9P/zZ2MCI0msec6uosE6iZ lMvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=u30xwcxCy80ZK6dyM8pP2MsdoEwOxGc5lWNn0kKyZ7Y=; b=o/uTzf/VnCDzOQk1cOGBJZEv+7PlYAniexlB5nBmnHXwL12gTkIc0PNZGpj3oyWoRK JDXqIjlkooXz4ZfKNlWYFuzluD9lITzrR+LCGAf+iF4wv/t0gL5Yeak5EoOJT4A1rt0h uKvry2uKgVTiKa4sXmEfCT9h6lSe7tnnP0A4BRgCegZubwhoF4p7wKJT1+JOz4c9wyZ7 0w3cfjghmwLGOTlNJFsvgQ9F7drgdWi3sDRROo+mexQEPWpGxthG26aPylqgWY+V/o4Y VRaDIAOsg54Zs0WYbE719WkRwi5DoFYE8Hz/vrPBEfGso9TZ1VVqcsFLmJIh5ktph0ud Awhg== X-Gm-Message-State: AOAM532CMn5b8uWRppXl6EvnpUa3Svqo8ZEQHGm8uFcZvRxBVkIUx1I6 nJtWLn2+t1fcp4kg9a5fCtymRGrEXnAH8g== X-Google-Smtp-Source: ABdhPJxpAMrSxhYSZMm9qKE+c5jfdCYVf8Bjdbb0bvj4m6Npb2aN0pc72XH0Hw/i3PZptjReH/iubw== X-Received: by 2002:a17:90a:a389:: with SMTP id x9mr17135362pjp.232.1619366274954; Sun, 25 Apr 2021 08:57:54 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 7/8] linux-user/sparc64: Include TARGET_STACK_BIAS in get_sp_from_cpustate Date: Sun, 25 Apr 2021 08:57:48 -0700 Message-Id: <20210425155749.896330-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210425155749.896330-1-richard.henderson@linaro.org> References: <20210425155749.896330-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1031; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1031.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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Content-Type: text/plain; charset="utf-8" Generic code cares about the logical stack pointer, not the physical one that has a bias applied for sparc64. Signed-off-by: Richard Henderson --- linux-user/sparc/target_cpu.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/linux-user/sparc/target_cpu.h b/linux-user/sparc/target_cpu.h index 37f6a1d62b..1f4bed50f4 100644 --- a/linux-user/sparc/target_cpu.h +++ b/linux-user/sparc/target_cpu.h @@ -46,6 +46,7 @@ static inline void cpu_clone_regs_child(CPUSPARCState *en= v, target_ulong newsp, #endif /* ??? The kernel appears to copy one stack frame to the new stack= . */ /* ??? The kernel force aligns the new stack. */ + /* Userspace provides a biased stack pointer value. */ env->regwptr[WREG_SP] =3D newsp; } =20 @@ -83,7 +84,7 @@ static inline void cpu_set_tls(CPUSPARCState *env, target= _ulong newtls) =20 static inline abi_ulong get_sp_from_cpustate(CPUSPARCState *state) { - return state->regwptr[WREG_SP]; + return state->regwptr[WREG_SP] + TARGET_STACK_BIAS; } =20 #endif --=20 2.25.1 From nobody Mon Feb 9 15:42:53 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1619366841; cv=none; d=zohomail.com; s=zohoarc; b=XbfVSXX2XsloPpXgW9GmgSCC6yNHJBCCMgg7Xub9z1XciWOc9CpR93Ti+n37PVwnszT8ARqgeMJEXbNZc7+VdGCWo0GCFu9Ul5v0kS7cQ0wBWEzImdxpejq9SVmPcRS98AnbZa60pv+Jyo3lW5mwpuXcKIugF9oHXD+6v/2/hVI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619366841; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=DKxGWYw3ADKuWB18lhyYVJwm1dNkTUIYY08wHRcIwcI=; b=UpSwClxBR++qii7Lv6vSubkkL8p4faZyEKlaupec9z9L5N98jckKnLyNiL95e6gWxRUvF2pKM7Fjjv2UYnKc+oQE1tityvqm3FaNWus3TdxmkuzqTdcsAt+pkstg5VBq8MgFBPAdDlPij4eMBBYPxW4X2o04esHcdPMeMquMvuw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1619366841184282.53219611671807; Sun, 25 Apr 2021 09:07:21 -0700 (PDT) Received: from localhost ([::1]:38470 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lahI0-0000SV-3s for importer@patchew.org; Sun, 25 Apr 2021 12:07:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48590) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lah8z-0007wp-Au for qemu-devel@nongnu.org; Sun, 25 Apr 2021 11:58:01 -0400 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]:36438) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lah8v-0003Cq-3C for qemu-devel@nongnu.org; Sun, 25 Apr 2021 11:58:01 -0400 Received: by mail-pf1-x432.google.com with SMTP id c3so18557644pfo.3 for ; Sun, 25 Apr 2021 08:57:56 -0700 (PDT) Received: from localhost.localdomain ([71.212.144.24]) by smtp.gmail.com with ESMTPSA id u21sm8594717pfm.89.2021.04.25.08.57.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Apr 2021 08:57:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=DKxGWYw3ADKuWB18lhyYVJwm1dNkTUIYY08wHRcIwcI=; b=teXZ7QcLMJYiOjvVuBT4Wk9Sp4beLXzC5nqmP/ISJY9HqQULZHJFodubMoHkE3khjG xTbNH0As2uuhEbxuF0l6XJQGd1dWJxbSxUASB9N80IRnQZxEO5677VJTy1mow6WQ30vA 4YCMgaoiV5sf1JP1lePYhhSF1Fhov8mK3FKDqH8bciR5R27V3pagVfVtLhIh3S5cKett pgBT88rpje8JBnnC59WK+6ouPBc3mIR71NREOJy2IgnEl9MBiaUCiZhR+GpDeY/Q8ApC x88s3GYWoSG/niMPH+YznBVe19rcdYbvrFqrk258L4RDl4CFW6Xpk2dUvCQGNgAtuPYb 4nsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DKxGWYw3ADKuWB18lhyYVJwm1dNkTUIYY08wHRcIwcI=; b=Pb8acq7c7kV2NBqanwcZogwsGqyL30ZRj6j+xhjM/05k15fnbMHD10TMfSqMEsvSf5 q/g7vp/Nw/VdqbVCnT9Zj4Bo7b7Yk6O8ta/UCtdLR3jxFTu5IpBGjWkdjyTxiZHo7s8q 6/tnnpj0fpwN/xKgPe5xgUuc1ZT+/ZHk9N2BVpMI+887gWnGW728Ff33pR8HsM8lysWO j3CpopPFuiCvDw6O2dJ1B4SpU/wz6/36ODs3NCHJaSOzB6ToCRC4n2XBVX1x0xxMbG1p DD+BLSSc1J4bLn3d1HT442f7hHcHoklw75hSKQYIFteF2iujnndk6Bk5WKMs3IJVV4oU l8sg== X-Gm-Message-State: AOAM530wuwMnPeIHpOSJn734n0DBQMDzUVR0dMManQHWvfFnI/zdHL7Y gMc22rxR7mEgOQV/McoAaafcqu77fVsT1w== X-Google-Smtp-Source: ABdhPJyPYN7WFKhLG4nuyEnQdPUVk8GfQ3JYe5aAWTe2fGWb6QUEWJVWcuKOf6rPuXLzzVZ8c6pYpQ== X-Received: by 2002:a63:5d18:: with SMTP id r24mr13429550pgb.94.1619366275647; Sun, 25 Apr 2021 08:57:55 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 8/8] linux-user/sparc64: Implement signals Date: Sun, 25 Apr 2021 08:57:49 -0700 Message-Id: <20210425155749.896330-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210425155749.896330-1-richard.henderson@linaro.org> References: <20210425155749.896330-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::432; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x432.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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Content-Type: text/plain; charset="utf-8" We've been using the 32-bit sparc abi for 64-bit signals. There's a surprising amount of difference, beginning with the fact that 64-bit always uses rt signal frames. Signed-off-by: Richard Henderson --- linux-user/sparc/target_signal.h | 2 + linux-user/sparc64/target_syscall.h | 14 +- linux-user/sparc64/signal.c | 245 +++++++++++++++++++++++++++- 3 files changed, 254 insertions(+), 7 deletions(-) diff --git a/linux-user/sparc/target_signal.h b/linux-user/sparc/target_sig= nal.h index 911a3f5af5..651320ab8d 100644 --- a/linux-user/sparc/target_signal.h +++ b/linux-user/sparc/target_signal.h @@ -67,7 +67,9 @@ typedef struct target_sigaltstack { #define TARGET_MINSIGSTKSZ 4096 #define TARGET_SIGSTKSZ 16384 =20 +#if !defined(TARGET_SPARC64) || defined(TARGET_ABI32) #define TARGET_ARCH_HAS_SETUP_FRAME +#endif =20 /* bit-flags */ #define TARGET_SS_AUTODISARM (1U << 31) /* disable sas during sighandling = */ diff --git a/linux-user/sparc64/target_syscall.h b/linux-user/sparc64/targe= t_syscall.h index 696a68b1ed..fcc71db16e 100644 --- a/linux-user/sparc64/target_syscall.h +++ b/linux-user/sparc64/target_syscall.h @@ -4,14 +4,16 @@ #include "../sparc/target_errno.h" =20 struct target_pt_regs { - abi_ulong u_regs[16]; - abi_ulong tstate; - abi_ulong pc; - abi_ulong npc; - abi_ulong y; - abi_ulong fprs; + abi_ulong u_regs[16]; + abi_ulong tstate; + abi_ulong pc; + abi_ulong npc; + uint32_t y; + uint32_t magic; }; =20 +#define TARGET_PT_REGS_MAGIC 0x57ac6c00 + #define UNAME_MACHINE "sparc64" #define UNAME_MINIMUM_RELEASE "2.6.32" =20 diff --git a/linux-user/sparc64/signal.c b/linux-user/sparc64/signal.c index d27e049c2a..7ba811d342 100644 --- a/linux-user/sparc64/signal.c +++ b/linux-user/sparc64/signal.c @@ -17,7 +17,10 @@ * along with this program; if not, see . */ =20 -#include "../sparc/signal.c" +#include "qemu/osdep.h" +#include "qemu.h" +#include "signal-common.h" +#include "linux-user/trace.h" =20 #define SPARC_MC_TSTATE 0 #define SPARC_MC_PC 1 @@ -295,3 +298,243 @@ void sparc64_get_context(CPUSPARCState *env) unlock_user_struct(ucp, ucp_addr, 1); force_sig(TARGET_SIGSEGV); } + +struct target_sparc_stackf { + struct target_reg_window win; + uint64_t xargs[8]; +}; + +struct target_siginfo_fpu_t { + uint64_t dregs[32]; + uint64_t fsr; + uint64_t gsr; + uint64_t fprs; +}; + +struct target_sigcontext { + target_siginfo_t info; + struct target_pt_regs regs; + uint64_t fpu_save; + target_stack_t stack; + target_sigset_t mask; + uint64_t rwin_save; +}; + +struct target_rt_sigframe { + struct target_sparc_stackf ss; + struct target_sigcontext sc; + struct target_siginfo_fpu_t fpu; +}; + +static abi_ulong get_sigframe(struct target_sigaction *sa, + CPUSPARCState *env, int framesize) +{ + abi_ulong sp =3D target_sigsp(get_sp_from_cpustate(env), sa); + return (sp - framesize) & -16; +} + +static void save_pt_regs(struct target_pt_regs *regs, CPUSPARCState *env) +{ + int i; + + for (i =3D 0; i < 8; i++) { + __put_user(env->gregs[i], ®s->u_regs[i]); + } + for (i =3D 0; i < 8; i++) { + __put_user(env->regwptr[WREG_O0 + i], ®s->u_regs[i + 8]); + } + __put_user(sparc64_tstate(env), ®s->tstate); + __put_user(env->pc, ®s->pc); + __put_user(env->npc, ®s->npc); + __put_user(env->y, ®s->y); + __put_user(TARGET_PT_REGS_MAGIC, ®s->magic); +} + +static void restore_pt_regs(struct target_pt_regs *regs, CPUSPARCState *en= v) +{ + uint64_t tstate; + int i; + + for (i =3D 0; i < 8; i++) { + __get_user(env->gregs[i], ®s->u_regs[i]); + } + for (i =3D 0; i < 8; i++) { + __get_user(env->regwptr[WREG_O0 + i], ®s->u_regs[i + 8]); + } + + __get_user(env->y, ®s->y); + __get_user(tstate, ®s->tstate); + + /* User can only change condition codes and %asi in tstate. */ + cpu_put_ccr(env, tstate >> 32); + env->asi =3D extract64(tstate, 24, 8); +} + +static void save_fpu_state(struct target_siginfo_fpu_t *regs, + CPUSPARCState *env) +{ + int i; + + /* QEMU does not lazy fpu saving. Save the entire fp register bank. */ + for (i =3D 0; i < 32; ++i) { + __put_user(env->fpr[i].ll, ®s->dregs[i]); + } + __put_user(env->fsr, ®s->fsr); + __put_user(env->gsr, ®s->gsr); + __put_user(env->fprs, ®s->fprs); +} + +static void restore_fpu_state(struct target_siginfo_fpu_t *regs, + CPUSPARCState *env) +{ + uint64_t fprs; + int i; + + /* In case the user mucks about with FPRS, restore as directed. */ + __get_user(fprs, ®s->fprs); + if (fprs & FPRS_DL) { + for (i =3D 0; i < 16; ++i) { + __get_user(env->fpr[i].ll, ®s->dregs[i]); + } + } + if (fprs & FPRS_DU) { + for (i =3D 16; i < 32; ++i) { + __get_user(env->fpr[i].ll, ®s->dregs[i]); + } + } + __get_user(env->fsr, ®s->fsr); + __get_user(env->gsr, ®s->gsr); + env->fprs |=3D fprs; +} + +void setup_rt_frame(int sig, struct target_sigaction *ka, + target_siginfo_t *info, + target_sigset_t *set, CPUSPARCState *env) +{ + abi_ulong sf_addr, sp; + struct target_rt_sigframe *sf =3D NULL; + void *window; + + sf_addr =3D get_sigframe(ka, env, sizeof(*sf)); + trace_user_setup_rt_frame(env, sf_addr); + if (!lock_user_struct(VERIFY_WRITE, sf, sf_addr, 0)) { + goto do_sigsegv; + } + + /* 2. Save the current process state */ + save_pt_regs(&sf->sc.regs, env); + save_fpu_state(&sf->fpu, env); + __put_user(sf_addr + offsetof(struct target_rt_sigframe, fpu), + &sf->sc.fpu_save); + __put_user(0, &sf->sc.rwin_save); /* TODO: save_rwin_state */ + + /* + * Copy one register window from the top-of-stack into the signal fram= e. + * The balance of the sparc_stackf struct is for the callee --- the ca= ll + * abi requires the space for spilling argument registers. + */ + sp =3D get_sp_from_cpustate(env); + window =3D lock_user(VERIFY_READ, sp, sizeof(struct target_reg_window)= , 1); + if (!window) { + goto do_sigsegv; + } + memcpy(sf, window, sizeof(struct target_reg_window)); + unlock_user(window, sp, 0); + + target_save_altstack(&sf->sc.stack, env); + for (int i =3D 0; i < TARGET_NSIG_WORDS; ++i) { + __put_user(set->sig[i], &sf->sc.mask.sig[i]); + } + + unlock_user(sf, sf_addr, sizeof(*sf)); + + /* 3. signal handler back-trampoline and parameters */ + env->regwptr[WREG_SP] =3D sf_addr - TARGET_STACK_BIAS; + env->regwptr[WREG_O0] =3D sig; + env->regwptr[WREG_O1] =3D sf_addr + offsetof(struct target_rt_sigframe= , sc); + env->regwptr[WREG_O2] =3D sf_addr + offsetof(struct target_rt_sigframe= , sc); + + /* 4. return to kernel instructions */ + env->regwptr[WREG_O7] =3D ka->ka_restorer; + + /* 5. signal handler */ + env->pc =3D ka->_sa_handler; + env->npc =3D env->pc + 4; + return; + + do_sigsegv: + unlock_user(sf, sf_addr, 0); + force_sigsegv(sig); +} + +/* + * __NR_sigreturn still exists for backward compatiblity, + * but it is set to sys_nis_syscall for sparc64. + */ +long do_sigreturn(CPUSPARCState *env) +{ + return -TARGET_ENOSYS; +} + +long do_rt_sigreturn(CPUSPARCState *env) +{ + abi_ulong sf_addr, sc_addr, tpc, tnpc, ptr; + struct target_sigcontext *sc =3D NULL; + sigset_t set; + + sf_addr =3D get_sp_from_cpustate(env); + trace_user_do_rt_sigreturn(env, sf_addr); + + if (sf_addr & 15) { + goto do_sigsegv; + } + sc_addr =3D sf_addr + offsetof(struct target_rt_sigframe, sc); + if (!lock_user_struct(VERIFY_READ, sc, sc_addr, 1)) { + goto do_sigsegv; + } + + /* Validate SP alignment. */ + __get_user(ptr, &sc->regs.u_regs[8 + WREG_SP]); + if ((ptr + TARGET_STACK_BIAS) & 7) { + goto do_sigsegv; + } + + /* Validate PC and NPC alignment. */ + __get_user(tpc, &sc->regs.pc); + __get_user(tnpc, &sc->regs.npc); + if ((tpc | tnpc) & 3) { + goto do_sigsegv; + } + + restore_pt_regs(&sc->regs, env); + + __get_user(ptr, &sc->fpu_save); + if (ptr) { + struct target_siginfo_fpu_t *fpu; + if ((ptr & 7) || !lock_user_struct(VERIFY_READ, fpu, ptr, 1)) { + goto do_sigsegv; + } + restore_fpu_state(fpu, env); + unlock_user_struct(fpu, ptr, 0); + } + + __get_user(ptr, &sc->rwin_save); + if (ptr) { + goto do_sigsegv; /* TODO: restore_rwin_state */ + } + + target_to_host_sigset(&set, &sc->mask); + set_sigmask(&set); + target_restore_altstack(&sc->stack, env); + + env->pc =3D tpc; + env->npc =3D tnpc; + + unlock_user_struct(sc, sc_addr, 0); + return -TARGET_QEMU_ESIGRETURN; + + do_sigsegv: + unlock_user_struct(sc, sc_addr, 0); + force_sig(TARGET_SIGSEGV); + return -TARGET_QEMU_ESIGRETURN; +} --=20 2.25.1