From patchwork Thu Aug 3 13:11:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 109327 Delivered-To: patch@linaro.org Received: by 10.140.101.6 with SMTP id t6csp762733qge; Thu, 3 Aug 2017 06:12:21 -0700 (PDT) X-Received: by 10.84.215.202 with SMTP id g10mr1888898plj.290.1501765941006; Thu, 03 Aug 2017 06:12:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501765941; cv=none; d=google.com; s=arc-20160816; b=wgN/Iedu5w3ay7WJ4jdI+SOY17XU+4Lu46kEIcjkqT+cUHQmx2XOxBdkrbxspLlzMQ a/70WROlKRfAVmJve9vRCUam9noI6QDfXYUa5WZVYEL1H4bByqQY+N2TzDcrHBjDWV/y KR4IJDSHHgkC7y3eOI6WzJLlQoOzKD7YjtMspg2bM1kEW6wcflrnUJHoUsUQGpl8mLhh meFt0teN/x7+LoolWyQJbsQbkecyKBRk/k/j3ZS3m9dQUcKu1YO04srhCYNigCzXSiFh aKbNreNq7/cgN/vCNaJBA84V1r6dWao/PvAUA2H+L3f/Y2sB1JtGclpuBd/IvVQ/6qSH vBXQ== 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:delivered-to :sender:list-help:list-post:list-archive:list-subscribe :list-unsubscribe:list-id:precedence:mailing-list:dkim-signature :domainkey-signature:arc-authentication-results; bh=kk77xOJh2ichiOdjwl96+8ha8tg3geYg9itYQqEKdgE=; b=U2E4oY9gO60NdeGn8wqnGWYHUw2HG8ViNoOpFikFE1vU7VnNlQ1aHPSif+Tr8jem6y Xh8mLJTQv+knMN8h2dhHwRdz7SGmm6cdahqaofX5MiYZUVp5tql3dnpuban23WuaaDnH 9MggB5KATChYW9foFTN6CvCAxeq1iJlQzzRF8i38nk/gfY3FzdRSxZsYO2zvbKdxT4n+ wRBrK7s1v9Aej8ZAWSx3tOicEfVyrWBqYi5VyaTzhv3LUumtENQaAKDCSs4JOWNO/oHF 0ChwBs5m8xX7Y957S+jlyIlFD2EDj3U22zpf8L1ZtQ8AW42j9hU0EfVgS1loUyC0mdHL Dc+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.b=JT8QUi4o; spf=pass (google.com: domain of libc-alpha-return-82681-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-82681-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id m188si21193355pfb.478.2017.08.03.06.12.20 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 03 Aug 2017 06:12:20 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-return-82681-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.b=JT8QUi4o; spf=pass (google.com: domain of libc-alpha-return-82681-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-82681-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=ypzqLFxW4jYJcncrWx6jZzs0sjpDc5M Xe5lf2lzX5euyj3OKZBBfetND2nfGieQWcHKDXZeIl4k2g+9LQ2BE5Gve81xDGHy uJADmSeL6OQ+pI3OmpReXYtxCVe1R4rqYC43OspkhQtH8QVMbgoEvaVXRlgHUUhl +86pxErp++UE= 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=v5DZUjTsCg+q93Fh0gpj7jROPsM=; b=JT8QU i4oDKmRIAlVGJI0TpetbBmpleN5d6JyxnTwduLm/tP2QMwKwJG9gFqxpJj8qIaKS SApifiE1NDDF8HBWJdDtI1BRyw/Is5u+eTvgssAyeIHAd+yv/HenB9pidyxXexYo Og1qmQnFL1xq+YJozJNdSqZ/NU9wylwqLggK6A= Received: (qmail 60917 invoked by alias); 3 Aug 2017 13:11:48 -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 60641 invoked by uid 89); 3 Aug 2017 13:11:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=1995 X-HELO: mail-qk0-f177.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=kk77xOJh2ichiOdjwl96+8ha8tg3geYg9itYQqEKdgE=; b=hVUNsIK6SGCMWxRnknkWbu/JVveDBdd5b1G7NYkTLQ4r3DvseyLIz/yoXxXsji12Xj Ylzy+t3FCmHTeAzj1yP3gL5GOh2yVlPdVH0vTx9HOfxGvWHd+4spoVnxtizstm4k4oAW B8RsH2uvyh2OfevnNs4dxWxL3+uo/ZShUiYeUZ+jO9BegAIa+o1sAPMrrjIQ0m5cNo1R F4QJ2XPJaSVcsql1i4boRxBjbB7HY84iNN2FRebLgSG5dfSkorBdxZYEj4vOXtIXU23W RVtalei6TqKk2/u/t1Z1LLguV9O9+RiAWO0SfGu3BfvPxhjF67wwJhm+jECagf/h8srz k9wA== X-Gm-Message-State: AHYfb5ijALVV56Iv51BDCx3Zt8wULjfHe41rUrqOcRmyNgOmZsJy7VCn 90MpdmfHYsq3XR7/v7XoSg== X-Received: by 10.55.108.131 with SMTP id h125mr2150119qkc.285.1501765900597; Thu, 03 Aug 2017 06:11:40 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH 03/14] Consolidate non cancellable write call Date: Thu, 3 Aug 2017 10:11:03 -0300 Message-Id: <1501765874-6201-4-git-send-email-adhemerval.zanella@linaro.org> In-Reply-To: <1501765874-6201-1-git-send-email-adhemerval.zanella@linaro.org> References: <1501765874-6201-1-git-send-email-adhemerval.zanella@linaro.org> This patch consolidates all the non cancellable write calls to use the __write_nocancel identifier. For non cancellable targets it will be just a macro to call the default respective symbol while on Linux will be a internal one. Checked on x86_64-linux-gnu, x86_64-linux-gnu-x32, and i686-linux-gnu. * sysdeps/generic/not-cancel.h (write_not_cancel): Remove macro. (__write_nocancel): New macro. * sysdeps/unix/sysv/linux/not-cancel.h (__write_nocancel): Rewrite as a function prototype. (write_not_cancel): Remove macro. * sysdeps/unix/sysv/linux/write.c (__write_nocancel): New function. * gmon/gmon.c (ERR): Replace write_not_cancel with __write_nocancel. (write_gmon): Likewise. * libio/fileops.c (_IO_new_file_write): Likewise. * login/utmp_file.c (pututline_file): Likewise. (updwtmp_file): Likewise. * stdio-common/psiginfo.c (psiginfo): Likewise. * sysdeps/posix/spawni.c (__spawni_child): Likewise. * sysdeps/unix/sysv/linux/gethostid.c (sethostid): Likewise. * sysdeps/unix/sysv/linux/libc_fatal.c (backtrace_and_maps): Likewise. * sysdeps/unix/sysv/linux/pthread_setname.c (pthread_setname_np): Likewise. --- ChangeLog | 19 +++++++++++++++++++ gmon/gmon.c | 4 ++-- libio/fileops.c | 2 +- login/utmp_file.c | 4 ++-- stdio-common/psiginfo.c | 2 +- sysdeps/generic/not-cancel.h | 2 +- sysdeps/posix/spawni.c | 3 +-- sysdeps/unix/sysv/linux/gethostid.c | 2 +- sysdeps/unix/sysv/linux/libc_fatal.c | 4 ++-- sysdeps/unix/sysv/linux/not-cancel.h | 8 ++------ sysdeps/unix/sysv/linux/pthread_setname.c | 2 +- sysdeps/unix/sysv/linux/write.c | 12 ++++++++++++ 12 files changed, 45 insertions(+), 19 deletions(-) -- 2.7.4 diff --git a/ChangeLog b/ChangeLog index 5199a69..0bc21b6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,24 @@ 2017-08-02 Adhemerval Zanella + * sysdeps/generic/not-cancel.h (write_not_cancel): Remove macro. + (__write_nocancel): New macro. + * sysdeps/unix/sysv/linux/not-cancel.h (__write_nocancel): + Rewrite as a function prototype. + (write_not_cancel): Remove macro. + * sysdeps/unix/sysv/linux/write.c (__write_nocancel): New function. + * gmon/gmon.c (ERR): Replace write_not_cancel with __write_nocancel. + (write_gmon): Likewise. + * libio/fileops.c (_IO_new_file_write): Likewise. + * login/utmp_file.c (pututline_file): Likewise. + (updwtmp_file): Likewise. + * stdio-common/psiginfo.c (psiginfo): Likewise. + * sysdeps/posix/spawni.c (__spawni_child): Likewise. + * sysdeps/unix/sysv/linux/gethostid.c (sethostid): Likewise. + * sysdeps/unix/sysv/linux/libc_fatal.c (backtrace_and_maps): + Likewise. + * sysdeps/unix/sysv/linux/pthread_setname.c (pthread_setname_np): + Likewise. + * sysdeps/generic/not-cancel.h (read_not_cancel): Remove macro. (__read_nocancel): New macro. * sysdeps/unix/sysv/linux/Versions (libc) [GLIBC_PRIVATE]: Add diff --git a/gmon/gmon.c b/gmon/gmon.c index 87c3c4e..e7701b9 100644 --- a/gmon/gmon.c +++ b/gmon/gmon.c @@ -58,7 +58,7 @@ struct gmonparam _gmonparam attribute_hidden = { GMON_PROF_OFF }; static int s_scale; #define SCALE_1_TO_1 0x10000L -#define ERR(s) write_not_cancel (STDERR_FILENO, s, sizeof (s) - 1) +#define ERR(s) __write_nocancel (STDERR_FILENO, s, sizeof (s) - 1) void moncontrol (int mode); void __moncontrol (int mode); @@ -375,7 +375,7 @@ write_gmon (void) memcpy (&ghdr.cookie[0], GMON_MAGIC, sizeof (ghdr.cookie)); ghdr.version = GMON_VERSION; memset (ghdr.spare, '\0', sizeof (ghdr.spare)); - write_not_cancel (fd, &ghdr, sizeof (struct gmon_hdr)); + __write_nocancel (fd, &ghdr, sizeof (struct gmon_hdr)); /* write PC histogram: */ write_hist (fd); diff --git a/libio/fileops.c b/libio/fileops.c index 80bd3f5..f025178 100644 --- a/libio/fileops.c +++ b/libio/fileops.c @@ -1251,7 +1251,7 @@ _IO_new_file_write (_IO_FILE *f, const void *data, _IO_ssize_t n) { _IO_ssize_t count = (__builtin_expect (f->_flags2 & _IO_FLAGS2_NOTCANCEL, 0) - ? write_not_cancel (f->_fileno, data, to_do) + ? __write_nocancel (f->_fileno, data, to_do) : write (f->_fileno, data, to_do)); if (count < 0) { diff --git a/login/utmp_file.c b/login/utmp_file.c index 61d03d6..26e3f4b 100644 --- a/login/utmp_file.c +++ b/login/utmp_file.c @@ -444,7 +444,7 @@ pututline_file (const struct utmp *data) } /* Write the new data. */ - if (write_not_cancel (file_fd, data, sizeof (struct utmp)) + if (__write_nocancel (file_fd, data, sizeof (struct utmp)) != sizeof (struct utmp)) { /* If we appended a new record this is only partially written. @@ -505,7 +505,7 @@ updwtmp_file (const char *file, const struct utmp *utmp) /* Write the entry. If we can't write all the bytes, reset the file size back to the original size. That way, no partial entries will remain. */ - if (write_not_cancel (fd, utmp, sizeof (struct utmp)) + if (__write_nocancel (fd, utmp, sizeof (struct utmp)) != sizeof (struct utmp)) { __ftruncate64 (fd, offset); diff --git a/stdio-common/psiginfo.c b/stdio-common/psiginfo.c index 6954a42..7bf2e2d 100644 --- a/stdio-common/psiginfo.c +++ b/stdio-common/psiginfo.c @@ -199,5 +199,5 @@ Signal generated by the completion of an I/O request"); fclose (fp); - write_not_cancel (STDERR_FILENO, buf, strlen (buf)); + __write_nocancel (STDERR_FILENO, buf, strlen (buf)); } diff --git a/sysdeps/generic/not-cancel.h b/sysdeps/generic/not-cancel.h index 4fada2f..e91cb6c 100644 --- a/sysdeps/generic/not-cancel.h +++ b/sysdeps/generic/not-cancel.h @@ -36,7 +36,7 @@ (void) __close (fd) #define __read_nocancel(fd, buf, n) \ __read (fd, buf, n) -#define write_not_cancel(fd, buf, n) \ +#define __write_nocancel(fd, buf, n) \ __write (fd, buf, n) #define writev_not_cancel_no_status(fd, iov, n) \ (void) __writev (fd, iov, n) diff --git a/sysdeps/posix/spawni.c b/sysdeps/posix/spawni.c index 823db11..a43b841 100644 --- a/sysdeps/posix/spawni.c +++ b/sysdeps/posix/spawni.c @@ -233,8 +233,7 @@ fail: abort(), but that seems needlessly harsh. */ ret = errno ? : ECHILD; if (ret) - /* Since sizeof errno < PIPE_BUF, the write is atomic. */ - while (write_not_cancel (args->pipe[1], &ret, sizeof (ret)) < 0); + while (__write_nocancel (args->pipe[1], &ret, sizeof (ret)) < 0); _exit (SPAWN_ERROR); } diff --git a/sysdeps/unix/sysv/linux/gethostid.c b/sysdeps/unix/sysv/linux/gethostid.c index 6e19dee..11c7e73 100644 --- a/sysdeps/unix/sysv/linux/gethostid.c +++ b/sysdeps/unix/sysv/linux/gethostid.c @@ -51,7 +51,7 @@ sethostid (long int id) if (fd < 0) return -1; - written = write_not_cancel (fd, &id32, sizeof (id32)); + written = __write_nocancel (fd, &id32, sizeof (id32)); close_not_cancel_no_status (fd); diff --git a/sysdeps/unix/sysv/linux/libc_fatal.c b/sysdeps/unix/sysv/linux/libc_fatal.c index ca838a7..c7c6a07 100644 --- a/sysdeps/unix/sysv/linux/libc_fatal.c +++ b/sysdeps/unix/sysv/linux/libc_fatal.c @@ -48,7 +48,7 @@ backtrace_and_maps (int do_abort, bool written, int fd) if (n > 2) { #define strnsize(str) str, strlen (str) -#define writestr(str) write_not_cancel (fd, str) +#define writestr(str) __write_nocancel (fd, str) writestr (strnsize ("======= Backtrace: =========\n")); __backtrace_symbols_fd (addrs + 1, n - 1, fd); @@ -57,7 +57,7 @@ backtrace_and_maps (int do_abort, bool written, int fd) char buf[1024]; ssize_t n2; while ((n2 = __read_nocancel (fd2, buf, sizeof (buf))) > 0) - if (write_not_cancel (fd, buf, n2) != n2) + if (__write_nocancel (fd, buf, n2) != n2) break; close_not_cancel_no_status (fd2); } diff --git a/sysdeps/unix/sysv/linux/not-cancel.h b/sysdeps/unix/sysv/linux/not-cancel.h index 3d26075..84dc72a 100644 --- a/sysdeps/unix/sysv/linux/not-cancel.h +++ b/sysdeps/unix/sysv/linux/not-cancel.h @@ -39,8 +39,8 @@ __typeof (__read) __read_nocancel; libc_hidden_proto (__read_nocancel) /* Uncancelable write. */ -#define __write_nocancel(fd, buf, len) \ - INLINE_SYSCALL (write, 3, fd, buf, len) +__typeof (__write) __write_nocancel; +libc_hidden_proto (__write_nocancel) /* Uncancelable openat. */ #define openat_not_cancel(fd, fname, oflag, mode) \ @@ -61,10 +61,6 @@ libc_hidden_proto (__read_nocancel) (void) ({ INTERNAL_SYSCALL_DECL (err); \ INTERNAL_SYSCALL (close, err, 1, (fd)); }) -/* Uncancelable write. */ -#define write_not_cancel(fd, buf, n) \ - __write_nocancel (fd, buf, n) - /* Uncancelable writev. */ #define writev_not_cancel_no_status(fd, iov, n) \ (void) ({ INTERNAL_SYSCALL_DECL (err); \ diff --git a/sysdeps/unix/sysv/linux/pthread_setname.c b/sysdeps/unix/sysv/linux/pthread_setname.c index 93f0e9d..c5e9a33 100644 --- a/sysdeps/unix/sysv/linux/pthread_setname.c +++ b/sysdeps/unix/sysv/linux/pthread_setname.c @@ -51,7 +51,7 @@ pthread_setname_np (pthread_t th, const char *name) return errno; int res = 0; - ssize_t n = TEMP_FAILURE_RETRY (write_not_cancel (fd, name, name_len)); + ssize_t n = TEMP_FAILURE_RETRY (__write_nocancel (fd, name, name_len)); if (n < 0) res = errno; else if (n != name_len) diff --git a/sysdeps/unix/sysv/linux/write.c b/sysdeps/unix/sysv/linux/write.c index d495145..f8896eb 100644 --- a/sysdeps/unix/sysv/linux/write.c +++ b/sysdeps/unix/sysv/linux/write.c @@ -18,6 +18,7 @@ #include #include +#include /* Write NBYTES of BUF to FD. Return the number written, or -1. */ ssize_t @@ -31,3 +32,14 @@ weak_alias (__libc_write, __write) libc_hidden_weak (__write) weak_alias (__libc_write, write) libc_hidden_weak (write) + +#if !IS_IN (rtld) +ssize_t +__write_nocancel (int fd, const void *buf, size_t nbytes) +{ + return INLINE_SYSCALL_CALL (write, fd, buf, nbytes); +} +#else +strong_alias (__libc_write, __write_nocancel) +#endif +libc_hidden_def (__write_nocancel)