[03/10] y2038: Provide conversion helpers for struct __timex64

Message ID 20200426133110.5312-4-lukma@denx.de
State New
Headers show
Series
  • y2038: Convert clock_adjtime related syscalls to support 64 bit time
Related show

Commit Message

Lukasz Majewski April 26, 2020, 1:31 p.m.
Those functions allow easy conversion between Y2038 safe, glibc internal
struct __timex64 and struct timex.

Those functions are put in Linux specific sys/timex.h file, as putting
them into glibc's local include/time.h would cause build break on HURD as
it doesn't support struct timex related syscalls.

Build tests:
./src/scripts/build-many-glibcs.py glibcs
---
 sysdeps/unix/sysv/linux/include/sys/timex.h | 61 +++++++++++++++++++++
 1 file changed, 61 insertions(+)

-- 
2.20.1

Comments

Michael Kerrisk \(man-pages\) via Libc-alpha April 27, 2020, 3:22 p.m. | #1
On Sun, Apr 26, 2020 at 6:31 AM Lukasz Majewski <lukma@denx.de> wrote:
>

> Those functions allow easy conversion between Y2038 safe, glibc internal

> struct __timex64 and struct timex.

>

> Those functions are put in Linux specific sys/timex.h file, as putting

> them into glibc's local include/time.h would cause build break on HURD as

> it doesn't support struct timex related syscalls.

>

> Build tests:

> ./src/scripts/build-many-glibcs.py glibcs


Reviewed-by: Alistair Francis <alistair.francis@wdc.com>


Alistair

> ---

>  sysdeps/unix/sysv/linux/include/sys/timex.h | 61 +++++++++++++++++++++

>  1 file changed, 61 insertions(+)

>

> diff --git a/sysdeps/unix/sysv/linux/include/sys/timex.h b/sysdeps/unix/sysv/linux/include/sys/timex.h

> index f25081639b..bab6b28920 100644

> --- a/sysdeps/unix/sysv/linux/include/sys/timex.h

> +++ b/sysdeps/unix/sysv/linux/include/sys/timex.h

> @@ -25,6 +25,7 @@

>

>  libc_hidden_proto (__adjtimex)

>

> +#  include <time.h>

>  #  include <struct___timeval64.h>

>  /* Local definition of 64 bit time supporting timex struct */

>  #  if __TIMESIZE == 64

> @@ -63,5 +64,65 @@ struct __timex64

>    int  :32; int  :32; int  :32;

>  };

>  #  endif

> +

> +/* Convert a known valid struct timex into a struct __timex64.  */

> +static inline struct __timex64

> +valid_timex_to_timex64 (const struct timex tx)

> +{

> +  struct __timex64 tx64;

> +

> +  tx64.modes = tx.modes;

> +  tx64.offset = tx.offset;

> +  tx64.freq = tx.freq;

> +  tx64.maxerror = tx.maxerror;

> +  tx64.esterror = tx.esterror;

> +  tx64.status = tx.status;

> +  tx64.constant = tx.constant;

> +  tx64.precision = tx.precision;

> +  tx64.tolerance = tx.tolerance;

> +  tx64.time = valid_timeval_to_timeval64 (tx.time);

> +  tx64.tick = tx.tick;

> +  tx64.ppsfreq = tx.ppsfreq;

> +  tx64.jitter = tx.jitter;

> +  tx64.shift = tx.shift;

> +  tx64.stabil = tx.stabil;

> +  tx64.jitcnt = tx.jitcnt;

> +  tx64.calcnt = tx.calcnt;

> +  tx64.errcnt = tx.errcnt;

> +  tx64.stbcnt = tx.stbcnt;

> +  tx64.tai = tx.tai;

> +

> +  return tx64;

> +}

> +

> +/* Convert a known valid struct __timex64 into a struct timex.  */

> +static inline struct timex

> +valid_timex64_to_timex (const struct __timex64 tx64)

> +{

> +  struct timex tx;

> +

> +  tx.modes = tx64.modes;

> +  tx.offset = tx64.offset;

> +  tx.freq = tx64.freq;

> +  tx.maxerror = tx64.maxerror;

> +  tx.esterror = tx64.esterror;

> +  tx.status = tx64.status;

> +  tx.constant = tx64.constant;

> +  tx.precision = tx64.precision;

> +  tx.tolerance = tx64.tolerance;

> +  tx.time = valid_timeval64_to_timeval (tx64.time);

> +  tx.tick = tx64.tick;

> +  tx.ppsfreq = tx64.ppsfreq;

> +  tx.jitter = tx64.jitter;

> +  tx.shift = tx64.shift;

> +  tx.stabil = tx64.stabil;

> +  tx.jitcnt = tx64.jitcnt;

> +  tx.calcnt = tx64.calcnt;

> +  tx.errcnt = tx64.errcnt;

> +  tx.stbcnt = tx64.stbcnt;

> +  tx.tai = tx64.tai;

> +

> +  return tx;

> +}

>  # endif /* _ISOMAC */

>  #endif /* sys/timex.h */

> --

> 2.20.1

>
Michael Kerrisk \(man-pages\) via Libc-alpha April 28, 2020, 3:56 p.m. | #2
On 26/04/2020 10:31, Lukasz Majewski wrote:
> Those functions allow easy conversion between Y2038 safe, glibc internal

> struct __timex64 and struct timex.

> 

> Those functions are put in Linux specific sys/timex.h file, as putting

> them into glibc's local include/time.h would cause build break on HURD as

> it doesn't support struct timex related syscalls.

> 

> Build tests:

> ./src/scripts/build-many-glibcs.py glibcs


LGTM, thanks.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>


> ---

>  sysdeps/unix/sysv/linux/include/sys/timex.h | 61 +++++++++++++++++++++

>  1 file changed, 61 insertions(+)

> 

> diff --git a/sysdeps/unix/sysv/linux/include/sys/timex.h b/sysdeps/unix/sysv/linux/include/sys/timex.h

> index f25081639b..bab6b28920 100644

> --- a/sysdeps/unix/sysv/linux/include/sys/timex.h

> +++ b/sysdeps/unix/sysv/linux/include/sys/timex.h

> @@ -25,6 +25,7 @@

>  

>  libc_hidden_proto (__adjtimex)

>  

> +#  include <time.h>

>  #  include <struct___timeval64.h>

>  /* Local definition of 64 bit time supporting timex struct */

>  #  if __TIMESIZE == 64

> @@ -63,5 +64,65 @@ struct __timex64

>    int  :32; int  :32; int  :32;

>  };

>  #  endif

> +

> +/* Convert a known valid struct timex into a struct __timex64.  */

> +static inline struct __timex64

> +valid_timex_to_timex64 (const struct timex tx)

> +{

> +  struct __timex64 tx64;

> +

> +  tx64.modes = tx.modes;

> +  tx64.offset = tx.offset;

> +  tx64.freq = tx.freq;

> +  tx64.maxerror = tx.maxerror;

> +  tx64.esterror = tx.esterror;

> +  tx64.status = tx.status;

> +  tx64.constant = tx.constant;

> +  tx64.precision = tx.precision;

> +  tx64.tolerance = tx.tolerance;

> +  tx64.time = valid_timeval_to_timeval64 (tx.time);

> +  tx64.tick = tx.tick;

> +  tx64.ppsfreq = tx.ppsfreq;

> +  tx64.jitter = tx.jitter;

> +  tx64.shift = tx.shift;

> +  tx64.stabil = tx.stabil;

> +  tx64.jitcnt = tx.jitcnt;

> +  tx64.calcnt = tx.calcnt;

> +  tx64.errcnt = tx.errcnt;

> +  tx64.stbcnt = tx.stbcnt;

> +  tx64.tai = tx.tai;

> +

> +  return tx64;

> +}

> +


Ok.

> +/* Convert a known valid struct __timex64 into a struct timex.  */

> +static inline struct timex

> +valid_timex64_to_timex (const struct __timex64 tx64)

> +{

> +  struct timex tx;

> +

> +  tx.modes = tx64.modes;

> +  tx.offset = tx64.offset;

> +  tx.freq = tx64.freq;

> +  tx.maxerror = tx64.maxerror;

> +  tx.esterror = tx64.esterror;

> +  tx.status = tx64.status;

> +  tx.constant = tx64.constant;

> +  tx.precision = tx64.precision;

> +  tx.tolerance = tx64.tolerance;

> +  tx.time = valid_timeval64_to_timeval (tx64.time);

> +  tx.tick = tx64.tick;

> +  tx.ppsfreq = tx64.ppsfreq;

> +  tx.jitter = tx64.jitter;

> +  tx.shift = tx64.shift;

> +  tx.stabil = tx64.stabil;

> +  tx.jitcnt = tx64.jitcnt;

> +  tx.calcnt = tx64.calcnt;

> +  tx.errcnt = tx64.errcnt;

> +  tx.stbcnt = tx64.stbcnt;

> +  tx.tai = tx64.tai;

> +

> +  return tx;

> +}

>  # endif /* _ISOMAC */

>  #endif /* sys/timex.h */

> 


Ok.

Patch

diff --git a/sysdeps/unix/sysv/linux/include/sys/timex.h b/sysdeps/unix/sysv/linux/include/sys/timex.h
index f25081639b..bab6b28920 100644
--- a/sysdeps/unix/sysv/linux/include/sys/timex.h
+++ b/sysdeps/unix/sysv/linux/include/sys/timex.h
@@ -25,6 +25,7 @@ 
 
 libc_hidden_proto (__adjtimex)
 
+#  include <time.h>
 #  include <struct___timeval64.h>
 /* Local definition of 64 bit time supporting timex struct */
 #  if __TIMESIZE == 64
@@ -63,5 +64,65 @@  struct __timex64
   int  :32; int  :32; int  :32;
 };
 #  endif
+
+/* Convert a known valid struct timex into a struct __timex64.  */
+static inline struct __timex64
+valid_timex_to_timex64 (const struct timex tx)
+{
+  struct __timex64 tx64;
+
+  tx64.modes = tx.modes;
+  tx64.offset = tx.offset;
+  tx64.freq = tx.freq;
+  tx64.maxerror = tx.maxerror;
+  tx64.esterror = tx.esterror;
+  tx64.status = tx.status;
+  tx64.constant = tx.constant;
+  tx64.precision = tx.precision;
+  tx64.tolerance = tx.tolerance;
+  tx64.time = valid_timeval_to_timeval64 (tx.time);
+  tx64.tick = tx.tick;
+  tx64.ppsfreq = tx.ppsfreq;
+  tx64.jitter = tx.jitter;
+  tx64.shift = tx.shift;
+  tx64.stabil = tx.stabil;
+  tx64.jitcnt = tx.jitcnt;
+  tx64.calcnt = tx.calcnt;
+  tx64.errcnt = tx.errcnt;
+  tx64.stbcnt = tx.stbcnt;
+  tx64.tai = tx.tai;
+
+  return tx64;
+}
+
+/* Convert a known valid struct __timex64 into a struct timex.  */
+static inline struct timex
+valid_timex64_to_timex (const struct __timex64 tx64)
+{
+  struct timex tx;
+
+  tx.modes = tx64.modes;
+  tx.offset = tx64.offset;
+  tx.freq = tx64.freq;
+  tx.maxerror = tx64.maxerror;
+  tx.esterror = tx64.esterror;
+  tx.status = tx64.status;
+  tx.constant = tx64.constant;
+  tx.precision = tx64.precision;
+  tx.tolerance = tx64.tolerance;
+  tx.time = valid_timeval64_to_timeval (tx64.time);
+  tx.tick = tx64.tick;
+  tx.ppsfreq = tx64.ppsfreq;
+  tx.jitter = tx64.jitter;
+  tx.shift = tx64.shift;
+  tx.stabil = tx64.stabil;
+  tx.jitcnt = tx64.jitcnt;
+  tx.calcnt = tx64.calcnt;
+  tx.errcnt = tx64.errcnt;
+  tx.stbcnt = tx64.stbcnt;
+  tx.tai = tx64.tai;
+
+  return tx;
+}
 # endif /* _ISOMAC */
 #endif /* sys/timex.h */