Message ID | 20200210174325.6566-3-alistair.francis@wdc.com |
---|---|
State | New |
Headers | show |
Series | Always use long time_t for certain syscalls | expand |
On Mon, 10 Feb 2020 09:43:21 -0800 Alistair Francis <alistair.francis@wdc.com> wrote: > 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. > --- > include/time.h | 41 +++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 41 insertions(+) > > diff --git a/include/time.h b/include/time.h > index 73f66277ac..f22abc13f4 100644 > --- a/include/time.h > +++ b/include/time.h > @@ -400,6 +400,47 @@ 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. */ Please update the above comment. > +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 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 Best regards, Lukasz Majewski -- DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma@denx.de
diff --git a/include/time.h b/include/time.h index 73f66277ac..f22abc13f4 100644 --- a/include/time.h +++ b/include/time.h @@ -400,6 +400,47 @@ 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) +{ + 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