From patchwork Mon Feb 3 18:31: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: 1232968 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=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-109129-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=wdc.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha1 header.s=default header.b=mVyulxh4; dkim=pass (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=hQn3IJkZ; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48BGnF4Kc2z9sRK for ; Tue, 4 Feb 2020 05:38:57 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; q=dns; s= default; b=nM+vAmurG2oUgoqcjaeHqrlkKQxihtTA2bWAp9wdURDo2yY28MC1E gvWGXRLSvy4tBcZHlE0UIDrxBrlUzp+b4cyNbZW2E1rYZHktFqT4U5KXMkXX/ZWx H8a6FHcNlHXz5qXhEqtGt34rmzyccAM/ZFc+s6RcXkoJg2e7JKXL2M= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; s=default; bh=oXS6L/B++Z3S2C1o8CpPlKQjmWQ=; b=mVyulxh4CJ85xHTqxrvWLeubuywR RY31q16pqgkfAqCCPoOB9vM4fr4EhosnJ0W7PNLeQ+BNEAKuTOaxpY40A64dfjRr SQBu/neiueC7fnntQ25Oe66izW7Zeye+wMz4B3uRcuNzHFXEv3ElfoCRjhj+4VVW 39cusT+z526aqrw= Received: (qmail 24511 invoked by alias); 3 Feb 2020 18:38:44 -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 24314 invoked by uid 89); 3 Feb 2020 18:38:43 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.6 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=1580755122; x=1612291122; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kP4bNIW271AJtaXfqnO4HEqg4KTH7NFIKmsYZdN6iYM=; b=hQn3IJkZr/xM09v+zHm8LJT4+86wYgOyaO/rvin9jUg4fsUwSFXid5Ga /+fr3auzzn6x4J2CEUeV6p9iuBdaXZ3v0v15JJYTwEjHhpikcE0668v4d P8VU16S/4eA+dyKbzDCweIZjPzysaDLdl3FlSVE8Hy6FdBbz67+CqYLAo wbcGFZPqeOPbQGp9m9r/+epKdu8InzPRp3PbxAZVH8CtdEYI5nQ46pg/M pVE8Ef0FUzTUXru8X3zv0epsVMlv/Mz3ar1TCnq5w09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-alpha@sourceware.org Cc: alistair23@gmail.com, lukma@denx.de, Alistair Francis Subject: [PATCH 2/6] time: Add a timeval with a long tv_sec and tv_usec Date: Mon, 3 Feb 2020 10:31:49 -0800 Message-Id: <20200203183153.11635-3-alistair.francis@wdc.com> In-Reply-To: <20200203183153.11635-1-alistair.francis@wdc.com> References: <20200203183153.11635-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 timeval_long struct to be used internally. --- include/time.h | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/include/time.h b/include/time.h index d425c69ede..c2c05bb671 100644 --- a/include/time.h +++ b/include/time.h @@ -388,6 +388,49 @@ timespec64_to_timeval64 (const struct __timespec64 ts64) return tv64; } +/* A version of 'struct timeval' with `long` time_t + and suseconds_t. */ +struct __timeval32 +{ + long tv_sec; /* Seconds. */ + long tv_usec; /* Microseconds. */ +}; + +/* Conversion functions for converting to/from __timeval32 +. If the seconds field of a __timeval32 would + overflow, they write { INT32_MAX, 999999 } to the output. */ +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) +{ + if (__glibc_unlikely (tv64.tv_sec > (time_t) 2147483647)) + return (struct __timeval32) { 2147483647, 999999}; + 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 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