From patchwork Tue Dec 10 18:32:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 181144 Delivered-To: patch@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp6241332ile; Tue, 10 Dec 2019 10:32:41 -0800 (PST) X-Google-Smtp-Source: APXvYqxsU+5Wz5uG1RDGtgzwQh+SRpmCxOn72fNutylu+Ejcwc7AQVQ8DhTKP88v4c4cZL6rkrAD X-Received: by 2002:aca:758c:: with SMTP id q134mr197910oic.33.1576002761396; Tue, 10 Dec 2019 10:32:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576002761; cv=none; d=google.com; s=arc-20160816; b=D6k/3gtxj5mN1wmiwUlulkC8GlZ30ws/cbbmsxbfeyVpUG1z8LJ4LprbZv9GFzBnWO yh+pgVD6fuXMoXXlU/Y56GsUb+is0HzkfxZ9af4v1upDoaJO5ZB9V/jvzSAXm49oW314 ebW9PV09xTuaMax3HBmQoQdRXlRZlQ2vnrrKZarXhHnNFDGVDYh7bobJ7mprk/PWJZxT ke6MfZrXUe7Wcuiiqd00u2qYkp8z0cfBztA7SaYuc63RStClOJNabazWVD9/XSlhiysa zl2rJIwH4pgHJS8aLPLxRFj7dSUtkkWFMAIslqR6awTP4q8YHHqFOt4iboVgm/0MAfvF rSvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:to:from:dkim-signature:delivered-to:sender :list-help:list-post:list-archive:list-subscribe:list-unsubscribe :list-id:precedence:mailing-list:dkim-signature:domainkey-signature; bh=G00okY5kT1CHVjY7jVSxw7mduRPANkNVsbtrUcq7sr4=; b=k4RBCXyKOlJTG4g+Lp9et2bFHdXYn/i1TO5Dz1RCzxIAejfTsi+4fUXARKlojXUzuV LZsP8DrL6ZTXrBvzapUZpapQ2bmwOcNXt5wVtKHjtY80j3Rg3Krb7Ku+1rIiXprSbk5E UfsTyspY5d/6T0VJpEX19Hq2GutIcAQlEmj94RzVSv0Dl6i97LLCOUFxEPSTk7138lJ9 J8fAUSdECw3yQtRWr6RWcFHN7SVePGU1dJY3v5MSP5MfitVB/7hv9PVSSUCKGg8gWwoZ MDuHeTMPjqwIfniA3szpa4CyglLeQhf1NtScLmcXWoeu6r7AgcPmwOBvhVYquiSavQwl wN7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=hCYUPwn8; dkim=pass header.i=@linaro.org header.s=google header.b="P7xCp/eg"; spf=pass (google.com: domain of libc-alpha-return-107895-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-107895-patch=linaro.org@sourceware.org"; dmarc=pass (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 i124si2275353oif.214.2019.12.10.10.32.41 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Dec 2019 10:32:41 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-107895-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=hCYUPwn8; dkim=pass header.i=@linaro.org header.s=google header.b="P7xCp/eg"; spf=pass (google.com: domain of libc-alpha-return-107895-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-107895-patch=linaro.org@sourceware.org"; dmarc=pass (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=mZLZt/8aGd2ofk1yoVOcmzKOhNQge9IMwkLRGNN59u7GrGIR9kjQI KmyUXy8HxUeGfLENx1nXQybuYtARehBvCeDjdIXXcP2OeG4UWuzefUbRS+mv+dR7 nWvv+qXLuWDW+0dCPLv/MXCJrCr6b1oeO5eUuxu0HVJwQiUvX86Yj0= 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=Htp7B2KJsq6MRpm/Nq94O77R6NI=; b=hCYUPwn8OW+6XB7GV0MdviUL3a6y WjExvpfLe+tvNxbYIQE2vuR1cimmx7s0yezm9jUj7hQpeQAHyYRdOuWvpj3PDT0Y Qhku5/7QSheKDe4r69QWRLBGIrhfhQ7Fo4/cX9XRA414ehdxWj5vi9FppUp1c1sz M06usKV6RTrWY9c= Received: (qmail 38862 invoked by alias); 10 Dec 2019 18:32:31 -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 38854 invoked by uid 89); 10 Dec 2019 18:32:30 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=sk:sparc64, __val X-HELO: mail-vk1-f193.google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id; bh=G00okY5kT1CHVjY7jVSxw7mduRPANkNVsbtrUcq7sr4=; b=P7xCp/egUnjyUZQIQib+iAfYS+FTseZzY3OiW5ucZIQvW1+2pnyi8pmEMLRGx08QvA WtJypaegX/hBD9TM4lqkufyJ35WKKNSp1CRxannZQ3581o4ohW8kk5nlIDpWMiWYTlYA PtHPg2B9brqZ7HL0+VrGNshydpp+R1EMiqcnv98Xt9h85vY/2vmfYZH7tukRk8aZMPnJ rGI3biQ+uZAqKuAx4Haz2tIW0JluesAfxcyGRWiYClKie5Cw4mi6kGR768KjccQMmeJ8 iHT55QTxialOd4SYPo6ifmtwIb71c1auA+EzCutK8OKsfGWTepXWWsXC3ok/Zml4hfgJ 0Ytg== Return-Path: From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH v3 1/7] Fix __libc_signal_block_all on sparc64 Date: Tue, 10 Dec 2019 15:32:15 -0300 Message-Id: <20191210183221.26912-1-adhemerval.zanella@linaro.org> Changes from previous version: - Remove unrelated changes. -- The a2e8aa0d9e shows two regressions on sparc64-linux-gnu: nptl/tst-cancel-self-canceltype nptl/tst-cancel5 This is not from the patch itself, but rather from an invalid __NR_rt_sigprocmask issued by the loader: rt_sigprocmask(SIG_UNBLOCK, [RTMIN RT_1], NULL, 8) = 0 rt_sigprocmask(0xffd07c60 /* SIG_??? */, ~[], 0x7feffd07d08, 8) = -1 EINVAL (Invalid argument) Tracking the culprit it really seems a wrong code generation in the INTERNAL_SYSCALL due the automatic sigset_t used on __libc_signal_block_all: return INTERNAL_SYSCALL (rt_sigprocmask, err, 4, SIG_BLOCK, &SIGALL_SET, set, _NSIG / 8); Where SIGALL_SET is defined as: ((__sigset_t) { .__val = {[0 ... _SIGSET_NWORDS-1 ] = -1 } }) Building the expanded __libc_signal_block_all on sparc64 with recent compiler (gcc 8.3.1 and 9.1.1): #include int _libc_signal_block_all (sigset_t *set) { INTERNAL_SYSCALL_DECL (err); return INTERNAL_SYSCALL (rt_sigprocmask, err, 4, SIG_BLOCK, &SIGALL_SET, set, _NSIG / 8); } It seems that the first argument (SIG_BLOCK) is not correctly set on 'o0' register: __libc_signal_block_all: save %sp, -304, %sp add %fp, 1919, %o0 mov 128, %o2 sethi %hi(.LC0), %o1 call memcpy, 0 or %o1, %lo(.LC0), %o1 add %fp, 1919, %o1 mov %i0, %o2 mov 8, %o3 mov 103, %g1 ta 0x6d; bcc,pt %xcc, 1f mov 0, %g1 sub %g0, %o0, %o0 mov 1, %g1 1: sra %o0, 0, %i0 return %i7+8 nop Where is I define SIGALL_SET outside INTERNAL_SYSCALL macro, gcc correctly sets the expected kernel argument in correct register: sethi %hi(.LC0), %o1 call memcpy, 0 or %o1, %lo(.LC0), %o1 -> mov 1, %o0 add %fp, 1919, %o1 This patch fixes it by moving both sigset_t that represent all signals sets and the application set to constant data objects. Checked on x86_64-linux-gnu, i686-linux-gnu, and sparc64-linux-gnu. --- sysdeps/unix/sysv/linux/internal-signals.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) -- 2.17.1 diff --git a/sysdeps/unix/sysv/linux/internal-signals.h b/sysdeps/unix/sysv/linux/internal-signals.h index 01d8bf0a4c..a496c7174c 100644 --- a/sysdeps/unix/sysv/linux/internal-signals.h +++ b/sysdeps/unix/sysv/linux/internal-signals.h @@ -22,6 +22,7 @@ #include #include #include +#include #include /* The signal used for asynchronous cancelation. */ @@ -53,15 +54,16 @@ __clear_internal_signals (sigset_t *set) __sigdelset (set, SIGSETXID); } -#define SIGALL_SET \ - ((__sigset_t) { .__val = {[0 ... _SIGSET_NWORDS-1 ] = -1 } }) +static const sigset_t sigall_set = { + .__val = {[0 ... _SIGSET_NWORDS-1 ] = -1 } +}; /* Block all signals, including internal glibc ones. */ static inline int __libc_signal_block_all (sigset_t *set) { INTERNAL_SYSCALL_DECL (err); - return INTERNAL_SYSCALL (rt_sigprocmask, err, 4, SIG_BLOCK, &SIGALL_SET, + return INTERNAL_SYSCALL (rt_sigprocmask, err, 4, SIG_BLOCK, &sigall_set, set, _NSIG / 8); } @@ -69,11 +71,11 @@ __libc_signal_block_all (sigset_t *set) static inline int __libc_signal_block_app (sigset_t *set) { - sigset_t allset = SIGALL_SET; + sigset_t allset = sigall_set; __clear_internal_signals (&allset); INTERNAL_SYSCALL_DECL (err); - return INTERNAL_SYSCALL (rt_sigprocmask, err, 4, SIG_BLOCK, &allset, set, - _NSIG / 8); + return INTERNAL_SYSCALL (rt_sigprocmask, err, 4, SIG_BLOCK, &allset, + set, _NSIG / 8); } /* Restore current process signal mask. */ From patchwork Tue Dec 10 18:32:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 181145 Delivered-To: patch@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp6241523ile; Tue, 10 Dec 2019 10:32:50 -0800 (PST) X-Google-Smtp-Source: APXvYqyR4hGFVKdYXE3vXPs/LYLH+76GygEYV7FC+Y132oqCCQD0GLKrK6CAxuyujdR8L2qT28hc X-Received: by 2002:a05:6830:4a7:: with SMTP id l7mr25666482otd.372.1576002770210; Tue, 10 Dec 2019 10:32:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576002770; cv=none; d=google.com; s=arc-20160816; b=ql9K660dsk6rDRxra1TeCr7aALwLUFAF5MrbL7VMokwvqbcZxx1WycINP4EifYsUkA qYm8e5e/xY2qUMmg/ua5bNBxTlQkw3Lfo8Wr/hjh5dVDB82kg5xtJzy/x5qg9IxkToWp 3xG5liLzH8fvBf2f49ehzf23Egz9I4mXnnT7bLC7j3MRFHvoUNK7YdZlYIA7NLbzVMOF WmZJGeqFeN37avSv7Tz76CGRnbss75yqrUs9kw3TJEI1sFQdGwkzl1BZrULitW6PIWZQ x944+GJIM63bclt0EkY1ZkSSUl+nqWiAUnrBXYfcYTzGUgyzlymMImP/q+fU7fN8aa/i Ie4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:to:from :dkim-signature:delivered-to:sender:list-help:list-post:list-archive :list-subscribe:list-unsubscribe:list-id:precedence:mailing-list :dkim-signature:domainkey-signature; bh=MLojER/go87pkZ54n+gOkr5WyhYQUD/MekehsNYLQBI=; b=twDyk+7at2qzqgB0SkybpO6uv+liceCYmrquO4OXzhRlSBqMRzfaAIx005EzZ3DPZZ QaDWR0ezGscwkiyuVQBZOuB63xNRnstvkZ1qI2PMv01r09ITZHtM2UYNrqy2exl3QQwc ojRrN7rZNoenOuePNmQFXSs1sHpSnu2oymybLJir59KYxdjDmPw2vEjLXaSBzpGhOB92 wbAhlYTXbolPknZQMjZ1Yc6fIW5FRuM4bi2ROf3gLwG546czK2TJFu0cjEsN7s4MDTfZ 9iTS/wAiDLFHmAK3cpJhIilsSBl4jQine5AMBcnV1p7n2b/6c4lKNaoq8JVHJCHVGdbF fznQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=kmtZvj02; dkim=pass header.i=@linaro.org header.s=google header.b=kFRiS1Hd; spf=pass (google.com: domain of libc-alpha-return-107896-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-107896-patch=linaro.org@sourceware.org"; dmarc=pass (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 v67si2328961oia.26.2019.12.10.10.32.50 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Dec 2019 10:32:50 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-107896-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=kmtZvj02; dkim=pass header.i=@linaro.org header.s=google header.b=kFRiS1Hd; spf=pass (google.com: domain of libc-alpha-return-107896-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-107896-patch=linaro.org@sourceware.org"; dmarc=pass (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:in-reply-to :references; q=dns; s=default; b=H/dHxsQ0EJqzrA3jsxboP4K7BnLLNwl RLS34dMzHDl4V09Rc0dXlLMPuc51oEO80kVelrCxjY7WZUO3iz9XAa1z+YWaj1sH FZH63KG79brVX8F2b1Zxw/EEBtXnWAzZkYMcpTMbVCjzsiXkqqMB+8RG9lXK8pla bGMLy/7F+MpA= 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:in-reply-to :references; s=default; bh=iNiUtOntKiBG0LsOfQABQQI4MJQ=; b=kmtZv j02KYQ55G5GK3tpKi2LTRxPkRu6zivW6JUMZ4OA7Y9Oe6sa4bjg/Gd2rx6JMapf0 noutXpiig77uhX2mbOFPh1cgYs5ozc/DdUvSdaBJPfsgKXMYTMlN8c8hW09Y3KE4 aN+JXIE01Lmk7WiNmHR5O87StFWwUgROhyRS28= Received: (qmail 39023 invoked by alias); 10 Dec 2019 18:32:31 -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 38968 invoked by uid 89); 10 Dec 2019 18:32:31 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=5818, __val X-HELO: mail-vs1-f47.google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=MLojER/go87pkZ54n+gOkr5WyhYQUD/MekehsNYLQBI=; b=kFRiS1HdRJpvXxJM7Oi24pzm3QVGDFm+GF0w0n0M4rpOcc3Ij5we72Kmbz87C1LSdc SCybTxpMy9+qKQ8wMpKafmDn9xmjjha9sMK1qBvmr0wP8Aoem/JaVCJ20dNttxDHv7tw jlYBHrL2gGIq5isZZtZnX5oVIC4+0BK7w6HMPO8nlwUD1PmFtYTVTjy/ZhSVaY3Py2M7 KNCceAa7jC3HgGc+FMHbb6MIEcyRRX1I823jG5LBb3vA8ev6I5PCY484PsBtXm7PIn5a IDC8ObScAC3Bvrc8+W1S2ZAjlWFEqm/JJtOvNb6a/DFMRcVSPuxlcYc5WFVAh8/YWT3J 544w== Return-Path: From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH 2/7] Add a constant data object for __libc_signal_block_app signal mask Date: Tue, 10 Dec 2019 15:32:16 -0300 Message-Id: <20191210183221.26912-2-adhemerval.zanella@linaro.org> In-Reply-To: <20191210183221.26912-1-adhemerval.zanella@linaro.org> References: <20191210183221.26912-1-adhemerval.zanella@linaro.org> It allows some minor optimization and less stack usage. Checked on x86_64-linux-gnu and i686-linux-gnu. --- sysdeps/unix/sysv/linux/internal-signals.h | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) -- 2.17.1 diff --git a/sysdeps/unix/sysv/linux/internal-signals.h b/sysdeps/unix/sysv/linux/internal-signals.h index a496c7174c..4b70109c14 100644 --- a/sysdeps/unix/sysv/linux/internal-signals.h +++ b/sysdeps/unix/sysv/linux/internal-signals.h @@ -58,6 +58,18 @@ static const sigset_t sigall_set = { .__val = {[0 ... _SIGSET_NWORDS-1 ] = -1 } }; +static const sigset_t sigapp_set = { +#if ULONG_MAX == 0xffffffff + .__val = { [0] = ~0UL & ~(__sigmask (SIGCANCEL)), + [1] = ~0UL & ~(__sigmask (SIGSETXID)), + [2 ... _SIGSET_NWORDS-1] = ~0UL } +#else + .__val = { [0] = ~0UL & ~(__sigmask (SIGCANCEL) + | __sigmask (SIGSETXID)), + [1 ... _SIGSET_NWORDS-1] = ~0UL } +#endif +}; + /* Block all signals, including internal glibc ones. */ static inline int __libc_signal_block_all (sigset_t *set) @@ -71,10 +83,8 @@ __libc_signal_block_all (sigset_t *set) static inline int __libc_signal_block_app (sigset_t *set) { - sigset_t allset = sigall_set; - __clear_internal_signals (&allset); INTERNAL_SYSCALL_DECL (err); - return INTERNAL_SYSCALL (rt_sigprocmask, err, 4, SIG_BLOCK, &allset, + return INTERNAL_SYSCALL (rt_sigprocmask, err, 4, SIG_BLOCK, &sigapp_set, set, _NSIG / 8); } From patchwork Tue Dec 10 18:32:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 181146 Delivered-To: patch@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp6241679ile; Tue, 10 Dec 2019 10:32:58 -0800 (PST) X-Google-Smtp-Source: APXvYqz2r6acWwRz1lQRi/+dl80mQWrGICyxnmY/0qgHPVqBHsZ/9cknFx5r8gvNY+YyYAeDj7u1 X-Received: by 2002:a9d:5c84:: with SMTP id a4mr15623528oti.305.1576002778785; Tue, 10 Dec 2019 10:32:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576002778; cv=none; d=google.com; s=arc-20160816; b=gOMyHxD3SavBbTXsZ4WHYFdytg6/LXvPnzHNkARgNLGOV+dmBT0jC6npqZR18QM44N ibgFktmHJdTRunzsoDBMKAMCZ+kU6Bjaan9JdMTrRxqBwCyS+FIen//R3quCJYVVKU4+ q5dzLWDk5uxdxpPJ2cLYXTb8njumYZxG63GVA1mB75caO104YGSnB2Q1ptrxYptDeDW0 8SpBe1n1kzBpc3P+/u88vA7ElY/q5EFFcFaWrhKlNeJ2rW/6EWUNHz2uaT7tXFKP5Q4i lKXXiJDIvjZhSvTRMJZ8+0fn9rtGURlOXwXj1opTTaCSFJWeHMuqAVVbKz8g/M24ee2K EnOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:to:from :dkim-signature:delivered-to:sender:list-help:list-post:list-archive :list-subscribe:list-unsubscribe:list-id:precedence:mailing-list :dkim-signature:domainkey-signature; bh=j3yYXVuNbU3rhESLy4t3wT/4T/s2fSR6sys/WNopir4=; b=hRct6ZGrde3VQrkjOTo3cF3dHbRW3jno/Mud5pIvt4hDjnSbaff2OLGHT3Bebymclj n9tXYWpBiv4PAbpUHGFGSegXDFdKCxhx+bGtaRa6MPBmfCmu/JW5WqA5NvH82o1g5ajt tCMgByUCaUVNaW3zHNKBJj0IW9xCGAloqISwRcJp1+K3uUMTEdx93JIwRgM4R/grk99D ydE43OT9mdQ7rL5aXvB9REq/WuhRgglp2FkpovxAMuU8knEELsHLhLGQd0nRpVLgdQKk 10z6wFkfR96e0qH0rB4+/3lHW++K/g3B6X/1R7uMd7ixkk6Y2r11A4U72uTKc1GveeBd GS2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=wyUIvYIo; dkim=pass header.i=@linaro.org header.s=google header.b=kFqs40Su; spf=pass (google.com: domain of libc-alpha-return-107897-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-107897-patch=linaro.org@sourceware.org"; dmarc=pass (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 z23si2292083otk.166.2019.12.10.10.32.58 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Dec 2019 10:32:58 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-107897-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=wyUIvYIo; dkim=pass header.i=@linaro.org header.s=google header.b=kFqs40Su; spf=pass (google.com: domain of libc-alpha-return-107897-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-107897-patch=linaro.org@sourceware.org"; dmarc=pass (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:in-reply-to :references; q=dns; s=default; b=hjPygp5l04YY/u2+bv835/Ln4iWu5Vs 0J4dYlWEjeWStbvjfa4Fd/Pn83DYuLgUm95GWqSXZGceXv8fK2T6vvX8OmKMbxSE lMcpi+iOR/WZoMwHdY/8p7sK2eshjASBUelzO/vXedFVtKqwzP/6QKgKoWlk26pk gKQlRBoMC4I4= 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:in-reply-to :references; s=default; bh=OXZDNyN+EuPNu9xOuaehhKvoRo0=; b=wyUIv YIof8TdfbfvS3TDFascqZulHVA7tF/rwgWkO6sO1h81TGkpZbLHjplfFEv+C103/ f1qn+3CY402HUnfZajC5dZskvjbcqOclBh0Fyt/JwuhHva/k6rFXkOqEz64rPv77 fdqZNXoObouZFmIbAu+O+/llGpX5quxKjQY11M= Received: (qmail 39318 invoked by alias); 10 Dec 2019 18:32:34 -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 39259 invoked by uid 89); 10 Dec 2019 18:32:33 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=communicate X-HELO: mail-ua1-f53.google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=j3yYXVuNbU3rhESLy4t3wT/4T/s2fSR6sys/WNopir4=; b=kFqs40Su22BU+4lm1TESbO3MFpjs9/WR6GwHpkaiOOOPPVV+87yQWEkiRNfVu3Y2Ca xoIkeIMuNjCuxw5EgsVauSszgevFKNhEdMSTUJqFhx4s6fed3O/lpPtTJOiEgx8igI3u Kdl46421VDfMY2eJJIIc4reFZJCYkc5/vuApQcX8kkoBruRzXpIcVSDitko/cDZjasK1 YE2k08TS4IDEtIlGBrBshN20mjE6g4DPB+DNm9F6Yu+eMCcVFySxnkPg6ody64NiHehV SEriIYoWZUNV1JNOlVETT4SC+NGgs20tNcVkVT4OXJTjfTuM+RuoO26d8b4xavGxSgAj QEzg== Return-Path: From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH 3/7] Fix return code for __libc_signal_* functions Date: Tue, 10 Dec 2019 15:32:17 -0300 Message-Id: <20191210183221.26912-3-adhemerval.zanella@linaro.org> In-Reply-To: <20191210183221.26912-1-adhemerval.zanella@linaro.org> References: <20191210183221.26912-1-adhemerval.zanella@linaro.org> since the function should not fail if input argument is NULL. Also, for Linux the return value is not fully correct on some platforms due the missing usage of INTERNAL_SYSCALL_ERROR_P / INTERNAL_SYSCALL_ERRNO macros. Checked on x86_64-linux-gnu, i686-linux-gnu, and sparc64-linux-gnu. --- sysdeps/generic/internal-signals.h | 12 ++++++------ sysdeps/unix/sysv/linux/internal-signals.h | 18 +++++++++--------- 2 files changed, 15 insertions(+), 15 deletions(-) -- 2.17.1 diff --git a/sysdeps/generic/internal-signals.h b/sysdeps/generic/internal-signals.h index a515e3e649..41c24dc4b3 100644 --- a/sysdeps/generic/internal-signals.h +++ b/sysdeps/generic/internal-signals.h @@ -34,28 +34,28 @@ __clear_internal_signals (sigset_t *set) { } -static inline int +static inline void __libc_signal_block_all (sigset_t *set) { sigset_t allset; __sigfillset (&allset); - return __sigprocmask (SIG_BLOCK, &allset, set); + __sigprocmask (SIG_BLOCK, &allset, set); } -static inline int +static inline void __libc_signal_block_app (sigset_t *set) { sigset_t allset; __sigfillset (&allset); __clear_internal_signals (&allset); - return __sigprocmask (SIG_BLOCK, &allset, set); + __sigprocmask (SIG_BLOCK, &allset, set); } /* Restore current process signal mask. */ -static inline int +static inline void __libc_signal_restore_set (const sigset_t *set) { - return __sigprocmask (SIG_SETMASK, set, NULL); + __sigprocmask (SIG_SETMASK, set, NULL); } diff --git a/sysdeps/unix/sysv/linux/internal-signals.h b/sysdeps/unix/sysv/linux/internal-signals.h index 4b70109c14..04e1ec4f0a 100644 --- a/sysdeps/unix/sysv/linux/internal-signals.h +++ b/sysdeps/unix/sysv/linux/internal-signals.h @@ -71,30 +71,30 @@ static const sigset_t sigapp_set = { }; /* Block all signals, including internal glibc ones. */ -static inline int +static inline void __libc_signal_block_all (sigset_t *set) { INTERNAL_SYSCALL_DECL (err); - return INTERNAL_SYSCALL (rt_sigprocmask, err, 4, SIG_BLOCK, &sigall_set, - set, _NSIG / 8); + INTERNAL_SYSCALL_CALL (rt_sigprocmask, err, SIG_BLOCK, &sigall_set, set, + _NSIG / 8); } /* Block all application signals (excluding internal glibc ones). */ -static inline int +static inline void __libc_signal_block_app (sigset_t *set) { INTERNAL_SYSCALL_DECL (err); - return INTERNAL_SYSCALL (rt_sigprocmask, err, 4, SIG_BLOCK, &sigapp_set, - set, _NSIG / 8); + INTERNAL_SYSCALL_CALL (rt_sigprocmask, err, SIG_BLOCK, &sigapp_set, set, + _NSIG / 8); } /* Restore current process signal mask. */ -static inline int +static inline void __libc_signal_restore_set (const sigset_t *set) { INTERNAL_SYSCALL_DECL (err); - return INTERNAL_SYSCALL (rt_sigprocmask, err, 4, SIG_SETMASK, set, NULL, - _NSIG / 8); + INTERNAL_SYSCALL_CALL (rt_sigprocmask, err, SIG_SETMASK, set, NULL, + _NSIG / 8); } /* Used to communicate with signal handler. */ From patchwork Tue Dec 10 18:32:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 181148 Delivered-To: patch@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp6242087ile; Tue, 10 Dec 2019 10:33:16 -0800 (PST) X-Google-Smtp-Source: APXvYqwLkHqnEWlqqMBkKIS0d+GSQpqe9B06ZSe2o122nYOdduFuBsZXxkjaPeZAWxHuVQuqXipM X-Received: by 2002:a05:6808:681:: with SMTP id k1mr181994oig.117.1576002796691; Tue, 10 Dec 2019 10:33:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576002796; cv=none; d=google.com; s=arc-20160816; b=eVPZr3F3OmaNfYMfDbxTIEef9WRXZarCH/ZuXcTvFRIUXpYSZQ4tzSWuSxRjIYhtYI dWmeCM1TJ+uvjok/TYHVesQRECzf3lCjH5jzaak1661PRYD6XnQVy9TWE7cGXemB8AGp c/1ZaDL8WEVwBHTvgMni7XAvizDHUcO0nFlPY2b4CDlg7as517WmPcUc/j811jM5jKTi vjUdr5cmbyiYspkcTSXxprz04b52KaZ3XNwHfYczgjWy0IHjpWTAiIMnxo0Mv0/BeWf7 2/vvabHCL7WEUeLwkOdX9qVDXvotPKfHCKu9KmFfQqJLuTeI+AmIVvNm36CZfxymyI33 rpZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:to:from :dkim-signature:delivered-to:sender:list-help:list-post:list-archive :list-subscribe:list-unsubscribe:list-id:precedence:mailing-list :dkim-signature:domainkey-signature; bh=plT90yHYMq9KJhSKgfBtVdIcr2ScTS8n0bGEHINWPbA=; b=h196iClYDGwx6ANii2HN9pS8xDZOePI71pdJCS+2HAdl1ZbN81PJsmFVlqdsbI9cF5 Oe/cjJrNL6qlx5mBJQaI/ltxZ9ghfMgPbVMCnpLoeQAUn63P+NqCP9cgsemjR8EizR+X e2Udb5VYWRUZOfn1TXuVXgXu8jMRJk/EiJkxJDTlrdcTrzQU1AS+yv3lvqEY3JGbR7y1 1pGX5dD3y3hBpaSaG68A1lEkbDrmXdrv/VRGBoITo8uiVWmV8Nq+zEtyiayIBEROrls7 PbI4XkxG62QJTl1cbt1hCfSQzFtv29zFVKMiL7axjUKoN7wGJVYAczmVBwCr7QHYuPvS eWIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=lrTdJhfA; dkim=pass header.i=@linaro.org header.s=google header.b=HWEib8OS; spf=pass (google.com: domain of libc-alpha-return-107899-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-107899-patch=linaro.org@sourceware.org"; dmarc=pass (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 i198si2242487oib.111.2019.12.10.10.33.16 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Dec 2019 10:33:16 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-107899-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=lrTdJhfA; dkim=pass header.i=@linaro.org header.s=google header.b=HWEib8OS; spf=pass (google.com: domain of libc-alpha-return-107899-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-107899-patch=linaro.org@sourceware.org"; dmarc=pass (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:in-reply-to :references; q=dns; s=default; b=ajUO4cVYBroaPoKPpk4MCFCKuH/6e8t 5ICFmbH1R9+mJUaPkW+QOnrPAtICkJ8/WSqg2E4hgvA3fpyd4xgEOaqEanUck1LV fhRFOxE0yFx+p66w2vVRZftb+b3/FhXJ8mmSxb53ZQpYm+eMSRh58T/gm7SBwuu3 NJdWRxQ2Cu9Y= 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:in-reply-to :references; s=default; bh=Vi8sGO3gUYsVqWi9ZRsGn10mTIQ=; b=lrTdJ hfAw2Fern+TBR9DK8/7lOdWaRtSiLdd49rMOC+b7oxNtcje8bLs+PE5ynaDqX98n 7jnwFXJbhRayRS54m8zbbl5Z2u8aw6ZXefuaZ/02ZzjKGR/dhdji0G616+eaKrcd bGzsDR2wnt+nQ6j6aWGTITWyAU1BtegR3hqPlw= Received: (qmail 39801 invoked by alias); 10 Dec 2019 18:32:38 -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 39739 invoked by uid 89); 10 Dec 2019 18:32:37 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=April, april, 1999, H*RU:209.85.222.67 X-HELO: mail-ua1-f67.google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=plT90yHYMq9KJhSKgfBtVdIcr2ScTS8n0bGEHINWPbA=; b=HWEib8OSsaWIZToRXYH9UdhZWbQPFW8xPq2j8Cf56PSUTNLAi110DVrWpBZphe2oMo sOiJWuDl6s8My9E7bx5bDMCwtF5QZJCWXiRY2JPwfxcwTtWEcA/t6v+8OywMBEvAXw3f Ht/gXmlG3lVQ8mLdW2idQlPMIJIUzqhQuaIJmym7kHrLjWjSpDB52X+7Rg9jW5NmnPUf vmdZSdUAE4PWNY4gbOX0VAhT94tbTE38UN7jYJuYCZFzu/N51OaNzXR09/S+wE6pvOVG 2phxxvj6KzoYPu4uhwwy4zJ2VArpxuj5X+smI+ALVwpjnmap8R+0tIDCKlykd/XdnJac gmNA== Return-Path: From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH v2 4/7] linux: Consolidate sigprocmask Date: Tue, 10 Dec 2019 15:32:18 -0300 Message-Id: <20191210183221.26912-4-adhemerval.zanella@linaro.org> In-Reply-To: <20191210183221.26912-1-adhemerval.zanella@linaro.org> References: <20191210183221.26912-1-adhemerval.zanella@linaro.org> All architectures now uses the Linux generic implementation which uses __NR_rt_sigprocmask. Checked on x86_64-linux-gnu, sparc64-linux-gnu, ia64-linux-gnu, s390x-linux-gnu, and alpha-linux-gnu. --- sysdeps/unix/sysv/linux/alpha/sigprocmask.c | 58 ------------------- sysdeps/unix/sysv/linux/ia64/sigprocmask.c | 40 ------------- .../sysv/linux/s390/s390-64/sigprocmask.c | 38 ------------ sysdeps/unix/sysv/linux/sigprocmask.c | 14 +---- .../sysv/linux/sparc/sparc64/sigprocmask.c | 34 ----------- sysdeps/unix/sysv/linux/x86_64/sigprocmask.c | 39 ------------- 6 files changed, 3 insertions(+), 220 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.17.1 diff --git a/sysdeps/unix/sysv/linux/alpha/sigprocmask.c b/sysdeps/unix/sysv/linux/alpha/sigprocmask.c deleted file mode 100644 index 0e807179bf..0000000000 --- a/sysdeps/unix/sysv/linux/alpha/sigprocmask.c +++ /dev/null @@ -1,58 +0,0 @@ -/* Copyright (C) 1993-2019 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 81c2d3cd8e..0000000000 --- a/sysdeps/unix/sysv/linux/ia64/sigprocmask.c +++ /dev/null @@ -1,40 +0,0 @@ -/* Copyright (C) 1997-2019 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/s390/s390-64/sigprocmask.c b/sysdeps/unix/sysv/linux/s390/s390-64/sigprocmask.c deleted file mode 100644 index f0eb099748..0000000000 --- a/sysdeps/unix/sysv/linux/s390/s390-64/sigprocmask.c +++ /dev/null @@ -1,38 +0,0 @@ -/* Copyright (C) 2001-2019 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 01521c8107..73b0d0c19a 100644 --- a/sysdeps/unix/sysv/linux/sigprocmask.c +++ b/sysdeps/unix/sysv/linux/sigprocmask.c @@ -15,17 +15,9 @@ License along with the GNU C Library; if not, see . */ -#include #include -#include /* Needed for string function builtin redirection. */ -#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) @@ -35,8 +27,8 @@ __sigprocmask (int how, const sigset_t *set, sigset_t *oset) /* 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))) + && __glibc_unlikely (__sigismember (set, SIGCANCEL) + || __glibc_unlikely (__sigismember (set, SIGSETXID)))) { local_newmask = *set; __sigdelset (&local_newmask, SIGCANCEL); @@ -44,7 +36,7 @@ __sigprocmask (int how, const sigset_t *set, sigset_t *oset) 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 5823826ab2..0000000000 --- a/sysdeps/unix/sysv/linux/sparc/sparc64/sigprocmask.c +++ /dev/null @@ -1,34 +0,0 @@ -/* Copyright (C) 1997-2019 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 c2e721d7b9..0000000000 --- a/sysdeps/unix/sysv/linux/x86_64/sigprocmask.c +++ /dev/null @@ -1,39 +0,0 @@ -/* Copyright (C) 1997-2019 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) From patchwork Tue Dec 10 18:32:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 181147 Delivered-To: patch@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp6241875ile; Tue, 10 Dec 2019 10:33:07 -0800 (PST) X-Google-Smtp-Source: APXvYqy7PuAD2N19IsFY9UVrQUrrn28mdor43snpQnWG5zWefQUWdDyXqeyPYdm6HaIMkFoF2lWK X-Received: by 2002:aca:180a:: with SMTP id h10mr190261oih.99.1576002787508; Tue, 10 Dec 2019 10:33:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576002787; cv=none; d=google.com; s=arc-20160816; b=ElQc8pCdvqdvl9XLXSEwlK2B0GR9XPB7l/YAz1ErGpp8GTNXbOM2F64AZW+tCXht8B RRJUQzDha603mb8ie5tZERAOiumqlY6tLZcZk3luB+Tb9fA0JhadSFscgF/L5PoG9vwz tYwYwjlTvMPiES6QomfH+238Ko/nEt7TS0mPmO9KQhP3Fszy84QFIyo3dTcb3g5eyk4R 34FOyNLgcwpyFIkp/U5gLA2AWObdnKnUtEiBsJPMrQfg4aNWDqkdcIhaKyX2/gly+FBW zwX6plCpTDiVQbqRxMKizbrJxvUaogviGfnElh7clzNNYBxWQagEgGzqsrD4Xpr99O2p eDgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:to:from :dkim-signature:delivered-to:sender:list-help:list-post:list-archive :list-subscribe:list-unsubscribe:list-id:precedence:mailing-list :dkim-signature:domainkey-signature; bh=Y4b4cd51VUxLBRlxTfEpD8Zg7+nIrQih252Za/Tdm78=; b=tPtJ7nXISPwft52o6UzZ2qokYPC8uoHMbwCbXTeppJOBOnS9nMCqDhiidg+0xvZlmH 94AXE2ZyEXriiU4pcHYRjSdM7eT0xcIf05UiCbHEsKy9ymwrjVd2JhP2ncZgBlH2Rnx3 gwKOf/5dKdXIfWPppJZyanYPkivLqiO0lJ5IbHv2wHNAr3UJDBZ64ov/LEoJKr+Mhn7q mOULlq9veET4hU0hBVELeymH82r0P8BEPBGMbE4fArPRu+iMyLLeCEyT4MYhCTXzoJgF 5DA3sIt4sLVhwEu96Nwb054UE9v7JHNfFtJ7O+PqDSEkUtyVqsYonGlbOcdIQ8ByiDqW HYrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=itCtDq0K; dkim=pass header.i=@linaro.org header.s=google header.b=qaU9nD5I; spf=pass (google.com: domain of libc-alpha-return-107898-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-107898-patch=linaro.org@sourceware.org"; dmarc=pass (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 a9si2434064oib.59.2019.12.10.10.33.07 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Dec 2019 10:33:07 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-107898-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=itCtDq0K; dkim=pass header.i=@linaro.org header.s=google header.b=qaU9nD5I; spf=pass (google.com: domain of libc-alpha-return-107898-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-107898-patch=linaro.org@sourceware.org"; dmarc=pass (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:in-reply-to :references; q=dns; s=default; b=JNCLQPamOSjRHJQz0wj36QgetCnDl0/ Y/xmh33RWVCHk2f63DB+/YIhCuYL8XfI+FyKc7jILX2GeHqlim7EFAwDK+pp7sx+ m/aUCybjws8m9cJxj3UUOL9QSaDBdu24sgaSo1Tcb4vWCf7GFfXDCii9brj1h86K rxW8AYcs3F3A= 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:in-reply-to :references; s=default; bh=EkcvdyCkGY4Jn+7/X4wtjWzBjvU=; b=itCtD q0KfxStWscGNqwfpFG6Hx0uE91Rb2skQem2F2227ntUGYupxyf0oUvBOxPCnbzB2 Ov1EKdYuVgTxe4iNccw9nXSBVuw2c0CD6aUQsE6V3+3RlxWfacCc2JrMmJw8AUKt czZQPDiUEyRsVJInAjUTffIUVrTkie6+6K9+j0= Received: (qmail 39646 invoked by alias); 10 Dec 2019 18:32:36 -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 39594 invoked by uid 89); 10 Dec 2019 18:32:36 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=HX-Languages-Length:1489, HX-Google-Smtp-Source:APXvYqwH X-HELO: mail-vs1-f68.google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=Y4b4cd51VUxLBRlxTfEpD8Zg7+nIrQih252Za/Tdm78=; b=qaU9nD5Iw+SIEM5Eb2B3RGc7IKhvuF1Ghdyyp2yyqeixNIVg0DfG7FDYnWXcovy2jV PBAFESm2NS09hT4g/Cxsg+Pvh4w37xrdDO5YgDA87pu47SsBWmsy2qpAWV95y8Iav4o7 r/E9mjgZh9KpQP8JD2BzT91Gd/sHKyGjqwJars2wL6XCyNe2/XyEAlYHZ0GiN7B9tzx2 tnxWkck4xmOzsAgpuzj9qjI8XPqBtIuNBLNFb+VnVxcirRDH35nzKNYtzQcIWcAZm3Bn hTNJMIUM7TbWljYiYdECjkGEmcdCpE+SWkU+vOud992kFyAT7FT0eKYbL7UdrmonSJC/ 6nLw== Return-Path: From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH v2 5/7] linux: Remove SIGCANCEL/SIGSETXID handling on sigprocmask Date: Tue, 10 Dec 2019 15:32:19 -0300 Message-Id: <20191210183221.26912-5-adhemerval.zanella@linaro.org> In-Reply-To: <20191210183221.26912-1-adhemerval.zanella@linaro.org> References: <20191210183221.26912-1-adhemerval.zanella@linaro.org> The sigfillset already does it, and this is the canonical way to operate on sigset_t. The only way to actually broke this assumption is if caller initialize sigset with memset or something similar, i.e, bypassing glibc (and again this is not a valid construction). Checked on x86_64-linux-gnu. --- sysdeps/unix/sysv/linux/sigprocmask.c | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) -- 2.17.1 diff --git a/sysdeps/unix/sysv/linux/sigprocmask.c b/sysdeps/unix/sysv/linux/sigprocmask.c index 73b0d0c19a..c6961a8ac4 100644 --- a/sysdeps/unix/sysv/linux/sigprocmask.c +++ b/sysdeps/unix/sysv/linux/sigprocmask.c @@ -16,26 +16,12 @@ . */ #include -#include /* SIGCANCEL, SIGSETXID */ +#include /* 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 - && __glibc_unlikely (__sigismember (set, SIGCANCEL) - || __glibc_unlikely (__sigismember (set, SIGSETXID)))) - { - local_newmask = *set; - __sigdelset (&local_newmask, SIGCANCEL); - __sigdelset (&local_newmask, SIGSETXID); - set = &local_newmask; - } - return INLINE_SYSCALL_CALL (rt_sigprocmask, how, set, oset, _NSIG / 8); } libc_hidden_def (__sigprocmask) From patchwork Tue Dec 10 18:32:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 181149 Delivered-To: patch@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp6242262ile; Tue, 10 Dec 2019 10:33:25 -0800 (PST) X-Google-Smtp-Source: APXvYqwj5EO8smWakpF0VCtzHFHS2Uz6WkDmDKH+F2twL8r6eqHhOB6Nr9GzydeuCfAKM/sfHl/Y X-Received: by 2002:a05:6830:1e2d:: with SMTP id t13mr27548471otr.128.1576002805528; Tue, 10 Dec 2019 10:33:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576002805; cv=none; d=google.com; s=arc-20160816; b=V+S1L7p60TP/NML6abAGQ4Zbdv1nsCyDUzvIV7C6CThAP1TXaA3U7x/QPVpLh2YCc4 NLP4onLRUP3UFj9CAKArTr+072mqHgyxLQt169obthXeJaO6fZZkk1PsJCnU7Mt5JuOJ 2T06cFJFsZXbDxOWMCTTVImcMh46za5bNP4N3LmX9cwSSrB7NA06S62rsXizoyAuqwxu NMxA9kCi4Ik89jh3dnzYJC5tjkBKqWiOe7iyFYhtFuXRp9TcIs58jmcaty1qytjDTyBh yJcimvzMI62kyifNwtscwqfc0cxGgO/YG0XAYuC7dbOjOPSrRbpruR6Tw/IKf9ev9FLz ow7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:to:from :dkim-signature:delivered-to:sender:list-help:list-post:list-archive :list-subscribe:list-unsubscribe:list-id:precedence:mailing-list :dkim-signature:domainkey-signature; bh=CwL6r6Xelg5Uw+QCbPHeqZQ849t9ehkMMBaRI7CovAw=; b=MJY+a9czbJ7UTXf8WCP98ZZhBYcLlt4SluU3+sDE065YBp4Cs2nqykP25nxqC4DN6W VyUo6wyVqLmbuNOjMSp42KHgmFAmKfo9bR4M63om0UNJqqSWoFxwBqYPmTM12/oLX8gX x5fE1zGwkFLMuPI7bp+//DSt197qY4JXeYakMuwPLRNbKPo3o4+KLREDDHXUtW9vN1T3 07RQjACROgVigcq3qTxuDgIVpv+hciejHQtrrqBiAjIxx8J1FNG4DQrYQcE3T582JJ58 aTIGUL1RNPH++ByaERgsy+LrWTjVKE7H8utj5OeBjmAp6WdxNXCqxmbmyCDBVMXouXH2 996Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b="CB2e6l3/"; dkim=pass header.i=@linaro.org header.s=google header.b=eEyMTnwl; spf=pass (google.com: domain of libc-alpha-return-107900-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-107900-patch=linaro.org@sourceware.org"; dmarc=pass (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 x24si2373368otk.188.2019.12.10.10.33.25 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Dec 2019 10:33:25 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-107900-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="CB2e6l3/"; dkim=pass header.i=@linaro.org header.s=google header.b=eEyMTnwl; spf=pass (google.com: domain of libc-alpha-return-107900-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-107900-patch=linaro.org@sourceware.org"; dmarc=pass (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:in-reply-to :references; q=dns; s=default; b=kw56MiHjLno8jC+hLtBRo+KBnE9VrmI nmv6mN4qKRCsGBvuTGCeEASTrgzLv9Yk1PXqd/eZ3dH7J/8EyNR3EhOmyqb670d7 UY9IKGX8eRvbyC5hUBTrrah1gNU3TIkWyh9khcMUpU/ZbBakf19le1CKkYBFIbU6 fXoTicJjwsiQ= 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:in-reply-to :references; s=default; bh=AWSFPXltg4zRdMchCYH6KmzqlpQ=; b=CB2e6 l3/Z1HYCc7ZdWpb61JfP4EsjzuuUH7Mvic9Qu0vuPo/stu3gnsDdOiQxjl+8SrtG d68ckVm4WGsiVqx3bnUBB4fm/8ajiLR9cuo/+RZbCYcV5QjtcA/2AtZijTOqOUF9 9pB1gGidbh9PF2pjnSSpCCVWydmiwMEtKPMlKk= Received: (qmail 40134 invoked by alias); 10 Dec 2019 18:32:40 -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 40060 invoked by uid 89); 10 Dec 2019 18:32:40 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=1000000, thoroughly X-HELO: mail-vk1-f176.google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=CwL6r6Xelg5Uw+QCbPHeqZQ849t9ehkMMBaRI7CovAw=; b=eEyMTnwlzUjtFrA9neZ2ND8LsGSxwABFgfjtJyOdzgykm2O7WVMwaO2nOH0Nxd1PrI PiKvp5J7gWUqFXB1pzSFOQeFh8Z1raRwLKfI8mueadbEhjWTiXSGn4y1427OxiQ/OFmM P5CxB/V2Nh4xXKEPP4+SSDM0pt8U4U1+K+Y0B/bCelmt9YoFrnle7aWVoRtOgfYC3D2c X3xe2SAYW5JqwLZtCtGKh6nhEYMnRVlZKzz+lEq/Xas19+bSIjxRy8V45VATbqf5hzFd uoPfRvil7P5pXo9vYoTShKEsrL6oe5sxgrJZr1kKwqZR9jHl2MTfKY1mlh8W6g2NFEs9 cyOw== Return-Path: From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH 6/7] Block all signals on timer_create thread (BZ#10815) Date: Tue, 10 Dec 2019 15:32:20 -0300 Message-Id: <20191210183221.26912-6-adhemerval.zanella@linaro.org> In-Reply-To: <20191210183221.26912-1-adhemerval.zanella@linaro.org> References: <20191210183221.26912-1-adhemerval.zanella@linaro.org> The behavior of the signal mask on threads created by timer_create for SIGEV_THREAD timers are implementation defined and glibc explicit unblocks all signals before calling the user-defined function. This behavior, although not incorrect standard-wise, opens a race if a program using a blocked rt-signal plus sigwaitinfo (and without an installed signal handler for the rt-signal) receives the signal while executing the timer threads created by SIGEV_THREAD. A better alternative discussed in bug report is to rather block all signals (besides the internal ones not available to application usage). This patch fixes by only unblock the SIGSETXID (used on set*uid). The SIGTIMER is the same as SIGCANCEL and it will be handled by sigwaitinfo on the helper thread (thus it can be masked as well). Checked on x86_64-linux-gnu and i686-linux-gnu. --- rt/Makefile | 7 +- rt/tst-timer-sigmask.c | 96 +++++++++++++++++++ sysdeps/unix/sysv/linux/internal-signals.h | 14 +++ sysdeps/unix/sysv/linux/kernel-posix-timers.h | 1 - sysdeps/unix/sysv/linux/timer_routines.c | 96 +++++++------------ 5 files changed, 148 insertions(+), 66 deletions(-) create mode 100644 rt/tst-timer-sigmask.c -- 2.17.1 diff --git a/rt/Makefile b/rt/Makefile index 6c8365e0c0..a7a82879c7 100644 --- a/rt/Makefile +++ b/rt/Makefile @@ -47,6 +47,7 @@ tests := tst-shm tst-timer tst-timer2 \ tst-timer3 tst-timer4 tst-timer5 \ tst-cpuclock2 tst-cputimer1 tst-cputimer2 tst-cputimer3 \ tst-shm-cancel +tests-internal := tst-timer-sigmask extra-libs := librt extra-libs-others := $(extra-libs) @@ -63,9 +64,11 @@ LDFLAGS-rt.so = -Wl,--enable-new-dtags,-z,nodelete $(objpfx)librt.so: $(shared-thread-library) ifeq (yes,$(build-shared)) -$(addprefix $(objpfx),$(tests)): $(objpfx)librt.so $(shared-thread-library) +$(addprefix $(objpfx),$(tests) $(tests-internal)): \ + $(objpfx)librt.so $(shared-thread-library) else -$(addprefix $(objpfx),$(tests)): $(objpfx)librt.a $(static-thread-library) +$(addprefix $(objpfx),$(tests)) $(tests-internal): \ + $(objpfx)librt.a $(static-thread-library) endif tst-mqueue7-ARGS = -- $(host-test-program-cmd) diff --git a/rt/tst-timer-sigmask.c b/rt/tst-timer-sigmask.c new file mode 100644 index 0000000000..1030e4c79f --- /dev/null +++ b/rt/tst-timer-sigmask.c @@ -0,0 +1,96 @@ +/* Check resulting signal mask from POSIX time using SIGEV_THREAD. + Copyright (C) 2019 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 + +#include +#include + +#include + +static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; +static pthread_cond_t cond = PTHREAD_COND_INITIALIZER; +static enum +{ + THREAD_SIGNAL_CHECK_INIT = 0, + THREAD_SIGNAL_CHECK_OK, + THREAD_SIGNAL_CHECK_FAIL +} thread_handler_check = THREAD_SIGNAL_CHECK_INIT; + +static void +thread_handler (union sigval sv) +{ + bool failure = false; + + sigset_t ss; + sigprocmask (SIG_BLOCK, NULL, &ss); + if (test_verbose > 0) + printf ("%s: blocked signal mask = { ", __func__); + for (int sig = 1; sig < NSIG; sig++) + { +#ifdef __linux__ + /* POSIX timers threads created to handle SIGEV_THREAD blocks + all signals except SIGKILL, SIGSTOP, and SIGSETXID. */ + if (!sigismember (&ss, sig) + && (sig != SIGSETXID && sig != SIGKILL && sig != SIGSTOP)) + { + failure = true; + } +#endif + if (test_verbose && sigismember (&ss, sig)) + printf ("%d, ", sig); + } + if (test_verbose > 0) + printf ("}\n"); + + pthread_mutex_lock (&lock); + thread_handler_check = failure + ? THREAD_SIGNAL_CHECK_FAIL : THREAD_SIGNAL_CHECK_OK; + pthread_cond_signal (&cond); + pthread_mutex_unlock (&lock); +} + +static int +do_test (void) +{ + struct sigevent sev = { 0 }; + sev.sigev_notify = SIGEV_THREAD; + sev.sigev_notify_function = &thread_handler; + + timer_t timerid; + TEST_COMPARE (timer_create (CLOCK_REALTIME, &sev, &timerid), 0); + + struct itimerspec trigger = { 0 }; + trigger.it_value.tv_nsec = 1000000; + TEST_COMPARE (timer_settime (timerid, 0, &trigger, NULL), 0); + + pthread_mutex_lock (&lock); + while (thread_handler_check == THREAD_SIGNAL_CHECK_INIT) + pthread_cond_wait (&cond, &lock); + pthread_mutex_unlock (&lock); + + TEST_COMPARE (thread_handler_check, THREAD_SIGNAL_CHECK_OK); + + return 0; +} + +#include diff --git a/sysdeps/unix/sysv/linux/internal-signals.h b/sysdeps/unix/sysv/linux/internal-signals.h index 04e1ec4f0a..f155a8cd32 100644 --- a/sysdeps/unix/sysv/linux/internal-signals.h +++ b/sysdeps/unix/sysv/linux/internal-signals.h @@ -70,6 +70,11 @@ static const sigset_t sigapp_set = { #endif }; +static const sigset_t sigtimer_set = { + .__val = { [0] = __sigmask (SIGTIMER), + [1 ... _SIGSET_NWORDS-1] = 0 } +}; + /* Block all signals, including internal glibc ones. */ static inline void __libc_signal_block_all (sigset_t *set) @@ -88,6 +93,15 @@ __libc_signal_block_app (sigset_t *set) _NSIG / 8); } +/* Block only the SIGTIMER set. */ +static inline void +__libc_signal_block_sigtimer (sigset_t *set) +{ + INTERNAL_SYSCALL_DECL (err); + INTERNAL_SYSCALL_CALL (rt_sigprocmask, err, SIG_BLOCK, &sigtimer_set, set, + _NSIG / 8); +} + /* Restore current process signal mask. */ static inline void __libc_signal_restore_set (const sigset_t *set) diff --git a/sysdeps/unix/sysv/linux/kernel-posix-timers.h b/sysdeps/unix/sysv/linux/kernel-posix-timers.h index 1ded4df51a..d60cb95f80 100644 --- a/sysdeps/unix/sysv/linux/kernel-posix-timers.h +++ b/sysdeps/unix/sysv/linux/kernel-posix-timers.h @@ -43,7 +43,6 @@ extern pthread_mutex_t __active_timer_sigev_thread_lock attribute_hidden; /* Type of timers in the kernel. */ typedef int kernel_timer_t; - /* Internal representation of timer. */ struct timer { diff --git a/sysdeps/unix/sysv/linux/timer_routines.c b/sysdeps/unix/sysv/linux/timer_routines.c index d96d963177..98bbe077fa 100644 --- a/sysdeps/unix/sysv/linux/timer_routines.c +++ b/sysdeps/unix/sysv/linux/timer_routines.c @@ -42,14 +42,6 @@ struct thread_start_data static void * timer_sigev_thread (void *arg) { - /* The parent thread has all signals blocked. This is a bit - surprising for user code, although valid. We unblock all - signals. */ - sigset_t ss; - sigemptyset (&ss); - INTERNAL_SYSCALL_DECL (err); - INTERNAL_SYSCALL (rt_sigprocmask, err, 4, SIG_SETMASK, &ss, NULL, _NSIG / 8); - struct thread_start_data *td = (struct thread_start_data *) arg; void (*thrfunc) (sigval_t) = td->thrfunc; @@ -69,65 +61,49 @@ timer_sigev_thread (void *arg) static void * timer_helper_thread (void *arg) { - /* Wait for the SIGTIMER signal, allowing the setXid signal, and - none else. */ - sigset_t ss; - sigemptyset (&ss); - __sigaddset (&ss, SIGTIMER); - /* Endless loop of waiting for signals. The loop is only ended when the thread is canceled. */ while (1) { siginfo_t si; - /* sigwaitinfo cannot be used here, since it deletes - SIGCANCEL == SIGTIMER from the set. */ - - /* XXX The size argument hopefully will have to be changed to the - real size of the user-level sigset_t. */ - int result = SYSCALL_CANCEL (rt_sigtimedwait, &ss, &si, NULL, _NSIG / 8); - - if (result > 0) + while (sigwaitinfo (&sigtimer_set, &si) < 0); + if (si.si_code == SI_TIMER) { - if (si.si_code == SI_TIMER) - { - struct timer *tk = (struct timer *) si.si_ptr; + struct timer *tk = (struct timer *) si.si_ptr; + + /* Check the timer is still used and will not go away + while we are reading the values here. */ + pthread_mutex_lock (&__active_timer_sigev_thread_lock); - /* Check the timer is still used and will not go away - while we are reading the values here. */ - pthread_mutex_lock (&__active_timer_sigev_thread_lock); + struct timer *runp = __active_timer_sigev_thread; + while (runp != NULL) + if (runp == tk) + break; + else + runp = runp->next; - struct timer *runp = __active_timer_sigev_thread; - while (runp != NULL) - if (runp == tk) - break; - else - runp = runp->next; + if (runp != NULL) + { + struct thread_start_data *td = malloc (sizeof (*td)); - if (runp != NULL) + /* There is not much we can do if the allocation fails. */ + if (td != NULL) { - struct thread_start_data *td = malloc (sizeof (*td)); - - /* There is not much we can do if the allocation fails. */ - if (td != NULL) - { - /* This is the signal we are waiting for. */ - td->thrfunc = tk->thrfunc; - td->sival = tk->sival; - - pthread_t th; - (void) pthread_create (&th, &tk->attr, - timer_sigev_thread, td); - } - } + /* This is the signal we are waiting for. */ + td->thrfunc = tk->thrfunc; + td->sival = tk->sival; - pthread_mutex_unlock (&__active_timer_sigev_thread_lock); + pthread_t th; + pthread_create (&th, &tk->attr, timer_sigev_thread, td); + } } - else if (si.si_code == SI_TKILL) - /* The thread is canceled. */ - pthread_exit (NULL); + + pthread_mutex_unlock (&__active_timer_sigev_thread_lock); } + else if (si.si_code == SI_TKILL) + /* The thread is canceled. */ + pthread_exit (NULL); } } @@ -161,15 +137,10 @@ __start_helper_thread (void) /* Block all signals in the helper thread but SIGSETXID. To do this thoroughly we temporarily have to block all signals here. The - helper can lose wakeups if SIGCANCEL is not blocked throughout, - but sigfillset omits it SIGSETXID. So, we add SIGCANCEL back - explicitly here. */ + helper can lose wakeups if SIGCANCEL is not blocked throughout. */ sigset_t ss; - sigset_t oss; - sigfillset (&ss); - __sigaddset (&ss, SIGCANCEL); - INTERNAL_SYSCALL_DECL (err); - INTERNAL_SYSCALL (rt_sigprocmask, err, 4, SIG_SETMASK, &ss, &oss, _NSIG / 8); + __libc_signal_block_app (&ss); + __libc_signal_block_sigtimer (NULL); /* Create the helper thread for this timer. */ pthread_t th; @@ -179,8 +150,7 @@ __start_helper_thread (void) __helper_tid = ((struct pthread *) th)->tid; /* Restore the signal mask. */ - INTERNAL_SYSCALL (rt_sigprocmask, err, 4, SIG_SETMASK, &oss, NULL, - _NSIG / 8); + __libc_signal_restore_set (&ss); /* No need for the attribute anymore. */ (void) pthread_attr_destroy (&attr); From patchwork Tue Dec 10 18:32:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 181150 Delivered-To: patch@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp6242466ile; Tue, 10 Dec 2019 10:33:35 -0800 (PST) X-Google-Smtp-Source: APXvYqx6pt1hFmTqTc+KAXuhFY+JR36fmvIXMS8GwdAcBb4Uytm8fWm87xRcTV3GK2iT5egxJRyf X-Received: by 2002:a9d:74c4:: with SMTP id a4mr27725669otl.119.1576002815643; Tue, 10 Dec 2019 10:33:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576002815; cv=none; d=google.com; s=arc-20160816; b=qkHXi3vaBeY0c5+z2If7gaPSWHSkWguegjAsEQMi+z5HEInmho5LQtqsl0soh1oGGv FyGXob0cLYiHXzWwnauMlylPX0SckXVWwzHmbEqF+axR10d3t7xm0nl8K67SZtBxSOvb JIUEPXv+AwfWXJ/ZDL8AosVMBEqH4xWtgu3CguKJ1KbmoBSmTIAlI4GTVIiqk9w6k0QM rG+qXEjxU5mXx5WPIboAAjwArfqZ36R6/cph+cbvby7I6/P4wFsDQ4hsrvf7K8BzA+3d +9+2FZ8zUMafzdac5JIgm8XVUztuAWl49IR3W7Hiodoy3OjpLrY3WmcBOXfSDm0Xy/Lf Sd0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:to:from :dkim-signature:delivered-to:sender:list-help:list-post:list-archive :list-subscribe:list-unsubscribe:list-id:precedence:mailing-list :dkim-signature:domainkey-signature; bh=gqEcjCnYMjIIPch4ut8YDYRA+E/suF++kEaGZKdgeBo=; b=XstIA4GEUSinKUCJJiHrYQ3YtjvojCOQaoM6eTXUsl31TECmeMmvCGaXcDdloXb9O3 P2v7u59PyHJoF4OD6NGV+QMxFHjEF2DYnjAH7LMFTmUjQ1wOn9ckuJhgO7yCszcHmzss MFpz3X0obyfq2zcU/JvmCTA0ObhKeMhyggpSLWb6BKEYxi9NuSSvjYczjClz4isvCuC0 ePROvrIChd84d+8IxBwWodPdflKk4KMZSD4NB7uqkFt9nrF87xbTR6CnmPtVmXiBuAdP buWycGWjQ1wbH5RU2TjeN5lpLNAbb2DWXyr4hwtD/Y6VTFdmkMLkvkgjfxCb+wnCIwEo tLnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b="YFKTMm7/"; dkim=pass header.i=@linaro.org header.s=google header.b=pjc5mQhN; spf=pass (google.com: domain of libc-alpha-return-107901-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-107901-patch=linaro.org@sourceware.org"; dmarc=pass (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 5si2351788ott.186.2019.12.10.10.33.35 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Dec 2019 10:33:35 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-107901-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="YFKTMm7/"; dkim=pass header.i=@linaro.org header.s=google header.b=pjc5mQhN; spf=pass (google.com: domain of libc-alpha-return-107901-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-107901-patch=linaro.org@sourceware.org"; dmarc=pass (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:in-reply-to :references; q=dns; s=default; b=bW1v4GwBsCCtoUktk0fQMjvi5W2fm+5 7exjetqdZR+5+lM3THPeJwOKPFqM3p0qn35I/h9V9ZUNPDwX18EmlJ3YJBLEHuSc v+dBTQr5aLroBSprOArAVKrK7jlYbMgBt1mF0ylUGcB4pdeke0davpO+SNqSqqKq wDSl6OkNZv6M= 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:in-reply-to :references; s=default; bh=t+mGM/WsKigS93MqKFuuQpuM3WU=; b=YFKTM m7/yFu7LeZzPEbE5rbY2qYsrcXgOm+etA1NNesE/+UG63bRmrOzEnta20Sr2D1nS b1X9MIaNaLTRK/SjJ2bRvAwe90jbSLt8dFgymEcxfNIDJIWtspFw2amJqh2955Y6 b5job9LVPz5NwKdaEBAl5vf7LW/nw+E6rI/3Ug= Received: (qmail 40296 invoked by alias); 10 Dec 2019 18:32:41 -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 40223 invoked by uid 89); 10 Dec 2019 18:32:41 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=11625, Lock, 1617 X-HELO: mail-vs1-f68.google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=gqEcjCnYMjIIPch4ut8YDYRA+E/suF++kEaGZKdgeBo=; b=pjc5mQhNebLoZlLU3oa1rFTgRf/i3EuHYmN6tD05DDUMQM6FISr2LONGlgvaH8AbOa sYLtykiJbayTksBuZoPNtw3iw0R7jWLsJD7tFlFtuux6Tt8Npi+xztUZTYrg3S3YavqY +DwGnjLG9OpSF4KM7REeT7TLnf3EvLAYv2E0Zvu98ilsGQRB7CwcF3zrKpoiV8igB1en OQFHS51SiGdjLeEweti2OGA8aEMIDB58jmgGwjxK/gNQxxCy8eNMNPYLRO0PiZdZbcBp VJuf/nkNjiOH1ZlIdIMaDu9NPoNWLKP4BIT6j31CQuVi8QJF8TdlQFhvoVHCOis+OX3n agvw== Return-Path: From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH 7/7] Cleanup timer_* routines Date: Tue, 10 Dec 2019 15:32:21 -0300 Message-Id: <20191210183221.26912-7-adhemerval.zanella@linaro.org> In-Reply-To: <20191210183221.26912-1-adhemerval.zanella@linaro.org> References: <20191210183221.26912-1-adhemerval.zanella@linaro.org> - Two function are added that manipulate the list of active timers, __{add,remove}_active_timer_sigev. This allows make both __active_timer_sigev_thread and __active_timer_sigev_thread_lock internal on timer_routine implementation. - Remove ununsed __no_posix_timers defition. - Use INLINE_SYSCALL_CALL on timer_* functions. - Simplify some code on timer_create and timer_routines, such as thread attribute handling and invalid notification method. Checked on x86_64-linux-gnu and i686-linux-gnu. --- sysdeps/unix/sysv/linux/kernel-posix-timers.h | 13 +- sysdeps/unix/sysv/linux/timer_create.c | 116 +++++++----------- sysdeps/unix/sysv/linux/timer_delete.c | 42 ++----- sysdeps/unix/sysv/linux/timer_getoverr.c | 2 +- sysdeps/unix/sysv/linux/timer_routines.c | 50 ++++++-- 5 files changed, 100 insertions(+), 123 deletions(-) -- 2.17.1 diff --git a/sysdeps/unix/sysv/linux/kernel-posix-timers.h b/sysdeps/unix/sysv/linux/kernel-posix-timers.h index d60cb95f80..bf17d8c915 100644 --- a/sysdeps/unix/sysv/linux/kernel-posix-timers.h +++ b/sysdeps/unix/sysv/linux/kernel-posix-timers.h @@ -21,10 +21,6 @@ #include #include - -/* Nonzero if the system calls are not available. */ -extern int __no_posix_timers attribute_hidden; - /* Callback to start helper thread. */ extern void __start_helper_thread (void) attribute_hidden; @@ -34,12 +30,6 @@ extern pthread_once_t __helper_once attribute_hidden; /* TID of the helper thread. */ extern pid_t __helper_tid attribute_hidden; -/* List of active SIGEV_THREAD timers. */ -extern struct timer *__active_timer_sigev_thread attribute_hidden; -/* Lock for the __active_timer_sigev_thread. */ -extern pthread_mutex_t __active_timer_sigev_thread_lock attribute_hidden; - - /* Type of timers in the kernel. */ typedef int kernel_timer_t; @@ -64,3 +54,6 @@ struct timer /* Next element in list of active SIGEV_THREAD timers. */ struct timer *next; }; + +void __add_active_timer_sigev (struct timer *tk) attribute_hidden; +void __remove_active_timer_sigev (struct timer *tk) attribute_hidden; diff --git a/sysdeps/unix/sysv/linux/timer_create.c b/sysdeps/unix/sysv/linux/timer_create.c index 4e41ca011f..e5dcdaab65 100644 --- a/sysdeps/unix/sysv/linux/timer_create.c +++ b/sysdeps/unix/sysv/linux/timer_create.c @@ -16,17 +16,12 @@ License along with the GNU C Library; see the file COPYING.LIB. If not, see . */ -#include -#include #include -#include -#include #include -#include -#include -#include -#include "kernel-posix-timers.h" -#include "kernel-posix-cpu-timers.h" + +#include +#include +#include #ifdef timer_create_alias @@ -38,17 +33,16 @@ int timer_create (clockid_t clock_id, struct sigevent *evp, timer_t *timerid) { #undef timer_create - { - clockid_t syscall_clockid = (clock_id == CLOCK_PROCESS_CPUTIME_ID - ? MAKE_PROCESS_CPUCLOCK (0, CPUCLOCK_SCHED) - : clock_id == CLOCK_THREAD_CPUTIME_ID - ? MAKE_THREAD_CPUCLOCK (0, CPUCLOCK_SCHED) - : clock_id); - - /* If the user wants notification via a thread we need to handle - this special. */ - if (evp == NULL - || __builtin_expect (evp->sigev_notify != SIGEV_THREAD, 1)) + clockid_t syscall_clockid = (clock_id == CLOCK_PROCESS_CPUTIME_ID + ? MAKE_PROCESS_CPUCLOCK (0, CPUCLOCK_SCHED) + : clock_id == CLOCK_THREAD_CPUTIME_ID + ? MAKE_THREAD_CPUCLOCK (0, CPUCLOCK_SCHED) + : clock_id); + + switch (evp != NULL ? evp->sigev_notify : SIGEV_SIGNAL) + { + case SIGEV_NONE: + case SIGEV_SIGNAL: { struct sigevent local_evp; @@ -75,27 +69,22 @@ timer_create (clockid_t clock_id, struct sigevent *evp, timer_t *timerid) } kernel_timer_t ktimerid; - int retval = INLINE_SYSCALL (timer_create, 3, syscall_clockid, evp, - &ktimerid); - - if (retval != -1) - { - newp->sigev_notify = (evp != NULL - ? evp->sigev_notify : SIGEV_SIGNAL); - newp->ktimerid = ktimerid; - - *timerid = (timer_t) newp; - } - else + int retval = INLINE_SYSCALL_CALL (timer_create, syscall_clockid, evp, + &ktimerid); + if (retval != 0) { /* Cannot allocate the timer, fail. */ free (newp); - retval = -1; + return-1; } - return retval; + newp->sigev_notify = (evp != NULL ? evp->sigev_notify : SIGEV_SIGNAL); + newp->ktimerid = ktimerid; + *timerid = (timer_t) newp; } - else + break; + + case SIGEV_THREAD: { /* Create the helper thread. */ pthread_once (&__helper_once, __start_helper_thread); @@ -116,25 +105,10 @@ timer_create (clockid_t clock_id, struct sigevent *evp, timer_t *timerid) newp->thrfunc = evp->sigev_notify_function; newp->sigev_notify = SIGEV_THREAD; - /* We cannot simply copy the thread attributes since the - implementation might keep internal information for - each instance. */ - (void) pthread_attr_init (&newp->attr); if (evp->sigev_notify_attributes != NULL) - { - struct pthread_attr *nattr; - struct pthread_attr *oattr; - - nattr = (struct pthread_attr *) &newp->attr; - oattr = (struct pthread_attr *) evp->sigev_notify_attributes; - - nattr->schedparam = oattr->schedparam; - nattr->schedpolicy = oattr->schedpolicy; - nattr->flags = oattr->flags; - nattr->guardsize = oattr->guardsize; - nattr->stackaddr = oattr->stackaddr; - nattr->stacksize = oattr->stacksize; - } + newp->attr = *evp->sigev_notify_attributes; + else + pthread_attr_init (&newp->attr); /* In any case set the detach flag. */ (void) pthread_attr_setdetachstate (&newp->attr, @@ -148,29 +122,25 @@ timer_create (clockid_t clock_id, struct sigevent *evp, timer_t *timerid) ._sigev_un = { ._pad = { [0] = __helper_tid } } }; /* Create the timer. */ - INTERNAL_SYSCALL_DECL (err); - int res; - res = INTERNAL_SYSCALL (timer_create, err, 3, - syscall_clockid, &sev, &newp->ktimerid); - if (! INTERNAL_SYSCALL_ERROR_P (res, err)) + int res = INLINE_SYSCALL_CALL (timer_create, syscall_clockid, &sev, + &newp->ktimerid); + if (res != 0) { - /* Add to the queue of active timers with thread - delivery. */ - pthread_mutex_lock (&__active_timer_sigev_thread_lock); - newp->next = __active_timer_sigev_thread; - __active_timer_sigev_thread = newp; - pthread_mutex_unlock (&__active_timer_sigev_thread_lock); - - *timerid = (timer_t) newp; - return 0; + free (newp); + return -1; } - /* Free the resources. */ - free (newp); + /* Add to the queue of active timers with thread delivery. */ + __add_active_timer_sigev (newp); - __set_errno (INTERNAL_SYSCALL_ERRNO (res, err)); - - return -1; + *timerid = (timer_t) newp; } - } + break; + + default: + __set_errno (-1); + return -1; + } + + return 0; } diff --git a/sysdeps/unix/sysv/linux/timer_delete.c b/sysdeps/unix/sysv/linux/timer_delete.c index 3aec393132..ee5deb8739 100644 --- a/sysdeps/unix/sysv/linux/timer_delete.c +++ b/sysdeps/unix/sysv/linux/timer_delete.c @@ -16,7 +16,6 @@ License along with the GNU C Library; see the file COPYING.LIB. If not, see . */ -#include #include #include #include @@ -35,38 +34,17 @@ timer_delete (timer_t timerid) struct timer *kt = (struct timer *) timerid; /* Delete the kernel timer object. */ - int res = INLINE_SYSCALL (timer_delete, 1, kt->ktimerid); + int r = INLINE_SYSCALL_CALL (timer_delete, kt->ktimerid); + if (r != 0) + /* The kernel timer is not known or something else bad happened. + Return the error. */ + return -1; - if (res == 0) - { - if (kt->sigev_notify == SIGEV_THREAD) - { - /* Remove the timer from the list. */ - pthread_mutex_lock (&__active_timer_sigev_thread_lock); - if (__active_timer_sigev_thread == kt) - __active_timer_sigev_thread = kt->next; - else - { - struct timer *prevp = __active_timer_sigev_thread; - while (prevp->next != NULL) - if (prevp->next == kt) - { - prevp->next = kt->next; - break; - } - else - prevp = prevp->next; - } - pthread_mutex_unlock (&__active_timer_sigev_thread_lock); - } + if (kt->sigev_notify == SIGEV_THREAD) + __remove_active_timer_sigev (kt); - /* Free the memory. */ - (void) free (kt); + /* Free the memory. */ + free (kt); - return 0; - } - - /* The kernel timer is not known or something else bad happened. - Return the error. */ - return -1; + return 0; } diff --git a/sysdeps/unix/sysv/linux/timer_getoverr.c b/sysdeps/unix/sysv/linux/timer_getoverr.c index 04122a9878..82627e4ee3 100644 --- a/sysdeps/unix/sysv/linux/timer_getoverr.c +++ b/sysdeps/unix/sysv/linux/timer_getoverr.c @@ -34,7 +34,7 @@ timer_getoverrun (timer_t timerid) struct timer *kt = (struct timer *) timerid; /* Get the information from the kernel. */ - int res = INLINE_SYSCALL (timer_getoverrun, 1, kt->ktimerid); + int res = INLINE_SYSCALL_CALL (timer_getoverrun, kt->ktimerid); return res; } diff --git a/sysdeps/unix/sysv/linux/timer_routines.c b/sysdeps/unix/sysv/linux/timer_routines.c index 98bbe077fa..97882f036b 100644 --- a/sysdeps/unix/sysv/linux/timer_routines.c +++ b/sysdeps/unix/sysv/linux/timer_routines.c @@ -16,19 +16,20 @@ License along with the GNU C Library; see the file COPYING.LIB. If not, see . */ -#include -#include +#include #include -#include -#include +#include + +#include +#include #include -#include "kernel-posix-timers.h" /* List of active SIGEV_THREAD timers. */ -struct timer *__active_timer_sigev_thread; +static struct timer *__active_timer_sigev_thread; /* Lock for the __active_timer_sigev_thread. */ -pthread_mutex_t __active_timer_sigev_thread_lock = PTHREAD_MUTEX_INITIALIZER; +static pthread_mutex_t __active_timer_sigev_thread_lock + = PTHREAD_MUTEX_INITIALIZER; struct thread_start_data @@ -56,6 +57,41 @@ timer_sigev_thread (void *arg) return NULL; } +/* Append a new time KT on the on the active list __active_timer_sigev_thread + list in a thread safe way. */ +void +__add_active_timer_sigev (struct timer *kt) +{ + pthread_mutex_lock (&__active_timer_sigev_thread_lock); + kt->next = __active_timer_sigev_thread; + __active_timer_sigev_thread = kt; + pthread_mutex_unlock (&__active_timer_sigev_thread_lock); +} + +/* Remove the active timer KT on the active list __active_timer_sigev_thread + list in a thread safe way. */ +void +__remove_active_timer_sigev (struct timer *kt) +{ + /* Remove the timer from the list. */ + pthread_mutex_lock (&__active_timer_sigev_thread_lock); + if (__active_timer_sigev_thread == kt) + __active_timer_sigev_thread = kt->next; + else + { + struct timer *prevp = __active_timer_sigev_thread; + while (prevp->next != NULL) + if (prevp->next == kt) + { + prevp->next = kt->next; + break; + } + else + prevp = prevp->next; + } + pthread_mutex_unlock (&__active_timer_sigev_thread_lock); +} + /* Helper function to support starting threads for SIGEV_THREAD. */ static void *