From patchwork Tue Mar 3 17:53:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 38385 Received: (qmail 130648 invoked by alias); 3 Mar 2020 18:01:19 -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 130414 invoked by uid 89); 3 Mar 2020 18:01:17 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy=HContent-Transfer-Encoding:8bit X-HELO: esa3.hgst.iphmx.com DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1583258477; x=1614794477; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=FRoRjXIBC6kFE1FHGrhDoFJWISABku6x8oXzDxiEUoE=; b=ScJ751OG2UIFhkqp2mmNYTnRD0bvBgsQyG6EjksvBFUd5HPX5JnfWz2e c80DPE9erDpeDn/f1oZbnVz9xLcP4anKsxybH2EufSHSnK0ZH0LXc50eA cLSPtwckVem2uNZSHD4W2znCq/HR4E2KyVRypOUzFrkHJH/rD1vzQBSWB A3bx1VAgxuCP+IbGybzpe/K6hhHwmuyfoRI5yqDF7QG7CXdU8iw2wE1YP 8itHBCUf14/xM2NT3WU5aolinkXX4IBT4eDYqpn2pXMVRH4rHusH/UFj3 +xc8E4JPFBayz9l0jtNNixtFGQcS9DGyJhC/AWbOyB21HYTlezsgUuh6i A==; IronPort-SDR: w/kh1dCVc0++ww91etzFh0OMi/Bc9sgK74SVthVHgB6kS0i8BgVvVmWru6oC/ikXRVdKC3e4Qi 3yOuFBgyyQgTcT6lrvMVwnow3Vyq4bRYpZvKPQ3JuJU2tOe5rNaG8UMLidw+VhICvoGsX2tukN mUfIpeMEwcqLNA2dnyCLz41gV1fdg85h4y+0hMvo7LoH9vG9SuSx2AqFDBybYf90XNzrDzvsY2 LGTZQp/X4fNKT389Iq2lbqWZdmyDfZgnoPBIQugWLMtcozcnD7kZoYNgG5bFx5zkRDry4nzFD6 37E= IronPort-SDR: Fkr5mtDJmFuVnYTSMi6fQ83YA+YNBd1ZzN9cq53TX7pNUGky5i29s6hWoAClj2JsOg1XiA5FE8 q4e71L3WThm4dUXwyyUsH3w0hiKQISAu1a/u0/iGUL6UpoVtr87opSdMd92NFe/wKgWzoi3k0Y fVtc0sXPaMJrBhCQnKgouuK8aVCeubGhq2zXcYROiCzZXXCjzcQx3rjOoa63fjJXMToozx94pM Bi1IlO6QXhgCs6Ci5TmcI4QFRCh4JBj5aN6sirC9Me8xybMWD7XD5eD5P/Yk17l51d93Rs/mwP 1QL6zqB/T3Y0eQndna3v/Pcb IronPort-SDR: 050OwnO4HISpAhSRLJlP3WHYtKpzsAUq3eyoyEh+kJHM8xbytnDohL+RNvC+JSMI2vzyHdL221 eRKBi10BuIYDGsZqLxJMcIETsxF0eUTeCCkZJAz2doZXhnuWXQpAPdvzBkmuyg2XgW12RLlUL1 5xZaOWTyIACItxaUawVZ4wugPlShuk+yclHk++1ZGBTo85VzCgbHpUezUffQiMJxz4G3TB/N6n uyQ8Vnn6CGbjMDM/U1Fqaun9Fd5dbItG5Fh77OTYYs7UWxy+tT7AYKtC7e2wY8qPT+9RJWYO+R Cb8= WDCIronportException: Internal From: Alistair Francis To: libc-alpha@sourceware.org Cc: adhemerval.zanella@linaro.org, Alistair Francis , Lukasz Majewski Subject: [PATCH v5 2/8] time: Add a timeval with a 32-bit tv_sec and tv_usec Date: Tue, 3 Mar 2020 09:53:49 -0800 Message-Id: <20200303175355.15770-3-alistair.francis@wdc.com> In-Reply-To: <20200303175355.15770-1-alistair.francis@wdc.com> References: <20200303175355.15770-1-alistair.francis@wdc.com> MIME-Version: 1.0 On y2038 safe 32-bit systems the Linux kernel expects itimerval to use a 32-bit time_t, even though the other time_t's are 64-bit. To address this let's add a __timeval32 struct to be used internally. Reviewed-by: Lukasz Majewski Reviewed-by: Adhemerval Zanella --- include/time.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/include/time.h b/include/time.h index 7737be1f7d..927b1ed587 100644 --- a/include/time.h +++ b/include/time.h @@ -422,6 +422,51 @@ timespec64_to_timeval64 (const struct __timespec64 ts64) return tv64; } +/* A version of 'struct timeval' with 32-bit time_t + and suseconds_t. */ +struct __timeval32 +{ + __int32_t tv_sec; /* Seconds. */ + __int32_t tv_usec; /* Microseconds. */ +}; + +/* Conversion functions for converting to/from __timeval32 */ +static inline struct __timeval64 +valid_timeval32_to_timeval64 (const struct __timeval32 tv) +{ + return (struct __timeval64) { tv.tv_sec, tv.tv_usec }; +} + +static inline struct __timeval32 +valid_timeval64_to_timeval32 (const struct __timeval64 tv64) +{ + return (struct __timeval32) { tv64.tv_sec, tv64.tv_usec }; +} + +static inline struct timeval +valid_timeval32_to_timeval (const struct __timeval32 tv) +{ + return (struct timeval) { tv.tv_sec, tv.tv_usec }; +} + +static inline struct __timeval32 +valid_timeval_to_timeval32 (const struct timeval tv) +{ + return (struct __timeval32) { tv.tv_sec, tv.tv_usec }; +} + +static inline struct timespec +valid_timeval32_to_timespec (const struct __timeval32 tv) +{ + return (struct timespec) { tv.tv_sec, tv.tv_usec * 1000 }; +} + +static inline struct __timeval32 +valid_timespec_to_timeval32 (const struct timespec ts) +{ + return (struct __timeval32) { (time_t) ts.tv_sec, ts.tv_nsec / 1000 }; +} + /* Check if a value is in the valid nanoseconds range. Return true if it is, false otherwise. */ static inline bool