From patchwork Tue Oct 31 21:19:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 24028 Received: (qmail 39938 invoked by alias); 31 Oct 2017 21:19:15 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 39911 invoked by uid 89); 31 Oct 2017 21:19:13 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=jes, Jes, U**, wise X-HELO: mail-qt0-f195.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=Edz8puFtDzzQsNdPlptZnnrYGFCI2+kizTtrouqw1IM=; b=GIAJaD54wiYl+rPvosdOr/jT3SBR7WXN2lsKt41+9cgGIUnY0mKBr8ZhnELaWh95Ku 3UuQyUbpN4irEALJbAzvTuQ40ck3N/gjmuS90DOfOhBGwsjyLnS6XmJhNSsyfrn20Zgu 4+mhT4kIggGf0lM3bWmtSMIYUbWlKLy2dLsHknKGMaXFRmquQrmNzBlJcJ6Otz1JqnGN Xq/fUa3F8oh73/Zpqs/JlHsKkr9fGm/QZ9wgAKRCtxZxXpiJLCp9C61FhswdqsksGFDT Nud+ZY6YdrQY1dNKHgeGyMbQWfj6xdW5/08y+XYa8ejzeZwq7Jxh+cnMANEv3ySK6dFQ PlNw== X-Gm-Message-State: AMCzsaWDcoXVrWVJCaRjnU3KXqF2OFDxNumT41gkBdsExUfdQtIPPX6m luhf8gFJfiI2Vq72D2p5c4J0GBza2DM= X-Google-Smtp-Source: ABhQp+RIUfNxUoGzNXRWKSd9udw4gna2nOJqSTwI/M1UzndnjK6fXc8Ho4wGDPM1VrgAhYUBkjRqjA== X-Received: by 10.200.44.203 with SMTP id 11mr4934523qtx.194.1509484746570; Tue, 31 Oct 2017 14:19:06 -0700 (PDT) From: Adhemerval Zanella Subject: Re: [PATCH 2/3] Consolidate Linux sigprocmask() implementation To: libc-alpha@sourceware.org References: <20171016043407.1142-1-ynorov@caviumnetworks.com> <20171016043407.1142-3-ynorov@caviumnetworks.com> Message-ID: <7d396fbb-b43d-4f9a-34c6-7bc11168fd27@linaro.org> Date: Tue, 31 Oct 2017 19:19:01 -0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <20171016043407.1142-3-ynorov@caviumnetworks.com> On 16/10/2017 02:34, Yury Norov wrote: > ia64, s390-64, sparc64, x86_64 and alpha ports has their own > implementations of sigprocmask(). They all but alpha do exactly > what generic sigprocmask() except the check and clear SIGCANCEL > and SIGSETXID flags. > > In this patch, the NEED_CLEAR_SIGCANCEL_SIGSETXID option is > introduced and disabled for that ports which allows to swith > them to generic implementation. Although the manual do not state the Linux implementation detail I think all supported Linux architecture should have the same semantic regarding SIGCANCEL and SIGSETXID. GLIBC on Linux requires both signal to proper implement both pthread cancellation and set*id function and having different semanticsis troublesome (a conformant program on a architecture that does not filter out the signals might inadvertently disable pthread asynchronous cancellation, set*id synchronization or posix timers). Also, sigfillset removes SIGCANCEL and SIGSETXID as expected, but sigaddset and sigdelset does not handle none of internal signals. I also think we should ignore internal nptl signals on sigaddset and sigdelset. And for this specific case I don't see adding compat symbols to keep the old semantic for the related architectures the best approach. There is a canonical way to actually disable pthread cancellation and masking SIGSETXID would make set*id non POSIX conformant. What about the following? --- This patch consolidates the sigprocmask Linux syscall implementation on sysdeps/unix/sysv/linux/sigprocmask.c. The changes are: 1. For ia64, s390-64, sparc64, and x86_64 the default semantic for filter out SIGCANCEL and SIGSETXID is used. Also the Linux pthread semantic is documented in the signal chapter. 2. A new internal function to check for NPTL internal signals within a signal set is added (__nptl_has_internal_signal). It is used to simplify the default sigprocmask.c implementation. Checked on x86_64-linux-gnu. * manual/signal.texi: Add a note about internal pthread signals on Linux. * sysdeps/unix/sysv/linux/alpha/sigprocmask.c: Remove file. * sysdeps/unix/sysv/linux/ia64/sigprocmask.c: Likewise. * sysdeps/unix/sysv/linux/sparc/sparc64/sigprocmask.c: Likewise. * sysdeps/unix/sysv/linux/x86_64/sigprocmask.c: Likewise. * sysdeps/unix/sysv/linux/nptl-signals.h (__nptl_has_internal_signal): New function. * sysdeps/unix/sysv/linux/sigprocmask.c (__sigprocmask): Use __nptl_has_internal_signal and __nptl_clear_internal_signals function. Signed-off-by: Adhemerval Zanella --- diff --git a/manual/signal.texi b/manual/signal.texi index 9577ff0..46696af 100644 --- a/manual/signal.texi +++ b/manual/signal.texi @@ -2461,6 +2461,11 @@ well. (In addition, it's not wise to put into your program an assumption that the system has no signals aside from the ones you know about.) +On Linux pthreads internally uses some signals to implement asynchronous +cancellation, effective ID synchronization for POSIX conformance, and +posix timer management. These signals are filtered out on signal set +function manipulation. + @deftypefun int sigemptyset (sigset_t *@var{set}) @standards{POSIX.1, signal.h} @safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}} diff --git a/sysdeps/unix/sysv/linux/alpha/sigprocmask.c b/sysdeps/unix/sysv/linux/alpha/sigprocmask.c deleted file mode 100644 index ebec70c..0000000 --- a/sysdeps/unix/sysv/linux/alpha/sigprocmask.c +++ /dev/null @@ -1,58 +0,0 @@ -/* Copyright (C) 1993-2017 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by David Mosberger (davidm@azstarnet.com). - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library. If not, see - . */ - -#include -#include -#include - -/* When there is kernel support for more than 64 signals, we'll have to - switch to a new system call convention here. */ - -int -__sigprocmask (int how, const sigset_t *set, sigset_t *oset) -{ - unsigned long int setval; - long result; - - if (set) - setval = set->__val[0]; - else - { - setval = 0; - how = SIG_BLOCK; /* ensure blocked mask doesn't get changed */ - } - - result = INLINE_SYSCALL (osf_sigprocmask, 2, how, setval); - if (result == -1) - /* If there are ever more than 63 signals, we need to recode this - in assembler since we wouldn't be able to distinguish a mask of - all 1s from -1, but for now, we're doing just fine... */ - return result; - - if (oset) - { - oset->__val[0] = result; - result = _SIGSET_NWORDS; - while (--result > 0) - oset->__val[result] = 0; - } - return 0; -} - -libc_hidden_def (__sigprocmask) -weak_alias (__sigprocmask, sigprocmask); diff --git a/sysdeps/unix/sysv/linux/ia64/sigprocmask.c b/sysdeps/unix/sysv/linux/ia64/sigprocmask.c deleted file mode 100644 index 920c5fd..0000000 --- a/sysdeps/unix/sysv/linux/ia64/sigprocmask.c +++ /dev/null @@ -1,40 +0,0 @@ -/* Copyright (C) 1997-2017 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Linux/IA64 specific sigprocmask - Written by Jes Sorensen, , April 1999. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -/* Linux/ia64 only has rt signals, thus we do not even want to try falling - back to the old style signals as the default Linux handler does. */ - -#include -#include -#include - -#include -#include - -/* Get and/or change the set of blocked signals. */ -int -__sigprocmask (int how, const sigset_t *set, sigset_t *oset) -{ - - /* XXX The size argument hopefully will have to be changed to the - real size of the user-level sigset_t. */ - return INLINE_SYSCALL (rt_sigprocmask, 4, how, set, oset, _NSIG / 8); -} -libc_hidden_def (__sigprocmask) -weak_alias (__sigprocmask, sigprocmask) diff --git a/sysdeps/unix/sysv/linux/nptl-signals.h b/sysdeps/unix/sysv/linux/nptl-signals.h index f30c597..6afd3fe 100644 --- a/sysdeps/unix/sysv/linux/nptl-signals.h +++ b/sysdeps/unix/sysv/linux/nptl-signals.h @@ -33,6 +33,12 @@ #define SIGSETXID (__SIGRTMIN + 1) +static inline bool +__nptl_has_internal_signal (const sigset_t *set) +{ + return __sigismember (set, SIGCANCEL) || __sigismember (set, SIGSETXID); +} + /* Return is sig is used internally. */ static inline int __nptl_is_internal_signal (int sig) diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/sigprocmask.c b/sysdeps/unix/sysv/linux/s390/s390-64/sigprocmask.c deleted file mode 100644 index a8010e7..0000000 --- a/sysdeps/unix/sysv/linux/s390/s390-64/sigprocmask.c +++ /dev/null @@ -1,38 +0,0 @@ -/* Copyright (C) 2001-2017 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -/* 64 bit Linux for S/390 only has rt signals, thus we do not even want to try - falling back to the old style signals as the default Linux handler does. */ - -#include -#include -#include - -#include -#include - -/* Get and/or change the set of blocked signals. */ -int -__sigprocmask (int how, const sigset_t *set, sigset_t *oset) -{ - - /* XXX The size argument hopefully will have to be changed to the - real size of the user-level sigset_t. */ - return INLINE_SYSCALL (rt_sigprocmask, 4, how, set, oset, _NSIG / 8); -} -libc_hidden_def (__sigprocmask) -weak_alias (__sigprocmask, sigprocmask) diff --git a/sysdeps/unix/sysv/linux/sigprocmask.c b/sysdeps/unix/sysv/linux/sigprocmask.c index e776563..d14fc5c 100644 --- a/sysdeps/unix/sysv/linux/sigprocmask.c +++ b/sysdeps/unix/sysv/linux/sigprocmask.c @@ -1,4 +1,5 @@ -/* Copyright (C) 1997-2017 Free Software Foundation, Inc. +/* Get and/or change the set of blocked signals. Linux version. + Copyright (C) 1997-2017 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -17,34 +18,22 @@ #include #include -#include /* Needed for string function builtin redirection. */ -#include +#include -#include -#include -#include /* SIGCANCEL, SIGSETXID */ - - -/* Get and/or change the set of blocked signals. */ int __sigprocmask (int how, const sigset_t *set, sigset_t *oset) { sigset_t local_newmask; - /* The only thing we have to make sure here is that SIGCANCEL and - SIGSETXID are not blocked. */ - if (set != NULL - && (__builtin_expect (__sigismember (set, SIGCANCEL), 0) - || __builtin_expect (__sigismember (set, SIGSETXID), 0))) + if (set != NULL && __glibc_unlikely (__nptl_has_internal_signal (set))) { local_newmask = *set; - __sigdelset (&local_newmask, SIGCANCEL); - __sigdelset (&local_newmask, SIGSETXID); + __nptl_clear_internal_signals (&local_newmask); set = &local_newmask; } - return INLINE_SYSCALL (rt_sigprocmask, 4, how, set, oset, _NSIG / 8); + return INLINE_SYSCALL_CALL (rt_sigprocmask, how, set, oset, _NSIG / 8); } libc_hidden_def (__sigprocmask) weak_alias (__sigprocmask, sigprocmask) diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/sigprocmask.c b/sysdeps/unix/sysv/linux/sparc/sparc64/sigprocmask.c deleted file mode 100644 index ef7d7fe..0000000 --- a/sysdeps/unix/sysv/linux/sparc/sparc64/sigprocmask.c +++ /dev/null @@ -1,34 +0,0 @@ -/* Copyright (C) 1997-2017 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include -#include - -#include -#include - -/* Get and/or change the set of blocked signals. */ -int -__sigprocmask (int how, const sigset_t *set, sigset_t *oset) -{ - /* XXX The size argument hopefully will have to be changed to the - real size of the user-level sigset_t. */ - return INLINE_SYSCALL (rt_sigprocmask, 4, how, set, oset, _NSIG / 8); -} -libc_hidden_def (__sigprocmask) -weak_alias (__sigprocmask, sigprocmask) diff --git a/sysdeps/unix/sysv/linux/x86_64/sigprocmask.c b/sysdeps/unix/sysv/linux/x86_64/sigprocmask.c deleted file mode 100644 index 1610ddf..0000000 --- a/sysdeps/unix/sysv/linux/x86_64/sigprocmask.c +++ /dev/null @@ -1,39 +0,0 @@ -/* Copyright (C) 1997-2017 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Jes Sorensen, , April 1999. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -/* Linux/x86_64 only has rt signals, thus we do not even want to try falling - back to the old style signals as the default Linux handler does. */ - -#include -#include -#include - -#include -#include - -/* Get and/or change the set of blocked signals. */ -int -__sigprocmask (int how, const sigset_t *set, sigset_t *oset) -{ - - /* XXX The size argument hopefully will have to be changed to the - real size of the user-level sigset_t. */ - return INLINE_SYSCALL (rt_sigprocmask, 4, how, set, oset, _NSIG / 8); -} -libc_hidden_def (__sigprocmask) -weak_alias (__sigprocmask, sigprocmask)