From patchwork Thu Sep 7 22:41:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Albert ARIBAUD X-Patchwork-Id: 22716 Received: (qmail 65283 invoked by alias); 7 Sep 2017 22:43:04 -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 65170 invoked by uid 89); 7 Sep 2017 22:43:04 -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 08/52] Y2038: add function __clock_settime64 Date: Fri, 8 Sep 2017 00:41:35 +0200 Message-Id: <20170907224219.12483-9-albert.aribaud@3adev.fr> In-Reply-To: <20170907224219.12483-8-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> Signed-off-by: Albert ARIBAUD (3ADEV) --- include/time.h | 2 ++ sysdeps/unix/clock_settime.c | 56 ++++++++++++++++++++++++++++++++- sysdeps/unix/sysv/linux/arm/Versions | 1 + sysdeps/unix/sysv/linux/clock_settime.c | 23 ++++++++++++++ 4 files changed, 81 insertions(+), 1 deletion(-) diff --git a/include/time.h b/include/time.h index eeefbb4e98..63237e23f4 100644 --- a/include/time.h +++ b/include/time.h @@ -50,6 +50,8 @@ extern __typeof (clock_getcpuclockid) __clock_getcpuclockid; extern int __clock_gettime64 (clockid_t __clock_id, struct __timespec64 *__tp) __THROW; +extern int __clock_settime64 (clockid_t __clock_id, + const struct __timespec64 *__tp) __THROW; /* Now define the internal interfaces. */ struct tm; diff --git a/sysdeps/unix/clock_settime.c b/sysdeps/unix/clock_settime.c index e744cae6a9..8d7de2a310 100644 --- a/sysdeps/unix/clock_settime.c +++ b/sysdeps/unix/clock_settime.c @@ -68,8 +68,62 @@ hp_timing_settime (clockid_t clock_id, const struct timespec *tp) } #endif +/* Set CLOCK to value TP, 64-bit Y2038-safe version. */ +int +__clock_settime64 (clockid_t clock_id, const struct __timespec64 *tp) +{ + int retval = EOVERFLOW; + + /* Make sure the time cvalue is OK. */ + if (tp->tv_nsec < 0 || tp->tv_nsec >= 1000000000) + { + __set_errno (EINVAL); + return -1; + } + + switch (clock_id) + { +#define HANDLE_REALTIME \ + do { \ + struct timeval tv; \ + TIMESPEC_TO_TIMEVAL (&tv, tp); \ + \ + retval = settimeofday (&tv, NULL); \ + } while (0) + +#ifdef SYSDEP_SETTIME64 + SYSDEP_SETTIME64; +#endif + +#ifndef HANDLED_REALTIME + case CLOCK_REALTIME: + HANDLE_REALTIME; + break; +#endif + + default: +#ifdef SYSDEP_SETTIME64_CPU + SYSDEP_SETTIME64_CPU; +#endif +#ifndef HANDLED_CPUTIME +# if HP_TIMING_AVAIL + if (CPUCLOCK_WHICH (clock_id) == CLOCK_PROCESS_CPUTIME_ID + || CPUCLOCK_WHICH (clock_id) == CLOCK_THREAD_CPUTIME_ID) + retval = hp_timing_settime (clock_id, tp); + else +# endif + { + __set_errno (EINVAL); + retval = -1; + } +#endif + break; + } + + return retval; +} -/* Set CLOCK to value TP. */ +/* Set CLOCK to value TP, 64-bit Y2038-unsafe version. */ int __clock_settime (clockid_t clock_id, const struct timespec *tp) { diff --git a/sysdeps/unix/sysv/linux/arm/Versions b/sysdeps/unix/sysv/linux/arm/Versions index a2655d6262..553cdd7543 100644 --- a/sysdeps/unix/sysv/linux/arm/Versions +++ b/sysdeps/unix/sysv/linux/arm/Versions @@ -30,5 +30,6 @@ libc { __clock_gettime64; __vdso_clock_gettime64; __y2038_kernel_support; + __clock_settime64; } } diff --git a/sysdeps/unix/sysv/linux/clock_settime.c b/sysdeps/unix/sysv/linux/clock_settime.c index 058c518e5a..40760ff494 100644 --- a/sysdeps/unix/sysv/linux/clock_settime.c +++ b/sysdeps/unix/sysv/linux/clock_settime.c @@ -35,4 +35,27 @@ #define SYSDEP_SETTIME_CPU \ retval = INLINE_SYSCALL (clock_settime, 2, clock_id, tp) +/* 64-bit time version */ + +extern int __y2038_linux_support; + +#define SYSDEP_SETTIME64 \ + case CLOCK_REALTIME: \ + if (__y2038_linux_support) \ + { \ + struct __timespec64 ts64; \ + ts64.tv_sec = tp->tv_sec; \ + ts64.tv_nsec = tp->tv_nsec; \ + ts64.tv_pad = 0; \ + retval = INLINE_SYSCALL (clock_settime64, 2, clock_id, &ts64); \ + } \ + else if (tp->tv_sec <= INT_MAX) \ + { \ + struct timespec ts32; \ + ts32.tv_sec = tp->tv_sec; \ + ts32.tv_nsec = tp->tv_nsec; \ + retval = INLINE_SYSCALL (clock_settime, 2, clock_id, &ts32); \ + } \ + break + #include