From patchwork Thu Sep 7 22:41:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Albert ARIBAUD X-Patchwork-Id: 22718 Received: (qmail 67233 invoked by alias); 7 Sep 2017 22:43:11 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 67133 invoked by uid 89); 7 Sep 2017 22:43:11 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy= X-HELO: smtp6-g21.free.fr From: "Albert ARIBAUD (3ADEV)" To: libc-alpha@sourceware.org Cc: "Albert ARIBAUD (3ADEV)" Subject: [RFC PATCH 10/52] Y2038: add function __clock_nanosleep64 Date: Fri, 8 Sep 2017 00:41:37 +0200 Message-Id: <20170907224219.12483-11-albert.aribaud@3adev.fr> In-Reply-To: <20170907224219.12483-10-albert.aribaud@3adev.fr> References: <20170907224219.12483-1-albert.aribaud@3adev.fr> <20170907224219.12483-2-albert.aribaud@3adev.fr> <20170907224219.12483-3-albert.aribaud@3adev.fr> <20170907224219.12483-4-albert.aribaud@3adev.fr> <20170907224219.12483-5-albert.aribaud@3adev.fr> <20170907224219.12483-6-albert.aribaud@3adev.fr> <20170907224219.12483-7-albert.aribaud@3adev.fr> <20170907224219.12483-8-albert.aribaud@3adev.fr> <20170907224219.12483-9-albert.aribaud@3adev.fr> <20170907224219.12483-10-albert.aribaud@3adev.fr> Signed-off-by: Albert ARIBAUD (3ADEV) --- include/time.h | 3 ++ sysdeps/unix/sysv/linux/arm/Versions | 1 + sysdeps/unix/sysv/linux/clock_nanosleep.c | 87 ++++++++++++++++++++++++++++++- 3 files changed, 90 insertions(+), 1 deletion(-) diff --git a/include/time.h b/include/time.h index 00bdb2853a..90c1385d13 100644 --- a/include/time.h +++ b/include/time.h @@ -54,6 +54,9 @@ extern int __clock_settime64 (clockid_t __clock_id, const struct __timespec64 *__tp) __THROW; extern int __clock_getres64 (clockid_t __clock_id, struct __timespec64 *__res) __THROW; +extern int __clock_nanosleep64 (clockid_t __clock_id, int __flags, + const struct __timespec64 *__req, + struct __timespec64 *__rem); /* Now define the internal interfaces. */ struct tm; diff --git a/sysdeps/unix/sysv/linux/arm/Versions b/sysdeps/unix/sysv/linux/arm/Versions index 4b03cce526..fd94c63672 100644 --- a/sysdeps/unix/sysv/linux/arm/Versions +++ b/sysdeps/unix/sysv/linux/arm/Versions @@ -32,5 +32,6 @@ libc { __y2038_kernel_support; __clock_settime64; __clock_getres64; + __clock_nanosleep64; } } diff --git a/sysdeps/unix/sysv/linux/clock_nanosleep.c b/sysdeps/unix/sysv/linux/clock_nanosleep.c index 93bc4cf47e..7d00176c3e 100644 --- a/sysdeps/unix/sysv/linux/clock_nanosleep.c +++ b/sysdeps/unix/sysv/linux/clock_nanosleep.c @@ -21,7 +21,6 @@ #include #include "kernel-posix-cpu-timers.h" - /* We can simply use the syscall. The CPU clocks are not supported with this function. */ int @@ -52,3 +51,89 @@ __clock_nanosleep (clockid_t clock_id, int flags, const struct timespec *req, ? INTERNAL_SYSCALL_ERRNO (r, err) : 0); } weak_alias (__clock_nanosleep, clock_nanosleep) + +/* 64-bit time version */ + +extern int __y2038_linux_support; + +int +__clock_nanosleep64 (clockid_t clock_id, int flags, + const struct __timespec64 *req, + struct __timespec64 *rem) +{ + INTERNAL_SYSCALL_DECL (err); + int r; + struct __timespec64 req64; + struct timespec req32, rem32; + + if (clock_id == CLOCK_THREAD_CPUTIME_ID) + return EINVAL; + if (clock_id == CLOCK_PROCESS_CPUTIME_ID) + clock_id = MAKE_PROCESS_CPUCLOCK (0, CPUCLOCK_SCHED); + + if (SINGLE_THREAD_P) + { + if (__y2038_linux_support) + { + req64.tv_sec = req->tv_sec; + req64.tv_nsec = req->tv_nsec; + req64.tv_pad = 0; + r = INTERNAL_SYSCALL (clock_nanosleep64, err, 4, clock_id, flags, + &req64, rem); + } + else if (req->tv_sec > INT_MAX) + r = EOVERFLOW; + else + { + req32.tv_sec = req->tv_sec; + req32.tv_nsec = req->tv_nsec; + r = INTERNAL_SYSCALL (clock_nanosleep, err, 4, clock_id, flags, + &req32, &rem32); + if (r == EINTR && rem != NULL && flags != TIMER_ABSTIME) + { + rem->tv_sec = rem32.tv_sec; + rem->tv_nsec = rem32.tv_nsec; + rem->tv_pad = 0; + } + } + } + else + { + int oldstate = LIBC_CANCEL_ASYNC (); + + if (__y2038_linux_support) + { + req64.tv_sec = req->tv_sec; + req64.tv_nsec = req->tv_nsec; + req64.tv_pad = 0; + r = INTERNAL_SYSCALL (clock_nanosleep64, err, 4, clock_id, flags, + &req64, rem); + } + else if (req->tv_sec > INT_MAX) + r = EOVERFLOW; + else + { + req32.tv_sec = req->tv_sec; + req32.tv_nsec = req->tv_nsec; + r = INTERNAL_SYSCALL (clock_nanosleep, err, 4, clock_id, flags, + &req32, &rem32); + if (r == EINTR && rem != NULL && flags != TIMER_ABSTIME) + { + rem->tv_sec = rem32.tv_sec; + rem->tv_nsec = rem32.tv_nsec; + rem->tv_pad = 0; + } + } + + LIBC_CANCEL_RESET (oldstate); + } + + if (INTERNAL_SYSCALL_ERROR_P (r, err)) + { + return INTERNAL_SYSCALL_ERRNO (r, err); + } + else + { + return 0; + } +}