From patchwork Wed Oct 18 23:31:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 735172 Delivered-To: patch@linaro.org Received: by 2002:adf:f0cd:0:b0:32d:baff:b0ca with SMTP id x13csp1258544wro; Wed, 18 Oct 2023 16:33:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFQKxet1s3J9NzZNg8pa/5P/nzsvp2krwgabCNeF/5fkBuZdfk1XvEyksRrU4AP9OlJ6PTk X-Received: by 2002:a05:6122:3d0d:b0:49e:1be5:de9b with SMTP id ga13-20020a0561223d0d00b0049e1be5de9bmr595154vkb.5.1697672008477; Wed, 18 Oct 2023 16:33:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697672008; cv=none; d=google.com; s=arc-20160816; b=SClUnK0KuwjlF1wWpPPwWozt/vsb1/aG08cRrBMrgP34vjP6Seqa8hV5ZqHWkNgu40 W9yICntsib23nQpO/37yamE7yD6sOCXETQwt4pAKawYlwkXJXFiKHCUzpkzQjKHeQnwg LbvA/X4DorHY8KJC4FnMoufY5ex66yeraP0e+8umotUh8GOeBTUDtd+0Fd/w353eoo59 c3TVwdpO3yMj/1eTllkH+7b0gyFEZYgjjUBS0O2nJIWOW/X1HV/mAuRbHHPidUugWiPr cXK93Lv1c5weZh5k6Cq1FxDfoNdsU/If99fDyYJpXGmFXd1AKti2dl9USluAAoJcADW0 Ib4A== 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=ypG+ldHB73o41Fm0bO8P6h70i3rbf+HtP65cG8LvxlI=; fh=wDljmxUHXfz9MGj2//jPHYRc53BMWF157v8rVKELrf4=; b=VLCdzknaimfpo8JFY6IGP2+Dc7QVGZhP4RgP311emvytMjmB0j2kn/Le+Ys+t7fCBl DBxRgPGkT4oYocEPZKDbb8rHEYKWRhqX/p8lKVZXtwqWhcmyxvuRy1Vj6q+uNoN2JFve Pgw36MJ9b6iRmiia/9wCbqa34CmGjFwunhqERC81bPJqWAkWqleVCv8XNICQ2z3/S9hs O8T+E3k/qe+mEFBT0DPdr97wN8g+BKdJQwdQTFv+EXbkamKL8zpI9CWbwwnvWJovYqjP /cODsFO95W6ZO9hmDPw0DIjVJJdSk5AiFwDBleA6fVs+AZuymOwOLzSE2rBfwjW8r2HY zRLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pzG5zr46; 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 m22-20020a05622a119600b0041b83bbd0eesi800757qtk.43.2023.10.18.16.33.28 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 18 Oct 2023 16:33:28 -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=pzG5zr46; 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 1qtG11-00046k-NV; Wed, 18 Oct 2023 19:31:51 -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 1qtG0x-00045t-Hs for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:47 -0400 Received: from mail-oo1-xc2e.google.com ([2607:f8b0:4864:20::c2e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qtG0v-0000M3-T7 for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:47 -0400 Received: by mail-oo1-xc2e.google.com with SMTP id 006d021491bc7-57b5f0d658dso4313547eaf.0 for ; Wed, 18 Oct 2023 16:31:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697671904; x=1698276704; 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=ypG+ldHB73o41Fm0bO8P6h70i3rbf+HtP65cG8LvxlI=; b=pzG5zr46atE5QdTXGfnCBd4stxYeKsXYGtFMl7A8ZcxYviExjTX8HwCKlrFZHyy1AM An25RFjTnbph3IrIkomaYHFjIFBLDrFrRDnCJmQb+rhOaRfAG2yGiUnFTLwHx9NVDx9s EoB7PfHaWcjHHnK9s4CZlMKy4pG/PuzFKf7jvvQ6GRW9RURkJrRea7r/z8YLj/zDrHfs b9tOuklMN80IlPKTM20/138fG0qWP+hPBJmwIxbFGIrUHdhp9WkqK77vxhi+aDYVWoye iGKhNCGA3J31YZ11rRDVnuig1pTIVw4g9fatPC+yz0KYtuDr4EWfj4+neApcpjPIf+ny /KiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697671904; x=1698276704; 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=ypG+ldHB73o41Fm0bO8P6h70i3rbf+HtP65cG8LvxlI=; b=huRgmOl8U2DpvKbr2rksGBYlDU7rfvZZbMf8k0d0BKkwlQy0bF3rqK2yWNQMhYWjBR Xz4F5+ZmCc7LOmJR55ChtWw6i1XArRt6lIh5TzpFHaIoK53BcpJ02g6ob6KchThOgyzG eetAHwmZitSi1CwVWOo3lqSOG8WHo84O3D6Fn8w6O/jRWkup0Ro1CMBgGDnMqKw/ZMVE 5fXYO8F7jDqA+dUsNsnX4SgDexsiolpAD2JoxaAYd4snpXb/jUhkp4+3fsh7lpA5kT6d ctCUAZsllQKXwCg2wWbeIr26KPTQGep8UVUBU/+bX2Ef1REQpVVUVU+3xOKPfnWCEKxp D6EQ== X-Gm-Message-State: AOJu0YybdRJc/AhjxsuCsq257HTv9kIrtt0ypECm9QTlynrqQmKihRUw CHZfLgABzLE9RsOZPZLSaYTd+2xIhgbZg724qPI= X-Received: by 2002:a05:6358:ca6:b0:143:8084:e625 with SMTP id o38-20020a0563580ca600b001438084e625mr514122rwj.11.1697671904636; Wed, 18 Oct 2023 16:31:44 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id g9-20020aa796a9000000b006be5af77f06sm3881690pfk.2.2023.10.18.16.31.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 16:31:44 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller Subject: [PULL 11/14] linux-user: Simplify signal_init Date: Wed, 18 Oct 2023 16:31:31 -0700 Message-Id: <20231018233134.1594292-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231018233134.1594292-1-richard.henderson@linaro.org> References: <20231018233134.1594292-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::c2e; envelope-from=richard.henderson@linaro.org; helo=mail-oo1-xc2e.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 Install the host signal handler at the same time we are probing the target signals for SIG_IGN/SIG_DFL. Ignore unmapped target signals. Acked-by: Helge Deller 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; } }