From patchwork Tue Oct 3 19:20:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 728823 Delivered-To: patch@linaro.org Received: by 2002:a05:6504:1305:b0:23f:8cfb:5ad7 with SMTP id s5csp43214lto; Tue, 3 Oct 2023 12:22:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGLigldF2vl5x3xcU4BtzY8BxvOHwTsgbUwa/3kXcPY2g4H6ZycdrZ5Xap0worPEbMXQPTi X-Received: by 2002:a05:6102:8a:b0:44d:4a41:8945 with SMTP id t10-20020a056102008a00b0044d4a418945mr274611vsp.8.1696360944095; Tue, 03 Oct 2023 12:22:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696360944; cv=none; d=google.com; s=arc-20160816; b=VP/U1gC1e4SqBy1sxOFGdDou1Xj7xBd4wcuJn4ueWf6B2FeSCF45sCB2byBtYb6CtI 3u81wQBYG0qaOjxtGbSmNxtlzjmGhApUhlDsAJ0mW6WEoNuhXQW/yzV+o+fLp8GYKWz1 lghai1poQ/rVC0l4UiKdE5cQ0Jj++j5ToH2SWqicU/Hpeshjh4TC922EIctFuIxGohUg 36qF1D1YTlMIoKFSJzyubHlGsarnPYqGhtvS514MDTYyr9QO/yZrvBxDv9fC7TuLGHeL 3AP3a/WoXgvfBxzTGSZ9I9y8afDwqUTZunYdPuizUiLeBDHshIPom3Nj4dASjgXnYwvs 4sbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=bQFT1MeaWl1DywCggWsF6gUy0qHwX2/cAPNMuk55ZU0=; fh=snLBdPgTZLfuTuSyp61TvDpWpPfo2RkZAUqks3lr5MQ=; b=lfte4NQicfzfvuVvFJr2p7VXR4E9fe+ehDSZMVTdfSv6DfWTZZe1IFej+eyT9jwmvA ZNYGm1BivVaMQeCCI3qI+IWMMAFMRRNWRl1q471ZksVb1M4athr5fcZd8dEI82FndVau 4zBv22MzOINySX0K0axGh9HTzvyDNCXhZoCaZ0xzJ268KEvLluH/2dpxAYMihUOaIzhI a5hR9RqbAZWhh9scH0ficOAHFOhHQp8md6AnAP8GJmmZ51rCI7I2xWWDPN2j/UnkZhm/ 8s+fHuVhvOOwB7uM9LBgF96rCmQKbq1i9XfsTcGbIzUBrhGFr1Xf/umsHqghgT+zZX6I 7BLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="pb99Swa/"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id m13-20020a0cf18d000000b0065b2d24b5bcsi782518qvl.173.2023.10.03.12.22.23 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 Oct 2023 12:22:24 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="pb99Swa/"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnkxO-00052p-DP; Tue, 03 Oct 2023 15:21:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qnkwy-0004vT-LU for qemu-devel@nongnu.org; Tue, 03 Oct 2023 15:20:58 -0400 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnkwT-0004dS-Us for qemu-devel@nongnu.org; Tue, 03 Oct 2023 15:20:56 -0400 Received: by mail-pj1-x1033.google.com with SMTP id 98e67ed59e1d1-2773f2e599cso960203a91.1 for ; Tue, 03 Oct 2023 12:20:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696360814; x=1696965614; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bQFT1MeaWl1DywCggWsF6gUy0qHwX2/cAPNMuk55ZU0=; b=pb99Swa/hbwJL/Zia60/yXd+Wn6OIj50niL5WoiCeSJf1//LuW3x5Qt94RapwsnGPz 2TtWcWhgWLPy3FqVV9sbP2YVQdvvfg7115VXvjLKupPSkAeJgaH9vIYgvpwwgRLBCsoS m2mqii+ztsUQVvAUE3Z0GN3Kyl0tejjhIRZHHDPBBFtT0xrYROkvzeqbski8iDOoUnD+ /C1Z9EYgctcMK+QfCvh+tYwi9c2wL3aF74NgGHk/Yh0HbicTOT5VTnx5SvUUirJ34P6E y9hGNrVeCnTGLMcmS1bBmVXUPEEeiqS2Zv9vgDe8d2eb18BSb677z7i2i4NoQDajj/kE SxzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696360814; x=1696965614; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bQFT1MeaWl1DywCggWsF6gUy0qHwX2/cAPNMuk55ZU0=; b=ft9N1lK8VTgpF9sxzSfw7ct56tr9xgHMfqjlhBLis/Qv6e4H+pfZUkw7/F5DqF8ymz PRE6KMbecfeiG+X1Q5tyJjdJrOHqIb1m9+4CTJ1UEJrvxyZbYVtkFz7lT1zvJAhCeFA5 UOzwySlA+aRKYNHB2e7sx6s582r8nbZvvSNMeVD/ncHG5kb5QaAUhWuWFiq6uq0INk3r dtac750LEDYsUof96uJPB8T771uTyEpyMcBA56vqxdT4ybxzFbNhusroM1xrLlR8Bux5 XL2Zlk5YWs4SBbqIhHe9p0Nz3oSNq2vzEL/uywM3iNzGvsNXZ5bbgAPg7w8ya8Y2tmCk HTfw== X-Gm-Message-State: AOJu0Yykfy3ntCj0/uP5+n/RNQse6tY/CQW1qjyR/fzdV+dWcx2FLudq 4Zx4WeBh7j0jvs8yZsBfxphQnf6Y7FuHd44e1iU= X-Received: by 2002:a17:90b:224d:b0:274:566a:3477 with SMTP id hk13-20020a17090b224d00b00274566a3477mr240985pjb.39.1696360814503; Tue, 03 Oct 2023 12:20:14 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id w5-20020a170902d3c500b001c5fd2a28d3sm1978497plb.28.2023.10.03.12.20.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 12:20:13 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, deller@gmx.de, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v5 1/9] linux-user: Split out die_with_signal Date: Tue, 3 Oct 2023 12:20:04 -0700 Message-Id: <20231003192012.1674888-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231003192012.1674888-1-richard.henderson@linaro.org> References: <20231003192012.1674888-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1033; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1033.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Because we trap so many signals for use by the guest, we have to take extra steps to exit properly. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/signal.c | 52 ++++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index a67ab47d30..b7a2c47837 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -689,13 +689,39 @@ void cpu_loop_exit_sigbus(CPUState *cpu, target_ulong addr, } /* abort execution with signal */ +static G_NORETURN +void die_with_signal(int host_sig) +{ + struct sigaction act = { + .sa_handler = SIG_DFL, + }; + + /* + * 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 + * the signal and we wait for it to arrive. + */ + sigfillset(&act.sa_mask); + sigaction(host_sig, &act, NULL); + + kill(getpid(), host_sig); + + /* Make sure the signal isn't masked (reusing the mask inside of act). */ + sigdelset(&act.sa_mask, host_sig); + sigsuspend(&act.sa_mask); + + /* unreachable */ + abort(); +} + static G_NORETURN void dump_core_and_abort(CPUArchState *env, int target_sig) { CPUState *cpu = env_cpu(env); TaskState *ts = (TaskState *)cpu->opaque; int host_sig, core_dumped = 0; - struct sigaction act; host_sig = target_to_host_signal(target_sig); trace_user_dump_core_and_abort(env, target_sig, host_sig); @@ -719,29 +745,7 @@ void dump_core_and_abort(CPUArchState *env, int target_sig) } preexit_cleanup(env, 128 + target_sig); - - /* 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. */ - sigfillset(&act.sa_mask); - act.sa_handler = SIG_DFL; - act.sa_flags = 0; - sigaction(host_sig, &act, NULL); - - /* For some reason raise(host_sig) doesn't send the signal when - * statically linked on x86-64. */ - 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(); + die_with_signal(host_sig); } /* queue a signal so that it will be send to the virtual CPU as soon From patchwork Tue Oct 3 19:20:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 728820 Delivered-To: patch@linaro.org Received: by 2002:a05:6504:1305:b0:23f:8cfb:5ad7 with SMTP id s5csp43197lto; Tue, 3 Oct 2023 12:22:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEk9LN+zlELsocNp65hA1xtA73mbGeS+R03I2s7+Du1SK89TNPVro98uyvmaWGiTwHG38aq X-Received: by 2002:a05:622a:308:b0:418:1e68:6eaf with SMTP id q8-20020a05622a030800b004181e686eafmr376311qtw.47.1696360942809; Tue, 03 Oct 2023 12:22:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696360942; cv=none; d=google.com; s=arc-20160816; b=slM4LkMw4QlyfyqhLI8m7o5DJUaoH0ap3cKJbX3IcBUFnIo3XF7GDRUYtvU4VSR3dl NUOhbSVDuLHZ/G7mw8plT0ujwN+Hd35ksC/i1UZ3PSRcWlANfg/tiZhSqOxCp1d9tuBi GW0SheQx1vaR9Hu8+ykla9ACEF1WdGUe+UsF7QAII7yItmepQZykfTnp5+CB5+2qT7x+ aKPPjOegpyz8Fxlk4JhH/C2hSO6xHK0TeScZ9yhmhWE8aHWRv49HOUmWwaY4AwAiYU4L iISIkYGsjejM2oYdvBL4HS3DwYVBofTp6J/KELTQXRuWaXRzu8Onz8hgOPIXD/YmdxxE 9zBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=H1WLp4iET98k15VXyaSQDw2efQeM3lo5zs7sjnpm5FA=; fh=snLBdPgTZLfuTuSyp61TvDpWpPfo2RkZAUqks3lr5MQ=; b=ToZ7TnSJW/+7z4k7HILOGOWHLDCDVRn+Vwe5kV9+Oxg9yMpSSGHT2i09SqN+UZahh+ td+hlakaKgq1K1Mow9MKO9IiMLbK4/y93M4/ebPU4Cd4IyY8knMTk0xxUZb+orK0AU8U GkvE1GbAsAIMpdNNcV2qYNCkpaHTUuPSxtAmQ7G6x65GXOX60pPIrFhtTmPUQ6OiN1Da ADvTNjQy8b8cqmRmuAUMVdkPSxjaapRLQLD5QkZsALLMmiD6VR2jeWRW3RWDlBngXoWr nbuZ5oPh4It8JtD7yZgw0cGYQGrKT8w+vMxVm9WFlNsYBqQfh2UOnAJ6HL1vpV663j9H yoag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bSvjW6Tv; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id g10-20020ac8580a000000b0041811ab1c0bsi786836qtg.531.2023.10.03.12.22.22 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 Oct 2023 12:22:22 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bSvjW6Tv; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnkxC-0004xs-De; Tue, 03 Oct 2023 15:21:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qnkwk-0004r6-Gx for qemu-devel@nongnu.org; Tue, 03 Oct 2023 15:20:42 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnkwT-0004dU-RS for qemu-devel@nongnu.org; Tue, 03 Oct 2023 15:20:42 -0400 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1c62d61dc96so9651395ad.0 for ; Tue, 03 Oct 2023 12:20:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696360815; x=1696965615; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=H1WLp4iET98k15VXyaSQDw2efQeM3lo5zs7sjnpm5FA=; b=bSvjW6Tvwxksg7jvbD2IvrfMHyKJ/dpjCHxFIbF+MfxncUSjpxlDMlhMNNFVfxKPVE iTrhGQoZj13DCyiss0v7FzkQ2eLDkZMkIHXAni0imbU47bYheit9LbFzlhM5OdkiY1oN 2Cs0wde6D9rfVv7WZr13+8/SUUx8FYlcDb2gZehTsLO+3A3sa7AatyqVP/UXJi8EWIzS guIfJ4W3WanTRnHsaJnxlj6kZ5bcZcXuSLe4tsw46Zlji9XQSvamNY6l0Og+bxaSUxni xaZtfKUT2iKKGiO1R3hGWcS+SZwxcPC5Yq/OnlMa6VHPTU7IZsn7F3PdldFyryY+soWM 11Dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696360815; x=1696965615; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=H1WLp4iET98k15VXyaSQDw2efQeM3lo5zs7sjnpm5FA=; b=BUKpo4ske9G/h/c6i60UAiP9TblHTwiX4YEfofY8XUlgIzq3OC6LDoxzDrhoONKMeN z+TWoqV9OT5EV57higVogQVHgsL8ye2+uZRznzirixthk3TYTI9G4NbbmswBMlk3FRqO 7zbtclzqIaDZZOMxS6ufZM9abR5L12Q8tNJJ91NfLGL2VhraGV2hSwj8h8gawq2TJQGc m70AJKJYQv2BaAvjsceMj7hbY9on4UyzrV0y2z05WrDOuhhy/m84DUR4yo7gBdhEU03A asl3UMYHCAjfQ1sxk8E/Fp02wQb0ux2MqXpYse9AU78MfLMH5EqhBLYmIwdtuO70Jtz2 7S+g== X-Gm-Message-State: AOJu0Ywn7sDsFKOLOoV/GtWi6/X4G0GAvfcv/ths1qeeITkXwdUkM0dd dXiwTizmUvXjQHKtpPlKDONfaADPl4rxV7ysGNw= X-Received: by 2002:a17:902:7207:b0:1bd:ca80:6fe6 with SMTP id ba7-20020a170902720700b001bdca806fe6mr470637plb.41.1696360815299; Tue, 03 Oct 2023 12:20:15 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id w5-20020a170902d3c500b001c5fd2a28d3sm1978497plb.28.2023.10.03.12.20.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 12:20:14 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, deller@gmx.de, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v5 2/9] linux-user: Exit not abort in die_with_backtrace Date: Tue, 3 Oct 2023 12:20:05 -0700 Message-Id: <20231003192012.1674888-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231003192012.1674888-1-richard.henderson@linaro.org> References: <20231003192012.1674888-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x634.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org This line is supposed to be unreachable, but if we're going to have it at all, SIGABRT via abort() is subject to the same signal peril that created this function in the first place. We can _exit immediately without peril. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/signal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index b7a2c47837..84a56b76cc 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -713,7 +713,7 @@ void die_with_signal(int host_sig) sigsuspend(&act.sa_mask); /* unreachable */ - abort(); + _exit(EXIT_FAILURE); } static G_NORETURN From patchwork Tue Oct 3 19:20:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 728822 Delivered-To: patch@linaro.org Received: by 2002:a05:6504:1305:b0:23f:8cfb:5ad7 with SMTP id s5csp43211lto; Tue, 3 Oct 2023 12:22:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGdWZbsDZoaV88Q3O0vnmz4ZSkdRm4Bx+i41ybqvOw+dQVOKdDI9CSIzJthyUNNLQsNXjHS X-Received: by 2002:a1f:da84:0:b0:49d:fab:fa37 with SMTP id r126-20020a1fda84000000b0049d0fabfa37mr263055vkg.4.1696360943952; Tue, 03 Oct 2023 12:22:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696360943; cv=none; d=google.com; s=arc-20160816; b=CJvRPGyaiYPHF1LEMZ6pvE/HoftBvYSska0gsfU216IHavhcXJmTMz3HLS2SxZdeto Jeez6xVnTh033Q25XPY1/7WnEsVykLgtTCE83B6cuHaaOh6+oOLIlt21EVrbuM8ctJ5w rvLkK/XrdCx8byh4J8rvHoZ97D0tMk8RRnVDvKA5ELx/me7BoucQ1eXQ4f2erdW48XJ1 h1XAQe5d7WIk6LDedIzQxZSm6krUOrBTW0e2QjJHKPJB/7YzfZ2xpa0waK046aDTcJPC PdS56MRAKs7Qm3YZ3U7gKYusIYWLahtnTxqEwhrxxK4+9rU9rxh2ctJQ5ZBqG5MXjsv5 gLDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=OQP2+HZbJmIj9sXXPBVMTwI7vC2S6c38AoM7akl90XU=; fh=YRZ+qgYKjKfO+J7iYLqJ+AhmJljeW1N2qgZkMPPeD1I=; b=dcjU1P5/+3QaiIAhEHYqlcI1WE4ts/o+1ZYDLHwV1ov3Aa3cl4OczmLNRHLnaGc5hU TZsg1TTRq0I/zIxOQiAo6B6BgPtswSegoTDod4orvxBKJjY+JcCpJVkc0+hQZTwJ4/m5 YuxUALdUdzQl8C5+gjY7m4w6w+tfleVvrPCwE971HV7tiAoHLRV+0ZJNE3G4VWiZz0Nl IpoLTGo+8cR7W8ZuzsoR37jdXAYd7MJddA/Lk06I+AWk49ZwF9HFi2rAtNruC3uPBAYp GnHPG+7DjIQz7ddjj9yilgxegY10QB1hUn0pY68tRsQHSeRJIBN8uHYRQljLwxAXFGoP NbPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lzog5Va2; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d22-20020ac85ad6000000b00417b6e630f2si804482qtd.274.2023.10.03.12.22.23 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 Oct 2023 12:22:23 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lzog5Va2; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnkwq-0004t3-Je; Tue, 03 Oct 2023 15:20:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qnkwk-0004qs-Ju for qemu-devel@nongnu.org; Tue, 03 Oct 2023 15:20:43 -0400 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnkwT-0004dh-S8 for qemu-devel@nongnu.org; Tue, 03 Oct 2023 15:20:40 -0400 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1c0ecb9a075so9979445ad.2 for ; Tue, 03 Oct 2023 12:20:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696360816; x=1696965616; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=OQP2+HZbJmIj9sXXPBVMTwI7vC2S6c38AoM7akl90XU=; b=lzog5Va2VVr3xhuo199ZJGARfS2H5rUovzlLFwuosMlYubSR8qyo1CvM7RP1E6BKZK dk/EDDyoJOlX5NfVFFZTemeajSFPg7bchO8JHbOvB0dstxI/owbd56KhGmiE19m2zab+ CVvp+uRVoaudipLppRMAs4u81EXYy1/8wjchnuwF2G1Vh5y/L6Xq6QXxJ4XBM2GB+5uW CQg70nvbWNV1idmAChMz3NYwVYW2S3Ny2xzfUqmQk3lT830kHwhkruM/hDK0tS0G9Q8Z Tpig7Z2mhm1ahJBRDnFp8eBjWRR6gKiBJpTiSg3y/ylJH60owaoROXy6dFDyNV6ALf5N FhZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696360816; x=1696965616; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OQP2+HZbJmIj9sXXPBVMTwI7vC2S6c38AoM7akl90XU=; b=qXwucJNCRGlfUbZPuAI/ToplFngGMKAMPAvE6IowHo5hovvo6SowHLRm8rgowFjvJc qOPZ5BzpsJSThCan3gfYreFdbKcIzIBW5Xmb1hDv0S7J3zgYberjIc07i2oHniAEPPDi VtqxSWKtcGRxOCTCirRcpTK8MWqTwy4hpNPtIBmSJt4m9KCRfv5jNS17dzf8zOSUVZUf ehxJgpRzBajtg+RmLR1fOikBfUbt7Ib7JVTdtS95lb1GbFH8yXMkRN47pJjkn+m+QRie BJ3TvntzTVd9a/fZJK7RmiT7qqQcvJv1DhJGItalvh8pF3vMkD8ISKO7Gtx8l1bvmNvN n74Q== X-Gm-Message-State: AOJu0YzjtyDydC5JF9UlcQS/pbrG8urLOvkWmFijO8KXNnwMtvEZLUNM mbYGhPx2L9p6dOSd1bIA9Pyv9z1OQ7dLtVmdXmg= X-Received: by 2002:a17:902:c946:b0:1c3:e3b1:98df with SMTP id i6-20020a170902c94600b001c3e3b198dfmr488534pla.52.1696360816134; Tue, 03 Oct 2023 12:20:16 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id w5-20020a170902d3c500b001c5fd2a28d3sm1978497plb.28.2023.10.03.12.20.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 12:20:15 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, deller@gmx.de Subject: [PATCH v5 3/9] linux-user: Detect and report host crashes Date: Tue, 3 Oct 2023 12:20:06 -0700 Message-Id: <20231003192012.1674888-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231003192012.1674888-1-richard.henderson@linaro.org> References: <20231003192012.1674888-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::636; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x636.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Helge Deller If there is an internal program error in the qemu source code which raises SIGSEGV or SIGBUS, we currently assume the signal belongs to the guest. With an artificial error introduced, we will now print QEMU internal SIGSEGV {code=MAPERR, addr=(nil)} Signed-off-by: Helge Deller Message-Id: <20230812164314.352131-1-deller@gmx.de> [rth: Use in_code_gen_buffer and die_with_signal; drop backtrace] Signed-off-by: Richard Henderson --- linux-user/signal.c | 69 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 63 insertions(+), 6 deletions(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index 84a56b76cc..9fadc51347 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -32,6 +32,7 @@ #include "signal-common.h" #include "host-signal.h" #include "user/safe-syscall.h" +#include "tcg/tcg.h" static struct target_sigaction sigact_table[TARGET_NSIG]; @@ -779,6 +780,50 @@ static inline void rewind_if_in_safe_syscall(void *puc) } } +static G_NORETURN +void die_from_signal(siginfo_t *info) +{ + char sigbuf[4], codebuf[12]; + const char *sig, *code = NULL; + + switch (info->si_signo) { + case SIGSEGV: + sig = "SEGV"; + switch (info->si_code) { + case SEGV_MAPERR: + code = "MAPERR"; + break; + case SEGV_ACCERR: + code = "ACCERR"; + break; + } + break; + case SIGBUS: + sig = "BUS"; + switch (info->si_code) { + case BUS_ADRALN: + code = "ADRALN"; + break; + case BUS_ADRERR: + code = "ADRERR"; + break; + } + break; + default: + snprintf(sigbuf, sizeof(sigbuf), "%d", info->si_signo); + sig = sigbuf; + break; + } + if (code == NULL) { + snprintf(codebuf, sizeof(sigbuf), "%d", info->si_code); + code = codebuf; + } + + error_report("QEMU internal SIG%s {code=%s, addr=%p}", + sig, code, info->si_addr); + die_with_signal(info->si_signo); +} + static void host_signal_handler(int host_sig, siginfo_t *info, void *puc) { CPUState *cpu = thread_cpu; @@ -814,16 +859,28 @@ static void host_signal_handler(int host_sig, siginfo_t *info, void *puc) is_write = host_signal_write(info, uc); access_type = adjust_signal_pc(&pc, is_write); + /* If this was a write to a TB protected page, restart. */ + if (is_write + && host_sig == SIGSEGV + && info->si_code == SEGV_ACCERR + && h2g_valid(host_addr) + && handle_sigsegv_accerr_write(cpu, sigmask, pc, guest_addr)) { + return; + } + + /* + * If the access was not on behalf of the guest, within the executable + * mapping of the generated code buffer, then it is a host bug. + */ + if (access_type != MMU_INST_FETCH + && !in_code_gen_buffer((void *)(pc - tcg_splitwx_diff))) { + die_from_signal(info); + } + 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, 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. From patchwork Tue Oct 3 19:20:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 728819 Delivered-To: patch@linaro.org Received: by 2002:a05:6504:1305:b0:23f:8cfb:5ad7 with SMTP id s5csp43181lto; Tue, 3 Oct 2023 12:22:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEGzTaYYGMjdv3a7KncYOgG2UV/06gt+99klH8qcRHIyAFD60pBhycaDuvHrEEBZnupnkZO X-Received: by 2002:a05:620a:448a:b0:76e:eb8a:febd with SMTP id x10-20020a05620a448a00b0076eeb8afebdmr598465qkp.36.1696360941858; Tue, 03 Oct 2023 12:22:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696360941; cv=none; d=google.com; s=arc-20160816; b=M0y2e4OCIs5HeYlm6pflYUXdB13WBKufAvwwqayo4yTyGROZmQVQ9tLojQZxvkuxoA MZYbhCCZNQwow/a3GpJ8rzLfi91JkHlIHAxKSxRV+q5U5g2PFxjCWMluL2oN6uZfsiRv LnFL38UXYiPO/zdgruYvOdTsdEhEvQgzCnGnJcmddAP6ll0pq0sakVvumv8m4l0Yk+i7 hBXVnF5jLrLt6B/HEkGbHQH/CYhIWUjiXpuhfamAXmZUzj+lNqIwJ6eSPnvJJrjv9APG esBwXtr/kLwD8Lxfxkx1LpqLuRgqIuBELqITcV2wZXWyAF5k/b2BTTgALxz3FK6lvYbv z9PQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=wk7Bln+tqnBhQ7Rx4jjEi5WJUcqRNod/ibptYsj0x9Y=; fh=YRZ+qgYKjKfO+J7iYLqJ+AhmJljeW1N2qgZkMPPeD1I=; b=vqp95uV/nP4inCKW1s/p8VcoAjOuhbjY21l7IBJrzOZzLon9+psD9uBVUTPa0vY0GG XSuImt6QcU1ZGQytxFLqvgnGckVwoe6eQjuPEZG7JjaOcQUPm0gnvdqKxGwkD/p4pe7b vR9DPVUzz9sZn670O6wBEkfbQDZ/8Ss2KMd0RMvuPQgGEizaEpTJtoppitlNAkfkdxIn UyMkg4ATTbcmgmdrat+fWMLpvA2QG/4jNshq5ufBI2+WtTDm6vfyEoj9N33ZG+DBYY77 NYBYNw/ZzwUr+3Z1ydV4K7/V1YXimPwnfBhgoIQqPyZduN9siFTehEBoRT1KiFt9yVtS XIGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SfZx7chi; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id qg10-20020a05620a664a00b0076f34d5c367si774623qkn.278.2023.10.03.12.22.21 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 Oct 2023 12:22:21 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SfZx7chi; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnkwZ-0004km-L1; Tue, 03 Oct 2023 15:20:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qnkwW-0004iD-VB for qemu-devel@nongnu.org; Tue, 03 Oct 2023 15:20:29 -0400 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnkwT-0004dp-S5 for qemu-devel@nongnu.org; Tue, 03 Oct 2023 15:20:28 -0400 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1c3bd829b86so10636455ad.0 for ; Tue, 03 Oct 2023 12:20:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696360817; x=1696965617; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wk7Bln+tqnBhQ7Rx4jjEi5WJUcqRNod/ibptYsj0x9Y=; b=SfZx7chibSlbVQIex+biKqqAYrZpLoHopZIlIEkXduCAEJFKmjAWKQsRVzL/soHdJD t/ZLHJfoi2PvLQjNaNl/k0Up/KauXIr0mwGtTedMEAsc4WgqGFiOLQ29JgC/Q1JSSFdO dy1UQxiqglIYkZutxwaUFDaecAz456t4PXtWmxzXdIwuHfJhRuwd+nUp48cvpOOdbyck pAFjf+Q9AsTqwnq2z7W++BD2UcVBRHrXpjydh1JhjKar1RjYwfPv7dUaNGv7bNiDgcEN NSJjEBkhgLht++l6iCOoPD0sbBseHWAxPCiXAr+Ux4Btgwu42WUDotMI3oMORjqYXmuJ o1zQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696360817; x=1696965617; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wk7Bln+tqnBhQ7Rx4jjEi5WJUcqRNod/ibptYsj0x9Y=; b=TAA9cV2YIeLnpPIz0RU9Pc4FV37zbqM8USV3l47sByMFetgAYREkk8cfZJSvf4e5jf HcUjWkiydav/6QHjcIbkDIoloHXt5Em2FSQr6BJjyS7DvQngt9Xr0qFIjbOAOEcIoAVW Yyh4rz8ryonyo4GlQYpOmHJaiwgDsySZ4UVRulLU7mwvJSXPwcw4RDoUaJXNcex4OBoT sbnvLwQ0EmYHQDD26qFtqghuv1u46JoGKU/cOZrJVs+8knf2JHZRl/FbsE61ypsZZp7B I8wFI6jSehsjVUXzLGQhiRI2jCdVKp5MF3u8kb/fu1Ows2WuZnDgpbFXAAc5XK4XKuNt GAeg== X-Gm-Message-State: AOJu0YwNhnERBGYmgNJD+YO2ysb0ZXYJ53Sr94xVaibWZKV+FNPK7k7w SNVKTk9dINy+1U9FyQiZauzPnwsxdrJ359fRFYg= X-Received: by 2002:a17:902:d489:b0:1c3:cdf5:d891 with SMTP id c9-20020a170902d48900b001c3cdf5d891mr615392plg.46.1696360817040; Tue, 03 Oct 2023 12:20:17 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id w5-20020a170902d3c500b001c5fd2a28d3sm1978497plb.28.2023.10.03.12.20.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 12:20:16 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, deller@gmx.de Subject: [PATCH v5 4/9] linux-user: Only register handlers for core_dump_signal by default Date: Tue, 3 Oct 2023 12:20:07 -0700 Message-Id: <20231003192012.1674888-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231003192012.1674888-1-richard.henderson@linaro.org> References: <20231003192012.1674888-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62e; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org The set of fatal signals is really immaterial. If one arrives, and is unhandled, then the qemu process dies and the parent gets the correct signal. It is only for those signals which we would like to perform a guest core dump instead of a host core dump that we need to catch. Signed-off-by: Richard Henderson --- linux-user/signal.c | 43 ++++++++++++++----------------------------- 1 file changed, 14 insertions(+), 29 deletions(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index 9fadc51347..aab05f8eec 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -488,26 +488,6 @@ void target_to_host_siginfo(siginfo_t *info, const target_siginfo_t *tinfo) info->si_value.sival_ptr = (void *)(long)sival_ptr; } -static int fatal_signal (int sig) -{ - switch (sig) { - case TARGET_SIGCHLD: - case TARGET_SIGURG: - case TARGET_SIGWINCH: - /* 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; - } -} - /* returns 1 if given signal should dump core if not handled */ static int core_dump_signal(int sig) { @@ -602,8 +582,9 @@ void signal_init(void) 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)) + if (core_dump_signal(i)) { sigaction(host_sig, &act, NULL); + } } } @@ -997,7 +978,6 @@ int do_sigaction(int sig, const struct target_sigaction *act, struct target_sigaction *oact, abi_ulong ka_restorer) { struct target_sigaction *k; - struct sigaction act1; int host_sig; int ret = 0; @@ -1057,22 +1037,27 @@ int do_sigaction(int sig, const struct target_sigaction *act, return 0; } if (host_sig != SIGSEGV && host_sig != SIGBUS) { + struct sigaction act1; + 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 - ignore state to avoid getting unexpected interrupted - syscalls */ if (k->_sa_handler == TARGET_SIG_IGN) { + /* + * It is important to update the host kernel signal ignore + * state to avoid getting unexpected interrupted syscalls. + */ act1.sa_sigaction = (void *)SIG_IGN; } else if (k->_sa_handler == TARGET_SIG_DFL) { - if (fatal_signal (sig)) + if (core_dump_signal(sig)) { act1.sa_sigaction = host_signal_handler; - else + } else { act1.sa_sigaction = (void *)SIG_DFL; + } } else { act1.sa_sigaction = host_signal_handler; + if (k->sa_flags & TARGET_SA_RESTART) { + act1.sa_flags |= SA_RESTART; + } } ret = sigaction(host_sig, &act1, NULL); } From patchwork Tue Oct 3 19:20:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 728818 Delivered-To: patch@linaro.org Received: by 2002:a05:6504:1305:b0:23f:8cfb:5ad7 with SMTP id s5csp43179lto; Tue, 3 Oct 2023 12:22:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFUJtoQ59bVFIrIH3uPScaNLqgB1MMnkS774gc1wgIXhnOtauHb3jFfI0TtsCs7xgO2vmOq X-Received: by 2002:a0c:b203:0:b0:656:2d03:a4be with SMTP id x3-20020a0cb203000000b006562d03a4bemr222903qvd.40.1696360941655; Tue, 03 Oct 2023 12:22:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696360941; cv=none; d=google.com; s=arc-20160816; b=nHScgMAR0GwBGKoKHiZtW14hWv6bxowohsWiCfGbSu7dn+6TodF8gSqMDd+2El6RnP 4lFu4PjZILp+ohhgBGpeGFKDq2tf3e4V4If9W/xITmHAVya4O4DujjoYn3h+FEiLxrC/ sIe9IaeYKoddj9v0/XuJN52fVH0+EN2ppaOJOt+yK8LESHYkKhPgnR4NQx8a+Bb0yfrn AhAzvqXyebS2rrrHhRNwhLYPmQEEk4M0VInS76CEOXBFZrbnHLURc9tiXbEBUISy9Wit pK91iRMLYxSuk0A1m2oUV6iIJHaueGam8bZWIt63D9NrAhhdLrJIQArNC7OAiV6uHUpa 1NXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Z5UDBGcrrmujtcvRVyuE029O9vjXuHtI35qzP2H7Ibo=; fh=YRZ+qgYKjKfO+J7iYLqJ+AhmJljeW1N2qgZkMPPeD1I=; b=saCUzM5f2S/ts/OZ/V+/5/EsNqnRMzR4iw2NH9epi64YPsAMfP7g7W0hU/h74Qj67/ MTeV7gbCDA3Gx7sr1GQ5zIRtLfOO2hEkbj6a4fUp99W1CD0Gq6V+O8ZcTBE6/qV60qWw UsWbkiqR3kCkNQsnWXFsfPdKa/OlCdPLsNmIHTi/fK/6eP3zecJE4UHadwDs2KdPugtQ nE+8aOPbCwLqojp2axGX8qsdV/xW5kJ6mD440IzkoxiwL76tzD/0Wqz2DHvB2p3Pw7dg orKzFI45bt0tJ9e8NHpHfYdjE7uZNz2WXhB2GCxNct89ZJDZklCryMMg/1uWWqsCU6mp nxcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SCEY5LqO; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id a19-20020a0cca93000000b00656262151b5si796152qvk.55.2023.10.03.12.22.21 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 Oct 2023 12:22:21 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SCEY5LqO; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnkxN-00051q-ED; Tue, 03 Oct 2023 15:21:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qnkws-0004ti-4A for qemu-devel@nongnu.org; Tue, 03 Oct 2023 15:20:52 -0400 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnkwT-0004dw-SQ for qemu-devel@nongnu.org; Tue, 03 Oct 2023 15:20:49 -0400 Received: by mail-pj1-x102c.google.com with SMTP id 98e67ed59e1d1-27777174297so877652a91.3 for ; Tue, 03 Oct 2023 12:20:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696360818; x=1696965618; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Z5UDBGcrrmujtcvRVyuE029O9vjXuHtI35qzP2H7Ibo=; b=SCEY5LqOplL3tFiRC/WQJZuEHzkhqCEIT5/+M5GRhNhSJS3jiJrBFlWXPNoNX+F29L qOmYhb9nxFGKq6bXmrNyqAPL6YvZ2vnRr/odtIzYtcSfpFDt+fRqF1/0QsqjDY7GCEYs 7xCqOeEhmrpJDrfhlyi0yiIJWCXJ3/1iHUESYYjyt0wVa9CmvOq0cydJ+Hq3m9adnGP0 t+ToyjU5MDTaybsRRWpWn+GZOxWRa8aAkGPXHYu9wD7RMqXz9JlzxuohzMk+YE0EqTES +JZtSYrh+KDWFazV2ixo8S250wPTwdHNxvJlYtbfylLtCYv3VNiM1Vl6XvS9XaYmk90J sjig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696360818; x=1696965618; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Z5UDBGcrrmujtcvRVyuE029O9vjXuHtI35qzP2H7Ibo=; b=C2yr5LmK1mQxOyNMg3aGXovLRtng/wyREg1dXLff8LN/qmu7YK3vuHNpOYLfjHP66d 1L5wwT5Dc/MSS8NmxZ/w2bXQgcBkwv2F5JT/MiWg1fEXKoVz6VkXluZ0ZiptSXrcPZNu 7kPUyBe+8zC0942qjwFU2q56TL9V6jtlzoLNMBlh7bEuWn5GoUCfsiTKD3Z6Ui5Xr3Pb iNvjqj8YyDMoKHGa40F/jitvqyoenvpnpy2EwvKrgJr5mBx0nZR16F0/A8A83P1ka5rK q22VHVTjMk91t+FszKyrdCFDMhpdKtxXH1PsyskYRWE91ggJyN2+5ugSlxVFyEtYxsZZ jdWQ== X-Gm-Message-State: AOJu0YyEBgxkTNpGpkK7cgoKBHCtNyXU7zg6jyv3BUrUX8g/do6Zi3X8 7KfO0MhKIrY8T9VGx4b7122N+3TvAn+oXCVOkbk= X-Received: by 2002:a17:90a:4f04:b0:274:77df:50d1 with SMTP id p4-20020a17090a4f0400b0027477df50d1mr295914pjh.21.1696360818159; Tue, 03 Oct 2023 12:20:18 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id w5-20020a170902d3c500b001c5fd2a28d3sm1978497plb.28.2023.10.03.12.20.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 12:20:17 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, deller@gmx.de Subject: [PATCH v5 5/9] linux-user: Map unsupported signals to an out-of-bounds value Date: Tue, 3 Oct 2023 12:20:08 -0700 Message-Id: <20231003192012.1674888-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231003192012.1674888-1-richard.henderson@linaro.org> References: <20231003192012.1674888-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102c; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Do not return a valid signal number in one domain when given an invalid signal number in the other domain. Signed-off-by: Richard Henderson --- linux-user/signal.c | 72 ++++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 34 deletions(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index aab05f8eec..653fd2f9fd 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -44,9 +44,8 @@ abi_ulong default_sigreturn; abi_ulong default_rt_sigreturn; /* - * System includes define _NSIG as SIGRTMAX + 1, - * but qemu (like the kernel) defines TARGET_NSIG as TARGET_SIGRTMAX - * and the first signal is SIGHUP defined as 1 + * System includes define _NSIG as SIGRTMAX + 1, but qemu (like the kernel) + * defines TARGET_NSIG as TARGET_SIGRTMAX and the first signal is 1. * Signal number 0 is reserved for use as kill(pid, 0), to test whether * a process exists without sending it a signal. */ @@ -57,7 +56,6 @@ static uint8_t host_to_target_signal_table[_NSIG] = { #define MAKE_SIG_ENTRY(sig) [sig] = TARGET_##sig, MAKE_SIGNAL_LIST #undef MAKE_SIG_ENTRY - /* next signals stay the same */ }; static uint8_t target_to_host_signal_table[TARGET_NSIG + 1]; @@ -65,18 +63,24 @@ static uint8_t target_to_host_signal_table[TARGET_NSIG + 1]; /* valid sig is between 1 and _NSIG - 1 */ int host_to_target_signal(int sig) { - if (sig < 1 || sig >= _NSIG) { + if (sig < 1) { return sig; } + if (sig >= _NSIG) { + return TARGET_NSIG + 1; + } return host_to_target_signal_table[sig]; } /* valid sig is between 1 and TARGET_NSIG */ int target_to_host_signal(int sig) { - if (sig < 1 || sig > TARGET_NSIG) { + if (sig < 1) { return sig; } + if (sig > TARGET_NSIG) { + return _NSIG; + } return target_to_host_signal_table[sig]; } @@ -507,48 +511,48 @@ static int core_dump_signal(int sig) static void signal_table_init(void) { - int host_sig, target_sig, count; + int hsig, tsig, count; /* * Signals are supported starting from TARGET_SIGRTMIN and going up - * until we run out of host realtime signals. - * glibc at least uses only the lower 2 rt signals and probably - * nobody's using the upper ones. - * it's why SIGRTMIN (34) is generally greater than __SIGRTMIN (32) - * To fix this properly we need to do manual signal delivery multiplexed - * over a single host signal. + * until we run out of host realtime signals. Glibc uses the lower 2 + * RT signals and (hopefully) nobody uses the upper ones. + * This is why SIGRTMIN (34) is generally greater than __SIGRTMIN (32). + * To fix this properly we would need to do manual signal delivery + * multiplexed over a single host signal. * Attempts for configure "missing" signals via sigaction will be * silently ignored. */ - for (host_sig = SIGRTMIN; host_sig <= SIGRTMAX; host_sig++) { - target_sig = host_sig - SIGRTMIN + TARGET_SIGRTMIN; - if (target_sig <= TARGET_NSIG) { - host_to_target_signal_table[host_sig] = target_sig; + for (hsig = SIGRTMIN; hsig <= SIGRTMAX; hsig++) { + tsig = hsig - SIGRTMIN + TARGET_SIGRTMIN; + if (tsig <= TARGET_NSIG) { + host_to_target_signal_table[hsig] = tsig; } } - /* generate signal conversion tables */ - for (target_sig = 1; target_sig <= TARGET_NSIG; target_sig++) { - target_to_host_signal_table[target_sig] = _NSIG; /* poison */ - } - for (host_sig = 1; host_sig < _NSIG; host_sig++) { - if (host_to_target_signal_table[host_sig] == 0) { - host_to_target_signal_table[host_sig] = host_sig; - } - target_sig = host_to_target_signal_table[host_sig]; - if (target_sig <= TARGET_NSIG) { - target_to_host_signal_table[target_sig] = host_sig; + /* Invert the mapping that has already been assigned. */ + for (hsig = 1; hsig < _NSIG; hsig++) { + tsig = host_to_target_signal_table[hsig]; + if (tsig) { + assert(target_to_host_signal_table[tsig] == 0); + target_to_host_signal_table[tsig] = hsig; } } - if (trace_event_get_state_backends(TRACE_SIGNAL_TABLE_INIT)) { - for (target_sig = 1, count = 0; target_sig <= TARGET_NSIG; target_sig++) { - if (target_to_host_signal_table[target_sig] == _NSIG) { - count++; - } + /* Map everything else out-of-bounds. */ + for (hsig = 1; hsig < _NSIG; hsig++) { + if (host_to_target_signal_table[hsig] == 0) { + host_to_target_signal_table[hsig] = TARGET_NSIG + 1; } - trace_signal_table_init(count); } + for (count = 0, tsig = 1; tsig <= TARGET_NSIG; tsig++) { + if (target_to_host_signal_table[tsig] == 0) { + target_to_host_signal_table[tsig] = _NSIG; + count++; + } + } + + trace_signal_table_init(count); } void signal_init(void) From patchwork Tue Oct 3 19:20:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 728825 Delivered-To: patch@linaro.org Received: by 2002:a05:6504:1305:b0:23f:8cfb:5ad7 with SMTP id s5csp43400lto; Tue, 3 Oct 2023 12:22:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHtd4GgkXPUkuQklq0FJ9TgUTyseFafznmEdes5LV7bHgMebiySFs9g4WcC+GHOCcqPYM/m X-Received: by 2002:a67:f146:0:b0:454:78c5:a848 with SMTP id t6-20020a67f146000000b0045478c5a848mr256763vsm.27.1696360967724; Tue, 03 Oct 2023 12:22:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696360967; cv=none; d=google.com; s=arc-20160816; b=eaUPhpS6olAJihHRIQugnTUePW8IiBTUcjSM4uynTV7YW3/XykxnvoXJvcTGLU5oQ8 +c3PzZ4quDl0iSATOsAG3yWzIj+PNBvCY+fZxRybxROGtUySJYrmbZSTqMmvpbVvwr+o aKFcEdO7MsKy2dtkp5+MFahV4ulB8Oh5K/KU9QtxhnBTH7ss/fSk+9dZuL0Y0U+Xz6LC L8rOsd+0yW3y9IFhI94HaeLiECtPLU+27CgHhBOV7BrU7sZwrjIAxYJVTbgHaKb27A8P vI0odMu0CNV6ADqfQjCiFf4bhYTU7kmxva5cscbWCI/VdzAeBUB5vgS539NdudkpCXM8 BoNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ZcBnZHSbuxu1CEXsD4rb1K43nNPKQuPu10A2c8iY0Bc=; fh=YRZ+qgYKjKfO+J7iYLqJ+AhmJljeW1N2qgZkMPPeD1I=; b=D8Jh9B8NoURLJUwD/eCUZ4KHw+dPajtTSpSzc5MwuTS9B9AvNbPrlapc3Q1UL4Zv5d P/ELIz3pKQFEYyK3VZKDOXCfnXAfBBK/nYEErd/OCjxfZtTRiBY/nPeud6AuqLRyb2YP EhIXCRUvwI3sxPdR8pbj2WdL+3A7y/2JZv+/WaASjVmRgcrirucu7Vl9NCa7fJ9l1wTi efeWHbdtG4ZsqVfR95YkqS8DcmmSkrSAofxmhAB0GKM25R+z9fVzmJUasZxZ+Xl3WC9j 7v3zhC2njjA8fApFnBEtXNEOSHrX28wUCLqABMZxM+1S5x7+Xx19d9ZtdHpbFPTaGsma bDYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=r1aYU5Nl; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 8-20020ac85708000000b00417d9251452si800293qtw.770.2023.10.03.12.22.47 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 Oct 2023 12:22:47 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=r1aYU5Nl; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnkxI-0004zp-4H; Tue, 03 Oct 2023 15:21:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qnkwk-0004r7-Gx for qemu-devel@nongnu.org; Tue, 03 Oct 2023 15:20:42 -0400 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnkwT-0004dy-Rc for qemu-devel@nongnu.org; Tue, 03 Oct 2023 15:20:42 -0400 Received: by mail-pj1-x102f.google.com with SMTP id 98e67ed59e1d1-27740ce6c76so870336a91.0 for ; Tue, 03 Oct 2023 12:20:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696360819; x=1696965619; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZcBnZHSbuxu1CEXsD4rb1K43nNPKQuPu10A2c8iY0Bc=; b=r1aYU5NlP+xZlqrGUDDxtHGyqTfATH5e2Ij5QXBzHgE8iRMsIqb1WPpuVZE6gziJFY sX/qgWlI304bA2ZwqlYyU5sbcc8kb1lGlXfTHLdSvMEh+Oq9hdBaIt2FKHUGYDhFPaga Ny2ExgOk3fC1AS8bvn4mpeMX8Glni+Ak8ocgWLhSe3LoadWF5bHFl6vKP9f8c8aDYlDb DOpa2oIooO4N6PadtuGN/IZ0krmXbx87UC6ezoldaKlAzb7wUWkMGw6Wpizxo+lZVhJR pEY6olW74XG7F+tbInH35yRY2JLTX5FsEQa9OT3yQ1DXOTUEka8J9cMofibMah2pMYv4 n8mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696360819; x=1696965619; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZcBnZHSbuxu1CEXsD4rb1K43nNPKQuPu10A2c8iY0Bc=; b=pYMtkqP6Pj9VGiUhqkOhzr5kvF8gFPhSSoBWGmBCwYMMTJ4gI3pZNgrQPNc1u32g/x wdwtrToQE+a7W01XJhaL1xFsyvS/CVj45qLdhC3C7o4Fc9pzTMAOvJI46gI1udtLCn5F TfPkwoOcZdqU2c0issg0DqUH4o1mVXe+38aYqQ7WhbgEGCKORsdNgVjcOnxR+I1Y1b+Y 2N6x43Cb7aug8Am17tCjaQ3rDtqbwfh5rBi3ov9n/qEdI52A+8BEXXgV68MdbWKury3L s/YZS5Ict502c38i+yqzwgDRRGLZoCOhQmTTbSnFUmi9UD80GWg8FjFy8MnjvAPFa1y8 SzDA== X-Gm-Message-State: AOJu0YzqOvJy3pP7F0IYTSK0v0mdRTAVUPcH2CQNcQD/oVKkW0lUuTFS TMcASJsOUo/wB8Vx+Qd+DK5MF5vwtu+svjTiiIY= X-Received: by 2002:a17:90a:fa89:b0:273:ef1b:5a2 with SMTP id cu9-20020a17090afa8900b00273ef1b05a2mr208416pjb.47.1696360819194; Tue, 03 Oct 2023 12:20:19 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id w5-20020a170902d3c500b001c5fd2a28d3sm1978497plb.28.2023.10.03.12.20.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 12:20:18 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, deller@gmx.de Subject: [PATCH v5 6/9] linux-user: Simplify signal_init Date: Tue, 3 Oct 2023 12:20:09 -0700 Message-Id: <20231003192012.1674888-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231003192012.1674888-1-richard.henderson@linaro.org> References: <20231003192012.1674888-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102f; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Install the host signal handler at the same time we are probing the target signals for SIG_IGN/SIG_DFL. Ignore unmapped target signals. Signed-off-by: Richard Henderson --- linux-user/signal.c | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index 653fd2f9fd..09840b0eb0 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -558,10 +558,7 @@ static void signal_table_init(void) void signal_init(void) { TaskState *ts = (TaskState *)thread_cpu->opaque; - struct sigaction act; - struct sigaction oact; - int i; - int host_sig; + struct sigaction act, oact; /* initialize signal conversion tables */ signal_table_init(); @@ -572,23 +569,28 @@ void signal_init(void) sigfillset(&act.sa_mask); act.sa_flags = SA_SIGINFO; act.sa_sigaction = host_signal_handler; - for(i = 1; i <= TARGET_NSIG; i++) { - 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 (core_dump_signal(i)) { - sigaction(host_sig, &act, NULL); + + /* + * A parent process may configure ignored signals, but all other + * signals are default. For any target signals that have no host + * mapping, set to ignore. For all core_dump_signal, install our + * host signal handler so that we may invoke dump_core_and_abort. + * This includes SIGSEGV and SIGBUS, which are also need our signal + * handler for paging and exceptions. + */ + for (int tsig = 1; tsig <= TARGET_NSIG; tsig++) { + int hsig = target_to_host_signal(tsig); + abi_ptr thand = TARGET_SIG_IGN; + + if (hsig < _NSIG) { + struct sigaction *iact = core_dump_signal(tsig) ? &act : NULL; + + sigaction(hsig, iact, &oact); + if (oact.sa_sigaction != (void *)SIG_IGN) { + thand = TARGET_SIG_DFL; + } } + sigact_table[tsig - 1]._sa_handler = thand; } } From patchwork Tue Oct 3 19:20:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 728827 Delivered-To: patch@linaro.org Received: by 2002:a05:6504:1305:b0:23f:8cfb:5ad7 with SMTP id s5csp43464lto; Tue, 3 Oct 2023 12:22:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFv9sFNh2j/h8UUVbq+ObNppMNM5I6SHaN5lrvyEYbVsgbX38j2xV91U9jHbGePKXNV6nFy X-Received: by 2002:ac8:5e4c:0:b0:413:5e4d:bf40 with SMTP id i12-20020ac85e4c000000b004135e4dbf40mr295961qtx.68.1696360975867; Tue, 03 Oct 2023 12:22:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696360975; cv=none; d=google.com; s=arc-20160816; b=OYQcvOeiSE4FwcyX5TQAAkLsVNGzmZ574V7O1ukAl2RGmz+0dF+zS3GM7WQhe25c5F 9Z5UnFftl/eE9LyFYSfy7i9Gou7lJoFsUxQpHWn4lYbNMWbu32tLrDs89ZJy2qUqj7z9 hZa8lWA3YapxQKhNX0Xn0Cd0ONsJgQ0hdnma70xkXFoe4gPA4EiO9xQ+un/mwfJKRgiP O+nh/ssK1/GcvF3eeqEwdDqSQaOEj0b4IpAWQUgvxlVpDQUnc1i1O0Gszimju3rd3JHh gQL8fW+yRgKT/5pj07V8E7SO+dXW0uvlgv2Y+ulENUTFsWdNKZUmDETvcvvDzo6sUVqQ a+wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=x2cyUxn+xuVK4D2wBUl4hDzhwAR15+4cIMS3lBIQ8QQ=; fh=YRZ+qgYKjKfO+J7iYLqJ+AhmJljeW1N2qgZkMPPeD1I=; b=gg3Y2KOfe8k4jy1wA5+KR6Nn0aGABMTyZwSrR7WUHDQVSUaeT5ybzF34sz2kY+QLyx MwqfM/Imjg+eCMju+N5hr+cK2kvwXty4M2ACgdX2hYYYxU4H4qptZTbjo/9GKjgc1HSi 3RhM/cL25dG9xpUdXcEiySl9maveWKaJGtCS9H5hELmNKf7Q6FvDB49madgn4whXnDNN 6xtAr8043emmSI0bZ0Yha0W+/l61Hl89zG/rEPqPBPva/n1EQqtrpb39/UVvBYXYxRVi j7DuavsK0xr5m4RjkK9w6Dy+x9n4T74H5rkFnk4WyKnHnAUmMi3bK9M0fYGF97fK+wGR ruLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=L1JHtDSU; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id f2-20020a05622a104200b0041983f51b2esi826318qte.67.2023.10.03.12.22.55 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 Oct 2023 12:22:55 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=L1JHtDSU; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnkxL-00051E-7d; Tue, 03 Oct 2023 15:21:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qnkwo-0004sI-2x for qemu-devel@nongnu.org; Tue, 03 Oct 2023 15:20:47 -0400 Received: from mail-oi1-x235.google.com ([2607:f8b0:4864:20::235]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnkwT-0004e7-Uz for qemu-devel@nongnu.org; Tue, 03 Oct 2023 15:20:44 -0400 Received: by mail-oi1-x235.google.com with SMTP id 5614622812f47-3af65455e7cso864218b6e.1 for ; Tue, 03 Oct 2023 12:20:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696360820; x=1696965620; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=x2cyUxn+xuVK4D2wBUl4hDzhwAR15+4cIMS3lBIQ8QQ=; b=L1JHtDSUHev1yQBec6ka2VC3UPilNJisSYn9X506O0sTBoHtghmDwWnTLxuqF9HdqB tVQyVPpcaMCIvAv6eu4wSvi2SWKxuf+D+w1UGABremlEJpWvo4ZsArEEwoIVCExhAES/ XygsnroxxVJrBU0newSGmDT2yhirVBLpJYakk4ZQM3UfVgpxLEpyHnql6NCmeSnyrvTI vH3mIj23JkcjDpcpgyM9n/9RhBPdNbnA9YZr2w5/zY9DT9qf6opb0CoK2rvkU0SxNGIG WYJKmBsg9jip3Y3F6xLelLaDiZUZIXEeFSVH98DxRE+KrQEkBn6SHpC2vGsK/mmfzICP Ialg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696360820; x=1696965620; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=x2cyUxn+xuVK4D2wBUl4hDzhwAR15+4cIMS3lBIQ8QQ=; b=qg9feWb7VJAOiidUSdYKQjFbFg7okDInPOzITUNCSpdeZ4yfFnxOxPRWQ7LqsgLkuf gsn9tPOmKLx3zd1cCG+hct7KXb1GvqD8NXQ7rs0+yXV+OWnDrOG/cOaLHE/gQrKRj/3k q19rhlwzLz6lg/J1dUDhLlWg7Wf/i3PPO1j040qJcAT7H68ZstJ9/izJYM1rSqf0i6fG K/3bCCCvIJABFAfPfMs3+VJsNhrvTdj834ytqHQMKlst21bUjIgEGdiAv4s62+uW/Aco ayZFzHB/90RNmKvG8UHXyiMgrxCwQvkSHddj5As4Ch8LUUWZnF6v5eGhhgt3iwBH8DuW nL8g== X-Gm-Message-State: AOJu0YyyoQKwRwFf+uItHND8gNvEhkd3EVsDMEh8AYO9ZdvDQYGhZ4dn /96Q9E62OcIRPUwomZvY6M0nE6M8iTsVteQdScE= X-Received: by 2002:a05:6808:13c5:b0:3a8:43d5:878b with SMTP id d5-20020a05680813c500b003a843d5878bmr604634oiw.2.1696360820120; Tue, 03 Oct 2023 12:20:20 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id w5-20020a170902d3c500b001c5fd2a28d3sm1978497plb.28.2023.10.03.12.20.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 12:20:19 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, deller@gmx.de Subject: [PATCH v5 7/9] linux-user: Split out host_sig{segv,bus}_handler Date: Tue, 3 Oct 2023 12:20:10 -0700 Message-Id: <20231003192012.1674888-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231003192012.1674888-1-richard.henderson@linaro.org> References: <20231003192012.1674888-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::235; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x235.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Make host_signal_handler slightly easier to read. Signed-off-by: Richard Henderson --- linux-user/signal.c | 145 ++++++++++++++++++++++++++------------------ 1 file changed, 85 insertions(+), 60 deletions(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index 09840b0eb0..706b8ac7a7 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -811,6 +811,80 @@ void die_from_signal(siginfo_t *info) die_with_signal(info->si_signo); } +static void host_sigsegv_handler(CPUState *cpu, siginfo_t *info, + host_sigcontext *uc) +{ + uintptr_t 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. + */ + bool is_valid = h2g_valid(host_addr); + abi_ptr guest_addr = h2g_nocheck(host_addr); + uintptr_t pc = host_signal_pc(uc); + bool is_write = host_signal_write(info, uc); + MMUAccessType access_type = adjust_signal_pc(&pc, is_write); + bool maperr; + + /* If this was a write to a TB protected page, restart. */ + if (is_write + && is_valid + && info->si_code == SEGV_ACCERR + && handle_sigsegv_accerr_write(cpu, host_signal_mask(uc), + pc, guest_addr)) { + return; + } + + /* + * If the access was not on behalf of the guest, within the executable + * mapping of the generated code buffer, then it is a host bug. + */ + if (access_type != MMU_INST_FETCH + && !in_code_gen_buffer((void *)(pc - tcg_splitwx_diff))) { + die_from_signal(info); + } + + maperr = true; + if (is_valid && info->si_code == SEGV_ACCERR) { + /* + * 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, host_signal_mask(uc), NULL); + cpu_loop_exit_sigsegv(cpu, guest_addr, access_type, maperr, pc); +} + +static void host_sigbus_handler(CPUState *cpu, siginfo_t *info, + host_sigcontext *uc) +{ + uintptr_t pc = host_signal_pc(uc); + bool is_write = host_signal_write(info, uc); + MMUAccessType access_type = adjust_signal_pc(&pc, is_write); + + /* + * If the access was not on behalf of the guest, within the executable + * mapping of the generated code buffer, then it is a host bug. + */ + if (!in_code_gen_buffer((void *)(pc - tcg_splitwx_diff))) { + die_from_signal(info); + } + + if (info->si_code == BUS_ADRALN) { + uintptr_t host_addr = (uintptr_t)info->si_addr; + abi_ptr guest_addr = h2g_nocheck(host_addr); + + sigprocmask(SIG_SETMASK, host_signal_mask(uc), NULL); + cpu_loop_exit_sigbus(cpu, guest_addr, access_type, pc); + } +} + static void host_signal_handler(int host_sig, siginfo_t *info, void *puc) { CPUState *cpu = thread_cpu; @@ -822,73 +896,23 @@ static void host_signal_handler(int host_sig, siginfo_t *info, void *puc) int guest_sig; uintptr_t pc = 0; bool sync_sig = false; - void *sigmask = host_signal_mask(uc); + void *sigmask; /* * 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 this was a write to a TB protected page, restart. */ - if (is_write - && host_sig == SIGSEGV - && info->si_code == SEGV_ACCERR - && h2g_valid(host_addr) - && handle_sigsegv_accerr_write(cpu, sigmask, pc, guest_addr)) { + if (info->si_code > 0) { + switch (host_sig) { + case SIGSEGV: + /* Only returns on handle_sigsegv_accerr_write success. */ + host_sigsegv_handler(cpu, info, uc); return; + case SIGBUS: + host_sigbus_handler(cpu, info, uc); + sync_sig = true; + break; } - - /* - * If the access was not on behalf of the guest, within the executable - * mapping of the generated code buffer, then it is a host bug. - */ - if (access_type != MMU_INST_FETCH - && !in_code_gen_buffer((void *)(pc - tcg_splitwx_diff))) { - die_from_signal(info); - } - - if (host_sig == SIGSEGV) { - bool maperr = true; - - if (info->si_code == SEGV_ACCERR && h2g_valid(host_addr)) { - /* - * 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, sigmask, NULL); - cpu_loop_exit_sigsegv(cpu, guest_addr, access_type, maperr, pc); - } else { - sigprocmask(SIG_SETMASK, sigmask, NULL); - if (info->si_code == BUS_ADRALN) { - cpu_loop_exit_sigbus(cpu, guest_addr, access_type, pc); - } - } - - sync_sig = true; } /* get target signal number */ @@ -929,6 +953,7 @@ static void host_signal_handler(int host_sig, siginfo_t *info, void *puc) * would write 0xff bytes off the end of the structure and trash * data on the struct. */ + sigmask = host_signal_mask(uc); memset(sigmask, 0xff, SIGSET_T_SIZE); sigdelset(sigmask, SIGSEGV); sigdelset(sigmask, SIGBUS); From patchwork Tue Oct 3 19:20:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 728824 Delivered-To: patch@linaro.org Received: by 2002:a05:6504:1305:b0:23f:8cfb:5ad7 with SMTP id s5csp43198lto; Tue, 3 Oct 2023 12:22:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHcIiwNzADoCAS+AQksQ7W3sp9XDTsq/zsYrJPnrxYTgWpPkb2SDTjq2cpg/6qZr95tKcfB X-Received: by 2002:a05:620a:1708:b0:76e:f90d:85d1 with SMTP id az8-20020a05620a170800b0076ef90d85d1mr213469qkb.26.1696360942843; Tue, 03 Oct 2023 12:22:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696360942; cv=none; d=google.com; s=arc-20160816; b=iwDtazXbtlInCYB8LvOwDv266QuJmtrMbedCJmEoq85gpVjP8GNZ5A6HFJwR7iNEhq B4Cj9rmrQ6UcR9EaLpbyX5f/FCSJ5yl0qinfXaH9byaNA3ECFrDZgN8qT9mEE6FTO3oh INJHHwO8MXjLd/DnMmbiAIhQ4fKkMKmjYR74OSJKfokPPB3q3Mx+vhVkObaw1rWiCF4e X7h4KKnIgY7GyDyfJWro4Eh3TgH+VZf9cbOTdsARmnp1xMpRGBasc6fxntLD2Rsboex5 A2GPh9aaHr9O5ASFhydBpBrhbQt5H7RqeE1U02wXs/DaEUypL/JDAWaep8aBberQajmH EXVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=MD3OzDuuDGgXDQMB1J8iXNmpATULZDtwIUTwe03wb+E=; fh=YRZ+qgYKjKfO+J7iYLqJ+AhmJljeW1N2qgZkMPPeD1I=; b=HBpRnJP+5uhJZyKrWo9i/d/vCKgZN6VfB+4yymt5hEQVfBGez5EkZAPrxNGkVxzXdw fm7hwuQ5OpE6X3VkETolNMbXZgUAZ/n4j1rq5IugpFndAQbCyZGqedUdnzI4pKjD/02y t8xlHF2nIdDBv+huFoSUzt9EemO31TbzNDUSgYebpEomYTL6gUCJ2MZ8iRk+SMcgqGFd ne6ZgoZQd+/SzPSmId09eu7/1ZAa5S61QOyciUtcb7Oc1t99KySDYQLRb8OJSnK7dfCp 2MATAE3IhHXPqCYDXS09ymqBnGLJhxmt/QZ7M/s4F6qZ5sIr+THMULM7cIYGPTd7XPvu XoCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ABfllLMS; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id re19-20020a05620a8e1300b0077419b27787si805489qkn.177.2023.10.03.12.22.22 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 Oct 2023 12:22:22 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ABfllLMS; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnkxR-00054Y-VP; Tue, 03 Oct 2023 15:21:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qnkws-0004th-2a for qemu-devel@nongnu.org; Tue, 03 Oct 2023 15:20:53 -0400 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnkwT-0004eG-UK for qemu-devel@nongnu.org; Tue, 03 Oct 2023 15:20:49 -0400 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1c7373cff01so1235335ad.1 for ; Tue, 03 Oct 2023 12:20:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696360821; x=1696965621; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MD3OzDuuDGgXDQMB1J8iXNmpATULZDtwIUTwe03wb+E=; b=ABfllLMSoaA4iPE8tJXyJl5SB2E/2UKGesTeXJrLzkg39n0xKwqVg8Pq/9ZtiQWijk 64uldqz/Sol8WbmmIxj2mHx9tQe6FqTVZM1tDNkd4NtHkh+xCeq5KWk6cHwajL3l7kzW qumOz/8PzWY3+H53lbzMooP7xfKuMLIwl61KnnnNCNx+kCeFLi8IQ7dErKl0i/taw0/d ttH26pFF+wF25bktr2JzVgCEwqROtUHGgH//scM8bQfEu9F3uSrYAjUp6ZAuarj4JuMV rEqN2fK5mzir36TtE+qbAI2+MKAn5pyzFry4I0pxIB2xHYKjrD6nP1/+COjpy1cfO05Z v6/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696360821; x=1696965621; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MD3OzDuuDGgXDQMB1J8iXNmpATULZDtwIUTwe03wb+E=; b=Ij+auvVWAsjEX/LV6hLIUCcvMu/ObQ3UflWgT09NC0e6UoYLT8lmKdQbyL15rjTi1o 6/tH5oRj8+LvHip2uv5F3D7sNcFZ5huhw6EdM9hcdx3eLssIrasieShseeYwDtiGPggT +4sAYP0UOhXnMaqRWdrvesKQlt1hzzYam4XH/PQgGKoWywl8EmTgSaSSg5QarKhNtPKf 6UKiGcDen3kJwvyWcrG7+7tYM0prsDqY3DMCc2php82eZZhIY1wFmSkvJ0ybPfjc3aG7 xMIbhJqgIRdqorXbRSRmbgcsXJkesu1DtXor0wvl4SwH/6UsfqGxXoERsDN3JGVamxCT 6N4Q== X-Gm-Message-State: AOJu0YyIzcr05K9KnD2OF2wWJew1PHGGipz4Wcw8l5/+FVZg+NtTDwD+ AS2YceePLxCAfeebiEKuG8u5hHTfRV0wBkZ4ZXs= X-Received: by 2002:a17:902:db0a:b0:1c3:432f:9f69 with SMTP id m10-20020a170902db0a00b001c3432f9f69mr247445plx.23.1696360821237; Tue, 03 Oct 2023 12:20:21 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id w5-20020a170902d3c500b001c5fd2a28d3sm1978497plb.28.2023.10.03.12.20.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 12:20:20 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, deller@gmx.de Subject: [PATCH v5 8/9] linux-user: Detect and report host SIGILL, SIGFPE, SIGTRAP Date: Tue, 3 Oct 2023 12:20:11 -0700 Message-Id: <20231003192012.1674888-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231003192012.1674888-1-richard.henderson@linaro.org> References: <20231003192012.1674888-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62c; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01 autolearn=ham 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org These signals, when not spoofed via kill(), are always bugs. Use die_from_signal to report this sensibly. Signed-off-by: Richard Henderson --- linux-user/signal.c | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index 706b8ac7a7..b67077f320 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -796,6 +796,43 @@ void die_from_signal(siginfo_t *info) break; } break; + case SIGILL: + sig = "ILL"; + switch (info->si_code) { + case ILL_ILLOPC: + code = "ILLOPC"; + break; + case ILL_ILLOPN: + code = "ILLOPN"; + break; + case ILL_ILLADR: + code = "ILLADR"; + break; + case ILL_PRVOPC: + code = "PRVOPC"; + break; + case ILL_PRVREG: + code = "PRVREG"; + break; + case ILL_COPROC: + code = "COPROC"; + break; + } + break; + case SIGFPE: + sig = "FPE"; + switch (info->si_code) { + case FPE_INTDIV: + code = "INTDIV"; + break; + case FPE_INTOVF: + code = "INTOVF"; + break; + } + break; + case SIGTRAP: + sig = "TRAP"; + break; default: snprintf(sigbuf, sizeof(sigbuf), "%d", info->si_signo); sig = sigbuf; @@ -900,7 +937,8 @@ static void host_signal_handler(int host_sig, siginfo_t *info, void *puc) /* * Non-spoofed SIGSEGV and SIGBUS are synchronous, and need special - * handling wrt signal blocking and unwinding. + * handling wrt signal blocking and unwinding. Non-spoofed SIGILL, + * SIGFPE, SIGTRAP are always host bugs. */ if (info->si_code > 0) { switch (host_sig) { @@ -912,6 +950,10 @@ static void host_signal_handler(int host_sig, siginfo_t *info, void *puc) host_sigbus_handler(cpu, info, uc); sync_sig = true; break; + case SIGILL: + case SIGFPE: + case SIGTRAP: + die_from_signal(info); } } From patchwork Tue Oct 3 19:20:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 728821 Delivered-To: patch@linaro.org Received: by 2002:a05:6504:1305:b0:23f:8cfb:5ad7 with SMTP id s5csp43200lto; Tue, 3 Oct 2023 12:22:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFZIXnOOOnuWmICXHdyqmyl96FLe+ev+Gd0EN2p9+KQpB5Bl9IhbDsqBkZO40fVmW+KhYib X-Received: by 2002:a25:cf45:0:b0:d12:1094:2036 with SMTP id f66-20020a25cf45000000b00d1210942036mr186679ybg.43.1696360943003; Tue, 03 Oct 2023 12:22:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696360942; cv=none; d=google.com; s=arc-20160816; b=p9Ys2kS1cB8DTKxdHUk7gSzcEB24ZvWJxDXR+dNbeOsLxQ4O6oWzv/4fTA5xdUKyko 0IpZ0j8X5imuv14dbgou0Ys+Mj6ecuYfUfk9fhDPngsY9bw+JQsLwVQUn+nceX/hVzik mca2absnKzS/K0Q7TMhnC0g11qGptA+KfvWUp/6sWNd87+CSkwWJ1jOsVnncxR0MdiSp w1+ejlbljkYKgW94gsg0okqqI+R0YSl8UGXbAG8c6NIqENNzEH8TRxeXLmQAezkzTxoW /TZzJJw5pWqki8SM7DIDEv+7+0vgNpPd+E1D7dDLjLV8iA61hxmk7xzOp1kqwF4Q2hDn I2Pg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=1E71x8AOuJqRUKKSfRCBk7J7r5yvF1NZG8wQysx060w=; fh=YRZ+qgYKjKfO+J7iYLqJ+AhmJljeW1N2qgZkMPPeD1I=; b=YHsW8lN9NjIRt9IskKMsD8iHVLEC2MzrX4KLp0kt379wJA/nsrF/I1MLHr17ArZxUH dQwqRoh7+aykWxdbNv42U233h+/t3pHE2UKavu/LfXMmdFphg1uF3mgDAFTSdLfDbFrI 0RpzY1xcJY4VYgcmxI10ZJPLIzMNet4QqVjrLIbc6t44gjD2SB3/PiRo55X/prX3fp+5 dJAa9rQzBQABOCV4H4mNaVue4fMrLLXRPNI4BWUUCsvf3CBRG3Akg1PuKscE1Y6B27+i T4FcQvlq3oJ1iGEI9rJZPgjrIGemX6SNgDJ3M93daiLOZ4jwndkH64x93cSBEaGDLM+l Z+Cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bTaY7M1I; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id v4-20020a0c8e04000000b0064f80d285e7si797652qvb.275.2023.10.03.12.22.22 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 Oct 2023 12:22:22 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bTaY7M1I; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnkwk-0004qu-4G; Tue, 03 Oct 2023 15:20:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qnkwi-0004qY-Ek for qemu-devel@nongnu.org; Tue, 03 Oct 2023 15:20:40 -0400 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnkwT-0004eP-SU for qemu-devel@nongnu.org; Tue, 03 Oct 2023 15:20:40 -0400 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1c760b34d25so9924595ad.3 for ; Tue, 03 Oct 2023 12:20:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696360822; x=1696965622; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1E71x8AOuJqRUKKSfRCBk7J7r5yvF1NZG8wQysx060w=; b=bTaY7M1IZio59YDb9lQ1LY2aWuQtcJFOpjPbqB4xE91rORLXP+5zC63K43ZyrMH3ai Xc0DHz5hVxHPnfTLRXS6qzxsvajTYkNZfr4LSPZgSUV7SA4TTsWWPiBFt2L4bhLEzVt4 IUobM8beRAPxKRiPE3QLBNaHhMiTfG5NKsnUT/JLpgMrD1N/0F2M3esvXxQAUUGI34Vo xpUZIyALjlVZX+EUMx3g7o4lj6Rzvcdn89UDT7x5vB6TRXm/erBuiF+bBwmT5HiG/oDi gWlTY08wYSTqN8OgmGv/wo35+oN6ne+Q+og4sYHqyqKdRN8kLZ72haeNsNKkIdVOk7y4 bSkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696360822; x=1696965622; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1E71x8AOuJqRUKKSfRCBk7J7r5yvF1NZG8wQysx060w=; b=k9e5kVHZLHni8gW0YQY2EsdIP9UGd0EH+5m8ZSz+OxM5oRoliFlgZz4l1wbJYBpZoL 3ZRSN4gUN5HJbxPMauqp4Ys8CU2d6Ac0pXC+CQt4Nm1blL6OPuCZvbJiGNEWf4xvug8R HFn+0YpCsN2/awSVllkfcq3DLkhXR4jeoHN5midfdKvXg1y2d0kO1CxqhSFti+qA78e5 MvFI+LbqlKOwXMvywwTnulEt7SXEyak3EVf2x+STG7KXGHS0/lXPbejrcSECJ301SOIZ hyvdJXmNK2ypAuCV4WMadeiY+EKc/+XtciywzC3bYGXwCQB2eGamtcEGcoipByvql/yq WwFg== X-Gm-Message-State: AOJu0YxIA64eDrx7yw9PqjxsWc8w4xzMhezN3Cjq6qzzXlNpqemT7aPa GmIot8WkTIRh5S8LziUD5PYim5o2BqNUSXgcBKU= X-Received: by 2002:a17:902:d4cc:b0:1c3:c687:4793 with SMTP id o12-20020a170902d4cc00b001c3c6874793mr385252plg.63.1696360822094; Tue, 03 Oct 2023 12:20:22 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id w5-20020a170902d3c500b001c5fd2a28d3sm1978497plb.28.2023.10.03.12.20.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 12:20:21 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, deller@gmx.de Subject: [PATCH v5 9/9] linux-user: Remap guest SIGABRT Date: Tue, 3 Oct 2023 12:20:12 -0700 Message-Id: <20231003192012.1674888-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231003192012.1674888-1-richard.henderson@linaro.org> References: <20231003192012.1674888-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62d; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Distinguish host SIGABRT from guest SIGABRT by mapping the guest signal onto one of the host RT signals. This prevents a cycle by which a host assertion failure is caught and handled by host_signal_handler, queued for the guest, and then we attempt to continue past the host abort. What happens next depends on the host libc, but is neither good nor helpful. Signed-off-by: Richard Henderson --- linux-user/signal.c | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index b67077f320..b7f4ce3cb9 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -522,8 +522,16 @@ static void signal_table_init(void) * multiplexed over a single host signal. * Attempts for configure "missing" signals via sigaction will be * silently ignored. + * + * Remap the target SIGABRT, so that we can distinguish host abort + * from guest abort. */ - for (hsig = SIGRTMIN; hsig <= SIGRTMAX; hsig++) { + + hsig = SIGRTMIN; + host_to_target_signal_table[SIGABRT] = 0; + host_to_target_signal_table[hsig++] = TARGET_SIGABRT; + + for (; hsig <= SIGRTMAX; hsig++) { tsig = hsig - SIGRTMIN + TARGET_SIGRTMIN; if (tsig <= TARGET_NSIG) { host_to_target_signal_table[hsig] = tsig; @@ -582,13 +590,21 @@ void signal_init(void) int hsig = target_to_host_signal(tsig); abi_ptr thand = TARGET_SIG_IGN; - if (hsig < _NSIG) { - struct sigaction *iact = core_dump_signal(tsig) ? &act : NULL; + if (hsig >= _NSIG) { + continue; + } + /* As we force remap SIGABRT, cannot probe and install in one step. */ + if (tsig == TARGET_SIGABRT) { + sigaction(SIGABRT, NULL, &oact); + sigaction(hsig, &act, NULL); + } else { + struct sigaction *iact = core_dump_signal(tsig) ? &act : NULL; sigaction(hsig, iact, &oact); - if (oact.sa_sigaction != (void *)SIG_IGN) { - thand = TARGET_SIG_DFL; - } + } + + if (oact.sa_sigaction != (void *)SIG_IGN) { + thand = TARGET_SIG_DFL; } sigact_table[tsig - 1]._sa_handler = thand; } @@ -711,7 +727,12 @@ void dump_core_and_abort(CPUArchState *env, int target_sig) TaskState *ts = (TaskState *)cpu->opaque; int host_sig, core_dumped = 0; - host_sig = target_to_host_signal(target_sig); + /* On exit, undo the remapping of SIGABRT. */ + if (target_sig == TARGET_SIGABRT) { + host_sig = SIGABRT; + } else { + host_sig = target_to_host_signal(target_sig); + } trace_user_dump_core_and_abort(env, target_sig, host_sig); gdb_signalled(env, target_sig);