From patchwork Wed Jun 15 21:20:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 70130 Delivered-To: patch@linaro.org Received: by 10.140.106.246 with SMTP id e109csp61037qgf; Wed, 15 Jun 2016 14:20:42 -0700 (PDT) X-Received: by 10.98.15.68 with SMTP id x65mr907042pfi.66.1466025642439; Wed, 15 Jun 2016 14:20:42 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id ie10si16649240pad.48.2016.06.15.14.20.42 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Jun 2016 14:20:42 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-return-70686-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; spf=pass (google.com: domain of libc-alpha-return-70686-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-70686-patch=linaro.org@sourceware.org; dmarc=fail (p=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=ZgIcya2B5xx4OvynBl0yQEm0NVGdZHa4wFzi9zmVsATkipvUOxe00 E5BCBA/kcDWA9etU/zJ+472I4Kw7y9TP4Rs5qLLkegIIZufCnoX4x48M2x0Imng/ 5+sIpK2XGLrH+vJt0hEgY/pUDO0ICHahb1l+aTRhAXdWq0reOqTmto= 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=w8lh3V3Ba3JCXHWJ/P323hOVJnc=; b=lyA9N6eP259go3MuMxGaHxWmL4RU YxtrCe7IQOf3RZEMTkUpjafYlipIXe42DnzC4dipfkUWuxUPVl23ML403sufkvZR lG7xCSbSl7nX24CP7xbFmbS8e7SCvBn2g/u7JqDoscvH32M5mcyYqqKHfTGrVt6C P4fxNWsJbFVe2UM= Received: (qmail 127114 invoked by alias); 15 Jun 2016 21:20:32 -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 127088 invoked by uid 89); 15 Jun 2016 21:20:30 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-qk0-f173.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id; bh=y6aDPUgfXtXUtp/kB5CTTs68HIhrFXXgu/t511clDWc=; b=EPr+PLqOLdX/D9NfXW7oXNKzsYkEeRdkVxCExEO1ifygP/nVeap760bXgw6YkI6NHz umxGDFEal4vHxxz+BJLP2ewcr2edLzthJRhkhfv+llf8thc0Cj3DHSXXfayQcFDqSgbz d1ZZvrk4quNpkAs6CDtrUXya5avFv+KIEpXSMcbB2lVypUAnnNNGg73gk9KrkgaZfO9D kpqhw4y67rIluLWPMhFclqpUfcryF9cz0ZhqcJH+vWm/2GLU57faB6R20dvo++RV9jPO qDGyDl3aY+yAJVkqlop18buT87gjHGNwIf/+rrZ9ls7d4dV0wnVmBnKTPMAsv2ILiy+B I7HA== X-Gm-Message-State: ALyK8tI3W718IGjLNtgeJ1pkdqq6tzP0SdO4IQyEIOCuADccZi9w+1d2syLJjPlu4+5spVWE X-Received: by 10.55.80.131 with SMTP id e125mr878937qkb.155.1466025617994; Wed, 15 Jun 2016 14:20:17 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH v2] Fix p{readv,writev}{64} consolidation implementation Date: Wed, 15 Jun 2016 18:20:04 -0300 Message-Id: <1466025604-17044-1-git-send-email-adhemerval.zanella@linaro.org> Changes from previous version: - Remove SYSCALL_LL{64} usage and replace by another macro based on previous default implementation (LO_HI_LONG) - Fix some issue with testcase -- This patch fixes the p{readv,writev}{64} consolidation implementation from commits 4e77815 and af5fdf5. Different from pread/pwrite implementation, preadv/pwritev implementation does not require __ALIGNMENT_ARG because kernel syscall prototypes define the high and low part of the off_t, if it is the case, directly (different from pread/pwrite where the architecture ABI for passing 64-bit values must be in consideration for passsing the arguments). It also adds some basic tests for preadv/pwritev. Tested on x86_64, i686, and armhf. * misc/Makefile (tests): Add tst-preadvwritev and tst-preadvwritev64. * misc/tst-preadvwritev.c: New file. * misc/tst-preadvwritev64.c: Likewise. * sysdeps/unix/sysv/linux/preadv.c (preadv): Remove SYSCALL_LL{64} usage. * sysdeps/unix/sysv/linux/preadv64.c (preadv64): Likewise. * sysdeps/unix/sysv/linux/pwritev.c (pwritev): Likewise. * sysdeps/unix/sysv/linux/pwritev64.c (pwritev64): Likewise. * sysdeps/unix/sysv/linux/sysdep.h (LO_HI_LONG): New macro. --- ChangeLog | 12 ++++ misc/Makefile | 3 +- misc/tst-preadvwritev.c | 114 ++++++++++++++++++++++++++++++++++++ misc/tst-preadvwritev64.c | 22 +++++++ sysdeps/unix/sysv/linux/preadv.c | 5 +- sysdeps/unix/sysv/linux/preadv64.c | 5 +- sysdeps/unix/sysv/linux/pwritev.c | 5 +- sysdeps/unix/sysv/linux/pwritev64.c | 7 +-- sysdeps/unix/sysv/linux/sysdep.h | 9 +++ 9 files changed, 168 insertions(+), 14 deletions(-) create mode 100644 misc/tst-preadvwritev.c create mode 100644 misc/tst-preadvwritev64.c -- 2.7.4 diff --git a/ChangeLog b/ChangeLog index a4a1cea..e555444 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2016-06-14 Adhemerval Zanella + + * misc/Makefile (tests): Add tst-preadvwritev and tst-preadvwritev64. + * misc/tst-preadvwritev.c: New file. + * misc/tst-preadvwritev64.c: Likewise. + * sysdeps/unix/sysv/linux/preadv.c (preadv): Remove SYSCALL_LL{64} + usage. + * sysdeps/unix/sysv/linux/preadv64.c (preadv64): Likewise. + * sysdeps/unix/sysv/linux/pwritev.c (pwritev): Likewise. + * sysdeps/unix/sysv/linux/pwritev64.c (pwritev64): Likewise. + * sysdeps/unix/sysv/linux/sysdep.h (LO_HI_LONG): New macro. + 2016-06-14 Joseph Myers [BZ #20255] diff --git a/misc/Makefile b/misc/Makefile index 6498adc..56e20ce 100644 --- a/misc/Makefile +++ b/misc/Makefile @@ -77,7 +77,8 @@ gpl2lgpl := error.c error.h tests := tst-dirname tst-tsearch tst-fdset tst-efgcvt tst-mntent tst-hsearch \ tst-error1 tst-pselect tst-insremque tst-mntent2 bug-hsearch1 \ - tst-mntent-blank-corrupt tst-mntent-blank-passno bug18240 + tst-mntent-blank-corrupt tst-mntent-blank-passno bug18240 \ + tst-preadvwritev tst-preadvwritev64 ifeq ($(run-built-tests),yes) tests-special += $(objpfx)tst-error1-mem.out endif diff --git a/misc/tst-preadvwritev.c b/misc/tst-preadvwritev.c new file mode 100644 index 0000000..6836574 --- /dev/null +++ b/misc/tst-preadvwritev.c @@ -0,0 +1,114 @@ +/* Tests for preadv and pwritev. + Copyright (C) 2016 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 + +/* Allow testing of the 64-bit versions as well. */ +#ifndef PREADV +# define PREADV preadv +# define PWRITEV pwritev +#endif + +static void do_prepare (void); +static int do_test (void); +#define PREPARE(argc, argv) do_prepare () +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" + +static char *temp_filename; +static int temp_fd; + +void +do_prepare (void) +{ + temp_fd = create_temp_file ("tst-PREADVwritev.", &temp_filename); + if (temp_fd == -1) + { + printf ("cannot create temporary file: %m\n"); + exit (1); + } +} + +#define FAIL(str) \ + do { printf ("error: %s (line %d)\n", str, __LINE__); return 1; } while (0) + +int +do_test (void) +{ + struct iovec iov[2]; + ssize_t ret; + + char buf1[32]; + char buf2[64]; + + memset (buf1, 0xf0, sizeof buf1); + memset (buf2, 0x0f, sizeof buf2); + + memset (iov, 0, sizeof iov); + iov[0].iov_base = buf1; + iov[0].iov_len = sizeof buf1; + iov[1].iov_base = buf2; + iov[1].iov_len = sizeof buf2; + + ret = PWRITEV (temp_fd, iov, 2, 0); + if (ret == -1) + FAIL ("first PWRITEV returned -1"); + if (ret != (sizeof buf1 + sizeof buf2)) + FAIL ("first PWRITEV returned an unexpected value"); + + ret = PWRITEV (temp_fd, iov, 2, sizeof buf1 + sizeof buf2); + if (ret == -1) + FAIL ("second PWRITEV returned -1"); + if (ret != (sizeof buf1 + sizeof buf2)) + FAIL ("second PWRITEV returned an unexpected value"); + + char buf3[32]; + char buf4[64]; + + memset (buf3, 0x0f, sizeof buf3); + memset (buf4, 0xf0, sizeof buf4); + + iov[0].iov_base = buf3; + iov[0].iov_len = sizeof buf3; + iov[1].iov_base = buf4; + iov[1].iov_len = sizeof buf4; + + ret = PREADV (temp_fd, iov, 2, 0); + if (ret == -1) + FAIL ("first PREADV returned -1"); + if (ret != (sizeof buf3 + sizeof buf4)) + FAIL ("first PREADV returned an unexpected value"); + + if (memcmp (buf1, buf3, sizeof buf1) != 0) + FAIL ("first buffer from first PREADV different than expected"); + if (memcmp (buf2, buf4, sizeof buf2) != 0) + FAIL ("second buffer from first PREADV different than expected"); + + ret = PREADV (temp_fd, iov, 2, sizeof buf3 + sizeof buf4); + if (ret == -1) + FAIL ("second PREADV returned -1"); + if (ret != (sizeof buf3 + sizeof buf4)) + FAIL ("second PREADV returned an unexpected value"); + + if (memcmp (buf1, buf3, sizeof buf1) != 0) + FAIL ("first buffer from second PREADV different than expected"); + if (memcmp (buf2, buf4, sizeof buf2) != 0) + FAIL ("second buffer from second PREADV different than expected"); + + return 0; +} diff --git a/misc/tst-preadvwritev64.c b/misc/tst-preadvwritev64.c new file mode 100644 index 0000000..ff6e134 --- /dev/null +++ b/misc/tst-preadvwritev64.c @@ -0,0 +1,22 @@ +/* Tests for pread64 and pwrite64. + Copyright (C) 2016 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 + . */ + +#define PREADV preadv64 +#define PWRITEV pwritev64 + +#include "tst-preadvwritev.c" diff --git a/sysdeps/unix/sysv/linux/preadv.c b/sysdeps/unix/sysv/linux/preadv.c index f6958c3..be206e2 100644 --- a/sysdeps/unix/sysv/linux/preadv.c +++ b/sysdeps/unix/sysv/linux/preadv.c @@ -29,8 +29,7 @@ ssize_t preadv (int fd, const struct iovec *vector, int count, off_t offset) { - return SYSCALL_CANCEL (preadv, fd, vector, count, - __ALIGNMENT_ARG SYSCALL_LL (offset)); + return SYSCALL_CANCEL (preadv, fd, vector, count, LO_HI_LONG (offset)); } # else static ssize_t __atomic_preadv_replacement (int, const struct iovec *, @@ -40,7 +39,7 @@ preadv (int fd, const struct iovec *vector, int count, off_t offset) { # ifdef __NR_preadv ssize_t result = SYSCALL_CANCEL (preadv, fd, vector, count, - __ALIGNMENT_ARG SYSCALL_LL (offset)); + LO_HI_LONG (offset)); if (result >= 0 || errno != ENOSYS) return result; # endif diff --git a/sysdeps/unix/sysv/linux/preadv64.c b/sysdeps/unix/sysv/linux/preadv64.c index 18f5550..64164bb 100644 --- a/sysdeps/unix/sysv/linux/preadv64.c +++ b/sysdeps/unix/sysv/linux/preadv64.c @@ -27,8 +27,7 @@ ssize_t preadv64 (int fd, const struct iovec *vector, int count, off64_t offset) { - return SYSCALL_CANCEL (preadv64, fd, vector, count, - __ALIGNMENT_ARG SYSCALL_LL64 (offset)); + return SYSCALL_CANCEL (preadv64, fd, vector, count, LO_HI_LONG (offset)); } #else static ssize_t __atomic_preadv64_replacement (int, const struct iovec *, @@ -38,7 +37,7 @@ preadv64 (int fd, const struct iovec *vector, int count, off64_t offset) { #ifdef __NR_preadv64 ssize_t result = SYSCALL_CANCEL (preadv64, fd, vector, count, - __ALIGNMENT_ARG SYSCALL_LL64 (offset)); + LO_HI_LONG (offset)); if (result >= 0 || errno != ENOSYS) return result; #endif diff --git a/sysdeps/unix/sysv/linux/pwritev.c b/sysdeps/unix/sysv/linux/pwritev.c index b11606c..19b4a10 100644 --- a/sysdeps/unix/sysv/linux/pwritev.c +++ b/sysdeps/unix/sysv/linux/pwritev.c @@ -29,8 +29,7 @@ ssize_t pwritev (int fd, const struct iovec *vector, int count, off_t offset) { - return SYSCALL_CANCEL (pwritev, fd, vector, count, - __ALIGNMENT_ARG SYSCALL_LL (offset)); + return SYSCALL_CANCEL (pwritev, fd, vector, count, LO_HI_LONG (offset)); } # else static ssize_t __atomic_pwritev_replacement (int, const struct iovec *, @@ -40,7 +39,7 @@ pwritev (int fd, const struct iovec *vector, int count, off_t offset) { # ifdef __NR_pwritev ssize_t result = SYSCALL_CANCEL (pwritev, fd, vector, count, - __ALIGNMENT_ARG SYSCALL_LL (offset)); + LO_HI_LONG (offset)); if (result >= 0 || errno != ENOSYS) return result; # endif diff --git a/sysdeps/unix/sysv/linux/pwritev64.c b/sysdeps/unix/sysv/linux/pwritev64.c index bed79b7..c0cfe4b 100644 --- a/sysdeps/unix/sysv/linux/pwritev64.c +++ b/sysdeps/unix/sysv/linux/pwritev64.c @@ -27,8 +27,7 @@ ssize_t pwritev64 (int fd, const struct iovec *vector, int count, off64_t offset) { - return SYSCALL_CANCEL (pwritev64, fd, vector, count, - __ALIGNMENT_ARG SYSCALL_LL64 (offset)); + return SYSCALL_CANCEL (pwritev64, fd, vector, count, LO_HI_LONG (offset)); } #else static ssize_t __atomic_pwritev64_replacement (int, const struct iovec *, @@ -36,9 +35,9 @@ static ssize_t __atomic_pwritev64_replacement (int, const struct iovec *, ssize_t pwritev64 (int fd, const struct iovec *vector, int count, off64_t offset) { -#ifdef __NR_pwrite64v +#ifdef __NR_pwritev64 ssize_t result = SYSCALL_CANCEL (pwritev64, fd, vector, count, - __ALIGNMENT_ARG SYSCALL_LL64 (offset)); + LO_HI_LONG (offset)); if (result >= 0 || errno != ENOSYS) return result; #endif diff --git a/sysdeps/unix/sysv/linux/sysdep.h b/sysdeps/unix/sysv/linux/sysdep.h index f2d7e05..24deb78 100644 --- a/sysdeps/unix/sysv/linux/sysdep.h +++ b/sysdeps/unix/sysv/linux/sysdep.h @@ -47,3 +47,12 @@ #define SYSCALL_LL64(val) \ __LONG_LONG_PAIR ((long) ((val) >> 32), (long) ((val) & 0xffffffff)) #endif + +/* Provide a macro to pass the off{64}_t argument on p{readv,writev}{64}. */ +#if __WORDSIZE == 64 || defined __ASSUME_WORDSIZE64_ILP32 +# define LO_HI_LONG(val) (val) +#else +# define LO_HI_LONG(val) \ + (off_t) (val), \ + (off_t) ((((uint64_t) (val)) >> (sizeof (long) * 4)) >> (sizeof (long) * 4)) +#endif