From nobody Thu Nov 28 12:40:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1692767933; cv=none; d=zohomail.com; s=zohoarc; b=DONc/HI24d+8kDVQaeXJJOSkrK1b7sWGwbRDIPN0v9CwNpJxk+ghTcr11Cl2PLLI74PSOooxJyVArQowCNQrqu6H5aS+lzxk6jRth4V4aRiCEr9nJNPKVILBhOaHHgeWsmgZMo1KcQlC93hqIx06Conhfx1tlWTAdtBkfzfsUZs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692767933; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=M9nEQb22Vi1UF1dUb8GzU/CvfTl2MHdw8gP+pRmxf80=; b=fBIcFWEm+mfTSRvFSygapQ+NOHPwk3yhq7SajZS/Q31nRyTQaOO8ln5NEoqLkNotEDbn6HSx+s/hmS7779aOcfzmoW2YZf6KOPQz7zoN5Vvcq17NqcOQ+3Fovocy0h52oi7jlzRczoq70il6XRPD3m+DIxU6xY6ZQSAE2HRKxxY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1692767933080686.2709058057147; Tue, 22 Aug 2023 22:18:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qYgEJ-0004xF-0W; Wed, 23 Aug 2023 01:16: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 1qYgEI-0004x3-4h for qemu-devel@nongnu.org; Wed, 23 Aug 2023 01:16:30 -0400 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qYgEF-0000tY-OV for qemu-devel@nongnu.org; Wed, 23 Aug 2023 01:16:29 -0400 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1bf092a16c9so41295065ad.0 for ; Tue, 22 Aug 2023 22:16:27 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:4e3c:f4a4:b92a:b5ab]) by smtp.gmail.com with ESMTPSA id 5-20020a170902c24500b001bf044dc1a6sm9969402plg.39.2023.08.22.22.16.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Aug 2023 22:16:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692767786; x=1693372586; 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=M9nEQb22Vi1UF1dUb8GzU/CvfTl2MHdw8gP+pRmxf80=; b=We7ZcoypwsN83nU6AT5pA20G536fzY+1J2h4IpXAX71VdWXYQtHCAER4NrfgcjHio5 lCMJMcnHr2aadKYU7HPMAbFVcFNrjDESez0TNr4O8IdKmJL3OJpnrqhtbUZYJ69wXhyg hQO+1zZ8oQ+VF7DgH04DKAkYhF/Xjvebu3ioScYsH23nzRwaucuXvhQMNkvJ9NqoWhRp dJ1F5ztB7EbLXZez1xKxEMtL7igjP4K6sNqoF8yCxOuEBugliqp9IYgoO4Lk8TAuCtGm CyCUEbjTtyGLR2SiZibNxpEH8CLt5g5ggq5Q4pjgLDaxrzculvsujmaoZPvNrg/uOpsZ eAGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692767786; x=1693372586; 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=M9nEQb22Vi1UF1dUb8GzU/CvfTl2MHdw8gP+pRmxf80=; b=FV3zl3f+j0aN6VXqZnvw8izfg9Qey8Po6sX135mlk4bR0yR1o1fTHmRnEoe9/NT/0E /7gBaEx1i3eWGYiAbdZf9j0GdbzLYX4jkHySrDh2J5ThmGU1iY9FTUioDlCQ4m0ol1PJ yIgpKMEsmKJz4hogLmr9Xc9qWw+Qvyz3UcTo7JuRSnSYr/mEpLLMgPbOt3TpBQipeOTk jllBOnixtqCcOQBFsWc6ExDKcBk2SVSEkGS2Q5ZEbYbnLvwRMgATj5MBBNgqsv8qR4dK ZuG5RDFfGklz9nj5UoW7M/CaxMZSw5dzAfr5ne36ELPBD6GjsqPGmN+6E6o81UjlA/k+ znGw== X-Gm-Message-State: AOJu0YzNMmGF8x9amR/q8Hc5QNUdqfiKo7+nTK/8IM8wMbyXDMqHKt7G 8cvT5YBp4VvhkzYxaz2dNRqsrh0hms2kM0PmCrs= X-Google-Smtp-Source: AGHT+IGJWyotsnHwY8d/tMB6caCv3Eo6WunSEkwjO0X0HUmV2t06DDBOzNVVeNlkCt9G3esVPbJ2+Q== X-Received: by 2002:a17:902:e846:b0:1b9:e241:ad26 with SMTP id t6-20020a170902e84600b001b9e241ad26mr14829987plg.9.1692767786328; Tue, 22 Aug 2023 22:16:26 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: deller@gmx.de Subject: [PATCH v4 08/10] linux-user: Simplify signal_init Date: Tue, 22 Aug 2023 22:16:13 -0700 Message-Id: <20230823051615.1297706-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230823051615.1297706-1-richard.henderson@linaro.org> References: <20230823051615.1297706-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62b; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62b.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1692767933728100002 Content-Type: text/plain; charset="utf-8" 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 | 47 +++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index b8913968cc..a6917eadd8 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -566,10 +566,7 @@ static void signal_table_init(void) void signal_init(void) { TaskState *ts =3D (TaskState *)thread_cpu->opaque; - struct sigaction act; - struct sigaction oact; - int i; - int host_sig; + struct sigaction act, oact; =20 /* initialize signal conversion tables */ signal_table_init(); @@ -580,28 +577,28 @@ void signal_init(void) sigfillset(&act.sa_mask); act.sa_flags =3D SA_SIGINFO; act.sa_sigaction =3D host_signal_handler; - for(i =3D 1; i <=3D TARGET_NSIG; i++) { -#ifdef CONFIG_GPROF - if (i =3D=3D TARGET_SIGPROF) { - continue; - } -#endif - host_sig =3D target_to_host_signal(i); - sigaction(host_sig, NULL, &oact); - if (oact.sa_sigaction =3D=3D (void *)SIG_IGN) { - sigact_table[i - 1]._sa_handler =3D TARGET_SIG_IGN; - } else if (oact.sa_sigaction =3D=3D (void *)SIG_DFL) { - sigact_table[i - 1]._sa_handler =3D 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 =3D 1; tsig <=3D TARGET_NSIG; tsig++) { + int hsig =3D target_to_host_signal(tsig); + abi_ptr thand =3D TARGET_SIG_IGN; + + if (hsig < _NSIG) { + struct sigaction *iact =3D core_dump_signal(tsig) ? &act : NUL= L; + + sigaction(hsig, iact, &oact); + if (oact.sa_sigaction !=3D (void *)SIG_IGN) { + thand =3D TARGET_SIG_DFL; + } } + sigact_table[tsig - 1]._sa_handler =3D thand; } } =20 --=20 2.34.1