From patchwork Sat Feb 1 12:27:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 1232237 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=vivier.eu 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 ozlabs.org (Postfix) with ESMTPS id 488tgW2JJKz9s1x for ; Sat, 1 Feb 2020 23:29:11 +1100 (AEDT) Received: from localhost ([::1]:45616 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ixrtd-0001Ym-8k for incoming@patchwork.ozlabs.org; Sat, 01 Feb 2020 07:29:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51797) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ixrsy-0001VU-Ky for qemu-devel@nongnu.org; Sat, 01 Feb 2020 07:28:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ixrsw-0001zJ-HA for qemu-devel@nongnu.org; Sat, 01 Feb 2020 07:28:27 -0500 Received: from mout.kundenserver.de ([212.227.126.187]:55499) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ixrsu-0001pD-Va for qemu-devel@nongnu.org; Sat, 01 Feb 2020 07:28:26 -0500 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue009 [212.227.15.167]) with ESMTPSA (Nemesis) id 1Mzz6s-1jjnGp42nG-00x5A6; Sat, 01 Feb 2020 13:27:54 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PATCH 4/4] linux-user: fix use of SIGRTMIN Date: Sat, 1 Feb 2020 13:27:46 +0100 Message-Id: <20200201122746.1478003-5-laurent@vivier.eu> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200201122746.1478003-1-laurent@vivier.eu> References: <20200201122746.1478003-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:uZvkDltmplsVxV9Exg8Kxxvw24erQUxYov1pUBuC/j8lafDsly+ UilvZAL8JzwbrxsoYImkxI6jyM+z+xlkdme05yogHsUXUSngYLVcmnv+qmilg8LA/KmG/AI c6haOJebBNzj0NJBZxA9YrRfLwzpdc2PTyNEx3ta7j/fbmY7WrOEVbFRmLhBKtjrcx/O550 UOZOY0/8W7o03WlheMmHw== X-UI-Out-Filterresults: notjunk:1; V03:K0:sidQ/StkU1M=:NKl/OWvunHRjA7l9h25j5/ 4uO7yHhCvfzU9Nf2urBPcfFBVBVE+Cs5MJ4FwRd32VdB1aI3ElOBA0H5lLFmoMRttXJAEz9jN l6Ctb/iiH3MGMui5pH+/zYSYQG0P6WDUvMNt+IEq64f/KP1WIznNRyBqpPrauPQVvCjkJ2X2G 04Ks/MkbQW6HEusPAtExy+PUxzPLCYKfnYI2V9UYbvtWLklXEiJsVD7oJi54p60ydeYVX75Q7 F/6f7orWScbWHXhLZYae3vYO7818C21t6nfNODyZ7nYOu9b+dh69+Ff2i5sHYlw/MSKR8o4bE TVNIXA5Zbn4Hkd6RTi8wUYa2InqX8OQGixrXpZ2ino/e5m39NPxTSeUZ8ZGTRvbJkh22Isdo7 liYjJKiVWy2+aJa4YdQamFeKHY/VSXh++0PnMLb5tbyGcted6LKRoyS/tqJ3dxq4biwBRgi3E jhzo+Sg79BuH8kW6e0jIaqThW81O25X3QR9sw0VrgbY8WNOG7/DxazV0dIKkRe+zv7Yx2ttLx qYjyBZ2PXrF+SPoxKMAAOsGUfY+uw3j/2FS1KVlaSjH4q+VMdn4CGkre7eEGxsgnT1UQCDbyt /5qxhWuTikUyYA9iNqeR7NezQiCU+ttRpeDwpHAbh4BR2UabJ/fy/SHV5JziXtcLm+rnkHMyz 7HGOivOJ2oTdO2HObY+FbFIMAcZuqo2V4hZvDfJSK6dLC8BGvj4tn3uwIiQzidgNM/tdi3P4y ckWT+M9w1GOVIzinUpmBqJIrX+ZgK6gGci0QnwqwnDw5CtPaRoJxnsqmTABUgeMUiz21r/xDg vmUyJZZSFR3KZD/o/ThR99kfwNxZpfMTrEgTePv8WIpNkbZP4rPtAt52HXBmaKBr0/lcG+z 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+incoming=patchwork.ozlabs.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 --- linux-user/signal.c | 34 ++++++++++++++++++++++++++++------ linux-user/trace-events | 3 +++ 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index 3491f0a7ecb1..c4abacde49a0 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -501,15 +501,20 @@ static void signal_table_init(void) int i, j; /* - * 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 (i = SIGRTMIN; i <= SIGRTMAX; i++) { + j = i - SIGRTMIN + TARGET_SIGRTMIN; + if (j <= TARGET_NSIG) { + host_to_target_signal_table[i] = j; + } + } /* generate signal conversion tables */ + for (i = 1; i <= TARGET_NSIG; i++) { + target_to_host_signal_table[i] = _NSIG; /* poison */ + } for (i = 1; i < _NSIG; i++) { if (host_to_target_signal_table[i] == 0) { host_to_target_signal_table[i] = i; @@ -519,6 +524,15 @@ static void signal_table_init(void) target_to_host_signal_table[j] = i; } } + + if (TRACE_SIGNAL_TABLE_INIT_BACKEND_DSTATE()) { + for (i = 1, j = 0; i <= TARGET_NSIG; i++) { + if (target_to_host_signal_table[i] == _NSIG) { + j++; + } + } + trace_signal_table_init(j); + } } 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,12 @@ 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\n", sig); + return -TARGET_EINVAL; + } 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..eb4b7701c400 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) "missing signal number: %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