From patchwork Tue Feb 4 17:10:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 11365059 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 870AB138D for ; Tue, 4 Feb 2020 17:27:05 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 66ECD2087E for ; Tue, 4 Feb 2020 17:27:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 66ECD2087E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=vivier.eu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:35045 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iz1ya-0002o5-HT for patchwork-qemu-devel@patchwork.kernel.org; Tue, 04 Feb 2020 12:27:04 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54881) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iz1jf-00077o-70 for qemu-devel@nongnu.org; Tue, 04 Feb 2020 12:11:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iz1je-0001aE-8s for qemu-devel@nongnu.org; Tue, 04 Feb 2020 12:11:39 -0500 Received: from mout.kundenserver.de ([212.227.126.187]:44553) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iz1jd-0001Vn-VR for qemu-devel@nongnu.org; Tue, 04 Feb 2020 12:11:38 -0500 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue009 [212.227.15.167]) with ESMTPSA (Nemesis) id 1N7Qp3-1jbANI0sk1-017j0m; Tue, 04 Feb 2020 18:11:05 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PATCH v2 1/4] linux-user: add missing TARGET_SIGRTMIN for hppa Date: Tue, 4 Feb 2020 18:10:50 +0100 Message-Id: <20200204171053.1718013-2-laurent@vivier.eu> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200204171053.1718013-1-laurent@vivier.eu> References: <20200204171053.1718013-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:Hez+TaxwiZ2OgXOrVQURJqgTRNhu9vhh7IwL997qbImZdCkSOCO iL6DaVN84nP1Qf3a/Ly0FdaMtAmx50E/b88LiKp/wCw/nLFKXGYKTDnioS+NwI1Qj44HKkJ 8T6POmK3KbeWyZqb+ZUdGKHeo2IdrZx9krBPtu1ckb56eO6RShIw/CUvmwNNJKyeT9fIlEN FjE6DeankRszdfUuKfeRA== X-UI-Out-Filterresults: notjunk:1;V03:K0:5iRV4ZfC85o=:knBopFuukOzK23u//SFYxe UO1M8apNQ3nDB/f0AiaFJmKGpdB7U9xtzw65maA4UqqyVYgzwpSAd9TolSYkOUg+RD3NrrnCC i/2kpaWdoacdheYHq/powQ0rha8ZDauA6RNrUw4tcMuH1ZnBml98cp8stcdMhX1KYnq6mgpDs tHqTdOY0kWLafPKHMo2tZnxuSj2ZNx6hJjy9Jvsv0diE70PUPoS2xcWkGZD2jOIoiNjccFWYv YxskVKZ/mAADfEJlQkE/z2mWf6v7fv65ZJh4Xyhno7YbF/8uwdFTur4WynXgU7Mfbbit2TEoe JzeR2bNDcobCdzAr+0hiinFK38H+SHAZLTxLRns08L8pzhg7cZJRHq5BJvohTMYMoOEnXAZoX DdPBcZArNQb5ezCPa7tO7FRQSgwSJL3nCTZ+kWy55MC3qnpB3vSEGUp09s9OW6hMcs7vONPFl 3zN2gDDUVQcSnIpSHrKQDwbN9ZbJpjNlwv1j/iHXkd9dpfnhewpY6UTxTfWhSPYwNXdZG1Zev 33hl2Q5ixGtyN1mWK9v+zfNxBZusZvzk4Hi2iuGM5M2Di2pqNvfCMtojdVCHahfzG+7kp2xcg EkVYH93FFRGpNsjGiBTxKhpYrf0NZmjkxyThU91Mg2/ROuxU2HbbmSZAZkZmyhvllp+oNan4d 5vhKQ+ORQKJHRtcrGDa4tHH5HGbkNPseHA+kP1YHwEboHtSVl0v3uIVsK12dd6riPMzS3fjpH bofM5+5L0EfhWVWZTa/FYcws8nma+X0rv4hBMLlDDd2iXYMHgnVtq1SVYkq0zJsGb7uGu9FAp AFVd3KMxTGgBqtNPefB0V+Fh3Cbf3/XMkMtNTgVZTsIVzzfIQhaHB7wFUEV9VaUOIwFRElp X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.126.187 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Marlies Ruck , Riku Voipio , Laurent Vivier , Aleksandar Markovic , Josh Kunz , Taylor Simpson , Matus Kysel , milos.stojanovic@rt-rk.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" This signal is defined for all other targets and we will need it later Signed-off-by: Laurent Vivier Reviewed-by: Peter Maydell --- linux-user/hppa/target_signal.h | 1 + 1 file changed, 1 insertion(+) diff --git a/linux-user/hppa/target_signal.h b/linux-user/hppa/target_signal.h index ba159ff8d006..c2a0102ed73d 100644 --- a/linux-user/hppa/target_signal.h +++ b/linux-user/hppa/target_signal.h @@ -34,6 +34,7 @@ #define TARGET_SIGURG 29 #define TARGET_SIGXFSZ 30 #define TARGET_SIGSYS 31 +#define TARGET_SIGRTMIN 32 #define TARGET_SIG_BLOCK 0 #define TARGET_SIG_UNBLOCK 1 From patchwork Tue Feb 4 17:10:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 11365061 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 34773186E for ; Tue, 4 Feb 2020 17:27:57 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 15C072082E for ; Tue, 4 Feb 2020 17:27:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 15C072082E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=vivier.eu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:35064 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iz1zQ-0005kJ-8B for patchwork-qemu-devel@patchwork.kernel.org; Tue, 04 Feb 2020 12:27:56 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54888) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iz1jf-00078Y-FR for qemu-devel@nongnu.org; Tue, 04 Feb 2020 12:11:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iz1je-0001aL-9J for qemu-devel@nongnu.org; Tue, 04 Feb 2020 12:11:39 -0500 Received: from mout.kundenserver.de ([212.227.126.130]:37669) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iz1jd-0001VE-Vp for qemu-devel@nongnu.org; Tue, 04 Feb 2020 12:11:38 -0500 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue009 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MbAYi-1jVtZL1IHg-00bdxB; Tue, 04 Feb 2020 18:11:07 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PATCH v2 2/4] linux-user: cleanup signal.c Date: Tue, 4 Feb 2020 18:10:51 +0100 Message-Id: <20200204171053.1718013-3-laurent@vivier.eu> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200204171053.1718013-1-laurent@vivier.eu> References: <20200204171053.1718013-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:EIm9a7+YzWA3RVuwlOMtseaQqYUyH2rlaronjAq9JvijJ1zS0yS 8kHGZY0eectH8FzOeo0O4if6eeeY8cXebK4aJQ8yx6LXnBGIk8xgJ2J4fkb+Zz4KBM4+H4+ KVsdYdlciyJhWRVZR1VM3jOAC6ZvzvRoSOn4fc5kiyqif+v6Q3CGGPlrGFT63jTUrMNge7P zlg7IkIchuu3l0vkxYJ4w== X-UI-Out-Filterresults: notjunk:1;V03:K0:LzrnhUWiL+k=:dAjJzbjW3JWg0JyGqsCeBN 3NIMm08WHB9KoJL/DcsWZltc6A5bmTOqt+ttgr2rosYEu2kKA5uH4vbirRMmmCT0TNdu3ec18 zUAy0W2+OPg+QWprGmVrb3kCi6XWT35SNJAsVKzeFDG0shD4d+qsouFg6E9uXGn3joA7nTSGq IalWl8XmTj0NrmTTJGviz4b4U9Rw52zeSrQ3vZS1/9/+RdBpMxNyg2i4JQBPkQhBrGSCojA8y VBUcahRDMDryTdXIrCd7LWxsjSTs9rwRLXmvEmDCndlzx9stImIdST5fe2dlnuGI74t4rCsaV mT1Day3DAgyHF92d3k904uyM6QXAjtvpoI4KprKNBp+6ASwJQ+FlW6b33S5Li6LG/XuTuxmMs 6T4+jCVL2wexGoWRZH+WZDbhD/A3MOq5xDwSnM+qhUtcAHbmjEA8BFPc3xv2AtI5BOO1CJ3+r 3hLYKgrmdURfKt72SDUHcgm2lVtYE0yFSjpPIKeLcy+3RB+7HFg74sc+/yH4oyQGhQfYeYrAx qxRpxJXqorHQMA2oe9n/61pqcY9asNgnFxw6h9z8i6pML14oQsxd54CuG1iCxCSRfz6LmgzTD GdVFRZ48032kWrMc4ThhMsR63Uk2rO7Pxn66OLQtB5D1TiKezJIQ6c4P4iyHYwTG+/kQG9m9S YMPXh0+EcHyYoTxtkFprRQvnZV6Us0bfQ3kf3DdujtV4pnKwxXHMFv+kpEfyRmRwZbIUn/UTQ BIV4/ja2ZSn2TpHQUmzuF82nnMu3rQa8tQBasJGWJomyfifGxWvptExNFLGT+MlQZsMCYPIhz Aqyulin0zsdGMElBc2RQShyIgxt7pMlkwEWKirT0GvxbqmLXx8dAidXy2ZRH12xfE1N23kg X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.126.130 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Marlies Ruck , Riku Voipio , Laurent Vivier , Aleksandar Markovic , Josh Kunz , Taylor Simpson , Matus Kysel , milos.stojanovic@rt-rk.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" No functional changes. Prepare the field for future fixes. Remove memset(.., 0, ...) that is useless on a static array Signed-off-by: Laurent Vivier Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Peter Maydell --- Notes: v2: replace i, j by target_sig, host_sig linux-user/signal.c | 48 ++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index 5ca6d62b15d3..246315571c09 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -66,12 +66,6 @@ static uint8_t host_to_target_signal_table[_NSIG] = { [SIGPWR] = TARGET_SIGPWR, [SIGSYS] = TARGET_SIGSYS, /* next signals stay the same */ - /* Nasty hack: Reverse SIGRTMIN and SIGRTMAX to avoid overlap with - host libpthread signals. This assumes no one actually uses SIGRTMAX :-/ - To fix this properly we need to do manual signal delivery multiplexed - over a single host signal. */ - [__SIGRTMIN] = __SIGRTMAX, - [__SIGRTMAX] = __SIGRTMIN, }; static uint8_t target_to_host_signal_table[_NSIG]; @@ -480,31 +474,45 @@ static int core_dump_signal(int sig) } } +static void signal_table_init(void) +{ + int host_sig, target_sig; + + /* + * Nasty hack: Reverse SIGRTMIN and SIGRTMAX to avoid overlap with + * host libpthread signals. This assumes no one actually uses SIGRTMAX :-/ + * To fix this properly we need to do manual signal delivery multiplexed + * over a single host signal. + */ + host_to_target_signal_table[__SIGRTMIN] = __SIGRTMAX; + host_to_target_signal_table[__SIGRTMAX] = __SIGRTMIN; + + /* generate signal conversion tables */ + 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; + } + } + for (host_sig = 1; host_sig < _NSIG; host_sig++) { + target_sig = host_to_target_signal_table[host_sig]; + target_to_host_signal_table[target_sig] = host_sig; + } +} + void signal_init(void) { TaskState *ts = (TaskState *)thread_cpu->opaque; struct sigaction act; struct sigaction oact; - int i, j; + int i; int host_sig; - /* generate signal conversion tables */ - for(i = 1; i < _NSIG; i++) { - if (host_to_target_signal_table[i] == 0) - host_to_target_signal_table[i] = i; - } - for(i = 1; i < _NSIG; i++) { - j = host_to_target_signal_table[i]; - target_to_host_signal_table[j] = i; - } + /* initialize signal conversion tables */ + signal_table_init(); /* Set the signal mask from the host mask. */ sigprocmask(0, 0, &ts->signal_mask); - /* set all host signal handlers. ALL signals are blocked during - the handlers to serialize them. */ - memset(sigact_table, 0, sizeof(sigact_table)); - sigfillset(&act.sa_mask); act.sa_flags = SA_SIGINFO; act.sa_sigaction = host_signal_handler; From patchwork Tue Feb 4 17:10:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 11365071 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D7924112B for ; Tue, 4 Feb 2020 17:31:53 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B852C2082E for ; Tue, 4 Feb 2020 17:31:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B852C2082E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=vivier.eu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:35186 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iz23E-0005ns-VR for patchwork-qemu-devel@patchwork.kernel.org; Tue, 04 Feb 2020 12:31:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54928) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iz1jh-0007ET-OJ for qemu-devel@nongnu.org; Tue, 04 Feb 2020 12:11:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iz1jg-0001g9-I7 for qemu-devel@nongnu.org; Tue, 04 Feb 2020 12:11:41 -0500 Received: from mout.kundenserver.de ([212.227.126.135]:52539) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iz1jg-0001dh-8l for qemu-devel@nongnu.org; Tue, 04 Feb 2020 12:11:40 -0500 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue009 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MWzXd-1j10k811lR-00XIGO; Tue, 04 Feb 2020 18:11:09 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PATCH v2 3/4] linux-user: fix TARGET_NSIG and _NSIG uses Date: Tue, 4 Feb 2020 18:10:52 +0100 Message-Id: <20200204171053.1718013-4-laurent@vivier.eu> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200204171053.1718013-1-laurent@vivier.eu> References: <20200204171053.1718013-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:89wBAKLTrp+zE9n8im8ri/9yJNtqGZYzXt8qUsE6KXQlMfNu2oh UuwYixD6UQ3NIQ99Eam1WxfBV5mqRrfVSdaimdgs4WEnZkfW2XXwU/H45Jbq25r3Wn8s1Vo QwKi4TokRVvuJClEIVg39AN2LL2FVzOeFA13rj7+hK60bT5wPC4o0XAYnBvWyCgS8OMxL0D uY/QiR4qySyXW9QpABBPg== X-UI-Out-Filterresults: notjunk:1;V03:K0:d4XJ6fcvKvY=:Wx0oyMpPw3fsH+LhQhwbnb SH8UrckX18+W0/t0cShLetRBA0/K5kqHkuRDZb2a6rkPkIzcu01zaj0eiC8bZ5XeyKKxnVYnR 5OkbZ/jUvvA4S9OWa3Ded8PmJ7nTLL+nMWbD+63omzG+svXGEJlri8lkaYx68wAGMpfGIH7Kg 60w0dkymF4crKCGa6RSm1riI48UiqlrSWR7PFe8huFB+qfurCGJVf2rzG3RcW9WsBlyCu6HUx BhpXkl91orLf26hzjfVpXICuThD2Tl9Nzsxq3JjHxvtoa5Nq2HjOufte/xJv8QJVFh3O/UgmY jRbRGI9Ckq578t6BwRTPNR4n5JWrKstyXCEqMFB07S41X2MLUKL/+rpjnlDceNv6RjyuwOrfL OW6d84KPpFxaNYpJwtr5RRDMlEVkCDFX3kwZCyihwcYWIpZqnceU2lx38DaVn6TJ+30XLaTJu eNGuCynNMiYnBcG1K4OyzAiougEn4iAwLhgMCAhu/b5pE1zZB2+mcLChqFD8hLBx7B+/I932q mSTNLqllsNBU9NNxDo9W877YKN2i3kvrkzpQqXdHpEOwOmCC3JhDbI+rhv+hggviB4iwuD3af d0ONxWizbEFaW4jdaAb20koqKTQkrqIs0vMoObAiK0w2lFP0O/SOMtqtGDQdYUNVOTpxAwXtU YsPo7feAhPaxy5uja7TNEow3mnxTYJJYmzeaWWWzhBqjQUiyrlBcFwqhHcnhI5aq+qtaKaHM9 0C9R8LsTrKIXYfWjNozusLIDwjOzU2dg/Ex+rMpW8esxCRhPSDSNseMu3qv4FW8y/v8skw3jn KXvuaDt0Qo9T65dZaSE1EP2HqeSfqPjuFhSYrDa3/DlFR0i2O/jfM0LfrcyY53FbUQPCkUw X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.126.135 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Marlies Ruck , Riku Voipio , Laurent Vivier , Aleksandar Markovic , Josh Kunz , Taylor Simpson , Matus Kysel , milos.stojanovic@rt-rk.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Valid signal numbers are between 1 (SIGHUP) and SIGRTMAX. System includes define _NSIG to SIGRTMAX + 1, but QEMU (like kernel) defines TARGET_NSIG to TARGET_SIGRTMAX. Fix all the checks involving the signal range. Signed-off-by: Laurent Vivier Reviewed-by: Peter Maydell --- Notes: v2: replace i, j by target_sig, host_sig linux-user/signal.c | 52 ++++++++++++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index 246315571c09..c1e664f97a7c 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -30,6 +30,15 @@ static struct target_sigaction sigact_table[TARGET_NSIG]; static void host_signal_handler(int host_signum, siginfo_t *info, void *puc); + +/* + * 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 + * Signal number 0 is reserved for use as kill(pid, 0), to test whether + * a process exists without sending it a signal. + */ +QEMU_BUILD_BUG_ON(__SIGRTMAX + 1 != _NSIG); static uint8_t host_to_target_signal_table[_NSIG] = { [SIGHUP] = TARGET_SIGHUP, [SIGINT] = TARGET_SIGINT, @@ -67,19 +76,24 @@ static uint8_t host_to_target_signal_table[_NSIG] = { [SIGSYS] = TARGET_SIGSYS, /* next signals stay the same */ }; -static uint8_t target_to_host_signal_table[_NSIG]; +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 < 0 || sig >= _NSIG) + if (sig < 1 || sig >= _NSIG) { return sig; + } return host_to_target_signal_table[sig]; } +/* valid sig is between 1 and TARGET_NSIG */ int target_to_host_signal(int sig) { - if (sig < 0 || sig >= _NSIG) + if (sig < 1 || sig > TARGET_NSIG) { return sig; + } return target_to_host_signal_table[sig]; } @@ -100,11 +114,15 @@ static inline int target_sigismember(const target_sigset_t *set, int signum) void host_to_target_sigset_internal(target_sigset_t *d, const sigset_t *s) { - int i; + int host_sig, target_sig; target_sigemptyset(d); - for (i = 1; i <= TARGET_NSIG; i++) { - if (sigismember(s, i)) { - target_sigaddset(d, host_to_target_signal(i)); + for (host_sig = 1; host_sig < _NSIG; host_sig++) { + target_sig = host_to_target_signal(host_sig); + if (target_sig < 1 || target_sig > TARGET_NSIG) { + continue; + } + if (sigismember(s, host_sig)) { + target_sigaddset(d, target_sig); } } } @@ -122,11 +140,15 @@ void host_to_target_sigset(target_sigset_t *d, const sigset_t *s) void target_to_host_sigset_internal(sigset_t *d, const target_sigset_t *s) { - int i; + int host_sig, target_sig; sigemptyset(d); - for (i = 1; i <= TARGET_NSIG; i++) { - if (target_sigismember(s, i)) { - sigaddset(d, target_to_host_signal(i)); + for (target_sig = 1; target_sig <= TARGET_NSIG; target_sig++) { + host_sig = target_to_host_signal(target_sig); + if (host_sig < 1 || host_sig >= _NSIG) { + continue; + } + if (target_sigismember(s, target_sig)) { + sigaddset(d, host_sig); } } } @@ -492,10 +514,10 @@ static void signal_table_init(void) if (host_to_target_signal_table[host_sig] == 0) { host_to_target_signal_table[host_sig] = host_sig; } - } - for (host_sig = 1; host_sig < _NSIG; host_sig++) { target_sig = host_to_target_signal_table[host_sig]; - target_to_host_signal_table[target_sig] = host_sig; + if (target_sig <= TARGET_NSIG) { + target_to_host_signal_table[target_sig] = host_sig; + } } } @@ -518,7 +540,7 @@ void signal_init(void) act.sa_sigaction = host_signal_handler; for(i = 1; i <= TARGET_NSIG; i++) { #ifdef TARGET_GPROF - if (i == SIGPROF) { + if (i == TARGET_SIGPROF) { continue; } #endif From patchwork Tue Feb 4 17:10:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 11365069 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 49BD9139A for ; Tue, 4 Feb 2020 17:30:50 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 29D622087E for ; Tue, 4 Feb 2020 17:30:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 29D622087E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=vivier.eu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:35150 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iz22D-000471-8d for patchwork-qemu-devel@patchwork.kernel.org; Tue, 04 Feb 2020 12:30:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54959) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iz1jl-0007OS-Ds for qemu-devel@nongnu.org; Tue, 04 Feb 2020 12:11:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iz1jk-0001pY-5R for qemu-devel@nongnu.org; Tue, 04 Feb 2020 12:11:45 -0500 Received: from mout.kundenserver.de ([212.227.126.134]:36621) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iz1jj-0001ma-SJ for qemu-devel@nongnu.org; Tue, 04 Feb 2020 12:11:44 -0500 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue009 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MStKw-1j7JjN2GLe-00UFah; Tue, 04 Feb 2020 18:11:12 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PATCH v2 4/4] linux-user: fix use of SIGRTMIN Date: Tue, 4 Feb 2020 18:10:53 +0100 Message-Id: <20200204171053.1718013-5-laurent@vivier.eu> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200204171053.1718013-1-laurent@vivier.eu> References: <20200204171053.1718013-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:VGnP/pTFnc8m9VvJBOJmv749YqgIDfWpmBAn8fYK+N/GwdhnQ9H ubNYF8APtbkxvfTv17RJmmLrKAQ+bPUAL68NB1b7PiQIVxsT+kjgS0Op7Dl/4J14sS0vqFX 8fu59HBOe3Op8gZBAkNlUOxu1unrp3xvWQxG5NMkTMnhyT0qYvYXDKaVM+FFjMj15fEu8qx EESvlw3afQYWUuOE7pDlg== X-UI-Out-Filterresults: notjunk:1;V03:K0:Tm4l63WDylA=:9QvhemgoUWUkKSYE7PUrB9 xKpF+N2QBwGsL4+8PAE/XVqeLb33nHkSoSBlBBJ/YZC2ie2zxCI731bVS8cKKdYZdrirJVLyd DJYeWSOduBD481PSrdfYObzn5Nn1DemF9kSgdk7nFNqRCmjrxFw/RCKp3DnQY9xMU6MJU49WM DgMQqq5AHMbld41/8hyQaG4l5y5wx2RR994Pga4WJulg5Qm5+DxZsqSFmt3g6SL51Zkj4TbrP fg5neaGjpHzXrFI9N5VDleZCX/OoRk5lz1GGqt1wW6YewpX5wkXWa2DX7Bk7SP4hZhgsGUqi7 WhaEw05Y/GXuV/1SnE+NtT9ZkOmE1WiEI0XV9Ojkv44ZZf/2ielRVMvN+qathamTL6nMySHCO J5Xzoknxs98kYVk3nXMuxnnWfiJHPO4fkq+jDAiZHnLEnhT1pgy6mDQwo0jT5/0BbjEZu8QKE PQeY2okPDpfK6FXwviJU1ZMvoogOg/oc9vKnzcw+onMz933ePOzQj6QyvmCsLT5bFiyamuUnJ qz65g2CA48PqOMRnLeKVOrqf7YtSvpPbFwdnWnLRAx+flvVPFlTGhJlfjIwA3kG032NSGw1MR 7h1T1Pk1EtRT5Bh9TtX0e5geo+qC2ROdGs06Pkwc8O1jlQBYlLTG30EkdCDitzQLSBf5OC851 Byqxd4eiO2PumNzBHzK3Rb5KY0diqq2fGKdNnejgKQ9em5YmSQNPRGiQuIZ2y2uqoJEN9FSpb eMcVB2ldfTzHva+7rabLqJB81GSOaUHX6ZtB8Gd4Fsg9ooW/7SEG5WcXhFZK3cmv4bbEWl7nM 7u/L88QTIAWLcxW3gAhWyeQPFsgL72NkT78ksV1I1KCePurcRcjtCnw3XQfYlEydxPGJKCX X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.126.134 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Marlies Ruck , Riku Voipio , Laurent Vivier , Aleksandar Markovic , Josh Kunz , Taylor Simpson , Matus Kysel , milos.stojanovic@rt-rk.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Some RT signals can be in use by glibc, it's why SIGRTMIN (34) is generally greater than __SIGRTMIN (32). So SIGRTMIN cannot be mapped to TARGET_SIGRTMIN. Instead of swapping only SIGRTMIN and SIGRTMAX, map all the range [TARGET_SIGRTMIN ... TARGET_SIGRTMAX - X] to [__SIGRTMIN + X ... SIGRTMAX ] (SIGRTMIN is __SIGRTMIN + X). Signed-off-by: Laurent Vivier Reviewed-by: Taylor Simson --- Notes: v2: ignore error when target sig <= TARGET_NSIG but host sig > SIGRTMAX replace i, j by target_sig, host_sig update signal_table_init() trace message linux-user/signal.c | 37 ++++++++++++++++++++++++++++++------- linux-user/trace-events | 3 +++ 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index c1e664f97a7c..e7e5581a016f 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -498,18 +498,23 @@ static int core_dump_signal(int sig) static void signal_table_init(void) { - int host_sig, target_sig; + int host_sig, target_sig, count; /* - * Nasty hack: Reverse SIGRTMIN and SIGRTMAX to avoid overlap with - * host libpthread signals. This assumes no one actually uses SIGRTMAX :-/ - * To fix this properly we need to do manual signal delivery multiplexed - * over a single host signal. + * some RT signals can be in use by glibc, + * it's why SIGRTMIN (34) is generally greater than __SIGRTMIN (32) */ - host_to_target_signal_table[__SIGRTMIN] = __SIGRTMAX; - host_to_target_signal_table[__SIGRTMAX] = __SIGRTMIN; + 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; + } + } /* 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; @@ -519,6 +524,15 @@ static void signal_table_init(void) target_to_host_signal_table[target_sig] = host_sig; } } + + if (TRACE_SIGNAL_TABLE_INIT_BACKEND_DSTATE()) { + for (target_sig = 1, count = 0; target_sig <= TARGET_NSIG; target_sig++) { + if (target_to_host_signal_table[target_sig] == _NSIG) { + count++; + } + } + trace_signal_table_init(count); + } } void signal_init(void) @@ -817,6 +831,8 @@ int do_sigaction(int sig, const struct target_sigaction *act, int host_sig; int ret = 0; + trace_signal_do_sigaction_guest(sig, TARGET_NSIG); + if (sig < 1 || sig > TARGET_NSIG || sig == TARGET_SIGKILL || sig == TARGET_SIGSTOP) { return -TARGET_EINVAL; } @@ -847,6 +863,13 @@ int do_sigaction(int sig, const struct target_sigaction *act, /* we update the host linux signal state */ host_sig = target_to_host_signal(sig); + trace_signal_do_sigaction_host(host_sig, TARGET_NSIG); + if (host_sig > SIGRTMAX) { + /* we don't have enough host signals to map all target signals */ + qemu_log_mask(LOG_UNIMP, "Unsupported target signal #%d, ignored\n", + sig); + return 0; + } if (host_sig != SIGSEGV && host_sig != SIGBUS) { sigfillset(&act1.sa_mask); act1.sa_flags = SA_SIGINFO; diff --git a/linux-user/trace-events b/linux-user/trace-events index f6de1b8befc0..0296133daeb6 100644 --- a/linux-user/trace-events +++ b/linux-user/trace-events @@ -1,6 +1,9 @@ # See docs/devel/tracing.txt for syntax documentation. # signal.c +signal_table_init(int i) "number of unavailable signals: %d" +signal_do_sigaction_guest(int sig, int max) "target signal %d (MAX %d)" +signal_do_sigaction_host(int sig, int max) "host signal %d (MAX %d)" # */signal.c user_setup_frame(void *env, uint64_t frame_addr) "env=%p frame_addr=0x%"PRIx64 user_setup_rt_frame(void *env, uint64_t frame_addr) "env=%p frame_addr=0x%"PRIx64