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); }