From patchwork Wed May 20 14:19:35 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 48805 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f71.google.com (mail-wg0-f71.google.com [74.125.82.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E5C162121F for ; Wed, 20 May 2015 14:19:57 +0000 (UTC) Received: by wgbgf7 with SMTP id gf7sf16166514wgb.2 for ; Wed, 20 May 2015 07:19:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:mailing-list:precedence:list-id :list-unsubscribe:list-subscribe:list-archive:list-post:list-help :sender:delivered-to:message-id:date:from:user-agent:mime-version:to :subject:content-type:content-transfer-encoding:x-original-sender :x-original-authentication-results; bh=1Bv11r2RrelmdlAAugVvEmNzwXI7rCd/Ao/QxxE02Cc=; b=WiTaJmqsYBrC20bY/y3JGwovTUbKalZ5MGhKQJlDXiCG7RlgOMiSVv3OyUWPFH6Gzf MO/AvgyZd9hDs/cBsh8ccWEDEU5RbwX6IeyvEml4WlpYCOjjpfxYuoGz4Iv+2zW+MsuJ 3OLEDj33oC62aP7vN5YEzxUn85BYOamJQ1CfhB5987YWrpUgTmcUuDdXjF0CPlWVCzlu UqaclNSHYq4xjf3PUpNSvTxLjeEIUnkRuMeEK4eFBxkXNfrx/R6TVXZ/YW1q016pCPmj NjQepOUHNs8MRzUu+spxim14wwVKZpvK+BfD902cUGCm01Xzw10LBvvPXBcNN+4DZnNg 1uzw== X-Gm-Message-State: ALoCoQnW92S567xNgYBGbfYo0UtgEgnWE0VapYWK/PAQaenmgOvMNtHgNyoYJuJYtgOlIVW26tu6 X-Received: by 10.112.160.197 with SMTP id xm5mr26573261lbb.15.1432131597167; Wed, 20 May 2015 07:19:57 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.204.168 with SMTP id kz8ls172214lac.105.gmail; Wed, 20 May 2015 07:19:57 -0700 (PDT) X-Received: by 10.112.17.8 with SMTP id k8mr26226879lbd.28.1432131597026; Wed, 20 May 2015 07:19:57 -0700 (PDT) Received: from mail-la0-x236.google.com (mail-la0-x236.google.com. [2a00:1450:4010:c03::236]) by mx.google.com with ESMTPS id aw7si11258099lbc.80.2015.05.20.07.19.56 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 May 2015 07:19:56 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c03::236 as permitted sender) client-ip=2a00:1450:4010:c03::236; Received: by laat2 with SMTP id t2so75986156laa.1 for ; Wed, 20 May 2015 07:19:56 -0700 (PDT) X-Received: by 10.112.204.72 with SMTP id kw8mr26112712lbc.88.1432131596871; Wed, 20 May 2015 07:19:56 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp1565448lbb; Wed, 20 May 2015 07:19:55 -0700 (PDT) X-Received: by 10.68.98.65 with SMTP id eg1mr63783620pbb.72.1432131594285; Wed, 20 May 2015 07:19:54 -0700 (PDT) Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id bi13si1919306pdb.40.2015.05.20.07.19.52 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 May 2015 07:19:54 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-return-59075-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Received: (qmail 81418 invoked by alias); 20 May 2015 14:19:42 -0000 Mailing-List: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org Precedence: list 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 81408 invoked by uid 89); 20 May 2015 14:19:42 -0000 X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS, UNSUBSCRIBE_BODY autolearn=no version=3.3.2 X-HELO: mail-qc0-f181.google.com X-Received: by 10.140.43.228 with SMTP id e91mr42674813qga.80.1432131578299; Wed, 20 May 2015 07:19:38 -0700 (PDT) Message-ID: <555C97F7.1060700@linaro.org> Date: Wed, 20 May 2015 11:19:35 -0300 From: Adhemerval Zanella User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: GNU C Library Subject: [PATCH] Use inline syscalls for non-cancellable versions X-Original-Sender: adhemerval.zanella@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c03::236 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=pass header.i=@sourceware.org X-Google-Group-Id: 836684582541 Hi This patch is one of the required adjustments for the fix for bz12683 (Race conditions in pthread cancellation) and the idea is to not rely on the non-cancelable entry points for cancelable syscalls (since the upcoming fill will remove them). This patch uses inline calls (through INLINE_SYSCALL macro) to define the non-cancellable functions macros to avoid use of the syscall_nocancel entrypoint. Tested on i386, x86_64, x32, powerpc32, powerpc64, arm, and aarch64. --- * sysdeps/unix/sysv/linux/not-cancel.h (open_not_cancel): Rewrite to be an inline implementation regardless of library is built within. (open_not_cancel_2): Likewise. (__read_nocancel): Likewise. (__write_nocancel): Likewise. (openat_not_cancel): Likewise. (openat_not_cancel_3): Likewise. (openat64_not_cancel): Likewise. (openat64_not_cancel_3): Likewise. (__close_nocancel): Likewise. (pause_not_cancel): Likewise. (nanosleep_not_cancel): Likewise. (sigsuspend_not_cancel): Likewise. -- diff --git a/sysdeps/unix/sysv/linux/not-cancel.h b/sysdeps/unix/sysv/linux/not-cancel.h index 62d487f..8a358fd 100644 --- a/sysdeps/unix/sysv/linux/not-cancel.h +++ b/sysdeps/unix/sysv/linux/not-cancel.h @@ -17,48 +17,48 @@ License along with the GNU C Library; if not, see . */ +#ifndef NOT_CANCEL_H +# define NOT_CANCEL_H + #include +#include +#include +#include -#if IS_IN (libc) || IS_IN (libpthread) || IS_IN (librt) -extern int __open_nocancel (const char *, int, ...) attribute_hidden; -extern int __close_nocancel (int) attribute_hidden; -extern int __read_nocancel (int, void *, size_t) attribute_hidden; -extern int __write_nocancel (int, const void *, size_t) attribute_hidden; -extern pid_t __waitpid_nocancel (pid_t, int *, int) attribute_hidden; -extern int __openat_nocancel (int fd, const char *fname, int oflag, - mode_t mode) attribute_hidden; -extern int __openat64_nocancel (int fd, const char *fname, int oflag, - mode_t mode) attribute_hidden; +/* Uncancelable open. */ +#ifdef __NR_open +# define open_not_cancel(name, flags, mode) \ + INLINE_SYSCALL (open, 3, name, flags, mode) +# define open_not_cancel_2(name, flags) \ + INLINE_SYSCALL (open, 2, name, flags) #else -# define __open_nocancel(name, ...) __open (name, __VA_ARGS__) -# define __close_nocancel(fd) __close (fd) -# define __read_nocancel(fd, buf, len) __read (fd, buf, len) -# define __write_nocancel(fd, buf, len) __write (fd, buf, len) -# define __waitpid_nocancel(pid, stat_loc, options) \ - __waitpid (pid, stat_loc, options) -# define __openat_nocancel(fd, fname, oflag, mode) \ - openat (fd, fname, oflag, mode) -# define __openat64_nocancel(fd, fname, oflag, mode) \ - openat64 (fd, fname, oflag, mode) +# define open_not_cancel(name, flags, mode) \ + INLINE_SYSCALL (openat, 4, AT_FDCWD, name, flags, mode) +# define open_not_cancel_2(name, flags) \ + INLINE_SYSCALL (openat, 3, AT_FDCWD, name, flags) #endif -/* Uncancelable open. */ -#define open_not_cancel(name, flags, mode) \ - __open_nocancel (name, flags, mode) -#define open_not_cancel_2(name, flags) \ - __open_nocancel (name, flags) +/* Uncancelable read. */ +#define __read_nocancel(fd, buf, len) \ + INLINE_SYSCALL (read, 3, fd, buf, len) + +/* Uncancelable write. */ +#define __write_nocancel(fd, buf, len) \ + INLINE_SYSCALL (write, 3, fd, buf, len) /* Uncancelable openat. */ #define openat_not_cancel(fd, fname, oflag, mode) \ - __openat_nocancel (fd, fname, oflag, mode) + INLINE_SYSCALL (openat, 4, fd, fname, oflag, mode) #define openat_not_cancel_3(fd, fname, oflag) \ - __openat_nocancel (fd, fname, oflag, 0) + INLINE_SYSCALL (openat, 3, fd, fname, oflag) #define openat64_not_cancel(fd, fname, oflag, mode) \ - __openat64_nocancel (fd, fname, oflag, mode) + INLINE_SYSCALL (openat, 4, fd, fname, oflag | O_LARGEFILE, mode) #define openat64_not_cancel_3(fd, fname, oflag) \ - __openat64_nocancel (fd, fname, oflag, 0) + INLINE_SYSCALL (openat, 3, fd, fname, oflag | O_LARGEFILE) /* Uncancelable close. */ +#define __close_nocancel(fd) \ + INLINE_SYSCALL (close, 1, fd) #define close_not_cancel(fd) \ __close_nocancel (fd) #define close_not_cancel_no_status(fd) \ @@ -83,17 +83,27 @@ extern int __openat64_nocancel (int fd, const char *fname, int oflag, __fcntl_nocancel (fd, cmd, val) /* Uncancelable waitpid. */ -#define waitpid_not_cancel(pid, stat_loc, options) \ +#define __waitpid_nocancel(pid, stat_loc, options) \ INLINE_SYSCALL (wait4, 4, pid, stat_loc, options, NULL) +#define waitpid_not_cancel(pid, stat_loc, options) \ + __waitpid_nocancel(pid, stat_loc, options) /* Uncancelable pause. */ #define pause_not_cancel() \ - __pause_nocancel () + ({ sigset_t set; \ + int __rc = INLINE_SYSCALL (rt_sigprocmask, 4, SIG_BLOCK, NULL, &set, \ + _NSIG / 8); \ + if (__rc == 0) \ + __rc = INLINE_SYSCALL (rt_sigsuspend, 2, &set, _NSIG / 8); \ + __rc; \ + }) /* Uncancelable nanosleep. */ #define nanosleep_not_cancel(requested_time, remaining) \ - __nanosleep_nocancel (requested_time, remaining) + INLINE_SYSCALL (nanosleep, 2, requested_time, remaining) /* Uncancelable sigsuspend. */ #define sigsuspend_not_cancel(set) \ - __sigsuspend_nocancel (set) + INLINE_SYSCALL (rt_sigsuspend, 2, set, _NSIG / 8) + +#endif /* NOT_CANCEL_H */ diff --git a/sysdeps/unix/sysv/linux/powerpc/get_clockfreq.c b/sysdeps/unix/sysv/linux/powerpc/get_clockfreq.c index 5b6bb51..3578ea8 100644 --- a/sysdeps/unix/sysv/linux/powerpc/get_clockfreq.c +++ b/sysdeps/unix/sysv/linux/powerpc/get_clockfreq.c @@ -41,7 +41,7 @@ __get_clockfreq (void) contains at least one line like: timebase : 33333333 We search for this line and convert the number into an integer. */ - int fd = __open_nocancel ("/proc/cpuinfo", O_RDONLY); + int fd = open_not_cancel_2 ("/proc/cpuinfo", O_RDONLY); if (__glibc_likely (fd != -1)) return result;