From patchwork Fri Nov 3 21:40:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 117961 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp213645qgn; Fri, 3 Nov 2017 14:41:14 -0700 (PDT) X-Google-Smtp-Source: ABhQp+SPDXvGU2JRT33li9J8n44jSJ82BrUM2AyJRAiop9ly3joclZpjr+3kf+276eU9ILgwnIV0 X-Received: by 10.99.64.3 with SMTP id n3mr8366521pga.357.1509745274793; Fri, 03 Nov 2017 14:41:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509745274; cv=none; d=google.com; s=arc-20160816; b=fPmIoemxLZwx94GdDsNvpsr8HyXy616TA66UIVOhS8ye7ICEhzV2Uwipahd3xm5QSx cP+aqOZIqV+6NtBosNe4eUcxyZ+thfqaDaywfgWeRB5ahUpiofih/x8OCOCLzNt66Tyr wmqffMxw3qLPPmnhYnYYc91PfvodkS3NSmgKOYFSrbaLameXq2x30LYNtKeezavR4m7B D7PDBiUZdnAQEKkJrDHp5AXaU2ei1rI77q61hb9XGcXE0IVo/4Ry7LJICcFUqiBZTauF HFiyg1REWdOnCosaAH8cGYJnB2s/p4JrifAlS6cQQFYHLiSJq5HfLWEb+eYLc0hJ/fuh UlUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:to:from:delivered-to:sender:list-help :list-post:list-archive:list-subscribe:list-unsubscribe:list-id :precedence:mailing-list:dkim-signature:domainkey-signature :arc-authentication-results; bh=MwCNOpr91KHbem/OvJJpup9YYGkkZtCHtqkqnw9jCCw=; b=LODLjn882dAacC+3bJm37riEYdAwIuu8l4dgVh5cKu0UNTnzgl2Uef06308ZcZGJBq 2yjetnu+9EzGf+Zp3t7cavloWFistNfPQ2Hejuk6Kx8PMVvq/nE56B+aGcQaXa2UeHhr nVW+32nNrcc/fe/OhlWRn9+jNLBjUPIlV7QFTWLnTLVo0VVGBbbqjKLpAcD9J55ROGmn 0qxV2Ox2fdY1WYhZxvlRBQ/xtNe2WGqz1fo1Nl2V2z3swQqaKtAj2OMw0rtC2hJdgoRu KI2H37jR/vY2fsoMO9TwUybrCCS4qiTgSPt2tgswWoleA4ehwWfqPAv236XgpE8Rh4aS zuuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=KDbJT2JE; spf=pass (google.com: domain of libc-alpha-return-86726-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-86726-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id b1si4632696pls.445.2017.11.03.14.41.14 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Nov 2017 14:41:14 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-return-86726-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=KDbJT2JE; spf=pass (google.com: domain of libc-alpha-return-86726-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-86726-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id; q=dns; s= default; b=Oavo2DpbtHrfNwukUMBNfjwDSSLrJV//LuVfyW/kuDkDvodGUbTqD 9w/f5Z8+MhDJJA8Qlqp6idxMAXCRYjS2Q2m6WAZQK5Q7vVzFFiJdEfISpXLSkCa/ ZilBITtreEHQje67gWs7cYkgUoOoNDdS3v0MEtk2FrmlBKfd4nugj0= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id; s=default; bh=GXdWzjPZj1Ga5L1Zn6ilcT/F4u8=; b=KDbJT2JE1bu/eMwra48nqEqACt6Q wTfSe6k5n3KRkI1FGgczvNhhnR5MGTxvyV4autP1SKPOCK/yUzeBk3NFLDArbeyX cV5VvdfP3Jh9vlgneqZjKSm9mLZd7ikOT7adMkNuxHKTo7mYfJdLNc6QPRTH+Oxu szUx8xODp4WlKBA= Received: (qmail 37670 invoked by alias); 3 Nov 2017 21:41:04 -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 37649 invoked by uid 89); 3 Nov 2017 21:41:03 -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= X-HELO: mail-qt0-f194.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:to:subject:date:message-id; bh=MwCNOpr91KHbem/OvJJpup9YYGkkZtCHtqkqnw9jCCw=; b=M6SxzZ2b56lyWAnO+3ntHplQfU8mugcf4fcyghY8zlnAtuZKQXwY1pw+Ja8szn38lh QSZmL3z9G8ge223FistHD0Fxolprdv2IUFUCyMozTuIXs5NgZbq7DVsdW1H5CJTqXvCV 0u7k2IxmFltrkifmPJytYd1X3rye/SH+sIWrw9cZDifce9u7Mu7wZhBahKAN1lkbmKA+ ZPQDEB0F8Y55D4eji/sQdAYmPZeBJQXqVdNU0orQTy3En6td4cHYlcCFYROetJjXdqG1 2pqXVXyX9zychXYORGmMBScXzGYBDxe/f2RMrqYAfGA5a5OwFQfuY0Q4NjaRsR0qYPqO 0MAA== X-Gm-Message-State: AMCzsaW4YH5B25++SGUq1+LIj12EI97y62TwKd7hAAu5c8k9EEWBqP1i fyA8UI/w+qgpO7rAM6hxv55679HsOHg= X-Received: by 10.200.53.34 with SMTP id y31mr12585697qtb.206.1509745258204; Fri, 03 Nov 2017 14:40:58 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH 1/6] Consolidate Linux sigprocmask implementation (BZ #22391) Date: Fri, 3 Nov 2017 19:40:44 -0200 Message-Id: <1509745249-11404-1-git-send-email-adhemerval.zanella@linaro.org> 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. [BZ #22391] * manual/signal.texi: Add a note about internal pthread signals on Linux. * sysdeps/unix/sysv/linux/ia64/sigprocmask.c: Remove file. * sysdeps/unix/sysv/linux/s390/s390-64/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 Reported-by: Yury Norov --- ChangeLog | 17 +++++++ manual/signal.texi | 5 ++ sysdeps/unix/sysv/linux/alpha/sigprocmask.c | 58 ---------------------- sysdeps/unix/sysv/linux/ia64/sigprocmask.c | 40 --------------- sysdeps/unix/sysv/linux/nptl-signals.h | 6 +++ sysdeps/unix/sysv/linux/s390/s390-64/sigprocmask.c | 38 -------------- sysdeps/unix/sysv/linux/sigprocmask.c | 23 +++------ .../unix/sysv/linux/sparc/sparc64/sigprocmask.c | 34 ------------- sysdeps/unix/sysv/linux/x86_64/sigprocmask.c | 39 --------------- 9 files changed, 34 insertions(+), 226 deletions(-) delete mode 100644 sysdeps/unix/sysv/linux/alpha/sigprocmask.c delete mode 100644 sysdeps/unix/sysv/linux/ia64/sigprocmask.c delete mode 100644 sysdeps/unix/sysv/linux/s390/s390-64/sigprocmask.c delete mode 100644 sysdeps/unix/sysv/linux/sparc/sparc64/sigprocmask.c delete mode 100644 sysdeps/unix/sysv/linux/x86_64/sigprocmask.c -- 2.7.4 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)