From patchwork Fri Dec 28 01:02:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1019053 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-98816-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="RmOwF1EF"; dkim=pass (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="LUDXJIdW"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43QpP636qnz9s2P for ; Fri, 28 Dec 2018 12:03:38 +1100 (AEDT) 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=URr6SZ2V5GPGmuhYsawpk+0WYQ7n4w3 zuw3zunyha76i1hmmBEUM7r+DaQ0JO1i5+uWjLaOPUGoQR9BP7b77+SQTDblEpE9 Zfz1Xcxcds34TPDvzNFYAFbk47BgS5DLOJ5/b+7fGvkwEkcYq/l23ymhu6wVQb4O wm6LiSDj5Eck= 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=xqjav+FI6PwS2XXXtkchKbRa8ZE=; b=RmOwF 1EF8pDxQrWvy2LURAth5V8BhJYhp4rp6r1ma1YDrJixj1yoAQ6QNdpovjWQ6Dsgn 3ytUcTQ7UlcSTCIw+/R9BOk6Any3WYMIcQ1GDD3RcDH0hk6IcU2uYgNLV2pVGcC9 rozSlA3qH3LmmwwUeOqJkAB89WFSO4YH7Hsq9A= Received: (qmail 35390 invoked by alias); 28 Dec 2018 01:03:09 -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 35273 invoked by uid 89); 28 Dec 2018 01:03:08 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, KAM_STOCKGEN, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=strip, select, Nothing, upcoming X-HELO: mail-qt1-f194.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=FXRzUX9dKtQTYwgDmugjESgCjGECdZqtjVyN7ht9gsw=; b=LUDXJIdWv956dyto7QMq2SDoPK2cI0EMd62pH/yJoP/+6O1ZmlxDai8KPB1uk7hKzn rw8dC8ClR9/TviHizS6cftH8G+x0EUJS9GErVdJhWJGn9PfUj2okANyhursr9nQHlHB5 lWnhVItJJDX1/rlWAg7NvCOM+Bft5C3TDrrPA= From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH v2 1/6] nptl: Remove tst-cancel-wrappers test and related macros Date: Thu, 27 Dec 2018 23:02:50 -0200 Message-Id: <20181228010255.21406-2-adhemerval.zanella@linaro.org> In-Reply-To: <20181228010255.21406-1-adhemerval.zanella@linaro.org> References: <20181228010255.21406-1-adhemerval.zanella@linaro.org> With upcoming BZ#12683 fix, syscall cancellation is not more handled by {libc,pthread,librt}_{enable,disable}_asynccancel symbols. This renders both LIBC_CANCEL_HANDLED and empty declaration and tst-cancel-wrappers.sh unrequired. This patch removes both the macro and the nptl test. Checked on x86_64-linux-gnu. * io/creat.c (LIBC_CANCEL_HANDLED): Remove macro. * io/ppoll.c (LIBC_CANCEL_HANDLED): Likewise. * misc/pselect.c (LIBC_CANCEL_HANDLED): Likewise. * nptl/pthreadP.h (LIBC_CANCEL_HANDLED): Likewise. * sysdeps/generic/sysdep-cancel.h (LIBC_CANCEL_HANDLED): Likewise. * sysdeps/mach/hurd/sysdep-cancel.h (LIBC_CANCEL_HANDLED): Likewise. * sysdeps/posix/pause.c (LIBC_CANCEL_HANDLED): Likewise. * sysdeps/posix/sigpause.c (LIBC_CANCEL_HANDLED): Likewise. * sysdeps/unix/sysv/linux/creat.c (LIBC_CANCEL_HANDLED): Likewise. * sysdeps/unix/sysv/linux/creat64.c (LIBC_CANCEL_HANDLED): Likewise. * sysdeps/unix/sysv/linux/sigwait.c (LIBC_CANCEL_HANDLED): Likewise. * sysdeps/unix/sysv/linux/sigwaitinfo.c (LIBC_CANCEL_HANDLED): Likewise. * nptl/Makefile [$(run-built-tests) = yes] (tests-special): Remove tst-cancel-wrappers.sh. (generated): Remove tst-cancel-wrappers.out. (tst-cancel-wrappers.out): Remove rule. * nptl/tst-cancel-wrappers.sh: Remove file. --- ChangeLog | 21 ++++++ io/creat.c | 3 - io/ppoll.c | 2 - misc/pselect.c | 2 - nptl/Makefile | 18 +----- nptl/pthreadP.h | 10 --- nptl/tst-cancel-wrappers.sh | 92 --------------------------- sysdeps/generic/sysdep-cancel.h | 1 - sysdeps/mach/hurd/sysdep-cancel.h | 1 - sysdeps/posix/pause.c | 2 - sysdeps/posix/sigpause.c | 3 - sysdeps/unix/sysv/linux/creat.c | 2 - sysdeps/unix/sysv/linux/creat64.c | 2 - sysdeps/unix/sysv/linux/sigwait.c | 3 - sysdeps/unix/sysv/linux/sigwaitinfo.c | 3 - 15 files changed, 23 insertions(+), 142 deletions(-) delete mode 100644 nptl/tst-cancel-wrappers.sh diff --git a/io/creat.c b/io/creat.c index 21ee56ebc9..3d0afcab54 100644 --- a/io/creat.c +++ b/io/creat.c @@ -27,6 +27,3 @@ creat (const char *file, mode_t mode) { return __open (file, O_WRONLY|O_CREAT|O_TRUNC, mode); } - -/* __open handles cancellation. */ -LIBC_CANCEL_HANDLED (); diff --git a/io/ppoll.c b/io/ppoll.c index ec26b99fee..5ccfdb9fda 100644 --- a/io/ppoll.c +++ b/io/ppoll.c @@ -70,7 +70,5 @@ ppoll (struct pollfd *fds, nfds_t nfds, const struct timespec *timeout, } #ifndef ppoll -/* __poll handles cancellation. */ -LIBC_CANCEL_HANDLED (); libc_hidden_def (ppoll); #endif diff --git a/misc/pselect.c b/misc/pselect.c index 2c29230596..07d5ffcef0 100644 --- a/misc/pselect.c +++ b/misc/pselect.c @@ -73,6 +73,4 @@ __pselect (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, } #ifndef __pselect weak_alias (__pselect, pselect) -/* __select handles cancellation. */ -LIBC_CANCEL_HANDLED (); #endif diff --git a/nptl/Makefile b/nptl/Makefile index b01f2b0626..c50fe81ad9 100644 --- a/nptl/Makefile +++ b/nptl/Makefile @@ -465,8 +465,7 @@ tests-reverse += tst-cancel5 tst-cancel23 tst-vfork1x tst-vfork2x ifeq ($(run-built-tests),yes) tests-special += $(objpfx)tst-stack3-mem.out $(objpfx)tst-oddstacklimit.out ifeq ($(build-shared),yes) -tests-special += $(objpfx)tst-tls6.out $(objpfx)tst-cleanup0-cmp.out \ - $(objpfx)tst-cancel-wrappers.out +tests-special += $(objpfx)tst-tls6.out $(objpfx)tst-cleanup0-cmp.out endif endif @@ -669,8 +668,7 @@ $(objpfx)$(multidir)/crtn.o: $(objpfx)crtn.o $(objpfx)$(multidir)/ ln -f $< $@ endif -generated += multidir.mk tst-atfork2.mtrace tst-cancel-wrappers.out \ - tst-tls6.out +generated += multidir.mk tst-atfork2.mtrace tst-tls6.out generated += $(objpfx)tst-atfork2.mtrace \ $(addsuffix .so,$(strip $(modules-names))) @@ -681,18 +679,6 @@ LDFLAGS-pthread.so += -e __nptl_main $(objpfx)pt-interp.os: $(common-objpfx)runtime-linker.h endif -ifeq ($(run-built-tests),yes) -ifeq (yes,$(build-shared)) -$(objpfx)tst-cancel-wrappers.out: tst-cancel-wrappers.sh - $(SHELL) $< '$(NM)' \ - $(common-objpfx)libc_pic.a \ - $(common-objpfx)libc.a \ - $(objpfx)libpthread_pic.a \ - $(objpfx)libpthread.a > $@; \ - $(evaluate-test) -endif -endif - tst-exec4-ARGS = $(host-test-program-cmd) $(objpfx)tst-execstack: $(libdl) diff --git a/nptl/pthreadP.h b/nptl/pthreadP.h index 7f16ba9800..36acb234ae 100644 --- a/nptl/pthreadP.h +++ b/nptl/pthreadP.h @@ -325,27 +325,17 @@ __do_cancel (void) /* Same as CANCEL_RESET, but for use in libc.so. */ # define LIBC_CANCEL_RESET(oldtype) \ __libc_disable_asynccancel (oldtype) -# define LIBC_CANCEL_HANDLED() \ - __asm (".globl " __SYMBOL_PREFIX "__libc_enable_asynccancel"); \ - __asm (".globl " __SYMBOL_PREFIX "__libc_disable_asynccancel") #elif IS_IN (libpthread) # define LIBC_CANCEL_ASYNC() CANCEL_ASYNC () # define LIBC_CANCEL_RESET(val) CANCEL_RESET (val) -# define LIBC_CANCEL_HANDLED() \ - __asm (".globl " __SYMBOL_PREFIX "__pthread_enable_asynccancel"); \ - __asm (".globl " __SYMBOL_PREFIX "__pthread_disable_asynccancel") #elif IS_IN (librt) # define LIBC_CANCEL_ASYNC() \ __librt_enable_asynccancel () # define LIBC_CANCEL_RESET(val) \ __librt_disable_asynccancel (val) -# define LIBC_CANCEL_HANDLED() \ - __asm (".globl " __SYMBOL_PREFIX "__librt_enable_asynccancel"); \ - __asm (".globl " __SYMBOL_PREFIX "__librt_disable_asynccancel") #else # define LIBC_CANCEL_ASYNC() 0 /* Just a dummy value. */ # define LIBC_CANCEL_RESET(val) ((void)(val)) /* Nothing, but evaluate it. */ -# define LIBC_CANCEL_HANDLED() /* Nothing. */ #endif diff --git a/nptl/tst-cancel-wrappers.sh b/nptl/tst-cancel-wrappers.sh deleted file mode 100644 index 0c5b614287..0000000000 --- a/nptl/tst-cancel-wrappers.sh +++ /dev/null @@ -1,92 +0,0 @@ -#!/bin/sh -# Test whether all cancelable functions are cancelable. -# Copyright (C) 2002-2018 Free Software Foundation, Inc. -# This file is part of the GNU C Library. -# Contributed by Jakub Jelinek , 2002. - -# 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 -# . - -NM="$1"; shift -while [ $# -gt 0 ]; do - ( $NM -P $1; echo 'end[end]:' ) | gawk ' BEGIN { -C["accept"]=1 -C["close"]=1 -C["connect"]=1 -C["creat"]=1 -C["fcntl"]=1 -C["fdatasync"]=1 -C["fsync"]=1 -C["msgrcv"]=1 -C["msgsnd"]=1 -C["msync"]=1 -C["nanosleep"]=1 -C["open"]=1 -C["open64"]=1 -C["pause"]=1 -C["poll"]=1 -C["pread"]=1 -C["pread64"]=1 -C["pselect"]=1 -C["pwrite"]=1 -C["pwrite64"]=1 -C["read"]=1 -C["readv"]=1 -C["recv"]=1 -C["recvfrom"]=1 -C["recvmsg"]=1 -C["select"]=1 -C["send"]=1 -C["sendmsg"]=1 -C["sendto"]=1 -C["sigpause"]=1 -C["sigsuspend"]=1 -C["sigwait"]=1 -C["sigwaitinfo"]=1 -C["tcdrain"]=1 -C["wait"]=1 -C["waitid"]=1 -C["waitpid"]=1 -C["write"]=1 -C["writev"]=1 -C["__xpg_sigpause"]=1 -} -/:$/ { - if (seen) - { - if (!seen_enable || !seen_disable) - { - printf "in '$1'(%s) %s'\''s cancellation missing\n", object, seen - ret = 1 - } - } - seen="" - seen_enable="" - seen_disable="" - object=gensub(/^.*\[(.*)\]:$/, "\\1", 1, $0) - next -} -{ - if (C[$1] && $2 ~ /^[TW]$/) - seen=$1 - else if ($1 ~ /^([.]|)__(libc|pthread)_enable_asynccancel$/ && $2 == "U") - seen_enable=1 - else if ($1 ~ /^([.]|)__(libc|pthread)_disable_asynccancel$/ && $2 == "U") - seen_disable=1 -} -END { - exit ret -}' || exit - shift -done diff --git a/sysdeps/generic/sysdep-cancel.h b/sysdeps/generic/sysdep-cancel.h index ba6a1e04ba..d22a786536 100644 --- a/sysdeps/generic/sysdep-cancel.h +++ b/sysdeps/generic/sysdep-cancel.h @@ -5,4 +5,3 @@ #define RTLD_SINGLE_THREAD_P (1) #define LIBC_CANCEL_ASYNC() 0 /* Just a dummy value. */ #define LIBC_CANCEL_RESET(val) ((void)(val)) /* Nothing, but evaluate it. */ -#define LIBC_CANCEL_HANDLED() /* Nothing. */ diff --git a/sysdeps/mach/hurd/sysdep-cancel.h b/sysdeps/mach/hurd/sysdep-cancel.h index ec55c7330f..f686a39024 100644 --- a/sysdeps/mach/hurd/sysdep-cancel.h +++ b/sysdeps/mach/hurd/sysdep-cancel.h @@ -6,4 +6,3 @@ #define RTLD_SINGLE_THREAD_P (0) #define LIBC_CANCEL_ASYNC() 0 /* Just a dummy value. */ #define LIBC_CANCEL_RESET(val) ((void)(val)) /* Nothing, but evaluate it. */ -#define LIBC_CANCEL_HANDLED() /* Nothing. */ diff --git a/sysdeps/posix/pause.c b/sysdeps/posix/pause.c index 2b9eca2192..879a8abd89 100644 --- a/sysdeps/posix/pause.c +++ b/sysdeps/posix/pause.c @@ -38,5 +38,3 @@ __libc_pause (void) return __sigsuspend (&set); } weak_alias (__libc_pause, pause) - -LIBC_CANCEL_HANDLED (); /* sigsuspend handles our cancellation. */ diff --git a/sysdeps/posix/sigpause.c b/sysdeps/posix/sigpause.c index db9df8eb6e..9a17d1b5d6 100644 --- a/sysdeps/posix/sigpause.c +++ b/sysdeps/posix/sigpause.c @@ -70,6 +70,3 @@ __xpg_sigpause (int sig) return __sigpause (sig, 1); } strong_alias (__xpg_sigpause, __libc___xpg_sigpause) - -/* __sigsuspend handles cancellation. */ -LIBC_CANCEL_HANDLED (); diff --git a/sysdeps/unix/sysv/linux/creat.c b/sysdeps/unix/sysv/linux/creat.c index c996cbd3cc..089a8692f2 100644 --- a/sysdeps/unix/sysv/linux/creat.c +++ b/sysdeps/unix/sysv/linux/creat.c @@ -35,6 +35,4 @@ __creat (const char *file, mode_t mode) } weak_alias (__creat, creat) -LIBC_CANCEL_HANDLED (); - #endif diff --git a/sysdeps/unix/sysv/linux/creat64.c b/sysdeps/unix/sysv/linux/creat64.c index d3ada38c9c..c9eba2ec5e 100644 --- a/sysdeps/unix/sysv/linux/creat64.c +++ b/sysdeps/unix/sysv/linux/creat64.c @@ -37,5 +37,3 @@ weak_alias (__creat64, creat64) strong_alias (__creat64, __creat) weak_alias (__creat64, creat) #endif - -LIBC_CANCEL_HANDLED (); diff --git a/sysdeps/unix/sysv/linux/sigwait.c b/sysdeps/unix/sysv/linux/sigwait.c index 920c924c9c..18ef2cf574 100644 --- a/sysdeps/unix/sysv/linux/sigwait.c +++ b/sysdeps/unix/sysv/linux/sigwait.c @@ -37,6 +37,3 @@ __sigwait (const sigset_t *set, int *sig) libc_hidden_def (__sigwait) weak_alias (__sigwait, sigwait) strong_alias (__sigwait, __libc_sigwait) - -/* __sigtimedwait handles cancellation. */ -LIBC_CANCEL_HANDLED (); diff --git a/sysdeps/unix/sysv/linux/sigwaitinfo.c b/sysdeps/unix/sysv/linux/sigwaitinfo.c index 55003fc516..71bdc943a0 100644 --- a/sysdeps/unix/sysv/linux/sigwaitinfo.c +++ b/sysdeps/unix/sysv/linux/sigwaitinfo.c @@ -28,6 +28,3 @@ __sigwaitinfo (const sigset_t *set, siginfo_t *info) libc_hidden_def (__sigwaitinfo) weak_alias (__sigwaitinfo, sigwaitinfo) strong_alias (__sigwaitinfo, __libc_sigwaitinfo) - -/* __sigtimedwait handles cancellation. */ -LIBC_CANCEL_HANDLED (); From patchwork Fri Dec 28 01:02:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1019051 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-98814-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="T1cEOlFZ"; dkim=pass (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="bvzZOaxZ"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43QpNl3DLQz9s2P for ; Fri, 28 Dec 2018 12:03:19 +1100 (AEDT) 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:cc:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=RM17WHtAP1QXVt5ld2Wnq/n6uSx4/qG GwhBHSjbtaNHU1XdCSpgofd+yPTHN8unjxxiHnHmdnFEotZe8zumkm5OaWYH3i4p iJ1zgms71LMbRM+YVKbRjPbdSw8WYIuSnvrSz7OeHLTVy/wAOc/m6V5OhaCC/NQX FbnLlShWcx+Y= 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:cc:subject:date:message-id:in-reply-to :references; s=default; bh=FBJi2oDFWGZLoeXbyfd9w+be9v4=; b=T1cEO lFZqIltbN+f6p0DUggyUjUcMLVhorAFrjldVTqvpqdfsmK5n3BmtWuvEnwZ9IRCb l10barSqkUHvcNqhFJnpMvHhNNYgNBp4bFdFOYvFETvI97ge6jmT+PWy7ocL3gmR 6E0ZikpV3eCkbz1mm3ive3HjNg5OFMprFvBP7U= Received: (qmail 35047 invoked by alias); 28 Dec 2018 01:03:07 -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 34956 invoked by uid 89); 28 Dec 2018 01:03:06 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=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.2 spammy=upcoming, 56, act X-HELO: mail-qt1-f193.google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=sHwaooOHDVgMVCIgf5T3xOkXrhPOlcRRg5pvWasicX4=; b=bvzZOaxZoht1gVMkz8THmFsttkhI3Wwk9NWv5/0t16sGhVoxjYeU6G9lHv+KbHjHFR wuHKCV8IR1Nnl8q9g9w06TjrKhWYclgRwjQvfj+y1MX+bE1M/cKUjgrBPmDCLDLXyh/U l5T+15hlOnrtFU7+xnu4siyV1ZEVJPgJ5vJOI= From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Adhemerval Zanella Subject: [PATCH v2 2/6] nptl: Fix testcases for new pthread cancellation mechanism Date: Thu, 27 Dec 2018 23:02:51 -0200 Message-Id: <20181228010255.21406-3-adhemerval.zanella@linaro.org> In-Reply-To: <20181228010255.21406-1-adhemerval.zanella@linaro.org> References: <20181228010255.21406-1-adhemerval.zanella@linaro.org> From: Adhemerval Zanella With upcoming fix for BZ#12683, pthread cancellation does not act for: 1. If syscall is blocked but with some side effects already having taken place (e.g. a partial read or write). 2. After the syscall has returned. The main change is due the fact programs need to act in syscalls with side-effects (for instance, to avoid leak of allocated resources or handle partial read/write). This patch changes the NPTL testcase that assumes the old behavior and also changes the tst-backtrace{5,6} to ignore the cancellable wrappers. Checked on i686-linux-gnu, x86_64-linux-gnu, x86_64-linux-gnux32, aarch64-linux-gnu, arm-linux-gnueabihf, powerpc64le-linux-gnu, powerpc-linux-gnu, sparcv9-linux-gnu, and sparc64-linux-gnu. * debug/tst-backtrace5.c (handle_signal): Avoid cancellable wrappers in backtrace analysis. * nptl/tst-cancel4.c (tf_write): Handle cancelled syscall with side-effects. (tf_send): Likewise. --- ChangeLog | 6 ++++++ debug/tst-backtrace5.c | 19 ++++++++++--------- nptl/tst-cancel4.c | 8 ++++++++ 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/debug/tst-backtrace5.c b/debug/tst-backtrace5.c index 0e6fb1a024..dad741e12a 100644 --- a/debug/tst-backtrace5.c +++ b/debug/tst-backtrace5.c @@ -69,17 +69,18 @@ handle_signal (int signum) FAIL (); return; } - /* Do not check name for signal trampoline. */ - i = 2; - if (!match (symbols[i++], "read")) + + /* Do not check name for signal trampoline or cancellable syscall + wrappers (__syscall_cancel*). */ + for (; i < n - 1; i++) + if (match (symbols[i], "read")) + break; + if (i == n - 1) { - /* Perhaps symbols[2] is __kernel_vsyscall? */ - if (!match (symbols[i++], "read")) - { - FAIL (); - return; - } + FAIL (); + return; } + for (; i < n - 1; i++) if (!match (symbols[i], "fn")) { diff --git a/nptl/tst-cancel4.c b/nptl/tst-cancel4.c index 05325385b1..45b3d43c3b 100644 --- a/nptl/tst-cancel4.c +++ b/nptl/tst-cancel4.c @@ -166,6 +166,10 @@ tf_write (void *arg) char buf[WRITE_BUFFER_SIZE]; memset (buf, '\0', sizeof (buf)); s = write (fd, buf, sizeof (buf)); + /* The write can return a value higher than 0 (meaning partial write) + due to the SIGCANCEL, but the thread may still be pending + cancellation. */ + pthread_testcancel (); pthread_cleanup_pop (0); @@ -743,6 +747,10 @@ tf_send (void *arg) char mem[WRITE_BUFFER_SIZE]; send (tempfd2, mem, arg == NULL ? sizeof (mem) : 1, 0); + /* The send can return a value higher than 0 (meaning partial send) + due to the SIGCANCEL, but the thread may still be pending + cancellation. */ + pthread_testcancel (); pthread_cleanup_pop (0); From patchwork Fri Dec 28 01:02:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1019052 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-98815-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="CSgDhI/F"; dkim=pass (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="JDNYY/OS"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43QpNw47T1z9s2P for ; Fri, 28 Dec 2018 12:03:28 +1100 (AEDT) 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=bw8+5WYN9r//1nlzwVPUNMpqT+2kPaX j6mHN7qetvIStnxznqu3cfX1/y3oRF8BrVSiCeHiZ0A4LqVbGa4Jn/UdNbXplWxn U6kr95Dvl6vXDWw2QyvwfHLGPTKAVzJIyG5J2th5B8eLTj0sWKms2eXxH4+c6Her ueUQtpGGDTDY= 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=J3wIIrY3fxfSAaeR/zeqglPu78M=; b=CSgDh I/FSkXRddul+NRD056vhRAr4jXN+3ItxB8twwjVRcJVnWetlG+WzmXG1QHav5O// ybn8e3sJV1Jo8zpICzkIJxb/x7Q7Wq9CYG/rCQYCJgrvbCyjWmV+D650uPGuX6AP lJuI3KwKT3ZfsQtW2kb1DgqxpfpooE3lsPCAew= Received: (qmail 35341 invoked by alias); 28 Dec 2018 01:03:08 -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 35236 invoked by uid 89); 28 Dec 2018 01:03:08 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=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.2 spammy=exchange, lock, optimize, indicated X-HELO: mail-qk1-f195.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=gzhUnGrl2CIILyE/qLsnzPtwIrjHGrO0EU8entvzrpg=; b=JDNYY/OSU/GrdDeA5zPTk7hbiblSZQ4p6Y3JNfp1C2/loxggj75fZ49QLJAAWwM1QD X3tEUKBo71W2zRKEknJMlVeW7hNst5vlY6gyhVCIahFFRfV9bwkcDJk2p0F1ebejeoLy F6npfn9FjaP9gjyYpTi9qJhb3onxdmNG4ZjgI= From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH v2 3/6] x86: Remove wrong THREAD_ATOMIC_* macros Date: Thu, 27 Dec 2018 23:02:52 -0200 Message-Id: <20181228010255.21406-4-adhemerval.zanella@linaro.org> In-Reply-To: <20181228010255.21406-1-adhemerval.zanella@linaro.org> References: <20181228010255.21406-1-adhemerval.zanella@linaro.org> The x86 defines optimized THREAD_ATOMIC_* macros where reference always the current thread instead of the one indicated by input 'descr' argument. It work as long the input is the self thread pointer, however it generates wrong code is the semantic is to set a bit atomicialy from another thread. This is not an issue for current GLIBC usage, however the new cancellation code expects that some synchronization code to atomically set bits from different threads. The generic code generates an additional load to reference to TLS segment, for instance the code: THREAD_ATOMIC_BIT_SET (THREAD_SELF, cancelhandling, CANCELED_BIT); Compiles to: lock;orl $4, %fs:776 Where with patch changes it now compiles to: mov %fs:16,%rax lock;orl $4, 776(%rax) If some usage indeed proves to be a hotspot we can add an extra macro with a more descriptive name (THREAD_ATOMIC_BIT_SET_SELF for instance) where x86_64 might optimize it. Checked on x86_64-linux-gnu. * sysdeps/x86_64/nptl/tls.h (THREAD_ATOMIC_CMPXCHG_VAL, THREAD_ATOMIC_AND, THREAD_ATOMIC_BIT_SET): Remove macros. --- ChangeLog | 3 +++ sysdeps/x86_64/nptl/tls.h | 37 ------------------------------------- 2 files changed, 3 insertions(+), 37 deletions(-) diff --git a/sysdeps/x86_64/nptl/tls.h b/sysdeps/x86_64/nptl/tls.h index e88561c934..835a0d3deb 100644 --- a/sysdeps/x86_64/nptl/tls.h +++ b/sysdeps/x86_64/nptl/tls.h @@ -306,43 +306,6 @@ _Static_assert (offsetof (tcbhead_t, __glibc_unused2) == 0x80, }}) -/* Atomic compare and exchange on TLS, returning old value. */ -# define THREAD_ATOMIC_CMPXCHG_VAL(descr, member, newval, oldval) \ - ({ __typeof (descr->member) __ret; \ - __typeof (oldval) __old = (oldval); \ - if (sizeof (descr->member) == 4) \ - asm volatile (LOCK_PREFIX "cmpxchgl %2, %%fs:%P3" \ - : "=a" (__ret) \ - : "0" (__old), "r" (newval), \ - "i" (offsetof (struct pthread, member))); \ - else \ - /* Not necessary for other sizes in the moment. */ \ - abort (); \ - __ret; }) - - -/* Atomic logical and. */ -# define THREAD_ATOMIC_AND(descr, member, val) \ - (void) ({ if (sizeof ((descr)->member) == 4) \ - asm volatile (LOCK_PREFIX "andl %1, %%fs:%P0" \ - :: "i" (offsetof (struct pthread, member)), \ - "ir" (val)); \ - else \ - /* Not necessary for other sizes in the moment. */ \ - abort (); }) - - -/* Atomic set bit. */ -# define THREAD_ATOMIC_BIT_SET(descr, member, bit) \ - (void) ({ if (sizeof ((descr)->member) == 4) \ - asm volatile (LOCK_PREFIX "orl %1, %%fs:%P0" \ - :: "i" (offsetof (struct pthread, member)), \ - "ir" (1 << (bit))); \ - else \ - /* Not necessary for other sizes in the moment. */ \ - abort (); }) - - /* Set the stack guard field in TCB head. */ # define THREAD_SET_STACK_GUARD(value) \ THREAD_SETMEM (THREAD_SELF, header.stack_guard, value) From patchwork Fri Dec 28 01:02:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1019054 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-98817-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="Lpn9V0Qd"; dkim=pass (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="OeH4p5Oy"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43QpPH2LWPz9s55 for ; Fri, 28 Dec 2018 12:03:46 +1100 (AEDT) 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=XA3GLVXaXm3IwIKewK2jZVP+GQy0wik bX7pnA5Aog7mUv7qyFXzoIsy9G4m3L1JvJhLVQU6t+L9bWcvwLS/Q4IdiJf/0n3i kG65gOTA8sLoChgQHvZ+qXuOEUI+OCMY/EqTnJWbFgl+uTj5YKH+x2S4NOP0PyZ0 05s6V1llyQDI= 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=c2X9oJGmZoB1k+zVLGIoO+KMXpY=; b=Lpn9V 0Qdh8LvEdR2Br4yWeva21F4T7qhbQe1Rg+kXarnltw/ecRqDO77h2gOHMu98j8Ns SHSZ8A9JzI2MH8prx++3Kd/tsn0JsPCSkRrOzp//RwxFWZQttAtzcMGIvKFN4Zvw 1MRrlIsuW+c/5mYH9vx8QaAE72l4BZ6srzIRpU= Received: (qmail 35444 invoked by alias); 28 Dec 2018 01:03:09 -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 35318 invoked by uid 89); 28 Dec 2018 01:03:08 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=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.2 spammy=exchange, optimize, indicated X-HELO: mail-qt1-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:in-reply-to:references; bh=qhYe6UrU7SVOJ3qWYli9JzPtOcdsQDWefh1Yi6BmuIA=; b=OeH4p5Oy7Zy+fjR5NYBYq6SknoDF10gzZZUuqhWyhIKqtJAghxvoG395pxVPpFYtcE u+bL12rR88yeM2jphF/xpNLSuwE45PGJlg9LtGvhzo24KvC7Kmt758l/TMePNdAj9DjH TBBagtd75/FaMl7JzZw4GO7RcOWDlHDt5gXuU= From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH v2 4/6] i386: Remove bogus THREAD_ATOMIC_* macros Date: Thu, 27 Dec 2018 23:02:53 -0200 Message-Id: <20181228010255.21406-5-adhemerval.zanella@linaro.org> In-Reply-To: <20181228010255.21406-1-adhemerval.zanella@linaro.org> References: <20181228010255.21406-1-adhemerval.zanella@linaro.org> The x86 defines optimized THREAD_ATOMIC_* macros where reference always the current thread instead of the one indicated by input 'descr' argument. It work as long the input is the self thread pointer, however it generates wrong code is the semantic is to set a bit atomicialy from another thread. This is not an issue for current GLIBC usage, however the new cancellation code expects that some synchronization code to atomically set bits from different threads. If some usage indeed proves to be a hotspot we can add an extra macro with a more descriptive name (THREAD_ATOMIC_BIT_SET_SELF for instance) where i386 might optimize it. Checked on i686-linux-gnu. * sysdeps/i686/nptl/tls.h (THREAD_ATOMIC_CMPXCHG_VAL, THREAD_ATOMIC_AND, THREAD_ATOMIC_BIT_SET): Remove macros. --- ChangeLog | 3 +++ sysdeps/i386/nptl/tls.h | 37 ------------------------------------- 2 files changed, 3 insertions(+), 37 deletions(-) diff --git a/sysdeps/i386/nptl/tls.h b/sysdeps/i386/nptl/tls.h index 12285d3217..22ebf3d741 100644 --- a/sysdeps/i386/nptl/tls.h +++ b/sysdeps/i386/nptl/tls.h @@ -362,43 +362,6 @@ tls_fill_user_desc (union user_desc_init *desc, }}) -/* Atomic compare and exchange on TLS, returning old value. */ -#define THREAD_ATOMIC_CMPXCHG_VAL(descr, member, newval, oldval) \ - ({ __typeof (descr->member) __ret; \ - __typeof (oldval) __old = (oldval); \ - if (sizeof (descr->member) == 4) \ - asm volatile (LOCK_PREFIX "cmpxchgl %2, %%gs:%P3" \ - : "=a" (__ret) \ - : "0" (__old), "r" (newval), \ - "i" (offsetof (struct pthread, member))); \ - else \ - /* Not necessary for other sizes in the moment. */ \ - abort (); \ - __ret; }) - - -/* Atomic logical and. */ -#define THREAD_ATOMIC_AND(descr, member, val) \ - (void) ({ if (sizeof ((descr)->member) == 4) \ - asm volatile (LOCK_PREFIX "andl %1, %%gs:%P0" \ - :: "i" (offsetof (struct pthread, member)), \ - "ir" (val)); \ - else \ - /* Not necessary for other sizes in the moment. */ \ - abort (); }) - - -/* Atomic set bit. */ -#define THREAD_ATOMIC_BIT_SET(descr, member, bit) \ - (void) ({ if (sizeof ((descr)->member) == 4) \ - asm volatile (LOCK_PREFIX "orl %1, %%gs:%P0" \ - :: "i" (offsetof (struct pthread, member)), \ - "ir" (1 << (bit))); \ - else \ - /* Not necessary for other sizes in the moment. */ \ - abort (); }) - - /* Set the stack guard field in TCB head. */ #define THREAD_SET_STACK_GUARD(value) \ THREAD_SETMEM (THREAD_SELF, header.stack_guard, value) From patchwork Fri Dec 28 01:02:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1019056 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-98819-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="r5L9JQLj"; dkim=pass (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="Cn4Aslyl"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43QpPg5kq9z9s2P for ; Fri, 28 Dec 2018 12:04:07 +1100 (AEDT) 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=CGu/nvi85Gk8k18gCQkcuSHvi47G4y0 HPXH8KjksXSI9zp+bW9U8wOqUnGDDd+S4B67W2zsVPXh++Cqds6QXmb0OAqvqIIH ehLfexalDYLHOq6G5GurME70EHMTbPwcu4R6crYNjWxb2JAr5y91Vgel+4bhZIEg F0tNCH9Guh7A= 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=W26QwQD7BMNKGR9N/kUDd158oIM=; b=r5L9J QLjAKCBgKomXg0ej/Fg1h+k3Y6MAKY9RD9WsGRCloDLjc65vsIlF2X9BjrxiJGeS MaVI3Lb3RomTcEIeaQPmEBvQodUh59cGAh1NiEYK3obAt52cf4Fsog4ukIDtWLrY cDO3y8+nnYRh2jDloRVzulC9QyLAxrdN/SYXM8= Received: (qmail 36700 invoked by alias); 28 Dec 2018 01:03:19 -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 36603 invoked by uid 89); 28 Dec 2018 01:03:18 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=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.2 spammy=interrupted X-HELO: mail-qk1-f194.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=Xp68K0uJH2vK+msXPR4/hCf468AbtDpJx2jTi6Aq/m0=; b=Cn4AslylzYsi/OV0NSCWLV5Htom9VIT47a1dqulTYAO//hUYjHjlXMe68syH5EZ14w aCsZDRY9Zo6LehY9WV4VZ79SZCyICNuzKHqR7sZJ/2z4E1UBSMEVCwEZXC0ffv7rxnnw DxmbPJrfY20Yeq23eWUje2MNnefhH9dhtKB5o= From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH v2 5/6] nptl: Cleanup cancellation macros Date: Thu, 27 Dec 2018 23:02:54 -0200 Message-Id: <20181228010255.21406-6-adhemerval.zanella@linaro.org> In-Reply-To: <20181228010255.21406-1-adhemerval.zanella@linaro.org> References: <20181228010255.21406-1-adhemerval.zanella@linaro.org> This patch wraps all uses of *_{enable,disable}_asynccancel and and *_CANCEL_{ASYNC,RESET} in either already provided macros (lll_futex_timed_wait_cancel) or creates new ones if the functionality is not provided (SYSCALL_CANCEL_NCS, lll_futex_wait_cancel, and lll_futex_timed_wait_cancel). Also for some generic implementations, the direct call of the macros are removed since the underlying symbols are suppose to provide cancellation support. This is a priliminary patch intended to simplify the work required for BZ#12683 fix. It is a refactor change, no semantic changes are expected. Checked on x86_64-linux-gnu and i686-linux-gnu. * nptl/pthread_join_common.c (__pthread_timedjoin_ex): Use lll_wait_tid with timeout. * nptl/sem_wait.c (__old_sem_wait): Use lll_futex_wait_cancel. * sysdeps/nptl/aio_misc.h (AIO_MISC_WAIT): Use futex_reltimed_wait_cancelable for cancelabla mode. * sysdeps/nptl/gai_misc.h (GAI_MISC_WAIT): Likewise. * sysdeps/posix/open64.c (__libc_open64): Do not call cancelation macros. * sysdeps/posix/sigwait.c (__sigwait): Likewise. * sysdeps/posix/waitid.c (__sigwait): Likewise. * sysdeps/unix/sysdep.h (__SYSCALL_CANCEL_CALL, SYSCALL_CANCEL_NCS): New macro. * sysdeps/nptl/lowlevellock.h (lll_wait_tid): Add timeout argument. (lll_timedwait_tid): Remove macro. * sysdeps/unix/sysv/linux/i386/lowlevellock.h (lll_wait_tid): Likewise. (lll_timedwait_tid): Likewise. * sysdeps/unix/sysv/linux/sparc/lowlevellock.h (lll_wait_tid): Likewise. (lll_timedwait_tid): Likewise. * sysdeps/unix/sysv/linux/x86_64/lowlevellock.h (lll_wait_tid): Likewise. (lll_timedwait_tid): Likewise. * sysdeps/unix/sysv/linux/clock_nanosleep.c (__clock_nanosleep): Use INTERNAL_SYSCALL_CANCEL. * sysdeps/unix/sysv/linux/futex-internal.h (futex_reltimed_wait_cancelable): Use LIBC_CANCEL_{ASYNC,RESET} instead of __pthread_{enable,disable}_asynccancel. * sysdeps/unix/sysv/linux/lowlevellock-futex.h (lll_futex_wait_cancel): New macro. --- ChangeLog | 31 ++++++++++++++ nptl/pthread_join_common.c | 9 +--- nptl/sem_wait.c | 8 +--- sysdeps/nptl/aio_misc.h | 15 +++---- sysdeps/nptl/gai_misc.h | 15 +++---- sysdeps/nptl/lowlevellock.h | 40 ++++++++---------- sysdeps/posix/open64.c | 12 +----- sysdeps/posix/sigwait.c | 12 +----- sysdeps/posix/waitid.c | 12 +----- sysdeps/unix/sysv/linux/clock_nanosleep.c | 20 +++------ sysdeps/unix/sysv/linux/futex-internal.h | 4 +- sysdeps/unix/sysv/linux/i386/lowlevellock.h | 42 +++++++++---------- sysdeps/unix/sysv/linux/lowlevellock-futex.h | 11 +++++ sysdeps/unix/sysv/linux/sparc/lowlevellock.h | 39 ++++++++--------- sysdeps/unix/sysv/linux/x86_64/lowlevellock.h | 40 +++++++++--------- 15 files changed, 146 insertions(+), 164 deletions(-) diff --git a/nptl/pthread_join_common.c b/nptl/pthread_join_common.c index 702fcd1545..63d693210d 100644 --- a/nptl/pthread_join_common.c +++ b/nptl/pthread_join_common.c @@ -81,14 +81,7 @@ __pthread_timedjoin_ex (pthread_t threadid, void **thread_return, un-wait-ed for again. */ pthread_cleanup_push (cleanup, &pd->joinid); - int oldtype = CANCEL_ASYNC (); - - if (abstime != NULL) - result = lll_timedwait_tid (pd->tid, abstime); - else - lll_wait_tid (pd->tid); - - CANCEL_RESET (oldtype); + result = lll_wait_tid (pd->tid, abstime); pthread_cleanup_pop (0); } diff --git a/nptl/sem_wait.c b/nptl/sem_wait.c index e7d910613f..e057b05dd6 100644 --- a/nptl/sem_wait.c +++ b/nptl/sem_wait.c @@ -56,14 +56,8 @@ __old_sem_wait (sem_t *sem) if (atomic_decrement_if_positive (futex) > 0) return 0; - /* Enable asynchronous cancellation. Required by the standard. */ - int oldtype = __pthread_enable_asynccancel (); - /* Always assume the semaphore is shared. */ - err = lll_futex_wait (futex, 0, LLL_SHARED); - - /* Disable asynchronous cancellation. */ - __pthread_disable_asynccancel (oldtype); + err = lll_futex_wait_cancel (futex, 0, LLL_SHARED); } while (err == 0 || err == -EWOULDBLOCK); diff --git a/sysdeps/nptl/aio_misc.h b/sysdeps/nptl/aio_misc.h index 206d8e193d..70f1e057b5 100644 --- a/sysdeps/nptl/aio_misc.h +++ b/sysdeps/nptl/aio_misc.h @@ -41,15 +41,15 @@ { \ pthread_mutex_unlock (&__aio_requests_mutex); \ \ - int oldtype; \ - if (cancel) \ - oldtype = LIBC_CANCEL_ASYNC (); \ - \ int status; \ do \ { \ - status = futex_reltimed_wait ((unsigned int *) futexaddr, oldval, \ - timeout, FUTEX_PRIVATE); \ + if (cancel) \ + status = futex_reltimed_wait_cancelable ( \ + (unsigned int *) futexaddr, oldval, timeout, FUTEX_PRIVATE); \ + else \ + status = futex_reltimed_wait ((unsigned int *) futexaddr, \ + oldval, timeout, FUTEX_PRIVATE); \ if (status != EAGAIN) \ break; \ \ @@ -57,9 +57,6 @@ } \ while (oldval != 0); \ \ - if (cancel) \ - LIBC_CANCEL_RESET (oldtype); \ - \ if (status == EINTR) \ result = EINTR; \ else if (status == ETIMEDOUT) \ diff --git a/sysdeps/nptl/gai_misc.h b/sysdeps/nptl/gai_misc.h index 815e6c0dc6..831b43a479 100644 --- a/sysdeps/nptl/gai_misc.h +++ b/sysdeps/nptl/gai_misc.h @@ -42,15 +42,15 @@ { \ pthread_mutex_unlock (&__gai_requests_mutex); \ \ - int oldtype; \ - if (cancel) \ - oldtype = LIBC_CANCEL_ASYNC (); \ - \ int status; \ do \ { \ - status = futex_reltimed_wait ((unsigned int *) futexaddr, oldval, \ - timeout, FUTEX_PRIVATE); \ + if (cancel) \ + status = futex_reltimed_wait_cancelable ( \ + (unsigned int *) futexaddr, oldval, timeout, FUTEX_PRIVATE); \ + else \ + status = futex_reltimed_wait ((unsigned int *) futexaddr, \ + oldval, timeout, FUTEX_PRIVATE); \ if (status != EAGAIN) \ break; \ \ @@ -58,9 +58,6 @@ } \ while (oldval != 0); \ \ - if (cancel) \ - LIBC_CANCEL_RESET (oldtype); \ - \ if (status == EINTR) \ result = EINTR; \ else if (status == ETIMEDOUT) \ diff --git a/sysdeps/nptl/lowlevellock.h b/sysdeps/nptl/lowlevellock.h index bfbda99940..d7837be5d4 100644 --- a/sysdeps/nptl/lowlevellock.h +++ b/sysdeps/nptl/lowlevellock.h @@ -175,33 +175,29 @@ extern int __lll_timedlock_wait (int *futex, const struct timespec *, #define LLL_LOCK_INITIALIZER (0) #define LLL_LOCK_INITIALIZER_LOCKED (1) +extern int __lll_timedwait_tid (int *, const struct timespec *) + attribute_hidden; /* The kernel notifies a process which uses CLONE_CHILD_CLEARTID via futex wake-up when the clone terminates. The memory location contains the thread ID while the clone is running and is reset to zero by the kernel afterwards. The kernel up to version 3.16.3 does not use the private futex - operations for futex wake-up when the clone terminates. */ -#define lll_wait_tid(tid) \ - do { \ - __typeof (tid) __tid; \ - /* We need acquire MO here so that we synchronize \ - with the kernel's store to 0 when the clone \ - terminates. (see above) */ \ - while ((__tid = atomic_load_acquire (&(tid))) != 0) \ - lll_futex_wait (&(tid), __tid, LLL_SHARED); \ - } while (0) - -extern int __lll_timedwait_tid (int *, const struct timespec *) - attribute_hidden; - -/* As lll_wait_tid, but with a timeout. If the timeout occurs then return - ETIMEDOUT. If ABSTIME is invalid, return EINVAL. */ -#define lll_timedwait_tid(tid, abstime) \ - ({ \ - int __res = 0; \ - if ((tid) != 0) \ - __res = __lll_timedwait_tid (&(tid), (abstime)); \ - __res; \ + operations for futex wake-up when the clone terminates. + If ABSTIME is not NULL, is used a timeout for futex call. If the timeout + occurs then return ETIMEOUT, if ABSTIME is invalid, return EINVAL. + The futex operation are issues with cancellable versions. */ +#define lll_wait_tid(tid, abstime) \ + ({ \ + int __res = 0; \ + __typeof (tid) __tid; \ + if (abstime != NULL) \ + __res = __lll_timedwait_tid (&(tid), (abstime)); \ + else \ + /* We need acquire MO here so that we synchronize with the \ + kernel's store to 0 when the clone terminates. (see above) */ \ + while ((__tid = atomic_load_acquire (&(tid))) != 0) \ + lll_futex_wait_cancel (&(tid), __tid, LLL_SHARED); \ + __res; \ }) diff --git a/sysdeps/posix/open64.c b/sysdeps/posix/open64.c index c4209c8cdb..e4ec5d1876 100644 --- a/sysdeps/posix/open64.c +++ b/sysdeps/posix/open64.c @@ -34,16 +34,8 @@ __libc_open64 (const char *file, int oflag, ...) va_end (arg); } - if (SINGLE_THREAD_P) - return __libc_open (file, oflag | O_LARGEFILE, mode); - - int oldtype = LIBC_CANCEL_ASYNC (); - - int result = __libc_open (file, oflag | O_LARGEFILE, mode); - - LIBC_CANCEL_RESET (oldtype); - - return result; + /* __libc_open should be a cancellation point. */ + return __libc_open (file, oflag | O_LARGEFILE, mode); } weak_alias (__libc_open64, __open64) libc_hidden_weak (__open64) diff --git a/sysdeps/posix/sigwait.c b/sysdeps/posix/sigwait.c index 4ff9d847d4..2803d2a0c5 100644 --- a/sysdeps/posix/sigwait.c +++ b/sysdeps/posix/sigwait.c @@ -85,16 +85,8 @@ do_sigwait (const sigset_t *set, int *sig) int __sigwait (const sigset_t *set, int *sig) { - if (SINGLE_THREAD_P) - return do_sigwait (set, sig); - - int oldtype = LIBC_CANCEL_ASYNC (); - - int result = do_sigwait (set, sig); - - LIBC_CANCEL_RESET (oldtype); - - return result; + /* __sigsuspend should be a cancellation point. */ + return do_sigitid (idtype, id, infop, options); } libc_hidden_def (__sigwait) weak_alias (__sigwait, sigwait) diff --git a/sysdeps/posix/waitid.c b/sysdeps/posix/waitid.c index 3207c742c2..98f35d078e 100644 --- a/sysdeps/posix/waitid.c +++ b/sysdeps/posix/waitid.c @@ -151,16 +151,8 @@ OUR_WAITID (idtype_t idtype, id_t id, siginfo_t *infop, int options) int __waitid (idtype_t idtype, id_t id, siginfo_t *infop, int options) { - if (SINGLE_THREAD_P) - return do_waitid (idtype, id, infop, options); - - int oldtype = LIBC_CANCEL_ASYNC (); - - int result = do_waitid (idtype, id, infop, options); - - LIBC_CANCEL_RESET (oldtype); - - return result; + /* __waitpid should be a cancellation point. */ + return do_waitid (idtype, id, infop, options); } weak_alias (__waitid, waitid) strong_alias (__waitid, __libc_waitid) diff --git a/sysdeps/unix/sysv/linux/clock_nanosleep.c b/sysdeps/unix/sysv/linux/clock_nanosleep.c index 93d5d6ef12..c91663acfd 100644 --- a/sysdeps/unix/sysv/linux/clock_nanosleep.c +++ b/sysdeps/unix/sysv/linux/clock_nanosleep.c @@ -28,26 +28,16 @@ int __clock_nanosleep (clockid_t clock_id, int flags, const struct timespec *req, struct timespec *rem) { - INTERNAL_SYSCALL_DECL (err); - int r; - if (clock_id == CLOCK_THREAD_CPUTIME_ID) return EINVAL; if (clock_id == CLOCK_PROCESS_CPUTIME_ID) clock_id = MAKE_PROCESS_CPUCLOCK (0, CPUCLOCK_SCHED); - if (SINGLE_THREAD_P) - r = INTERNAL_SYSCALL (clock_nanosleep, err, 4, clock_id, flags, req, rem); - else - { - int oldstate = LIBC_CANCEL_ASYNC (); - - r = INTERNAL_SYSCALL (clock_nanosleep, err, 4, clock_id, flags, req, - rem); - - LIBC_CANCEL_RESET (oldstate); - } - + /* If the call is interrupted by a signal handler or encounters an error, + it returns a positive value similar to errno. */ + INTERNAL_SYSCALL_DECL (err); + int r = INTERNAL_SYSCALL_CANCEL (clock_nanosleep, err, clock_id, flags, + req, rem); return (INTERNAL_SYSCALL_ERROR_P (r, err) ? INTERNAL_SYSCALL_ERRNO (r, err) : 0); } diff --git a/sysdeps/unix/sysv/linux/futex-internal.h b/sysdeps/unix/sysv/linux/futex-internal.h index 96a07b05b9..d36235a925 100644 --- a/sysdeps/unix/sysv/linux/futex-internal.h +++ b/sysdeps/unix/sysv/linux/futex-internal.h @@ -138,9 +138,9 @@ futex_reltimed_wait_cancelable (unsigned int *futex_word, const struct timespec *reltime, int private) { int oldtype; - oldtype = __pthread_enable_asynccancel (); + oldtype = LIBC_CANCEL_ASYNC (); int err = lll_futex_timed_wait (futex_word, expected, reltime, private); - __pthread_disable_asynccancel (oldtype); + LIBC_CANCEL_RESET (oldtype); switch (err) { case 0: diff --git a/sysdeps/unix/sysv/linux/i386/lowlevellock.h b/sysdeps/unix/sysv/linux/i386/lowlevellock.h index 38fbc2556f..c0b938bd9f 100644 --- a/sysdeps/unix/sysv/linux/i386/lowlevellock.h +++ b/sysdeps/unix/sysv/linux/i386/lowlevellock.h @@ -221,32 +221,30 @@ extern int __lll_timedlock_elision (int *futex, short *adapt_count, #define lll_islocked(futex) \ (futex != LLL_LOCK_INITIALIZER) +extern int __lll_timedwait_tid (int *tid, const struct timespec *abstime) + __attribute__ ((regparm (2))) attribute_hidden; + /* The kernel notifies a process which uses CLONE_CHILD_CLEARTID via futex wake-up when the clone terminates. The memory location contains the thread ID while the clone is running and is reset to zero by the kernel afterwards. The kernel up to version 3.16.3 does not use the private futex - operations for futex wake-up when the clone terminates. */ -#define lll_wait_tid(tid) \ - do { \ - __typeof (tid) __tid; \ - while ((__tid = (tid)) != 0) \ - lll_futex_wait (&(tid), __tid, LLL_SHARED);\ - } while (0) - -extern int __lll_timedwait_tid (int *tid, const struct timespec *abstime) - __attribute__ ((regparm (2))) attribute_hidden; - -/* As lll_wait_tid, but with a timeout. If the timeout occurs then return - ETIMEDOUT. If ABSTIME is invalid, return EINVAL. - XXX Note that this differs from the generic version in that we do the - error checking here and not in __lll_timedwait_tid. */ -#define lll_timedwait_tid(tid, abstime) \ - ({ \ - int __result = 0; \ - if ((tid) != 0) \ - __result = __lll_timedwait_tid (&(tid), (abstime)); \ - __result; }) - + operations for futex wake-up when the clone terminates. + If ABSTIME is not NULL, is used a timeout for futex call. If the timeout + occurs then return ETIMEOUT, if ABSTIME is invalid, return EINVAL. + The futex operation are issues with cancellable versions. */ +#define lll_wait_tid(tid, abstime) \ + ({ \ + int __res = 0; \ + __typeof (tid) __tid; \ + if (abstime != NULL) \ + __res = __lll_timedwait_tid (&(tid), (abstime)); \ + else \ + /* We need acquire MO here so that we synchronize with the \ + kernel's store to 0 when the clone terminates. (see above) */ \ + while ((__tid = atomic_load_acquire (&(tid))) != 0) \ + lll_futex_wait_cancel (&(tid), __tid, LLL_SHARED); \ + __res; \ + }) extern int __lll_lock_elision (int *futex, short *adapt_count, int private) attribute_hidden; diff --git a/sysdeps/unix/sysv/linux/lowlevellock-futex.h b/sysdeps/unix/sysv/linux/lowlevellock-futex.h index fc834ed16e..71420fea89 100644 --- a/sysdeps/unix/sysv/linux/lowlevellock-futex.h +++ b/sysdeps/unix/sysv/linux/lowlevellock-futex.h @@ -125,6 +125,17 @@ private), \ nr_wake, nr_move, mutex, val) + +/* Cancellable futex macros. */ +#define lll_futex_wait_cancel(futexp, val, private) \ + ({ \ + int __oldtype = CANCEL_ASYNC (); \ + long int __err = lll_futex_wait (futexp, val, LLL_SHARED); \ + CANCEL_RESET (__oldtype); \ + __err; \ + }) + + #endif /* !__ASSEMBLER__ */ #endif /* lowlevellock-futex.h */ diff --git a/sysdeps/unix/sysv/linux/sparc/lowlevellock.h b/sysdeps/unix/sysv/linux/sparc/lowlevellock.h index e2c0b2abaa..28f368dbe7 100644 --- a/sysdeps/unix/sysv/linux/sparc/lowlevellock.h +++ b/sysdeps/unix/sysv/linux/sparc/lowlevellock.h @@ -108,28 +108,29 @@ __lll_timedlock (int *futex, const struct timespec *abstime, int private) #define LLL_LOCK_INITIALIZER (0) #define LLL_LOCK_INITIALIZER_LOCKED (1) -/* The kernel notifies a process which uses CLONE_CHILD_CLEARTID via futex - wakeup when the clone terminates. The memory location contains the - thread ID while the clone is running and is reset to zero - afterwards. */ -#define lll_wait_tid(tid) \ - do \ - { \ - __typeof (tid) __tid; \ - while ((__tid = (tid)) != 0) \ - lll_futex_wait (&(tid), __tid, LLL_SHARED); \ - } \ - while (0) - extern int __lll_timedwait_tid (int *, const struct timespec *) attribute_hidden; -#define lll_timedwait_tid(tid, abstime) \ - ({ \ - int __res = 0; \ - if ((tid) != 0) \ - __res = __lll_timedwait_tid (&(tid), (abstime)); \ - __res; \ +/* The kernel notifies a process which uses CLONE_CHILD_CLEARTID via futex + wake-up when the clone terminates. The memory location contains the + thread ID while the clone is running and is reset to zero by the kernel + afterwards. The kernel up to version 3.16.3 does not use the private futex + operations for futex wake-up when the clone terminates. + If ABSTIME is not NULL, is used a timeout for futex call. If the timeout + occurs then return ETIMEOUT, if ABSTIME is invalid, return EINVAL. + The futex operation are issues with cancellable versions. */ +#define lll_wait_tid(tid, abstime) \ + ({ \ + int __res = 0; \ + __typeof (tid) __tid; \ + if (abstime != NULL) \ + __res = __lll_timedwait_tid (&(tid), (abstime)); \ + else \ + /* We need acquire MO here so that we synchronize with the \ + kernel's store to 0 when the clone terminates. (see above) */ \ + while ((__tid = atomic_load_acquire (&(tid))) != 0) \ + lll_futex_wait_cancel (&(tid), __tid, LLL_SHARED); \ + __res; \ }) #endif /* lowlevellock.h */ diff --git a/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h b/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h index eedb6fc990..3c5860d4cf 100644 --- a/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h +++ b/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h @@ -224,32 +224,30 @@ extern int __lll_timedlock_elision (int *futex, short *adapt_count, #define lll_islocked(futex) \ (futex != LLL_LOCK_INITIALIZER) +extern int __lll_timedwait_tid (int *, const struct timespec *) + attribute_hidden; /* The kernel notifies a process which uses CLONE_CHILD_CLEARTID via futex wake-up when the clone terminates. The memory location contains the thread ID while the clone is running and is reset to zero by the kernel afterwards. The kernel up to version 3.16.3 does not use the private futex - operations for futex wake-up when the clone terminates. */ -#define lll_wait_tid(tid) \ - do { \ - __typeof (tid) __tid; \ - while ((__tid = (tid)) != 0) \ - lll_futex_wait (&(tid), __tid, LLL_SHARED);\ - } while (0) - -extern int __lll_timedwait_tid (int *, const struct timespec *) - attribute_hidden; - -/* As lll_wait_tid, but with a timeout. If the timeout occurs then return - ETIMEDOUT. If ABSTIME is invalid, return EINVAL. - XXX Note that this differs from the generic version in that we do the - error checking here and not in __lll_timedwait_tid. */ -#define lll_timedwait_tid(tid, abstime) \ - ({ \ - int __result = 0; \ - if ((tid) != 0) \ - __result = __lll_timedwait_tid (&(tid), (abstime)); \ - __result; }) + operations for futex wake-up when the clone terminates. + If ABSTIME is not NULL, is used a timeout for futex call. If the timeout + occurs then return ETIMEOUT, if ABSTIME is invalid, return EINVAL. + The futex operation are issues with cancellable versions. */ +#define lll_wait_tid(tid, abstime) \ + ({ \ + int __res = 0; \ + __typeof (tid) __tid; \ + if (abstime != NULL) \ + __res = __lll_timedwait_tid (&(tid), (abstime)); \ + else \ + /* We need acquire MO here so that we synchronize with the \ + kernel's store to 0 when the clone terminates. (see above) */ \ + while ((__tid = atomic_load_acquire (&(tid))) != 0) \ + lll_futex_wait_cancel (&(tid), __tid, LLL_SHARED); \ + __res; \ + }) extern int __lll_lock_elision (int *futex, short *adapt_count, int private) attribute_hidden; From patchwork Fri Dec 28 01:02:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1019055 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-98818-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="q1n/hM8d"; dkim=pass (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="YF4c2vBS"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43QpPV3jrSz9s2P for ; Fri, 28 Dec 2018 12:03:58 +1100 (AEDT) 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=MFCpwfvULuNIYdukQZF01G4h8nO4Hds ZV7odO/dosCbIZKefEfiFiAahFbxdQ8wgzLs3OjUMai7yGkXaJUO0coGnzE15WPc MDKHURGoeIU4bm3/jmZ66b7nGdalKhNU1JnR3LuE0Tw/XPTaO1NTi5QKHxXNxUYc 72ZHl6t9S+4Y= 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=qHYKOlCwXNCugux0KDX57qEpw4E=; b=q1n/h M8dhs8/B9KpCYsAf2TyC90polED7aKLyJD8mhA+BsT1yyShO3tmYjrasAx0QtTmF cIXRqmFWzdkPMub+6uR6feGRLMlAvQS3dGn0AG7oz21PZKrr2xK+VQCDOFOAaMHq I5UjBpYd/LLrrvkCz4c1NNmY1ZrEgY5Ku+oG9Y= Received: (qmail 35808 invoked by alias); 28 Dec 2018 01:03:11 -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 35738 invoked by uid 89); 28 Dec 2018 01:03:11 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=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.2 spammy= X-HELO: mail-qt1-f181.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=bxs/cCFaaa3Slef0teDbyMzbHGu/wTrwX15T5IT4OMk=; b=YF4c2vBS9ZHc9wB39R7znhG300wEi2Ue5wBa8Yf/4F8kggtp+Pky4atnp8RPvNjhwW sgLyLAxMJl99jncocI2Kse50AVddjOpEoWyqXq8iH8mvfcSAX41Su0+Z3bNDJ50/e28x Kq6VWEYkNJTTQUTjYO6B5hfvx+jSfxtw5J+Tg= From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH v2 6/6] support: Add support_create_temp_fifo Date: Thu, 27 Dec 2018 23:02:55 -0200 Message-Id: <20181228010255.21406-7-adhemerval.zanella@linaro.org> In-Reply-To: <20181228010255.21406-1-adhemerval.zanella@linaro.org> References: <20181228010255.21406-1-adhemerval.zanella@linaro.org> Checked on x86_64-linux-gnu. * support/temp_file.c (support_create_temp_fifo): New function. * support/temp_file.h (support_create_temp_fifo): New prototype. --- ChangeLog | 3 +++ support/temp_file.c | 23 +++++++++++++++++++++++ support/temp_file.h | 6 ++++++ 3 files changed, 32 insertions(+) diff --git a/support/temp_file.c b/support/temp_file.c index 0bbc7f9972..362ef171cc 100644 --- a/support/temp_file.c +++ b/support/temp_file.c @@ -86,6 +86,29 @@ create_temp_file (const char *base, char **filename) return fd; } +int +support_create_temp_fifo (const char *base, char **fifoname) +{ + char *fname = xasprintf ("%s/%sXXXXXX", test_dir, base); + mktemp (fname); + + int fd = mkfifo (fname, 0600); + if (fd == -1) + { + printf ("cannot open temporary fifo '%s': %m\n", fname); + free (fname); + return -1; + } + + add_temp_file (fname); + if (fifoname != NULL) + *fifoname = fname; + else + free (fname); + + return fd; +} + char * support_create_temp_directory (const char *base) { diff --git a/support/temp_file.h b/support/temp_file.h index c7795cc577..081b241b68 100644 --- a/support/temp_file.h +++ b/support/temp_file.h @@ -32,6 +32,12 @@ void add_temp_file (const char *name); *FILENAME. */ int create_temp_file (const char *base, char **filename); +/* Create a temporary fifo. Return the opened file descriptor on + success, or -1 on failure. Write the file name to *FILENAME if + FILENAME is not NULL. In this case, the caller is expected to free + *FILENAME. */ +int support_create_temp_fifo (const char *name, char **fifoname); + /* Create a temporary directory and schedule it for deletion. BASE is used as a prefix for the unique directory name, which the function returns. The caller should free this string. */