From patchwork Thu Jun 17 11:50:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 1493396 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=q9MTOibS; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4G5L6b0hXbz9sPf for ; Thu, 17 Jun 2021 21:53:27 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D34693894410 for ; Thu, 17 Jun 2021 11:53:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D34693894410 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1623930804; bh=Gu7tvz03sBjqm7lETgUsacK9TYTJRlngkuQ2DGbavUQ=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=q9MTOibSyhUnJITff8Shxr7MIZZ64mqYUx25eDajIyDr2r5Du+AMvyIGWQQ0h2+I8 UvFkP/013imL+xQQ7BTd3VRxEUgo5gM6JuNuiwaXgFsUz+dWHh21rE+2IEBwJg1bdC 6hjbVeeKq+Mym2OphRrBBBDa7UWX+5IvUt0nYVVc= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qv1-xf31.google.com (mail-qv1-xf31.google.com [IPv6:2607:f8b0:4864:20::f31]) by sourceware.org (Postfix) with ESMTPS id A035F3894412 for ; Thu, 17 Jun 2021 11:51:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A035F3894412 Received: by mail-qv1-xf31.google.com with SMTP id x6so1465794qvx.4 for ; Thu, 17 Jun 2021 04:51:12 -0700 (PDT) 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:mime-version:content-transfer-encoding; bh=Gu7tvz03sBjqm7lETgUsacK9TYTJRlngkuQ2DGbavUQ=; b=er5dJPrPvn1rS62/VOw4bhKntdthwtfaApz1ibuwwkZbA33e792WqY74bsXVFud5YJ MpU9FC9cSfjsoipBVkXctsjnldWAC9wZ3rR6Dj1nWX+Pu/7cV7KvOV+atU4EuhADfMwV 3BSXNzq/XXWo5UM8hINV5q/bbrmNiTg1qIk50BvVHS2HYmLoJZR6onWE7pyI75FtLET+ 5+pqjNs8+T19S4a5bJYrOanIe+Cy0wZL/nfSJAaxHBdtsLHAPj/zg8ALkecB2ZwE6OIf 09BDOCUDZaz2mmG4QM7Fce9f/Ee4o8Ha0pGmX5aoY8nyC33DIPHnkkmEs0E0gpmn8veN 8rWQ== X-Gm-Message-State: AOAM530xBSmYU7RCtWpxWv+bMiImqa+mNzEr4vnygnWZLvzsbZWWgWoS NoC6Vjsqfm3JWgi72C0oy1VdAMrGiYvUnA== X-Google-Smtp-Source: ABdhPJyczM7Tsgnf/SfVOjIdke1x7Xkcf/s+Vf4pVx5nMJhuGN9beo+i/io7jywbsOR7Kcx+WlRKTA== X-Received: by 2002:ad4:4502:: with SMTP id k2mr5313155qvu.43.1623930671644; Thu, 17 Jun 2021 04:51:11 -0700 (PDT) Received: from birita.. ([177.194.59.218]) by smtp.googlemail.com with ESMTPSA id p12sm3016435qtw.61.2021.06.17.04.51.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 04:51:11 -0700 (PDT) To: libc-alpha@sourceware.org, Lukasz Majewski , Carlos O'Donell Subject: [PATCH 01/18] Use 64 bit time_t stat internally Date: Thu, 17 Jun 2021 08:50:47 -0300 Message-Id: <20210617115104.1359598-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210617115104.1359598-1-adhemerval.zanella@linaro.org> References: <20210617115104.1359598-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" For the legacy ABI with supports 32 bit time_t it calls the 64 bit time directly, since the LFS symbols calls the 64 bit time_t ones internally. Checked on i686-linux-gnu and x86_64-linux-gnu. Reviewed-by: Lukasz Majewski --- csu/check_fds.c | 8 ++++---- elf/dl-load.c | 8 ++++---- elf/dl-misc.c | 4 ++-- elf/dl-profile.c | 4 ++-- iconv/gconv_cache.c | 4 ++-- include/dirent.h | 2 +- include/file_change_detection.h | 6 +++--- inet/rcmd.c | 6 +++--- intl/loadmsgcat.c | 4 ++-- io/Makefile | 4 ++-- io/file_change_detection.c | 16 +++++++++------- io/getdirname.c | 6 +++--- libio/filedoalloc.c | 2 +- libio/fileops.c | 8 ++++---- libio/oldfileops.c | 2 +- libio/wfileops.c | 2 +- locale/loadarchive.c | 8 ++++---- locale/loadlocale.c | 6 +++--- nscd/nscd_helper.c | 4 ++-- nss/nss_database.c | 4 ++-- sysdeps/posix/dl-fileid.h | 4 ++-- sysdeps/posix/euidaccess.c | 4 ++-- sysdeps/posix/getaddrinfo.c | 21 +++++++++++---------- sysdeps/posix/getcwd.c | 15 ++++++++------- sysdeps/posix/pathconf.c | 4 ++-- sysdeps/posix/sysconf.c | 4 ++-- sysdeps/posix/tempname.c | 8 ++++---- sysdeps/unix/sysv/linux/fdopendir.c | 4 ++-- sysdeps/unix/sysv/linux/fexecve.c | 4 ++-- sysdeps/unix/sysv/linux/opendir.c | 7 ++++--- sysdeps/unix/sysv/linux/pathconf.c | 5 +++-- sysdeps/unix/sysv/linux/ttyname.h | 10 ++-------- sysdeps/unix/sysv/linux/ttyname_r.c | 16 ++++++++-------- sysvipc/ftok.c | 4 ++-- time/tzfile.c | 6 +++--- 35 files changed, 112 insertions(+), 112 deletions(-) diff --git a/csu/check_fds.c b/csu/check_fds.c index fbab28c284..6dc67334af 100644 --- a/csu/check_fds.c +++ b/csu/check_fds.c @@ -69,10 +69,10 @@ check_one_fd (int fd, int mode) Note that the following code assumes that STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO are the three lowest file decsriptor numbers, in this order. */ - struct stat64 st; - if (__builtin_expect (nullfd != fd, 0) - || __builtin_expect (__fstat64 (fd, &st), 0) != 0 - || __builtin_expect (S_ISCHR (st.st_mode), 1) == 0 + struct __stat64_t64 st; + if (__glibc_unlikely (nullfd != fd) + || __glibc_likely (__fstat64_time64 (fd, &st) != 0) + || __glibc_unlikely (S_ISCHR (st.st_mode) == 0) || st.st_rdev != dev) /* We cannot even give an error message here since it would run into the same problems. */ diff --git a/elf/dl-load.c b/elf/dl-load.c index 918ec7546c..a08df001af 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -1946,11 +1946,11 @@ open_path (const char *name, size_t namelen, int mode, { /* We failed to open machine dependent library. Let's test whether there is any directory at all. */ - struct stat64 st; + struct __stat64_t64 st; buf[buflen - namelen - 1] = '\0'; - if (__stat64 (buf, &st) != 0 + if (__stat64_time64 (buf, &st) != 0 || ! S_ISDIR (st.st_mode)) /* The directory does not exist or it is no directory. */ this_dir->status[cnt] = nonexisting; @@ -1968,9 +1968,9 @@ open_path (const char *name, size_t namelen, int mode, /* This is an extra security effort to make sure nobody can preload broken shared objects which are in the trusted directories and so exploit the bugs. */ - struct stat64 st; + struct __stat64_t64 st; - if (__fstat64 (fd, &st) != 0 + if (__fstat64_time64 (fd, &st) != 0 || (st.st_mode & S_ISUID) == 0) { /* The shared object cannot be tested for being SUID diff --git a/elf/dl-misc.c b/elf/dl-misc.c index d4803bba4e..b256d792c6 100644 --- a/elf/dl-misc.c +++ b/elf/dl-misc.c @@ -43,11 +43,11 @@ void * _dl_sysdep_read_whole_file (const char *file, size_t *sizep, int prot) { void *result = MAP_FAILED; - struct stat64 st; + struct __stat64_t64 st; int fd = __open64_nocancel (file, O_RDONLY | O_CLOEXEC); if (fd >= 0) { - if (__fstat64 (fd, &st) >= 0) + if (__fstat64_time64 (fd, &st) >= 0) { *sizep = st.st_size; diff --git a/elf/dl-profile.c b/elf/dl-profile.c index 35b03959bc..088c023d95 100644 --- a/elf/dl-profile.c +++ b/elf/dl-profile.c @@ -185,7 +185,7 @@ _dl_start_profile (void) { char *filename; int fd; - struct stat64 st; + struct __stat64_t64 st; const ElfW(Phdr) *ph; ElfW(Addr) mapstart = ~((ElfW(Addr)) 0); ElfW(Addr) mapend = 0; @@ -342,7 +342,7 @@ _dl_start_profile (void) return; } - if (__fstat64 (fd, &st) < 0 || !S_ISREG (st.st_mode)) + if (__fstat64_time64 (fd, &st) < 0 || !S_ISREG (st.st_mode)) { /* Not stat'able or not a regular file => don't use it. */ errstr = "%s: cannot stat file: %s\n"; diff --git a/iconv/gconv_cache.c b/iconv/gconv_cache.c index 642cc731eb..68d6386d01 100644 --- a/iconv/gconv_cache.c +++ b/iconv/gconv_cache.c @@ -48,7 +48,7 @@ int __gconv_load_cache (void) { int fd; - struct stat64 st; + struct __stat64_t64 st; struct gconvcache_header *header; /* We cannot use the cache if the GCONV_PATH environment variable is @@ -64,7 +64,7 @@ __gconv_load_cache (void) return -1; /* Get information about the file. */ - if (__builtin_expect (__fstat64 (fd, &st), 0) < 0 + if (__glibc_unlikely (__fstat64_time64 (fd, &st) < 0) /* We do not have to start looking at the file if it cannot contain at least the cache header. */ || (size_t) st.st_size < sizeof (struct gconvcache_header)) diff --git a/include/dirent.h b/include/dirent.h index f1d7e8359c..d7567f5e86 100644 --- a/include/dirent.h +++ b/include/dirent.h @@ -49,7 +49,7 @@ extern int __versionsort64 (const struct dirent64 **a, const struct dirent64 **b) __attribute_pure__; extern DIR *__alloc_dir (int fd, bool close_fd, int flags, - const struct stat64 *statp) + const struct __stat64_t64 *statp) __nonnull (4) attribute_hidden; extern __typeof (rewinddir) __rewinddir; extern __typeof (seekdir) __seekdir; diff --git a/include/file_change_detection.h b/include/file_change_detection.h index 9de2bd0b79..953de7c7fd 100644 --- a/include/file_change_detection.h +++ b/include/file_change_detection.h @@ -33,8 +33,8 @@ struct file_change_detection off64_t size; ino64_t ino; - struct timespec mtime; - struct timespec ctime; + struct __timespec64 mtime; + struct __timespec64 ctime; }; /* Returns true if *LEFT and *RIGHT describe the same version of the @@ -45,7 +45,7 @@ bool __file_is_unchanged (const struct file_change_detection *left, /* Extract file change information to *FILE from the stat buffer *ST. */ void __file_change_detection_for_stat (struct file_change_detection *file, - const struct stat64 *st); + const struct __stat64_t64 *st); /* Writes file change information for PATH to *FILE. Returns true on success. For benign errors, *FILE is cleared, and true is diff --git a/inet/rcmd.c b/inet/rcmd.c index 0cfdaee15e..0d6b595572 100644 --- a/inet/rcmd.c +++ b/inet/rcmd.c @@ -468,14 +468,14 @@ ruserok (const char *rhost, int superuser, const char *ruser, static FILE * iruserfopen (const char *file, uid_t okuser) { - struct stat64 st; + struct __stat64_t64 st; char *cp = NULL; FILE *res = NULL; /* If not a regular file, if owned by someone other than user or root, if writeable by anyone but the owner, or if hardlinked anywhere, quit. */ - if (__lstat64 (file, &st)) + if (__lstat64_time64 (file, &st)) cp = _("lstat failed"); else if (!S_ISREG (st.st_mode)) cp = _("not regular file"); @@ -484,7 +484,7 @@ iruserfopen (const char *file, uid_t okuser) res = fopen (file, "rce"); if (!res) cp = _("cannot open"); - else if (__fstat64 (fileno (res), &st) < 0) + else if (__fstat64_time64 (fileno (res), &st) < 0) cp = _("fstat failed"); else if (st.st_uid && st.st_uid != okuser) cp = _("bad owner"); diff --git a/intl/loadmsgcat.c b/intl/loadmsgcat.c index 4fda9b0219..30588e9996 100644 --- a/intl/loadmsgcat.c +++ b/intl/loadmsgcat.c @@ -756,7 +756,7 @@ _nl_load_domain (struct loaded_l10nfile *domain_file, int fd = -1; size_t size; #ifdef _LIBC - struct stat64 st; + struct __stat64_t64 st; #else struct stat st; #endif @@ -804,7 +804,7 @@ _nl_load_domain (struct loaded_l10nfile *domain_file, /* We must know about the size of the file. */ if ( #ifdef _LIBC - __builtin_expect (__fstat64 (fd, &st) != 0, 0) + __builtin_expect (__fstat64_time64 (fd, &st) != 0, 0) #else __builtin_expect (fstat (fd, &st) != 0, 0) #endif diff --git a/io/Makefile b/io/Makefile index ba8bd37355..1a16990205 100644 --- a/io/Makefile +++ b/io/Makefile @@ -69,7 +69,7 @@ tests := test-utime test-stat test-stat2 test-lfs tst-getcwd \ tst-posix_fallocate tst-posix_fallocate64 \ tst-fts tst-fts-lfs tst-open-tmpfile \ tst-copy_file_range tst-getcwd-abspath tst-lockf \ - tst-ftw-lnk tst-file_change_detection tst-lchmod \ + tst-ftw-lnk tst-lchmod \ tst-ftw-bz26353 tst-stat tst-stat-lfs \ tst-utime \ tst-utimes \ @@ -90,7 +90,7 @@ tests-time64 := \ tst-utimes-time64 \ # Likewise for statx, but we do not need static linking here. -tests-internal += tst-statx +tests-internal += tst-statx tst-file_change_detection tests-static += tst-statx ifeq ($(run-built-tests),yes) diff --git a/io/file_change_detection.c b/io/file_change_detection.c index 9871bc9166..ac5e451513 100644 --- a/io/file_change_detection.c +++ b/io/file_change_detection.c @@ -44,7 +44,7 @@ libc_hidden_def (__file_is_unchanged) void __file_change_detection_for_stat (struct file_change_detection *file, - const struct stat64 *st) + const struct __stat64_t64 *st) { if (S_ISDIR (st->st_mode)) /* Treat as empty file. */ @@ -56,8 +56,10 @@ __file_change_detection_for_stat (struct file_change_detection *file, { file->size = st->st_size; file->ino = st->st_ino; - file->mtime = st->st_mtim; - file->ctime = st->st_ctim; + file->mtime = (struct __timespec64 ) { .tv_sec = st->st_mtim.tv_sec, + .tv_nsec = st->st_mtim.tv_nsec }; + file->ctime = (struct __timespec64 ) { .tv_sec = st->st_ctim.tv_sec, + .tv_nsec = st->st_mtim.tv_nsec }; } } libc_hidden_def (__file_change_detection_for_stat) @@ -66,8 +68,8 @@ bool __file_change_detection_for_path (struct file_change_detection *file, const char *path) { - struct stat64 st; - if (__stat64 (path, &st) != 0) + struct __stat64_t64 st; + if (__stat64_time64 (path, &st) != 0) switch (errno) { case EACCES: @@ -104,8 +106,8 @@ __file_change_detection_for_fp (struct file_change_detection *file, } else { - struct stat64 st; - if (__fstat64 (__fileno (fp), &st) != 0) + struct __stat64_t64 st; + if (__fstat64_time64 (__fileno (fp), &st) != 0) /* If we already have a file descriptor, all errors are fatal. */ return false; else diff --git a/io/getdirname.c b/io/getdirname.c index 32b5ab4b6c..f29e910b37 100644 --- a/io/getdirname.c +++ b/io/getdirname.c @@ -28,12 +28,12 @@ char * get_current_dir_name (void) { char *pwd; - struct stat64 dotstat, pwdstat; + struct __stat64_t64 dotstat, pwdstat; pwd = getenv ("PWD"); if (pwd != NULL - && __stat64 (".", &dotstat) == 0 - && __stat64 (pwd, &pwdstat) == 0 + && __stat64_time64 (".", &dotstat) == 0 + && __stat64_time64 (pwd, &pwdstat) == 0 && pwdstat.st_dev == dotstat.st_dev && pwdstat.st_ino == dotstat.st_ino) /* The PWD value is correct. Use it. */ diff --git a/libio/filedoalloc.c b/libio/filedoalloc.c index 7afa3cb683..c792eec88f 100644 --- a/libio/filedoalloc.c +++ b/libio/filedoalloc.c @@ -78,7 +78,7 @@ _IO_file_doallocate (FILE *fp) { size_t size; char *p; - struct stat64 st; + struct __stat64_t64 st; size = BUFSIZ; if (fp->_fileno >= 0 && __builtin_expect (_IO_SYSSTAT (fp, &st), 0) >= 0) diff --git a/libio/fileops.c b/libio/fileops.c index a71a567547..e8ee374821 100644 --- a/libio/fileops.c +++ b/libio/fileops.c @@ -545,7 +545,7 @@ libc_hidden_ver (_IO_new_file_underflow, _IO_file_underflow) static int mmap_remap_check (FILE *fp) { - struct stat64 st; + struct __stat64_t64 st; if (_IO_SYSSTAT (fp, &st) == 0 && S_ISREG (st.st_mode) && st.st_size != 0 @@ -663,7 +663,7 @@ decide_maybe_mmap (FILE *fp) file descriptors are for mmap-able objects and on 32-bit machines we don't want to map files which are too large since this would require too much virtual memory. */ - struct stat64 st; + struct __stat64_t64 st; if (_IO_SYSSTAT (fp, &st) == 0 && S_ISREG (st.st_mode) && st.st_size != 0 @@ -962,7 +962,7 @@ _IO_new_file_seekoff (FILE *fp, off64_t offset, int dir, int mode) break; case _IO_seek_end: { - struct stat64 st; + struct __stat64_t64 st; if (_IO_SYSSTAT (fp, &st) == 0 && S_ISREG (st.st_mode)) { offset += st.st_size; @@ -1145,7 +1145,7 @@ libc_hidden_def (_IO_file_seek) int _IO_file_stat (FILE *fp, void *st) { - return __fstat64 (fp->_fileno, (struct stat64 *) st); + return __fstat64_time64 (fp->_fileno, (struct __stat64_t64 *) st); } libc_hidden_def (_IO_file_stat) diff --git a/libio/oldfileops.c b/libio/oldfileops.c index ed235360ad..ed3c98bd6d 100644 --- a/libio/oldfileops.c +++ b/libio/oldfileops.c @@ -487,7 +487,7 @@ _IO_old_file_seekoff (FILE *fp, off64_t offset, int dir, int mode) break; case _IO_seek_end: { - struct stat64 st; + struct __stat64_t64 st; if (_IO_SYSSTAT (fp, &st) == 0 && S_ISREG (st.st_mode)) { offset += st.st_size; diff --git a/libio/wfileops.c b/libio/wfileops.c index 5d23566171..37f44780f8 100644 --- a/libio/wfileops.c +++ b/libio/wfileops.c @@ -840,7 +840,7 @@ _IO_wfile_seekoff (FILE *fp, off64_t offset, int dir, int mode) break; case _IO_seek_end: { - struct stat64 st; + struct __stat64_t64 st; if (_IO_SYSSTAT (fp, &st) == 0 && S_ISREG (st.st_mode)) { offset += st.st_size; diff --git a/locale/loadarchive.c b/locale/loadarchive.c index 4177fc8972..512769eaec 100644 --- a/locale/loadarchive.c +++ b/locale/loadarchive.c @@ -78,7 +78,7 @@ static struct archmapped *archmapped; ARCHMAPPED points to this; if mapping the archive header failed, then headmap.ptr is null. */ static struct archmapped headmap; -static struct stat64 archive_stat; /* stat of archive when header mapped. */ +static struct __stat64_t64 archive_stat; /* stat of archive when header mapped. */ /* Record of locales that we have already loaded from the archive. */ struct locale_in_archive @@ -207,7 +207,7 @@ _nl_load_locale_from_archive (int category, const char **namep) /* Cannot open the archive, for whatever reason. */ return NULL; - if (__fstat64 (fd, &archive_stat) == -1) + if (__fstat64_time64 (fd, &archive_stat) == -1) { /* stat failed, very strange. */ close_and_out: @@ -396,7 +396,7 @@ _nl_load_locale_from_archive (int category, const char **namep) /* Open the file if it hasn't happened yet. */ if (fd == -1) { - struct stat64 st; + struct __stat64_t64 st; fd = __open_nocancel (archfname, O_RDONLY|O_LARGEFILE|O_CLOEXEC); if (fd == -1) @@ -405,7 +405,7 @@ _nl_load_locale_from_archive (int category, const char **namep) /* Now verify we think this is really the same archive file we opened before. If it has been changed we cannot trust the header we read previously. */ - if (__fstat64 (fd, &st) < 0 + if (__fstat64_time64 (fd, &st) < 0 || st.st_size != archive_stat.st_size || st.st_mtime != archive_stat.st_mtime || st.st_dev != archive_stat.st_dev diff --git a/locale/loadlocale.c b/locale/loadlocale.c index 9c03490883..f4e6cc9fc2 100644 --- a/locale/loadlocale.c +++ b/locale/loadlocale.c @@ -167,7 +167,7 @@ _nl_load_locale (struct loaded_l10nfile *file, int category) { int fd; void *filedata; - struct stat64 st; + struct __stat64_t64 st; struct __locale_data *newdata; int save_err; int alloc = ld_mapped; @@ -180,7 +180,7 @@ _nl_load_locale (struct loaded_l10nfile *file, int category) /* Cannot open the file. */ return; - if (__builtin_expect (__fstat64 (fd, &st), 0) < 0) + if (__glibc_unlikely (__fstat64_time64 (fd, &st) < 0)) { puntfd: __close_nocancel_nostatus (fd); @@ -206,7 +206,7 @@ _nl_load_locale (struct loaded_l10nfile *file, int category) if (__builtin_expect (fd, 0) < 0) return; - if (__builtin_expect (__fstat64 (fd, &st), 0) < 0) + if (__glibc_unlikely (__fstat64_time64 (fd, &st) < 0)) goto puntfd; } diff --git a/nscd/nscd_helper.c b/nscd/nscd_helper.c index 462504d828..06ba7476e5 100644 --- a/nscd/nscd_helper.c +++ b/nscd/nscd_helper.c @@ -324,8 +324,8 @@ __nscd_get_mapping (request_type type, const char *key, if (__glibc_unlikely (n == keylen)) { - struct stat64 st; - if (__builtin_expect (__fstat64 (mapfd, &st) != 0, 0) + struct __stat64_t64 st; + if (__glibc_unlikely (__fstat64_time64 (mapfd, &st) != 0) || __builtin_expect (st.st_size < sizeof (struct database_pers_head), 0)) goto out_close; diff --git a/nss/nss_database.c b/nss/nss_database.c index 1e11294406..ab121cb371 100644 --- a/nss/nss_database.c +++ b/nss/nss_database.c @@ -394,7 +394,7 @@ nss_database_check_reload_and_get (struct nss_database_state *local, nss_action_list *result, enum nss_database database_index) { - struct stat64 str; + struct __stat64_t64 str; /* Acquire MO is needed because the thread that sets reload_disabled may have loaded the configuration first, so synchronize with the @@ -424,7 +424,7 @@ nss_database_check_reload_and_get (struct nss_database_state *local, errors here are very unlikely, but the chance that we're entering a container is also very unlikely, so we err on the side of both very unlikely things not happening at the same time. */ - if (__stat64 ("/", &str) != 0 + if (__stat64_time64 ("/", &str) != 0 || (local->root_ino != 0 && (str.st_ino != local->root_ino || str.st_dev != local->root_dev))) diff --git a/sysdeps/posix/dl-fileid.h b/sysdeps/posix/dl-fileid.h index 0bb6794dbe..bf437f3d71 100644 --- a/sysdeps/posix/dl-fileid.h +++ b/sysdeps/posix/dl-fileid.h @@ -32,9 +32,9 @@ struct r_file_id static inline bool _dl_get_file_id (int fd, struct r_file_id *id) { - struct stat64 st; + struct __stat64_t64 st; - if (__glibc_unlikely (__fstat64 (fd, &st) < 0)) + if (__glibc_unlikely (__fstat64_time64 (fd, &st) < 0)) return false; id->dev = st.st_dev; diff --git a/sysdeps/posix/euidaccess.c b/sysdeps/posix/euidaccess.c index 26ebb432a2..86f3285471 100644 --- a/sysdeps/posix/euidaccess.c +++ b/sysdeps/posix/euidaccess.c @@ -119,7 +119,7 @@ int group_member (); int euidaccess (const char *path, int mode) { - struct stat64 stats; + struct __stat64_t64 stats; int granted; #ifdef _LIBC @@ -140,7 +140,7 @@ euidaccess (const char *path, int mode) return access (path, mode); #endif - if (__stat64 (path, &stats)) + if (__stat64_time64 (path, &stats)) return -1; mode &= (X_OK | W_OK | R_OK); /* Clear any bogus bits. */ diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c index b7e1aee80f..b2831508c4 100644 --- a/sysdeps/posix/getaddrinfo.c +++ b/sysdeps/posix/getaddrinfo.c @@ -1636,16 +1636,17 @@ static int gaiconf_reload_flag_ever_set; /* Last modification time. */ #ifdef _STATBUF_ST_NSEC -static struct timespec gaiconf_mtime; +static struct __timespec64 gaiconf_mtime; static inline void -save_gaiconf_mtime (const struct stat64 *st) +save_gaiconf_mtime (const struct __stat64_t64 *st) { - gaiconf_mtime = st->st_mtim; + gaiconf_mtime = (struct __timespec64) { .tv_sec = st->st_mtim.tv_sec, + .tv_nsec = st->st_mtim.tv_nsec }; } static inline bool -check_gaiconf_mtime (const struct stat64 *st) +check_gaiconf_mtime (const struct __stat64_t64 *st) { return (st->st_mtim.tv_sec == gaiconf_mtime.tv_sec && st->st_mtim.tv_nsec == gaiconf_mtime.tv_nsec); @@ -1656,13 +1657,13 @@ check_gaiconf_mtime (const struct stat64 *st) static time_t gaiconf_mtime; static inline void -save_gaiconf_mtime (const struct stat64 *st) +save_gaiconf_mtime (const struct __stat64_t64 *st) { gaiconf_mtime = st->st_mtime; } static inline bool -check_gaiconf_mtime (const struct stat64 *st) +check_gaiconf_mtime (const struct __stat64_t64 *st) { return st->st_mtime == gaiconf_mtime; } @@ -1777,8 +1778,8 @@ gaiconf_init (void) FILE *fp = fopen (GAICONF_FNAME, "rce"); if (fp != NULL) { - struct stat64 st; - if (__fstat64 (fileno (fp), &st) != 0) + struct __stat64_t64 st; + if (__fstat64_time64 (fileno (fp), &st) != 0) { fclose (fp); goto no_file; @@ -2130,8 +2131,8 @@ gaiconf_init (void) static void gaiconf_reload (void) { - struct stat64 st; - if (__stat64 (GAICONF_FNAME, &st) != 0 + struct __stat64_t64 st; + if (__stat64_time64 (GAICONF_FNAME, &st) != 0 || !check_gaiconf_mtime (&st)) gaiconf_init (); } diff --git a/sysdeps/posix/getcwd.c b/sysdeps/posix/getcwd.c index f11644aae7..13680026ff 100644 --- a/sysdeps/posix/getcwd.c +++ b/sysdeps/posix/getcwd.c @@ -183,7 +183,7 @@ __getcwd_generic (char *buf, size_t size) ino_t rootino, thisino; char *dir; register char *dirp; - struct stat64 st; + struct __stat64_t64 st; size_t allocated = size; size_t used; @@ -249,12 +249,12 @@ __getcwd_generic (char *buf, size_t size) dirp = dir + allocated; *--dirp = '\0'; - if (__lstat64 (".", &st) < 0) + if (__lstat64_time64 (".", &st) < 0) goto lose; thisdev = st.st_dev; thisino = st.st_ino; - if (__lstat64 ("/", &st) < 0) + if (__lstat64_time64 ("/", &st) < 0) goto lose; rootdev = st.st_dev; rootino = st.st_ino; @@ -276,12 +276,12 @@ __getcwd_generic (char *buf, size_t size) if (fd < 0) goto lose; fd_needs_closing = true; - parent_status = __fstat64 (fd, &st); + parent_status = __fstat64_time64 (fd, &st); #else dotlist[dotlen++] = '.'; dotlist[dotlen++] = '.'; dotlist[dotlen] = '\0'; - parent_status = __lstat64 (dotlist, &st); + parent_status = __lstat64_time64 (dotlist, &st); #endif if (parent_status != 0) goto lose; @@ -353,7 +353,8 @@ __getcwd_generic (char *buf, size_t size) { int entry_status; #if HAVE_OPENAT_SUPPORT - entry_status = __fstatat64 (fd, d->d_name, &st, AT_SYMLINK_NOFOLLOW); + entry_status = __fstatat64_time64 (fd, d->d_name, &st, + AT_SYMLINK_NOFOLLOW); #else /* Compute size needed for this file name, or for the file name ".." in the same directory, whichever is larger. @@ -390,7 +391,7 @@ __getcwd_generic (char *buf, size_t size) } memcpy (dotlist + dotlen, d->d_name, _D_ALLOC_NAMLEN (d)); - entry_status = __lstat64 (dotlist, &st); + entry_status = __lstat64_time64 (dotlist, &st); #endif /* We don't fail here if we cannot stat() a directory entry. This can happen when (network) file systems fail. If this diff --git a/sysdeps/posix/pathconf.c b/sysdeps/posix/pathconf.c index 9eb17d1536..89fcfad49d 100644 --- a/sysdeps/posix/pathconf.c +++ b/sysdeps/posix/pathconf.c @@ -129,9 +129,9 @@ __pathconf (const char *path, int name) #ifdef _POSIX_ASYNC_IO { /* AIO is only allowed on regular files and block devices. */ - struct stat64 st; + struct __stat64_t64 st; - if (__stat64 (path, &st) < 0 + if (__stat64_time64 (path, &st) < 0 || (! S_ISREG (st.st_mode) && ! S_ISBLK (st.st_mode))) return -1; else diff --git a/sysdeps/posix/sysconf.c b/sysdeps/posix/sysconf.c index 54d6046d00..3e8ec5cd51 100644 --- a/sysdeps/posix/sysconf.c +++ b/sysdeps/posix/sysconf.c @@ -1215,8 +1215,8 @@ __sysconf_check_spec (const char *spec) "/POSIX_V6_", sizeof ("/POSIX_V6_") - 1), spec, speclen + 1); - struct stat64 st; - long int ret = __stat64 (name, &st) >= 0 ? 1 : -1; + struct __stat64_t64 st; + long int ret = __stat64_time64 (name, &st) >= 0 ? 1 : -1; __set_errno (save_errno); return ret; diff --git a/sysdeps/posix/tempname.c b/sysdeps/posix/tempname.c index 5f804b38d7..ff38f1e31f 100644 --- a/sysdeps/posix/tempname.c +++ b/sysdeps/posix/tempname.c @@ -55,14 +55,14 @@ #include #if _LIBC -# define struct_stat64 struct stat64 +# define struct_stat64 struct __stat64_t64 # define __secure_getenv __libc_secure_getenv #else # define struct_stat64 struct stat # define __gen_tempname gen_tempname # define __mkdir mkdir # define __open open -# define __lstat64(file, buf) lstat (file, buf) +# define __lstat64_time64(file, buf) lstat (file, buf) # define __stat64(file, buf) stat (file, buf) # define __getrandom getrandom # define __clock_gettime64 clock_gettime @@ -99,7 +99,7 @@ static int direxists (const char *dir) { struct_stat64 buf; - return __stat64 (dir, &buf) == 0 && S_ISDIR (buf.st_mode); + return __stat64_time64 (dir, &buf) == 0 && S_ISDIR (buf.st_mode); } /* Path search algorithm, for tmpnam, tmpfile, etc. If DIR is @@ -191,7 +191,7 @@ try_nocreate (char *tmpl, void *flags _GL_UNUSED) { struct_stat64 st; - if (__lstat64 (tmpl, &st) == 0 || errno == EOVERFLOW) + if (__lstat64_time64 (tmpl, &st) == 0 || errno == EOVERFLOW) __set_errno (EEXIST); return errno == ENOENT ? 0 : -1; } diff --git a/sysdeps/unix/sysv/linux/fdopendir.c b/sysdeps/unix/sysv/linux/fdopendir.c index ede43f2485..32ec10e206 100644 --- a/sysdeps/unix/sysv/linux/fdopendir.c +++ b/sysdeps/unix/sysv/linux/fdopendir.c @@ -27,9 +27,9 @@ DIR * __fdopendir (int fd) { - struct stat64 statbuf; + struct __stat64_t64 statbuf; - if (__builtin_expect (__fstat64 (fd, &statbuf), 0) < 0) + if (__glibc_unlikely (__fstat64_time64 (fd, &statbuf) < 0)) return NULL; if (__glibc_unlikely (! S_ISDIR (statbuf.st_mode))) { diff --git a/sysdeps/unix/sysv/linux/fexecve.c b/sysdeps/unix/sysv/linux/fexecve.c index df25c2acb8..4dfcaeedc1 100644 --- a/sysdeps/unix/sysv/linux/fexecve.c +++ b/sysdeps/unix/sysv/linux/fexecve.c @@ -58,8 +58,8 @@ fexecve (int fd, char *const argv[], char *const envp[]) /* We come here only if the 'execve' call fails. Determine whether /proc is mounted. If not we return ENOSYS. */ - struct stat64 st; - if (__stat64 ("/proc/self/fd", &st) != 0 && errno == ENOENT) + struct __stat64_t64 st; + if (__stat64_time64 ("/proc/self/fd", &st) != 0 && errno == ENOENT) save = ENOSYS; __set_errno (save); diff --git a/sysdeps/unix/sysv/linux/opendir.c b/sysdeps/unix/sysv/linux/opendir.c index 4020a826f9..48f254d169 100644 --- a/sysdeps/unix/sysv/linux/opendir.c +++ b/sysdeps/unix/sysv/linux/opendir.c @@ -49,8 +49,8 @@ opendir_tail (int fd) /* Now make sure this really is a directory and nothing changed since the `stat' call. The S_ISDIR check is superfluous if O_DIRECTORY works, but it's cheap and we need the stat call for st_blksize anyway. */ - struct stat64 statbuf; - if (__glibc_unlikely (__fstat64 (fd, &statbuf) < 0)) + struct __stat64_t64 statbuf; + if (__glibc_unlikely (__fstat64_time64 (fd, &statbuf) < 0)) goto lose; if (__glibc_unlikely (! S_ISDIR (statbuf.st_mode))) { @@ -88,7 +88,8 @@ __opendir (const char *name) weak_alias (__opendir, opendir) DIR * -__alloc_dir (int fd, bool close_fd, int flags, const struct stat64 *statp) +__alloc_dir (int fd, bool close_fd, int flags, + const struct __stat64_t64 *statp) { /* We have to set the close-on-exit flag if the user provided the file descriptor. */ diff --git a/sysdeps/unix/sysv/linux/pathconf.c b/sysdeps/unix/sysv/linux/pathconf.c index f37e8aaf68..b599a66c93 100644 --- a/sysdeps/unix/sysv/linux/pathconf.c +++ b/sysdeps/unix/sysv/linux/pathconf.c @@ -65,9 +65,10 @@ distinguish_extX (const struct statfs *fsbuf, const char *file, int fd) { char buf[64]; char path[PATH_MAX]; - struct stat64 st; + struct __stat64_t64 st; - if ((file == NULL ? __fstat64 (fd, &st) : __stat64 (file, &st)) != 0) + if ((file == NULL ? __fstat64_time64 (fd, &st) + : __stat64_time64 (file, &st)) != 0) /* Strange. The statfd call worked, but stat fails. Default to the more pessimistic value. */ return EXT2_LINK_MAX; diff --git a/sysdeps/unix/sysv/linux/ttyname.h b/sysdeps/unix/sysv/linux/ttyname.h index 0a0048cc02..5dcbfef973 100644 --- a/sysdeps/unix/sysv/linux/ttyname.h +++ b/sysdeps/unix/sysv/linux/ttyname.h @@ -25,24 +25,18 @@ linux/Documentation/devices.txt (on linux < 4.10) or linux/Documentation/admin-guide/devices.txt (on linux >= 4.10). */ static inline bool -is_pty (struct stat64 *sb) +is_pty (struct __stat64_t64 *sb) { -#ifdef _STATBUF_ST_RDEV int m = __gnu_dev_major (sb->st_rdev); return (136 <= m && m <= 143); -#else - return false; -#endif } static inline bool -is_mytty (const struct stat64 *mytty, const struct stat64 *maybe) +is_mytty (const struct __stat64_t64 *mytty, const struct __stat64_t64 *maybe) { return (maybe->st_ino == mytty->st_ino && maybe->st_dev == mytty->st_dev -#ifdef _STATBUF_ST_RDEV && S_ISCHR (maybe->st_mode) && maybe->st_rdev == mytty->st_rdev -#endif ); } diff --git a/sysdeps/unix/sysv/linux/ttyname_r.c b/sysdeps/unix/sysv/linux/ttyname_r.c index 899a851a83..9ef9f42883 100644 --- a/sysdeps/unix/sysv/linux/ttyname_r.c +++ b/sysdeps/unix/sysv/linux/ttyname_r.c @@ -31,15 +31,15 @@ #include "ttyname.h" static int getttyname_r (char *buf, size_t buflen, - const struct stat64 *mytty, int save, + const struct __stat64_t64 *mytty, int save, int *dostat); static int attribute_compat_text_section -getttyname_r (char *buf, size_t buflen, const struct stat64 *mytty, +getttyname_r (char *buf, size_t buflen, const struct __stat64_t64 *mytty, int save, int *dostat) { - struct stat64 st; + struct __stat64_t64 st; DIR *dirstream; struct dirent64 *d; size_t devlen = strlen (buf); @@ -71,7 +71,7 @@ getttyname_r (char *buf, size_t buflen, const struct stat64 *mytty, cp = __stpncpy (buf + devlen, d->d_name, needed); cp[0] = '\0'; - if (__stat64 (buf, &st) == 0 + if (__stat64_time64 (buf, &st) == 0 && is_mytty (mytty, &st)) { (void) __closedir (dirstream); @@ -93,7 +93,7 @@ int __ttyname_r (int fd, char *buf, size_t buflen) { struct fd_to_filename filename; - struct stat64 st, st1; + struct __stat64_t64 st, st1; int dostat = 0; int doispty = 0; int save = errno; @@ -118,7 +118,7 @@ __ttyname_r (int fd, char *buf, size_t buflen) if (__glibc_unlikely (__tcgetattr (fd, &term) < 0)) return errno; - if (__fstat64 (fd, &st) < 0) + if (__fstat64_time64 (fd, &st) < 0) return errno; /* We try using the /proc filesystem. */ @@ -144,7 +144,7 @@ __ttyname_r (int fd, char *buf, size_t buflen) /* Verify readlink result, fall back on iterating through devices. */ if (buf[0] == '/' - && __stat64 (buf, &st1) == 0 + && __stat64_time64 (buf, &st1) == 0 && is_mytty (&st, &st1)) return 0; @@ -155,7 +155,7 @@ __ttyname_r (int fd, char *buf, size_t buflen) memcpy (buf, "/dev/pts/", sizeof ("/dev/pts/")); buflen -= sizeof ("/dev/pts/") - 1; - if (__stat64 (buf, &st1) == 0 && S_ISDIR (st1.st_mode)) + if (__stat64_time64 (buf, &st1) == 0 && S_ISDIR (st1.st_mode)) { ret = getttyname_r (buf, buflen, &st, save, &dostat); diff --git a/sysvipc/ftok.c b/sysvipc/ftok.c index 2e39c74415..bd633bd395 100644 --- a/sysvipc/ftok.c +++ b/sysvipc/ftok.c @@ -22,10 +22,10 @@ key_t ftok (const char *pathname, int proj_id) { - struct stat64 st; + struct __stat64_t64 st; key_t key; - if (__stat64 (pathname, &st) < 0) + if (__stat64_time64 (pathname, &st) < 0) return (key_t) -1; key = ((st.st_ino & 0xffff) | ((st.st_dev & 0xff) << 16) diff --git a/time/tzfile.c b/time/tzfile.c index 040a5e341f..4377018a55 100644 --- a/time/tzfile.c +++ b/time/tzfile.c @@ -150,9 +150,9 @@ __tzfile_read (const char *file, size_t extra, char **extrap) } /* If we were already using tzfile, check whether the file changed. */ - struct stat64 st; + struct __stat64_t64 st; if (was_using_tzfile - && __stat64 (file, &st) == 0 + && __stat64_time64 (file, &st) == 0 && tzfile_ino == st.st_ino && tzfile_dev == st.st_dev && tzfile_mtime == st.st_mtime) goto done; /* Nothing to do. */ @@ -164,7 +164,7 @@ __tzfile_read (const char *file, size_t extra, char **extrap) goto ret_free_transitions; /* Get information about the file we are actually using. */ - if (__fstat64 (__fileno (f), &st) != 0) + if (__fstat64_time64 (__fileno (f), &st) != 0) goto lose; free ((void *) transitions); From patchwork Thu Jun 17 11:50:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 1493398 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=GWmJoC/i; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4G5L7R3KVzz9sRK for ; Thu, 17 Jun 2021 21:54:11 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 33003385383A for ; Thu, 17 Jun 2021 11:54:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 33003385383A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1623930849; bh=A+E8IzNKZijrilk5RhXn9AlElTfAfQBIouaGu9zYAEs=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=GWmJoC/i39U4h7YctahwfIqXz7N80bANOqf3xOOdVL2nu3+t/71J0dXnN/EDWfZY7 RKhSrzl2eyNAqlki6z5ILy+d1rEUNP8ngMRaXeZCrNnxOZVmuoiCQtjbfkZ4npzpq2 RWajDYM0Wgk8Ei7reR4ywaM5VTs/uyDw/vW8CiAk= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qt1-x829.google.com (mail-qt1-x829.google.com [IPv6:2607:f8b0:4864:20::829]) by sourceware.org (Postfix) with ESMTPS id E15933893C44 for ; Thu, 17 Jun 2021 11:51:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E15933893C44 Received: by mail-qt1-x829.google.com with SMTP id r20so4447907qtp.3 for ; Thu, 17 Jun 2021 04:51:13 -0700 (PDT) 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:mime-version:content-transfer-encoding; bh=A+E8IzNKZijrilk5RhXn9AlElTfAfQBIouaGu9zYAEs=; b=lLVVrsNiOvyAJbFlsNLF1zCi0WRccffg8QOMAwsyh1ozyi0WXrCCX6wFKnxpV00Dtr PG9bhsNjR5kcu+Rs/CkNExr9AXNOYBfw9nayBKWitSvFy1F9lz4IyzXmtmtWHOv9ngel Y/azjpmLtIVMMJLUiscbZcj97QEUeX5CJ9IY4Vj8Tgd0czey/DL0QKaG4ZowyK9ygG8g 55l2lhyK3y5oFYwDzE/IEzlk/B8UxcuujI0qaiU+EZJY0Fl+GjBK0iFEJAQy1YlXU6WE f0JfpKotAeVbw5K8MfW3gips46gmXfZXhElQFRV0TISRNgEzEWzc32fUWKBNcT7A9FaJ mfOg== X-Gm-Message-State: AOAM530aVHEU955q1zX7Aiu7ozMVwQ+UVgM+XJ4etDn3f65m3fqZ6eA9 1DSSzmRuThzeyG8Xu8Lxsx38NNI4hxvN2g== X-Google-Smtp-Source: ABdhPJz4HoQyDopadTdCW/Di/TRL7zecKnu4JPEaMMOgSqbYXQyT+Jwlb6iJxACKZCYWyRkSXLFT6w== X-Received: by 2002:ac8:b02:: with SMTP id e2mr4621577qti.159.1623930673306; Thu, 17 Jun 2021 04:51:13 -0700 (PDT) Received: from birita.. ([177.194.59.218]) by smtp.googlemail.com with ESMTPSA id p12sm3016435qtw.61.2021.06.17.04.51.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 04:51:13 -0700 (PDT) To: libc-alpha@sourceware.org, Lukasz Majewski , Carlos O'Donell Subject: [PATCH 02/18] Use LFS and 64 bit time for installed programs Date: Thu, 17 Jun 2021 08:50:48 -0300 Message-Id: <20210617115104.1359598-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210617115104.1359598-1-adhemerval.zanella@linaro.org> References: <20210617115104.1359598-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" The installed programs are built with a combination of different values for MODULE_NAME, as below. To enable both Long File Support and 64 bt time, -D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64 is added for nonlib, nscd, lddlibc4, ldconfig, locale_programs, and iconvprogs modules. nscd/nscd nscd/nscd.o MODULE_NAME=nscd nscd/connections.o MODULE_NAME=nscd nscd/pwdcache.o MODULE_NAME=nscd nscd/getpwnam_r.o MODULE_NAME=nscd nscd/getpwuid_r.o MODULE_NAME=nscd nscd/grpcache.o MODULE_NAME=nscd nscd/getgrnam_r.o MODULE_NAME=nscd nscd/getgrgid_r.o MODULE_NAME=nscd nscd/hstcache.o MODULE_NAME=nscd nscd/gethstbyad_r.o MODULE_NAME=nscd nscd/gethstbynm3_r.o MODULE_NAME=nscd nscd/getsrvbynm_r.o MODULE_NAME=nscd nscd/getsrvbypt_r.o MODULE_NAME=nscd nscd/servicescache.o MODULE_NAME=nscd nscd/dbg_log.o MODULE_NAME=nscd nscd/nscd_conf.o MODULE_NAME=nscd nscd/nscd_stat.o MODULE_NAME=nscd nscd/cache.o MODULE_NAME=nscd nscd/mem.o MODULE_NAME=nscd nscd/nscd_setup_thread.o MODULE_NAME=nscd nscd/xmalloc.o MODULE_NAME=nscd nscd/xstrdup.o MODULE_NAME=nscd nscd/aicache.o MODULE_NAME=nscd nscd/initgrcache.o MODULE_NAME=nscd nscd/gai.o MODULE_NAME=nscd nscd/res_hconf.o MODULE_NAME=nscd nscd/netgroupcache.o MODULE_NAME=nscd nscd/cachedumper.o MODULE_NAME=nscd elf/lddlibc4 elf/lddlibc4 MODULE_NAME=lddlibc4 elf/pldd elf/pldd.o MODULE_NAME=nonlib elf/xmalloc.o MODULE_NAME=nonlib elf/sln elf/sln.o MODULE_NAME=nonlib elf/static-stubs.o MODULE_NAME=nonlib elf/sprof MODULE_NAME=nonlib elf/ldconfig elf/ldconfig.o MODULE_NAME=ldconfig elf/cache.o MODULE_NAME=nonlib elf/readlib.o MODULE_NAME=nonlib elf/xmalloc.o MODULE_NAME=nonlib elf/xstrdup.o MODULE_NAME=nonlib elf/chroot_canon.o MODULE_NAME=nonlib elf/static-stubs.o MODULE_NAME=nonlib elf/stringtable.o MODULE_NAME=nonlib io/pwd io/pwd.o MODULE_NAME=nonlib locale/locale locale/locale.o MODULE_NAME=locale_programs locale/locale-spec.o MODULE_NAME=locale_programs locale/charmap-dir.o MODULE_NAME=locale_programs locale/simple-hash.o MODULE_NAME=locale_programs locale/xmalloc.o MODULE_NAME=locale_programs locale/xstrdup.o MODULE_NAME=locale_programs locale/record-status.o MODULE_NAME=locale_programs locale/xasprintf.o MODULE_NAME=locale_programs locale/localedef locale/localedef.o MODULE_NAME=locale_programs locale/ld-ctype.o MODULE_NAME=locale_programs locale/ld-messages.o MODULE_NAME=locale_programs locale/ld-monetary.o MODULE_NAME=locale_programs locale/ld-numeric.o MODULE_NAME=locale_programs locale/ld-time.o MODULE_NAME=locale_programs locale/ld-paper.o MODULE_NAME=locale_programs locale/ld-name.o MODULE_NAME=locale_programs locale/ld-address.o MODULE_NAME=locale_programs locale/ld-telephone.o MODULE_NAME=locale_programs locale/ld-measurement.o MODULE_NAME=locale_programs locale/ld-identification.o MODULE_NAME=locale_programs locale/ld-collate.o MODULE_NAME=locale_programs locale/charmap.o MODULE_NAME=locale_programs locale/linereader.o MODULE_NAME=locale_programs locale/locfile.o MODULE_NAME=locale_programs locale/repertoire.o MODULE_NAME=locale_programs locale/locarchive.o MODULE_NAME=locale_programs locale/md5.o MODULE_NAME=locale_programs locale/charmap-dir.o MODULE_NAME=locale_programs locale/simple-hash.o MODULE_NAME=locale_programs locale/xmalloc.o MODULE_NAME=locale_programs locale/xstrdup.o MODULE_NAME=locale_programs locale/record-status.o MODULE_NAME=locale_programs locale/xasprintf.o MODULE_NAME=locale_programs catgets/gencat catgets/gencat.o MODULE_NAME=nonlib catgets/xmalloc.o MODULE_NAME=nonlib nss/makedb nss/makedb.o MODULE_NAME=nonlib nss/xmalloc.o MODULE_NAME=nonlib nss/hash-string.o MODULE_NAME=nonlib nss/getent nss/getent.o MODULE_NAME=nonlib posix/getconf posix/getconf.o MODULE_NAME=nonlib login/utmpdump login/utmpdump.o MODULE_NAME=nonlib debug/pcprofiledump debug/pcprofiledump.o MODULE_NAME=nonlib timezone/zic timezone/zic.o MODULE_NAME=nonlib timezone/zdump timezone/zdump.o MODULE_NAME=nonlib iconv/iconv_prog iconv/iconv_prog.o MODULE_NAME=nonlib iconv/iconv_charmap.o MODULE_NAME=iconvprogs iconv/charmap.o MODULE_NAME=iconvprogs iconv/charmap-dir.o MODULE_NAME=iconvprogs iconv/linereader.o MODULE_NAME=iconvprogs iconv/dummy-repertoire.o MODULE_NAME=iconvprogs iconv/simple-hash.o MODULE_NAME=iconvprogs iconv/xstrdup.o MODULE_NAME=iconvprogs iconv/xmalloc.o MODULE_NAME=iconvprogs iconv/record-status.o MODULE_NAME=iconvprogs iconv/iconvconfig iconv/iconvconfig.o MODULE_NAME=nonlib iconv/strtab.o MODULE_NAME=iconvprogs iconv/xmalloc.o MODULE_NAME=iconvprogs iconv/hash-string.o MODULE_NAME=iconvprogs Also, to avoid addinf both LFS and 64 bit time support on internal tests they are moved to a newer 'testsuite-internal' module. It should be similar to 'nonlib' regarding internal definition and linking namespace. This patch also enables LFS and 64 bit support of libsupport container programs (echo-container, test-container, shell-container, and true-container). Checked on x86_64-linux-gnu and i686-linux-gnu. --- Makeconfig | 8 ++++++-- Makerules | 12 ++++++++++-- locale/localeinfo.h | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/Makeconfig b/Makeconfig index 6482a43025..de30ba3fa6 100644 --- a/Makeconfig +++ b/Makeconfig @@ -851,6 +851,10 @@ endif # -fno-math-errno. +extra-math-flags = $(if $(filter libm,$(in-module)),-fno-math-errno,-fmath-errno) +# Use 64 bit time_t support for installed programs ++extra-time-flags = $(if $(filter nonlib nscd lddlibc4 ldconfig locale_programs iconvprogs,\ + $(in-module)),-D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64) + # We might want to compile with some stack-protection flag. ifneq ($(stack-protector),) +stack-protector=$(stack-protector) @@ -951,7 +955,7 @@ libio-include = -I$(..)libio built-modules = iconvprogs iconvdata ldconfig lddlibc4 libmemusage \ libSegFault libpcprofile librpcsvc locale-programs \ memusagestat nonlib nscd extramodules libnldbl libsupport \ - testsuite + testsuite testsuite-internal in-module = $(subst -,_,$(firstword $(libof-$(basename $(@F))) \ $(libof-$( X-Patchwork-Id: 1493402 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=EVbR9f+E; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4G5L8Q1Vx9z9sRK for ; Thu, 17 Jun 2021 21:55:02 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DAFC1389367E for ; Thu, 17 Jun 2021 11:54:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DAFC1389367E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1623930899; bh=IY/eSK2jBnjs4KtMf2C3DPx3Q/TGZauuULn29pOerJw=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=EVbR9f+EMlTQaw6kUfKXHAnQ1vzPxZkiyc0iYQDwtEk15ugsItPKoKWXFUwurxA8i kKpcGv4ppn0Kuu1P/0Qwy1ZYdUOqevxMBPrwPuAzcL4Czxd3c7x1uiGcIRVWLXBCuB kFNehWJrel+6aus0sI7htyfcqh5lrrgxb6IgujDU= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x72f.google.com (mail-qk1-x72f.google.com [IPv6:2607:f8b0:4864:20::72f]) by sourceware.org (Postfix) with ESMTPS id 6BF4C3894411 for ; Thu, 17 Jun 2021 11:51:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6BF4C3894411 Received: by mail-qk1-x72f.google.com with SMTP id g4so1528288qkl.1 for ; Thu, 17 Jun 2021 04:51:15 -0700 (PDT) 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:mime-version:content-transfer-encoding; bh=IY/eSK2jBnjs4KtMf2C3DPx3Q/TGZauuULn29pOerJw=; b=Hy+xCeCrW11JI84yVBQnRAUmFRlZEw59Y4neod/g5N7rTUHc70dWqjLnohTiPzMSK6 VqcrbsJxyTb3zp9LtEIcqEy84nVh2q+dXesYfXVtUqd8I6FLn8Oume1g+udyYalD4tCD R4QttBgZDcQ0KukG6BAZjQVErMM47wiXAbohFL4/B5biWkOtl/4nJ/X4JyvwdCtUvnWE ety0bLR2AV1DLfPa6JTFn1wYpf1GD9LJfwSMe9oFNHEzd6/RTsSkfLBGs79ludzQ89dk UtVdGlLnFtQ/f0XFOhRvGMeuWkQqr5lY+POc7XWK+Uz1ceiBBp8f9qDNwzJUyzS3sj22 DZYA== X-Gm-Message-State: AOAM532PtxHeyAIr+bNXSuKuKnY62ZYNxUMVmFFxqm+Zral02NcnxAtJ J42KfDzihvfooAQAPvvicrUh+aSTFRdDYg== X-Google-Smtp-Source: ABdhPJze6eRtNR3HiY9ZiQt5hwzpyPKYtze0sK4mQZttgNKBtaaqxdnmEkGyi8E4v7+7g7MFF3thZA== X-Received: by 2002:ae9:e512:: with SMTP id w18mr3329072qkf.281.1623930674893; Thu, 17 Jun 2021 04:51:14 -0700 (PDT) Received: from birita.. ([177.194.59.218]) by smtp.googlemail.com with ESMTPSA id p12sm3016435qtw.61.2021.06.17.04.51.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 04:51:14 -0700 (PDT) To: libc-alpha@sourceware.org, Lukasz Majewski , Carlos O'Donell Subject: [PATCH 03/18] support: Add support_create_timer Date: Thu, 17 Jun 2021 08:50:49 -0300 Message-Id: <20210617115104.1359598-4-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210617115104.1359598-1-adhemerval.zanella@linaro.org> References: <20210617115104.1359598-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" It is a simple wrapper over timer_create, timer_settime, and sigaction. It will be used to check for large timeout to trigger an EINTR. Reviewed-by: Lukasz Majewski --- support/Makefile | 1 + support/support.h | 11 ++++++ support/support_create_timer.c | 69 ++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 support/support_create_timer.c diff --git a/support/Makefile b/support/Makefile index f3ebaa8d2e..278f4627d8 100644 --- a/support/Makefile +++ b/support/Makefile @@ -50,6 +50,7 @@ libsupport-routines = \ support_chroot \ support_copy_file \ support_copy_file_range \ + support_create_timer \ support_descriptor_supports_holes \ support_descriptors \ support_enter_mount_namespace \ diff --git a/support/support.h b/support/support.h index 874204b7fc..9ec8ecb8d7 100644 --- a/support/support.h +++ b/support/support.h @@ -24,6 +24,7 @@ #define SUPPORT_H #include +#include #include #include /* For mode_t. */ @@ -153,6 +154,16 @@ extern bool support_select_modifies_timeout (void); tv_usec larger than 1000000. */ extern bool support_select_normalizes_timeout (void); +/* Create a timer that trigger after SEC seconds and NSEC nanoseconds. If + REPEAT is true the timer will repeat indefinitely. If CALLBACK is not + NULL, the function will be called when the timer expires; otherwise a + dummy empty function is used instead. + This is implemented with POSIX per-process timer with SIGEV_SIGNAL. */ +timer_t support_create_timer (uint64_t sec, long int nsec, bool repeat, + void (*callback)(int)); +/* Disable the timer TIMER. */ +void support_delete_timer (timer_t timer); + __END_DECLS #endif /* SUPPORT_H */ diff --git a/support/support_create_timer.c b/support/support_create_timer.c new file mode 100644 index 0000000000..c93aaa5c6b --- /dev/null +++ b/support/support_create_timer.c @@ -0,0 +1,69 @@ +/* Create a periodic timer. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include + +static void +dummy_alrm_handler (int sig) +{ +} + +timer_t +support_create_timer (uint64_t sec, long int nsec, bool repeat, + void (*callback)(int)) +{ + struct sigaction sa; + sa.sa_handler = callback != NULL ? callback : dummy_alrm_handler; + sigemptyset (&sa.sa_mask); + sa.sa_flags = 0; + xsigaction (SIGALRM, &sa, NULL); + + struct sigevent ev = { + .sigev_notify = SIGEV_SIGNAL, + .sigev_signo = SIGALRM + }; + timer_t timerid; + int r = timer_create (CLOCK_REALTIME, &ev, &timerid); + if (r == -1) + FAIL_EXIT1 ("timer_create: %m"); + + /* Single timer with 0.1s. */ + struct itimerspec its = + { + { .tv_sec = repeat ? sec : 0, .tv_nsec = repeat ? nsec : 0 }, + { .tv_sec = sec, .tv_nsec = nsec } + }; + r = timer_settime (timerid, 0, &its, NULL); + if (r == -1) + FAIL_EXIT1 ("timer_settime: %m"); + + return timerid; +} + +/* Disable the timer TIMER. */ +void +support_delete_timer (timer_t timer) +{ + int r = timer_delete (timer); + if (r == -1) + FAIL_EXIT1 ("timer_delete: %m"); + xsignal (SIGALRM, SIG_DFL); +} From patchwork Thu Jun 17 11:50:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 1493405 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=ZuRI4ZDX; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4G5LB6632kz9sRK for ; Thu, 17 Jun 2021 21:56:30 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 030C03894411 for ; Thu, 17 Jun 2021 11:56:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 030C03894411 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1623930988; bh=9hwRRQ+oYtjo5ntqKEDWt0n6fU+ysZXUF+z91Sm8NMA=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=ZuRI4ZDX3MfIOD5Yt+Qyv2yOikaofkeg3Lu+v6D+q0wT7y/oSJTVN3wu6Rk+1qAmB byfl0MLkH8QV+hXdtgpzYGVp3GPSwaRIVnOWT43UpTLEIAcRiyLNk1pC+iZxMI+MnU j4BdZJJCmDm0RQHhYfspKqqKlW2TnngQJj8djBDI= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x733.google.com (mail-qk1-x733.google.com [IPv6:2607:f8b0:4864:20::733]) by sourceware.org (Postfix) with ESMTPS id 0B2E73893C56 for ; Thu, 17 Jun 2021 11:51:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0B2E73893C56 Received: by mail-qk1-x733.google.com with SMTP id 5so2754499qkc.8 for ; Thu, 17 Jun 2021 04:51:17 -0700 (PDT) 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:mime-version:content-transfer-encoding; bh=9hwRRQ+oYtjo5ntqKEDWt0n6fU+ysZXUF+z91Sm8NMA=; b=EB0I2Ydl1x0vulcxrmwvekjFqV/eU/wGU32hHgeTBwInBt7at5u3UoBCNc/zJz5Ju5 Cv0OkucbimbGXjo4V4hyfyJ7VRY5KLgbfwGPTVR8U2wAq5gmTTPwvmMl0qWrp28ORz3C 5e4zcWtE6n/cix0UBrsT80Dj0S+5DzjKhB8VDLyYZWcTnuj24u5xbPDNcTDb3yGoIWuM VpVXg6hWoa0uqh4e8tmnJOYnKyOW068vhmB4dddnbaYkq6iIqcXBwfSov+4a1PPMojoY 1HZ6dV1f35RjV2RxSqSi4eF71ARciif4DiduYM5+jOH3m3871MV+5OGNL9gm8sWVghsD 78ug== X-Gm-Message-State: AOAM531SYW90RF52uWkbhRAPyVuX5R3vNtcxamFEnNyNQAc95tvFMf0n eenqh4+B2ZZFgpMJM9Zs73kw3/SuC29PxA== X-Google-Smtp-Source: ABdhPJxqt73V/Dl9luBLeUEip59KOzhJpBFulbHl83R+GOqX9agVXjWgGHz93vz8dgKR5Cu6BHjfRw== X-Received: by 2002:a37:e53:: with SMTP id 80mr3382372qko.187.1623930676465; Thu, 17 Jun 2021 04:51:16 -0700 (PDT) Received: from birita.. ([177.194.59.218]) by smtp.googlemail.com with ESMTPSA id p12sm3016435qtw.61.2021.06.17.04.51.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 04:51:16 -0700 (PDT) To: libc-alpha@sourceware.org, Lukasz Majewski , Carlos O'Donell Subject: [PATCH 04/18] linux: Only use 64-bit syscall if required for ppoll Date: Thu, 17 Jun 2021 08:50:50 -0300 Message-Id: <20210617115104.1359598-5-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210617115104.1359598-1-adhemerval.zanella@linaro.org> References: <20210617115104.1359598-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" For !__ASSUME_TIME64_SYSCALLS there is no need to issue a 64-bit syscall if the provided timeout fits in a 32-bit one. The 64-bit usage should be rare since the timeout is a relative one. This also avoids the need to use supports_time64() (which breaks the usage case of live migration like CRIU or similar). Checked on i686-linux-gnu on a 4.15 kernel and on a 5.11 kernel (with and without --enable-kernel=5.1) and on x86_64-linux-gnu. Reviewed-by: Lukasz Majewski --- sysdeps/unix/sysv/linux/Makefile | 9 +++++++ sysdeps/unix/sysv/linux/ppoll.c | 41 +++++++++++------------------ sysdeps/unix/sysv/linux/tst-ppoll.c | 15 +++++++++++ 3 files changed, 40 insertions(+), 25 deletions(-) diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index 294c366e3b..c36ea0e494 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -137,6 +137,15 @@ tests-time64 += \ CFLAGS-tst-sigcontext-get_pc.c = -fasynchronous-unwind-tables +ifeq (yes,$(build-shared)) +librt = $(common-objpfx)rt/librt.so +else +librt = $(common-objpfx)rt/librt.a +endif + +$(objpfx)tst-ppoll: $(librt) +$(objpfx)tst-ppoll-time64: $(librt) + # Generate the list of SYS_* macros for the system calls (__NR_* # macros). The file syscall-names.list contains all possible system # call names, and the generated header file produces SYS_* macros for diff --git a/sysdeps/unix/sysv/linux/ppoll.c b/sysdeps/unix/sysv/linux/ppoll.c index 624f14f517..e1ad316e2e 100644 --- a/sysdeps/unix/sysv/linux/ppoll.c +++ b/sysdeps/unix/sysv/linux/ppoll.c @@ -21,9 +21,6 @@ #include #include #include -#include -#include - int __ppoll64 (struct pollfd *fds, nfds_t nfds, const struct __timespec64 *timeout, @@ -38,40 +35,34 @@ __ppoll64 (struct pollfd *fds, nfds_t nfds, const struct __timespec64 *timeout, timeout = &tval; } - int ret; - - if (supports_time64 ()) - { #ifndef __NR_ppoll_time64 # define __NR_ppoll_time64 __NR_ppoll #endif + +#ifdef __ASSUME_TIME64_SYSCALLS + return SYSCALL_CANCEL (ppoll_time64, fds, nfds, timeout, sigmask, + __NSIG_BYTES); +#else + bool is32bit = timeout != NULL + ? in_time_t_range (timeout->tv_sec) : true; + int ret; + if (!is32bit) + { ret = SYSCALL_CANCEL (ppoll_time64, fds, nfds, timeout, sigmask, __NSIG_BYTES); - if (ret == 0 || errno != ENOSYS) return ret; - - mark_time64_unsupported (); + __set_errno (EOVERFLOW); + return -1; } -#ifndef __ASSUME_TIME64_SYSCALLS struct timespec ts32; - if (timeout) - { - if (! in_time_t_range (timeout->tv_sec)) - { - __set_errno (EOVERFLOW); - return -1; - } - - ts32 = valid_timespec64_to_timespec (*timeout); - } + if (timeout != NULL) + ts32 = valid_timespec64_to_timespec (*timeout); - ret = SYSCALL_CANCEL (ppoll, fds, nfds, timeout ? &ts32 : NULL, sigmask, - __NSIG_BYTES); + return SYSCALL_CANCEL (ppoll, fds, nfds, timeout ? &ts32 : NULL, sigmask, + __NSIG_BYTES); #endif - - return ret; } #if __TIMESIZE != 64 diff --git a/sysdeps/unix/sysv/linux/tst-ppoll.c b/sysdeps/unix/sysv/linux/tst-ppoll.c index 9fe6ad07ce..e21e2fcc72 100644 --- a/sysdeps/unix/sysv/linux/tst-ppoll.c +++ b/sysdeps/unix/sysv/linux/tst-ppoll.c @@ -19,9 +19,11 @@ #include #include #include +#include #include #include #include +#include #include static int test_ppoll_timeout (bool zero_tmo) @@ -41,6 +43,16 @@ static int test_ppoll_timeout (bool zero_tmo) return 0; } +static void +test_ppoll_large_timeout (void) +{ + support_create_timer (0, 100000000, false, NULL); + struct timespec ts = { TYPE_MAXIMUM (time_t), 0 }; + struct pollfd fds = { -1, 0, 0 }; + TEST_COMPARE (ppoll (&fds, 1, &ts, 0), -1); + TEST_VERIFY (errno == EINTR || errno == EOVERFLOW); +} + static int do_test (void) { @@ -50,6 +62,9 @@ do_test (void) /* Check if ppoll exits after specified timeout. */ test_ppoll_timeout (false); + /* Check if ppoll with large timeout. */ + test_ppoll_large_timeout (); + return 0; } From patchwork Thu Jun 17 11:50:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 1493403 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=suQokwUd; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4G5L9G1wr4z9sRK for ; Thu, 17 Jun 2021 21:55:46 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 11E413896C03 for ; Thu, 17 Jun 2021 11:55:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 11E413896C03 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1623930944; bh=y7lgduzDHGHJDqB2CtyXV6ZAiND8IVp+3qRksuODL8w=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=suQokwUdPdYGhmD0EeRWt+eCs3TvWXW6bCc+CtvLYta+qFO3PmQp01l6uqEY8kj2l n8bslsQOYDi1Alq2vmPhQwYz222csAHei7V+0oqn1rcSamOIGgg/WlSHRojnOudw1j QrkPhYjDr5NgMmzkvqMKRTHrPZZXvX98aO2f57CQ= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x731.google.com (mail-qk1-x731.google.com [IPv6:2607:f8b0:4864:20::731]) by sourceware.org (Postfix) with ESMTPS id C2C793894430 for ; Thu, 17 Jun 2021 11:51:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C2C793894430 Received: by mail-qk1-x731.google.com with SMTP id g142so2770299qke.4 for ; Thu, 17 Jun 2021 04:51:18 -0700 (PDT) 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:mime-version:content-transfer-encoding; bh=y7lgduzDHGHJDqB2CtyXV6ZAiND8IVp+3qRksuODL8w=; b=HykSugU3MqzmXtsZf4nVv20iRKoEV0o6sqDYT4iJuBsFkG9+3zVXfbttgfnHma/7kc bCbHqFn7l0qUv+b4DcTRpXUl8VT4JU9k2WqSaiFpTFkS4L7IOID2rEDsLRd08YPYajRL FuN6+UaYqBLPtybxZ6XP91JMdaiv57Yxqy9MpuyE2ec/YrWBMJY7/sZTSFevQLWfHhZk d4F09aHp6UcecsUfuZae0D4h++nCFKujopnRLncHoq6Rkt3lyHOY5rKnmgmW77CVc5vA Jfr7B6oZ+mlXPb3Hy/i03ixDbD2TXuv2d23V0zcA8P8HmKhC7luk6rNwDhnVZS4BOQam 5Jvw== X-Gm-Message-State: AOAM530Itbgkt29/e+Q5SPmY0qVyVv217nrwUEpNianwW3dWibWl6YYC xKAzMmKgi/RuEl7LgEI6e8dph9elXEUEjw== X-Google-Smtp-Source: ABdhPJyPCXOVJR07C6k6x3XGtBfKeoctF/H+cpH76b1kUfpCLdna/94LMK+KSOSNuMud+8/ufkNSwg== X-Received: by 2002:a05:620a:1424:: with SMTP id k4mr3277461qkj.299.1623930678081; Thu, 17 Jun 2021 04:51:18 -0700 (PDT) Received: from birita.. ([177.194.59.218]) by smtp.googlemail.com with ESMTPSA id p12sm3016435qtw.61.2021.06.17.04.51.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 04:51:17 -0700 (PDT) To: libc-alpha@sourceware.org, Lukasz Majewski , Carlos O'Donell Subject: [PATCH 05/18] linux: Only use 64-bit syscall if required for pselect Date: Thu, 17 Jun 2021 08:50:51 -0300 Message-Id: <20210617115104.1359598-6-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210617115104.1359598-1-adhemerval.zanella@linaro.org> References: <20210617115104.1359598-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" For !__ASSUME_TIME64_SYSCALLS there is no need to issue a 64-bit syscall if the provided timeout fits in a 32-bit one. The 64-bit usage should be rare since the timeout is a relative one. This also avoids the need to use supports_time64() (which breaks the usage case of live migration like CRIU or similar). Checked on i686-linux-gnu on a 4.15 kernel and on a 5.11 kernel (with and without --enable-kernel=5.1) and on x86_64-linux-gnu. Reviewed-by: Lukasz Majewski --- misc/Makefile | 9 ++ misc/tst-pselect.c | 120 ++++++++---------- .../unix/sysv/linux/microblaze/pselect32.c | 3 +- sysdeps/unix/sysv/linux/pselect.c | 47 ++++--- sysdeps/unix/sysv/linux/pselect32.c | 6 - 5 files changed, 95 insertions(+), 90 deletions(-) diff --git a/misc/Makefile b/misc/Makefile index f34ab09fe3..fa40bf0e11 100644 --- a/misc/Makefile +++ b/misc/Makefile @@ -148,6 +148,12 @@ CFLAGS-brk.op = $(no-stack-protector) include ../Rules +ifeq (yes,$(build-shared)) +librt = $(common-objpfx)rt/librt.so +else +librt = $(common-objpfx)rt/librt.a +endif + $(objpfx)libg.a: $(dep-dummy-lib); $(make-dummy-lib) $(objpfx)tst-tsearch: $(libm) @@ -162,3 +168,6 @@ tst-allocate_once-ENV = MALLOC_TRACE=$(objpfx)tst-allocate_once.mtrace $(objpfx)tst-allocate_once-mem.out: $(objpfx)tst-allocate_once.out $(common-objpfx)malloc/mtrace $(objpfx)tst-allocate_once.mtrace > $@; \ $(evaluate-test) + +$(objpfx)tst-pselect: $(librt) +$(objpfx)tst-pselect-time64: $(librt) diff --git a/misc/tst-pselect.c b/misc/tst-pselect.c index c89176b058..f8c404c275 100644 --- a/misc/tst-pselect.c +++ b/misc/tst-pselect.c @@ -16,14 +16,14 @@ . */ #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include - static volatile int handler_called; static void @@ -33,59 +33,43 @@ handler (int sig) } -static int -do_test (void) +static void +test_pselect_basic (void) { struct sigaction sa; sa.sa_handler = handler; sa.sa_flags = 0; sigemptyset (&sa.sa_mask); - if (sigaction (SIGUSR1, &sa, NULL) != 0) - { - puts ("sigaction failed"); - return 1; - } + xsigaction (SIGUSR1, &sa, NULL); sa.sa_handler = SIG_IGN; - if (sigaction (SIGCHLD, &sa, NULL) != 0) - { - puts ("2nd sigaction failed"); - return 1; - } + xsigaction (SIGCHLD, &sa, NULL); sigset_t ss_usr1; sigemptyset (&ss_usr1); sigaddset (&ss_usr1, SIGUSR1); - if (sigprocmask (SIG_BLOCK, &ss_usr1, NULL) != 0) - { - puts ("sigprocmask failed"); - return 1; - } + TEST_COMPARE (sigprocmask (SIG_BLOCK, &ss_usr1, NULL), 0); int fds[2][2]; - - if (pipe (fds[0]) != 0 || pipe (fds[1]) != 0) - { - puts ("pipe failed"); - return 1; - } + xpipe (fds[0]); + xpipe (fds[1]); fd_set rfds; FD_ZERO (&rfds); sigset_t ss; - sigprocmask (SIG_SETMASK, NULL, &ss); + TEST_COMPARE (sigprocmask (SIG_SETMASK, NULL, &ss), 0); sigdelset (&ss, SIGUSR1); struct timespec to = { .tv_sec = 0, .tv_nsec = 500000000 }; pid_t parent = getpid (); - pid_t p = fork (); + pid_t p = xfork (); if (p == 0) { - close (fds[0][1]); - close (fds[1][0]); + xclose (fds[0][1]); + xclose (fds[1][0]); FD_SET (fds[0][0], &rfds); @@ -93,55 +77,63 @@ do_test (void) do { if (getppid () != parent) - exit (2); + FAIL_EXIT1 ("getppid()=%d != parent=%d", getppid(), parent); errno = 0; e = pselect (fds[0][0] + 1, &rfds, NULL, NULL, &to, &ss); } while (e == 0); - if (e != -1) - { - puts ("child: pselect did not fail"); - return 0; - } - if (errno != EINTR) - { - puts ("child: pselect did not set errno to EINTR"); - return 0; - } + TEST_COMPARE (e, -1); + TEST_COMPARE (errno, EINTR); TEMP_FAILURE_RETRY (write (fds[1][1], "foo", 3)); exit (0); } - close (fds[0][0]); - close (fds[1][1]); + xclose (fds[0][0]); + xclose (fds[1][1]); FD_SET (fds[1][0], &rfds); - kill (p, SIGUSR1); + TEST_COMPARE (kill (p, SIGUSR1), 0); int e = pselect (fds[1][0] + 1, &rfds, NULL, NULL, NULL, &ss); - if (e == -1) - { - puts ("parent: pselect failed"); - return 1; - } - if (e != 1) - { - puts ("parent: pselect did not report readable fd"); - return 1; - } - if (!FD_ISSET (fds[1][0], &rfds)) - { - puts ("parent: pselect reports wrong fd"); - return 1; - } + TEST_COMPARE (e, 1); + TEST_VERIFY (FD_ISSET (fds[1][0], &rfds)); +} + +static void +test_pselect_large_timeout (void) +{ + support_create_timer (0, 100000000, false, NULL); + + int fds[2]; + xpipe (fds); + + fd_set rfds; + FD_ZERO (&rfds); + FD_SET (fds[0], &rfds); + + sigset_t ss; + TEST_COMPARE (sigprocmask (SIG_SETMASK, NULL, &ss), 0); + sigdelset (&ss, SIGALRM); + + struct timespec ts = { TYPE_MAXIMUM (time_t), 0 }; + + TEST_COMPARE (pselect (fds[0] + 1, &rfds, NULL, NULL, &ts, &ss), -1); + TEST_VERIFY (errno == EINTR || errno == EOVERFLOW); +} + +static int +do_test (void) +{ + test_pselect_basic (); + + test_pselect_large_timeout (); return 0; } -#define TEST_FUNCTION do_test () -#include "../test-skeleton.c" +#include diff --git a/sysdeps/unix/sysv/linux/microblaze/pselect32.c b/sysdeps/unix/sysv/linux/microblaze/pselect32.c index a4f436462b..70b7b52a48 100644 --- a/sysdeps/unix/sysv/linux/microblaze/pselect32.c +++ b/sysdeps/unix/sysv/linux/microblaze/pselect32.c @@ -35,8 +35,7 @@ __pselect32 (int nfds, fd_set *readfds, fd_set *writefds, struct timeval tv32, *ptv32 = NULL; if (timeout != NULL) { - if (! in_time_t_range (timeout->tv_sec) - || ! valid_nanoseconds (timeout->tv_nsec)) + if (! valid_nanoseconds (timeout->tv_nsec)) { __set_errno (EINVAL); return -1; diff --git a/sysdeps/unix/sysv/linux/pselect.c b/sysdeps/unix/sysv/linux/pselect.c index 5e8a0cc2dc..79e8584ea7 100644 --- a/sysdeps/unix/sysv/linux/pselect.c +++ b/sysdeps/unix/sysv/linux/pselect.c @@ -18,7 +18,23 @@ #include #include -#include + +static int +pselect64_syscall (int nfds, fd_set *readfds, fd_set *writefds, + fd_set *exceptfds, const struct __timespec64 *timeout, + const sigset_t *sigmask) +{ +#ifndef __NR_pselect6_time64 +# define __NR_pselect6_time64 __NR_pselect6 +#endif + /* NB: This is required by ARGIFY used in x32 internal_syscallN. */ + __syscall_ulong_t data[2] = + { + (uintptr_t) sigmask, __NSIG_BYTES + }; + return SYSCALL_CANCEL (pselect6_time64, nfds, readfds, writefds, exceptfds, + timeout, data); +} int __pselect64 (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, @@ -37,30 +53,25 @@ __pselect64 (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, we can only pass in 6 directly. If there is an architecture with support for more parameters a new version of this file needs to be created. */ - -#ifndef __NR_pselect6_time64 -# define __NR_pselect6_time64 __NR_pselect6 -#endif +#ifdef __ASSUME_TIME64_SYSCALLS + return pselect64_syscall (nfds, readfds, writefds, exceptfds, timeout, + sigmask); +#else + bool is32bit = timeout != NULL + ? in_time_t_range (timeout->tv_sec) : true; int r; - if (supports_time64 ()) + if (!is32bit) { - /* NB: This is required by ARGIFY used in x32 internal_syscallN. */ - __syscall_ulong_t data[2] = - { - (uintptr_t) sigmask, __NSIG_BYTES - }; - r = SYSCALL_CANCEL (pselect6_time64, nfds, readfds, writefds, exceptfds, - timeout, data); + r = pselect64_syscall (nfds, readfds, writefds, exceptfds, timeout, + sigmask); if (r == 0 || errno != ENOSYS) return r; - - mark_time64_unsupported (); + __set_errno (EOVERFLOW); + return -1; } -#ifndef __ASSUME_TIME64_SYSCALLS - r = __pselect32 (nfds, readfds, writefds, exceptfds, timeout, sigmask); + return __pselect32 (nfds, readfds, writefds, exceptfds, timeout, sigmask); #endif - return r; } #if __TIMESIZE != 64 diff --git a/sysdeps/unix/sysv/linux/pselect32.c b/sysdeps/unix/sysv/linux/pselect32.c index eb59b51cdf..48724d8727 100644 --- a/sysdeps/unix/sysv/linux/pselect32.c +++ b/sysdeps/unix/sysv/linux/pselect32.c @@ -29,12 +29,6 @@ __pselect32 (int nfds, fd_set *readfds, fd_set *writefds, struct timespec ts32, *pts32 = NULL; if (timeout != NULL) { - if (! in_time_t_range (timeout->tv_sec)) - { - __set_errno (EINVAL); - return -1; - } - ts32 = valid_timespec64_to_timespec (*timeout); pts32 = &ts32; } From patchwork Thu Jun 17 11:50:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 1493410 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=WSRn0sUj; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4G5LCw23SYz9sT6 for ; Thu, 17 Jun 2021 21:58:04 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CE56D3896C01 for ; Thu, 17 Jun 2021 11:58:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CE56D3896C01 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1623931081; bh=jRnlhPN7jVrO6IREM3pYqysSDKBpHiTb5IAyqSjB9VU=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=WSRn0sUjXNBY0vc9kWZrk5KMg5RWDwIk+fh2YYh9lyj594+5Xm9VXe8iiqs+F0H+G QParucywhFiSLTUeKxAYwGAYT3xRS5ozoNZ6ROBh0rAzR74B3CgCN0eI+7zGOhWZFn YlFVM812jBHOU9U5Zy6JqkB9Gowya8kceJB7/OKA= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qv1-xf2c.google.com (mail-qv1-xf2c.google.com [IPv6:2607:f8b0:4864:20::f2c]) by sourceware.org (Postfix) with ESMTPS id 51EC0389441F for ; Thu, 17 Jun 2021 11:51:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 51EC0389441F Received: by mail-qv1-xf2c.google.com with SMTP id ct13so1259632qvb.12 for ; Thu, 17 Jun 2021 04:51:20 -0700 (PDT) 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:mime-version:content-transfer-encoding; bh=jRnlhPN7jVrO6IREM3pYqysSDKBpHiTb5IAyqSjB9VU=; b=l+t518kWZwSKnuX0wKGMHhpgu8NYt590J6ymgqYeP0CVPt/zZl9BENAyS5+LNN7Wb1 8pUuKztiirSqhOM+ZWwQDVyYzPKONlYcF4crLr0Xr9EZTh6mfLzD4/xJTNBPoNUNOZvn aHE1tq7ocQxyxgZ/xm9NoIkZPyAl+nPZ5mxLh/wdqz3KYJdgsVcKz3JvaNc1vGgPFpsY zwUNYfiy3I8OxsUM94xqUfvNyaQ0vYUVejKC/VtW4XwnP4SZ6fiPoLeVuvrsanLdbRQM RxmQ3ui30bpck7nXbJ79xuQJAak6GdPiyrDpEkI2gTN5eWxLss4hUR2g9MK7W9YdGhuE guJA== X-Gm-Message-State: AOAM532pGyqr/A1+9j9/3pFXHceaooi5gqXEd3o2D/elKlLROcMXeHd9 fIUn5/NZC1fiBxw4Fm1131mmj24aKq0tYQ== X-Google-Smtp-Source: ABdhPJzuXRZPUibVEuxqQKQ8Lg0Vjr0RDDtyBMQL56DI+o3t1EaW1yAuAO7WVIEutfkdHCwDxqWjfA== X-Received: by 2002:ad4:5561:: with SMTP id w1mr5529667qvy.47.1623930679737; Thu, 17 Jun 2021 04:51:19 -0700 (PDT) Received: from birita.. ([177.194.59.218]) by smtp.googlemail.com with ESMTPSA id p12sm3016435qtw.61.2021.06.17.04.51.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 04:51:19 -0700 (PDT) To: libc-alpha@sourceware.org, Lukasz Majewski , Carlos O'Donell Subject: [PATCH 06/18] linux: Only use 64-bit syscall if required for select Date: Thu, 17 Jun 2021 08:50:52 -0300 Message-Id: <20210617115104.1359598-7-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210617115104.1359598-1-adhemerval.zanella@linaro.org> References: <20210617115104.1359598-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" For !__ASSUME_TIME64_SYSCALLS there is no need to issue a 64-bit syscall if the provided timeout fits in a 32-bit one. The 64-bit usage should be rare since the timeout is a relative one. This also avoids the need to use supports_time64() (which breaks the usage case of live migration like CRIU or similar). It also fixes an issue on 32-bit select call for !__ASSUME_PSELECT (microblase with older kernels only) where the expected timeout is a 'struct timeval' instead of 'struct timespec'. Checked on i686-linux-gnu on a 4.15 kernel and on a 5.11 kernel (with and without --enable-kernel=5.1) and on x86_64-linux-gnu. Reviewed-by: Lukasz Majewski --- include/sys/select.h | 5 +++ misc/Makefile | 2 + misc/tst-select.c | 39 +++++++++++-------- sysdeps/unix/sysv/linux/Makefile | 2 +- sysdeps/unix/sysv/linux/select.c | 60 ++++++++++-------------------- sysdeps/unix/sysv/linux/select32.c | 58 +++++++++++++++++++++++++++++ 6 files changed, 109 insertions(+), 57 deletions(-) create mode 100644 sysdeps/unix/sysv/linux/select32.c diff --git a/include/sys/select.h b/include/sys/select.h index ec073deeba..a8961afbed 100644 --- a/include/sys/select.h +++ b/include/sys/select.h @@ -21,6 +21,11 @@ extern int __pselect32 (int __nfds, fd_set *__readfds, const struct __timespec64 *__timeout, const __sigset_t *__sigmask) attribute_hidden; +extern int __select32 (int __nfds, fd_set *__readfds, + fd_set *__writefds, fd_set *__exceptfds, + const struct __timespec64 *ts64, + struct __timeval64 *timeout) + attribute_hidden; extern int __select64 (int __nfds, fd_set *__readfds, fd_set *__writefds, fd_set *__exceptfds, diff --git a/misc/Makefile b/misc/Makefile index fa40bf0e11..66586bcc7e 100644 --- a/misc/Makefile +++ b/misc/Makefile @@ -169,5 +169,7 @@ $(objpfx)tst-allocate_once-mem.out: $(objpfx)tst-allocate_once.out $(common-objpfx)malloc/mtrace $(objpfx)tst-allocate_once.mtrace > $@; \ $(evaluate-test) +$(objpfx)tst-select: $(librt) +$(objpfx)tst-select-time64: $(librt) $(objpfx)tst-pselect: $(librt) $(objpfx)tst-pselect-time64: $(librt) diff --git a/misc/tst-select.c b/misc/tst-select.c index 52aa26651f..134eed99be 100644 --- a/misc/tst-select.c +++ b/misc/tst-select.c @@ -17,6 +17,7 @@ . */ #include +#include #include #include #include @@ -31,12 +32,6 @@ struct child_args struct timeval tmo; }; -static void -alarm_handler (int signum) -{ - /* Do nothing. */ -} - static void do_test_child (void *clousure) { @@ -69,17 +64,20 @@ do_test_child (void *clousure) static void do_test_child_alarm (void *clousure) { - struct sigaction act = { .sa_handler = alarm_handler }; - xsigaction (SIGALRM, &act, NULL); - alarm (1); + struct child_args *args = (struct child_args *) clousure; - struct timeval tv = { .tv_sec = 10, .tv_usec = 0 }; + support_create_timer (0, 100000000, false, NULL); + struct timeval tv = { .tv_sec = args->tmo.tv_sec, .tv_usec = 0 }; int r = select (0, NULL, NULL, NULL, &tv); TEST_COMPARE (r, -1); - TEST_COMPARE (errno, EINTR); - - if (support_select_modifies_timeout ()) - TEST_VERIFY (tv.tv_sec < 10); + if (args->tmo.tv_sec > INT_MAX) + TEST_VERIFY (errno == EINTR || errno == EOVERFLOW); + else + { + TEST_COMPARE (errno, EINTR); + if (support_select_modifies_timeout ()) + TEST_VERIFY (tv.tv_sec < args->tmo.tv_sec); + } } static int @@ -121,13 +119,24 @@ do_test (void) xclose (args.fds[0][0]); xclose (args.fds[1][1]); + args.tmo = (struct timeval) { .tv_sec = 10, .tv_usec = 0 }; + { + struct support_capture_subprocess result; + result = support_capture_subprocess (do_test_child_alarm, &args); + support_capture_subprocess_check (&result, "tst-select-child", 0, + sc_allow_none); + } + + args.tmo = (struct timeval) { .tv_sec = TYPE_MAXIMUM (time_t), + .tv_usec = 0 }; { struct support_capture_subprocess result; - result = support_capture_subprocess (do_test_child_alarm, NULL); + result = support_capture_subprocess (do_test_child_alarm, &args); support_capture_subprocess_check (&result, "tst-select-child", 0, sc_allow_none); } + args.tmo = (struct timeval) { .tv_sec = 0, .tv_usec = 0 }; { fd_set rfds; FD_ZERO (&rfds); diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index c36ea0e494..710169a454 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -61,7 +61,7 @@ sysdep_routines += adjtimex clone umount umount2 readahead sysctl \ open_by_handle_at mlock2 pkey_mprotect pkey_set pkey_get \ timerfd_gettime timerfd_settime prctl \ process_vm_readv process_vm_writev clock_adjtime \ - time64-support pselect32 \ + time64-support pselect32 select32 \ xstat fxstat lxstat xstat64 fxstat64 lxstat64 \ fxstatat fxstatat64 \ xmknod xmknodat convert_scm_timestamps diff --git a/sysdeps/unix/sysv/linux/select.c b/sysdeps/unix/sysv/linux/select.c index dc16a816ed..2d2a7fa720 100644 --- a/sysdeps/unix/sysv/linux/select.c +++ b/sysdeps/unix/sysv/linux/select.c @@ -21,7 +21,6 @@ #include #include #include -#include /* Check the first NFDS descriptors each in READFDS (if not NULL) for read readiness, in WRITEFDS (if not NULL) for write readiness, and in EXCEPTFDS @@ -65,53 +64,32 @@ __select64 (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, #ifndef __NR_pselect6_time64 # define __NR_pselect6_time64 __NR_pselect6 #endif + +#ifdef __ASSUME_TIME64_SYSCALLS + int r = SYSCALL_CANCEL (pselect6_time64, nfds, readfds, writefds, exceptfds, + pts64, NULL); + if (timeout != NULL) + TIMESPEC_TO_TIMEVAL (timeout, pts64); + return r; +#else + bool is32bit = timeout != NULL + ? in_time_t_range (timeout->tv_sec) : true; int r; - if (supports_time64 ()) + if (!is32bit) { - r = SYSCALL_CANCEL (pselect6_time64, nfds, readfds, writefds, exceptfds, - pts64, NULL); - /* Linux by default will update the timeout after a pselect6 syscall - (though the pselect() glibc call suppresses this behavior). - Since select() on Linux has the same behavior as the pselect6 - syscall, we update the timeout here. */ - if (r >= 0 || errno != ENOSYS) + r = SYSCALL_CANCEL (pselect6_time64, nfds, readfds, writefds, + exceptfds, pts64, NULL); + if ((r >= 0 || errno != ENOSYS) && timeout != NULL) { - if (timeout != NULL) - TIMESPEC_TO_TIMEVAL (timeout, &ts64); - return r; + TIMESPEC_TO_TIMEVAL (timeout, &ts64); } - - mark_time64_unsupported (); + else + __set_errno (EOVERFLOW); + return r; } -#ifndef __ASSUME_TIME64_SYSCALLS - struct timespec ts32, *pts32 = NULL; - if (pts64 != NULL) - { - if (! in_time_t_range (pts64->tv_sec)) - { - __set_errno (EINVAL); - return -1; - } - ts32.tv_sec = s; - ts32.tv_nsec = ns; - pts32 = &ts32; - } -# ifndef __ASSUME_PSELECT -# ifdef __NR__newselect -# undef __NR_select -# define __NR_select __NR__newselect -# endif - r = SYSCALL_CANCEL (select, nfds, readfds, writefds, exceptfds, pts32); -# else - r = SYSCALL_CANCEL (pselect6, nfds, readfds, writefds, exceptfds, pts32, - NULL); -# endif - if (timeout != NULL) - *timeout = valid_timespec_to_timeval64 (ts32); + return __select32 (nfds, readfds, writefds, exceptfds, pts64, timeout); #endif - - return r; } #if __TIMESIZE != 64 diff --git a/sysdeps/unix/sysv/linux/select32.c b/sysdeps/unix/sysv/linux/select32.c new file mode 100644 index 0000000000..b7e122fe2c --- /dev/null +++ b/sysdeps/unix/sysv/linux/select32.c @@ -0,0 +1,58 @@ +/* Synchronous I/O multiplexing. Linux 32-bit time fallback. + Copyright (C) 2020-2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include + +#ifndef __ASSUME_TIME64_SYSCALLS + +int +__select32 (int nfds, fd_set *readfds, fd_set *writefds, + fd_set *exceptfds, const struct __timespec64 *ts64, + struct __timeval64 *timeout) +{ +#ifdef __ASSUME_PSELECT + struct timespec ts32, *pts32 = NULL; + if (ts64 != NULL) + { + ts32.tv_sec = ts64->tv_sec; + ts32.tv_nsec = ts64->tv_nsec; + pts32 = &ts32; + } + + int r = SYSCALL_CANCEL (pselect6, nfds, readfds, writefds, exceptfds, pts32, + NULL); + if (timeout != NULL) + TIMESPEC_TO_TIMEVAL (timeout, pts32); + return r; +#else + struct timeval tv32, *ptv32 = NULL; + if (ts64 != NULL) + { + tv32 = valid_timespec64_to_timeval (*ts64); + ptv32 = &tv32; + } + + int r = SYSCALL_CANCEL (select, nfds, readfds, writefds, exceptfds, ptv32); + if (timeout != NULL) + *timeout = valid_timeval_to_timeval64 (tv32); + return r; +#endif /* __ASSUME_PSELECT */ +} + +#endif From patchwork Thu Jun 17 11:50:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 1493409 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=etCRMwLv; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4G5LC452V0z9sT6 for ; Thu, 17 Jun 2021 21:57:20 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E21B93894C0C for ; Thu, 17 Jun 2021 11:57:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E21B93894C0C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1623931037; bh=cw/wTvswUiMDXMrHMAZOh54EkS0QmC1YTIBIm0SpATI=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=etCRMwLvlaMFcjfTCKr9XqZYW/CrI4rBCdm3jygiW1g7qsOnVPFgp8qqjeggfNxX9 3gUWc0hDPTuR7sYKe5uShbcCjFyW1BiIJkJJbDjCk9fAOvAuuRLDd09Ki29xCzBa3B /taKiCjU2k90Qlbx8n3GeBTqfcFDSSu4iVteqM+w= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x730.google.com (mail-qk1-x730.google.com [IPv6:2607:f8b0:4864:20::730]) by sourceware.org (Postfix) with ESMTPS id D84173854803 for ; Thu, 17 Jun 2021 11:51:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D84173854803 Received: by mail-qk1-x730.google.com with SMTP id c138so2777543qkg.5 for ; Thu, 17 Jun 2021 04:51:21 -0700 (PDT) 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:mime-version:content-transfer-encoding; bh=cw/wTvswUiMDXMrHMAZOh54EkS0QmC1YTIBIm0SpATI=; b=paUHZAASfvLe/pYx21V7wsdpe7w3lOQchH0PVQh0W1IbFKCy06F4ypA9Ve4SCuIGRV 86j9P9LyvqT0HgvoozuzrypRQR7Kbf7ZckBdA/UK7UDYZqyjgLtxT5RaDmOFNFOk1ch4 qYVNIA+Gxdd91+JWnmxl1mUUgR/G1TVoQIwenOXnGzbu8YW+pzHUAYrc66I/w51l0QPu R+sL+p3hNwfkZXE6bYLGX4sRKGHbdCJJL8+TEuzaVxLXvpxtLFJD+bKRXmiINSPRrqNg eFJHD8B1NrW8g+tzjoMBgJvhHM1cMlTNk9MKxc8kBuJ9PYTf2AzxXSSLwv7uxDJe2nQ0 WYxg== X-Gm-Message-State: AOAM530afWP851/Bq+ED5HE9DEHSkOHPWysMUHGEn+m/fZIE9yHy6dDN vCIycl+CEH1jK+6CAYpAEP9MoftSPG5ROQ== X-Google-Smtp-Source: ABdhPJz+9u2cUQENw+/+jSpTqTh/8JPMqMGy5B5sgEUJA7tQQ8l5aC1dJTaTeb5MNOa7LBk+kBNIhA== X-Received: by 2002:ae9:eb82:: with SMTP id b124mr3265319qkg.51.1623930681359; Thu, 17 Jun 2021 04:51:21 -0700 (PDT) Received: from birita.. ([177.194.59.218]) by smtp.googlemail.com with ESMTPSA id p12sm3016435qtw.61.2021.06.17.04.51.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 04:51:21 -0700 (PDT) To: libc-alpha@sourceware.org, Lukasz Majewski , Carlos O'Donell Subject: [PATCH 07/18] linux: Remove supports_time64 () from clock_getres Date: Thu, 17 Jun 2021 08:50:53 -0300 Message-Id: <20210617115104.1359598-8-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210617115104.1359598-1-adhemerval.zanella@linaro.org> References: <20210617115104.1359598-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" It breaks the usage case of live migration like CRIU or similar. The performance drawback is it would require an extra syscall on older kernels without 64-bit time support. Checked on i686-linux-gnu on a 4.15 kernel and on a 5.11 kernel (with and without --enable-kernel=5.1) and on x86_64-linux-gnu. Reviewed-by: Lukasz Majewski --- sysdeps/unix/sysv/linux/clock_getres.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/sysdeps/unix/sysv/linux/clock_getres.c b/sysdeps/unix/sysv/linux/clock_getres.c index a9edec93e6..83f0593074 100644 --- a/sysdeps/unix/sysv/linux/clock_getres.c +++ b/sysdeps/unix/sysv/linux/clock_getres.c @@ -21,7 +21,6 @@ #include #include -#include #include #include @@ -34,19 +33,14 @@ __clock_getres64 (clockid_t clock_id, struct __timespec64 *res) #ifndef __NR_clock_getres_time64 # define __NR_clock_getres_time64 __NR_clock_getres #endif - if (supports_time64 ()) - { + #ifdef HAVE_CLOCK_GETRES64_VSYSCALL - r = INLINE_VSYSCALL (clock_getres_time64, 2, clock_id, res); + r = INLINE_VSYSCALL (clock_getres_time64, 2, clock_id, res); #else - r = INLINE_SYSCALL_CALL (clock_getres_time64, clock_id, res); + r = INLINE_SYSCALL_CALL (clock_getres_time64, clock_id, res); #endif - - if (r == 0 || errno != ENOSYS) - return r; - - mark_time64_unsupported (); - } + if (r == 0 || errno != ENOSYS) + return r; #ifndef __ASSUME_TIME64_SYSCALLS /* Fallback code that uses 32-bit support. */ From patchwork Thu Jun 17 11:50:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 1493412 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=S35abVXH; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4G5LDm34xyz9sRK for ; Thu, 17 Jun 2021 21:58:48 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2BF0A3896802 for ; Thu, 17 Jun 2021 11:58:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2BF0A3896802 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1623931126; bh=8vhERQgGy5zvoAY36fUGUkyJEgk62SKv7Q5SiIdwxjk=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=S35abVXHYVQ1mhCD6J7hnmkQAxn72DLqeEy2H8fBzgHHTi3Ts3X+Ogxm4N1qWLE8k PozMaWkHOfhZKVs+NDigBGd6mLPVD14G0sXBPTBlVarMnwGD2r7oTx6Rrg3k8SuHPT JTQPBVmKmdbTIzQE2W0MVxJ8M00WoMWmHhJNJSmk= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x729.google.com (mail-qk1-x729.google.com [IPv6:2607:f8b0:4864:20::729]) by sourceware.org (Postfix) with ESMTPS id 6FDFB3894411 for ; Thu, 17 Jun 2021 11:51:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6FDFB3894411 Received: by mail-qk1-x729.google.com with SMTP id d196so2733610qkg.12 for ; Thu, 17 Jun 2021 04:51:23 -0700 (PDT) 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:mime-version:content-transfer-encoding; bh=8vhERQgGy5zvoAY36fUGUkyJEgk62SKv7Q5SiIdwxjk=; b=lKu5KxX3Tu1t0GubMxwQsTc5oeVXrx+ckEk44G93fkuVN2bc/vaYcR3mgUopEwkfwE h3rBQOMSOVKQXFh7g6ueGYoSOlrQNIdKPFxT7mqAD/wnTBr9dn4Tfh4L+wHIFHvWDFwX oOUluttGURw8vcpAyvwA3mjl95m/7ClzgwL23hGJSXd+ogpFql1esfVrsSuYfJBW+m1J ICFyUPdq6Sgg/QzNNuiKcx158PfnL/FFLu5UNHfbFACHxdkkOgg4W6uP5ckGnARgdIfg A9ZqVZzvbj28UjMy1Rd20kewy5rzz46Ov9QjpWskJ6/7p2oALVyNat3+7rcyF0dFa7hY YTfg== X-Gm-Message-State: AOAM532D5vCspyKhlKsXsTC+LzeiN5r0EyAe06Ez/iv9f9W4HA506WuG EP20+zk1aJh5RnPnPgtPf/swPpD5RcJYWQ== X-Google-Smtp-Source: ABdhPJxybt9cJpItjlvfLgDEURpdlSENkF9CrKlvK86nkxis2yozN+kCH32fvI3aiZWfelvWtI1W4A== X-Received: by 2002:a37:a8c1:: with SMTP id r184mr3326812qke.129.1623930682924; Thu, 17 Jun 2021 04:51:22 -0700 (PDT) Received: from birita.. ([177.194.59.218]) by smtp.googlemail.com with ESMTPSA id p12sm3016435qtw.61.2021.06.17.04.51.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 04:51:22 -0700 (PDT) To: libc-alpha@sourceware.org, Lukasz Majewski , Carlos O'Donell Subject: [PATCH 08/18] linux: Remove supports_time64 () from clock_gettime Date: Thu, 17 Jun 2021 08:50:54 -0300 Message-Id: <20210617115104.1359598-9-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210617115104.1359598-1-adhemerval.zanella@linaro.org> References: <20210617115104.1359598-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" It breaks the usage case of live migration like CRIU or similar. The performance drawback is it would require an extra syscall on older kernels without 64-bit time support. Checked on i686-linux-gnu on a 4.15 kernel and on a 5.11 kernel (with and without --enable-kernel=5.1) and on x86_64-linux-gnu. Reviewed-by: Lukasz Majewski --- sysdeps/unix/sysv/linux/clock_gettime.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/sysdeps/unix/sysv/linux/clock_gettime.c b/sysdeps/unix/sysv/linux/clock_gettime.c index 781d05c2fd..cfe9370455 100644 --- a/sysdeps/unix/sysv/linux/clock_gettime.c +++ b/sysdeps/unix/sysv/linux/clock_gettime.c @@ -22,7 +22,6 @@ #include #include "kernel-posix-cpu-timers.h" #include -#include #include /* Get current value of CLOCK and store it in TP. */ @@ -35,19 +34,14 @@ __clock_gettime64 (clockid_t clock_id, struct __timespec64 *tp) # define __NR_clock_gettime64 __NR_clock_gettime #endif - if (supports_time64 ()) - { #ifdef HAVE_CLOCK_GETTIME64_VSYSCALL - r = INLINE_VSYSCALL (clock_gettime64, 2, clock_id, tp); + r = INLINE_VSYSCALL (clock_gettime64, 2, clock_id, tp); #else - r = INLINE_SYSCALL_CALL (clock_gettime64, clock_id, tp); + r = INLINE_SYSCALL_CALL (clock_gettime64, clock_id, tp); #endif - if (r == 0 || errno != ENOSYS) - return r; - - mark_time64_unsupported (); - } + if (r == 0 || errno != ENOSYS) + return r; #ifndef __ASSUME_TIME64_SYSCALLS /* Fallback code that uses 32-bit support. */ From patchwork Thu Jun 17 11:50:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 1493415 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=Pn5YtfVP; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4G5LFc4rVTz9sT6 for ; Thu, 17 Jun 2021 21:59:32 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5126C3896C27 for ; Thu, 17 Jun 2021 11:59:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5126C3896C27 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1623931170; bh=BGZssOnqtu5bxMEvBvvx9K90V5JiPUnj2shcjQTDbQo=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Pn5YtfVP9Kti4T3itsOKK3SEBZ8ElICdh1vUurNYwv+R9dXB1/zsDEl5sdcQKGy6v ojSzz9minRTc5gmRLzYijphDxG3rjR7891UE0oETsTMCaIoRxqjjynm07v08zmKuRu afSrP+dOoNv2n49gL6FKU4VYhf5Q7j0LFRTO8+L0= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x736.google.com (mail-qk1-x736.google.com [IPv6:2607:f8b0:4864:20::736]) by sourceware.org (Postfix) with ESMTPS id 0ACF63894409 for ; Thu, 17 Jun 2021 11:51:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0ACF63894409 Received: by mail-qk1-x736.google.com with SMTP id q16so2744262qkm.9 for ; Thu, 17 Jun 2021 04:51:25 -0700 (PDT) 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:mime-version:content-transfer-encoding; bh=BGZssOnqtu5bxMEvBvvx9K90V5JiPUnj2shcjQTDbQo=; b=BCTnqK25+JmvRkeEGCQhn1Qk2PU/hioaKbuV5+uidLOocc/ar3AFbjYLkCGMUBqTlN Ut7v0Ox3ZYuEoFx6j90mfUu3OJ5jY3/xGJk/y6CXWnj2/s7GV2ai5wfgYCLx9mMWcYJy nUuKXzQDK2ipkRZGeskrCwr7a+uma7op6fx2EvAvdweSrAScZn3LQ9lHTzJlGmIyF+8z lRj1ijpC2arfgeS2d0NvO98R5djkSzylKEQfiDfK8uxwJ7E6rOQD0J6yrMdjNB3FPRBe 6sFR0Xl/8Ffn2FHCmbGSC6Jc2pJW/yuK/WVeJBXpkfk/wngFz3ta5xqxzyOHx0EYveGK +gTw== X-Gm-Message-State: AOAM531DnMEKvoGgl2gtliNypq9oZdNYnqQeUM+JdwcZwRy8KKGT18jN 875f3oaP58cH+wKvGGA58ia+B9sLoSdCew== X-Google-Smtp-Source: ABdhPJz18FznCdzCLHGOPWjJL60UdLSwul+nUcY0660JVoit/m4IlCDg4ccLJt+ZzGcp6We+1EMSww== X-Received: by 2002:a05:620a:12e5:: with SMTP id f5mr3298489qkl.406.1623930684485; Thu, 17 Jun 2021 04:51:24 -0700 (PDT) Received: from birita.. ([177.194.59.218]) by smtp.googlemail.com with ESMTPSA id p12sm3016435qtw.61.2021.06.17.04.51.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 04:51:24 -0700 (PDT) To: libc-alpha@sourceware.org, Lukasz Majewski , Carlos O'Donell Subject: [PATCH 09/18] linux: Remove time64-support Date: Thu, 17 Jun 2021 08:50:55 -0300 Message-Id: <20210617115104.1359598-10-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210617115104.1359598-1-adhemerval.zanella@linaro.org> References: <20210617115104.1359598-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" It breaks the usage case of live migration like CRIU or similar and most usages can be optimized away by either building glibc with a minimum 5.1 kernel or by using the 32-bit syscall for the common case. Checked on i686-linux-gnu on a 4.15 kernel and on a 5.11 kernel (with and without --enable-kernel=5.1) and on x86_64-linux-gnu. Reviewed-by: Lukasz Majewski --- sysdeps/unix/sysv/linux/Makefile | 2 +- sysdeps/unix/sysv/linux/time64-support.c | 23 -------- sysdeps/unix/sysv/linux/time64-support.h | 70 ------------------------ 3 files changed, 1 insertion(+), 94 deletions(-) delete mode 100644 sysdeps/unix/sysv/linux/time64-support.c delete mode 100644 sysdeps/unix/sysv/linux/time64-support.h diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index 710169a454..982755f980 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -61,7 +61,7 @@ sysdep_routines += adjtimex clone umount umount2 readahead sysctl \ open_by_handle_at mlock2 pkey_mprotect pkey_set pkey_get \ timerfd_gettime timerfd_settime prctl \ process_vm_readv process_vm_writev clock_adjtime \ - time64-support pselect32 select32 \ + pselect32 select32 \ xstat fxstat lxstat xstat64 fxstat64 lxstat64 \ fxstatat fxstatat64 \ xmknod xmknodat convert_scm_timestamps diff --git a/sysdeps/unix/sysv/linux/time64-support.c b/sysdeps/unix/sysv/linux/time64-support.c deleted file mode 100644 index 0718e7421b..0000000000 --- a/sysdeps/unix/sysv/linux/time64-support.c +++ /dev/null @@ -1,23 +0,0 @@ -/* Auxiliary definitions for 64-bit time_t support. - Copyright (C) 2020-2021 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 - -#ifndef __ASSUME_TIME64_SYSCALLS -int __time64_support = 1; -#endif diff --git a/sysdeps/unix/sysv/linux/time64-support.h b/sysdeps/unix/sysv/linux/time64-support.h deleted file mode 100644 index 8466d37f8f..0000000000 --- a/sysdeps/unix/sysv/linux/time64-support.h +++ /dev/null @@ -1,70 +0,0 @@ -/* Auxiliary definitions for 64-bit time_t support. - Copyright (C) 2020-2021 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include - -/* These helper functions are used to optimize the 64-bit time_t support on - configurations that requires support for 32-bit time_t fallback - (!__ASSUME_TIME64_SYSCALLS). The idea is once the kernel advertises that - it does not have 64-bit time_t support, glibc will stop to try issue the - 64-bit time_t syscall altogether. - - For instance: - - #ifndef __NR_symbol_time64 - # define __NR_symbol_time64 __NR_symbol - #endif - int r; - if (supports_time64 ()) - { - r = INLINE_SYSCALL_CALL (symbol, ...); - if (r == 0 || errno != ENOSYS) - return r; - - mark_time64_unsupported (); - } - #ifndef __ASSUME_TIME64_SYSCALLS - <32-bit fallback syscall> - #endif - return r; - - On configuration with default 64-bit time_t this optimization should be - optimized away by the compiler resulting in no overhead. */ - -#ifndef __ASSUME_TIME64_SYSCALLS -extern int __time64_support attribute_hidden; -#endif - -static inline bool -supports_time64 (void) -{ -#ifdef __ASSUME_TIME64_SYSCALLS - return true; -#else - return atomic_load_relaxed (&__time64_support) != 0; -#endif -} - -static inline void -mark_time64_unsupported (void) -{ -#ifndef __ASSUME_TIME64_SYSCALLS - atomic_store_relaxed (&__time64_support, 0); -#endif -} From patchwork Thu Jun 17 11:50:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 1493416 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=YuKoDAb/; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4G5LGb5Gx5z9sTD for ; Thu, 17 Jun 2021 22:00:23 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6CB1D389683B for ; Thu, 17 Jun 2021 12:00:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6CB1D389683B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1623931221; bh=sRQTS9GPtihbR/Wnnx/q7OSW8O7UVHSdUS51p/OE7e4=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=YuKoDAb/MvgRUMkW+lpPQMkx5JyjT1ilCQSYzMT0zeaRr0B204EngwZKuPQd/FlII 2/b3Mx3dCdZj9Ng2EpfP9NN5S/z13okrEFqdu9qEzn/jhx4CAK6jsing6977idi7Ox g6dX48VVlYo54BzvsFoBuJwHnTqxq+jKRxsVl+iQ= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qv1-xf31.google.com (mail-qv1-xf31.google.com [IPv6:2607:f8b0:4864:20::f31]) by sourceware.org (Postfix) with ESMTPS id 8C1453893670 for ; Thu, 17 Jun 2021 11:51:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8C1453893670 Received: by mail-qv1-xf31.google.com with SMTP id c10so1458082qvo.9 for ; Thu, 17 Jun 2021 04:51:26 -0700 (PDT) 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:mime-version:content-transfer-encoding; bh=sRQTS9GPtihbR/Wnnx/q7OSW8O7UVHSdUS51p/OE7e4=; b=DKgEofs8qSj1YG3pk7JS+gksrKJPkKoMAS5NtZlTDPxtVrAE/116R5fC5TdZsAz3JA R/OQp7aup0ahoKxwuD2kc7n80TyleaA7qRlgRFluitv+55O5gHgbPPjwBjanQizHfSzR NCsQyTNYff1qHdJRaLj79QqNbET2G1mWBN3+zB5QaZ6NIItL+uBaVDuBEQVvLkJ8kKoX w7Xm7o+wJ4Bgv6YamZF4CdrC8iDCVjmCI2s8L7w5OXHtPg5GpUWYsJYmQ5zR5UpBxDUK +b8mSgS15Maqd4dDqEPcLqJwwvBJlOO7ogZ9EY0ZECrmGLg6UvVs163gr5FbYDg/xedc 1Onw== X-Gm-Message-State: AOAM533NtmvNivzT5zkNw2uR2OzG+Bhgtw/FlUETYZWT55IkrlSbIZ/c D4d5Cc2a8REdJDFGpLKm+GCz9b1qGxo28A== X-Google-Smtp-Source: ABdhPJwvhecQBzR3ou6kzVudyM30TF5zAdQD9pZv8eusW3reof7vGphDlI+gHFrL0zoKsbplFd0ATw== X-Received: by 2002:a05:6214:321:: with SMTP id j1mr5654457qvu.38.1623930686061; Thu, 17 Jun 2021 04:51:26 -0700 (PDT) Received: from birita.. ([177.194.59.218]) by smtp.googlemail.com with ESMTPSA id p12sm3016435qtw.61.2021.06.17.04.51.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 04:51:25 -0700 (PDT) To: libc-alpha@sourceware.org, Lukasz Majewski , Carlos O'Donell Subject: [PATCH 10/18] linux: timerfd_gettime minor cleanup Date: Thu, 17 Jun 2021 08:50:56 -0300 Message-Id: <20210617115104.1359598-11-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210617115104.1359598-1-adhemerval.zanella@linaro.org> References: <20210617115104.1359598-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" The __NR_timerfd_gettime64 is always defined. Reviewed-by: Lukasz Majewski --- sysdeps/unix/sysv/linux/timerfd_gettime.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sysdeps/unix/sysv/linux/timerfd_gettime.c b/sysdeps/unix/sysv/linux/timerfd_gettime.c index 89f8066b91..5f668257c4 100644 --- a/sysdeps/unix/sysv/linux/timerfd_gettime.c +++ b/sysdeps/unix/sysv/linux/timerfd_gettime.c @@ -25,17 +25,17 @@ int __timerfd_gettime64 (int fd, struct __itimerspec64 *value) { +#ifndef __NR_timerfd_gettime64 +# define __NR_timerfd_gettime64 __NR_timerfd_gettime +#endif + #ifdef __ASSUME_TIME64_SYSCALLS -# ifndef __NR_timerfd_gettime64 -# define __NR_timerfd_gettime64 __NR_timerfd_gettime -# endif return INLINE_SYSCALL_CALL (timerfd_gettime64, fd, value); #else -# ifdef __NR_timerfd_gettime64 int ret = INLINE_SYSCALL_CALL (timerfd_gettime64, fd, value); if (ret == 0 || errno != ENOSYS) return ret; -# endif + struct itimerspec its32; int retval = INLINE_SYSCALL_CALL (timerfd_gettime, fd, &its32); if (retval == 0) From patchwork Thu Jun 17 11:50:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 1493417 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=EP9GA8cw; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4G5LHR5Rqxz9sRK for ; Thu, 17 Jun 2021 22:01:07 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 60A423938398 for ; Thu, 17 Jun 2021 12:01:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 60A423938398 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1623931265; bh=puhkguV8tZOD+G1wJgKdrfkp4sXAC1/UC5UDljsmiHU=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=EP9GA8cwuZQq5VseDODCWrFIaF6916afKZnxR6f244zdVWeOcQrqY8EaW5tqnvx7m QJn9PX/h6W+HrioMnLWpCwvJFQnOFsd+g2WNAM6dWNkEMg6m/5gTAPo65OKUYFPQc/ dGr6IQL2ga7AkF9tts68avdn4oezpbHGNSxb9P9g= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qv1-xf29.google.com (mail-qv1-xf29.google.com [IPv6:2607:f8b0:4864:20::f29]) by sourceware.org (Postfix) with ESMTPS id 32BFF3894412 for ; Thu, 17 Jun 2021 11:51:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 32BFF3894412 Received: by mail-qv1-xf29.google.com with SMTP id c10so1458124qvo.9 for ; Thu, 17 Jun 2021 04:51:28 -0700 (PDT) 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:mime-version:content-transfer-encoding; bh=puhkguV8tZOD+G1wJgKdrfkp4sXAC1/UC5UDljsmiHU=; b=hG1qUE34Zx64ewis1V86gi+yk+T/VgZSIE2aVz3NexOm6kz+yIzBKs+n7Pe/X7lxcu 4m5qO8TLFQPEf01FzjgteqgR07iLNaiwBppJmd4AxFy5OE0gbxKcazUMPBItUMLhFXEw p3vnoNg1+Fa31jfP/NV1A1ou0W6KERY3f6/5cwGE8cRhQERZ4oYPfkkR6Mos5GOVTTr5 zCzTu6ElQjLPP+Djpli86qQGRb+0HMNJSKJYIvKYWYfkWtspgtirLOdqVRjrSBPvmqax UH9zGKq8HKuxyNm1xlT/beDBTUjPHqaLNCJRJPBdwGqgaoZkothY/jdYC7EviTMRmPmJ bf9Q== X-Gm-Message-State: AOAM530j0Bqe4YSDdcO9pYFZCFiE8OwQUrxqjqOYIPa0GP0iHrInluOC bs5YJlJ8Mjqj6mAftfdG7MmaQiVlZAaXoA== X-Google-Smtp-Source: ABdhPJwbNFEZQT+mknVQouhPmsN+m5Qz0nvCMOnMjw22gsynmCJZmzLcwSQavUmku7bDsIdWdefe7A== X-Received: by 2002:ad4:50c6:: with SMTP id e6mr5580622qvq.6.1623930687644; Thu, 17 Jun 2021 04:51:27 -0700 (PDT) Received: from birita.. ([177.194.59.218]) by smtp.googlemail.com with ESMTPSA id p12sm3016435qtw.61.2021.06.17.04.51.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 04:51:27 -0700 (PDT) To: libc-alpha@sourceware.org, Lukasz Majewski , Carlos O'Donell Subject: [PATCH 11/18] linux: Only use 64-bit syscall if required for semtimedop Date: Thu, 17 Jun 2021 08:50:57 -0300 Message-Id: <20210617115104.1359598-12-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210617115104.1359598-1-adhemerval.zanella@linaro.org> References: <20210617115104.1359598-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" For !__ASSUME_TIME64_SYSCALLS there is no need to issue a 64-bit syscall if the provided timeout fits in a 32-bit one. The 64-bit usage should be rare since the timeout is a relative one. Checked on i686-linux-gnu on a 4.15 kernel and on a 5.11 kernel (with and without --enable-kernel=5.1) and on x86_64-linux-gnu. Reviewed-by: Lukasz Majewski --- sysdeps/unix/sysv/linux/semtimedop.c | 54 ++++++++++++++++------------ sysvipc/Makefile | 9 +++++ sysvipc/test-sysvsem.c | 22 +++++++++--- 3 files changed, 57 insertions(+), 28 deletions(-) diff --git a/sysdeps/unix/sysv/linux/semtimedop.c b/sysdeps/unix/sysv/linux/semtimedop.c index b732b6db48..65a8c080f7 100644 --- a/sysdeps/unix/sysv/linux/semtimedop.c +++ b/sysdeps/unix/sysv/linux/semtimedop.c @@ -21,44 +21,52 @@ #include #include +static int +semtimedop_syscall (int semid, struct sembuf *sops, size_t nsops, + const struct __timespec64 *timeout) +{ +#ifdef __NR_semtimedop_time64 + return INLINE_SYSCALL_CALL (semtimedop_time64, semid, sops, nsops, timeout); +#elif defined __ASSUME_DIRECT_SYSVIPC_SYSCALLS && defined __NR_semtimedop + return INLINE_SYSCALL_CALL (semtimedop, semid, sops, nsops, timeout); +#else + return INLINE_SYSCALL_CALL (ipc, IPCOP_semtimedop, semid, + SEMTIMEDOP_IPC_ARGS (nsops, sops, timeout)); +#endif +} + /* Perform user-defined atomical operation of array of semaphores. */ int __semtimedop64 (int semid, struct sembuf *sops, size_t nsops, const struct __timespec64 *timeout) { - int r; -#if defined __NR_semtimedop_time64 - r = INLINE_SYSCALL_CALL (semtimedop_time64, semid, sops, nsops, timeout); -#elif defined __ASSUME_DIRECT_SYSVIPC_SYSCALLS && defined __NR_semtimedop - r = INLINE_SYSCALL_CALL (semtimedop, semid, sops, nsops, timeout); +#ifdef __ASSUME_TIME64_SYSCALLS + return semtimedop_syscall (semid, sops, nsops, timeout); #else - r = INLINE_SYSCALL_CALL (ipc, IPCOP_semtimedop, semid, - SEMTIMEDOP_IPC_ARGS (nsops, sops, timeout)); -#endif - -#ifndef __ASSUME_TIME64_SYSCALLS - if (r == 0 || errno != ENOSYS) - return r; + bool is32bit = timeout != NULL + ? in_time_t_range (timeout->tv_sec) : true; + if (!is32bit) + { + int r = semtimedop_syscall (semid, sops, nsops, timeout); + if (r == 0 || errno != ENOSYS) + return r; + __set_errno (EOVERFLOW); + return -1; + } struct timespec ts32, *pts32 = NULL; if (timeout != NULL) { - if (! in_time_t_range (timeout->tv_sec)) - { - __set_errno (EINVAL); - return -1; - } ts32 = valid_timespec64_to_timespec (*timeout); pts32 = &ts32; } -# if defined __ASSUME_DIRECT_SYSVIPC_SYSCALLS - r = INLINE_SYSCALL_CALL (semtimedop, semid, sops, nsops, pts32); +# ifdef __ASSUME_DIRECT_SYSVIPC_SYSCALLS + return INLINE_SYSCALL_CALL (semtimedop, semid, sops, nsops, pts32); # else - r = INLINE_SYSCALL_CALL (ipc, IPCOP_semtimedop, semid, - SEMTIMEDOP_IPC_ARGS (nsops, sops, pts32)); + return INLINE_SYSCALL_CALL (ipc, IPCOP_semtimedop, semid, + SEMTIMEDOP_IPC_ARGS (nsops, sops, pts32)); # endif -#endif /* __ASSUME_TIME64_SYSCALLS */ - return r; +#endif } #if __TIMESIZE != 64 libc_hidden_def (__semtimedop64) diff --git a/sysvipc/Makefile b/sysvipc/Makefile index 86911803b5..d2acb6a70b 100644 --- a/sysvipc/Makefile +++ b/sysvipc/Makefile @@ -38,3 +38,12 @@ include ../Rules CFLAGS-msgrcv.c += -fexceptions -fasynchronous-unwind-tables CFLAGS-msgsnd.c += -fexceptions -fasynchronous-unwind-tables + +ifeq (yes,$(build-shared)) +librt = $(common-objpfx)rt/librt.so +else +librt = $(common-objpfx)rt/librt.a +endif + +$(objpfx)test-sysvsem: $(librt) +$(objpfx)test-sysvsem-time64: $(librt) diff --git a/sysvipc/test-sysvsem.c b/sysvipc/test-sysvsem.c index 092418205d..d9034c3dae 100644 --- a/sysvipc/test-sysvsem.c +++ b/sysvipc/test-sysvsem.c @@ -16,6 +16,7 @@ License along with the GNU C Library; if not, see . */ +#include #include #include #include @@ -30,6 +31,8 @@ #include #include #include +#include +#include /* These are for the temporary file we generate. */ static char *name; @@ -112,11 +115,20 @@ do_test (void) #ifdef _GNU_SOURCE /* Set a time for half a second. The semaphore operation should timeout with EAGAIN. */ - struct timespec ts = { 0 /* sec */, 500000000 /* nsec */ }; - if (semtimedop (semid, &sb2, 1, &ts) != -1 - || (errno != EAGAIN && errno != ENOSYS)) - FAIL_EXIT1 ("semtimedop succeed or returned errno != {EAGAIN,ENOSYS} " - "(errno=%i)", errno); + { + struct timespec ts = { 0 /* sec */, 500000000 /* nsec */ }; + if (semtimedop (semid, &sb2, 1, &ts) != -1 + || (errno != EAGAIN && errno != ENOSYS)) + FAIL_EXIT1 ("semtimedop succeed or returned errno != {EAGAIN,ENOSYS} " + "(errno=%i)", errno); + } + + { + support_create_timer (0, 100000000, false, NULL); + struct timespec ts = { TYPE_MAXIMUM (time_t), 0 }; + TEST_COMPARE (semtimedop (semid, &sb2, 1, &ts), -1); + TEST_VERIFY (errno == EINTR || errno == EOVERFLOW); + } #endif /* Finally free up the semnaphore resource. */ From patchwork Thu Jun 17 11:50:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 1493418 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=NL17DF+/; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4G5LJJ0BQQz9sRK for ; Thu, 17 Jun 2021 22:01:52 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AE572389851F for ; Thu, 17 Jun 2021 12:01:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AE572389851F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1623931309; bh=3LhDGz8V3/hWP7tcUCOihH5aMt2hU+hMGHTPxACeSyc=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=NL17DF+/0VujM/BjqHFyXBLYpjsRl0p7Iv9lh9h2IHVuFKL56q42n2IeTNm+5p9pO CvuL4oZ9Qimd06AivsmJm4ghlUq8hQ0ksPYrhuGym4Wl5FwL4c9SUvB52Y+awrL1vj DV0qxLk7XeRWvpxAfXpl6w8rqE13wDweAiIsM0PU= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x730.google.com (mail-qk1-x730.google.com [IPv6:2607:f8b0:4864:20::730]) by sourceware.org (Postfix) with ESMTPS id 200E53890022 for ; Thu, 17 Jun 2021 11:51:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 200E53890022 Received: by mail-qk1-x730.google.com with SMTP id 5so2755023qkc.8 for ; Thu, 17 Jun 2021 04:51:30 -0700 (PDT) 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:mime-version:content-transfer-encoding; bh=3LhDGz8V3/hWP7tcUCOihH5aMt2hU+hMGHTPxACeSyc=; b=BzjDbOV+X6GATsb21GGknxXQd+NbikyIA8RWjeILgea14BGSUqE5IO7uN8RTLXP5bG VOpLWoJdPseV23cGdYGfncdq9maJOmrnLPaMmRBNua4stpbwNsoBXntbB6Nqp4u/W6CL zczjSV3MQ1jSjmQmvWasxXpZjSjwSjZ6ERA6xXzptPTFs3/h+GwnFxpjWkoTIKYGaZCI phg34ZaoNFTkWYc4gEjeuLqVeRu3t5wxHuyP/KicLLoyOcqSffGS4/lBBEEv7/Vu1up5 lBweuSI4KrCib9l3u1ni5VOj/Kij02OK9x8SPU+cFY0Txzp5bfeCdFWu891WHJVr6HW7 gz0w== X-Gm-Message-State: AOAM530Iuhz3AfUWRXqLK6M/TJFsVdm4qJQGE6/s4W8DwHy9DvGJf8ph tcoCbvdQICO4lQzDNbcKJjWQ5RGlss+GyA== X-Google-Smtp-Source: ABdhPJwe0M8NvR9Ujt/7wCJmGDsmGxWYIimEUNK5j0ur+IEYlGhfQ2a2QR0bw4aJlfsyorPzMTLVAA== X-Received: by 2002:ae9:e84f:: with SMTP id a76mr3429115qkg.366.1623930689583; Thu, 17 Jun 2021 04:51:29 -0700 (PDT) Received: from birita.. ([177.194.59.218]) by smtp.googlemail.com with ESMTPSA id p12sm3016435qtw.61.2021.06.17.04.51.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 04:51:28 -0700 (PDT) To: libc-alpha@sourceware.org, Lukasz Majewski , Carlos O'Donell Subject: [PATCH 12/18] linux: Only use 64-bit syscall if required for timerfd_settime Date: Thu, 17 Jun 2021 08:50:58 -0300 Message-Id: <20210617115104.1359598-13-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210617115104.1359598-1-adhemerval.zanella@linaro.org> References: <20210617115104.1359598-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" For !__ASSUME_TIME64_SYSCALLS there is no need to issue a 64-bit syscall if the provided timeout fits in a 32-bit one. The 64-bit usage should be rare since the timeout is a relative one. Checked on i686-linux-gnu on a 4.15 kernel and on a 5.11 kernel (with and without --enable-kernel=5.1) and on x86_64-linux-gnu. Reviewed-by: Lukasz Majewski --- sysdeps/unix/sysv/linux/Makefile | 2 ++ sysdeps/unix/sysv/linux/timerfd_settime.c | 25 ++++++++++--------- sysdeps/unix/sysv/linux/tst-timerfd.c | 29 +++++++++++++++++++++-- 3 files changed, 43 insertions(+), 13 deletions(-) diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index 982755f980..2e5b5e1dc4 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -145,6 +145,8 @@ endif $(objpfx)tst-ppoll: $(librt) $(objpfx)tst-ppoll-time64: $(librt) +$(objpfx)tst-timerfd: $(librt) +$(objpfx)tst-timerfd-time64: $(librt) # Generate the list of SYS_* macros for the system calls (__NR_* # macros). The file syscall-names.list contains all possible system diff --git a/sysdeps/unix/sysv/linux/timerfd_settime.c b/sysdeps/unix/sysv/linux/timerfd_settime.c index 0dd6fa026e..8f08133a73 100644 --- a/sysdeps/unix/sysv/linux/timerfd_settime.c +++ b/sysdeps/unix/sysv/linux/timerfd_settime.c @@ -29,31 +29,34 @@ __timerfd_settime64 (int fd, int flags, const struct __itimerspec64 *value, #ifndef __NR_timerfd_settime64 # define __NR_timerfd_settime64 __NR_timerfd_settime #endif - int ret = INLINE_SYSCALL_CALL (timerfd_settime64, fd, flags, value, ovalue); -#ifndef __ASSUME_TIME64_SYSCALLS - if (ret == 0 || errno != ENOSYS) - return ret; - if (! in_time_t_range ((value->it_value).tv_sec) - || ! in_time_t_range ((value->it_interval).tv_sec)) +#ifdef __ASSUME_TIME64_SYSCALLS + return INLINE_SYSCALL_CALL (timerfd_settime64, fd, flags, value, ovalue); +#else + bool is32bit_value = in_time_t_range (value->it_value.tv_sec); + bool is32bit_interval = in_time_t_range (value->it_interval.tv_sec); + if (!is32bit_value || !is32bit_interval) { + int r = INLINE_SYSCALL_CALL (timerfd_settime64, fd, flags, value, + ovalue); + if (r == 0 || errno != ENOSYS) + return r; __set_errno (EOVERFLOW); - return -1; + return r; } struct itimerspec its32, oits32; its32.it_interval = valid_timespec64_to_timespec (value->it_interval); its32.it_value = valid_timespec64_to_timespec (value->it_value); - - ret = INLINE_SYSCALL_CALL (timerfd_settime, fd, flags, - &its32, ovalue ? &oits32 : NULL); + int ret = INLINE_SYSCALL_CALL (timerfd_settime, fd, flags, + &its32, ovalue != NULL ? &oits32 : NULL); if (ret == 0 && ovalue != NULL) { ovalue->it_interval = valid_timespec_to_timespec64 (oits32.it_interval); ovalue->it_value = valid_timespec_to_timespec64 (oits32.it_value); } -#endif return ret; +#endif } #if __TIMESIZE != 64 diff --git a/sysdeps/unix/sysv/linux/tst-timerfd.c b/sysdeps/unix/sysv/linux/tst-timerfd.c index 8828399119..27f1263ac6 100644 --- a/sysdeps/unix/sysv/linux/tst-timerfd.c +++ b/sysdeps/unix/sysv/linux/tst-timerfd.c @@ -16,15 +16,18 @@ License along with the GNU C Library; if not, see . */ +#include +#include #include #include +#include #include #include #include #include -static int -do_test (void) +static void +timerfd_test (void) { struct itimerspec settings = { { 0, 0 }, { 2, 0 } }; struct itimerspec val; @@ -52,6 +55,28 @@ do_test (void) /* Check difference between timerfd_gettime calls. */ TEST_COMPARE (support_timespec_check_in_range ((struct timespec) { 1, 0 }, val.it_value, 0.9, 1.0), 1); + + xclose (fd); +} + +static void +timerfd_large_timeout (void) +{ + int fd = timerfd_create (CLOCK_REALTIME, 0); + TEST_VERIFY (fd != -1); + support_create_timer (0, 100000000, false, NULL); + struct itimerspec it = { { 0, 0 }, { TYPE_MAXIMUM (time_t), 0 } }; + TEST_COMPARE (timerfd_settime (fd, 0, &it, NULL), 0); + uint64_t buf; + TEST_COMPARE (read (fd, &buf, sizeof (buf)), -1); + TEST_VERIFY (errno == EINTR || errno == EOVERFLOW); +} + +static int +do_test (void) +{ + timerfd_test (); + timerfd_large_timeout (); return 0; } From patchwork Thu Jun 17 11:50:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 1493419 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=vuI9rMkw; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4G5LK82DVRz9sRK for ; Thu, 17 Jun 2021 22:02:36 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D4CDD3894430 for ; Thu, 17 Jun 2021 12:02:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D4CDD3894430 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1623931353; bh=Yu4olqf/q/+zOMm534EVbGi8U5Hm8XEUi/bdAEYRx4U=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=vuI9rMkw9800AktXhePbNRmqqqDK3C/+mSYeQDAq5T/KDlzNHSccj6pkVJi+Vuwo9 PyPU2aT/nrYrniEVMHCjrlyQmI5uBkPl9QK/vOtykFA3KplT2UVNdBhl2IQSzs4H51 R2NVV8jWCP1UbEqFcz5Aqid3OJ/TV9L4cC32v0vo= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x733.google.com (mail-qk1-x733.google.com [IPv6:2607:f8b0:4864:20::733]) by sourceware.org (Postfix) with ESMTPS id AF3DE3893C44 for ; Thu, 17 Jun 2021 11:51:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AF3DE3893C44 Received: by mail-qk1-x733.google.com with SMTP id q190so158018qkd.2 for ; Thu, 17 Jun 2021 04:51:31 -0700 (PDT) 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:mime-version:content-transfer-encoding; bh=Yu4olqf/q/+zOMm534EVbGi8U5Hm8XEUi/bdAEYRx4U=; b=VvaqsTwuiMJca6bmYczAnwOzjnznvN2h7gShKqXCwOiH3iRc9sNMgUj5/JQ8Sx+24f MU9mPZah+rLr1LzoaMijfoTDuuw9sZUMj/XePJ5636yBbdqSAbJSue9m4UcF3sM/d0Vz wekTSPLZ031M7bdklN+r57jwgJG9qjbnzlh9m2g1mThvz4GeKU+KnLuz0xIDlEi2bXRl ehUqoVlQPLUG/7JkD0iDZ9r/ji+IyLG8ucaw09GyDgJPtsXsUrcdvwW8FbeyKW8J+l7C NUrAYq9v4O1YhK6pl9QS2MqKKU8a48ohE49H7grHl46EMVBGv8iAD9TrkTjYQYN0j0Ly jt7g== X-Gm-Message-State: AOAM533W1DCLL3eUGR8GPq8LnIh6NJy8uNju9+aUoXunPVTl3TitVLxj odKG49lVzBfo24UdAb/P9kZ9LfHXIzakww== X-Google-Smtp-Source: ABdhPJzVWLSRnCsg4BQ9ENa2FoDJO58zync29nt0x05ln1Ab4w0tRAvbCL+F+RUao4rBp3S7mfkrEQ== X-Received: by 2002:a05:620a:2449:: with SMTP id h9mr3286889qkn.315.1623930691168; Thu, 17 Jun 2021 04:51:31 -0700 (PDT) Received: from birita.. ([177.194.59.218]) by smtp.googlemail.com with ESMTPSA id p12sm3016435qtw.61.2021.06.17.04.51.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 04:51:30 -0700 (PDT) To: libc-alpha@sourceware.org, Lukasz Majewski , Carlos O'Donell Subject: [PATCH 13/18] linux: Only use 64-bit syscall if required for mq_timedreceive Date: Thu, 17 Jun 2021 08:50:59 -0300 Message-Id: <20210617115104.1359598-14-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210617115104.1359598-1-adhemerval.zanella@linaro.org> References: <20210617115104.1359598-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" For !__ASSUME_TIME64_SYSCALLS there is no need to issue a 64-bit syscall if the provided timeout fits in a 32-bit one. The 64-bit usage should be rare since the timeout is a relative one. Checked on i686-linux-gnu on a 4.15 kernel and on a 5.11 kernel (with and without --enable-kernel=5.1) and on x86_64-linux-gnu. Reviewed-by: Lukasz Majewski --- rt/Makefile | 4 +- rt/tst-mqueue10-time64.c | 1 + rt/tst-mqueue10.c | 62 +++++++++++++++++++++++ sysdeps/unix/sysv/linux/mq_timedreceive.c | 35 +++++++------ 4 files changed, 85 insertions(+), 17 deletions(-) create mode 100644 rt/tst-mqueue10-time64.c create mode 100644 rt/tst-mqueue10.c diff --git a/rt/Makefile b/rt/Makefile index 797f2da51e..3382c7a1d2 100644 --- a/rt/Makefile +++ b/rt/Makefile @@ -48,7 +48,8 @@ tests := tst-shm tst-timer tst-timer2 \ tst-mqueue5 tst-mqueue6 tst-mqueue7 tst-mqueue8 tst-mqueue9 \ tst-timer3 tst-timer4 tst-timer5 \ tst-cpuclock2 tst-cputimer1 tst-cputimer2 tst-cputimer3 \ - tst-shm-cancel + tst-shm-cancel \ + tst-mqueue10 tests-internal := tst-timer-sigmask tests-time64 := \ @@ -58,6 +59,7 @@ tests-time64 := \ tst-mqueue2-time64 \ tst-mqueue4-time64 \ tst-mqueue8-time64 \ + tst-mqueue10-time64 \ tst-timer4-time64 extra-libs := librt diff --git a/rt/tst-mqueue10-time64.c b/rt/tst-mqueue10-time64.c new file mode 100644 index 0000000000..2c8a4ae372 --- /dev/null +++ b/rt/tst-mqueue10-time64.c @@ -0,0 +1 @@ +#include "tst-mqueue10.c" diff --git a/rt/tst-mqueue10.c b/rt/tst-mqueue10.c new file mode 100644 index 0000000000..7fb53a1cae --- /dev/null +++ b/rt/tst-mqueue10.c @@ -0,0 +1,62 @@ +/* Check for large timeout with mq_timedsend and mq_timedreceive. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include +#include +#include +#include +#include + +static char name[sizeof "/tst-mqueue2-" + INT_BUFSIZE_BOUND (pid_t)]; + +static void +do_cleanup (void) +{ + mq_unlink (name); +} +#define CLEANUP_HANDLER do_cleanup + +static int +do_test (void) +{ + snprintf (name, sizeof (name), "/tst-mqueue2-%u", getpid ()); + + char msg[8] = { 0x55 }; + + struct mq_attr attr = { .mq_maxmsg = 1, .mq_msgsize = sizeof (msg) }; + mqd_t q = mq_open (name, O_CREAT | O_EXCL | O_RDWR, 0600, &attr); + TEST_VERIFY_EXIT (q != (mqd_t) -1); + + struct timespec ts = { TYPE_MAXIMUM (time_t), 0 }; + + { + timer_t timer = support_create_timer (0, 100000000, false, NULL); + TEST_COMPARE (mq_timedreceive (q, msg, sizeof (msg), NULL, &ts), -1); + TEST_VERIFY (errno == EINTR || errno == EOVERFLOW); + support_delete_timer (timer); + } + + mq_unlink (name); + + return 0; +} + +#include diff --git a/sysdeps/unix/sysv/linux/mq_timedreceive.c b/sysdeps/unix/sysv/linux/mq_timedreceive.c index eb948ccc18..8776977daf 100644 --- a/sysdeps/unix/sysv/linux/mq_timedreceive.c +++ b/sysdeps/unix/sysv/linux/mq_timedreceive.c @@ -29,30 +29,33 @@ __mq_timedreceive_time64 (mqd_t mqdes, char *__restrict msg_ptr, size_t msg_len, #ifndef __NR_mq_timedreceive_time64 # define __NR_mq_timedreceive_time64 __NR_mq_timedreceive #endif - int ret = SYSCALL_CANCEL (mq_timedreceive_time64, mqdes, msg_ptr, msg_len, - msg_prio, abs_timeout); -#ifndef __ASSUME_TIME64_SYSCALLS - if (ret == 0 || errno != ENOSYS) - return ret; +#ifdef __ASSUME_TIME64_SYSCALLS + return SYSCALL_CANCEL (mq_timedreceive_time64, mqdes, msg_ptr, msg_len, + msg_prio, abs_timeout); +#else + bool is32bit = abs_timeout != NULL + ? in_time_t_range (abs_timeout->tv_sec) : true; + if (!is32bit) + { + int r = SYSCALL_CANCEL (mq_timedreceive_time64, mqdes, msg_ptr, msg_len, + msg_prio, abs_timeout); + if (r == 0 || errno != ENOSYS) + return r; + __set_errno (EOVERFLOW); + return -1; + } - struct timespec ts32; + struct timespec ts32, *pts32 = NULL; if (abs_timeout != NULL) { - if (! in_time_t_range (abs_timeout->tv_sec)) - { - __set_errno (EOVERFLOW); - return -1; - } - ts32 = valid_timespec64_to_timespec (*abs_timeout); + pts32 = &ts32; } - ret = SYSCALL_CANCEL (mq_timedreceive, mqdes, msg_ptr, msg_len, msg_prio, - abs_timeout != NULL ? &ts32 : NULL); + return SYSCALL_CANCEL (mq_timedreceive, mqdes, msg_ptr, msg_len, msg_prio, + pts32); #endif - - return ret; } #if __TIMESIZE != 64 From patchwork Thu Jun 17 11:51:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 1493422 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=e0jbcEG6; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4G5LL04lcSz9sRK for ; Thu, 17 Jun 2021 22:03:20 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 495DE3938C02 for ; Thu, 17 Jun 2021 12:03:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 495DE3938C02 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1623931398; bh=wxL+wuLse+5RJPiXxK/95JTd55PjtaKahV36/7G2LDo=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=e0jbcEG6eV35AvR/vHNYX80XgeExeo82As101HXh8+X5CCRLNENqat8w6UWGfjGG7 dlmuygJ4vSMuwaK3PhWTO4kmTHM9MTNQsNGzlZ49G+ATGT2n78OhK2saIwMODqfIzU TzqHKP2ViCWzO6DRBK3Qt6BZZ2+vCiqI/JhpbdAM= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qv1-xf2f.google.com (mail-qv1-xf2f.google.com [IPv6:2607:f8b0:4864:20::f2f]) by sourceware.org (Postfix) with ESMTPS id 3D8193894418 for ; Thu, 17 Jun 2021 11:51:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3D8193894418 Received: by mail-qv1-xf2f.google.com with SMTP id ct13so1259940qvb.12 for ; Thu, 17 Jun 2021 04:51:33 -0700 (PDT) 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:mime-version:content-transfer-encoding; bh=wxL+wuLse+5RJPiXxK/95JTd55PjtaKahV36/7G2LDo=; b=liEXYxqSlC5jaceC8rmiqEAHxf7J0nQFP+zki8k0PTE/37iA8cWG3f7ugcnYg9N7QF gVn8GIghRiEqHJeMH0KTn7a4Ke3RkUOIYEArW3TJjGYTkanNxDL8ar/kzekYN3M5O5xq CJGwPdfKeptedkjF23Zv4h2jLby0U8kwX+UvfuCEEzDKM1mVxO9iqWiAqXxkAnSa//4x KYRRe4jemNHao/2Eef5Ct1cA6fck+8nUtc84isvyyek7GC+rwOz5vC+d6rjkGeULt9Li eDxHE/68o92SiQO4bRiwfHYf4WczwjJzAI9lY1sw5/b83ST3hbJuitxvATqwPhTIT7Vq V4Vg== X-Gm-Message-State: AOAM530SXBjY6B4GfonUkqTS10AytkpQdMSJ8VJSbI+xXcQbs7AFeTGB ITir9VukOZOampuJq/glvsRg5Wd7vLgxPg== X-Google-Smtp-Source: ABdhPJzKSIxeHsWiYgrTy9SXSGrastLllBbeD6FtgT1gOpAgXfmnBHDarQ3TUo7kQ7/FnDgodBONEQ== X-Received: by 2002:a0c:f085:: with SMTP id g5mr5606434qvk.18.1623930692733; Thu, 17 Jun 2021 04:51:32 -0700 (PDT) Received: from birita.. ([177.194.59.218]) by smtp.googlemail.com with ESMTPSA id p12sm3016435qtw.61.2021.06.17.04.51.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 04:51:32 -0700 (PDT) To: libc-alpha@sourceware.org, Lukasz Majewski , Carlos O'Donell Subject: [PATCH 14/18] linux: Only use 64-bit syscall if required for mq_timedsend Date: Thu, 17 Jun 2021 08:51:00 -0300 Message-Id: <20210617115104.1359598-15-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210617115104.1359598-1-adhemerval.zanella@linaro.org> References: <20210617115104.1359598-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" For !__ASSUME_TIME64_SYSCALLS there is no need to issue a 64-bit syscall if the provided timeout fits in a 32-bit one. The 64-bit usage should be rare since the timeout is a relative one. Checked on i686-linux-gnu on a 4.15 kernel and on a 5.11 kernel (with and without --enable-kernel=5.1) and on x86_64-linux-gnu. Reviewed-by: Lukasz Majewski --- rt/tst-mqueue10.c | 10 ++++++++ sysdeps/unix/sysv/linux/mq_timedsend.c | 35 ++++++++++++++------------ 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/rt/tst-mqueue10.c b/rt/tst-mqueue10.c index 7fb53a1cae..18795808e0 100644 --- a/rt/tst-mqueue10.c +++ b/rt/tst-mqueue10.c @@ -54,6 +54,16 @@ do_test (void) support_delete_timer (timer); } + { + timer_t timer = support_create_timer (0, 100000000, false, NULL); + /* Fill the internal buffer first. */ + TEST_COMPARE (mq_timedsend (q, msg, sizeof (msg), 0, + &(struct timespec) { 0, 0 }), 0); + TEST_COMPARE (mq_timedsend (q, msg, sizeof (msg), 0, &ts), -1); + TEST_VERIFY (errno == EINTR || errno == EOVERFLOW); + support_delete_timer (timer); + } + mq_unlink (name); return 0; diff --git a/sysdeps/unix/sysv/linux/mq_timedsend.c b/sysdeps/unix/sysv/linux/mq_timedsend.c index 5f14ecb0bf..8fa8c010ad 100644 --- a/sysdeps/unix/sysv/linux/mq_timedsend.c +++ b/sysdeps/unix/sysv/linux/mq_timedsend.c @@ -29,30 +29,33 @@ __mq_timedsend_time64 (mqd_t mqdes, const char *msg_ptr, size_t msg_len, # ifndef __NR_mq_timedsend_time64 # define __NR_mq_timedsend_time64 __NR_mq_timedsend # endif - int ret = SYSCALL_CANCEL (mq_timedsend_time64, mqdes, msg_ptr, msg_len, - msg_prio, abs_timeout); -#ifndef __ASSUME_TIME64_SYSCALLS - if (ret == 0 || errno != ENOSYS) - return ret; +#ifdef __ASSUME_TIME64_SYSCALLS + return SYSCALL_CANCEL (mq_timedsend_time64, mqdes, msg_ptr, msg_len, + msg_prio, abs_timeout); +#else + bool is32bit = abs_timeout != NULL + ? in_time_t_range (abs_timeout->tv_sec) : true; + if (!is32bit) + { + int r = SYSCALL_CANCEL (mq_timedsend_time64, mqdes, msg_ptr, msg_len, + msg_prio, abs_timeout); + if (r == 0 || errno != ENOSYS) + return r; + __set_errno (EOVERFLOW); + return -1; + } - struct timespec ts32; + struct timespec ts32, *pts32 = NULL; if (abs_timeout != NULL) { - if (! in_time_t_range (abs_timeout->tv_sec)) - { - __set_errno (EOVERFLOW); - return -1; - } - ts32 = valid_timespec64_to_timespec (*abs_timeout); + pts32 = &ts32; } - ret = SYSCALL_CANCEL (mq_timedsend, mqdes, msg_ptr, msg_len, msg_prio, - abs_timeout != NULL ? &ts32 : NULL); + return SYSCALL_CANCEL (mq_timedsend, mqdes, msg_ptr, msg_len, msg_prio, + pts32); #endif - - return ret; } #if __TIMESIZE != 64 From patchwork Thu Jun 17 11:51:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 1493423 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=d0NJ3LSe; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4G5LLy4R0Mz9sT6 for ; Thu, 17 Jun 2021 22:04:10 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0D4583938C20 for ; Thu, 17 Jun 2021 12:04:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0D4583938C20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1623931448; bh=p/vknGMi9cEu+5RVgPEoKUMJ4h/QkhIH74PMzM58fyI=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=d0NJ3LSehQqC4t5NF/UW35n4UdwHkfxw5iiSSH7LczkDUkJF6m4oAzxHNrf4Sl35y COhwaHuvZYKEKvbP4aS4aiqdBU36xmippKmBsoybCImr8Y83QXy1qmE9jsp+2BLgjN wr/6tdQb3feLMEIUYdmuLu+zxQJxUCt53/bgiEiY= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x72e.google.com (mail-qk1-x72e.google.com [IPv6:2607:f8b0:4864:20::72e]) by sourceware.org (Postfix) with ESMTPS id C95EC3893C44 for ; Thu, 17 Jun 2021 11:51:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C95EC3893C44 Received: by mail-qk1-x72e.google.com with SMTP id c138so2778140qkg.5 for ; Thu, 17 Jun 2021 04:51:34 -0700 (PDT) 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:mime-version:content-transfer-encoding; bh=p/vknGMi9cEu+5RVgPEoKUMJ4h/QkhIH74PMzM58fyI=; b=IRbyfoZyYw7IISxNmeDAqF1Y9Ua8JMVdg0wquhEAGm3L5PIeeAqD6U7+xGxgAoAlyQ LE+UqIQnJjHSzdHHGFVPf7E/r9BNwcVCydWQi2hFS0vPh9YyMmgXb4jL/FLhpq4Qbnam TnibEhaoKqDtrpZZF/WPzXnxHU2GuihCW3omo2eGbzykfOFhZCeqwJ9IXpYRLHKAHOim ASQJ6J550mRYwGWztGVe34y9F3N2NL/5gCisTIFwCV/cgtQamfWsyeNs++jfhuTiadDu aaVrC+vyhc/H7oPX68Vsx4c7LwcKQsuLKCeBiYF0KWUVwGs3JS7RUnF7ozb6fCXBYGVf 1GYw== X-Gm-Message-State: AOAM532O1qsEeyGsBWPUWQRu0KO6NlgFp7964iKdKJ3Y/z//QdiVwXNR AmNKzPNJi2ZsZLSzJUQvSt/pG583AZJ6gw== X-Google-Smtp-Source: ABdhPJyesOZV27eQy3vl7sVPS9sqvJ+XLDg+8TocnNNkzS4dHGKnFuGmp5wtkN3r92SkaEoxSUIQ5w== X-Received: by 2002:a05:620a:5b5:: with SMTP id q21mr3360161qkq.58.1623930694280; Thu, 17 Jun 2021 04:51:34 -0700 (PDT) Received: from birita.. ([177.194.59.218]) by smtp.googlemail.com with ESMTPSA id p12sm3016435qtw.61.2021.06.17.04.51.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 04:51:34 -0700 (PDT) To: libc-alpha@sourceware.org, Lukasz Majewski , Carlos O'Donell Subject: [PATCH 15/18] linux: Only use 64-bit syscall if required for sigtimedwait Date: Thu, 17 Jun 2021 08:51:01 -0300 Message-Id: <20210617115104.1359598-16-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210617115104.1359598-1-adhemerval.zanella@linaro.org> References: <20210617115104.1359598-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" For !__ASSUME_TIME64_SYSCALLS there is no need to issue a 64-bit syscall if the provided timeout fits in a 32-bit one. The 64-bit usage should be rare since the timeout is a relative one. Checked on i686-linux-gnu on a 4.15 kernel and on a 5.11 kernel (with and without --enable-kernel=5.1) and on x86_64-linux-gnu. --- sysdeps/unix/sysv/linux/Makefile | 2 ++ sysdeps/unix/sysv/linux/sigtimedwait.c | 26 ++++++++++++++-------- sysdeps/unix/sysv/linux/tst-sigtimedwait.c | 18 +++++++++++++++ 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index 2e5b5e1dc4..9a65fc39c0 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -145,6 +145,8 @@ endif $(objpfx)tst-ppoll: $(librt) $(objpfx)tst-ppoll-time64: $(librt) +$(objpfx)tst-sigtimedwait: $(librt) +$(objpfx)tst-sigtimedwait-time64: $(librt) $(objpfx)tst-timerfd: $(librt) $(objpfx)tst-timerfd-time64: $(librt) diff --git a/sysdeps/unix/sysv/linux/sigtimedwait.c b/sysdeps/unix/sysv/linux/sigtimedwait.c index 25ed0adb0d..bae9bf44bc 100644 --- a/sysdeps/unix/sysv/linux/sigtimedwait.c +++ b/sysdeps/unix/sysv/linux/sigtimedwait.c @@ -25,20 +25,28 @@ __sigtimedwait64 (const sigset_t *set, siginfo_t *info, #ifndef __NR_rt_sigtimedwait_time64 # define __NR_rt_sigtimedwait_time64 __NR_rt_sigtimedwait #endif - int result = SYSCALL_CANCEL (rt_sigtimedwait_time64, set, info, timeout, - __NSIG_BYTES); -#ifndef __ASSUME_TIME64_SYSCALLS - if (result != 0 && errno == ENOSYS) + int result; +#ifdef __ASSUME_TIME64_SYSCALLS + result = SYSCALL_CANCEL (rt_sigtimedwait_time64, set, info, timeout, + __NSIG_BYTES); +#else + bool is32bit = timeout != NULL + ? in_time_t_range (timeout->tv_sec) : true; + if (!is32bit) + { + result = SYSCALL_CANCEL (rt_sigtimedwait_time64, set, info, timeout, + __NSIG_BYTES); + if (result == 0 || errno != ENOSYS) + return result; + __set_errno (EOVERFLOW); + return -1; + } + else { struct timespec ts32, *pts32 = NULL; if (timeout != NULL) { - if (! in_time_t_range (timeout->tv_sec)) - { - __set_errno (EINVAL); - return -1; - } ts32 = valid_timespec64_to_timespec (*timeout); pts32 = &ts32; } diff --git a/sysdeps/unix/sysv/linux/tst-sigtimedwait.c b/sysdeps/unix/sysv/linux/tst-sigtimedwait.c index 973fb5d301..a8b9893c61 100644 --- a/sysdeps/unix/sysv/linux/tst-sigtimedwait.c +++ b/sysdeps/unix/sysv/linux/tst-sigtimedwait.c @@ -17,11 +17,13 @@ . */ #include +#include #include #include #include #include #include +#include #include static int @@ -47,6 +49,20 @@ test_sigtimedwait_timeout (bool zero_tmo) return 0; } +static void +test_sigtimedwait_large_timeout (void) +{ + support_create_timer (0, 100000000, false, NULL); + struct timespec ts = { TYPE_MAXIMUM (time_t), 0 }; + + sigset_t ss_usr1; + sigemptyset (&ss_usr1); + sigaddset (&ss_usr1, SIGUSR1); + + TEST_COMPARE (sigtimedwait (&ss_usr1, NULL, &ts), -1); + TEST_VERIFY (errno == EINTR || errno == EOVERFLOW); +} + static int do_test (void) { @@ -56,6 +72,8 @@ do_test (void) /* Check if sigtimedwait exits after specified timeout. */ test_sigtimedwait_timeout (false); + test_sigtimedwait_large_timeout (); + return 0; } From patchwork Thu Jun 17 11:51:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 1493424 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=WFvRdfYq; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4G5LMp45lSz9sRf for ; Thu, 17 Jun 2021 22:04:54 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3C37A393A411 for ; Thu, 17 Jun 2021 12:04:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3C37A393A411 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1623931492; bh=M4MW3vSSsGi+lkE3F0xq35Lp7GhotaDGe3fAiS70ci0=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=WFvRdfYqcjsmQ1NKBO+Xj5Xp6s2Dv63mW0bJDuEeRSn/BM9zJZFGCJQ6aPxcATLdZ 6Bp4wdn+N8EoqXdJ3DyT20aFDDNoNkOEo8KoNSxgK96GkEataN6iAKvU0JJLyFwjZV LGGRqJgxirX1UlMdzZPRMJ6kCmHwVyBLCS97RS1I= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qv1-xf2a.google.com (mail-qv1-xf2a.google.com [IPv6:2607:f8b0:4864:20::f2a]) by sourceware.org (Postfix) with ESMTPS id 5CA953893670 for ; Thu, 17 Jun 2021 11:51:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5CA953893670 Received: by mail-qv1-xf2a.google.com with SMTP id x6so1466383qvx.4 for ; Thu, 17 Jun 2021 04:51:36 -0700 (PDT) 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:mime-version:content-transfer-encoding; bh=M4MW3vSSsGi+lkE3F0xq35Lp7GhotaDGe3fAiS70ci0=; b=e1R15oJE4qkDhFWVfqFUsGduCUqX3CJoyMxaH9BB/rIa/8oeJUlAAzKU+Yan9tRmKJ P2+C1hzw0e5MmWi7BWs72I6Oz0ubuEvzc9Fq48bE3c57hi9AMyGWjHoWpmgiCHUfFKAX 71uv18SwYm3FiHJnperjnUAEl/DUB8oggSFV67i+65vKbnQHFcwIgkjX3C8S0F4/X5/X tfJmhEpeOZB5ITOX0RvTmORkRNptbxSLcwecuQKd5MD6Cmcrb/pAvS6oYnXatRAZFW2m 5jutuBUVUXJVIZzva5vr3p48MkIvSAiyZ4rScGAKroVymvuHnUDYkSWASHXdMdp+w32h Wutw== X-Gm-Message-State: AOAM533FCod+qXsfjR8wH0873mzhBfaEDHWLXkiSfn8gLeiQYqaSI7RX n/B9jB68fmCXaXX6xDj+PwUhjm4qqCcdRQ== X-Google-Smtp-Source: ABdhPJyacWbzwkTf3iBdoizXm+t5KmYZy1u13heQSRQzsQ9uQ6XrulsvXApnjWxxJ12Dhar+HIO7nw== X-Received: by 2002:ad4:5561:: with SMTP id w1mr5530743qvy.47.1623930695855; Thu, 17 Jun 2021 04:51:35 -0700 (PDT) Received: from birita.. ([177.194.59.218]) by smtp.googlemail.com with ESMTPSA id p12sm3016435qtw.61.2021.06.17.04.51.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 04:51:35 -0700 (PDT) To: libc-alpha@sourceware.org, Lukasz Majewski , Carlos O'Donell Subject: [PATCH 16/18] linux: Only use 64-bit syscall if required for utimensat family Date: Thu, 17 Jun 2021 08:51:02 -0300 Message-Id: <20210617115104.1359598-17-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210617115104.1359598-1-adhemerval.zanella@linaro.org> References: <20210617115104.1359598-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" For !__ASSUME_TIME64_SYSCALLS there is no need to issue a 64-bit syscall if the provided timeout fits in a 32-bit one. The 64-bit usage should be rare since the timeout is a relative one. The large timeout are already tests by io/tst-utimensat-skeleton.c. Checked on i686-linux-gnu on a 4.15 kernel and on a 5.11 kernel (with and without --enable-kernel=5.1) and on x86_64-linux-gnu. Reviewed-by: Lukasz Majewski --- sysdeps/unix/sysv/linux/utimensat.c | 35 ++++++++++++++++++----------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/sysdeps/unix/sysv/linux/utimensat.c b/sysdeps/unix/sysv/linux/utimensat.c index 909a29762b..e79e4351d6 100644 --- a/sysdeps/unix/sysv/linux/utimensat.c +++ b/sysdeps/unix/sysv/linux/utimensat.c @@ -31,34 +31,43 @@ __utimensat64_helper (int fd, const char *file, #ifndef __NR_utimensat_time64 # define __NR_utimensat_time64 __NR_utimensat #endif - int ret = INLINE_SYSCALL_CALL (utimensat_time64, fd, file, &tsp64[0], flags); -#ifndef __ASSUME_TIME64_SYSCALLS - if (ret == 0 || errno != ENOSYS) - return ret; +#ifdef __ASSUME_TIME64_SYSCALLS + return INLINE_SYSCALL_CALL (utimensat_time64, fd, file, &tsp64[0], flags); +#else /* For UTIME_NOW and UTIME_OMIT the value of tv_sec field is ignored. */ -# define TS_VALID(ns) \ - ((((ns).tv_nsec == UTIME_NOW || (ns).tv_nsec == UTIME_OMIT) \ - || in_time_t_range ((ns).tv_sec))) +# define TS_SPECIAL(ts) \ + ((ts).tv_nsec == UTIME_NOW || (ts).tv_nsec == UTIME_OMIT) - if (tsp64 != NULL - && (!TS_VALID (tsp64[0]) || !TS_VALID (tsp64[1]))) + bool is32bit_t0 = tsp64 != NULL + ? TS_SPECIAL (tsp64[0]) + || in_time_t_range (tsp64[0].tv_sec) + : true; + bool is32bit_t1 = tsp64 != NULL + ? TS_SPECIAL (tsp64[1]) + || in_time_t_range (tsp64[1].tv_sec) + : true; + + if (!is32bit_t0 || !is32bit_t1) { + int r = INLINE_SYSCALL_CALL (utimensat_time64, fd, file, &tsp64[0], + flags); + if (r == 0 || errno != ENOSYS) + return r; __set_errno (EOVERFLOW); return -1; } - struct timespec tsp32[2]; + struct timespec tsp32[2], *ptsp32 = NULL; if (tsp64) { tsp32[0] = valid_timespec64_to_timespec (tsp64[0]); tsp32[1] = valid_timespec64_to_timespec (tsp64[1]); + ptsp32 = tsp32; } - ret = INLINE_SYSCALL_CALL (utimensat, fd, file, tsp64 ? &tsp32[0] : NULL, - flags); + return INLINE_SYSCALL_CALL (utimensat, fd, file, ptsp32, flags); #endif - return ret; } libc_hidden_def (__utimensat64_helper) From patchwork Thu Jun 17 11:51:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 1493426 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=ekoLOuAZ; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4G5LNf5VhYz9sRf for ; Thu, 17 Jun 2021 22:05:38 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 29FBF3938C1A for ; Thu, 17 Jun 2021 12:05:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 29FBF3938C1A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1623931536; bh=aamX2mJCUM2UOfO081QDbVpP30oU1VkUORJIMKTW5qQ=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=ekoLOuAZwOEGBThTflmlHXCnGZmN6jud5zZbzGeaJ8u9q5ge0OhV295MoxMqTp9UB car+ttSQlANmU3kptFVwGEPRaO4WVJnlWHFbcspxYaBIxjRxZQhAt8fSh+rZf6fq5T vttSmeJOaExSi36kPNc12Nn8vCmEsTC314gs4Etw= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x734.google.com (mail-qk1-x734.google.com [IPv6:2607:f8b0:4864:20::734]) by sourceware.org (Postfix) with ESMTPS id E8243385383A for ; Thu, 17 Jun 2021 11:51:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E8243385383A Received: by mail-qk1-x734.google.com with SMTP id c138so2778265qkg.5 for ; Thu, 17 Jun 2021 04:51:37 -0700 (PDT) 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:mime-version:content-transfer-encoding; bh=aamX2mJCUM2UOfO081QDbVpP30oU1VkUORJIMKTW5qQ=; b=dyMExEB5EZneLM6N+AwwvRejJ+jRQ0lS2Yodz+nPruP+ul+29grG8iBpQZE2rLqxpk R4iJPoFxlzeCM7bULGJaWGYIHT2ODt1zyoYan/Xb7XMk/hkIwajAr+Y4E9paenoPMx9v mQ68wTItkoa0hJjp061JP8NBukVc7++HtReUS/KopmbL5vlt9vJ+e9kC1BXFLEO/ngvo JYfD/p1M/G4a22rJcU3s4EshDcPwErU4aqZQH5XCpu53MZ6ouKYa7TLdH5K7Wh7k7ikS 1pnjl2afKIo91B0CMwS4rnvSa0YQoWldMK5F0THlfToYCld1cVROt2ErmO2qET11bpQn TbZw== X-Gm-Message-State: AOAM532QAQRFDMttijamYDVfHn9nZJP/uFpOOrVl+OMRrOtDds8GswIQ gBtNkTboCJbvhQAalH9Z47gUaWtl/p9tmw== X-Google-Smtp-Source: ABdhPJzwjLDMIupouEQMMj2kfYfwkILtl5vP4xbC3pINMLX58SqrWCgxgbTyy6vEcH8e+iXBwfh0bw== X-Received: by 2002:ae9:ed02:: with SMTP id c2mr3414689qkg.128.1623930697419; Thu, 17 Jun 2021 04:51:37 -0700 (PDT) Received: from birita.. ([177.194.59.218]) by smtp.googlemail.com with ESMTPSA id p12sm3016435qtw.61.2021.06.17.04.51.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 04:51:37 -0700 (PDT) To: libc-alpha@sourceware.org, Lukasz Majewski , Carlos O'Donell Subject: [PATCH 17/18] linux: Only use 64-bit syscall if required for internal futex Date: Thu, 17 Jun 2021 08:51:03 -0300 Message-Id: <20210617115104.1359598-18-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210617115104.1359598-1-adhemerval.zanella@linaro.org> References: <20210617115104.1359598-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" For !__ASSUME_TIME64_SYSCALLS there is no need to issue a 64-bit syscall if the provided timeout fits in a 32-bit one. The 64-bit usage should be rare since the timeout is a relative one. Checked on i686-linux-gnu on a 4.15 kernel and on a 5.11 kernel (with and without --enable-kernel=5.1) and on x86_64-linux-gnu. Reviewed-by: Lukasz Majewski --- nptl/futex-internal.c | 52 +++++++++++++++++++++++------------ sysdeps/nptl/futex-internal.h | 24 ++++++++++------ 2 files changed, 50 insertions(+), 26 deletions(-) diff --git a/nptl/futex-internal.c b/nptl/futex-internal.c index 850bf4fd83..277e60986e 100644 --- a/nptl/futex-internal.c +++ b/nptl/futex-internal.c @@ -32,9 +32,6 @@ __futex_abstimed_wait_common32 (unsigned int* futex_word, struct timespec ts32, *pts32 = NULL; if (abstime != NULL) { - if (! in_time_t_range (abstime->tv_sec)) - return -EOVERFLOW; - ts32 = valid_timespec64_to_timespec (*abstime); pts32 = &ts32; } @@ -52,12 +49,28 @@ __futex_abstimed_wait_common32 (unsigned int* futex_word, static int __futex_abstimed_wait_common64 (unsigned int* futex_word, - unsigned int expected, clockid_t clockid, + unsigned int expected, int op, const struct __timespec64* abstime, int private, bool cancel) { - unsigned int clockbit; + if (cancel) + return INTERNAL_SYSCALL_CANCEL (futex_time64, futex_word, op, expected, + abstime, NULL /* Unused. */, + FUTEX_BITSET_MATCH_ANY); + else + return INTERNAL_SYSCALL_CALL (futex_time64, futex_word, op, expected, + abstime, NULL /* Ununsed. */, + FUTEX_BITSET_MATCH_ANY); +} + +static int +__futex_abstimed_wait_common (unsigned int* futex_word, + unsigned int expected, clockid_t clockid, + const struct __timespec64* abstime, + int private, bool cancel) +{ int err; + unsigned int clockbit; /* Work around the fact that the kernel rejects negative timeout values despite them being valid. */ @@ -70,16 +83,19 @@ __futex_abstimed_wait_common64 (unsigned int* futex_word, clockbit = (clockid == CLOCK_REALTIME) ? FUTEX_CLOCK_REALTIME : 0; int op = __lll_private_flag (FUTEX_WAIT_BITSET | clockbit, private); - if (cancel) - err = INTERNAL_SYSCALL_CANCEL (futex_time64, futex_word, op, expected, - abstime, NULL /* Unused. */, - FUTEX_BITSET_MATCH_ANY); +#ifdef __ASSUME_TIME64_SYSCALLS + err = __futex_abstimed_wait_common64 (futex_word, expected, op, abstime, + private, cancel); +#else + bool is32bit = abstime != NULL ? in_time_t_range (abstime->tv_sec) : true; + if (!is32bit) + { + err = __futex_abstimed_wait_common64 (futex_word, expected, op, abstime, + private, cancel); + if (err == -ENOSYS) + err = -EOVERFLOW; + } else - err = INTERNAL_SYSCALL_CALL (futex_time64, futex_word, op, expected, - abstime, NULL /* Ununsed. */, - FUTEX_BITSET_MATCH_ANY); -#ifndef __ASSUME_TIME64_SYSCALLS - if (err == -ENOSYS) err = __futex_abstimed_wait_common32 (futex_word, expected, op, abstime, private, cancel); #endif @@ -109,8 +125,8 @@ __futex_abstimed_wait64 (unsigned int* futex_word, unsigned int expected, clockid_t clockid, const struct __timespec64* abstime, int private) { - return __futex_abstimed_wait_common64 (futex_word, expected, clockid, - abstime, private, false); + return __futex_abstimed_wait_common (futex_word, expected, clockid, + abstime, private, false); } libc_hidden_def (__futex_abstimed_wait64) @@ -120,7 +136,7 @@ __futex_abstimed_wait_cancelable64 (unsigned int* futex_word, const struct __timespec64* abstime, int private) { - return __futex_abstimed_wait_common64 (futex_word, expected, clockid, - abstime, private, true); + return __futex_abstimed_wait_common (futex_word, expected, clockid, + abstime, private, true); } libc_hidden_def (__futex_abstimed_wait_cancelable64) diff --git a/sysdeps/nptl/futex-internal.h b/sysdeps/nptl/futex-internal.h index 969ab2bf4b..b54fdd44c1 100644 --- a/sysdeps/nptl/futex-internal.h +++ b/sysdeps/nptl/futex-internal.h @@ -254,15 +254,23 @@ static __always_inline int futex_lock_pi64 (int *futex_word, const struct __timespec64 *abstime, int private) { - int err = INTERNAL_SYSCALL_CALL (futex_time64, futex_word, - __lll_private_flag - (FUTEX_LOCK_PI, private), 0, abstime); -#ifndef __ASSUME_TIME64_SYSCALLS - if (err == -ENOSYS) + int err; +#ifdef __ASSUME_TIME64_SYSCALLS + err = INTERNAL_SYSCALL_CALL (futex_time64, futex_word, + __lll_private_flag (FUTEX_LOCK_PI, private), 0, + abstime); +#else + bool is32bit = abstime != NULL ? in_time_t_range (abstime->tv_sec) : true; + if (!is32bit) + { + err = INTERNAL_SYSCALL_CALL (futex_time64, futex_word, + __lll_private_flag (FUTEX_LOCK_PI, private), + 0, abstime); + if (err == -ENOSYS) + err = -EOVERFLOW; + } + else { - if (abstime != NULL && ! in_time_t_range (abstime->tv_sec)) - return EOVERFLOW; - struct timespec ts32; if (abstime != NULL) ts32 = valid_timespec64_to_timespec (*abstime); From patchwork Thu Jun 17 11:51:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 1493428 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=NwKuO5iq; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4G5LPV4K6Rz9sRf for ; Thu, 17 Jun 2021 22:06:22 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1F84B3939C23 for ; Thu, 17 Jun 2021 12:06:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1F84B3939C23 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1623931580; bh=zF1iKOoU1pLZtHHMQhlYyiw0IQ8qo5s3OunKYYepjWk=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=NwKuO5iqGll+g1s5jMFb0UGNIDk1HnSG50bYNzGJuV5TOumHlb+IJyLByrgVu2+K1 BfBTRqPm2tt1DLK36tW/lmGQBF6YP3xSI6UwMyAUOcABow0B7+sX8/BYM4K1YpvCRV ORmro9IpPqWVxKrkgT55YjZFYe7ZV7VYLn+dN7h4= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qt1-x834.google.com (mail-qt1-x834.google.com [IPv6:2607:f8b0:4864:20::834]) by sourceware.org (Postfix) with ESMTPS id 855FB3894C1E for ; Thu, 17 Jun 2021 11:51:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 855FB3894C1E Received: by mail-qt1-x834.google.com with SMTP id o20so4419660qtr.8 for ; Thu, 17 Jun 2021 04:51:39 -0700 (PDT) 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:mime-version:content-transfer-encoding; bh=zF1iKOoU1pLZtHHMQhlYyiw0IQ8qo5s3OunKYYepjWk=; b=BBbxswygg2zc33ypGLx3ljjjJWcWJAP2tWpLDL1I/X722OAOTYPjOIDt3P7Dln2dol /D7hAzVwRsIMZeQjjKjA4k4z13utjcGmiXGW/Sq3uGLvPGrGOfcU8wstUK/qI7J1cucn diBVnmYpVQnmly8CEVPqGI/OLyoQG+UUy3ZkOQ7hBKSSYT3CYS8+FxbaeI9AYVTiWVn/ 4DOmeoP7rBPA1PuIfTDKygfDSxKw9y0pf1P+i1/oUpi6BYiT/moD8+dZYwRVojY1J47P g3pk9JLLMYjGm+RtSHlEZdjpa4bTZ9lZXvuFsxFHj0jCBndUL0ccRC+Q1czzLcJIzKCF 0EzQ== X-Gm-Message-State: AOAM530sHV2YcJKCcJg1Ip/IQiIx6Jo3YwpsG8mKSsOQLz6ykxk0Yw8h XAa0PTHrdPqhKGXJqXeAjVES5gdXbXGM8w== X-Google-Smtp-Source: ABdhPJz2XoHvwbCv6euBD6mbVctaHAmuoY0B5kTEHq4/05SAeFdExEjE5umfBYkulBMfkzrj+vpKGg== X-Received: by 2002:ac8:5685:: with SMTP id h5mr4712191qta.255.1623930698988; Thu, 17 Jun 2021 04:51:38 -0700 (PDT) Received: from birita.. ([177.194.59.218]) by smtp.googlemail.com with ESMTPSA id p12sm3016435qtw.61.2021.06.17.04.51.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 04:51:38 -0700 (PDT) To: libc-alpha@sourceware.org, Lukasz Majewski , Carlos O'Donell Subject: [PATCH 18/18] linux: Only use 64-bit syscall if required for clock_nanosleep Date: Thu, 17 Jun 2021 08:51:04 -0300 Message-Id: <20210617115104.1359598-19-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210617115104.1359598-1-adhemerval.zanella@linaro.org> References: <20210617115104.1359598-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" For !__ASSUME_TIME64_SYSCALLS there is no need to issue a 64-bit syscall if the provided timeout fits in a 32-bit one. The 64-bit usage should be rare since the timeout is a relative one. Checked on i686-linux-gnu on a 4.15 kernel and on a 5.11 kernel (with and without --enable-kernel=5.1) and on x86_64-linux-gnu. Reviewed-by: Lukasz Majewski --- sysdeps/unix/sysv/linux/clock_nanosleep.c | 47 +++++++++++++---------- time/Makefile | 9 +++++ time/tst-clock_nanosleep.c | 40 +++++++++++-------- 3 files changed, 60 insertions(+), 36 deletions(-) diff --git a/sysdeps/unix/sysv/linux/clock_nanosleep.c b/sysdeps/unix/sysv/linux/clock_nanosleep.c index 007f1736cb..46b0f1e269 100644 --- a/sysdeps/unix/sysv/linux/clock_nanosleep.c +++ b/sysdeps/unix/sysv/linux/clock_nanosleep.c @@ -27,8 +27,9 @@ /* We can simply use the syscall. The CPU clocks are not supported with this function. */ int -__clock_nanosleep_time64 (clockid_t clock_id, int flags, const struct __timespec64 *req, - struct __timespec64 *rem) +__clock_nanosleep_time64 (clockid_t clock_id, int flags, + const struct __timespec64 *req, + struct __timespec64 *rem) { if (clock_id == CLOCK_THREAD_CPUTIME_ID) return EINVAL; @@ -37,33 +38,37 @@ __clock_nanosleep_time64 (clockid_t clock_id, int flags, const struct __timespec /* If the call is interrupted by a signal handler or encounters an error, it returns a positive value similar to errno. */ + #ifndef __NR_clock_nanosleep_time64 # define __NR_clock_nanosleep_time64 __NR_clock_nanosleep #endif - int r = INTERNAL_SYSCALL_CANCEL (clock_nanosleep_time64, clock_id, - flags, req, rem); - -#ifndef __ASSUME_TIME64_SYSCALLS - if (r == 0 || r != -ENOSYS) - return -r; - if (! in_time_t_range (req->tv_sec)) + int r; +#ifdef __ASSUME_TIME64_SYSCALLS + r = INTERNAL_SYSCALL_CANCEL (clock_nanosleep_time64, clock_id, flags, req, + rem); +#else + bool is32bit = in_time_t_range (req->tv_sec); + if (!is32bit) { - __set_errno (EOVERFLOW); - return -1; + r = INTERNAL_SYSCALL_CANCEL (clock_nanosleep_time64, clock_id, flags, + req, rem); + if (r == -ENOSYS) + r = -EOVERFLOW; } - - struct timespec tr32; - struct timespec ts32 = valid_timespec64_to_timespec (*req); - r = INTERNAL_SYSCALL_CANCEL (clock_nanosleep, clock_id, flags, - &ts32, &tr32); - if (INTERNAL_SYSCALL_ERROR_P (r)) + else { - if (r == -EINTR && rem != NULL && (flags & TIMER_ABSTIME) == 0) - *rem = valid_timespec_to_timespec64 (tr32); + struct timespec tr32; + struct timespec ts32 = valid_timespec64_to_timespec (*req); + r = INTERNAL_SYSCALL_CANCEL (clock_nanosleep, clock_id, flags, &ts32, + &tr32); + if (INTERNAL_SYSCALL_ERROR_P (r)) + { + if (r == -EINTR && rem != NULL && (flags & TIMER_ABSTIME) == 0) + *rem = valid_timespec_to_timespec64 (tr32); + } } -#endif /* __ASSUME_TIME64_SYSCALLS */ - +#endif return -r; } diff --git a/time/Makefile b/time/Makefile index c84bd5d3ec..0bea84966c 100644 --- a/time/Makefile +++ b/time/Makefile @@ -86,6 +86,15 @@ $(objpfx)tst-strftime2.out: $(gen-locales) $(objpfx)tst-strftime3.out: $(gen-locales) endif +ifeq (yes,$(build-shared)) +librt = $(common-objpfx)rt/librt.so +else +librt = $(common-objpfx)rt/librt.a +endif + +$(objpfx)tst-clock_nanosleep: $(librt) +$(objpfx)tst-clock_nanosleep-time64: $(librt) + tz-cflags = -DTZDIR='"$(zonedir)"' \ -DTZDEFAULT='"$(localtime-file)"' \ -DTZDEFRULES='"$(posixrules-file)"' diff --git a/time/tst-clock_nanosleep.c b/time/tst-clock_nanosleep.c index 47537435c1..a5a7f9430a 100644 --- a/time/tst-clock_nanosleep.c +++ b/time/tst-clock_nanosleep.c @@ -20,38 +20,48 @@ #include #include #include - +#include +#include +#include /* Test that clock_nanosleep() does sleep. */ -static int -do_test (void) +static void +clock_nanosleep_test (void) { /* Current time. */ struct timeval tv1; - (void) gettimeofday (&tv1, NULL); + gettimeofday (&tv1, NULL); - struct timespec ts; - ts.tv_sec = 1; - ts.tv_nsec = 0; + struct timespec ts = { 1, 0 }; TEMP_FAILURE_RETRY (clock_nanosleep (CLOCK_REALTIME, 0, &ts, &ts)); /* At least one second must have passed. */ struct timeval tv2; - (void) gettimeofday (&tv2, NULL); + gettimeofday (&tv2, NULL); tv2.tv_sec -= tv1.tv_sec; tv2.tv_usec -= tv1.tv_usec; if (tv2.tv_usec < 0) --tv2.tv_sec; - if (tv2.tv_sec < 1) - { - puts ("clock_nanosleep didn't sleep long enough"); - return 1; - } + TEST_VERIFY (tv2.tv_sec >= 1); +} + +static void +clock_nanosleep_large_timeout (void) +{ + support_create_timer (0, 100000000, false, NULL); + struct timespec ts = { TYPE_MAXIMUM (time_t), 0 }; + int r = clock_nanosleep (CLOCK_REALTIME, 0, &ts, NULL); + TEST_VERIFY (r == EINTR || r == EOVERFLOW); +} +static int +do_test (void) +{ + clock_nanosleep_test (); + clock_nanosleep_large_timeout (); return 0; } -#define TEST_FUNCTION do_test () -#include "../test-skeleton.c" +#include