From patchwork Thu Sep 7 22:41:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Albert ARIBAUD X-Patchwork-Id: 22714 Received: (qmail 62627 invoked by alias); 7 Sep 2017 22:42:55 -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 62541 invoked by uid 89); 7 Sep 2017 22:42:55 -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 06/52] Y2038: add struct __timespec64 Date: Fri, 8 Sep 2017 00:41:33 +0200 Message-Id: <20170907224219.12483-7-albert.aribaud@3adev.fr> In-Reply-To: <20170907224219.12483-6-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> To be Y2038-proof, struct __timespec64 needs its tv_sec field to be a __time64_t rather than a __time_t. However, the question is which type should the tv_nsec field be. Keeping tv_nsec a long (32-bit) would be compatible with Posix requirements but would result in the GLIBC struct timespec being binary-incompatible with the Linux 64-bit struct timespec, which contains a 64-bit, not 32-bit, signed tv_nsec field. In order to maintain Posix compatibility yet simplify conversion between Posix and Linux struct timespec values, the Y2038-proof struct time stores its tv_nsec field as a 32-bit signed integer plus a padding which can serve as a 64-bit sign extension. This both meets Posix requirements and makes the GLIBC and Linux struct timespec binary compatible. Note that in the API (which is not modified here, and will be later alongside all Y2038-sensitive APIs), this padding is made 'invisible' by defining it as an anonymous bitfield; whereas the struct __timespec64 introduced here has a named field for the padding, allowing implementations to read and write it. Signed-off-by: Albert ARIBAUD (3ADEV) --- include/time.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/include/time.h b/include/time.h index 79ab6ab6a1..c436c44539 100644 --- a/include/time.h +++ b/include/time.h @@ -4,6 +4,8 @@ #ifndef _ISOMAC # include +#include + extern __typeof (strftime_l) __strftime_l; libc_hidden_proto (__strftime_l) extern __typeof (strptime_l) __strptime_l; @@ -18,6 +20,22 @@ libc_hidden_proto (localtime) libc_hidden_proto (strftime) libc_hidden_proto (strptime) +#if BYTE_ORDER == BIG_ENDIAN +struct __timespec64 +{ + __time64_t tv_sec; /* Seconds */ + int tv_pad: 32; /* Padding named for checking/setting */ + __syscall_slong_t tv_nsec; /* Nanoseconds */ +}; +#else +struct __timespec64 +{ + __time64_t tv_sec; /* Seconds */ + __syscall_slong_t tv_nsec; /* Nanoseconds */ + int tv_pad: 32; /* Padding named for checking/setting */ +}; +#endif + extern __typeof (clock_getres) __clock_getres; extern __typeof (clock_gettime) __clock_gettime; libc_hidden_proto (__clock_gettime)