From patchwork Mon Jan 31 19:55:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 12731080 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CDE00C433EF for ; Mon, 31 Jan 2022 20:03:53 +0000 (UTC) Received: from localhost ([::1]:50292 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nEcu0-0001n0-G2 for qemu-devel@archiver.kernel.org; Mon, 31 Jan 2022 15:03:52 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42602) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nEcn0-0004cs-C7 for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:56:39 -0500 Received: from [2607:f8b0:4864:20::d2f] (port=40554 helo=mail-io1-xd2f.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nEcmx-0002am-5F for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:56:37 -0500 Received: by mail-io1-xd2f.google.com with SMTP id d188so18385148iof.7 for ; Mon, 31 Jan 2022 11:56:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=q2wkolIh2lCmSomI63wI2LjQYXEA5OUzuuGqVAAxz7A=; b=yKlQdzwsPGz6vQuakhUVpN9KSwzkrfpfw4EYDdc1071PU4J6XKgQK14eonBzotg51C ADbiYAY+wfsLw0DyjVUrCeUHkbJg1m4VCGK2ydZjOYITR0cUy6Je7xWsDU+c13YeiKVu ltqnDfrWvnd3FSR+xdctgC8vUL3LwjA1szES1y505dtDbjTar0vSXKiIfqPgo5r8mBLt gfbZnwDYPqx6xIwyoaKvfM2gmvffS6+C7pNVDzEXWa88aiDiYJCaI2GjM20zB978B8as pbzEczMBUcmap2uyiGRz5WF9jLXyPy8BqjWkNDXxNTycJGDlvS8ixtcztkNTmKh4YDkp qG3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=q2wkolIh2lCmSomI63wI2LjQYXEA5OUzuuGqVAAxz7A=; b=70FYOxqsS9LU5WJ20VUq70ig6uI4jVXrjiIx4O7YAlvC5qRC9HVBavwuLiNVAWuC+R jx26V/UEP30QbBht3GuRwyYOa77ciRsrRqdhbG4b9q408Amtd76KDClF3YFxZ8mz7aKh ZXxGUTbrD4XW6X8awYh2dNLkYltrGdNE02DYzrqAFOx9Fp1NbF/JHO2IC9uDa7eO12Rv nhleiPYo/lM6hblDfolZ0+xMtnU5ajTo0yHaozrDWQrxrPYEFnc9exrP1U0jch2PBMgX E+HQnGlLbucaCqRZ0AWuzKA6onAQbkKlngoAaQcxzCWaxVBFllobYCbyBHpf7xgYK7Cp +aTg== X-Gm-Message-State: AOAM533BbMKUxqYqNgcKU5TqM2woIcIpUm2FemwpPM94LF5t0orYeAk2 UeztF/v4RLIopszV3gr8uykb501GekWRlw== X-Google-Smtp-Source: ABdhPJyesfyVcY4JMTYc2N4WMT0l2sqT9nb+a272nkK7+XExAIz9EZTEGQ86Cu6/0GDS/u8wzCW1ig== X-Received: by 2002:a02:29cd:: with SMTP id p196mr11947066jap.100.1643658991491; Mon, 31 Jan 2022 11:56:31 -0800 (PST) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id j2sm1972989ilu.82.2022.01.31.11.56.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jan 2022 11:56:31 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PULL 01/40] bsd-user: Complete FreeBSD siginfo Date: Mon, 31 Jan 2022 12:55:57 -0700 Message-Id: <20220131195636.31991-2-imp@bsdimp.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220131195636.31991-1-imp@bsdimp.com> References: <20220131195636.31991-1-imp@bsdimp.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::d2f (failed) Received-SPF: none client-ip=2607:f8b0:4864:20::d2f; envelope-from=imp@bsdimp.com; helo=mail-io1-xd2f.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Kyle Evans , Richard Henderson , def@FreeBSD.org, jrtc27@FreeBSD.org, Warner Losh Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Fill in the missing FreeBSD siginfo fields, and add some comments. Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/freebsd/target_os_siginfo.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/bsd-user/freebsd/target_os_siginfo.h b/bsd-user/freebsd/target_os_siginfo.h index 84944faa4d3..d50a3034a88 100644 --- a/bsd-user/freebsd/target_os_siginfo.h +++ b/bsd-user/freebsd/target_os_siginfo.h @@ -71,11 +71,24 @@ typedef struct target_siginfo { int32_t _mqd; } _mesgp; - /* SIGPOLL */ + /* SIGPOLL -- Not really genreated in FreeBSD ??? */ struct { int _band; /* POLL_IN, POLL_OUT, POLL_MSG */ } _poll; + struct { + int _mqd; + } _mesgq; + + struct { + /* + * Syscall number for signals delivered as a result of system calls + * denied by Capsicum. + */ + int _syscall; + } _capsicum; + + /* Spare for future growth */ struct { abi_long __spare1__; int32_t __spare2_[7]; From patchwork Mon Jan 31 19:55:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 12731123 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2160FC433EF for ; Mon, 31 Jan 2022 20:36:16 +0000 (UTC) Received: from localhost ([::1]:47132 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nEdPL-0005OZ-2i for qemu-devel@archiver.kernel.org; Mon, 31 Jan 2022 15:36:15 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42704) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nEcnZ-0004jo-MG for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:14 -0500 Received: from [2607:f8b0:4864:20::129] (port=47042 helo=mail-il1-x129.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nEcmx-0002az-Lw for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:56:39 -0500 Received: by mail-il1-x129.google.com with SMTP id e8so12374825ilm.13 for ; Mon, 31 Jan 2022 11:56:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kxfL+Uf67jAojsgUJ24l/wKbWp/n0flIHdow2eRHTNw=; b=ZQ+0VT2UdAMhVBqqlyLV7JySPuBLd200HYv2qTevSMndBjiiovDkc4f1OcO/CJgIb6 kBowo1HbEN6cHX4t0L716EzxGPY7tmDRYAIrIzXh0wM+kI+w+MS2d81pAYNMgDr72HxW t5/AzdwazzRY20Qfn7ChQSBFgcwOXfHycPOvVFa1isTt79pEncLsaknhLkQFM7k/b5sd kjw3Y0MiJ+CXK61Q2NMz7j6tn2YEaQWIi/LA8bRfQS92uby099HPR33RwexRaiZoz1Jv TWrxu4tSH+INXRYYaXsmaqJs2G4SFxzs7iXAU8to7j8WnOFPi9tTlT0SOBjn/vgHtbBs lD9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kxfL+Uf67jAojsgUJ24l/wKbWp/n0flIHdow2eRHTNw=; b=CJWl0FaBLiFVMRCHTgSaq+8FhBJZBWyeNLxhEdLPwFm5hxEQhR3waRyV/58W17WFvU bN4e1bn/vu4rwBHgp93+Ad83BSwufJ6oh9QxsfaCfeKumHgiLS9rGBnl5H8qoo5OE6MF wqcGZOz9E+UHW55DXLIeqf/2zN6eJr3DgAy2zTqLHbs0t04Dm5Ufdjq6aFue3TD+L9g4 kFUfcXxJCjwfmxr78I/utovQcdYDWEeXmKeSykesxCgUBrV5huTQw3ccVgzwa84odhqL XCRqlW+nzX+mBMJ4lQ5ZHlIjLo3JukSFJiz01aqf8mnfNgxsmsu3ZnVIOjTorlGrsvqC O3LA== X-Gm-Message-State: AOAM530UMezTkpl+mW/FzB5rhXnaS0aN6ifHL3HbvhpkfoKR1qq+UyKS bEIaxWGE3ECY5AWthGNaHsqF+6V4m69/eg== X-Google-Smtp-Source: ABdhPJw3RnZS4pdfjb/KqxONmDOU2SDJvzSjYlRbcjK5f14cNWDIpZStaJ+iwyLzB+zT9bsPLZKkGA== X-Received: by 2002:a05:6e02:1a4d:: with SMTP id u13mr2113590ilv.136.1643658992588; Mon, 31 Jan 2022 11:56:32 -0800 (PST) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id j2sm1972989ilu.82.2022.01.31.11.56.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jan 2022 11:56:32 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PULL 02/40] bsd-user: Create setup_sigframe_arch to setup sigframe context Date: Mon, 31 Jan 2022 12:55:58 -0700 Message-Id: <20220131195636.31991-3-imp@bsdimp.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220131195636.31991-1-imp@bsdimp.com> References: <20220131195636.31991-1-imp@bsdimp.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::129 (failed) Received-SPF: none client-ip=2607:f8b0:4864:20::129; envelope-from=imp@bsdimp.com; helo=mail-il1-x129.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Kyle Evans , Richard Henderson , def@FreeBSD.org, jrtc27@FreeBSD.org, Warner Losh Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Define setup_sigframe_arch whose job it is to setup the mcontext for the sigframe. Implement for x86 to just call mcontext. Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/freebsd/target_os_signal.h | 3 +++ bsd-user/i386/signal.c | 13 +++++++++++++ bsd-user/x86_64/signal.c | 13 +++++++++++++ 3 files changed, 29 insertions(+) diff --git a/bsd-user/freebsd/target_os_signal.h b/bsd-user/freebsd/target_os_signal.h index 3ed454e086d..43700d08f71 100644 --- a/bsd-user/freebsd/target_os_signal.h +++ b/bsd-user/freebsd/target_os_signal.h @@ -4,6 +4,9 @@ #include "target_os_siginfo.h" #include "target_arch_signal.h" +abi_long setup_sigframe_arch(CPUArchState *env, abi_ulong frame_addr, + struct target_sigframe *frame, int flags); + /* Compare to sys/signal.h */ #define TARGET_SIGHUP 1 /* hangup */ #define TARGET_SIGINT 2 /* interrupt */ diff --git a/bsd-user/i386/signal.c b/bsd-user/i386/signal.c index 2939d32400c..5dd975ce56a 100644 --- a/bsd-user/i386/signal.c +++ b/bsd-user/i386/signal.c @@ -32,6 +32,19 @@ abi_long set_sigtramp_args(CPUX86State *env, int sig, return 0; } +/* + * Compare to i386/i386/exec_machdep.c sendsig() + * Assumes that the memory is locked if frame points to user memory. + */ +abi_long setup_sigframe_arch(CPUX86State *env, abi_ulong frame_addr, + struct target_sigframe *frame, int flags) +{ + target_mcontext_t *mcp = &frame->sf_uc.uc_mcontext; + + get_mcontext(env, mcp, flags); + return 0; +} + /* Compare to i386/i386/machdep.c get_mcontext() */ abi_long get_mcontext(CPUX86State *regs, target_mcontext_t *mcp, int flags) { diff --git a/bsd-user/x86_64/signal.c b/bsd-user/x86_64/signal.c index 8885152a7da..c3875bc4c6a 100644 --- a/bsd-user/x86_64/signal.c +++ b/bsd-user/x86_64/signal.c @@ -30,6 +30,19 @@ abi_long set_sigtramp_args(CPUX86State *regs, return 0; } +/* + * Compare to amd64/amd64/exec_machdep.c sendsig() + * Assumes that the memory is locked if frame points to user memory. + */ +abi_long setup_sigframe_arch(CPUX86State *env, abi_ulong frame_addr, + struct target_sigframe *frame, int flags) +{ + target_mcontext_t *mcp = &frame->sf_uc.uc_mcontext; + + get_mcontext(env, mcp, flags); + return 0; +} + /* Compare to amd64/amd64/machdep.c get_mcontext() */ abi_long get_mcontext(CPUX86State *regs, target_mcontext_t *mcp, int flags) From patchwork Mon Jan 31 19:55:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 12731082 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D37EFC433F5 for ; Mon, 31 Jan 2022 20:09:50 +0000 (UTC) Received: from localhost ([::1]:58750 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nEczl-0007g7-PL for qemu-devel@archiver.kernel.org; Mon, 31 Jan 2022 15:09:49 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42702) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nEcnZ-0004jm-M0 for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:14 -0500 Received: from [2607:f8b0:4864:20::12b] (port=47044 helo=mail-il1-x12b.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nEcmx-0002bH-Gu for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:56:39 -0500 Received: by mail-il1-x12b.google.com with SMTP id e8so12374887ilm.13 for ; Mon, 31 Jan 2022 11:56:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TqTK+KI3YcgM6rmeXyGDTKC+kTxHQQ89yzMVSFkLyKI=; b=tiWu/j6yeog5QGhlaMi9YcMXSIx0nlA9nvIGwSmyVz84woDTY78CCYolEQb8lKLD/P 6wQR4lJMYE4oQS43TIvHsPkB20x5pXk6Tr2OVorQWLEPfX66x0Hwld7djmFiqGGo5aCP cv0++lv/+GyBZHiHzeqQ5N/ZlA5Wl6j7gw06/USqbmcVCzVCSRNgLLURadRu34temJRy BygVaeapNwR3CEzM6w56PlC1J52QKmls37Pr8oe5X2JsTDVP/4nqLxz3NdDsCUuOI7v2 cpGsEqo/pyOebJqlisduuI592aBuzjQRDSNya9piHHvvrx/r0q9mDliPJzl6yD3JA/1s eg9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TqTK+KI3YcgM6rmeXyGDTKC+kTxHQQ89yzMVSFkLyKI=; b=aFNN6RN93wv69ON//9bwOvGYXKmFmp1HDJZs76Fq8WXcEg4mxsireBseQRZrqWT6w5 d6m5kCy9+qocFfAR/o7p9JMAtNqVXhoGDMu/kN4L6HAPId/xkEGdNnZr7rtP8QVp3/aL 14M6AL187EwNEQK3AtYSKKXpVOBYLyYS6cR48m/c4BTDqOok30hsjUc/T/InuFk/rqHr lbQiX4m71/8LuUfvcQ2b+Wpp5t19/3OHfbHoObdvgknvKfxIDtqs3GKUGvSfzKreNdom JQrraf64iMz7BAlte0+ctttJgIHEDPYmT2P+nkvUOffzytCYzb02MA5tMCXwF8UAIwzK qE8Q== X-Gm-Message-State: AOAM530ZOVbiTYgAhliGxJ140X9a2ywmae6qvIzVPfJNdA0KPGP4UeLq kLSXAIfmXG2s5Dcovw48YYSixQNGgUU8jg== X-Google-Smtp-Source: ABdhPJyy4s/2X9smHpzk4azP4zgyWHUgywSO1/ICM4kJokeKbS9U4f2bTARAfbH5lji9Tjk5ckcrPw== X-Received: by 2002:a05:6e02:198b:: with SMTP id g11mr13787306ilf.25.1643658993523; Mon, 31 Jan 2022 11:56:33 -0800 (PST) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id j2sm1972989ilu.82.2022.01.31.11.56.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jan 2022 11:56:33 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PULL 03/40] bsd-user/arm/signal.c: Implement setup_sigframe_arch for arm Date: Mon, 31 Jan 2022 12:55:59 -0700 Message-Id: <20220131195636.31991-4-imp@bsdimp.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220131195636.31991-1-imp@bsdimp.com> References: <20220131195636.31991-1-imp@bsdimp.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::12b (failed) Received-SPF: none client-ip=2607:f8b0:4864:20::12b; envelope-from=imp@bsdimp.com; helo=mail-il1-x12b.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Kyle Evans , Richard Henderson , def@FreeBSD.org, jrtc27@FreeBSD.org, Warner Losh Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Fix the broken context setting for arm. FreeBSD's get_mcontext does not fill in the vfp info. It's filled in in sigframe(). This corresponds to the new setup_sigframe_arch which fills in mcontext, then adjusts it to point to the vfp context in the sigframe and fills in that context as well. Add pointer to where this code is done. Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/arm/signal.c | 50 ++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/bsd-user/arm/signal.c b/bsd-user/arm/signal.c index 1478f008d13..9026343b478 100644 --- a/bsd-user/arm/signal.c +++ b/bsd-user/arm/signal.c @@ -59,19 +59,31 @@ abi_long set_sigtramp_args(CPUARMState *env, int sig, return 0; } +static abi_long get_vfpcontext(CPUARMState *env, abi_ulong frame_addr, + struct target_sigframe *frame) +{ + /* see sendsig and get_vfpcontext in sys/arm/arm/exec_machdep.c */ + target_mcontext_vfp_t *vfp = &frame->sf_vfp; + target_mcontext_t *mcp = &frame->sf_uc.uc_mcontext; + + /* Assumes that mcp and vfp are locked */ + for (int i = 0; i < 32; i++) { + vfp->mcv_reg[i] = tswap64(*aa32_vfp_dreg(env, i)); + } + vfp->mcv_fpscr = tswap32(vfp_get_fpscr(env)); + mcp->mc_vfp_size = tswap32(sizeof(*vfp)); + mcp->mc_vfp_ptr = tswap32(frame_addr + ((uintptr_t)vfp - (uintptr_t)frame)); + return 0; +} + /* - * Compare to arm/arm/machdep.c get_mcontext() + * Compare to arm/arm/exec_machdep.c get_mcontext() * Assumes that the memory is locked if mcp points to user memory. */ abi_long get_mcontext(CPUARMState *env, target_mcontext_t *mcp, int flags) { - int err = 0; uint32_t *gr = mcp->__gregs; - if (mcp->mc_vfp_size != 0 && mcp->mc_vfp_size != sizeof(target_mcontext_vfp_t)) { - return -TARGET_EINVAL; - } - gr[TARGET_REG_CPSR] = tswap32(cpsr_read(env)); if (flags & TARGET_MC_GET_CLEAR_RET) { gr[TARGET_REG_R0] = 0; @@ -97,17 +109,21 @@ abi_long get_mcontext(CPUARMState *env, target_mcontext_t *mcp, int flags) gr[TARGET_REG_LR] = tswap32(env->regs[14]); gr[TARGET_REG_PC] = tswap32(env->regs[15]); - if (mcp->mc_vfp_size != 0 && mcp->mc_vfp_ptr != 0) { - /* see get_vfpcontext in sys/arm/arm/exec_machdep.c */ - target_mcontext_vfp_t *vfp; - vfp = lock_user(VERIFY_WRITE, mcp->mc_vfp_ptr, sizeof(*vfp), 0); - for (int i = 0; i < 32; i++) { - vfp->mcv_reg[i] = tswap64(*aa32_vfp_dreg(env, i)); - } - vfp->mcv_fpscr = tswap32(vfp_get_fpscr(env)); - unlock_user(vfp, mcp->mc_vfp_ptr, sizeof(*vfp)); - } - return err; + return 0; +} + +/* + * Compare to arm/arm/exec_machdep.c sendsig() + * Assumes that the memory is locked if frame points to user memory. + */ +abi_long setup_sigframe_arch(CPUARMState *env, abi_ulong frame_addr, + struct target_sigframe *frame, int flags) +{ + target_mcontext_t *mcp = &frame->sf_uc.uc_mcontext; + + get_mcontext(env, mcp, flags); + get_vfpcontext(env, frame_addr, frame); + return 0; } /* Compare to arm/arm/exec_machdep.c set_mcontext() */ From patchwork Mon Jan 31 19:56:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 12731109 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C4CEBC433F5 for ; Mon, 31 Jan 2022 20:30:22 +0000 (UTC) Received: from localhost ([::1]:38492 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nEdJd-0007kA-Gg for qemu-devel@archiver.kernel.org; Mon, 31 Jan 2022 15:30:21 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42714) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nEcnZ-0004k6-Ud for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:14 -0500 Received: from [2607:f8b0:4864:20::d32] (port=39854 helo=mail-io1-xd32.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nEcmx-0002bN-Ty for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:56:39 -0500 Received: by mail-io1-xd32.google.com with SMTP id c188so18402672iof.6 for ; Mon, 31 Jan 2022 11:56:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=k9zDtgXS+L05+ekpD7VMpQo1Lh9R8HC1kSXvuE27qsY=; b=5At6AW7jsIGvsHhzFugiT8MsmO/itxFMr8HZKsadLx2pt0ceMHGSRAUgPh/FfXxFGA eTorMgkl4bgpx+O5BFLkFplGVbfRNXmIDYEECjo+CQmn5+SgjTCFU1wawFLPWzc5Q846 T0sx5lB3wtjY5lDnL6cQh0QEeudIu8hpE+vPjr7q1fmVFYPknI7IVM4/yadOT1pnr8Bm FYel4EISo3kOc7PqAxNvyYFkXoFgVmg2x9Lp0vSn9ZJj/3phhar5wCoRNrPSuh0ClfQZ xbdjc7iuyNHRd/jw16oTfT47UwY6r4n/hUMubxUKvaS8vwgrXl51sO1w7p8Gz2ut6iFv QyiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=k9zDtgXS+L05+ekpD7VMpQo1Lh9R8HC1kSXvuE27qsY=; b=z6ZjYIoHcUeB7W5YauCt7SlmMkd3/njJH3ySqFEGYoy9IVKK69HafOYigAl7wu1EQ+ DMGTOMQ8SGdwSo8ItWVFrj17sXXeUJwvE9XhhhlKwPjvYWpBHjCAePhnKCAjgFBT5xP+ 7l+5xxF7iJXGTGJHoJ8n7eua2cQ7OqfK9p+7smKFTu3YwDemO4vhgZvECFOaeAW/SETZ Xw+8nB7WxIulGQkv8AjVud907BHZcGk70rJ098kcyW9U8Rn3gxJmLZwTezR8gkVxbVij 8st/AsxKYR46j6hjNR5ycd/PNAPt5uancaFsiksV+N2uGRr4FIBVWLe9EbyCaCMXcAyU gkUw== X-Gm-Message-State: AOAM531gBxTZPuvy5sMtbQd6qNbMdVTM0o2qO/7uNTtd42HhvRDz41YA VLkMwb2Czln1e6gQMrLAPFq5HcwtjIqJEQ== X-Google-Smtp-Source: ABdhPJyF4ITUXFo7axp7m/nsLzt4J5K8DLS2AxhwGkMRHoWzOnGPTc37sOHrTP38PWRuSbc494J7Xg== X-Received: by 2002:a5e:8406:: with SMTP id h6mr12194987ioj.144.1643658994519; Mon, 31 Jan 2022 11:56:34 -0800 (PST) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id j2sm1972989ilu.82.2022.01.31.11.56.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jan 2022 11:56:34 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PULL 04/40] bsd-user/arm/signal.c: get_mcontext should zero vfp data Date: Mon, 31 Jan 2022 12:56:00 -0700 Message-Id: <20220131195636.31991-5-imp@bsdimp.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220131195636.31991-1-imp@bsdimp.com> References: <20220131195636.31991-1-imp@bsdimp.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::d32 (failed) Received-SPF: none client-ip=2607:f8b0:4864:20::d32; envelope-from=imp@bsdimp.com; helo=mail-io1-xd32.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Kyle Evans , Richard Henderson , def@FreeBSD.org, jrtc27@FreeBSD.org, Warner Losh Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" FreeBSD's get_mcontext doesn't return any vfp data. Instead, it zeros out the vfp feilds (and all the spare fields). Impelement this behavior. We're still missing the sysarch(ARM_GET_VFPCONTEXT) syscall, though. Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/arm/signal.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/bsd-user/arm/signal.c b/bsd-user/arm/signal.c index 9026343b478..2b1dd745d13 100644 --- a/bsd-user/arm/signal.c +++ b/bsd-user/arm/signal.c @@ -109,6 +109,15 @@ abi_long get_mcontext(CPUARMState *env, target_mcontext_t *mcp, int flags) gr[TARGET_REG_LR] = tswap32(env->regs[14]); gr[TARGET_REG_PC] = tswap32(env->regs[15]); + /* + * FreeBSD's get_mcontext doesn't save VFP info, but sets the pointer and + * size to zero. Applications that need the VFP state use + * sysarch(ARM_GET_VFPSTATE) and are expected to adjust mcontext after that. + */ + mcp->mc_vfp_size = 0; + mcp->mc_vfp_ptr = 0; + memset(&mcp->mc_spare, 0, sizeof(mcp->mc_spare)); + return 0; } From patchwork Mon Jan 31 19:56:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 12731083 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 567FEC433EF for ; Mon, 31 Jan 2022 20:10:02 +0000 (UTC) Received: from localhost ([::1]:59258 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nEczx-00080f-Bf for qemu-devel@archiver.kernel.org; Mon, 31 Jan 2022 15:10:01 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42706) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nEcnZ-0004jv-N5 for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:14 -0500 Received: from [2607:f8b0:4864:20::12b] (port=40850 helo=mail-il1-x12b.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nEcmy-0002ba-RK for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:56:39 -0500 Received: by mail-il1-x12b.google.com with SMTP id s1so12394149ilj.7 for ; Mon, 31 Jan 2022 11:56:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tyuB/O2WEXIGgHuAFX6b2tzEg4QPq9MhpbLYs5ZniS4=; b=F2wTc5A9ra6+wEqJJLgT6qVQxgUcJUVPNx8Ma4kv03i8cAuJJctbNl8hrqW8uJTYAt /FONGXLms2Heu1DbVid77XPgYl/1YiJYHcztYIbkFjMxnwSWKx86AANS5IVrw3HwNUWG HB14z3Csg6aW1ymVyEKEoFGyk3i/32j75LXZPk+ZGPnI9DYMFwjZyh03O3FvGuQnLjFW LyXhSaiuzoM4JZlPVDCTP2BsEnkHnj3es3aDK9Jm8TDz7njU2KtdQ6eahZxv4NxLbXih njUnEUDgyjnSM9vWkYwe/MJ+vR55AgEyfFCo1XnXkm1cs67tbwwRhYb4ojOAYNQvvot1 gxDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tyuB/O2WEXIGgHuAFX6b2tzEg4QPq9MhpbLYs5ZniS4=; b=4Lif7VlXSLcRTjAW+2WRumew3LKdbpoO3RzKeKqq6RF3me5wPjIKbhco3Q+VhkwOSi uAS2wKO1mXP7ZcZpHYvS+Aiwnym9G7TzDhVkSy7dhnUgi+ArnMT7AD3udbmIj0Cspzk2 eydPhNm3nXQHAm3pc0py6wNrXdMnDf82Qfh/5PAR4AlTrfTieRTLmWKh0UqQGAxBVXF9 EdsD8YrGiGDKyXUnjPVtEz1XhhlpbiJ1tKtekfER5Fg/Xh6JyE94dz88NtL/q4qqK09Z 7vkojM3BIY+C8gIz7FldvUXUOByj6Ft3/I8RBLsw/gNipDa3jPQdve3v1A93re0bRYR4 pIKA== X-Gm-Message-State: AOAM530B+k+tsftq/dpGZd6rnUR6QE05QHUK6E0NjMo8Drum0AvEmv/4 kJFsbrHQ4f3B3gDA6yp9cZTRsrhi2J8b6g== X-Google-Smtp-Source: ABdhPJzEBT2Vc07J17S7MG8qZRHFK+0RzKK0EefkN0EUur8bcbWm8yPye61bA9MJSQAAszFacaRfMg== X-Received: by 2002:a05:6e02:1e04:: with SMTP id g4mr4096161ila.188.1643658995377; Mon, 31 Jan 2022 11:56:35 -0800 (PST) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id j2sm1972989ilu.82.2022.01.31.11.56.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jan 2022 11:56:34 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PULL 05/40] bsd-user: Remove vestiges of signal queueing code Date: Mon, 31 Jan 2022 12:56:01 -0700 Message-Id: <20220131195636.31991-6-imp@bsdimp.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220131195636.31991-1-imp@bsdimp.com> References: <20220131195636.31991-1-imp@bsdimp.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::12b (failed) Received-SPF: none client-ip=2607:f8b0:4864:20::12b; envelope-from=imp@bsdimp.com; helo=mail-il1-x12b.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Kyle Evans , Richard Henderson , def@FreeBSD.org, jrtc27@FreeBSD.org, Warner Losh Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" bsd-user was copied from linux-user at a time when it queued signals. Remove those vestiges of thse code. Retain the init function, even though it's now empty since other stuff will likely be added there. Make it static since it's not called from outside of main.c Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/main.c | 9 +-------- bsd-user/qemu.h | 13 +------------ 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/bsd-user/main.c b/bsd-user/main.c index cb5ea402361..29cf4e15693 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -215,15 +215,8 @@ void qemu_cpu_kick(CPUState *cpu) } /* Assumes contents are already zeroed. */ -void init_task_state(TaskState *ts) +static void init_task_state(TaskState *ts) { - int i; - - ts->first_free = ts->sigqueue_table; - for (i = 0; i < MAX_SIGQUEUE_SIZE - 1; i++) { - ts->sigqueue_table[i].next = &ts->sigqueue_table[i + 1]; - } - ts->sigqueue_table[i].next = NULL; } void gemu_log(const char *fmt, ...) diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index 1b3b974afe9..4dd209e402d 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -70,17 +70,9 @@ struct image_info { uint32_t elf_flags; }; -#define MAX_SIGQUEUE_SIZE 1024 - -struct qemu_sigqueue { - struct qemu_sigqueue *next; - target_siginfo_t info; -}; - struct emulated_sigtable { int pending; /* true if signal is pending */ - struct qemu_sigqueue *first; - struct qemu_sigqueue info; /* Put first signal info here */ + target_siginfo_t info; }; /* @@ -94,14 +86,11 @@ typedef struct TaskState { struct image_info *info; struct emulated_sigtable sigtab[TARGET_NSIG]; - struct qemu_sigqueue sigqueue_table[MAX_SIGQUEUE_SIZE]; /* siginfo queue */ - struct qemu_sigqueue *first_free; /* first free siginfo queue entry */ int signal_pending; /* non zero if a signal may be pending */ uint8_t stack[]; } __attribute__((aligned(16))) TaskState; -void init_task_state(TaskState *ts); void stop_all_tasks(void); extern const char *qemu_uname_release; From patchwork Mon Jan 31 19:56:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 12731081 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id ED41AC433F5 for ; Mon, 31 Jan 2022 20:06:28 +0000 (UTC) Received: from localhost ([::1]:52124 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nEcwV-00032s-Mc for qemu-devel@archiver.kernel.org; Mon, 31 Jan 2022 15:06:27 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42698) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nEcnZ-0004jl-M7 for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:14 -0500 Received: from [2607:f8b0:4864:20::131] (port=41853 helo=mail-il1-x131.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nEcmz-0002bk-Gp for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:56:39 -0500 Received: by mail-il1-x131.google.com with SMTP id 15so12391586ilg.8 for ; Mon, 31 Jan 2022 11:56:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kr3WAg3LFuIjGK7Kv0poOIctPcCnCwAaBtFgS4qf/b0=; b=u1Ldz/wJzFV4X9Q92P1sBl9Tnp18AhpT6hVph82SyBvOaVwhNgv7lVbqy1gZo0CGF0 B+WEEyh5XBih30gL19n3A/D4TUFnWqFvPgaLruqdo0SpuuKlEuxpYQi8fVl1QziMVugd 2d4QaTsGu8nPk3NyoPETZjQxjhASwvrrWO4icPBVFA3AgnP9m5yQgMdUeSWzxKLsfkeo jqUYUVTbJZQb7LL/r9OI1VvATuEsPs6LsXvHcjORuzgJHj0wwD05HyrDRN1y7TgngcBG ZfHbGgp/aqCZMqh3ICI6igPY4aa+JUK+8WCo7BUcgE+HZEZDnTtgZNnb+Mwp1C2QwaxU rrOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kr3WAg3LFuIjGK7Kv0poOIctPcCnCwAaBtFgS4qf/b0=; b=lxViE0QdkzZzCncsTijW3PlIp0OwVsJ1Lnqk0O9Afeie5ZU6pjQK7NnpnPB8mZZXss wM57q8oZGpNznrgMnRM1De4ZiNA8acnWLj+tJo5quoqlDZ9H6yIiDN1X+BCraEkdZuLT KE8kXSpBsiZ9KUp6aRGDPHspj+w+/U/VwUz5NoCBuVkp1cf1Z5feYEns0MpKZ8mPGo8p LDjmh+Y7TJ8NTgoHF5+Y4NoXkEkHjySGD29eX0rOuWU6TU7Rdb7N7hJnRnZNXg5CcAzI r0Iwk9m7V6pbJGZNlIU6pX8HXDctyBe7ZVHmXAq+QNcQWpj82vXm6qRCeJnUyOyQYqvb JwCQ== X-Gm-Message-State: AOAM533iccgGIxZMMPDpTYoIwcDWXWONg1tuP6qyhFmAWbA8mdsBT0Ob XQ9RLne3m2AfZIoSxEsWc000Mxesz7mAJQ== X-Google-Smtp-Source: ABdhPJzk68R8J6qVUJfIbZwhdptQQLqu6Tezv+Q+JGCGu/gwek2gvqDIjts3I65ue4tMfSKIVWQgUA== X-Received: by 2002:a05:6e02:18c9:: with SMTP id s9mr14159992ilu.294.1643658996259; Mon, 31 Jan 2022 11:56:36 -0800 (PST) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id j2sm1972989ilu.82.2022.01.31.11.56.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jan 2022 11:56:35 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PULL 06/40] bsd-user: Bring in docs from linux-user for signal_pending Date: Mon, 31 Jan 2022 12:56:02 -0700 Message-Id: <20220131195636.31991-7-imp@bsdimp.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220131195636.31991-1-imp@bsdimp.com> References: <20220131195636.31991-1-imp@bsdimp.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::131 (failed) Received-SPF: none client-ip=2607:f8b0:4864:20::131; envelope-from=imp@bsdimp.com; helo=mail-il1-x131.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Kyle Evans , Richard Henderson , def@FreeBSD.org, jrtc27@FreeBSD.org, Warner Losh Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" This is currently unused, so no code adjustments are needed. Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/qemu.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index 4dd209e402d..671b26f00cc 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -86,7 +86,14 @@ typedef struct TaskState { struct image_info *info; struct emulated_sigtable sigtab[TARGET_NSIG]; - int signal_pending; /* non zero if a signal may be pending */ + /* + * Nonzero if process_pending_signals() needs to do something (either + * handle a pending signal or unblock signals). + * This flag is written from a signal handler so should be accessed via + * the qatomic_read() and qatomic_set() functions. (It is not accessed + * from multiple threads.) + */ + int signal_pending; uint8_t stack[]; } __attribute__((aligned(16))) TaskState; From patchwork Mon Jan 31 19:56:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 12731132 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AA598C433F5 for ; Mon, 31 Jan 2022 20:42:33 +0000 (UTC) Received: from localhost ([::1]:35952 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nEdVQ-0000Hs-Om for qemu-devel@archiver.kernel.org; Mon, 31 Jan 2022 15:42:32 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42756) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nEcnb-0004ll-Hu for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:15 -0500 Received: from [2607:f8b0:4864:20::131] (port=39530 helo=mail-il1-x131.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nEcnD-0002c3-3h for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:06 -0500 Received: by mail-il1-x131.google.com with SMTP id z7so12400811ilb.6 for ; Mon, 31 Jan 2022 11:56:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6fk8Rm7tbwnMJwW6ytgiwa7PMfU+rVxxXH2pSHcB2Zs=; b=6DO3aUHBFwRcvQXdDht3Ks10VZ5Oi1OzItTtVonDCJm7duSqHovv5jLOoXV+kYtSgG EAHd9q0cIZYpQuXALjSphnmvV/Um4PxfgoZMsxS0Z257tbFJk0bPxuR3gLBkeLNKfpi7 kv3xtvxhasAD/eGi8Vh5720JxekRKN6N6yfA4XJ+WxyqG/qnI5Vx8A+fC+BHSh0tKWWq JqLC0GLQ15adKndAFaxyL0L8EXXWGaxB965B6KvJvoKO7JkhwOCfAPEgSXy+XCpSiXLj ipkXwnZg6YyWmU7TkKLrH7uHR2gVmXI2sFs4FlzglyZvrYJP7ZLtOGX/MJVYsusHFwrw fdYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6fk8Rm7tbwnMJwW6ytgiwa7PMfU+rVxxXH2pSHcB2Zs=; b=3fiqV0F24Dw9AFQu3O2CcvD7FKzIxHZfNROB0j5Byojjxho24d07NlC6ONojKuydi0 UEy8Ygqs2BKb+yJ4yklUmctNeYcL4tKroAXF3T6bBaBDfQV4KfZxzoD/PxUARRjUP5sT VqYgw2FTmKnvi39yoTXmkNjdlNmXHBUnvEw4vnNttCfZs+/wgINPHL65Ojb5zxqJ74/N Vdo6qn3KwIbouCZyoL+3oi0sPVJ2go7uBQo1lmMPDZ0uiOuK5dk+dBlQLbzv/96jsdL1 HcDSFj+r02V+R07SdDgX/TjYbislma/0ejsaBOCeF3oqAAgLl9T/+ZHJ8GxzDc9UsiZ2 294A== X-Gm-Message-State: AOAM533Yh/sIKT8FbTj3V+qBrB/7wKFeNhaXgM6oAms8cuyk8Ek5GD/4 UCRq0fGJS261blyNNUPLETe4+4fKNJwHyw== X-Google-Smtp-Source: ABdhPJxP8/7HM6nTabyvEwwLaeyYAl078joBNk6OxjAJJQtm9jtMebKrTNPDjjdDBvSktf+8Ixu1BQ== X-Received: by 2002:a92:d84c:: with SMTP id h12mr4698629ilq.168.1643658997179; Mon, 31 Jan 2022 11:56:37 -0800 (PST) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id j2sm1972989ilu.82.2022.01.31.11.56.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jan 2022 11:56:36 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PULL 07/40] bsd-user/arm/target_arch_cpu.h: Move EXCP_ATOMIC to match linux-user Date: Mon, 31 Jan 2022 12:56:03 -0700 Message-Id: <20220131195636.31991-8-imp@bsdimp.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220131195636.31991-1-imp@bsdimp.com> References: <20220131195636.31991-1-imp@bsdimp.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::131 (failed) Received-SPF: none client-ip=2607:f8b0:4864:20::131; envelope-from=imp@bsdimp.com; helo=mail-il1-x131.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Kyle Evans , Richard Henderson , def@FreeBSD.org, jrtc27@FreeBSD.org, Warner Losh Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Move the EXCP_ATOMIC case to match linux-user/arm/cpu_loop.c:cpu_loop ordering. Signed-off-by: Warner Losh Reviewed-by: Peter Maydell Reviewed-by: Richard Henderson --- bsd-user/arm/target_arch_cpu.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bsd-user/arm/target_arch_cpu.h b/bsd-user/arm/target_arch_cpu.h index c675419c30a..c526fc73502 100644 --- a/bsd-user/arm/target_arch_cpu.h +++ b/bsd-user/arm/target_arch_cpu.h @@ -180,12 +180,12 @@ static inline void target_cpu_loop(CPUARMState *env) queue_signal(env, info.si_signo, &info); } break; - case EXCP_ATOMIC: - cpu_exec_step_atomic(cs); - break; case EXCP_YIELD: /* nothing to do here for user-mode, just resume guest code */ break; + case EXCP_ATOMIC: + cpu_exec_step_atomic(cs); + break; default: fprintf(stderr, "qemu: unhandled CPU exception 0x%x - aborting\n", trapnr); From patchwork Mon Jan 31 19:56:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 12731121 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8E5AFC433F5 for ; Mon, 31 Jan 2022 20:36:00 +0000 (UTC) Received: from localhost ([::1]:45716 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nEdP5-0004Nj-Gc for qemu-devel@archiver.kernel.org; Mon, 31 Jan 2022 15:35:59 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43290) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nEcnl-00054C-6R for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:25 -0500 Received: from [2607:f8b0:4864:20::d33] (port=44560 helo=mail-io1-xd33.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nEcnb-0002cJ-Qt for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:24 -0500 Received: by mail-io1-xd33.google.com with SMTP id p63so17548543iod.11 for ; Mon, 31 Jan 2022 11:56:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/PjL9OS801//J6FLPGxe5bj91YwywO1H07GXqkeIugE=; b=R9qydVIq5yCAAjfQY7m0iL0DFx8mEWbc04Kc1HF9nHt84w9GwhkeyCUqwQw0Xddc+e JNTHVw8qpEnsQTgpSZHHP4DMixv9pyvW0/RglzToT2PXrnSXWY+6WBRmcZm5O8XE2AKf tlVkucauIE1b5rsr0PFUg5K78SMoIsA4I9FoFaXFcI5R1uiL+meVcLMdCDnVRetkMd18 Rqt32YQtJDIA3fe4MnzWeTudvk0V6ispR2FdVYkCSitY8wcJNKWVsNnefPxMERUKbYit Pk8DdzmLBJr1KFwnnMxYF24UpjGZyVMwQswhUrUEQteeQcsvtMofncQtwO8Viu7mofy6 Nv7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/PjL9OS801//J6FLPGxe5bj91YwywO1H07GXqkeIugE=; b=Exbs1FjN+tXbO1Oha8wD5G9T64WSXPeoDnQnv8KDjpN44usDcPmnOlJWBjbZX0VeYy bi9JGvqUOa9yJ5rgZO/a97MlxOxTfex8zV3tO0nKKiXZXvV3LyCERIrNf6fmSO/U47R8 fw7i/0QsBkV4T7AxGhbmqiYtdW3J6DbakIodCbXR6l23WSLBW5AGwdm9yCqjONC8fvGK Vn74T6TfHV+Pujmqjsa5/VUcWNncNZKvg2a26qrrtRfM04E+woiQhivxOdJ4K454lsXq oVr+6kHxQRj0H0a0NHGrbJllPapsDEyJFUpEigWO3QCUk9ApXYW5Jdig4Io+9jhb1S44 l+yg== X-Gm-Message-State: AOAM531wlujjRAxsDMyHNxX50cEUEL7wdewejOmGUQntqR+DaARjOiV8 255zbfRQvUYMOhDUrRrcHFSjPVEPGHwr0A== X-Google-Smtp-Source: ABdhPJzMSSRmLg8X8zh89BkTxK7lzDkxlmGd7j1JFqSQPyI6vi2BlWj6OheGL/3zT6TH9T7PX5u0aA== X-Received: by 2002:a05:6602:3411:: with SMTP id n17mr11937169ioz.128.1643658998219; Mon, 31 Jan 2022 11:56:38 -0800 (PST) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id j2sm1972989ilu.82.2022.01.31.11.56.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jan 2022 11:56:37 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PULL 08/40] bsd-user/signal.c: implement force_sig_fault Date: Mon, 31 Jan 2022 12:56:04 -0700 Message-Id: <20220131195636.31991-9-imp@bsdimp.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220131195636.31991-1-imp@bsdimp.com> References: <20220131195636.31991-1-imp@bsdimp.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::d33 (failed) Received-SPF: none client-ip=2607:f8b0:4864:20::d33; envelope-from=imp@bsdimp.com; helo=mail-io1-xd33.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Stacey Son , Kyle Evans , Richard Henderson , def@FreeBSD.org, jrtc27@FreeBSD.org, Warner Losh Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Start to implement the force_sig_fault code. This currently just calls queue_signal(). The bsd-user fork version of that will handle this the synchronous nature of this call. Add signal-common.h to hold signal helper functions like force_sig_fault. Signed-off-by: Stacey Son Signed-off-by: Kyle Evans Signed-off-by: Warner Losh Reviewed-by: Peter Maydell Reviewed-by: Richard Henderson --- bsd-user/signal-common.h | 14 ++++++++++++++ bsd-user/signal.c | 18 ++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 bsd-user/signal-common.h diff --git a/bsd-user/signal-common.h b/bsd-user/signal-common.h new file mode 100644 index 00000000000..6207417d39e --- /dev/null +++ b/bsd-user/signal-common.h @@ -0,0 +1,14 @@ +/* + * Emulation of BSD signals + * + * Copyright (c) 2013 Stacey Son + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef SIGNAL_COMMON_H +#define SIGNAL_COMMON_H + +void force_sig_fault(int sig, int code, abi_ulong addr); + +#endif diff --git a/bsd-user/signal.c b/bsd-user/signal.c index 05b277c6422..1206d0d728c 100644 --- a/bsd-user/signal.c +++ b/bsd-user/signal.c @@ -19,6 +19,7 @@ #include "qemu/osdep.h" #include "qemu.h" +#include "signal-common.h" /* * Stubbed out routines until we merge signal support from bsd-user @@ -34,6 +35,23 @@ void queue_signal(CPUArchState *env, int sig, target_siginfo_t *info) qemu_log_mask(LOG_UNIMP, "No signal queueing, dropping signal %d\n", sig); } +/* + * Force a synchronously taken QEMU_SI_FAULT signal. For QEMU the + * 'force' part is handled in process_pending_signals(). + */ +void force_sig_fault(int sig, int code, abi_ulong addr) +{ + CPUState *cpu = thread_cpu; + CPUArchState *env = cpu->env_ptr; + target_siginfo_t info = {}; + + info.si_signo = sig; + info.si_errno = 0; + info.si_code = code; + info.si_addr = addr; + queue_signal(env, sig, &info); +} + void signal_init(void) { } From patchwork Mon Jan 31 19:56:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 12731138 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6D9F5C433EF for ; Mon, 31 Jan 2022 20:49:48 +0000 (UTC) Received: from localhost ([::1]:51756 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nEdcR-0002a3-H3 for qemu-devel@archiver.kernel.org; Mon, 31 Jan 2022 15:49:47 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43236) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nEcnk-00053r-1g for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:25 -0500 Received: from [2607:f8b0:4864:20::134] (port=37392 helo=mail-il1-x134.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nEcnb-0002cS-Ov for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:23 -0500 Received: by mail-il1-x134.google.com with SMTP id z4so12420254ilz.4 for ; Mon, 31 Jan 2022 11:56:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=IIwWr4XQkvp7rEwjOGXmWZZadDj8kG6ZitoG4k00onk=; b=FOphxRvuBD4S0RNhmNtnhkO3QkRgy4HOtkoHcLsYsoqhQXdJaWS0cShK6dVqdVdxE7 IYlfOpwSRd8ZNfBAwt76apHO96kGPR4NGueBHm7JorHVzsr2604hf7mmwEeZpdXythqu e2GhhpGRWGpsUUoIo8zpFkJi1szWVdk2zSwfncLN/7HQI60+Azic/dMJ1RpZoXrp+iyZ 8LaloBi2xauR48de3CRKJUTo+C79/MuIv/+QKeCrZaQaymViTc9nJOTNTdxm6o4S8s1Y 0Hqup/gsF1y2sT27MmSXHzpH8Rux/rv9hAVamUuOdDQwfuZKe3LvSf12WyznYjRE6Z9h 6Z0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IIwWr4XQkvp7rEwjOGXmWZZadDj8kG6ZitoG4k00onk=; b=CCW81W/t6/dGNy2ionU50hoXTsK3duOP4a21vUJT2yKQ1ppuIlXhudA2bsO7t4N1/e wjHfsRiFHldz+G1U0thhYlpYikr8gn2v3yALcEHs9CFMLN2al5cjfg2qjLCD5TMubLvL cfLw3qMK//mEC0Mwwx2fdK1FVxY4scXcs/QKWq44q/0StJ/bsyWkYQu6++wYJLgYz+PS QiuDeHphVoNGTzDqYjppEhnsckWSOYvrEjcNTImUfZdeXDBatigh2BC0kV1K8/EfVmc7 T8c9pnufxVIGx6Goo5Iq55zw4xXUC4pahETW6gGG05TkZuU9/WnLt/aSGt132lq8XJnz nzew== X-Gm-Message-State: AOAM530co6oSb+3YzwskrYdvTsczZ8aUyFqpKqdB/Kqh5tnnCESYVMcK AV0ti1G0T+iyy1OXL/VfG7I55rbtUcFAUQ== X-Google-Smtp-Source: ABdhPJz94Iw1AG4kbvBNH/LyUtaiW3nzlKU//Q/OLqGtqz2VD9wBgAbJWDUrCrLNrJ1ZDzWt2IudIA== X-Received: by 2002:a05:6e02:1d08:: with SMTP id i8mr13132561ila.121.1643658999099; Mon, 31 Jan 2022 11:56:39 -0800 (PST) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id j2sm1972989ilu.82.2022.01.31.11.56.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jan 2022 11:56:38 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PULL 09/40] bsd-user/signal-common.h: Move signal functions prototypes to here Date: Mon, 31 Jan 2022 12:56:05 -0700 Message-Id: <20220131195636.31991-10-imp@bsdimp.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220131195636.31991-1-imp@bsdimp.com> References: <20220131195636.31991-1-imp@bsdimp.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::134 (failed) Received-SPF: none client-ip=2607:f8b0:4864:20::134; envelope-from=imp@bsdimp.com; helo=mail-il1-x134.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Kyle Evans , Richard Henderson , def@FreeBSD.org, jrtc27@FreeBSD.org, Warner Losh Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/arm/target_arch_cpu.h | 1 + bsd-user/i386/target_arch_cpu.h | 1 + bsd-user/qemu.h | 8 -------- bsd-user/signal-common.h | 6 ++++++ bsd-user/x86_64/target_arch_cpu.h | 1 + 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/bsd-user/arm/target_arch_cpu.h b/bsd-user/arm/target_arch_cpu.h index c526fc73502..b7f728fd667 100644 --- a/bsd-user/arm/target_arch_cpu.h +++ b/bsd-user/arm/target_arch_cpu.h @@ -21,6 +21,7 @@ #define _TARGET_ARCH_CPU_H_ #include "target_arch.h" +#include "signal-common.h" #define TARGET_DEFAULT_CPU_MODEL "any" diff --git a/bsd-user/i386/target_arch_cpu.h b/bsd-user/i386/target_arch_cpu.h index b28602adbbd..472a96689fc 100644 --- a/bsd-user/i386/target_arch_cpu.h +++ b/bsd-user/i386/target_arch_cpu.h @@ -20,6 +20,7 @@ #define _TARGET_ARCH_CPU_H_ #include "target_arch.h" +#include "signal-common.h" #define TARGET_DEFAULT_CPU_MODEL "qemu32" diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index 671b26f00cc..99c37fc9942 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -199,14 +199,6 @@ print_openbsd_syscall(int num, void print_openbsd_syscall_ret(int num, abi_long ret); extern int do_strace; -/* signal.c */ -void process_pending_signals(CPUArchState *cpu_env); -void signal_init(void); -long do_sigreturn(CPUArchState *env); -long do_rt_sigreturn(CPUArchState *env); -void queue_signal(CPUArchState *env, int sig, target_siginfo_t *info); -abi_long do_sigaltstack(abi_ulong uss_addr, abi_ulong uoss_addr, abi_ulong sp); - /* mmap.c */ int target_mprotect(abi_ulong start, abi_ulong len, int prot); abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, diff --git a/bsd-user/signal-common.h b/bsd-user/signal-common.h index 6207417d39e..f9a9d1e01aa 100644 --- a/bsd-user/signal-common.h +++ b/bsd-user/signal-common.h @@ -9,6 +9,12 @@ #ifndef SIGNAL_COMMON_H #define SIGNAL_COMMON_H +long do_rt_sigreturn(CPUArchState *env); +abi_long do_sigaltstack(abi_ulong uss_addr, abi_ulong uoss_addr, abi_ulong sp); +long do_sigreturn(CPUArchState *env); void force_sig_fault(int sig, int code, abi_ulong addr); +void process_pending_signals(CPUArchState *env); +void queue_signal(CPUArchState *env, int sig, target_siginfo_t *info); +void signal_init(void); #endif diff --git a/bsd-user/x86_64/target_arch_cpu.h b/bsd-user/x86_64/target_arch_cpu.h index 5172b230f09..14def48adb5 100644 --- a/bsd-user/x86_64/target_arch_cpu.h +++ b/bsd-user/x86_64/target_arch_cpu.h @@ -20,6 +20,7 @@ #define _TARGET_ARCH_CPU_H_ #include "target_arch.h" +#include "signal-common.h" #define TARGET_DEFAULT_CPU_MODEL "qemu64" From patchwork Mon Jan 31 19:56:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 12731094 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 901A5C433EF for ; Mon, 31 Jan 2022 20:18:46 +0000 (UTC) Received: from localhost ([::1]:39160 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nEd8P-0005Qj-Bu for qemu-devel@archiver.kernel.org; Mon, 31 Jan 2022 15:18:45 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42762) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nEcnb-0004ls-Iv for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:15 -0500 Received: from [2607:f8b0:4864:20::d2e] (port=36662 helo=mail-io1-xd2e.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nEcnI-0002dc-RW for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:14 -0500 Received: by mail-io1-xd2e.google.com with SMTP id h7so18426579iof.3 for ; Mon, 31 Jan 2022 11:56:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SGJfV2pZjNq6/Lkgq5idUT85KpfDUjfI//YVpMiMT3c=; b=ASz31J81lA7yv78WrHgzg7lo+F4ndKfXkJKRC7nDqs21+qipa2pw3sMURp5qQo3mYr kmSC6g98Aw9e8dDkuJol+K50wXMta7imOeMxSDgaFahuUC2zm4RoR4dQEyCAbxd3J5qp 4lT91F8tuQAsygFXnjUTMnSAJRJaYHNmwDBpePTkN0u6ryv9IzZIBwnYxpaLl4F7tHxB u7x/De7Gac1ghBFPfOaY28OziWD+1YBIQUvIiShAV5TtxmF+gYtPVAvyffbfFBYXrg7o zLb6WSaHa6eYRqFxbod8fdj77ju6keGFtmAyw3zA/2c2FSdDSRKRImHRoBMd4Yjcj/LU 4Rkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SGJfV2pZjNq6/Lkgq5idUT85KpfDUjfI//YVpMiMT3c=; b=jqI56Ct6arGh9NormjGC2s5zBC3mAuHvwnt+vPURKoyY2Uihn3TFnZRG4AEZ0UvRBB DhVFsIUNb8ehFimYVmhChCK/20/lkGFU7S9mDnHVqNh1sAZWT8qNPIVUEEYPQrTLNRUK tKrKKBhyQdESqDv2a9HC/vOwn4NyoKGmVakkEX923DOQKAf7WFzOYVxmbB6hIpFYIQeD 8ED8I3YPmoL2ogUI4i6JO87X83zX7ycpZNiOp+eUNOglm7d2eG2KwzxD3RJCVt0FyU3y jV+5AK7zc9oZ0dX37ZbBLdBI7F9lQ4+/8YgUU8N9qL++rQsuMEnS++/u1wVg1aV7Ll2d OebQ== X-Gm-Message-State: AOAM532oz4iEHp+zH098klJJbhafTC2a9k/kczR2aASPgdZz43eVvXQJ LCy9uS1VyVJX9/AFtLJaS3KBgagdWZiOBA== X-Google-Smtp-Source: ABdhPJyIX1ivq6eo+rjEh2X/LRYp1bHctz7Sz0ULDqHeOtLx1igvZWvcLe85EZ6iqp0n1QeoLqw2Ng== X-Received: by 2002:a05:6638:382a:: with SMTP id i42mr10148857jav.256.1643659000181; Mon, 31 Jan 2022 11:56:40 -0800 (PST) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id j2sm1972989ilu.82.2022.01.31.11.56.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jan 2022 11:56:39 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PULL 10/40] bsd-user/signal.c: Implement cpu_loop_exit_sigsegv Date: Mon, 31 Jan 2022 12:56:06 -0700 Message-Id: <20220131195636.31991-11-imp@bsdimp.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220131195636.31991-1-imp@bsdimp.com> References: <20220131195636.31991-1-imp@bsdimp.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::d2e (failed) Received-SPF: none client-ip=2607:f8b0:4864:20::d2e; envelope-from=imp@bsdimp.com; helo=mail-io1-xd2e.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Stacey Son , Kyle Evans , Richard Henderson , def@FreeBSD.org, jrtc27@FreeBSD.org, Warner Losh Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" First attempt at implementing cpu_loop_exit_sigsegv, mostly copied from linux-user version of this function. Signed-off-by: Stacey Son Signed-off-by: Kyle Evans Signed-off-by: Warner Losh Reviewed-by: Peter Maydell Reviewed-by: Richard Henderson --- bsd-user/signal.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/bsd-user/signal.c b/bsd-user/signal.c index 1206d0d728c..12de0e2dea4 100644 --- a/bsd-user/signal.c +++ b/bsd-user/signal.c @@ -20,6 +20,7 @@ #include "qemu/osdep.h" #include "qemu.h" #include "signal-common.h" +#include "hw/core/tcg-cpu-ops.h" /* * Stubbed out routines until we merge signal support from bsd-user @@ -63,9 +64,17 @@ void process_pending_signals(CPUArchState *cpu_env) void cpu_loop_exit_sigsegv(CPUState *cpu, target_ulong addr, MMUAccessType access_type, bool maperr, uintptr_t ra) { - qemu_log_mask(LOG_UNIMP, "No signal support for SIGSEGV\n"); - /* unreachable */ - abort(); + const struct TCGCPUOps *tcg_ops = CPU_GET_CLASS(cpu)->tcg_ops; + + if (tcg_ops->record_sigsegv) { + tcg_ops->record_sigsegv(cpu, addr, access_type, maperr, ra); + } + + force_sig_fault(TARGET_SIGSEGV, + maperr ? TARGET_SEGV_MAPERR : TARGET_SEGV_ACCERR, + addr); + cpu->exception_index = EXCP_INTERRUPT; + cpu_loop_exit_restore(cpu, ra); } void cpu_loop_exit_sigbus(CPUState *cpu, target_ulong addr, From patchwork Mon Jan 31 19:56:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 12731140 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B9696C433F5 for ; Mon, 31 Jan 2022 20:52:56 +0000 (UTC) Received: from localhost ([::1]:60526 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nEdfT-0007uT-Nn for qemu-devel@archiver.kernel.org; Mon, 31 Jan 2022 15:52:55 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43288) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nEcnl-00054B-5z for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:25 -0500 Received: from [2607:f8b0:4864:20::d2d] (port=35653 helo=mail-io1-xd2d.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nEcnb-0002dg-SF for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:24 -0500 Received: by mail-io1-xd2d.google.com with SMTP id 9so18464814iou.2 for ; Mon, 31 Jan 2022 11:56:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WzkIKVsgbL3BkTFsfAwelEbf+OyNiGDSqNoHVUm1RWE=; b=BgGg6kln7oKQ6M96TqFFD0Uhe1+tLpZtQ95+L31nbWLmJ8u/W0F8qIroOboJw6wgE9 dKIdImf8UdnUIDLqozRJeFpi1lJjTgMlPtyRXyB9FvYp0AeikDm+0LGknCC6+RIF1IP3 Iga1iBeq0QQhUpRLQrH5IIKWOwcfRfrHmP4Rpo7f2xs6Y3DKOkJdol1tGPuYciDt8Xwf bYOdA2xXFG1g3aRPt5mJp9m3LdrbSz4vxbo9z/7y/Hce+++qEv9548XT4+CzwfU27/xx zl/vJ0sAJu5mssri3nUlPBH4t2RrxhPHN/2axYnhmU0r4V5s1G8WYtkJ8TdmAPuzY9Kf zTsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WzkIKVsgbL3BkTFsfAwelEbf+OyNiGDSqNoHVUm1RWE=; b=m10GCTu/KilaLpM6zjTlUMWdilmbenv7RD1OlfhCMp0Rz+lIyStVjDskNT4JiQydXF 0AlHPU/JHVSCCcsooHLdzdzmv53CY2A+T5SvZpKtkEGXPzoAUdBb1BqupVNzUwD57hvS KSusEk4SVbXUK9d3om7mAVUjrYnyW8FdhbanE3r8WrCh5T+wQLzhkajq6X0rYi6ot6f2 D/lwVunuSN0a6Yf8Df6LX+q7QZ4JsIdn5C5p+CTdPo5oDWa+iDLUhvTCWpm2lTArDE1G tc863nBH9Xr7iryPxoEpUuvVMA3McK14gVek1FqtCBPKcl4aqzkkxef58HYn7ND7haGE veeQ== X-Gm-Message-State: AOAM532T4TiD75a+IxpdMUaAg4QhzECLZi7UpeZvLE4B2aTRZp1c+AJw pM+7MJX3bxfbTe2LWZqkXQjT6YWHZo93hg== X-Google-Smtp-Source: ABdhPJwMpOfZ+7jkhA3MaP7nR+GTHZh/UXr3ndEsgDxGf0TqvD2gxK9+Xaslcfe32ytoyqpJs9cUYA== X-Received: by 2002:a02:2208:: with SMTP id o8mr7844047jao.72.1643659000990; Mon, 31 Jan 2022 11:56:40 -0800 (PST) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id j2sm1972989ilu.82.2022.01.31.11.56.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jan 2022 11:56:40 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PULL 11/40] bsd-user/signal.c: implement cpu_loop_exit_sigbus Date: Mon, 31 Jan 2022 12:56:07 -0700 Message-Id: <20220131195636.31991-12-imp@bsdimp.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220131195636.31991-1-imp@bsdimp.com> References: <20220131195636.31991-1-imp@bsdimp.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::d2d (failed) Received-SPF: none client-ip=2607:f8b0:4864:20::d2d; envelope-from=imp@bsdimp.com; helo=mail-io1-xd2d.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Stacey Son , Kyle Evans , Richard Henderson , def@FreeBSD.org, jrtc27@FreeBSD.org, Warner Losh Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" First attempt at implementing cpu_loop_exit_sigbus, mostly copied from linux-user version of this function. Signed-off-by: Stacey Son Signed-off-by: Kyle Evans Signed-off-by: Warner Losh Reviewed-by: Peter Maydell Reviewed-by: Richard Henderson --- bsd-user/signal.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/bsd-user/signal.c b/bsd-user/signal.c index 12de0e2dea4..844dfa19095 100644 --- a/bsd-user/signal.c +++ b/bsd-user/signal.c @@ -80,7 +80,13 @@ void cpu_loop_exit_sigsegv(CPUState *cpu, target_ulong addr, void cpu_loop_exit_sigbus(CPUState *cpu, target_ulong addr, MMUAccessType access_type, uintptr_t ra) { - qemu_log_mask(LOG_UNIMP, "No signal support for SIGBUS\n"); - /* unreachable */ - abort(); + const struct TCGCPUOps *tcg_ops = CPU_GET_CLASS(cpu)->tcg_ops; + + if (tcg_ops->record_sigbus) { + tcg_ops->record_sigbus(cpu, addr, access_type, ra); + } + + force_sig_fault(TARGET_SIGBUS, TARGET_BUS_ADRALN, addr); + cpu->exception_index = EXCP_INTERRUPT; + cpu_loop_exit_restore(cpu, ra); } From patchwork Mon Jan 31 19:56:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 12731102 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1F0C7C433F5 for ; Mon, 31 Jan 2022 20:24:27 +0000 (UTC) Received: from localhost ([::1]:55934 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nEdDu-00008m-60 for qemu-devel@archiver.kernel.org; Mon, 31 Jan 2022 15:24:26 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42890) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nEcnc-0004qO-T5 for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:16 -0500 Received: from [2607:f8b0:4864:20::d2a] (port=47078 helo=mail-io1-xd2a.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nEcna-0002dn-Cr for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:16 -0500 Received: by mail-io1-xd2a.google.com with SMTP id e79so18352527iof.13 for ; Mon, 31 Jan 2022 11:56:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Bc6DcyWj3C/koTrEJ9qrW7xAW1qoks2DIh1czZk9FmE=; b=WdE0MqagTBN+c8wUZvMuRF0bcnDpk4w2PKZyjgJC/Yyn9MzsUAmHWrUeLMVGuiGJ5W HcvOg3B3b2eCIcP2p2rGkFZ6iMpUYjOIPx2XDv6fO7oJ5Ai1gaO58mA1YVSSMFG6RZgB BWrDLDAwEj1bMhhsSt3V5ul3LB5CLxrkM6263xYeCAckITOOSapPFjAR93SAAAVss42O yZZXBTaqXfowlycfzhxU68f7FpPH9IQcRH34fl9B7nP36Y2BrKA9gHrREPqF4Hb5V0+L jtQXW5Fuky3qHPJID6mViF+hBoY18IJctYPsfBghqOD3RbR/2qQh+FTLK5ZFbJmrxQS/ 6i2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Bc6DcyWj3C/koTrEJ9qrW7xAW1qoks2DIh1czZk9FmE=; b=CSHUyYvIcJyOkB3Pcf6NTx04c5szKD/hySDPq2Zq83sAKYw8TvantMrefSfoPBD739 N9fvponioRZB4ATIRlnWQpA5CxkeQG0tqqi967Lo4cLZVHY+V6PZZZ7JGTDsy8cMmizc 0T+cWD/nDBO2xd+F3HR4p6+CxCAAX1PL5RJA/ZQT5r40+XlE4KbprnnFiGgng+4kRUQe 4v7lGNKUbigkSUGer4dHLOEW5C2B8hfYFhRv98FF903Vbw13NWGHmrWL6rGsiyuovBkf BRNcwiqAVXLbwF3MLAjYxLTfruWDhf3EYdkw1xvyAXBv4f+dHBVvVk9brwlpkDIPddMK iPww== X-Gm-Message-State: AOAM530+JVRmwNKe+hH9GY72cFJ8y+6zn0LpXDlm2jkNDuSAAf9tohBP QWt3BqgSP+XdaTx7BNzzht6OKVoGv57Hhg== X-Google-Smtp-Source: ABdhPJxUpY/FL7G+jfntG/FwNVvA9lRe4eB3uat5LLxN8BnrZB91f7GuzJ/cfEbjlA5ccTjIhhZu3g== X-Received: by 2002:a05:6602:1507:: with SMTP id g7mr7083472iow.7.1643659002143; Mon, 31 Jan 2022 11:56:42 -0800 (PST) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id j2sm1972989ilu.82.2022.01.31.11.56.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jan 2022 11:56:41 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PULL 12/40] bsd-user/arm/arget_arch_cpu.h: Move EXCP_DEBUG and EXCP_BKPT together Date: Mon, 31 Jan 2022 12:56:08 -0700 Message-Id: <20220131195636.31991-13-imp@bsdimp.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220131195636.31991-1-imp@bsdimp.com> References: <20220131195636.31991-1-imp@bsdimp.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::d2a (failed) Received-SPF: none client-ip=2607:f8b0:4864:20::d2a; envelope-from=imp@bsdimp.com; helo=mail-io1-xd2a.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Kyle Evans , Richard Henderson , def@FreeBSD.org, jrtc27@FreeBSD.org, Warner Losh Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Implement EXCP_DEBUG and EXCP_BKPT the same, as is done in linux-user. The prior adjustment of register 15 isn't needed, so remove that. Remove a redunant comment (that code in FreeBSD never handled break points). It's unclear why BKPT was an alias for system calls, but FreeBSD doesn't do that today. Signed-off-by: Warner Losh Reviewed-by: Peter Maydell Reviewed-by: Richard Henderson --- bsd-user/arm/target_arch_cpu.h | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/bsd-user/arm/target_arch_cpu.h b/bsd-user/arm/target_arch_cpu.h index b7f728fd667..05b19ce6119 100644 --- a/bsd-user/arm/target_arch_cpu.h +++ b/bsd-user/arm/target_arch_cpu.h @@ -65,19 +65,7 @@ static inline void target_cpu_loop(CPUARMState *env) } break; case EXCP_SWI: - case EXCP_BKPT: { - /* - * system call - * See arm/arm/trap.c cpu_fetch_syscall_args() - */ - if (trapnr == EXCP_BKPT) { - if (env->thumb) { - env->regs[15] += 2; - } else { - env->regs[15] += 4; - } - } n = env->regs[7]; if (bsd_type == target_freebsd) { int ret; @@ -172,14 +160,8 @@ static inline void target_cpu_loop(CPUARMState *env) queue_signal(env, info.si_signo, &info); break; case EXCP_DEBUG: - { - - info.si_signo = TARGET_SIGTRAP; - info.si_errno = 0; - info.si_code = TARGET_TRAP_BRKPT; - info.si_addr = env->exception.vaddress; - queue_signal(env, info.si_signo, &info); - } + case EXCP_BKPT: + force_sig_fault(TARGET_SIGTRAP, TARGET_TRAP_BRKPT, env->regs[15]); break; case EXCP_YIELD: /* nothing to do here for user-mode, just resume guest code */ From patchwork Mon Jan 31 19:56:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 12731216 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5C6ACC433EF for ; Mon, 31 Jan 2022 21:10:02 +0000 (UTC) Received: from localhost ([::1]:59648 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nEdw0-00021W-Lh for qemu-devel@archiver.kernel.org; Mon, 31 Jan 2022 16:10:00 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43282) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nEcnl-000548-3N for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:25 -0500 Received: from [2607:f8b0:4864:20::12c] (port=43823 helo=mail-il1-x12c.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nEcnb-0002du-Qo for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:24 -0500 Received: by mail-il1-x12c.google.com with SMTP id d3so12385831ilr.10 for ; Mon, 31 Jan 2022 11:56:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=w4FRMcODA3Yw9ipRGV2deCv5GoQkPWInOh9N0fcX/6E=; b=GVhiZpjA5T+Cg+ZkAMZMJ1sP/5R6wcjvCoxqqZBOMOMtElaYdxTTjZfRcQrJlWNg9B BW6VOo6oXFReOp+7TusA6p6Z8kic8KIyNiEmoFVl1ot2/SucZjxNk9TO0KT1WtyPJUVA fxDcO+1feYTBm4IYGPtReDEAZEu/GeLwxyyDTXgQIwIqMWOBMU/pc4hixOOORf6Fpyc1 uSYCN6yq7JwDQND6yuTQebmN1FfFpU9I2kVlXIm6uLPUHgjvID5Vcjdagh3mm+WIpJ5L FyXTjEvhycaHJGkKAzDSlO2af6egXHeOJGn0apbrVx6cL5CYpN3/yV5uNAQr5BcWK3qZ qnEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=w4FRMcODA3Yw9ipRGV2deCv5GoQkPWInOh9N0fcX/6E=; b=rnqo9w40ryRSMY2HB15B7ZexKr29iNeeeRzJaI7VmGHlpz3IldYYUbZET8Hh8fBZt2 qTz00DdkpzUYxHYMIEhhqUmtHD3TenrH7TCAhgoUu304NQS+AyY38BjMQUr+CnndV3Ym 7x2avUWpwqitGAx7Lt5+anOpLclxIUJOjBg73ZztS825kSrvjefhZThaZKBn5wuXYiBj FVgsCRd5c9v1B9NfsAJi9S+GkVDFob00df4eAPLmTSJLnTCXSoUYpPfaHlT2kQnrIgrG J0XuV4fawwAlE3tx8Dg5jpvciIinTqBeV9QRJU2qB4liGHS2VlQjnvv/aBeU6SzBwwi7 gdPA== X-Gm-Message-State: AOAM530L0Tw2uxkhbx3WlngcYC2N4xyOt97scxq5g0c8u7eTT37GyvSk Q0oFkpTL9fHBh/mqcz4ta70v+wG7EHgVWw== X-Google-Smtp-Source: ABdhPJzzPjbjMhHLbpulJPmj0qeWmmV3pbTaYCgFLMAj/zuEm8fzMCqCFq7+JEM/WSBic0+HxOdhWQ== X-Received: by 2002:a92:cd8e:: with SMTP id r14mr13527540ilb.53.1643659003419; Mon, 31 Jan 2022 11:56:43 -0800 (PST) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id j2sm1972989ilu.82.2022.01.31.11.56.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jan 2022 11:56:43 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PULL 13/40] bsd-user/arm/target_arch_cpu.h: Correct code pointer Date: Mon, 31 Jan 2022 12:56:09 -0700 Message-Id: <20220131195636.31991-14-imp@bsdimp.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220131195636.31991-1-imp@bsdimp.com> References: <20220131195636.31991-1-imp@bsdimp.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::12c (failed) Received-SPF: none client-ip=2607:f8b0:4864:20::12c; envelope-from=imp@bsdimp.com; helo=mail-il1-x12c.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Kyle Evans , Richard Henderson , def@FreeBSD.org, jrtc27@FreeBSD.org, Warner Losh Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The code has moved in FreeBSD since the emulator was started, update the comment to reflect that change. Signed-off-by: Warner Losh Reviewed-by: Peter Maydell Reviewed-by: Richard Henderson --- bsd-user/arm/target_arch_cpu.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bsd-user/arm/target_arch_cpu.h b/bsd-user/arm/target_arch_cpu.h index 05b19ce6119..905f13aa1b9 100644 --- a/bsd-user/arm/target_arch_cpu.h +++ b/bsd-user/arm/target_arch_cpu.h @@ -73,7 +73,7 @@ static inline void target_cpu_loop(CPUARMState *env) int32_t syscall_nr = n; int32_t arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8; - /* See arm/arm/trap.c cpu_fetch_syscall_args() */ + /* See arm/arm/syscall.c cpu_fetch_syscall_args() */ if (syscall_nr == TARGET_FREEBSD_NR_syscall) { syscall_nr = env->regs[0]; arg1 = env->regs[1]; From patchwork Mon Jan 31 19:56:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 12731107 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 797D5C433F5 for ; Mon, 31 Jan 2022 20:29:36 +0000 (UTC) Received: from localhost ([::1]:36310 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nEdIt-0006DD-3q for qemu-devel@archiver.kernel.org; Mon, 31 Jan 2022 15:29:35 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42902) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nEcnd-0004rw-B4 for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:17 -0500 Received: from [2607:f8b0:4864:20::d2f] (port=41770 helo=mail-io1-xd2f.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nEcna-0002e0-D4 for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:16 -0500 Received: by mail-io1-xd2f.google.com with SMTP id q204so18390593iod.8 for ; Mon, 31 Jan 2022 11:56:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=p0pz1mYsxMG+ZM0MzZl75FORMdT6nHp51WXALYPrt0k=; b=yKHIpUPvuC7CfZhUIVaY+eAB2DPGRXxwDGIQ2VklII+h4uSgW/BglKx0OpJlM7TCQJ X6Xj1do+Zksnouy5Mu48Gx2X44sTmxILp/kvTj+CONSF6UbQeegCILvJ6W/Tbnox4y5o xEg2rthXwoAmJlMUuK1y9oBvGIlqEWyIcTomiFKHULZtLaMDvYs1UxApIlj3dZ/X8Hiz uadT8Dbzum4cny1079jjtk419/hiXBCNuggS/TiV6yt28Bgxau+qqYM2mt7iHol2t5Oo or0UBlBsUOIRblNtp4SycxSCksLcIMBNZsYy/6yw3NFvy5lebaS6VpFWkypGyJS8eBQu kz0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=p0pz1mYsxMG+ZM0MzZl75FORMdT6nHp51WXALYPrt0k=; b=fzJW2PZBjsIEWXiMtCxTIfnsFpW5M279L1xdH+3bc809WJDxxnAqWYXW3JoqkvcNVI E3p4lwAFA/aNgf/g2J1eNvuaL+PNmgen1ho67ihKINwZ6cF6dp/17NTFnjd140wgi0pf tPBxy0Y5NRpR+eXd3YZPCPwRRMBPRYLhf2h59b2nj+6VVaGDZhEVHZg6L0tFJf+FwmyL 4M6KPyOgvb003+zi9VHq3LhxrsTjr236vb0QajxbewFcddnB82wdhRDOt9GGqiSmWW2x 9rszJ58llCKVRspGssf7d3WNu1JBX8wMPal4m1kCDEYxiOAhJQXIIhA6VPN75LH07fYR F8gA== X-Gm-Message-State: AOAM530BxZKyP3J0Y0vdxf4yR+arJ4tHkwnVZyGSQjcYYv6E8cXAg8Ok hJJEwQOTxhKPOEKMhk3tq6O3Na15GbfAGg== X-Google-Smtp-Source: ABdhPJykNUcrpp7ibap7u7oVHWxyUdHqYyeYXAafgwch5ITwO6xih5FRJywOya+JIKKncQrHdTeHxw== X-Received: by 2002:a05:6638:389a:: with SMTP id b26mr10820116jav.158.1643659004227; Mon, 31 Jan 2022 11:56:44 -0800 (PST) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id j2sm1972989ilu.82.2022.01.31.11.56.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jan 2022 11:56:43 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PULL 14/40] bsd-user/arm/target_arch_cpu.h: Use force_sig_fault for EXCP_UDEF Date: Mon, 31 Jan 2022 12:56:10 -0700 Message-Id: <20220131195636.31991-15-imp@bsdimp.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220131195636.31991-1-imp@bsdimp.com> References: <20220131195636.31991-1-imp@bsdimp.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::d2f (failed) Received-SPF: none client-ip=2607:f8b0:4864:20::d2f; envelope-from=imp@bsdimp.com; helo=mail-io1-xd2f.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Kyle Evans , Richard Henderson , def@FreeBSD.org, jrtc27@FreeBSD.org, Warner Losh Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Use force_sig_fault to implement unknown opcode. This just uninlines that function, so simplify things by using it. Fold in EXCP_NOCP and EXCP_INVSTATE, as is done in linux-user. Make a note about slight differences with FreeBSD in case any of them turn out to be important later. Signed-off-by: Warner Losh Reviewed-by: Peter Maydell Reviewed-by: Richard Henderson --- bsd-user/arm/target_arch_cpu.h | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/bsd-user/arm/target_arch_cpu.h b/bsd-user/arm/target_arch_cpu.h index 905f13aa1b9..9d790176420 100644 --- a/bsd-user/arm/target_arch_cpu.h +++ b/bsd-user/arm/target_arch_cpu.h @@ -51,18 +51,19 @@ static inline void target_cpu_loop(CPUARMState *env) process_queued_cpu_work(cs); switch (trapnr) { case EXCP_UDEF: - { - /* See arm/arm/undefined.c undefinedinstruction(); */ - info.si_addr = env->regs[15]; - - /* illegal instruction */ - info.si_signo = TARGET_SIGILL; - info.si_errno = 0; - info.si_code = TARGET_ILL_ILLOPC; - queue_signal(env, info.si_signo, &info); - - /* TODO: What about instruction emulation? */ - } + case EXCP_NOCP: + case EXCP_INVSTATE: + /* + * See arm/arm/undefined.c undefinedinstruction(); + * + * A number of details aren't emulated (they likely don't matter): + * o Misaligned PC generates ILL_ILLADR (these can't come from qemu) + * o Thumb-2 instructions generate ILLADR + * o Both modes implement coprocessor instructions, which we don't + * do here. FreeBSD just implements them for the VFP coprocessor + * and special kernel breakpoints, trace points, dtrace, etc. + */ + force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPC, env->regs[15]); break; case EXCP_SWI: { From patchwork Mon Jan 31 19:56:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 12731098 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 80DC6C433F5 for ; Mon, 31 Jan 2022 20:22:30 +0000 (UTC) Received: from localhost ([::1]:47582 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nEdC1-0002yh-Dq for qemu-devel@archiver.kernel.org; Mon, 31 Jan 2022 15:22:29 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42840) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nEcnc-0004nA-1m for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:16 -0500 Received: from [2607:f8b0:4864:20::12c] (port=38409 helo=mail-il1-x12c.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nEcnV-0002e6-Ix for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:15 -0500 Received: by mail-il1-x12c.google.com with SMTP id i1so12412234ils.5 for ; Mon, 31 Jan 2022 11:56:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+DlEs5WrZvuXfm29/4/3j1YKa0M1X3SLWmqACMEYKjk=; b=z8yvaXGmjjAJ3zxjpMyRBIyn2YA3hO9O/a6mMOBKDyC0tgNnT17OwJWgvMhm6Lfn7c /GLdOqA1YzzAZsjD8cIqWRY52IS0TwyfVoVZwjNea5t2LoZ/msZwZhvXdFzxtWatLQvx PRKSgiqhXX12m9azSPBFhanXp8i0FXm74sk5qsmEMhSSPcIuRnLZ2y5vuVatNqrwgfp6 aLLwvNTvsrPqbW+DPH4L3z9aE3I8Htelb23UhZWODiYUwbymet5jKBEgbmemLiHWiZm6 etbzfxeUdAL0wPeDsD6L9oXoUFj8aEjgL96zJNSaWkap+pVOd98wil4eLFstNbLAj/B6 QjuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+DlEs5WrZvuXfm29/4/3j1YKa0M1X3SLWmqACMEYKjk=; b=qqWgKxK03MVNfZSACkpsW5tj3F33bzSQsFh0qsemLwBlSVQA4XVfLj+L/gMi6yZJeI dni3x6opLVmBfr/TpVddOV4Ce4p2kiBK9fOngjLwsMd21SOs8R+ILL0ArJggB9xfpPp4 lXh9q96Vv6s82nQoemAqMRmS66/CDCBdkNxrFTvjk3Pg/Nnx8U52reB5SDrQZ495CU4u c0l119+cg2rMpoQjDdmI3G7DmMHrusWLV/6Ssg26B4o/Id3kbq8hIbvpnwQhJhoc4hww cslgFB9bX9rUBl+SaUCGy9l5hW7lCELFTTZD1KpABMWRfiL3jNfEwsCztM+vr2j6Yeir qHqQ== X-Gm-Message-State: AOAM531ewqNGsfsiFfcpOe+B9oWyxivZMKiBeTZRw+Qi5XSzbAtN2LBz nbwKhxeDGDl0Wl1IfdKqHNJSwc3Qp2Y5kw== X-Google-Smtp-Source: ABdhPJyauF7mcsxdPUt3mbZ6nIRT2xtkIXyZcY3taAO3zpQrK1eB5g8marn6ERwGNbLB/V5DZg1V2Q== X-Received: by 2002:a92:c109:: with SMTP id p9mr13239469ile.129.1643659005027; Mon, 31 Jan 2022 11:56:45 -0800 (PST) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id j2sm1972989ilu.82.2022.01.31.11.56.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jan 2022 11:56:44 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PULL 15/40] bsd-user/arm/target_arch_cpu.h: Implement data faults Date: Mon, 31 Jan 2022 12:56:11 -0700 Message-Id: <20220131195636.31991-16-imp@bsdimp.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220131195636.31991-1-imp@bsdimp.com> References: <20220131195636.31991-1-imp@bsdimp.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::12c (failed) Received-SPF: none client-ip=2607:f8b0:4864:20::12c; envelope-from=imp@bsdimp.com; helo=mail-il1-x12c.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Kyle Evans , Richard Henderson , def@FreeBSD.org, jrtc27@FreeBSD.org, Warner Losh Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Update for the richer set of data faults that are now possible. Copied largely from linux-user/arm/cpu_loop.c, with minor typo fixes. Signed-off-by: Warner Losh Reviewed-by: Peter Maydell Reviewed-by: Richard Henderson --- bsd-user/arm/target_arch_cpu.h | 45 ++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/bsd-user/arm/target_arch_cpu.h b/bsd-user/arm/target_arch_cpu.h index 9d790176420..2b395d5c97f 100644 --- a/bsd-user/arm/target_arch_cpu.h +++ b/bsd-user/arm/target_arch_cpu.h @@ -39,8 +39,7 @@ static inline void target_cpu_init(CPUARMState *env, static inline void target_cpu_loop(CPUARMState *env) { - int trapnr; - target_siginfo_t info; + int trapnr, si_signo, si_code; unsigned int n; CPUState *cs = env_cpu(env); @@ -150,15 +149,41 @@ static inline void target_cpu_loop(CPUARMState *env) /* just indicate that signals should be handled asap */ break; case EXCP_PREFETCH_ABORT: - /* See arm/arm/trap.c prefetch_abort_handler() */ case EXCP_DATA_ABORT: - /* See arm/arm/trap.c data_abort_handler() */ - info.si_signo = TARGET_SIGSEGV; - info.si_errno = 0; - /* XXX: check env->error_code */ - info.si_code = 0; - info.si_addr = env->exception.vaddress; - queue_signal(env, info.si_signo, &info); + /* + * See arm/arm/trap-v6.c prefetch_abort_handler() and + * data_abort_handler() + * + * However, FreeBSD maps these to a generic value and then uses that + * to maybe fault in pages in vm/vm_fault.c:vm_fault_trap(). I + * believe that the indirection maps the same as Linux, but haven't + * chased down every single possible indirection. + */ + + /* For user-only we don't set TTBCR_EAE, so look at the FSR. */ + switch (env->exception.fsr & 0x1f) { + case 0x1: /* Alignment */ + si_signo = TARGET_SIGBUS; + si_code = TARGET_BUS_ADRALN; + break; + case 0x3: /* Access flag fault, level 1 */ + case 0x6: /* Access flag fault, level 2 */ + case 0x9: /* Domain fault, level 1 */ + case 0xb: /* Domain fault, level 2 */ + case 0xd: /* Permission fault, level 1 */ + case 0xf: /* Permission fault, level 2 */ + si_signo = TARGET_SIGSEGV; + si_code = TARGET_SEGV_ACCERR; + break; + case 0x5: /* Translation fault, level 1 */ + case 0x7: /* Translation fault, level 2 */ + si_signo = TARGET_SIGSEGV; + si_code = TARGET_SEGV_MAPERR; + break; + default: + g_assert_not_reached(); + } + force_sig_fault(si_signo, si_code, env->exception.vaddress); break; case EXCP_DEBUG: case EXCP_BKPT: From patchwork Mon Jan 31 19:56:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 12731122 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2C446C433FE for ; Mon, 31 Jan 2022 20:36:16 +0000 (UTC) Received: from localhost ([::1]:47032 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nEdPL-0005KH-4p for qemu-devel@archiver.kernel.org; Mon, 31 Jan 2022 15:36:15 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43088) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nEcnh-0004zD-4e for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:21 -0500 Received: from [2607:f8b0:4864:20::d29] (port=42999 helo=mail-io1-xd29.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nEcnb-0002eD-I1 for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:20 -0500 Received: by mail-io1-xd29.google.com with SMTP id r144so18376178iod.9 for ; Mon, 31 Jan 2022 11:56:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kcZ/fxJZTdiXxs5uHcd2Nm1OFR/CKnoGxaFeU6jvAsI=; b=rG2dXs9bVpvmqNM+p56Q0Kee7kTT/kV4FeICxqh8kBNIg08ssvU5HkP/wb8XGar21q NOI8UTt2pgl3GTP47dDtjQaB3XUngpcpO+CB0GSQQVO4dsz0Q8EZqVIHyv3M20bDgDWz 7+ZquRIC+PlhK8+Pt6aEVZauo3hvDUt6hlOaPWkThJXXK6UVtHysHnCaZesYXyX1yxgI jNTOpt5kNGLq55EFUN3KM/Q7v5Sei6TBe9j/dvCYuMTOKDVJ+D8poyeteC9DLRUH4uUz Nk28QP00OIR/lrQfA4CFVYpVXi5nKqoi2DxwCvl5f6nR9M1LU1S6ETnNQeHCVsBLLeS/ HTdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kcZ/fxJZTdiXxs5uHcd2Nm1OFR/CKnoGxaFeU6jvAsI=; b=ReXjrOzEJktDoMUA3XpTLpyqxOzCuL7Mbib6xa3mrG/orAFkr7QQ0sXg6L9u0QwFVQ +BR6O4lkgsh2KPrvaIBjU9ZjVk98QO9sD/KfR/dVrPL3ybXImZCJXJ4fYuvRNmn5E2n5 DwUXuTyZROpjXFYNOCTcR1wyRq/cMwCydh9KNk1kzcg9L6lTq8jwnKhSAv/Y5DKXL9ma 2v33ZPhaYRYPUYiSXlLoz7PClK5ybBXh5q8jge/ic7a9Qa+NgIm3CFdqlmBZTObFhGqa lwlnLYt35H+0M6JclG+Ppk85dmPRG00FAb4ZREeuzu1UAnWBIKYR1Li0v1F8eSIwvSDJ CfZQ== X-Gm-Message-State: AOAM5305c3F5e2LDSWUVBd/xd4ZWKQKLPM1jeIojgh6jr9k2Cizx8Faz cPUYnRSYwIuSG780/7UHlphwWIwtsrouCg== X-Google-Smtp-Source: ABdhPJxlWhpGTn0JchWNe9jJMbOHvj8A8cgqof28pR0IG7T74cBj5t+Xfzb85id197ZWM2H2f1dsWg== X-Received: by 2002:a05:6638:10e6:: with SMTP id g6mr11260764jae.135.1643659006076; Mon, 31 Jan 2022 11:56:46 -0800 (PST) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id j2sm1972989ilu.82.2022.01.31.11.56.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jan 2022 11:56:45 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PULL 16/40] bsd-user/signal.c: implement abstract target / host signal translation Date: Mon, 31 Jan 2022 12:56:12 -0700 Message-Id: <20220131195636.31991-17-imp@bsdimp.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220131195636.31991-1-imp@bsdimp.com> References: <20220131195636.31991-1-imp@bsdimp.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::d29 (failed) Received-SPF: none client-ip=2607:f8b0:4864:20::d29; envelope-from=imp@bsdimp.com; helo=mail-io1-xd29.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Stacey Son , Kyle Evans , Richard Henderson , def@FreeBSD.org, jrtc27@FreeBSD.org, Warner Losh Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Implement host_to_target_signal and target_to_host_signal. Signed-off-by: Stacey Son Signed-off-by: Kyle Evans Signed-off-by: Warner Losh Reviewed-by: Peter Maydell Reviewed-by: Richard Henderson --- bsd-user/signal-common.h | 2 ++ bsd-user/signal.c | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/bsd-user/signal-common.h b/bsd-user/signal-common.h index f9a9d1e01aa..efed23d9efb 100644 --- a/bsd-user/signal-common.h +++ b/bsd-user/signal-common.h @@ -13,8 +13,10 @@ long do_rt_sigreturn(CPUArchState *env); abi_long do_sigaltstack(abi_ulong uss_addr, abi_ulong uoss_addr, abi_ulong sp); long do_sigreturn(CPUArchState *env); void force_sig_fault(int sig, int code, abi_ulong addr); +int host_to_target_signal(int sig); void process_pending_signals(CPUArchState *env); void queue_signal(CPUArchState *env, int sig, target_siginfo_t *info); void signal_init(void); +int target_to_host_signal(int sig); #endif diff --git a/bsd-user/signal.c b/bsd-user/signal.c index 844dfa19095..1313baec96a 100644 --- a/bsd-user/signal.c +++ b/bsd-user/signal.c @@ -2,6 +2,7 @@ * Emulation of BSD signals * * Copyright (c) 2003 - 2008 Fabrice Bellard + * Copyright (c) 2013 Stacey Son * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,6 +28,21 @@ * fork. */ +/* + * The BSD ABIs use the same singal numbers across all the CPU architectures, so + * (unlike Linux) these functions are just the identity mapping. This might not + * be true for XyzBSD running on AbcBSD, which doesn't currently work. + */ +int host_to_target_signal(int sig) +{ + return sig; +} + +int target_to_host_signal(int sig) +{ + return sig; +} + /* * Queue a signal so that it will be send to the virtual CPU as soon as * possible. From patchwork Mon Jan 31 19:56:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 12731141 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3D913C433F5 for ; Mon, 31 Jan 2022 20:55:12 +0000 (UTC) Received: from localhost ([::1]:36712 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nEdhf-0002Xg-2o for qemu-devel@archiver.kernel.org; Mon, 31 Jan 2022 15:55:11 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43140) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nEcni-00051b-1R for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:22 -0500 Received: from [2607:f8b0:4864:20::d31] (port=37493 helo=mail-io1-xd31.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nEcnb-0002eI-LJ for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:21 -0500 Received: by mail-io1-xd31.google.com with SMTP id n17so18417372iod.4 for ; Mon, 31 Jan 2022 11:56:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=l8RA7yWCAX4kkKStNQOwlFxMIKNeQ5iUFxaPSVvYcxY=; b=dYTVc5bb0z4Qi38hRHKARf6sogNj33CQ0uB9UvgSHjdu+Exx4Zbc1pXwpv0mo1DTM3 nUp2qruW80Rugsj39VEJNA3jFZ8upSFH5RIL/Y25XM27UQWajTCMLlThm5G/ASDysNO7 y5NCwX1M/DM7k46FQRANickKc0b1bGHimqLTSlVMjMvoY2LjLZGerzLeqq7iT8HspQce 4gevp767V8/QDOmESp8OlFMVoDhQ7rtqjti4vCrIfdWbAaMAcZZLJRtdEpJYZ5gtUnLj EYIuOlc+1SQ+d6cA98tMJAC1Q92hXO0y7YWvirs3Cg01JWBa5QqBIEbAjspPInyqR/dC vdiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=l8RA7yWCAX4kkKStNQOwlFxMIKNeQ5iUFxaPSVvYcxY=; b=nDBqmnmENdrpBwORlyMCKB7KXGHtypAHxgMrElI+Ur1CZiINHJsNMKF5W6QKFmpa+J YP7pglSrEzslBpdYaiu+QWDMufAB98/QUviulMV+hr7nbsaQ8Vkt10XBqaCtn/8IYXHD 2J6siqVP1Cg3k74obByhy53PXZablNB3k34h+bZVKMLDlsU4OClzxij1P4jCHLYZ/LUD Xij+YSkAknpv45Db/3rzNF766Z9/1jfvdY2ujLmlIxKVoiV0KhwqCPLvwcHWExpKYdY2 uARo9U5NQUgNOycAMRpUgMwlPD31azDYQZRzjxkZQFVw6yRV9TphjGxq5e+9uxSPfZUi A3Iw== X-Gm-Message-State: AOAM533iVKfKenb32aQp5WN5/WBeN5zCbtMC0csrVnsc3N8NgVp2fZBh MWDPrWL4YjuiEeYcbs5VIZ8fuR2rjQucZg== X-Google-Smtp-Source: ABdhPJw3hxC+QI6ndFmtGUL892ozEA7+6TxgompY221NkHZbGpYCts1VFhq8RNdya5mzIPis/JuhEA== X-Received: by 2002:a02:69c6:: with SMTP id e189mr11188458jac.137.1643659007290; Mon, 31 Jan 2022 11:56:47 -0800 (PST) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id j2sm1972989ilu.82.2022.01.31.11.56.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jan 2022 11:56:46 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PULL 17/40] bsd-user/signal.c: Implement signal_init() Date: Mon, 31 Jan 2022 12:56:13 -0700 Message-Id: <20220131195636.31991-18-imp@bsdimp.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220131195636.31991-1-imp@bsdimp.com> References: <20220131195636.31991-1-imp@bsdimp.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::d31 (failed) Received-SPF: none client-ip=2607:f8b0:4864:20::d31; envelope-from=imp@bsdimp.com; helo=mail-io1-xd31.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Stacey Son , Kyle Evans , Richard Henderson , def@FreeBSD.org, jrtc27@FreeBSD.org, Warner Losh Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Initialize the signal state for the emulator. Setup a set of sane default signal handlers, mirroring the host's signals. For fatal signals (those that exit by default), establish our own set of signal handlers. Stub out the actual signal handler we use for the moment. Signed-off-by: Stacey Son Signed-off-by: Kyle Evans Signed-off-by: Warner Losh Reviewed-by: Peter Maydell Reviewed-by: Richard Henderson XXX SIGPROF PENDING --- bsd-user/qemu.h | 7 +++++ bsd-user/signal.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index 99c37fc9942..49f01932a53 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -94,6 +94,13 @@ typedef struct TaskState { * from multiple threads.) */ int signal_pending; + /* + * This thread's signal mask, as requested by the guest program. + * The actual signal mask of this thread may differ: + * + we don't let SIGSEGV and SIGBUS be blocked while running guest code + * + sometimes we block all signals to avoid races + */ + sigset_t signal_mask; uint8_t stack[]; } __attribute__((aligned(16))) TaskState; diff --git a/bsd-user/signal.c b/bsd-user/signal.c index 1313baec96a..3ef7cf5e23c 100644 --- a/bsd-user/signal.c +++ b/bsd-user/signal.c @@ -28,6 +28,9 @@ * fork. */ +static struct target_sigaction sigact_table[TARGET_NSIG]; +static void host_signal_handler(int host_sig, siginfo_t *info, void *puc); + /* * The BSD ABIs use the same singal numbers across all the CPU architectures, so * (unlike Linux) these functions are just the identity mapping. This might not @@ -52,6 +55,28 @@ void queue_signal(CPUArchState *env, int sig, target_siginfo_t *info) qemu_log_mask(LOG_UNIMP, "No signal queueing, dropping signal %d\n", sig); } +static int fatal_signal(int sig) +{ + + switch (sig) { + case TARGET_SIGCHLD: + case TARGET_SIGURG: + case TARGET_SIGWINCH: + case TARGET_SIGINFO: + /* Ignored by default. */ + return 0; + case TARGET_SIGCONT: + case TARGET_SIGSTOP: + case TARGET_SIGTSTP: + case TARGET_SIGTTIN: + case TARGET_SIGTTOU: + /* Job control signals. */ + return 0; + default: + return 1; + } +} + /* * Force a synchronously taken QEMU_SI_FAULT signal. For QEMU the * 'force' part is handled in process_pending_signals(). @@ -69,8 +94,50 @@ void force_sig_fault(int sig, int code, abi_ulong addr) queue_signal(env, sig, &info); } +static void host_signal_handler(int host_sig, siginfo_t *info, void *puc) +{ +} + void signal_init(void) { + TaskState *ts = (TaskState *)thread_cpu->opaque; + struct sigaction act; + struct sigaction oact; + int i; + int host_sig; + + /* Set the signal mask from the host mask. */ + sigprocmask(0, 0, &ts->signal_mask); + + sigfillset(&act.sa_mask); + act.sa_sigaction = host_signal_handler; + act.sa_flags = SA_SIGINFO; + + for (i = 1; i <= TARGET_NSIG; i++) { +#ifdef CONFIG_GPROF + if (i == TARGET_SIGPROF) { + continue; + } +#endif + host_sig = target_to_host_signal(i); + sigaction(host_sig, NULL, &oact); + if (oact.sa_sigaction == (void *)SIG_IGN) { + sigact_table[i - 1]._sa_handler = TARGET_SIG_IGN; + } else if (oact.sa_sigaction == (void *)SIG_DFL) { + sigact_table[i - 1]._sa_handler = TARGET_SIG_DFL; + } + /* + * If there's already a handler installed then something has + * gone horribly wrong, so don't even try to handle that case. + * Install some handlers for our own use. We need at least + * SIGSEGV and SIGBUS, to detect exceptions. We can not just + * trap all signals because it affects syscall interrupt + * behavior. But do trap all default-fatal signals. + */ + if (fatal_signal(i)) { + sigaction(host_sig, &act, NULL); + } + } } void process_pending_signals(CPUArchState *cpu_env) From patchwork Mon Jan 31 19:56:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 12731143 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 47D9BC433F5 for ; Mon, 31 Jan 2022 21:02:01 +0000 (UTC) Received: from localhost ([::1]:49410 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nEdoG-0002yZ-9L for qemu-devel@archiver.kernel.org; Mon, 31 Jan 2022 16:02:00 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43172) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nEcni-00052x-Q2 for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:23 -0500 Received: from [2607:f8b0:4864:20::12c] (port=47046 helo=mail-il1-x12c.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nEcnb-0002eO-NQ for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:22 -0500 Received: by mail-il1-x12c.google.com with SMTP id e8so12375450ilm.13 for ; Mon, 31 Jan 2022 11:56:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wqlbtS2VUgC/Bp8lefRD+Zfc/A3KiIGoEh621L0tTtg=; b=DbVZWF1EXOUFLrE9J3qIn43sjinR351YF6C7wgp7+GXw4WkwcZas3aiy6Ch0sohMXt rNhX9lJQ5GXtIhPjRIZ3jLy41caynPLQay2I7yOT344Xk+qtLIF/Or4ZAmnsCqAVFujQ Ixrwdai/Xc++Zfdj844xVTLLu2E8Ps66O2NNw04rOCFjuNaf2qQhhqSGyuBoUwnA2+Sw zJyzIjZ68qoERFdtveAzxtsFOOyfvNg6yVjK7XvFOOnvy9hd2vxkbI2XS3ZK0V7eflzm fDG3phZtKgOKAhWGUFLL2mA90ofdl1/4prIQP0Syn3NqXR78gN+dcjTZxuBdab/wYV2h DrxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wqlbtS2VUgC/Bp8lefRD+Zfc/A3KiIGoEh621L0tTtg=; b=f1vMEanHs1m2o1y3ii4zTiJhh8dtuEJQLf8wCeGcS2N6jWAUL+UTljJz+CihGAT+mK lvzXuxxr9L0TSPG0lE741SFcFE49PmiP99T08JJJ08wmbuI5j2S6ljsWqV95TEIJREc0 At/P8Dv7iOsexMlksaPBHVKdQwHEb89gpmRQMc9cHlHTkE5OFM4yOJKAYxecFG/phFyo C97KCQYD6BIbpPf/H3x3/5lY4O2VBV8hQm0FOwGJikC8xi/U8CCu2V0bmKEeHn3dTly2 FiPow7i77D3be/lNCnE+6UThGLJ662EA4uC9X+ei/upTXC24yrsTVXA4JNZwhkU16Zjh QJBg== X-Gm-Message-State: AOAM531vNHkkaJb6y+rMHMRHGTAlAmZbc5Gc84vohGlP2k7iCtXUFbQD l14mw+j3HrXz/HH7VqNtaoRZ2Q4rAHLBqA== X-Google-Smtp-Source: ABdhPJxeD1j0/5j6pfHjsLpYpSzrbP/qZ/Ni9r9/39O7kTuxODXevBUVoew1eW35VnZt6SG5m1EsqQ== X-Received: by 2002:a05:6e02:1488:: with SMTP id n8mr12323253ilk.12.1643659008422; Mon, 31 Jan 2022 11:56:48 -0800 (PST) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id j2sm1972989ilu.82.2022.01.31.11.56.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jan 2022 11:56:47 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PULL 18/40] bsd-user/signal.c: Add si_type argument to queue_signal Date: Mon, 31 Jan 2022 12:56:14 -0700 Message-Id: <20220131195636.31991-19-imp@bsdimp.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220131195636.31991-1-imp@bsdimp.com> References: <20220131195636.31991-1-imp@bsdimp.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::12c (failed) Received-SPF: none client-ip=2607:f8b0:4864:20::12c; envelope-from=imp@bsdimp.com; helo=mail-il1-x12c.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Kyle Evans , Richard Henderson , def@FreeBSD.org, jrtc27@FreeBSD.org, Warner Losh Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Mirror the linux-user practice and add a si_type argument to queue signal. This will be transported as the upper 8 bits in the si_type element of siginfo so that we know what bits of the structure are valid and so we can properly implement host_to_target_siginfo_noswap and tswap_siginfo. Adapt the one caller of queue_signal to the new interface. Use all the same names as Linux (except _RT which we don't treat differently, unlike Linux), though some are unused. Place this into signal-common.h since that's a better place given bsd-user's structure. Move prototype of queue_signal to signal-common.h to mirror linux-user's location. Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/signal-common.h | 26 +++++++++++++++++++++++++- bsd-user/signal.c | 5 +++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/bsd-user/signal-common.h b/bsd-user/signal-common.h index efed23d9efb..80e9503238a 100644 --- a/bsd-user/signal-common.h +++ b/bsd-user/signal-common.h @@ -15,8 +15,32 @@ long do_sigreturn(CPUArchState *env); void force_sig_fault(int sig, int code, abi_ulong addr); int host_to_target_signal(int sig); void process_pending_signals(CPUArchState *env); -void queue_signal(CPUArchState *env, int sig, target_siginfo_t *info); +void queue_signal(CPUArchState *env, int sig, int si_type, + target_siginfo_t *info); void signal_init(void); int target_to_host_signal(int sig); +/* + * Within QEMU the top 8 bits of si_code indicate which of the parts of the + * union in target_siginfo is valid. This only applies between + * host_to_target_siginfo_noswap() and tswap_siginfo(); it does not appear + * either within host siginfo_t or in target_siginfo structures which we get + * from the guest userspace program. Linux kenrels use this internally, but BSD + * kernels don't do this, but its a useful abstraction. + * + * The linux-user version of this uses the top 16 bits, but FreeBSD's SI_USER + * and other signal indepenent SI_ codes have bit 16 set, so we only use the top + * byte instead. + * + * For FreeBSD, we have si_pid, si_uid, si_status, and si_addr always. Linux and + * {Open,Net}BSD have a different approach (where their reason field is larger, + * but whose siginfo has fewer fields always). + */ +#define QEMU_SI_NOINFO 0 /* nothing other than si_signo valid */ +#define QEMU_SI_FAULT 1 /* _fault is valid in _reason */ +#define QEMU_SI_TIMER 2 /* _timer is valid in _reason */ +#define QEMU_SI_MESGQ 3 /* _mesgq is valid in _reason */ +#define QEMU_SI_POLL 4 /* _poll is valid in _reason */ +#define QEMU_SI_CAPSICUM 5 /* _capsicum is valid in _reason */ + #endif diff --git a/bsd-user/signal.c b/bsd-user/signal.c index 3ef7cf5e23c..ad8437a8bfb 100644 --- a/bsd-user/signal.c +++ b/bsd-user/signal.c @@ -50,7 +50,8 @@ int target_to_host_signal(int sig) * Queue a signal so that it will be send to the virtual CPU as soon as * possible. */ -void queue_signal(CPUArchState *env, int sig, target_siginfo_t *info) +void queue_signal(CPUArchState *env, int sig, int si_type, + target_siginfo_t *info) { qemu_log_mask(LOG_UNIMP, "No signal queueing, dropping signal %d\n", sig); } @@ -91,7 +92,7 @@ void force_sig_fault(int sig, int code, abi_ulong addr) info.si_errno = 0; info.si_code = code; info.si_addr = addr; - queue_signal(env, sig, &info); + queue_signal(env, sig, QEMU_SI_FAULT, &info); } static void host_signal_handler(int host_sig, siginfo_t *info, void *puc) From patchwork Mon Jan 31 19:56:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 12731142 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4F187C433EF for ; Mon, 31 Jan 2022 20:58:48 +0000 (UTC) Received: from localhost ([::1]:43986 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nEdl9-0007eL-0n for qemu-devel@archiver.kernel.org; Mon, 31 Jan 2022 15:58:47 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43148) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nEcni-000526-8s for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:22 -0500 Received: from [2607:f8b0:4864:20::130] (port=42924 helo=mail-il1-x130.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nEcnb-0002eS-Ld for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:21 -0500 Received: by mail-il1-x130.google.com with SMTP id u5so12377696ilq.9 for ; Mon, 31 Jan 2022 11:56:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1mpwYZNs4mJXgxPDyP8VAeZVM/ryFURuOJnVXj3MG+M=; b=nKEYO/7CHzriQbLWuFHMcY04draIWrhA+9IGrcCA6hE+GbMamelk1FQHllIajU8G4z U38MB8FUq+MevkswhvhKGoHAI/V2vlsjTVqCFXvyLwsGgkDBIM1ZFLpHmmmgjl8hFNYw PV1SHP9F2zF5PQbKNJCSuLTtzus5IGwKJq7oytn6Lt0PCX5l9jxOAqetb5XKPrp3KOHQ pf+DCZyms+KjRj2M/jTQaVeiO0Yy+uKHJdoR72lo4AEZQQzS/WGxtM9UzqbUqxDgt9PJ Qo45DA+6Qj7m4BrKncI6eiPscaTIO9gSH4YjnXP0264kFDE8Id45HjVZPXRV2mMBfx0W MZGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1mpwYZNs4mJXgxPDyP8VAeZVM/ryFURuOJnVXj3MG+M=; b=u4W6tmeBQ3AoCSj+Hvq/mkXTXn3p3sVLFS6UaKnop4of+vYQ88tKeFS5w88jWRq4Nz pp+yFRoCz9f8++J+VlYek79QsB3qR4deQemqd1xFmEnvScOF4RLV8SZxr7I5Dgq6vJpS 2rM08Kp2Iem3nXbVZYVECaYASYneKBkJp1LOaIXtyWpNxuw76QwiZDhL8AkZHjDorynK ancvIvAZM1QyAOAj2yPi0QuC7E+tLFgHfQ1d6F0vnvC+PD54zWtdA9cyMSpGGGq5Ec/N aejp3ntdsbG5iQ7ZuJ6/lm4FzZuos9YiB/qPZDQvZ3uZ9WwuzWp680AcFDkputTBFOFF mRpQ== X-Gm-Message-State: AOAM531qSaleFFqwQjVWmYqypMkQY0Pmq4Yk+Yr0jpW3OdDeh/saBtgJ l5yKnTjeZbYaXXNu6vDQ8pGW3oP7N1ffgg== X-Google-Smtp-Source: ABdhPJz5yW3FBCXlmO2sZ9eo+cXfsvxfdlCKDcvdjzGaY8T/TgqnGo02mySyKrIAzBc5bkHNB0KqVw== X-Received: by 2002:a05:6e02:170c:: with SMTP id u12mr2183746ill.135.1643659009354; Mon, 31 Jan 2022 11:56:49 -0800 (PST) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id j2sm1972989ilu.82.2022.01.31.11.56.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jan 2022 11:56:48 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PULL 19/40] bsd-user/host/arm/host-signal.h: Implement host_signal_* Date: Mon, 31 Jan 2022 12:56:15 -0700 Message-Id: <20220131195636.31991-20-imp@bsdimp.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220131195636.31991-1-imp@bsdimp.com> References: <20220131195636.31991-1-imp@bsdimp.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::130 (failed) Received-SPF: none client-ip=2607:f8b0:4864:20::130; envelope-from=imp@bsdimp.com; helo=mail-il1-x130.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Kyle Evans , Richard Henderson , def@FreeBSD.org, jrtc27@FreeBSD.org, Warner Losh Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Implement host_signal_pc, host_signal_set_pc and host_signal_write for arm. Signed-off-by: Kyle Evans Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/host/arm/host-signal.h | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 bsd-user/host/arm/host-signal.h diff --git a/bsd-user/host/arm/host-signal.h b/bsd-user/host/arm/host-signal.h new file mode 100644 index 00000000000..56679bd6993 --- /dev/null +++ b/bsd-user/host/arm/host-signal.h @@ -0,0 +1,35 @@ +/* + * host-signal.h: signal info dependent on the host architecture + * + * Copyright (c) 2021 Warner Losh + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef ARM_HOST_SIGNAL_H +#define ARM_HOST_SIGNAL_H + +#include + +static inline uintptr_t host_signal_pc(ucontext_t *uc) +{ + return uc->uc_mcontext.__gregs[_REG_PC]; +} + +static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc) +{ + uc->uc_mcontext.__gregs[_REG_PC] = pc; +} + +static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc) +{ + /* + * In the FSR, bit 11 is WnR. FreeBSD returns this as part of the + * si_info.si_trapno. + */ + uint32_t fsr = info->si_trapno; + + return extract32(fsr, 11, 1); +} + +#endif From patchwork Mon Jan 31 19:56:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 12731108 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 74EFBC433F5 for ; Mon, 31 Jan 2022 20:29:44 +0000 (UTC) Received: from localhost ([::1]:37118 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nEdJ1-0006l0-CV for qemu-devel@archiver.kernel.org; Mon, 31 Jan 2022 15:29:43 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43156) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nEcni-00052c-ID for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:22 -0500 Received: from [2607:f8b0:4864:20::d34] (port=37496 helo=mail-io1-xd34.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nEcnb-0002eX-NH for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:22 -0500 Received: by mail-io1-xd34.google.com with SMTP id n17so18417563iod.4 for ; Mon, 31 Jan 2022 11:56:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6lp+mf01Obw62O4XR76se3KsYTrGoqPsoy/y1+puMOw=; b=Sl6oaauEX+cU+VPCcpcnOjWZjkAg66bk8DOizjp4sJIQaYns/H8/AVvgg4nPUm/Rv2 VoZ+X1XS7XRoGUg0WxlDLpXif3Tqbd3zCqVnkoLL+kqNvcH6GHDx5AGHrM24+nEhc7Hz YOm7ssfLyRmbUYlA855DQztJjw+UK9+Inarv0IWdw405TVf+vgAraOxRNbS9U58gPaMD F0axVq6aenRL6X4FROp8TS6I6Ph3/DN/4h7Dlz0r62nwTRuR8KownFDyT5WeICABaNu+ 4HzEwZeSuyULEVVLxjXppbx03XJ9FrVM/KthUSenhpZIesjvqF8vs5T3kjA6KDpYfibF UKxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6lp+mf01Obw62O4XR76se3KsYTrGoqPsoy/y1+puMOw=; b=LqzhFw6ZS/tamdXC2orvnrEF/0OQ5jEC0hN1RCddIm7r+783yb9sicjFzfbGIf5nMx BoBO010JNxxD5xYjspZ2wXh0dgTmLtluVAXQguLVz5MmHeuzt0HcBxsabC8OPcR2EAFO 39Ww/rVQrizkpAjHM5MVsNhGX/M16E4ZFCxF9IPFGPH/36HQBmxzFdTbQC2WhJOlseg9 wNFL8+JGqfwt3r9r5UxJPiFPV1r4x+FIpLAb6PWYaQlp/zwhJ7RFBSvYoW+WV2LEPMwS SRrqAZXS81GhvwS+GCz3z/gvw5uxJY8lsjpee9F2jTT9pDcddFg0J6D9ly7sYg09YHKY JDPA== X-Gm-Message-State: AOAM533brzNPz83ew4xnNRp1aWaYuKQ5muLXDornZsQEibArs4Ld9QQV xWL+K5kW0nhYMhukZ4/bbfxhZGwLFdejzw== X-Google-Smtp-Source: ABdhPJzzwtbIFkNWBLRXArV/lgNGrUI03iij+wO1iGjstoJCc1+HWcuryGf7AdYyo3/A++iX1FXYsA== X-Received: by 2002:a05:6638:3781:: with SMTP id w1mr10240136jal.26.1643659010547; Mon, 31 Jan 2022 11:56:50 -0800 (PST) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id j2sm1972989ilu.82.2022.01.31.11.56.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jan 2022 11:56:49 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PULL 20/40] bsd-user/host/i386/host-signal.h: Implement host_signal_* Date: Mon, 31 Jan 2022 12:56:16 -0700 Message-Id: <20220131195636.31991-21-imp@bsdimp.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220131195636.31991-1-imp@bsdimp.com> References: <20220131195636.31991-1-imp@bsdimp.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::d34 (failed) Received-SPF: none client-ip=2607:f8b0:4864:20::d34; envelope-from=imp@bsdimp.com; helo=mail-io1-xd34.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Kyle Evans , Richard Henderson , def@FreeBSD.org, jrtc27@FreeBSD.org, Warner Losh Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Implement host_signal_pc, host_signal_set_pc and host_signal_write for i386. Signed-off-by: Kyle Evans Signed-off-by: Warner Losh Reviewed-by: Peter Maydell Reviewed-by: Richard Henderson --- bsd-user/host/i386/host-signal.h | 37 ++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 bsd-user/host/i386/host-signal.h diff --git a/bsd-user/host/i386/host-signal.h b/bsd-user/host/i386/host-signal.h new file mode 100644 index 00000000000..169e61b154c --- /dev/null +++ b/bsd-user/host/i386/host-signal.h @@ -0,0 +1,37 @@ +/* + * host-signal.h: signal info dependent on the host architecture + * + * Copyright (c) 2021 Warner Losh + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef I386_HOST_SIGNAL_H +#define I386_HOST_SIGNAL_H + +#include +#include +#include +#include + +static inline uintptr_t host_signal_pc(ucontext_t *uc) +{ + return uc->uc_mcontext.mc_eip; +} + +static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc) +{ + uc->uc_mcontext.mc_eip = pc; +} + +static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc) +{ + /* + * Look in sys/i386/i386/trap.c. NOTE: mc_err == tr_err due to type punning + * between a trapframe and mcontext on FreeBSD/i386. + */ + return uc->uc_mcontext.mc_trapno == T_PAGEFLT && + uc->uc_mcontext.mc_err & PGEX_W; +} + +#endif From patchwork Mon Jan 31 19:56:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 12731084 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 235B2C433F5 for ; Mon, 31 Jan 2022 20:11:48 +0000 (UTC) Received: from localhost ([::1]:60990 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nEd1f-0000ko-2d for qemu-devel@archiver.kernel.org; Mon, 31 Jan 2022 15:11:47 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42916) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nEcnd-0004sq-Gc for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:17 -0500 Received: from [2607:f8b0:4864:20::d35] (port=42499 helo=mail-io1-xd35.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nEcnb-0002ec-6c for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:17 -0500 Received: by mail-io1-xd35.google.com with SMTP id r144so18376570iod.9 for ; Mon, 31 Jan 2022 11:56:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+J/ZcXBMkl7vIRUbXRkoafaooBA4s7iAGTsSYqX/VvY=; b=djDQUxApj4ttbasQSfDnHZEdyu/8JJE/BzdHxQoCYVyj0WAh9/VQ1SlGwPMgivNNJ4 WY14lFoAVV+1bRXE2K/YBOZ1UX+KzAeAsFnNjk4DeS6SsRAWVaG9BMy43KEpC88LJ/Nm iIhBjmhG4dm9dNkZf/fnkuJ2L5bX1fE6L1vVNtmhBEQ7CYX1kQnoUIAWq+6Lx4cmO0hi 6RylR6+AGhebd88Pou2EdP57c3gekuFU1e8k4DmiuKehujAmpWpm29CJVFRL1ea/rECw FowfzMxVbsBktpxH14xxqfj6EHSQttOa5A+02hwMgD+yEk6ihdPdMpcM53L6vbA6Ndop TyeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+J/ZcXBMkl7vIRUbXRkoafaooBA4s7iAGTsSYqX/VvY=; b=QIpNXxviay6IniJjV9RBK/IHJwBY4UcDK4pxTCMYT4uj3rfakZU2gNdsu+UEDFBTmM olASTsYsSpJZIyAgB48r9fuDsqWDilKe+z7Eyo3Y2RTa6hHBNhBqr8yGgTTv/YwATOZv 8mJHOALhzp5wTRrcEyXdjk5brmtga7+pLx0mG6iLk/fkTUxb7NX6LExsTpcefLPrzmKw eAAZ6flg6qEG8hJhb/EXnHo8k5SfVTYesVBKfgnytyFclH4w1d5F+vqS9MXvRDALQFFi +zVzvlp1GBcc7x4TfcuuFmj+WIs1jfiQqv3uFi9pSFVAYkWIXDBJ1roCkUpplRGfYx1k rjxg== X-Gm-Message-State: AOAM531dF+6SoSHHubZwEdgTYpjRX78KjWR4lfXB5fj8odFfdA69/sFp /5gJDJLMgEUxfd9mcXinO0t2PUcpCmn/1A== X-Google-Smtp-Source: ABdhPJyY8Qsp3vkBukdRkvtpT9rclcV2rs592HLA/rSJbjc0gscnceBOehctlw0OZF4xesJRWti8pg== X-Received: by 2002:a02:9997:: with SMTP id a23mr3028256jal.12.1643659011413; Mon, 31 Jan 2022 11:56:51 -0800 (PST) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id j2sm1972989ilu.82.2022.01.31.11.56.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jan 2022 11:56:50 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PULL 21/40] bsd-user/host/x86_64/host-signal.h: Implement host_signal_* Date: Mon, 31 Jan 2022 12:56:17 -0700 Message-Id: <20220131195636.31991-22-imp@bsdimp.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220131195636.31991-1-imp@bsdimp.com> References: <20220131195636.31991-1-imp@bsdimp.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::d35 (failed) Received-SPF: none client-ip=2607:f8b0:4864:20::d35; envelope-from=imp@bsdimp.com; helo=mail-io1-xd35.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Kyle Evans , Richard Henderson , def@FreeBSD.org, jrtc27@FreeBSD.org, Warner Losh Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Implement host_signal_pc, host_signal_set_pc and host_signal_write for x86_64. Signed-off-by: Kyle Evans Signed-off-by: Warner Losh Reviewed-by: Peter Maydell Reviewed-by: Richard Henderson --- bsd-user/host/x86_64/host-signal.h | 37 ++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 bsd-user/host/x86_64/host-signal.h diff --git a/bsd-user/host/x86_64/host-signal.h b/bsd-user/host/x86_64/host-signal.h new file mode 100644 index 00000000000..47ca19f8814 --- /dev/null +++ b/bsd-user/host/x86_64/host-signal.h @@ -0,0 +1,37 @@ +/* + * host-signal.h: signal info dependent on the host architecture + * + * Copyright (c) 2021 Warner Losh + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef X86_64_HOST_SIGNAL_H +#define X86_64_HOST_SIGNAL_H + +#include +#include +#include +#include + +static inline uintptr_t host_signal_pc(ucontext_t *uc) +{ + return uc->uc_mcontext.mc_rip; +} + +static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc) +{ + uc->uc_mcontext.mc_rip = pc; +} + +static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc) +{ + /* + * Look in sys/amd64/amd64/trap.c. NOTE: mc_err == tr_err due to type + * punning between a trapframe and mcontext on FreeBSD/amd64. + */ + return uc->uc_mcontext.mc_trapno == T_PAGEFLT && + uc->uc_mcontext.mc_err & PGEX_W; +} + +#endif From patchwork Mon Jan 31 19:56:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 12731127 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BF6B2C433F5 for ; Mon, 31 Jan 2022 20:38:45 +0000 (UTC) Received: from localhost ([::1]:54278 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nEdRk-0001oc-Qs for qemu-devel@archiver.kernel.org; Mon, 31 Jan 2022 15:38:44 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43238) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nEcnk-00053s-2k for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:25 -0500 Received: from [2607:f8b0:4864:20::d32] (port=38808 helo=mail-io1-xd32.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nEcnb-0002eh-Pe for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:23 -0500 Received: by mail-io1-xd32.google.com with SMTP id w7so18426610ioj.5 for ; Mon, 31 Jan 2022 11:56:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Uu/c8NbwOYwvWKC+skM1aHWNApehobWbRU2Oop3qnVw=; b=jd+0DNe6KR1avL3TpquKJrYByvlHm+3wI+ypNU76me4irSfVff8YeVaSam9TTcMvFi 0TkRUQLW2Kno9Ap6D2DTK52kWX+XDQMaYP/PlRZgVNbY+Y6x2DUokX+vXv3eOAHbWJhf uRyTJTJL7CnZWnB1K9LHu8NY44ZhJc9P5AjelbI3caj2yAHbAEYdRtUbZC14KctaPOB0 xOZZfMH1CP08vI6vYPpnIB7yjkzoR1jY0Pqfh+sStEjPuFTkwJwyiv03ayDH2tzM2xkl +pb+gsKt4kqPmXwVjYFYY1PsPIvlYngGc7qO2hgvODNIAW7Fm2psWG9PYYAUb0oRzU2N 6SfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Uu/c8NbwOYwvWKC+skM1aHWNApehobWbRU2Oop3qnVw=; b=1Zam4fuqb6F2yuenQUtpmJ3kWgIlfSVRAQVghWR0XHj4aJHaXquUm57QG0L8n4uA0y rGMrQiaq1geyQGcObCB49/adEyK9C6ntc/QU8lPNqMfprrxhVVOEXcJQZ5LONNmaNk3k P2fCUrgdcCNvPPI3IL80+lpJcLJYgDgQhwbnfKisbh/xA8LsDATIraZACqsrni+lWXff 1Z4sRHm0GGUAuuEDVCSlTPN8ufa+tVQME04zTkx1tC+0TL/bwtEW6SGFC657ytIUCGo8 gsJ2+5S8XgVvjrW00xhoKQvlNEp7lUUEBxlYYNQheJobgoxTOsdCLBdbbFl1ILWRTUE6 RQdA== X-Gm-Message-State: AOAM533J0ibL7VJBxnTw4r2fvoZ4ErH7Gw5dtfJmOcZ/CBO9pJhTKXZb eAWJygE16VA8A63uQi4uzlb/EV1LAnqkow== X-Google-Smtp-Source: ABdhPJyEcn2X4GnwagvKLvpoZodovhLT280+TRCPeeHH75vbgMD/1JWRjyhfknwU8Rbi61bJpWexCQ== X-Received: by 2002:a5e:9316:: with SMTP id k22mr11654944iom.18.1643659012182; Mon, 31 Jan 2022 11:56:52 -0800 (PST) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id j2sm1972989ilu.82.2022.01.31.11.56.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jan 2022 11:56:51 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PULL 22/40] bsd-user: Add host signals to the build Date: Mon, 31 Jan 2022 12:56:18 -0700 Message-Id: <20220131195636.31991-23-imp@bsdimp.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220131195636.31991-1-imp@bsdimp.com> References: <20220131195636.31991-1-imp@bsdimp.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::d32 (failed) Received-SPF: none client-ip=2607:f8b0:4864:20::d32; envelope-from=imp@bsdimp.com; helo=mail-io1-xd32.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Kyle Evans , Richard Henderson , def@FreeBSD.org, jrtc27@FreeBSD.org, Warner Losh Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Start to add the host signal functionality to the build. Signed-off-by: Warner Losh Reviewed-by: Peter Maydell Reviewed-by: Richard Henderson --- bsd-user/signal.c | 1 + meson.build | 1 + 2 files changed, 2 insertions(+) diff --git a/bsd-user/signal.c b/bsd-user/signal.c index ad8437a8bfb..f3e020e004a 100644 --- a/bsd-user/signal.c +++ b/bsd-user/signal.c @@ -22,6 +22,7 @@ #include "qemu.h" #include "signal-common.h" #include "hw/core/tcg-cpu-ops.h" +#include "host-signal.h" /* * Stubbed out routines until we merge signal support from bsd-user diff --git a/meson.build b/meson.build index 5dbc9a7a365..155403d44f4 100644 --- a/meson.build +++ b/meson.build @@ -2947,6 +2947,7 @@ foreach target : target_dirs if 'CONFIG_BSD_USER' in config_target base_dir = 'bsd-user' target_inc += include_directories('bsd-user/' / targetos) + target_inc += include_directories('bsd-user/host/' / host_arch) dir = base_dir / abi arch_srcs += files(dir / 'signal.c', dir / 'target_arch_cpu.c') endif From patchwork Mon Jan 31 19:56:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 12731130 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9062CC433EF for ; Mon, 31 Jan 2022 20:42:03 +0000 (UTC) Received: from localhost ([::1]:33776 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nEdUw-0007C6-9Y for qemu-devel@archiver.kernel.org; Mon, 31 Jan 2022 15:42:02 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43086) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nEcnh-0004ym-0X for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:21 -0500 Received: from [2607:f8b0:4864:20::d29] (port=36659 helo=mail-io1-xd29.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nEcnb-0002eo-I1 for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:20 -0500 Received: by mail-io1-xd29.google.com with SMTP id h7so18427335iof.3 for ; Mon, 31 Jan 2022 11:56:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=o+QXYNucUNSFJmHLJBCESvObOSc/YtVcWa7eAm4Hhi8=; b=b5UvnI2F5VyIjkGYTt8zQLxy3YOGTHkShMwz+doHd37enWW9p6LuKA2+l/ahje3IYc 6jZp9+G7zudHA6l6GLSVhtZu5ZgzboO8AOVU5t0836XXeI+COZrTvlsLHBO8AO2ASE2j fSUThdR8gIdshNIyrGwMhUTXAc70BT4OYNJ4wVLmkK4wU/EEeaRBYwiPID9NWK7GsOE6 LZTC89rcfM1IjxgzvB5susoBrMIkiHue2rZaOP0z/taFLXzDhqF6OZpJjXxTfOYJXRTa 30j417EHOKug4+p1VQ11LieTOHcT6R5FUTJ8Fp9EAgTJmiyst1AV57aYuYfi6EEBLDvJ gNAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=o+QXYNucUNSFJmHLJBCESvObOSc/YtVcWa7eAm4Hhi8=; b=X5NO4xAxeP8NfTeGk5MJrudGyFtV9rNxZ0Wiub3Jt67/UIpmvOu6k79wxcQjgUw6Bg wy9q84QXP7iCSESgbv+MTFdKEzzSdUbpGCMfF6qts09hNk9l4wZASjJB2HhVGvcREcG/ szdKcebN1M+z3AL/uS9r9QqcyYS6PWJHu60h2sMoVTTcK0FLDdMGBN0e0g4sp9xyDwfR xu8N51NSePqyVHIOyW43kvIUQq0QGQB15sG/vnM5T6qQo44/CpH4sqYRXJHKp4J6Au5n IVkrWHTSdmJjun1q5Dak5GYC0/YlP1994/MISPaOXKJZ8Vb3MHNxIJuIUOxxeQQr53qN VXeg== X-Gm-Message-State: AOAM532WIYOa5xYTHrScEjwCFU3ICI6Ilv+LoI5jIJQrd5ZJB1yf26oi F7SM6wsk7JvFlodh2nLYXUghApppAlbZVA== X-Google-Smtp-Source: ABdhPJyGZi6RcFLV/OpWpK8DCvuVlPRLTTips9P24vequ6H7AwFsmfxvDUNqPshn99DjOWyZexzZeQ== X-Received: by 2002:a5e:8711:: with SMTP id y17mr11497468ioj.175.1643659013272; Mon, 31 Jan 2022 11:56:53 -0800 (PST) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id j2sm1972989ilu.82.2022.01.31.11.56.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jan 2022 11:56:52 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PULL 23/40] bsd-user: Add trace events for bsd-user Date: Mon, 31 Jan 2022 12:56:19 -0700 Message-Id: <20220131195636.31991-24-imp@bsdimp.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220131195636.31991-1-imp@bsdimp.com> References: <20220131195636.31991-1-imp@bsdimp.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::d29 (failed) Received-SPF: none client-ip=2607:f8b0:4864:20::d29; envelope-from=imp@bsdimp.com; helo=mail-io1-xd29.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Stacey Son , Kyle Evans , Richard Henderson , def@FreeBSD.org, jrtc27@FreeBSD.org, Warner Losh Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Add the bsd-user specific events and infrastructure. Only include the linux-user trace events for linux-user, not bsd-user. Signed-off-by: Stacey Son Signed-off-by: Kyle Evans Signed-off-by: Warner Losh Reviewed-by: Peter Maydell Reviewed-by: Richard Henderson --- bsd-user/signal.c | 1 + bsd-user/trace-events | 11 +++++++++++ bsd-user/trace.h | 1 + meson.build | 5 ++++- 4 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 bsd-user/trace-events create mode 100644 bsd-user/trace.h diff --git a/bsd-user/signal.c b/bsd-user/signal.c index f3e020e004a..cb0036acb61 100644 --- a/bsd-user/signal.c +++ b/bsd-user/signal.c @@ -21,6 +21,7 @@ #include "qemu/osdep.h" #include "qemu.h" #include "signal-common.h" +#include "trace.h" #include "hw/core/tcg-cpu-ops.h" #include "host-signal.h" diff --git a/bsd-user/trace-events b/bsd-user/trace-events new file mode 100644 index 00000000000..843896f6271 --- /dev/null +++ b/bsd-user/trace-events @@ -0,0 +1,11 @@ +# See docs/tracing.txt for syntax documentation. + +# bsd-user/signal.c +user_setup_frame(void *env, uint64_t frame_addr) "env=%p frame_addr=0x%"PRIx64 +user_setup_rt_frame(void *env, uint64_t frame_addr) "env=%p frame_addr=0x%"PRIx64 +user_do_rt_sigreturn(void *env, uint64_t frame_addr) "env=%p frame_addr=0x%"PRIx64 +user_do_sigreturn(void *env, uint64_t frame_addr) "env=%p frame_addr=0x%"PRIx64 +user_dump_core_and_abort(void *env, int target_sig, int host_sig) "env=%p signal %d (host %d)" +user_handle_signal(void *env, int target_sig) "env=%p signal %d" +user_host_signal(void *env, int host_sig, int target_sig) "env=%p signal %d (target %d(" +user_queue_signal(void *env, int target_sig) "env=%p signal %d" diff --git a/bsd-user/trace.h b/bsd-user/trace.h new file mode 100644 index 00000000000..593c0204add --- /dev/null +++ b/bsd-user/trace.h @@ -0,0 +1 @@ +#include "trace/trace-bsd_user.h" diff --git a/meson.build b/meson.build index 155403d44f4..5f433550718 100644 --- a/meson.build +++ b/meson.build @@ -2458,9 +2458,12 @@ trace_events_subdirs = [ 'monitor', 'util', ] -if have_user +if have_linux_user trace_events_subdirs += [ 'linux-user' ] endif +if have_bsd_user + trace_events_subdirs += [ 'bsd-user' ] +endif if have_block trace_events_subdirs += [ 'authz', From patchwork Mon Jan 31 19:56:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 12731135 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 067C7C433F5 for ; Mon, 31 Jan 2022 20:44:36 +0000 (UTC) Received: from localhost ([::1]:42976 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nEdXP-00050E-5N for qemu-devel@archiver.kernel.org; Mon, 31 Jan 2022 15:44:35 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43280) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nEcnl-000547-3U for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:25 -0500 Received: from [2607:f8b0:4864:20::d2e] (port=35656 helo=mail-io1-xd2e.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nEcnb-0002es-Pm for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:24 -0500 Received: by mail-io1-xd2e.google.com with SMTP id 9so18465552iou.2 for ; Mon, 31 Jan 2022 11:56:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zR/nS77HGi58NxQ6lCjkdyeychDCjgXBLWsqt7gXmDg=; b=wF1KMNpdBoINrX9NNqMySMwJJr1OOwiktoo0sPDGe+bsNNX5cXODVywDtKi0e8KkoJ zwoeOGFRxxeuS35D1CY5ijcKfAMDkYmyJyz9TRABgo1iY7hwLDfcKV+jlQJeABJjcxIt SlkGwn8F30ldj4639GiPkhKigXkHQqIFoTNFx2fh3u9uVLVbURzyqdZBeLuwjoMJ9GBZ x1XyDEjZC/3N1C3MyRp6lmQUg46g8FN4+Ced+Q2TWmIIJusQoTeU2TDX0vAraTrhipDj cyXoFtfE06H0DLnUnYcBKW6BkIWVWtVeuuXym1AHfG2SU3OEbh6JGJ4Wd+dWXBLJWENp Woxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zR/nS77HGi58NxQ6lCjkdyeychDCjgXBLWsqt7gXmDg=; b=adhpEVjkOVerkJz+BFO9XoNco1/+/dFWr/ahCTSejcW/DJdMD+1oUhbGg35QvvXu2T z3Vhx/o84XZxhMiWQBE34L+fInpVo6VJT1i8U3XTwP/njnNwaOFHCXOCLGOeycz6ghs7 HtiVHpjUujCmRG3ogODL9+v6EbFWj1CDU3n8g0AhYizegRqShaoJlqoZ1DVdVIosPlRH 8A7Lj8tmb1GAfNh30ni6Y1mhyTH7x+o7RfN1HBhGUXcbLXdtcoDyuZ22Fd5Qe/uR3T3L k6BBaGndce5DyMsSTsMXDqR1qDoicz8l0D0tH6mViHAcQE5EtTjRlSzp45qHNyCf2UNn 1ABA== X-Gm-Message-State: AOAM532lz8cxtYmhzn4v+Oiy8+8n/0u2jlgg9upQ5kwYoZ8+XwTyMAWi 91WbdiMZ7j26Rh9ABegnkp3fTQ+TU7fidQ== X-Google-Smtp-Source: ABdhPJztQb605PAHH3vEaGKJa5BiPVKQTBmBl3th3DvQDY58rYgdR7M3V8eS6fKTDphFI9TGEyVhiQ== X-Received: by 2002:a5d:9151:: with SMTP id y17mr11702211ioq.38.1643659014023; Mon, 31 Jan 2022 11:56:54 -0800 (PST) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id j2sm1972989ilu.82.2022.01.31.11.56.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jan 2022 11:56:53 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PULL 24/40] bsd-user/signal.c: host_to_target_siginfo_noswap Date: Mon, 31 Jan 2022 12:56:20 -0700 Message-Id: <20220131195636.31991-25-imp@bsdimp.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220131195636.31991-1-imp@bsdimp.com> References: <20220131195636.31991-1-imp@bsdimp.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::d2e (failed) Received-SPF: none client-ip=2607:f8b0:4864:20::d2e; envelope-from=imp@bsdimp.com; helo=mail-io1-xd2e.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Stacey Son , Kyle Evans , Richard Henderson , def@FreeBSD.org, jrtc27@FreeBSD.org, Warner Losh Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Implement conversion of host to target siginfo. Signed-off-by: Stacey Son Signed-off-by: Kyle Evans Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/signal.c | 113 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) diff --git a/bsd-user/signal.c b/bsd-user/signal.c index cb0036acb61..db8cf0a08f1 100644 --- a/bsd-user/signal.c +++ b/bsd-user/signal.c @@ -48,6 +48,119 @@ int target_to_host_signal(int sig) return sig; } +static bool has_trapno(int tsig) +{ + return tsig == TARGET_SIGILL || + tsig == TARGET_SIGFPE || + tsig == TARGET_SIGSEGV || + tsig == TARGET_SIGBUS || + tsig == TARGET_SIGTRAP; +} + + +/* Siginfo conversion. */ + +/* + * Populate tinfo w/o swapping based on guessing which fields are valid. + */ +static inline void host_to_target_siginfo_noswap(target_siginfo_t *tinfo, + const siginfo_t *info) +{ + int sig = host_to_target_signal(info->si_signo); + int si_code = info->si_code; + int si_type; + + /* + * Make sure we that the variable portion of the target siginfo is zeroed + * out so we don't leak anything into that. + */ + memset(&tinfo->_reason, 0, sizeof(tinfo->_reason)); + + /* + * This is awkward, because we have to use a combination of the si_code and + * si_signo to figure out which of the union's members are valid.o We + * therefore make our best guess. + * + * Once we have made our guess, we record it in the top 16 bits of + * the si_code, so that tswap_siginfo() later can use it. + * tswap_siginfo() will strip these top bits out before writing + * si_code to the guest (sign-extending the lower bits). + */ + tinfo->si_signo = sig; + tinfo->si_errno = info->si_errno; + tinfo->si_code = info->si_code; + tinfo->si_pid = info->si_pid; + tinfo->si_uid = info->si_uid; + tinfo->si_status = info->si_status; + tinfo->si_addr = (abi_ulong)(unsigned long)info->si_addr; + /* + * si_value is opaque to kernel. On all FreeBSD platforms, + * sizeof(sival_ptr) >= sizeof(sival_int) so the following + * always will copy the larger element. + */ + tinfo->si_value.sival_ptr = + (abi_ulong)(unsigned long)info->si_value.sival_ptr; + + switch (si_code) { + /* + * All the SI_xxx codes that are defined here are global to + * all the signals (they have values that none of the other, + * more specific signal info will set). + */ + case SI_USER: + case SI_LWP: + case SI_KERNEL: + case SI_QUEUE: + case SI_ASYNCIO: + /* + * Only the fixed parts are valid (though FreeBSD doesn't always + * set all the fields to non-zero values. + */ + si_type = QEMU_SI_NOINFO; + break; + case SI_TIMER: + tinfo->_reason._timer._timerid = info->_reason._timer._timerid; + tinfo->_reason._timer._overrun = info->_reason._timer._overrun; + si_type = QEMU_SI_TIMER; + break; + case SI_MESGQ: + tinfo->_reason._mesgq._mqd = info->_reason._mesgq._mqd; + si_type = QEMU_SI_MESGQ; + break; + default: + /* + * We have to go based on the signal number now to figure out + * what's valid. + */ + if (has_trapno(sig)) { + tinfo->_reason._fault._trapno = info->_reason._fault._trapno; + si_type = QEMU_SI_FAULT; + } +#ifdef TARGET_SIGPOLL + /* + * FreeBSD never had SIGPOLL, but emulates it for Linux so there's + * a chance it may popup in the future. + */ + if (sig == TARGET_SIGPOLL) { + tinfo->_reason._poll._band = info->_reason._poll._band; + si_type = QEMU_SI_POLL; + } +#endif + /* + * Unsure that this can actually be generated, and our support for + * capsicum is somewhere between weak and non-existant, but if we get + * one, then we know what to save. + */ + if (sig == TARGET_SIGTRAP) { + tinfo->_reason._capsicum._syscall = + info->_reason._capsicum._syscall; + si_type = QEMU_SI_CAPSICUM; + } + break; + } + tinfo->si_code = deposit32(si_code, 24, 8, si_type); +} + /* * Queue a signal so that it will be send to the virtual CPU as soon as * possible. From patchwork Mon Jan 31 19:56:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 12731144 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F1AD2C433EF for ; Mon, 31 Jan 2022 21:04:42 +0000 (UTC) Received: from localhost ([::1]:54530 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nEdqr-0006Qy-OY for qemu-devel@archiver.kernel.org; Mon, 31 Jan 2022 16:04:41 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43284) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nEcnl-00054A-3i for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:25 -0500 Received: from [2607:f8b0:4864:20::d32] (port=35660 helo=mail-io1-xd32.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nEcnb-0002ey-PJ for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:24 -0500 Received: by mail-io1-xd32.google.com with SMTP id 9so18465605iou.2 for ; Mon, 31 Jan 2022 11:56:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2cxVzUGQfUKapU6iJyRCNz3mEY37Sx777/SzAWGZs48=; b=MntQDAUF+/auInE6Lqv2Hrz1wQucNLiwZVcLEFAdbVoUdla4N9cJroz027SYU0jmai bym8Q+CefIMnXb6HdNsbNppSZdQhUS0hZBSfsLFBu0vhmEM+3PfjBMAhfZYUY208pYsi KUMDIwxFqj2TIVF6t1oUUjZ2fM/+KinhnK2NsRKQ5P+Zxi8tM39MDPjLDgnco0ziCvkb liqdoIOrOROl0y2I9GuUWek/1Vy49Zjdj3b1oM5XEXfTUFVZdDH1BWKo/v0vh3DIv0vB ixQsCiaTvsndxqS7UixeOL14GAgGNZY5SBh86CAhYSVKzTIzzqlamwoRkcrWNh3vaIMp jHdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2cxVzUGQfUKapU6iJyRCNz3mEY37Sx777/SzAWGZs48=; b=2uAVJDSEt83R2Tu2lX2LXgGbo9sNtwQtVuOo70QCQejoimX+SkTX02fPQqIKPqMbVA IHLuLSElX0LEcDRcsK46oB1kJRkwZJ6zvo6H697zPgMt4Jp4dtusB1+3q9x9KHV9y8yD bHgbkgUUabJhxHJF6nBvAg2sXtDa8kMHRqY+mBS27SjVZYryZq7jWmtKWS7f+EO9K3Pe GFiXnuWtvUsDKyMeeopcrEgm7gTGDfffnSekviCQhFvSX/88Yt963LBB/w5+qaL918nV 5z/ZiKKxgRRMjNxZ13kisqAfHHrSWLzNhK1cOn8/ASw5uw9gHH1ucOb3oHqmIxsunn6S N/iw== X-Gm-Message-State: AOAM532j99k8d+v8v9ZsjiJm7p5bR9uoTwsMefa4UvRBx1Osh9VDTqso NGUOIver5JTlma5l+UjHJXDBdIKwiBbp9w== X-Google-Smtp-Source: ABdhPJz7tdoYrAfNvMqFqbOiBYos4+yoliNsdImVX0FNS95u4CRV+HlFE2x19bMXkZOmB53MLfDfEA== X-Received: by 2002:a6b:4417:: with SMTP id r23mr11906817ioa.23.1643659014974; Mon, 31 Jan 2022 11:56:54 -0800 (PST) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id j2sm1972989ilu.82.2022.01.31.11.56.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jan 2022 11:56:54 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PULL 25/40] bsd-user/signal.c: Implement rewind_if_in_safe_syscall Date: Mon, 31 Jan 2022 12:56:21 -0700 Message-Id: <20220131195636.31991-26-imp@bsdimp.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220131195636.31991-1-imp@bsdimp.com> References: <20220131195636.31991-1-imp@bsdimp.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::d32 (failed) Received-SPF: none client-ip=2607:f8b0:4864:20::d32; envelope-from=imp@bsdimp.com; helo=mail-io1-xd32.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Kyle Evans , Richard Henderson , def@FreeBSD.org, jrtc27@FreeBSD.org, Warner Losh Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Kyle Evans Signed-off-by: Warner Losh Reviewed-by: Peter Maydell Reviewed-by: Richard Henderson --- bsd-user/qemu.h | 2 ++ bsd-user/signal.c | 13 ++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index 49f01932a53..8ed1bfbca89 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -446,4 +446,6 @@ static inline void *lock_user_string(abi_ulong guest_addr) #include +#include "user/safe-syscall.h" + #endif /* QEMU_H */ diff --git a/bsd-user/signal.c b/bsd-user/signal.c index db8cf0a08f1..454aef2993e 100644 --- a/bsd-user/signal.c +++ b/bsd-user/signal.c @@ -48,6 +48,18 @@ int target_to_host_signal(int sig) return sig; } +/* Adjust the signal context to rewind out of safe-syscall if we're in it */ +static inline void rewind_if_in_safe_syscall(void *puc) +{ + ucontext_t *uc = (ucontext_t *)puc; + uintptr_t pcreg = host_signal_pc(uc); + + if (pcreg > (uintptr_t)safe_syscall_start + && pcreg < (uintptr_t)safe_syscall_end) { + host_signal_set_pc(uc, (uintptr_t)safe_syscall_start); + } +} + static bool has_trapno(int tsig) { return tsig == TARGET_SIGILL || @@ -57,7 +69,6 @@ static bool has_trapno(int tsig) tsig == TARGET_SIGTRAP; } - /* Siginfo conversion. */ /* From patchwork Mon Jan 31 19:56:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 12731110 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7D40DC433EF for ; Mon, 31 Jan 2022 20:31:08 +0000 (UTC) Received: from localhost ([::1]:38590 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nEdKN-0007nz-F5 for qemu-devel@archiver.kernel.org; Mon, 31 Jan 2022 15:31:07 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43036) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nEcnf-0004xP-UO for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:20 -0500 Received: from [2607:f8b0:4864:20::d2c] (port=38803 helo=mail-io1-xd2c.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nEcnb-0002f8-Fc for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:19 -0500 Received: by mail-io1-xd2c.google.com with SMTP id w7so18426814ioj.5 for ; Mon, 31 Jan 2022 11:56:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hAe6rnov1L/1Q8gAAU9EYHXCUv7q8m8Zw5gDaFIXI5o=; b=V3l+O6ttBclevhbjeUO7sqRoudPQ7w/PorOgn91eh8xqlea+MwIbWruoJpgWJahuxX BKeiN9a8cB5lJi43xgfmcr0aGSHG27rpOcPPUJYfIBzATeO1x8zINQvzpu8TWGOHd6X0 nFiN2hYxC5w2OgjSlfQAtUuN4jkGZXvES8EJDSnMh6XASN3OINXcvoTW0h4PGasmR0wK /zMZRVVfg5Bf4VDGMUn/0mT82a+cdZ2DGaSX++Oygal+FNfWPRpqxYscghSbwNRLRg6h nUnDCMUMW4RG3nVdMUwyhoWP0mGZO5c+V2ZpUud2zkEzfiJjgbWV6TdEr1chTgX6HUCj Pdwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hAe6rnov1L/1Q8gAAU9EYHXCUv7q8m8Zw5gDaFIXI5o=; b=Q8f+1+bY2PxalWsyg9aRfD8CzhM0UHkPK2qse5lvg1KECbHNvQgKgS49MXxy5soYtj 1XqvdYJRRn0EvOp5bBP/sp4jEL71+BNr9yWSnO3SYCOKzvC07aMfEFb9opCjxDZFJSl6 aSt6PzH6Q33NpCewc43K2kjSPcKwKYyGUf0p/GTuaU4+s5+cXC8IDCofRxJRn7K9yRXd cM1QzBr09wE05TKX32ddjiTvyUjFIP3A9TpcazsjG6hD66Q8E2YCptHpkV3tENYsD6XX 9Y5dTEW27KQKEHISRrlwb1cSv8m9mp2IwqnMvO6UPJvPGkQjp5Ez4ADcBqigiEeW4NCq kn7w== X-Gm-Message-State: AOAM530LfToH4Q9UIPJuOGzvsiJ9VWBdDmB3/F3Q0q1Yk4m8RyDPD/7a iHbLJCEZQxm7WrFyxryL6bCl6TXsC+fUhA== X-Google-Smtp-Source: ABdhPJxFMwFr/u7HfKihiw2ho9J01MaiMRJIGBRzi5CLraL6ULPvRc01IZvCoowfSPxCJgmeWWdYKA== X-Received: by 2002:a6b:4e18:: with SMTP id c24mr12208613iob.179.1643659015932; Mon, 31 Jan 2022 11:56:55 -0800 (PST) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id j2sm1972989ilu.82.2022.01.31.11.56.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jan 2022 11:56:55 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PULL 26/40] bsd-user/signal.c: Implement host_signal_handler Date: Mon, 31 Jan 2022 12:56:22 -0700 Message-Id: <20220131195636.31991-27-imp@bsdimp.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220131195636.31991-1-imp@bsdimp.com> References: <20220131195636.31991-1-imp@bsdimp.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::d2c (failed) Received-SPF: none client-ip=2607:f8b0:4864:20::d2c; envelope-from=imp@bsdimp.com; helo=mail-io1-xd2c.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Stacey Son , Kyle Evans , Richard Henderson , def@FreeBSD.org, jrtc27@FreeBSD.org, Warner Losh Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Implement host_signal_handler to handle signals generated by the host and to do safe system calls. Signed-off-by: Stacey Son Signed-off-by: Kyle Evans Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/signal.c | 105 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) diff --git a/bsd-user/signal.c b/bsd-user/signal.c index 454aef2993e..24cf4b1120b 100644 --- a/bsd-user/signal.c +++ b/bsd-user/signal.c @@ -223,6 +223,111 @@ void force_sig_fault(int sig, int code, abi_ulong addr) static void host_signal_handler(int host_sig, siginfo_t *info, void *puc) { + CPUArchState *env = thread_cpu->env_ptr; + CPUState *cpu = env_cpu(env); + TaskState *ts = cpu->opaque; + target_siginfo_t tinfo; + ucontext_t *uc = puc; + struct emulated_sigtable *k; + int guest_sig; + uintptr_t pc = 0; + bool sync_sig = false; + + /* + * Non-spoofed SIGSEGV and SIGBUS are synchronous, and need special + * handling wrt signal blocking and unwinding. + */ + if ((host_sig == SIGSEGV || host_sig == SIGBUS) && info->si_code > 0) { + MMUAccessType access_type; + uintptr_t host_addr; + abi_ptr guest_addr; + bool is_write; + + host_addr = (uintptr_t)info->si_addr; + + /* + * Convert forcefully to guest address space: addresses outside + * reserved_va are still valid to report via SEGV_MAPERR. + */ + guest_addr = h2g_nocheck(host_addr); + + pc = host_signal_pc(uc); + is_write = host_signal_write(info, uc); + access_type = adjust_signal_pc(&pc, is_write); + + if (host_sig == SIGSEGV) { + bool maperr = true; + + if (info->si_code == SEGV_ACCERR && h2g_valid(host_addr)) { + /* If this was a write to a TB protected page, restart. */ + if (is_write && + handle_sigsegv_accerr_write(cpu, &uc->uc_sigmask, + pc, guest_addr)) { + return; + } + + /* + * With reserved_va, the whole address space is PROT_NONE, + * which means that we may get ACCERR when we want MAPERR. + */ + if (page_get_flags(guest_addr) & PAGE_VALID) { + maperr = false; + } else { + info->si_code = SEGV_MAPERR; + } + } + + sigprocmask(SIG_SETMASK, &uc->uc_sigmask, NULL); + cpu_loop_exit_sigsegv(cpu, guest_addr, access_type, maperr, pc); + } else { + sigprocmask(SIG_SETMASK, &uc->uc_sigmask, NULL); + if (info->si_code == BUS_ADRALN) { + cpu_loop_exit_sigbus(cpu, guest_addr, access_type, pc); + } + } + + sync_sig = true; + } + + /* Get the target signal number. */ + guest_sig = host_to_target_signal(host_sig); + if (guest_sig < 1 || guest_sig > TARGET_NSIG) { + return; + } + trace_user_host_signal(cpu, host_sig, guest_sig); + + host_to_target_siginfo_noswap(&tinfo, info); + + k = &ts->sigtab[guest_sig - 1]; + k->info = tinfo; + k->pending = guest_sig; + ts->signal_pending = 1; + + /* + * For synchronous signals, unwind the cpu state to the faulting + * insn and then exit back to the main loop so that the signal + * is delivered immediately. + */ + if (sync_sig) { + cpu->exception_index = EXCP_INTERRUPT; + cpu_loop_exit_restore(cpu, pc); + } + + rewind_if_in_safe_syscall(puc); + + /* + * Block host signals until target signal handler entered. We + * can't block SIGSEGV or SIGBUS while we're executing guest + * code in case the guest code provokes one in the window between + * now and it getting out to the main loop. Signals will be + * unblocked again in process_pending_signals(). + */ + sigfillset(&uc->uc_sigmask); + sigdelset(&uc->uc_sigmask, SIGSEGV); + sigdelset(&uc->uc_sigmask, SIGBUS); + + /* Interrupt the virtual CPU as soon as possible. */ + cpu_exit(thread_cpu); } void signal_init(void) From patchwork Mon Jan 31 19:56:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 12731096 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 20AEBC433EF for ; Mon, 31 Jan 2022 20:19:28 +0000 (UTC) Received: from localhost ([::1]:41472 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nEd95-00075g-7X for qemu-devel@archiver.kernel.org; Mon, 31 Jan 2022 15:19:27 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42956) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nEcne-0004ui-Ak for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:19 -0500 Received: from [2607:f8b0:4864:20::12d] (port=40854 helo=mail-il1-x12d.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nEcnb-0002fF-7W for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:17 -0500 Received: by mail-il1-x12d.google.com with SMTP id s1so12394934ilj.7 for ; Mon, 31 Jan 2022 11:56:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sPl9lqrZjcfTpqegDhQDXRvfLIYwDJ07NuHAvjSC0jE=; b=NZSrtCOCmwxoQlCIUBH8bIBYl8dEIZEWE1QT6tw2jfpkX+/ZusibsDmWGozj1RDu9f YRXz48XvfxFaCID2wunFvfwUsNW1Y5E+h+AFf3S/eg7KZ0zkSI/M3AmyjFE1R2eV3a52 szIQ7sxq3Wh4flYsutmSBWcfVEuXtrlUjlEvtQDM6pM5TYBA4uHv7Mc3Ojm9O5sqfe39 ga5W0cKSIJdpMZn0p+Kk1dqsNEeS31xhs6TOFH3NXmr8vxkLCJnenV0jqG7r63m8AkUi epcSbhS64Z5cmd9Ty+VCn86OrVkOGuZyh9NEBVC9fAFpNQ/96gyC0rqN7VHNAzv8jTE5 a6cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sPl9lqrZjcfTpqegDhQDXRvfLIYwDJ07NuHAvjSC0jE=; b=D055Z/ztO9cZOaj4GUJW7NMaQxJJ6KM7MQQcOSgJnWOc6SBafEDY7e3J52OZVJombQ sVPIPS8yP6xGW5H21RpU6YVnet/6+wSlJUFHP7jRprLcNrv1GWsHuTNpBN8/PFIqk1Qv RwF20wL4dBMHaCj53PB9kMosPHE5JhRCAfLv4X+rhphhg73D4NB4BLUyRnnlnhqmq3Xo qzvitnpWXOegLnSNX+DmXqhWWMA1cUsEMhgWJWYdcDbAbaIuYv/u+i9O8c1TXQPBSuUp PG4vfxrNR0zn1TBHgv0hw1/iatz2NKehj9GhVWiMB800IOaguFfZHENcROPH2Yoga7lm R15A== X-Gm-Message-State: AOAM533l2ZCkdZKSwqEohzjS7RYq68fKsWNeqESR4G3HMRccswEqnDlM awqcvAC75R7I2jKH1cIAAzCqCd889T+Wiw== X-Google-Smtp-Source: ABdhPJwebBVeZq6X5vcZwDBnLTLqvVMi8E19b9DFPJpI9M/COsJRYpJ8SruwPkvcSm6jMELeSCA5wA== X-Received: by 2002:a05:6e02:1945:: with SMTP id x5mr13207737ilu.49.1643659017206; Mon, 31 Jan 2022 11:56:57 -0800 (PST) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id j2sm1972989ilu.82.2022.01.31.11.56.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jan 2022 11:56:56 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PULL 27/40] bsd-user/strace.c: print_taken_signal Date: Mon, 31 Jan 2022 12:56:23 -0700 Message-Id: <20220131195636.31991-28-imp@bsdimp.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220131195636.31991-1-imp@bsdimp.com> References: <20220131195636.31991-1-imp@bsdimp.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::12d (failed) Received-SPF: none client-ip=2607:f8b0:4864:20::12d; envelope-from=imp@bsdimp.com; helo=mail-il1-x12d.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Stacey Son , Kyle Evans , Richard Henderson , def@FreeBSD.org, jrtc27@FreeBSD.org, Warner Losh Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" print_taken_signal() prints signals when we're tracing signals. Signed-off-by: Stacey Son Signed-off-by: Kyle Evans Signed-off-by: Warner Losh Reviewed-by: Peter Maydell Reviewed-by: Richard Henderson --- bsd-user/qemu.h | 10 +++++ bsd-user/strace.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+) diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index 8ed1bfbca89..a7964776fdb 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -204,6 +204,16 @@ print_openbsd_syscall(int num, abi_long arg1, abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5, abi_long arg6); void print_openbsd_syscall_ret(int num, abi_long ret); +/** + * print_taken_signal: + * @target_signum: target signal being taken + * @tinfo: target_siginfo_t which will be passed to the guest for the signal + * + * Print strace output indicating that this signal is being taken by the guest, + * in a format similar to: + * --- SIGSEGV {si_signo=SIGSEGV, si_code=SI_KERNEL, si_addr=0} --- + */ +void print_taken_signal(int target_signum, const target_siginfo_t *tinfo); extern int do_strace; /* mmap.c */ diff --git a/bsd-user/strace.c b/bsd-user/strace.c index be40b8a20cf..a77d10dd6b6 100644 --- a/bsd-user/strace.c +++ b/bsd-user/strace.c @@ -31,6 +31,24 @@ int do_strace; /* * Utility functions */ +static const char * +get_comma(int last) +{ + return (last) ? "" : ","; +} + +/* + * Prints out raw parameter using given format. Caller needs + * to do byte swapping if needed. + */ +static void +print_raw_param(const char *fmt, abi_long param, int last) +{ + char format[64]; + + (void)snprintf(format, sizeof(format), "%s%s", fmt, get_comma(last)); + gemu_log(format, param); +} static void print_sysctl(const struct syscallname *name, abi_long arg1, abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5, @@ -239,3 +257,82 @@ void print_openbsd_syscall_ret(int num, abi_long ret) print_syscall_ret(num, ret, openbsd_scnames, ARRAY_SIZE(openbsd_scnames)); } + +static void +print_signal(abi_ulong arg, int last) +{ + const char *signal_name = NULL; + switch (arg) { + case TARGET_SIGHUP: + signal_name = "SIGHUP"; + break; + case TARGET_SIGINT: + signal_name = "SIGINT"; + break; + case TARGET_SIGQUIT: + signal_name = "SIGQUIT"; + break; + case TARGET_SIGILL: + signal_name = "SIGILL"; + break; + case TARGET_SIGABRT: + signal_name = "SIGABRT"; + break; + case TARGET_SIGFPE: + signal_name = "SIGFPE"; + break; + case TARGET_SIGKILL: + signal_name = "SIGKILL"; + break; + case TARGET_SIGSEGV: + signal_name = "SIGSEGV"; + break; + case TARGET_SIGPIPE: + signal_name = "SIGPIPE"; + break; + case TARGET_SIGALRM: + signal_name = "SIGALRM"; + break; + case TARGET_SIGTERM: + signal_name = "SIGTERM"; + break; + case TARGET_SIGUSR1: + signal_name = "SIGUSR1"; + break; + case TARGET_SIGUSR2: + signal_name = "SIGUSR2"; + break; + case TARGET_SIGCHLD: + signal_name = "SIGCHLD"; + break; + case TARGET_SIGCONT: + signal_name = "SIGCONT"; + break; + case TARGET_SIGSTOP: + signal_name = "SIGSTOP"; + break; + case TARGET_SIGTTIN: + signal_name = "SIGTTIN"; + break; + case TARGET_SIGTTOU: + signal_name = "SIGTTOU"; + break; + } + if (signal_name == NULL) { + print_raw_param("%ld", arg, last); + return; + } + gemu_log("%s%s", signal_name, get_comma(last)); +} + +void print_taken_signal(int target_signum, const target_siginfo_t *tinfo) +{ + /* + * Print the strace output for a signal being taken: + * --- SIGSEGV {si_signo=SIGSEGV, si_code=SI_KERNEL, si_addr=0} --- + */ + gemu_log("%d ", getpid()); + gemu_log("--- "); + print_signal(target_signum, 1); + gemu_log(" ---\n"); +} From patchwork Mon Jan 31 19:56:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 12731104 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 96C98C433F5 for ; Mon, 31 Jan 2022 20:24:54 +0000 (UTC) Received: from localhost ([::1]:58154 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nEdEL-0001dD-OV for qemu-devel@archiver.kernel.org; Mon, 31 Jan 2022 15:24:53 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43048) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nEcng-0004xU-65 for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:20 -0500 Received: from [2607:f8b0:4864:20::d32] (port=33448 helo=mail-io1-xd32.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nEcnb-0002fL-Hu for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:19 -0500 Received: by mail-io1-xd32.google.com with SMTP id y84so18496745iof.0 for ; Mon, 31 Jan 2022 11:56:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=U8VtaM8f6H1mBedMcMN2t5hogqkVzA4l3N+z2sTiAUQ=; b=UxAJSeqOb0X8WTk0+XqmlJ98pz3QkdHKj+aZw2m+InBvq2krgKLCKyMxvJvzLCwVwI zHmZQDQctgU7ocnbq42ABrd3RyrMyJTImzYfUZBD26BpCOV0onCkMekJ58veOoVGDyRP gJEcxaOblzFUkReeWk6pXpe4bd+AaPbXbfqnZdoRj7s/ULwEPsRIo6BGSIs81bXBK1Hh mHqoVYDDNZASi0JQbZzUjxEenD+E2kBef7A9tLz7usi99fVC/qgNLMhCxSFJdgqMZy31 9RUz44wtACoOMbgMXyvNh4DbIbq/qYwDg8yG+5vyxpEMyIfIyxFhsKitlu/9ZDxd4odi rmCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=U8VtaM8f6H1mBedMcMN2t5hogqkVzA4l3N+z2sTiAUQ=; b=TZtVC4u9fIME/awhoU+nRX6dY+1rjQZ9hFuZCUEqf73DEWvY0GauWOKAD27OksAReU JT8nN5TW10lreIlr6Lo5By+IX/Hf7UliuPopAPwoem7XJRjfugqpWOEc8e2SeqXq1KlD fWsyVn5HHmfEpCCdT9JQzCHDRTB5irk1QfqGKJdSfkrqalJCkMlnnR9ttIh8PVFYZhgi lBJZpnAH7D5s4KsIqIa0qizODaXvjG9xaOoXJFy9RldhN09mt3YNzOElPjFTRWp4iV6Y sY8aJkcVavXQxEYsMRlZg97iVHLds73iiy/c/bwqmy1qV4YG7XHFAvG+ilCJNlsqoKu2 M0mg== X-Gm-Message-State: AOAM5335tDf5Ek95OFTF0yPceIBsiNnmhd/q2wqvL9PZtU83aAh/vqBo 8UGMygBvg4acJ07Ln+8vNXBbt4nL3IPKBg== X-Google-Smtp-Source: ABdhPJwt+pkOPn5WU/Y8ilImgdCcLGsMxwLFzj8hVgumiC19wIIrmmQwXyZebig5eo5HBgR7Bw8hjw== X-Received: by 2002:a6b:c817:: with SMTP id y23mr11724218iof.71.1643659018090; Mon, 31 Jan 2022 11:56:58 -0800 (PST) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id j2sm1972989ilu.82.2022.01.31.11.56.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jan 2022 11:56:57 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PULL 28/40] bsd-user/signal.c: Implement dump_core_and_abort Date: Mon, 31 Jan 2022 12:56:24 -0700 Message-Id: <20220131195636.31991-29-imp@bsdimp.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220131195636.31991-1-imp@bsdimp.com> References: <20220131195636.31991-1-imp@bsdimp.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::d32 (failed) Received-SPF: none client-ip=2607:f8b0:4864:20::d32; envelope-from=imp@bsdimp.com; helo=mail-io1-xd32.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Stacey Son , Kyle Evans , Richard Henderson , def@FreeBSD.org, jrtc27@FreeBSD.org, Warner Losh Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Force delivering a signal and generating a core file. It's a global function for the moment... Signed-off-by: Stacey Son Signed-off-by: Kyle Evans Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/signal.c | 76 +++++++++++++++++++++++++++++++++++++++++ bsd-user/syscall_defs.h | 1 + 2 files changed, 77 insertions(+) diff --git a/bsd-user/signal.c b/bsd-user/signal.c index 24cf4b1120b..ccda7adbeef 100644 --- a/bsd-user/signal.c +++ b/bsd-user/signal.c @@ -172,6 +172,82 @@ static inline void host_to_target_siginfo_noswap(target_siginfo_t *tinfo, tinfo->si_code = deposit32(si_code, 24, 8, si_type); } +/* Returns 1 if given signal should dump core if not handled. */ +static int core_dump_signal(int sig) +{ + switch (sig) { + case TARGET_SIGABRT: + case TARGET_SIGFPE: + case TARGET_SIGILL: + case TARGET_SIGQUIT: + case TARGET_SIGSEGV: + case TARGET_SIGTRAP: + case TARGET_SIGBUS: + return 1; + default: + return 0; + } +} + +/* Abort execution with signal. */ +static void QEMU_NORETURN dump_core_and_abort(int target_sig) +{ + CPUArchState *env = thread_cpu->env_ptr; + CPUState *cpu = env_cpu(env); + TaskState *ts = cpu->opaque; + int core_dumped = 0; + int host_sig; + struct sigaction act; + + host_sig = target_to_host_signal(target_sig); + gdb_signalled(env, target_sig); + + /* Dump core if supported by target binary format */ + if (core_dump_signal(target_sig) && (ts->bprm->core_dump != NULL)) { + stop_all_tasks(); + core_dumped = + ((*ts->bprm->core_dump)(target_sig, env) == 0); + } + if (core_dumped) { + struct rlimit nodump; + + /* + * We already dumped the core of target process, we don't want + * a coredump of qemu itself. + */ + getrlimit(RLIMIT_CORE, &nodump); + nodump.rlim_cur = 0; + setrlimit(RLIMIT_CORE, &nodump); + (void) fprintf(stderr, "qemu: uncaught target signal %d (%s) " + "- %s\n", target_sig, strsignal(host_sig), "core dumped"); + } + + /* + * The proper exit code for dying from an uncaught signal is + * -. The kernel doesn't allow exit() or _exit() to pass + * a negative value. To get the proper exit code we need to + * actually die from an uncaught signal. Here the default signal + * handler is installed, we send ourself a signal and we wait for + * it to arrive. + */ + memset(&act, 0, sizeof(act)); + sigfillset(&act.sa_mask); + act.sa_handler = SIG_DFL; + sigaction(host_sig, &act, NULL); + + kill(getpid(), host_sig); + + /* + * Make sure the signal isn't masked (just reuse the mask inside + * of act). + */ + sigdelset(&act.sa_mask, host_sig); + sigsuspend(&act.sa_mask); + + /* unreachable */ + abort(); +} + /* * Queue a signal so that it will be send to the virtual CPU as soon as * possible. diff --git a/bsd-user/syscall_defs.h b/bsd-user/syscall_defs.h index 04a1a886d7b..62b472b990b 100644 --- a/bsd-user/syscall_defs.h +++ b/bsd-user/syscall_defs.h @@ -21,6 +21,7 @@ #define _SYSCALL_DEFS_H_ #include +#include #include "errno_defs.h" From patchwork Mon Jan 31 19:56:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 12731099 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B85B6C433EF for ; Mon, 31 Jan 2022 20:22:37 +0000 (UTC) Received: from localhost ([::1]:48366 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nEdC8-0003Vo-RS for qemu-devel@archiver.kernel.org; Mon, 31 Jan 2022 15:22:36 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42990) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nEcnf-0004v4-3B for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:19 -0500 Received: from [2607:f8b0:4864:20::134] (port=47055 helo=mail-il1-x134.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nEcnb-0002fT-CJ for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:18 -0500 Received: by mail-il1-x134.google.com with SMTP id e8so12375849ilm.13 for ; Mon, 31 Jan 2022 11:57:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MVWZUYxrpCifraNDGYSj461HH4N52sJPo6Fc3sNZUKk=; b=X/BhydrfXIDLK8VV/LWNjp9DUyMbsAH0cNJqmpFlZ4Uq5DVLgo+o8lnOKT8oyVEBLW wAJuVHAsYSKzsZp2fxPP7FHSTrGJdXDSP95SB+KMoQAULwAxsXfOv5ulrGls3vGVA2om NOH9kT8WF+t8TnG5kX1u2nS5LQqhwGgMvyY+vFi/Elx+3Xl9huNhIE06MS0VPyvbUjv2 eoqyQHbAT+UDZxI90zBEHIogBca6gWLUQpc2El+OTVw12sQibgVnhxE3ds4ICF706ToL m5mDC7FAIpNYeopfAav21nXLLSGz84228BqJ4UVY4+5N3ck1q7DeJ8MDF5N0D15ptbmD SDQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MVWZUYxrpCifraNDGYSj461HH4N52sJPo6Fc3sNZUKk=; b=KSM+V498pmc3rRo9SVj04rD4A5j++QT3RMVzmNvUXJFpGwR9yiCEwrhgZ3Dc3hSNNy B661USTcZVDQSyQbxBFsla96tLvdbguQjU6eXJAkHit1EgX4iqIhXYGkdPJHUMrqsNng bXrHvXtSnr/u41Clax6vXCKO5Rd/C89jhKzYnp+Pq5kkX8phpgMGFTJ0dvGy1LXNbCt7 OM/Zjh9HkAa8/HpW/eWtuTuBaIbqWklGNoqXaYucHySDXGjmOsDCDJ7lAH5sghgCPXQv 3a9fB3uZl8y2SspFY7mUABcxctccAeH96oakXVsqT5JEnf917n0DWp/4UwTiitM8hApH frfA== X-Gm-Message-State: AOAM533UCKy/E2k95SKufCHVJSImoAKdeFrjFqRPv12vCKWFA9/r78jv KrWE+CLhewUhmY6uWeIkbJ1qFB+kH0MEqA== X-Google-Smtp-Source: ABdhPJxstx98rtVCcAkApxnnHmpivBG8BKfinJYDBq2aKJBTMxX6fXL+MRne6W0aDY6bstk2ut51Zg== X-Received: by 2002:a05:6e02:1a4d:: with SMTP id u13mr2114394ilv.136.1643659019357; Mon, 31 Jan 2022 11:56:59 -0800 (PST) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id j2sm1972989ilu.82.2022.01.31.11.56.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jan 2022 11:56:58 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PULL 29/40] bsd-user/signal.c: Fill in queue_signal Date: Mon, 31 Jan 2022 12:56:25 -0700 Message-Id: <20220131195636.31991-30-imp@bsdimp.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220131195636.31991-1-imp@bsdimp.com> References: <20220131195636.31991-1-imp@bsdimp.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::134 (failed) Received-SPF: none client-ip=2607:f8b0:4864:20::134; envelope-from=imp@bsdimp.com; helo=mail-il1-x134.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Stacey Son , Kyle Evans , Richard Henderson , def@FreeBSD.org, jrtc27@FreeBSD.org, Warner Losh Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Fill in queue signal implementation, as well as routines allocate and delete elements of the signal queue. Signed-off-by: Stacey Son Signed-off-by: Kyle Evans Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/qemu.h | 5 +++++ bsd-user/signal.c | 13 ++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index a7964776fdb..1648a509b9c 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -85,6 +85,11 @@ typedef struct TaskState { struct bsd_binprm *bprm; struct image_info *info; + struct emulated_sigtable sync_signal; + /* + * TODO: Since we block all signals while returning to the main CPU + * loop, this needn't be an array + */ struct emulated_sigtable sigtab[TARGET_NSIG]; /* * Nonzero if process_pending_signals() needs to do something (either diff --git a/bsd-user/signal.c b/bsd-user/signal.c index ccda7adbeef..34663f7a28a 100644 --- a/bsd-user/signal.c +++ b/bsd-user/signal.c @@ -255,7 +255,18 @@ static void QEMU_NORETURN dump_core_and_abort(int target_sig) void queue_signal(CPUArchState *env, int sig, int si_type, target_siginfo_t *info) { - qemu_log_mask(LOG_UNIMP, "No signal queueing, dropping signal %d\n", sig); + CPUState *cpu = env_cpu(env); + TaskState *ts = cpu->opaque; + + trace_user_queue_signal(env, sig); + + info->si_code = deposit32(info->si_code, 24, 8, si_type); + + ts->sync_signal.info = *info; + ts->sync_signal.pending = sig; + /* Signal that a new signal is pending. */ + qatomic_set(&ts->signal_pending, 1); + return; } static int fatal_signal(int sig) From patchwork Mon Jan 31 19:56:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 12731124 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B53A3C433F5 for ; Mon, 31 Jan 2022 20:38:26 +0000 (UTC) Received: from localhost ([::1]:53486 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nEdRR-0001HU-LL for qemu-devel@archiver.kernel.org; Mon, 31 Jan 2022 15:38:25 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42992) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nEcnf-0004v5-3M for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:19 -0500 Received: from [2607:f8b0:4864:20::130] (port=33306 helo=mail-il1-x130.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nEcnb-0002fY-CJ for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:18 -0500 Received: by mail-il1-x130.google.com with SMTP id o10so12440938ilh.0 for ; Mon, 31 Jan 2022 11:57:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rw3tCyrqXVGsCR1NJHkGgUyguO31bINLvGmuRP6N6Bw=; b=POiBvCAzXizOIiO/66fPR/S/qHCDH0ZBsOMuWzzSw9vBdlxSgfImFkSlKBREvn6bJp 91da2dHHKdYoUTAGEZd/PVTOxKYbpOiNBeBHfCtgfDlUt9s85o6lJkAZlB/jCuUC/k0O dL62d5a/KHbcGT8i9TTkBsDx5BAV6Qq+beOmTFxTUaqsewmfLQJuphc1K7bX8pnJ1J+3 yBBaNVtigdZpGvtkYIFnHCs5MX/aqzUe5cm6Wl9UwLaBaxPzgCX4JI+zz2GGGTu68mx7 5cX+0YZUlzwBkhFi4QftvHRbb5oMZGkARvrnIdPA5oO5EeUakV8dfryXEyHgkjwwXIGc LfTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rw3tCyrqXVGsCR1NJHkGgUyguO31bINLvGmuRP6N6Bw=; b=p7Y/u5/7jc2kTwEzWAMR85IcbUxH8gfZy6F0D9pAtBbEemerYWhvwPA+TaLnQERCtW /kkfmBjvoW13n24ScNW2wF8glSeDKemGKeTIcVexKG6QSSI5XkT0KkjUEz/mfHwgv7E1 +2MIpdJjooWd85eYw5G98YSdwcdE+kcYvsQIdGmSrilYvNRLNTZgJLbZEHCWf8DFP0w/ Lu9EwazSNRRaz69QYTbVfW0nrmAnuNZGllZ4xeYfbe23uBmBocuyJN/XnLV2S9dwVCX/ PdyGBD0wanPpH6FubQeEObC+sJn/Nt/T2Fj6hiqfNM8AawSy3Xs1krz3miMW/iYzRXta 8CKg== X-Gm-Message-State: AOAM532XPGZXSPwbvaWNswNxMLlv6Y88R/aFZPMjswUD9b4Nl3Y1KQmv vAaWiXAhbr2W8iPIlSrYjaLl8aPKpew6PQ== X-Google-Smtp-Source: ABdhPJxBm3pXSBRaz/63meW2w6qqaBNy0XGAba0yCPSvLhbq0FrvjyBkvSO0O9itDMYPjNv6vwTVAQ== X-Received: by 2002:a05:6e02:216a:: with SMTP id s10mr2307594ilv.287.1643659020225; Mon, 31 Jan 2022 11:57:00 -0800 (PST) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id j2sm1972989ilu.82.2022.01.31.11.56.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jan 2022 11:56:59 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PULL 30/40] bsd-user/signal.c: sigset manipulation routines. Date: Mon, 31 Jan 2022 12:56:26 -0700 Message-Id: <20220131195636.31991-31-imp@bsdimp.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220131195636.31991-1-imp@bsdimp.com> References: <20220131195636.31991-1-imp@bsdimp.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::130 (failed) Received-SPF: none client-ip=2607:f8b0:4864:20::130; envelope-from=imp@bsdimp.com; helo=mail-il1-x130.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Stacey Son , Kyle Evans , Richard Henderson , def@FreeBSD.org, jrtc27@FreeBSD.org, Warner Losh Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" target_sigemptyset: resets a set to having no bits set target_sigaddset: adds a signal to a set target_sigismember: returns true when signal is a member host_to_target_sigset_internal: convert host sigset to target host_to_target_sigset: convert host sigset to target target_to_host_sigset_internal: convert target sigset to host target_to_host_sigset: convert target sigset to host Signed-off-by: Stacey Son Signed-off-by: Kyle Evans Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/signal-common.h | 2 ++ bsd-user/signal.c | 74 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/bsd-user/signal-common.h b/bsd-user/signal-common.h index 80e9503238a..ee819266f54 100644 --- a/bsd-user/signal-common.h +++ b/bsd-user/signal-common.h @@ -14,11 +14,13 @@ abi_long do_sigaltstack(abi_ulong uss_addr, abi_ulong uoss_addr, abi_ulong sp); long do_sigreturn(CPUArchState *env); void force_sig_fault(int sig, int code, abi_ulong addr); int host_to_target_signal(int sig); +void host_to_target_sigset(target_sigset_t *d, const sigset_t *s); void process_pending_signals(CPUArchState *env); void queue_signal(CPUArchState *env, int sig, int si_type, target_siginfo_t *info); void signal_init(void); int target_to_host_signal(int sig); +void target_to_host_sigset(sigset_t *d, const target_sigset_t *s); /* * Within QEMU the top 8 bits of si_code indicate which of the parts of the diff --git a/bsd-user/signal.c b/bsd-user/signal.c index 34663f7a28a..84dafa4e9fe 100644 --- a/bsd-user/signal.c +++ b/bsd-user/signal.c @@ -32,6 +32,9 @@ static struct target_sigaction sigact_table[TARGET_NSIG]; static void host_signal_handler(int host_sig, siginfo_t *info, void *puc); +static void target_to_host_sigset_internal(sigset_t *d, + const target_sigset_t *s); + /* * The BSD ABIs use the same singal numbers across all the CPU architectures, so @@ -48,6 +51,25 @@ int target_to_host_signal(int sig) return sig; } +static inline void target_sigemptyset(target_sigset_t *set) +{ + memset(set, 0, sizeof(*set)); +} + +static inline void target_sigaddset(target_sigset_t *set, int signum) +{ + signum--; + uint32_t mask = (uint32_t)1 << (signum % TARGET_NSIG_BPW); + set->__bits[signum / TARGET_NSIG_BPW] |= mask; +} + +static inline int target_sigismember(const target_sigset_t *set, int signum) +{ + signum--; + abi_ulong mask = (abi_ulong)1 << (signum % TARGET_NSIG_BPW); + return (set->__bits[signum / TARGET_NSIG_BPW] & mask) != 0; +} + /* Adjust the signal context to rewind out of safe-syscall if we're in it */ static inline void rewind_if_in_safe_syscall(void *puc) { @@ -60,6 +82,58 @@ static inline void rewind_if_in_safe_syscall(void *puc) } } +/* + * Note: The following take advantage of the BSD signal property that all + * signals are available on all architectures. + */ +static void host_to_target_sigset_internal(target_sigset_t *d, + const sigset_t *s) +{ + int i; + + target_sigemptyset(d); + for (i = 1; i <= NSIG; i++) { + if (sigismember(s, i)) { + target_sigaddset(d, host_to_target_signal(i)); + } + } +} + +void host_to_target_sigset(target_sigset_t *d, const sigset_t *s) +{ + target_sigset_t d1; + int i; + + host_to_target_sigset_internal(&d1, s); + for (i = 0; i < _SIG_WORDS; i++) { + d->__bits[i] = tswap32(d1.__bits[i]); + } +} + +static void target_to_host_sigset_internal(sigset_t *d, + const target_sigset_t *s) +{ + int i; + + sigemptyset(d); + for (i = 1; i <= TARGET_NSIG; i++) { + if (target_sigismember(s, i)) { + sigaddset(d, target_to_host_signal(i)); + } + } +} + +void target_to_host_sigset(sigset_t *d, const target_sigset_t *s) +{ + target_sigset_t s1; + int i; + + for (i = 0; i < TARGET_NSIG_WORDS; i++) { + s1.__bits[i] = tswap32(s->__bits[i]); + } + target_to_host_sigset_internal(d, &s1); +} + static bool has_trapno(int tsig) { return tsig == TARGET_SIGILL || From patchwork Mon Jan 31 19:56:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 12731128 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B25EFC433F5 for ; Mon, 31 Jan 2022 20:38:58 +0000 (UTC) Received: from localhost ([::1]:55540 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nEdRx-0002fy-Rj for qemu-devel@archiver.kernel.org; Mon, 31 Jan 2022 15:38:57 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43108) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nEcnh-0004zr-Dm for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:21 -0500 Received: from [2607:f8b0:4864:20::d2e] (port=43006 helo=mail-io1-xd2e.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nEcnb-0002fk-Iy for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:21 -0500 Received: by mail-io1-xd2e.google.com with SMTP id r144so18377148iod.9 for ; Mon, 31 Jan 2022 11:57:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=C76G+GuQMn9cxisURWPURc1dlhmprPr1u46P1kEgqjQ=; b=P9Vl8Qfvy0CCHnPXE6z0mkc0m/nIzLA7BOHVHz9R8QQnEB0TrWwpjU98BGOrPcK9m+ XV6mtGpixJLUpaOXjH1wiFnDzQ6P1+PprBz1eR7UzVACKbJOWI+xWM8IjyIXVT1LKswV 2AQ/FeXaeUdmQxwf9UaCnh9Dmhp1lUmWGgZcf3rHrnOJdt5p0EfS8H78k2EGwF9mZMUn GY4S45zW+Vj+5Rsucw95DLgiz3UqTITO3p42DtkvZ/nrXOYLzKzVbViGLnydyZqNcvug Q4xDdyaA8lMje9ihM4FQsVgJc5avFvJjKJpshHDOaAdfE/jzyUoLR7TjyFtbAFGJc0FZ YVgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=C76G+GuQMn9cxisURWPURc1dlhmprPr1u46P1kEgqjQ=; b=4vj66f1f4A2hjPNgY4tjFRQgTPi9jY2v1nB1ff5XkcMM7L1A/IkM+vvj85R8o4NpHH 5wXCTD2Bch++S8QW9Z74vB6Ua55MZD8etBnaOYKOBaKRLwxcbml93eZOFv0TXsYCl6hq hN88jyh/Rzi67UDUdTf7L5YhDzqnC2bMZQU1xMPcBeS6C7hZFjhkn/dfiraBW0v5NwCM eVGk54wFWHDSPJzngPPwjOy6uMS5yntZihafOCpvOzXoxbbGJdZv4lvaqKyl35sdGJjU /kxIQy66wBu0tz08pAp6Qmsny9vlTNRweoRMveRT5xtuIDD56JR0H3ijEzT2tX0qCag1 ahOQ== X-Gm-Message-State: AOAM530JawmGJZzGBs8qlvpLugC3g1Q3tHiVfq6wv+EqV1UxI2NgFmaU Fg+Z5PbcosWrH9zbdEybEowQ72F08AwYAg== X-Google-Smtp-Source: ABdhPJxTfObAae1puZS8tZyqFBljnqNIkMZ1JD4zWGSJCEQQAKl0YBlvDmijJe36T5VCAOqkqqTqNg== X-Received: by 2002:a05:6602:2d95:: with SMTP id k21mr12578268iow.84.1643659021819; Mon, 31 Jan 2022 11:57:01 -0800 (PST) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id j2sm1972989ilu.82.2022.01.31.11.57.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jan 2022 11:57:01 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PULL 31/40] bsd-user/signal.c: setup_frame Date: Mon, 31 Jan 2022 12:56:27 -0700 Message-Id: <20220131195636.31991-32-imp@bsdimp.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220131195636.31991-1-imp@bsdimp.com> References: <20220131195636.31991-1-imp@bsdimp.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::d2e (failed) Received-SPF: none client-ip=2607:f8b0:4864:20::d2e; envelope-from=imp@bsdimp.com; helo=mail-io1-xd2e.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Stacey Son , Kyle Evans , Richard Henderson , def@FreeBSD.org, jrtc27@FreeBSD.org, Warner Losh Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" setup_frame sets up a signalled stack frame. Associated routines to extract the pointer to the stack frame and to support alternate stacks. Signed-off-by: Stacey Son Signed-off-by: Kyle Evans Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/main.c | 5 +++ bsd-user/qemu.h | 3 +- bsd-user/signal.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+), 1 deletion(-) diff --git a/bsd-user/main.c b/bsd-user/main.c index 29cf4e15693..f1d58e905e7 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -217,6 +217,11 @@ void qemu_cpu_kick(CPUState *cpu) /* Assumes contents are already zeroed. */ static void init_task_state(TaskState *ts) { + ts->sigaltstack_used = (struct target_sigaltstack) { + .ss_sp = 0, + .ss_size = 0, + .ss_flags = TARGET_SS_DISABLE, + }; } void gemu_log(const char *fmt, ...) diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index 1648a509b9c..de20650a00d 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -107,7 +107,8 @@ typedef struct TaskState { */ sigset_t signal_mask; - uint8_t stack[]; + /* This thread's sigaltstack, if it has one */ + struct target_sigaltstack sigaltstack_used; } __attribute__((aligned(16))) TaskState; void stop_all_tasks(void); diff --git a/bsd-user/signal.c b/bsd-user/signal.c index 84dafa4e9fe..dbc13736073 100644 --- a/bsd-user/signal.c +++ b/bsd-user/signal.c @@ -35,6 +35,16 @@ static void host_signal_handler(int host_sig, siginfo_t *info, void *puc); static void target_to_host_sigset_internal(sigset_t *d, const target_sigset_t *s); +static inline int on_sig_stack(TaskState *ts, unsigned long sp) +{ + return sp - ts->sigaltstack_used.ss_sp < ts->sigaltstack_used.ss_size; +} + +static inline int sas_ss_flags(TaskState *ts, unsigned long sp) +{ + return ts->sigaltstack_used.ss_size == 0 ? SS_DISABLE : + on_sig_stack(ts, sp) ? SS_ONSTACK : 0; +} /* * The BSD ABIs use the same singal numbers across all the CPU architectures, so @@ -491,6 +501,79 @@ static void host_signal_handler(int host_sig, siginfo_t *info, void *puc) cpu_exit(thread_cpu); } +static inline abi_ulong get_sigframe(struct target_sigaction *ka, + CPUArchState *env, size_t frame_size) +{ + TaskState *ts = (TaskState *)thread_cpu->opaque; + abi_ulong sp; + + /* Use default user stack */ + sp = get_sp_from_cpustate(env); + + if ((ka->sa_flags & TARGET_SA_ONSTACK) && sas_ss_flags(ts, sp) == 0) { + sp = ts->sigaltstack_used.ss_sp + ts->sigaltstack_used.ss_size; + } + +/* TODO: make this a target_arch function / define */ +#if defined(TARGET_ARM) + return (sp - frame_size) & ~7; +#elif defined(TARGET_AARCH64) + return (sp - frame_size) & ~15; +#else + return sp - frame_size; +#endif +} + +/* compare to $M/$M/exec_machdep.c sendsig and sys/kern/kern_sig.c sigexit */ + +static void setup_frame(int sig, int code, struct target_sigaction *ka, + target_sigset_t *set, target_siginfo_t *tinfo, CPUArchState *env) +{ + struct target_sigframe *frame; + abi_ulong frame_addr; + int i; + + frame_addr = get_sigframe(ka, env, sizeof(*frame)); + trace_user_setup_frame(env, frame_addr); + if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0)) { + unlock_user_struct(frame, frame_addr, 1); + dump_core_and_abort(TARGET_SIGILL); + return; + } + + memset(frame, 0, sizeof(*frame)); + setup_sigframe_arch(env, frame_addr, frame, 0); + + for (i = 0; i < TARGET_NSIG_WORDS; i++) { + __put_user(set->__bits[i], &frame->sf_uc.uc_sigmask.__bits[i]); + } + + if (tinfo) { + frame->sf_si.si_signo = tinfo->si_signo; + frame->sf_si.si_errno = tinfo->si_errno; + frame->sf_si.si_code = tinfo->si_code; + frame->sf_si.si_pid = tinfo->si_pid; + frame->sf_si.si_uid = tinfo->si_uid; + frame->sf_si.si_status = tinfo->si_status; + frame->sf_si.si_addr = tinfo->si_addr; + /* see host_to_target_siginfo_noswap() for more details */ + frame->sf_si.si_value.sival_ptr = tinfo->si_value.sival_ptr; + /* + * At this point, whatever is in the _reason union is complete + * and in target order, so just copy the whole thing over, even + * if it's too large for this specific signal. + * host_to_target_siginfo_noswap() and tswap_siginfo() have ensured + * that's so. + */ + memcpy(&frame->sf_si._reason, &tinfo->_reason, + sizeof(tinfo->_reason)); + } + + set_sigtramp_args(env, sig, frame, frame_addr, ka); + + unlock_user_struct(frame, frame_addr, 1); +} + void signal_init(void) { TaskState *ts = (TaskState *)thread_cpu->opaque; From patchwork Mon Jan 31 19:56:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 12731133 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1C4F8C433EF for ; Mon, 31 Jan 2022 20:42:33 +0000 (UTC) Received: from localhost ([::1]:35836 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nEdVQ-0000CM-43 for qemu-devel@archiver.kernel.org; Mon, 31 Jan 2022 15:42:32 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43180) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nEcni-00053B-S7 for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:23 -0500 Received: from [2607:f8b0:4864:20::132] (port=33308 helo=mail-il1-x132.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nEcnb-0002fo-Nr for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:22 -0500 Received: by mail-il1-x132.google.com with SMTP id o10so12441017ilh.0 for ; Mon, 31 Jan 2022 11:57:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LXHWOyKgi1YLQ++jL8z64ESafHKvZ4x5SjsBEBXqU1c=; b=e7Z3KDpzHW161AvBJWpv38GelPaY2aMal1gZt1xpi2FxN8UD3A9YOW8uUx2t4geFKa RFY3ksO0q82ug9QZ2GJ6U4OhZrHZZSST713BaZikOsjJ4Uh0qx1gYyY4/hjPyfZMSI+D g0DQddFBFgoZhIeZ8r2RfUJNGa3oyocF82bBlyN2zwl4ZIMRLyFR+A+Q7DhpSCJmgGQU NLox1JQ870qXi5ixxOzcM1IW7qpSVrZjaEwze1lNHsmPjq53ObbIJvAUi9angBqaa/3w yDqeKOZpQ+LsYqQz4yC7Lqi3aUI6dffw/a7tvGwXANI9opZxFKP5+S4w7CsaUVlTEHsy oTpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LXHWOyKgi1YLQ++jL8z64ESafHKvZ4x5SjsBEBXqU1c=; b=75ATJps1i+ZgRPHtCn8XTeFuNSJlUBgUpd0A3FGNmsytzogxrZrFG4v9EwVnaMU82V yxInq1jmgnb0RHCB5zk/8QMClFSNG7T/VpvEL9MfARs288OKsCARAhrB+hXfMecdBEun NZia7dWQCTx54/Cr1Pws5a3FWFV/Mrl/bxsREvebY3yebs76ndRTw1r02u2gviCnV/Ni g74ww9iOPtH039TTRAsOeUHIlzkznrbuMcfmPdQ+uERnGjbrhE86TjgdyuZ7Pnsz7xrk K4GHkSYxDPf4zWD7SpHSrE425OD8Zp42qLoOd2gR9I+iSH/7i+Y24B8ybQjs8mDHyz9/ +0Og== X-Gm-Message-State: AOAM530JvFc/Eh2EdvseuhBWfPCXu83Pk0WEDWnHE4Pki682QBWddNYi yjHwg9gfo8J4kPaf7/IE2bCb47dQJUyckw== X-Google-Smtp-Source: ABdhPJwt1u+mDTxnxnJBB8kg88QO3MGQIBRLrM43YZUIv3AECAH3gCozvvZxhB8ZuJNxY316MzuHPQ== X-Received: by 2002:a05:6e02:20cd:: with SMTP id 13mr12941422ilq.225.1643659022745; Mon, 31 Jan 2022 11:57:02 -0800 (PST) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id j2sm1972989ilu.82.2022.01.31.11.57.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jan 2022 11:57:02 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PULL 32/40] bsd-user/signal.c: handle_pending_signal Date: Mon, 31 Jan 2022 12:56:28 -0700 Message-Id: <20220131195636.31991-33-imp@bsdimp.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220131195636.31991-1-imp@bsdimp.com> References: <20220131195636.31991-1-imp@bsdimp.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::132 (failed) Received-SPF: none client-ip=2607:f8b0:4864:20::132; envelope-from=imp@bsdimp.com; helo=mail-il1-x132.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Stacey Son , Kyle Evans , Richard Henderson , def@FreeBSD.org, jrtc27@FreeBSD.org, Warner Losh Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Handle a queued signal. Signed-off-by: Stacey Son Signed-off-by: Kyle Evans Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/qemu.h | 7 ++++ bsd-user/signal.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index de20650a00d..02921ac8b3b 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -99,6 +99,8 @@ typedef struct TaskState { * from multiple threads.) */ int signal_pending; + /* True if we're leaving a sigsuspend and sigsuspend_mask is valid. */ + bool in_sigsuspend; /* * This thread's signal mask, as requested by the guest program. * The actual signal mask of this thread may differ: @@ -106,6 +108,11 @@ typedef struct TaskState { * + sometimes we block all signals to avoid races */ sigset_t signal_mask; + /* + * The signal mask imposed by a guest sigsuspend syscall, if we are + * currently in the middle of such a syscall + */ + sigset_t sigsuspend_mask; /* This thread's sigaltstack, if it has one */ struct target_sigaltstack sigaltstack_used; diff --git a/bsd-user/signal.c b/bsd-user/signal.c index dbc13736073..366e047cccc 100644 --- a/bsd-user/signal.c +++ b/bsd-user/signal.c @@ -616,6 +616,93 @@ void signal_init(void) } } +static void handle_pending_signal(CPUArchState *env, int sig, + struct emulated_sigtable *k) +{ + CPUState *cpu = env_cpu(env); + TaskState *ts = cpu->opaque; + struct target_sigaction *sa; + int code; + sigset_t set; + abi_ulong handler; + target_siginfo_t tinfo; + target_sigset_t target_old_set; + + trace_user_handle_signal(env, sig); + + k->pending = 0; + + sig = gdb_handlesig(cpu, sig); + if (!sig) { + sa = NULL; + handler = TARGET_SIG_IGN; + } else { + sa = &sigact_table[sig - 1]; + handler = sa->_sa_handler; + } + + if (do_strace) { + print_taken_signal(sig, &k->info); + } + + if (handler == TARGET_SIG_DFL) { + /* + * default handler : ignore some signal. The other are job + * control or fatal. + */ + if (sig == TARGET_SIGTSTP || sig == TARGET_SIGTTIN || + sig == TARGET_SIGTTOU) { + kill(getpid(), SIGSTOP); + } else if (sig != TARGET_SIGCHLD && sig != TARGET_SIGURG && + sig != TARGET_SIGINFO && sig != TARGET_SIGWINCH && + sig != TARGET_SIGCONT) { + dump_core_and_abort(sig); + } + } else if (handler == TARGET_SIG_IGN) { + /* ignore sig */ + } else if (handler == TARGET_SIG_ERR) { + dump_core_and_abort(sig); + } else { + /* compute the blocked signals during the handler execution */ + sigset_t *blocked_set; + + target_to_host_sigset(&set, &sa->sa_mask); + /* + * SA_NODEFER indicates that the current signal should not be + * blocked during the handler. + */ + if (!(sa->sa_flags & TARGET_SA_NODEFER)) { + sigaddset(&set, target_to_host_signal(sig)); + } + + /* + * Save the previous blocked signal state to restore it at the + * end of the signal execution (see do_sigreturn). + */ + host_to_target_sigset_internal(&target_old_set, &ts->signal_mask); + + blocked_set = ts->in_sigsuspend ? + &ts->sigsuspend_mask : &ts->signal_mask; + sigorset(&ts->signal_mask, blocked_set, &set); + ts->in_sigsuspend = false; + sigprocmask(SIG_SETMASK, &ts->signal_mask, NULL); + + /* XXX VM86 on x86 ??? */ + + code = k->info.si_code; /* From host, so no si_type */ + /* prepare the stack frame of the virtual CPU */ + if (sa->sa_flags & TARGET_SA_SIGINFO) { + tswap_siginfo(&tinfo, &k->info); + setup_frame(sig, code, sa, &target_old_set, &tinfo, env); + } else { + setup_frame(sig, code, sa, &target_old_set, NULL, env); + } + if (sa->sa_flags & TARGET_SA_RESETHAND) { + sa->_sa_handler = TARGET_SIG_DFL; + } + } +} + void process_pending_signals(CPUArchState *cpu_env) { } From patchwork Mon Jan 31 19:56:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 12731131 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 72E42C433F5 for ; Mon, 31 Jan 2022 20:42:14 +0000 (UTC) Received: from localhost ([::1]:34472 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nEdV7-0007ho-6h for qemu-devel@archiver.kernel.org; Mon, 31 Jan 2022 15:42:13 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43222) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nEcnj-00053h-TI for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:25 -0500 Received: from [2607:f8b0:4864:20::d2d] (port=38805 helo=mail-io1-xd2d.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nEcnb-0002fs-O7 for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:23 -0500 Received: by mail-io1-xd2d.google.com with SMTP id w7so18427240ioj.5 for ; Mon, 31 Jan 2022 11:57:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=r5D/XxRSLmmsB5rAEeVEsKXhTzCrfhyXP8EzMrhJHxQ=; b=VS7zOHLD5xKHelvh4Yc4YzIcLjD2iCzTWU1DQB5H1lgiv+g/WmRsiikr4ECwEVBj/J MbAT3Gh743EnOdRNa0CRM5cTFdIgiAmuHZnYofa/7phiQygNurF6wSJgXX05KlapVICx 1vfAslZ8QTey4IGffietANscoX56YwCCWp18+0q114akDvj4RBT71eNWM1/iq4ACe/Q8 Uqy3Hp3Ymn/rNNc/Uf+WUlHnadt8da+UCm4WWg7IrqBChMixcqdubu3yfGOMiSKAzGBq o9aOrf3jN9yTJ09RWv8bjdxPdfmMWTpcUpIwYZTkpmmXiyJeOrmwomfI5YEPbwUXFSbs rREA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=r5D/XxRSLmmsB5rAEeVEsKXhTzCrfhyXP8EzMrhJHxQ=; b=lruOAq/E2NM7UKr0/hVgfZFMRduoi9J7griXI1q2XsRyFGQVjFH8p7Qm9h0eOAvkfb 1RgBCgg0zrG6EK4urOf4wY/NX4Fhsjk/FDTkQ5WPj1bGmSVIW6ZupjbXsMyTqJ+CILCF Q/jQ+zSxPcBZ3LCWPckoDuhfIxhBAWoYe6nn0QVQ89stUvkwsVlITJWKAlmUN3K3eAQY RMriyRQFKSgNb8zdxWxYIYVpKrhI/DvJDjSsDhitenZ8Qaa1bUB32a1s30cdu4LWbYu2 iXN0s72amhK/xB2wFXAcOS3E9S06Qfnf0rfHGUPKnRl9PO5sRRTR44eL1ZzsUoxTMlGQ fEWw== X-Gm-Message-State: AOAM532TdX+LPdlbHmTqKlF1FQAg/XdiEQpq2o1NT3rPmqba3n8IPl5R LwnDAmMmoouLSHzlfwV2/jlqQsbIOp5vvw== X-Google-Smtp-Source: ABdhPJzHaY0h5y+du0Ki/IG1kF92I0XQx9+AENqXlVo5eKb7RbXu0F9w4fbq/4Pt5Fo44NQZV0TGaQ== X-Received: by 2002:a05:6638:38a0:: with SMTP id b32mr10157240jav.228.1643659023766; Mon, 31 Jan 2022 11:57:03 -0800 (PST) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id j2sm1972989ilu.82.2022.01.31.11.57.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jan 2022 11:57:03 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PULL 33/40] bsd-user/signal.c: tswap_siginfo Date: Mon, 31 Jan 2022 12:56:29 -0700 Message-Id: <20220131195636.31991-34-imp@bsdimp.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220131195636.31991-1-imp@bsdimp.com> References: <20220131195636.31991-1-imp@bsdimp.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::d2d (failed) Received-SPF: none client-ip=2607:f8b0:4864:20::d2d; envelope-from=imp@bsdimp.com; helo=mail-io1-xd2d.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Stacey Son , Kyle Evans , Richard Henderson , def@FreeBSD.org, jrtc27@FreeBSD.org, Warner Losh Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Convert siginfo from targer to host. Signed-off-by: Stacey Son Signed-off-by: Kyle Evans Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/signal.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/bsd-user/signal.c b/bsd-user/signal.c index 366e047cccc..34e8c811ad6 100644 --- a/bsd-user/signal.c +++ b/bsd-user/signal.c @@ -256,6 +256,59 @@ static inline void host_to_target_siginfo_noswap(target_siginfo_t *tinfo, tinfo->si_code = deposit32(si_code, 24, 8, si_type); } +static void tswap_siginfo(target_siginfo_t *tinfo, const target_siginfo_t *info) +{ + int si_type = extract32(info->si_code, 24, 8); + int si_code = sextract32(info->si_code, 0, 24); + + __put_user(info->si_signo, &tinfo->si_signo); + __put_user(info->si_errno, &tinfo->si_errno); + __put_user(si_code, &tinfo->si_code); /* Zero out si_type, it's internal */ + __put_user(info->si_pid, &tinfo->si_pid); + __put_user(info->si_uid, &tinfo->si_uid); + __put_user(info->si_status, &tinfo->si_status); + __put_user(info->si_addr, &tinfo->si_addr); + /* + * Unswapped, because we passed it through mostly untouched. si_value is + * opaque to the kernel, so we didn't bother with potentially wasting cycles + * to swap it into host byte order. + */ + tinfo->si_value.sival_ptr = info->si_value.sival_ptr; + + /* + * We can use our internal marker of which fields in the structure + * are valid, rather than duplicating the guesswork of + * host_to_target_siginfo_noswap() here. + */ + switch (si_type) { + case QEMU_SI_NOINFO: /* No additional info */ + break; + case QEMU_SI_FAULT: + __put_user(info->_reason._fault._trapno, + &tinfo->_reason._fault._trapno); + break; + case QEMU_SI_TIMER: + __put_user(info->_reason._timer._timerid, + &tinfo->_reason._timer._timerid); + __put_user(info->_reason._timer._overrun, + &tinfo->_reason._timer._overrun); + break; + case QEMU_SI_MESGQ: + __put_user(info->_reason._mesgq._mqd, &tinfo->_reason._mesgq._mqd); + break; + case QEMU_SI_POLL: + /* Note: Not generated on FreeBSD */ + __put_user(info->_reason._poll._band, &tinfo->_reason._poll._band); + break; + case QEMU_SI_CAPSICUM: + __put_user(info->_reason._capsicum._syscall, + &tinfo->_reason._capsicum._syscall); + break; + default: + g_assert_not_reached(); + } +} + /* Returns 1 if given signal should dump core if not handled. */ static int core_dump_signal(int sig) { From patchwork Mon Jan 31 19:56:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 12731139 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 393ACC433EF for ; Mon, 31 Jan 2022 20:51:57 +0000 (UTC) Received: from localhost ([::1]:56218 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nEdeW-00054r-4X for qemu-devel@archiver.kernel.org; Mon, 31 Jan 2022 15:51:56 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43046) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nEcng-0004xT-5U for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:20 -0500 Received: from [2607:f8b0:4864:20::d34] (port=39860 helo=mail-io1-xd34.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nEcnb-0002g0-Hf for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:19 -0500 Received: by mail-io1-xd34.google.com with SMTP id c188so18404288iof.6 for ; Mon, 31 Jan 2022 11:57:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yFznSEKSLa4wr4LT6m629JqoMGJyil+XeLDgIrumdQM=; b=UbOVK6+q8y5HMod4jvFX0eXD83YN1oQA8rQdJMXfc1bhcdEFb8/WrNZmZdgy6txIW9 BxcAg8ufgc3J+V6zVpa77xl6LVPVFLkO7rKi3Sird2sdH5aVDhXgPcefAorQO3AR0DiE 6h2TZqmtTd05X1J/64a94pxJBOsbK/bqJG+WUWMAeJrwiXbQ9xc2ed/6ioPmhnWP/t8R 5EZDaNIieKxs12p3iVvcsbwym7DH1Nbd2R6CMAKeZxOFirDNDJvcIWbaeaSyZyEWfIS8 VK83I3oHlBQ+6YKiuPwhzKlWF1aTOKDFiVPid8Yl4/8d8DTkMtajBoztoaA/xP592yki mVWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yFznSEKSLa4wr4LT6m629JqoMGJyil+XeLDgIrumdQM=; b=7LENEb1e43Pycba9FufACJLtrp7nGYdoewHmgtqciUa5VKcUsCFpMLT02THsZWcKrS Re5Zouv6lWltKofdO/dccL5AFwwklBheL6WhK/Mm+hXoIqGs70Pa6y8dY6RA0BYk4gC9 0S+PJV8/hBio4kWUQKeus69TioV5LOEFFZDTli5Daf2rSZ9FAGOVcVYxsd9kamAtEeYS RfOL3KIgd4fS3dHJZFb/rCyOMbEgU7CFIJVDE+xgfvm1TcCgEzNt/RHwV+dYFqVba7Zx RIuIm4uO2elnhcx6vQDFw3iusEC8/a+mjjnR+S/JYXch4xiiHxr2qgoW/rq31PWO6E0g UN9w== X-Gm-Message-State: AOAM53247IWZjw4zk0WhSiqEx74/ps8PpRFLySXcExGiS1iO2gEM6Ipn rNlZ5Fk1qyuAHRMtK5sh6HXyX8ezaJm79g== X-Google-Smtp-Source: ABdhPJw+lO5ryTJS5ySw4nqeeI2EW0ziKWe5q6gu1atKWc2bLrz41WXyBfRdeVafUXTHAXKFIySjOw== X-Received: by 2002:a02:a602:: with SMTP id c2mr4602171jam.220.1643659024973; Mon, 31 Jan 2022 11:57:04 -0800 (PST) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id j2sm1972989ilu.82.2022.01.31.11.57.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jan 2022 11:57:04 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PULL 34/40] bsd-user/signal.c: process_pending_signals Date: Mon, 31 Jan 2022 12:56:30 -0700 Message-Id: <20220131195636.31991-35-imp@bsdimp.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220131195636.31991-1-imp@bsdimp.com> References: <20220131195636.31991-1-imp@bsdimp.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::d34 (failed) Received-SPF: none client-ip=2607:f8b0:4864:20::d34; envelope-from=imp@bsdimp.com; helo=mail-io1-xd34.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Stacey Son , Kyle Evans , Richard Henderson , def@FreeBSD.org, jrtc27@FreeBSD.org, Warner Losh Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Process the currently queued signals. Signed-off-by: Stacey Son Signed-off-by: Kyle Evans Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/signal.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/bsd-user/signal.c b/bsd-user/signal.c index 34e8c811ad6..4b398745f45 100644 --- a/bsd-user/signal.c +++ b/bsd-user/signal.c @@ -756,8 +756,62 @@ static void handle_pending_signal(CPUArchState *env, int sig, } } -void process_pending_signals(CPUArchState *cpu_env) +void process_pending_signals(CPUArchState *env) { + CPUState *cpu = env_cpu(env); + int sig; + sigset_t *blocked_set, set; + struct emulated_sigtable *k; + TaskState *ts = cpu->opaque; + + while (qatomic_read(&ts->signal_pending)) { + sigfillset(&set); + sigprocmask(SIG_SETMASK, &set, 0); + + restart_scan: + sig = ts->sync_signal.pending; + if (sig) { + /* + * Synchronous signals are forced by the emulated CPU in some way. + * If they are set to ignore, restore the default handler (see + * sys/kern_sig.c trapsignal() and execsigs() for this behavior) + * though maybe this is done only when forcing exit for non SIGCHLD. + */ + if (sigismember(&ts->signal_mask, target_to_host_signal(sig)) || + sigact_table[sig - 1]._sa_handler == TARGET_SIG_IGN) { + sigdelset(&ts->signal_mask, target_to_host_signal(sig)); + sigact_table[sig - 1]._sa_handler = TARGET_SIG_DFL; + } + handle_pending_signal(env, sig, &ts->sync_signal); + } + + k = ts->sigtab; + for (sig = 1; sig <= TARGET_NSIG; sig++, k++) { + blocked_set = ts->in_sigsuspend ? + &ts->sigsuspend_mask : &ts->signal_mask; + if (k->pending && + !sigismember(blocked_set, target_to_host_signal(sig))) { + handle_pending_signal(env, sig, k); + /* + * Restart scan from the beginning, as handle_pending_signal + * might have resulted in a new synchronous signal (eg SIGSEGV). + */ + goto restart_scan; + } + } + + /* + * Unblock signals and check one more time. Unblocking signals may cause + * us to take another host signal, which will set signal_pending again. + */ + qatomic_set(&ts->signal_pending, 0); + ts->in_sigsuspend = false; + set = ts->signal_mask; + sigdelset(&set, SIGSEGV); + sigdelset(&set, SIGBUS); + sigprocmask(SIG_SETMASK, &set, 0); + } + ts->in_sigsuspend = false; } void cpu_loop_exit_sigsegv(CPUState *cpu, target_ulong addr, From patchwork Mon Jan 31 19:56:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 12731103 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 260B5C433F5 for ; Mon, 31 Jan 2022 20:24:34 +0000 (UTC) Received: from localhost ([::1]:56674 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nEdE1-0000e9-8I for qemu-devel@archiver.kernel.org; Mon, 31 Jan 2022 15:24:33 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43034) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nEcnf-0004xN-Tk for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:20 -0500 Received: from [2607:f8b0:4864:20::d36] (port=43996 helo=mail-io1-xd36.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nEcnb-0002g6-Gc for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:19 -0500 Received: by mail-io1-xd36.google.com with SMTP id z199so18396154iof.10 for ; Mon, 31 Jan 2022 11:57:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sL+j8/qMLIuHq5OnGr0sHnHdREY1Bcj+mIcecdeQ4BA=; b=Le2lBG1imaMOlTuR+qViUyb+VKQjzAdjCxdDgkWQa8t75c7WiDFbBrCO/TqXoGVZOT fhiN32RTrIgLWckwhxYRZxSX3uqJYLuPp/YARAtE3jejMYD1pAkEBLAdwSelZMQS7g0M yRZLEnQsH7b6i26xCXxEfnEFV1CTEWyhiB+1zE3MFBlu7jNHsgECNaV1Go3CxFuaKbWm bFdHF3do1cBiNqFj4EQwd5Jd38PT1m6y5B5Jj600nfVLcgd/VhLXUGSdH/dwV/Ib/fcS YTjDAYGdfl1rAA2iNel6M+eS6kYsc3otsBvdAAMQDNapdGipz2Emve2Tpe2vJeXdPMjZ y5Qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sL+j8/qMLIuHq5OnGr0sHnHdREY1Bcj+mIcecdeQ4BA=; b=1BQoNC/nBviEnIPIA+kus4Q8TrQ5NWfeFBiUbUYRnsXnnMQfWD1nbPfn+xsUadSHga wzsyRF32sXZgRrfiQwBQkjLSqkX85qPSpwx+YGR9xON+eWzlOpJAqvmH17tDLwEez7ro UqnlKXNIpizA2C3CtsgR8E91EjQtLRUp/ouFFUaPoCWOgZndJ/vqCzchmkBah0qudDfR vG1fole4Vy7TvC8hM58lbjQwYoEnBCgR167MeBwZY5GkDclsKVYAAHpmxqp2bxzneWqz 4lkh0nqfdgzVW/dWR4m74cJ0t+jjzLWZkQehbC3rkv91rVBLcH1QlI1m5y06Px9kjhNg vLKw== X-Gm-Message-State: AOAM533XFXEh6jacqH18oCgKM3UZz3/sQChYsXVfQOewWNTUXIxqc0yF 50zKBTqHt9Sht5OG+s2jggztF7ls+vu27g== X-Google-Smtp-Source: ABdhPJxR1AOshpL+V70GZE6wP8TOEwv1vfhCbgAlbnfuaU6m3XMpaTJNJrbGapB6/ilkA15xlxUKrA== X-Received: by 2002:a02:6988:: with SMTP id e130mr11298152jac.120.1643659026112; Mon, 31 Jan 2022 11:57:06 -0800 (PST) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id j2sm1972989ilu.82.2022.01.31.11.57.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jan 2022 11:57:05 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PULL 35/40] bsd-user/signal.c: implement do_sigreturn Date: Mon, 31 Jan 2022 12:56:31 -0700 Message-Id: <20220131195636.31991-36-imp@bsdimp.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220131195636.31991-1-imp@bsdimp.com> References: <20220131195636.31991-1-imp@bsdimp.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::d36 (failed) Received-SPF: none client-ip=2607:f8b0:4864:20::d36; envelope-from=imp@bsdimp.com; helo=mail-io1-xd36.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Stacey Son , Kyle Evans , Richard Henderson , def@FreeBSD.org, jrtc27@FreeBSD.org, Warner Losh Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Implements the meat of a sigreturn(2) system call via do_sigreturn, and helper reset_signal_mask. Fix the prototype of do_sigreturn in qemu.h and remove do_rt_sigreturn since it's linux only. Signed-off-by: Stacey Son Signed-off-by: Kyle Evans Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/signal-common.h | 2 +- bsd-user/signal.c | 56 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/bsd-user/signal-common.h b/bsd-user/signal-common.h index ee819266f54..786ec592d18 100644 --- a/bsd-user/signal-common.h +++ b/bsd-user/signal-common.h @@ -11,7 +11,7 @@ long do_rt_sigreturn(CPUArchState *env); abi_long do_sigaltstack(abi_ulong uss_addr, abi_ulong uoss_addr, abi_ulong sp); -long do_sigreturn(CPUArchState *env); +long do_sigreturn(CPUArchState *env, abi_ulong addr); void force_sig_fault(int sig, int code, abi_ulong addr); int host_to_target_signal(int sig); void host_to_target_sigset(target_sigset_t *d, const sigset_t *s); diff --git a/bsd-user/signal.c b/bsd-user/signal.c index 4b398745f45..150262a87e5 100644 --- a/bsd-user/signal.c +++ b/bsd-user/signal.c @@ -627,6 +627,62 @@ static void setup_frame(int sig, int code, struct target_sigaction *ka, unlock_user_struct(frame, frame_addr, 1); } +static int reset_signal_mask(target_ucontext_t *ucontext) +{ + int i; + sigset_t blocked; + target_sigset_t target_set; + TaskState *ts = (TaskState *)thread_cpu->opaque; + + for (i = 0; i < TARGET_NSIG_WORDS; i++) { + if (__get_user(target_set.__bits[i], + &ucontext->uc_sigmask.__bits[i])) { + return -TARGET_EFAULT; + } + } + target_to_host_sigset_internal(&blocked, &target_set); + ts->signal_mask = blocked; + + return 0; +} + +/* See sys/$M/$M/exec_machdep.c sigreturn() */ +long do_sigreturn(CPUArchState *env, abi_ulong addr) +{ + long ret; + abi_ulong target_ucontext; + target_ucontext_t *ucontext = NULL; + + /* Get the target ucontext address from the stack frame */ + ret = get_ucontext_sigreturn(env, addr, &target_ucontext); + if (is_error(ret)) { + return ret; + } + trace_user_do_sigreturn(env, addr); + if (!lock_user_struct(VERIFY_READ, ucontext, target_ucontext, 0)) { + goto badframe; + } + + /* Set the register state back to before the signal. */ + if (set_mcontext(env, &ucontext->uc_mcontext, 1)) { + goto badframe; + } + + /* And reset the signal mask. */ + if (reset_signal_mask(ucontext)) { + goto badframe; + } + + unlock_user_struct(ucontext, target_ucontext, 0); + return -TARGET_EJUSTRETURN; + +badframe: + if (ucontext != NULL) { + unlock_user_struct(ucontext, target_ucontext, 0); + } + return -TARGET_EFAULT; +} + void signal_init(void) { TaskState *ts = (TaskState *)thread_cpu->opaque; From patchwork Mon Jan 31 19:56:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 12731120 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D47F5C433F5 for ; Mon, 31 Jan 2022 20:34:47 +0000 (UTC) Received: from localhost ([::1]:44854 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nEdNu-0003oR-81 for qemu-devel@archiver.kernel.org; Mon, 31 Jan 2022 15:34:46 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42924) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nEcnd-0004sy-Mq for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:18 -0500 Received: from [2607:f8b0:4864:20::d2a] (port=39851 helo=mail-io1-xd2a.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nEcnb-0002gA-6Q for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:17 -0500 Received: by mail-io1-xd2a.google.com with SMTP id c188so18404416iof.6 for ; Mon, 31 Jan 2022 11:57:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=R3pj83Xth48GR9Dv5oQfOEFsuSaIVC2VMfTQGHp+Fyg=; b=4EAZTKrOPmE3eG+TXI6Og3EhKBi0+RarjsoWcm73JZue8/sRYZddppvJVPy8toZLc5 pqZttk4Q63iUVf1dKg/CtWIPoLDhjzzxZf8+Hxq7D4E3yGr56PgNbrfdfgma6q9kY/2J BprKUzQ98vHmhEbxoq4fh1tNQGohRlWCljTu2yXjDIR4Hg8FqRuVkr1oCpKc3B3MAjgx Cs+9vsSnrZsaNd7dW4RHFPQIWb0R7MzFM+Q1KyjabIgrRrZitSVuV2rj6vpEwFB1CpU4 S03S4ereR0L8AcV6VRlfWbU29J1ql5aOpePgWoQFZzNA/wlbM7XuyWtov1cx1tDyJ2L9 a3kQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=R3pj83Xth48GR9Dv5oQfOEFsuSaIVC2VMfTQGHp+Fyg=; b=MHtCC1jQ76X/UeBPDRzxPjDsCowYDLddY4vllQhG1OOt6l6cAp9gTyK6G1s5VQ1T4g svnyvqHk9Ov9WI7Ps/8B3rnPetBJ6qsk6S4ARHJYjbn+RHzFPkKzfoTeIk9Ka9S1Cx8Y NdkrUFBCFPT3rqzhwORMoaxdE1ArBoczBfcZ8NCxuOC8CzQEEg1oyJkMz2TqMjyOCCpv re1KLwzwh6VNaGVVfbZY41rCZbgPCX9VijZg4B9dqzUxbQ4M6+DqFtnEhp6Hbs0E381t JbP4+44nF4/Ek2qC4YlUMh3N9WpCvNlIyrNgsHt9FtEXyCR+fRXIJwIkx1kYgmCGdQD3 nXfQ== X-Gm-Message-State: AOAM530U9/2hi52GmIRpMUekhD7Tf08aYzOnBvA15vP1WwfZk2haLzsl W4vbUKSI73scVX3trXX56g4XX+yaUjAK0w== X-Google-Smtp-Source: ABdhPJy5yCgyiBJ1PDqJwPiIuzhcguMJtbG3MR0dFy3N8lwDsW82jKESItciEFnK6RNhgYPDr8WrTA== X-Received: by 2002:a02:9687:: with SMTP id w7mr2373858jai.316.1643659026936; Mon, 31 Jan 2022 11:57:06 -0800 (PST) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id j2sm1972989ilu.82.2022.01.31.11.57.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jan 2022 11:57:06 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PULL 36/40] bsd-user/signal.c: implement do_sigaction Date: Mon, 31 Jan 2022 12:56:32 -0700 Message-Id: <20220131195636.31991-37-imp@bsdimp.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220131195636.31991-1-imp@bsdimp.com> References: <20220131195636.31991-1-imp@bsdimp.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::d2a (failed) Received-SPF: none client-ip=2607:f8b0:4864:20::d2a; envelope-from=imp@bsdimp.com; helo=mail-io1-xd2a.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Stacey Son , Kyle Evans , Richard Henderson , def@FreeBSD.org, jrtc27@FreeBSD.org, Warner Losh Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Implement the meat of the sigaction(2) system call with do_sigaction and helper routiner block_signals (which is also used to implemement signal masking so it's global). Signed-off-by: Stacey Son Signed-off-by: Kyle Evans Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/signal-common.h | 22 +++++++++++ bsd-user/signal.c | 82 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+) diff --git a/bsd-user/signal-common.h b/bsd-user/signal-common.h index 786ec592d18..7ff8e8f2e40 100644 --- a/bsd-user/signal-common.h +++ b/bsd-user/signal-common.h @@ -9,7 +9,29 @@ #ifndef SIGNAL_COMMON_H #define SIGNAL_COMMON_H +/** + * block_signals: block all signals while handling this guest syscall + * + * Block all signals, and arrange that the signal mask is returned to + * its correct value for the guest before we resume execution of guest code. + * If this function returns non-zero, then the caller should immediately + * return -TARGET_ERESTARTSYS to the main loop, which will take the pending + * signal and restart execution of the syscall. + * If block_signals() returns zero, then the caller can continue with + * emulation of the system call knowing that no signals can be taken + * (and therefore that no race conditions will result). + * This should only be called once, because if it is called a second time + * it will always return non-zero. (Think of it like a mutex that can't + * be recursively locked.) + * Signals will be unblocked again by process_pending_signals(). + * + * Return value: non-zero if there was a pending signal, zero if not. + */ +int block_signals(void); /* Returns non zero if signal pending */ + long do_rt_sigreturn(CPUArchState *env); +int do_sigaction(int sig, const struct target_sigaction *act, + struct target_sigaction *oact); abi_long do_sigaltstack(abi_ulong uss_addr, abi_ulong uoss_addr, abi_ulong sp); long do_sigreturn(CPUArchState *env, abi_ulong addr); void force_sig_fault(int sig, int code, abi_ulong addr); diff --git a/bsd-user/signal.c b/bsd-user/signal.c index 150262a87e5..5c94bd02e38 100644 --- a/bsd-user/signal.c +++ b/bsd-user/signal.c @@ -309,6 +309,25 @@ static void tswap_siginfo(target_siginfo_t *tinfo, const target_siginfo_t *info) } } +int block_signals(void) +{ + TaskState *ts = (TaskState *)thread_cpu->opaque; + sigset_t set; + + /* + * It's OK to block everything including SIGSEGV, because we won't run any + * further guest code before unblocking signals in + * process_pending_signals(). We depend on the FreeBSD behaivor here where + * this will only affect this thread's signal mask. We don't use + * pthread_sigmask which might seem more correct because that routine also + * does odd things with SIGCANCEL to implement pthread_cancel(). + */ + sigfillset(&set); + sigprocmask(SIG_SETMASK, &set, 0); + + return qatomic_xchg(&ts->signal_pending, 1); +} + /* Returns 1 if given signal should dump core if not handled. */ static int core_dump_signal(int sig) { @@ -554,6 +573,69 @@ static void host_signal_handler(int host_sig, siginfo_t *info, void *puc) cpu_exit(thread_cpu); } +/* do_sigaction() return host values and errnos */ +int do_sigaction(int sig, const struct target_sigaction *act, + struct target_sigaction *oact) +{ + struct target_sigaction *k; + struct sigaction act1; + int host_sig; + int ret = 0; + + if (sig < 1 || sig > TARGET_NSIG) { + return -TARGET_EINVAL; + } + + if ((sig == TARGET_SIGKILL || sig == TARGET_SIGSTOP) && + act != NULL && act->_sa_handler != TARGET_SIG_DFL) { + return -TARGET_EINVAL; + } + + if (block_signals()) { + return -TARGET_ERESTART; + } + + k = &sigact_table[sig - 1]; + if (oact) { + oact->_sa_handler = tswapal(k->_sa_handler); + oact->sa_flags = tswap32(k->sa_flags); + oact->sa_mask = k->sa_mask; + } + if (act) { + k->_sa_handler = tswapal(act->_sa_handler); + k->sa_flags = tswap32(act->sa_flags); + k->sa_mask = act->sa_mask; + + /* Update the host signal state. */ + host_sig = target_to_host_signal(sig); + if (host_sig != SIGSEGV && host_sig != SIGBUS) { + memset(&act1, 0, sizeof(struct sigaction)); + sigfillset(&act1.sa_mask); + act1.sa_flags = SA_SIGINFO; + if (k->sa_flags & TARGET_SA_RESTART) { + act1.sa_flags |= SA_RESTART; + } + /* + * Note: It is important to update the host kernel signal mask to + * avoid getting unexpected interrupted system calls. + */ + if (k->_sa_handler == TARGET_SIG_IGN) { + act1.sa_sigaction = (void *)SIG_IGN; + } else if (k->_sa_handler == TARGET_SIG_DFL) { + if (fatal_signal(sig)) { + act1.sa_sigaction = host_signal_handler; + } else { + act1.sa_sigaction = (void *)SIG_DFL; + } + } else { + act1.sa_sigaction = host_signal_handler; + } + ret = sigaction(host_sig, &act1, NULL); + } + } + return ret; +} + static inline abi_ulong get_sigframe(struct target_sigaction *ka, CPUArchState *env, size_t frame_size) { From patchwork Mon Jan 31 19:56:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 12731095 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 32F5AC433F5 for ; Mon, 31 Jan 2022 20:19:00 +0000 (UTC) Received: from localhost ([::1]:39866 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nEd8c-0005vB-TU for qemu-devel@archiver.kernel.org; Mon, 31 Jan 2022 15:18:59 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42968) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nEcne-0004uy-KU for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:19 -0500 Received: from [2607:f8b0:4864:20::d34] (port=34545 helo=mail-io1-xd34.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nEcnb-0002gE-9X for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:18 -0500 Received: by mail-io1-xd34.google.com with SMTP id i62so18434679ioa.1 for ; Mon, 31 Jan 2022 11:57:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=L53wLRKkzhSwZeg5kGDXA2T9I89c4pRBaMotKhUPWks=; b=gpeuxAvy2cEXfh8/CZTPQnr+kklDg9Modgmh7soEjYHxoMuXx2EDwsdJGCPM21Jd8y LTT7mat0psrTFmVAxIDtOtOxm8/2ERBgKYHIltO/KuAkyGuOhPTBpyFIX0Pypmj/ycKL qMy7AC8O9cg5jcCgTspl+ffmkT9ZYg7IkSYa0IbQyrcciP1f6lZrdSNPWsyR4O3Q0lXx Dr1FhYFEZkOtWqCk2yRcFZs3CBY2FDEfFxSvb/UPUJH2Z7HqxSRmJrFYjRsSBfwuxeNC iB3iRDCJf5OrrCWF70hmzSZSJvR0bVbL8rS8JuqHmfnq2Zt717PyDZSPMgJfTl+WzEfi 3QvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=L53wLRKkzhSwZeg5kGDXA2T9I89c4pRBaMotKhUPWks=; b=x/A9j9C+DpTjypZZyiz5mXQto5l393JkjI18yUTAaburDDej5c+ULBuK3rVSCyqw8j rbWYzkS40/3PVAL6r0vEieOtiTW8P/XqOmTFZO0HrqpPF6tGm8/6SZNrSPslc69s2AYF 8wUqfB0uj6BKD0sygfkoxfBCTznzCfdjbiOtdIBG84ncrCJ/bKFq0+z4aAAI4mOZm5iH sOs8oiZnb4vTCH8uRZJqKPdG4jXLwoNN7dnJiLW2EuskGaJFtV8hJSaZUvqRMnlcsCHM 49jZdBadmv1Nj4XlrKVMqqesrBVSNVugq7zbSxBoFEdFFsaTiaf2LvDquUroEb+PofuJ gvRQ== X-Gm-Message-State: AOAM530H6tyvGlo1JQwQIt1DvUEcsIsX3EYEkwjHhXvVmz34JBuKb8QA vYXyne8ppuCVvbSh4xVlZphx/QyOZ60WXA== X-Google-Smtp-Source: ABdhPJzQYVQmI02Vj2n+sgNXqwaPDQio2dqMKdAYKVNuM3U7+CFRZVkWN6HYeqJAbXkpbsqR/LuWtw== X-Received: by 2002:a02:29cd:: with SMTP id p196mr11947992jap.100.1643659028003; Mon, 31 Jan 2022 11:57:08 -0800 (PST) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id j2sm1972989ilu.82.2022.01.31.11.57.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jan 2022 11:57:07 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PULL 37/40] bsd-user/signal.c: do_sigaltstack Date: Mon, 31 Jan 2022 12:56:33 -0700 Message-Id: <20220131195636.31991-38-imp@bsdimp.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220131195636.31991-1-imp@bsdimp.com> References: <20220131195636.31991-1-imp@bsdimp.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::d34 (failed) Received-SPF: none client-ip=2607:f8b0:4864:20::d34; envelope-from=imp@bsdimp.com; helo=mail-io1-xd34.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Stacey Son , Kyle Evans , Richard Henderson , def@FreeBSD.org, jrtc27@FreeBSD.org, Warner Losh Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Implement the meat of the sigaltstack(2) system call with do_sigaltstack. With that, all the stubbed out routines are complete, so remove now-incorrect comment. Signed-off-by: Stacey Son Signed-off-by: Kyle Evans Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/signal.c | 72 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 67 insertions(+), 5 deletions(-) diff --git a/bsd-user/signal.c b/bsd-user/signal.c index 5c94bd02e38..ad22ba9d90d 100644 --- a/bsd-user/signal.c +++ b/bsd-user/signal.c @@ -25,11 +25,6 @@ #include "hw/core/tcg-cpu-ops.h" #include "host-signal.h" -/* - * Stubbed out routines until we merge signal support from bsd-user - * fork. - */ - static struct target_sigaction sigact_table[TARGET_NSIG]; static void host_signal_handler(int host_sig, siginfo_t *info, void *puc); static void target_to_host_sigset_internal(sigset_t *d, @@ -573,6 +568,73 @@ static void host_signal_handler(int host_sig, siginfo_t *info, void *puc) cpu_exit(thread_cpu); } +/* do_sigaltstack() returns target values and errnos. */ +/* compare to kern/kern_sig.c sys_sigaltstack() and kern_sigaltstack() */ +abi_long do_sigaltstack(abi_ulong uss_addr, abi_ulong uoss_addr, abi_ulong sp) +{ + TaskState *ts = (TaskState *)thread_cpu->opaque; + int ret; + target_stack_t oss; + + if (uoss_addr) { + /* Save current signal stack params */ + oss.ss_sp = tswapl(ts->sigaltstack_used.ss_sp); + oss.ss_size = tswapl(ts->sigaltstack_used.ss_size); + oss.ss_flags = tswapl(sas_ss_flags(ts, sp)); + } + + if (uss_addr) { + target_stack_t *uss; + target_stack_t ss; + size_t minstacksize = TARGET_MINSIGSTKSZ; + + ret = -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 = -TARGET_EPERM; + if (on_sig_stack(ts, sp)) { + goto out; + } + + ret = -TARGET_EINVAL; + if (ss.ss_flags != TARGET_SS_DISABLE + && ss.ss_flags != TARGET_SS_ONSTACK + && ss.ss_flags != 0) { + goto out; + } + + if (ss.ss_flags == TARGET_SS_DISABLE) { + ss.ss_size = 0; + ss.ss_sp = 0; + } else { + ret = -TARGET_ENOMEM; + if (ss.ss_size < minstacksize) { + goto out; + } + } + + ts->sigaltstack_used.ss_sp = ss.ss_sp; + ts->sigaltstack_used.ss_size = ss.ss_size; + } + + if (uoss_addr) { + ret = -TARGET_EFAULT; + if (copy_to_user(uoss_addr, &oss, sizeof(oss))) { + goto out; + } + } + + ret = 0; +out: + return ret; +} + /* do_sigaction() return host values and errnos */ int do_sigaction(int sig, const struct target_sigaction *act, struct target_sigaction *oact) From patchwork Mon Jan 31 19:56:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 12731134 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7ADA4C433F5 for ; Mon, 31 Jan 2022 20:44:28 +0000 (UTC) Received: from localhost ([::1]:42234 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nEdXH-0004VT-Fc for qemu-devel@archiver.kernel.org; Mon, 31 Jan 2022 15:44:27 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43104) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nEcnh-0004zq-D6 for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:21 -0500 Received: from [2607:f8b0:4864:20::131] (port=38416 helo=mail-il1-x131.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nEcnb-0002gJ-KB for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:21 -0500 Received: by mail-il1-x131.google.com with SMTP id i1so12413163ils.5 for ; Mon, 31 Jan 2022 11:57:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pumpyPycN9DoXDBuQYFrkloUl4gD+5Jdk6jBPn6GXxc=; b=j0/CiE4tcf15Nb4xd8wEQlb60L9L1J00nDwSIFGy9C+caia55BmywHaNLAmb6471CV 1D+rMkUu1RkQ5qLZTPQivl+kkPDIE8FUfePHGqBejAcXc2kd7C8ZdGyd3sMvTOVoVrDs kp6CtyeSDA/vscM8ymxXtwffkRV6JGIlPE2VogXA9p3If5sIbc7gEsaXIMrFanvclT+P ojZSPm1cr/t1umaCwjzuv69o2yDKK1f9vcHwpgdAFKS3yuylXInx0QlIx7pKP3F5w7Xd kV26W9fRZiI/n4miPiBSvdpOgt3uu+f2d96s1db/q3TC9ucIfXOu/XFRVRP00Je6nvza zqPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pumpyPycN9DoXDBuQYFrkloUl4gD+5Jdk6jBPn6GXxc=; b=XEh7X0O6TGOHs6KR5lpOWcHpaWMG6D5yjXXQMzxqlua3iprg58tLqZh5U/QEhXq3p9 TcnZVojHhan6YSo1V2TbPFsaXuCsPmX9GMWQpBRiouit0EMoNh2IJ18Gv+IUSyCt4wHj kl5k7KdmcTiOWVBHAL5nDsvm/S9n1w/vEFvFn+yC58Tov9DxYXG/jIIGbtIlQQvNXxvI x1tdUpqMuYOlxX/v3jKREJGd9jEqySnDUk0Tc1+Z1CYbq0ftu7aQzcTkfOR9Z8wb/qiw IvCMgAWYWn9hALp1/znE7n9lRgda2omhP86uLgPuhuIDeniKwnGsjXhqugWtNsBjLLmA nAmA== X-Gm-Message-State: AOAM531EziRaos+J7TEWOfeZ2ly99qWGyyPoJknlBmEeb2Sagfk7dJRI Gb/UvqTNsB1wXeUEtZPARtn7bduab4m5uQ== X-Google-Smtp-Source: ABdhPJzTLBb43fggvGuWuYlTTU2mLpNpB5wbqlwnFy18F5b79lHILcQv7loGAKwocEZ+EBUE6FgxmA== X-Received: by 2002:a92:d84c:: with SMTP id h12mr4699489ilq.168.1643659029029; Mon, 31 Jan 2022 11:57:09 -0800 (PST) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id j2sm1972989ilu.82.2022.01.31.11.57.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jan 2022 11:57:08 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PULL 38/40] MAINTAINERS: Add tests/vm/*bsd to the list to get reviews on Date: Mon, 31 Jan 2022 12:56:34 -0700 Message-Id: <20220131195636.31991-39-imp@bsdimp.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220131195636.31991-1-imp@bsdimp.com> References: <20220131195636.31991-1-imp@bsdimp.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::131 (failed) Received-SPF: none client-ip=2607:f8b0:4864:20::131; envelope-from=imp@bsdimp.com; helo=mail-il1-x131.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Kyle Evans , Richard Henderson , def@FreeBSD.org, jrtc27@FreeBSD.org, Warner Losh Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" tests/vm/*bsd (especailly tests/vm/freebsd) are adjacent to the bsd-user stuff and we're keen on keeping them working as well. Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- MAINTAINERS | 1 + 1 file changed, 1 insertion(+) diff --git a/MAINTAINERS b/MAINTAINERS index e4b3a4bcdf4..b7487f9b54b 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3181,6 +3181,7 @@ R: Kyle Evans S: Maintained F: bsd-user/ F: configs/targets/*-bsd-user.mak +F: tests/vm/*bsd T: git https://github.com/qemu-bsd-user/qemu-bsd-user bsd-user-rebase-3.1 Linux user From patchwork Mon Jan 31 19:56:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 12731100 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B2B20C433EF for ; Mon, 31 Jan 2022 20:22:56 +0000 (UTC) Received: from localhost ([::1]:49872 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nEdCR-0004UK-O2 for qemu-devel@archiver.kernel.org; Mon, 31 Jan 2022 15:22:55 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43018) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nEcnf-0004vd-F7 for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:19 -0500 Received: from [2607:f8b0:4864:20::d30] (port=36668 helo=mail-io1-xd30.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nEcnb-0002gN-Eb for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:19 -0500 Received: by mail-io1-xd30.google.com with SMTP id h7so18428264iof.3 for ; Mon, 31 Jan 2022 11:57:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cJUtiOr7bO9JD4Wqr53h0+Q8HUYGQ4WMAMmhjYNlvEg=; b=J9s/pRw9Sp+CetKctX74jNUIt2N/uz6newjRSYr/uHC1IhZhiuu9tyX/NqfQAyXpV+ 9P2KyE6Pz7Lm7yQ3LBhuwd/lj6dgNgPX+biK2WkTVnL2a1PCn1ZMINQ44v/M7NZ5/DUd MmEtQAnK0T4vV3CcDzhCa3XoAOJuBPUvh6tjLzHHLVsOV5B2/y39ixc2EvWLnHnBAG8O tYYAbygVgOcOgZ+Y4lbNza4semw3bbFUPq5+aQiVIL31z+vtB0NHYJAjBtUaacGh01oT RTccDJBCKqUzFLdQRUFBHdwZ5H8NXQChKzZI3nm1JhRCMgUENdniZhzNDzsqONU1GSmF BI1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cJUtiOr7bO9JD4Wqr53h0+Q8HUYGQ4WMAMmhjYNlvEg=; b=BrwIf2SscZWliQeZ4wkSWPewXGAG/NnTgqGN8FcPY1Jo0ZtpILxS/s41gNfR9JlfyE NpRVhZ8l26fJ0N67691w6+H/HGrfKWgBDVIVSou4CZBTYg8kjkbymMj4qvZutUXCCHCH 5MV08LMjFORer4NNIj8jXWdBjyb7qY8VTodtoktCE4hcpKXmfN+LxnKaLAQnpEbMcfO0 XGQP2FKUR/K3eRcdNagqrYQfKuK/UEegIPXgvz9sB6RLxIvJUFZslc+sYMkfmxIxgi6W LW69FMzgxtc27cWQ1R7Mp37gf83GrfUzP6zgEUjrMuSEWPHMMcUZU7esyzBsG4MO+orQ 3kbw== X-Gm-Message-State: AOAM531qHXn6HT7Fgr0ueS7FRW3q6a2Qny8vJiUVYU+epo4hYurMM29l qiM2Sa7U2q3+U155M2X6omDibQ9Z6UF76w== X-Google-Smtp-Source: ABdhPJwGIoPNCRQ/KF9ds6Xm6fJbzDuEf3hYoJTds+0eflOnl8MWD7rd2QShKo6lZ7xsojpBL/dJUg== X-Received: by 2002:a05:6602:2b13:: with SMTP id p19mr2310147iov.72.1643659030073; Mon, 31 Jan 2022 11:57:10 -0800 (PST) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id j2sm1972989ilu.82.2022.01.31.11.57.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jan 2022 11:57:09 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PULL 39/40] bsd-user: Rename arg name for target_cpu_reset to env Date: Mon, 31 Jan 2022 12:56:35 -0700 Message-Id: <20220131195636.31991-40-imp@bsdimp.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220131195636.31991-1-imp@bsdimp.com> References: <20220131195636.31991-1-imp@bsdimp.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::d30 (failed) Received-SPF: none client-ip=2607:f8b0:4864:20::d30; envelope-from=imp@bsdimp.com; helo=mail-io1-xd30.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Kyle Evans , Richard Henderson , def@FreeBSD.org, jrtc27@FreeBSD.org, Warner Losh Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Rename the parameter name for target_cpu_reset's CPUArchState * arg from cpu to env. Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/arm/target_arch_cpu.h | 2 +- bsd-user/i386/target_arch_cpu.h | 4 ++-- bsd-user/x86_64/target_arch_cpu.h | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bsd-user/arm/target_arch_cpu.h b/bsd-user/arm/target_arch_cpu.h index 2b395d5c97f..b087db48fa4 100644 --- a/bsd-user/arm/target_arch_cpu.h +++ b/bsd-user/arm/target_arch_cpu.h @@ -213,7 +213,7 @@ static inline void target_cpu_clone_regs(CPUARMState *env, target_ulong newsp) env->regs[0] = 0; } -static inline void target_cpu_reset(CPUArchState *cpu) +static inline void target_cpu_reset(CPUArchState *env) { } diff --git a/bsd-user/i386/target_arch_cpu.h b/bsd-user/i386/target_arch_cpu.h index 472a96689fc..3cbf69d8af2 100644 --- a/bsd-user/i386/target_arch_cpu.h +++ b/bsd-user/i386/target_arch_cpu.h @@ -200,9 +200,9 @@ static inline void target_cpu_clone_regs(CPUX86State *env, target_ulong newsp) env->regs[R_EAX] = 0; } -static inline void target_cpu_reset(CPUArchState *cpu) +static inline void target_cpu_reset(CPUArchState *env) { - cpu_reset(env_cpu(cpu)); + cpu_reset(env_cpu(env)); } #endif /* ! _TARGET_ARCH_CPU_H_ */ diff --git a/bsd-user/x86_64/target_arch_cpu.h b/bsd-user/x86_64/target_arch_cpu.h index 14def48adb5..0a9c0f08946 100644 --- a/bsd-user/x86_64/target_arch_cpu.h +++ b/bsd-user/x86_64/target_arch_cpu.h @@ -238,9 +238,9 @@ static inline void target_cpu_clone_regs(CPUX86State *env, target_ulong newsp) env->regs[R_EAX] = 0; } -static inline void target_cpu_reset(CPUArchState *cpu) +static inline void target_cpu_reset(CPUArchState *env) { - cpu_reset(env_cpu(cpu)); + cpu_reset(env_cpu(env)); } #endif /* ! _TARGET_ARCH_CPU_H_ */ From patchwork Mon Jan 31 19:56:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 12731136 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 86EFBC433F5 for ; Mon, 31 Jan 2022 20:47:58 +0000 (UTC) Received: from localhost ([::1]:47396 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nEdaf-00088Q-D9 for qemu-devel@archiver.kernel.org; Mon, 31 Jan 2022 15:47:57 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42908) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nEcnd-0004sM-EZ for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:17 -0500 Received: from [2607:f8b0:4864:20::d32] (port=35662 helo=mail-io1-xd32.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nEcnb-0002gR-58 for qemu-devel@nongnu.org; Mon, 31 Jan 2022 14:57:17 -0500 Received: by mail-io1-xd32.google.com with SMTP id 9so18466486iou.2 for ; Mon, 31 Jan 2022 11:57:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0gTkuAZAhwvC63lNdvy3u7JBBQLnkso7fXqMJsrKqkM=; b=ybhMYU1/kDfTkTqmeo1AuWW8onHihoZOweAWNHpY961IVE56e20bUUEEVD/Smil742 fgzQjKzdNucayh8ThtFtQ4XNBoiqKcSQSxkmCPvo06s3uSW5prR2If68axQ4pdEAt4tI lDVhR0c76u5eshcPj+vhQeQyf3/QI9yQW4KUcx6+9/ekWOWM9nFu81xn2CB2RNulgt/4 /bJ/XZzacrI0vjE4SFTahmdRb5skPPDMLpG5XhWDbsSj3bcbYBUYgBYNXyC4bGskdBV9 TxIU1HzeZoi1msU2VTQv4hX9skSSdatjaaKgPCE3CS1XwqasHsPTjhSOXPkzaeeYkrtf C0fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0gTkuAZAhwvC63lNdvy3u7JBBQLnkso7fXqMJsrKqkM=; b=bW8ip8AgOKdxuorklbrA9CpzIcJslb2i4IIj27DeqgQP1TP2TklyR7A9cAAzNVrImE GHWuxg6/MlFlPllGYiKfJiXuI7G+Icyufz6HwaEu4m85ZYAOv3+u45MBFdJsbaHFPf7E naP1IzHcJQH885ubWYiZ0y8zqDAAdZamU0kWDQ16D16TD4tf1U/tfapMa/vwJTE5Gne8 44/HCpS6p7cxlIDfvcNVK7AW6BmjWZRR83cwonmkVyfN+UdB/V/uiDMhvsWRR5bw/C5M 9FcrMOLcykbNiGs6KYMjvvAlxmvnJfs/7Yafu7X/U91JUYfjAdVAq4CacFwGd4DlEoLB 5qnA== X-Gm-Message-State: AOAM5304oKI0EAu/NJODpaSg2McQhlUg6DM+Fd5WAmUWEWwV18DXyZi/ 3cWf3zFpBU7WXGv/AwTnBohgZy0oISLTSQ== X-Google-Smtp-Source: ABdhPJx9fcUjR9lvMYia240j3UQG87xi1cxJKsw8B1qF8KMOPrny/lQghE5fU2x0tEmU8xXwTa12iQ== X-Received: by 2002:a05:6638:1927:: with SMTP id p39mr1766950jal.247.1643659031251; Mon, 31 Jan 2022 11:57:11 -0800 (PST) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id j2sm1972989ilu.82.2022.01.31.11.57.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jan 2022 11:57:10 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PULL 40/40] bsd-user/freebsd/target_os_ucontext.h: Prefer env as arg name for CPUArchState args Date: Mon, 31 Jan 2022 12:56:36 -0700 Message-Id: <20220131195636.31991-41-imp@bsdimp.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220131195636.31991-1-imp@bsdimp.com> References: <20220131195636.31991-1-imp@bsdimp.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::d32 (failed) Received-SPF: none client-ip=2607:f8b0:4864:20::d32; envelope-from=imp@bsdimp.com; helo=mail-io1-xd32.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Kyle Evans , Richard Henderson , def@FreeBSD.org, jrtc27@FreeBSD.org, Warner Losh Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/freebsd/target_os_ucontext.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bsd-user/freebsd/target_os_ucontext.h b/bsd-user/freebsd/target_os_ucontext.h index 41b28b2c150..b196b1c629f 100644 --- a/bsd-user/freebsd/target_os_ucontext.h +++ b/bsd-user/freebsd/target_os_ucontext.h @@ -36,9 +36,9 @@ abi_long set_sigtramp_args(CPUArchState *env, int sig, struct target_sigframe *frame, abi_ulong frame_addr, struct target_sigaction *ka); -abi_long get_mcontext(CPUArchState *regs, target_mcontext_t *mcp, int flags); -abi_long set_mcontext(CPUArchState *regs, target_mcontext_t *mcp, int srflag); -abi_long get_ucontext_sigreturn(CPUArchState *regs, abi_ulong target_sf, +abi_long get_mcontext(CPUArchState *env, target_mcontext_t *mcp, int flags); +abi_long set_mcontext(CPUArchState *env, target_mcontext_t *mcp, int srflag); +abi_long get_ucontext_sigreturn(CPUArchState *env, abi_ulong target_sf, abi_ulong *target_uc); #endif /* TARGET_OS_UCONTEXT_H */