From: Alistair Francis <alistair.francis@wdc.com>
To: libc-alpha@sourceware.org
Cc: adhemerval.zanella@linaro.org,
Alistair Francis <alistair.francis@wdc.com>,
Lukasz Majewski <lukma@denx.de>
Subject: [PATCH v5 2/8] time: Add a timeval with a 32-bit tv_sec and tv_usec
Date: Tue, 03 Mar 2020 18:01:00 -0000 [thread overview]
Message-ID: <20200303175355.15770-3-alistair.francis@wdc.com> (raw)
In-Reply-To: <20200303175355.15770-1-alistair.francis@wdc.com>
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 <lukma@denx.de>
---
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
--
2.25.1
next prev parent reply other threads:[~2020-03-03 18:01 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-03 18:01 [PATCH v5 0/8] Always use 32-bit time_t for certain syscalls Alistair Francis
2020-03-03 18:01 ` [PATCH v5 3/8] time: Add a __itimerval64 struct Alistair Francis
2020-03-27 17:01 ` Adhemerval Zanella
2020-03-03 18:01 ` [PATCH v5 8/8] sysv/alpha: Use generic __timeval32 and helpers Alistair Francis
2020-04-01 16:57 ` Adhemerval Zanella
2020-04-01 16:54 ` Alistair Francis
2020-03-03 18:01 ` [PATCH v5 4/8] sysv: Define __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64 Alistair Francis
2020-03-27 17:58 ` Adhemerval Zanella
2020-03-27 18:36 ` Alistair Francis
2020-03-03 18:01 ` [PATCH v5 5/8] linux: Use long time_t __getitimer/__setitimer Alistair Francis
2020-03-27 18:09 ` Adhemerval Zanella
2020-03-27 18:21 ` Alistair Francis
2020-03-03 18:01 ` [PATCH v5 1/8] sysv/linux: Rename alpha functions to be alpha specific Alistair Francis
2020-03-05 9:51 ` Lukasz Majewski
2020-03-05 21:38 ` Zack Weinberg
2020-03-09 22:16 ` Alistair Francis
2020-03-12 18:45 ` Alistair Francis
2020-03-18 19:46 ` Alistair Francis
2020-03-24 7:33 ` Lukasz Majewski
2020-03-24 23:58 ` Alistair Francis
2020-03-27 16:15 ` Adhemerval Zanella
2020-03-27 16:25 ` Alistair Francis
2020-03-27 16:46 ` Adhemerval Zanella
2020-03-03 18:01 ` [PATCH v5 7/8] linux: Use long time_t for wait4/getrusage Alistair Francis
2020-03-27 18:31 ` Adhemerval Zanella
2020-03-27 18:42 ` Alistair Francis
2020-04-04 14:52 ` Andreas Schwab
2020-03-03 18:01 ` [PATCH v5 6/8] resource: Add a __rusage64 struct Alistair Francis
2020-03-27 18:14 ` Adhemerval Zanella
2020-03-03 18:01 ` Alistair Francis [this message]
2020-03-27 17:00 ` [PATCH v5 2/8] time: Add a timeval with a 32-bit tv_sec and tv_usec Adhemerval Zanella
2020-04-04 13:58 ` [PATCH v5 0/8] Always use 32-bit time_t for certain syscalls Andreas Schwab
2020-04-06 13:24 ` Adhemerval Zanella
2020-04-06 14:03 ` Andreas Schwab
2020-04-06 16:16 ` Adhemerval Zanella
2020-04-06 17:07 ` Andreas Schwab
2020-04-06 17:34 ` Adhemerval Zanella
2020-04-06 17:43 ` Adhemerval Zanella
2020-04-06 17:48 ` Andreas Schwab
2020-04-06 17:45 ` Alistair Francis
2020-04-06 18:02 ` Alistair Francis
2020-04-06 18:21 ` Adhemerval Zanella
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200303175355.15770-3-alistair.francis@wdc.com \
--to=alistair.francis@wdc.com \
--cc=adhemerval.zanella@linaro.org \
--cc=libc-alpha@sourceware.org \
--cc=lukma@denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).