[07/10] y2038: Introduce struct __ntptimeval64 - new internal glibc type

Message ID 20200426133110.5312-8-lukma@denx.de
State Superseded
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.
This type is a glibc's "internal" type to get time parameters data from
Linux kernel (NTP daemon interface). It stores time in struct __timeval64
rather than struct timeval, which makes it Y2038-proof.

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

-- 
2.20.1

Comments

Michael Kerrisk \(man-pages\) via Libc-alpha April 28, 2020, 6:41 p.m. | #1
On 26/04/2020 10:31, Lukasz Majewski wrote:
> @@ -69,6 +70,19 @@ extern int __clock_adjtime64 (const clockid_t clock_id, struct __timex64 *tx64);

>  libc_hidden_proto (__clock_adjtime64);

>  extern int ___adjtimex64 (struct __timex64 *tx64);

>  libc_hidden_proto (___adjtimex64)

> +

> +struct __ntptimeval64

> +{

> +  struct __timeval64 time;	/* current time (ro) */

> +  long int maxerror;	/* maximum error (us) (ro) */

> +  long int esterror;	/* estimated error (us) (ro) */

> +  long int tai;		/* TAI offset (ro) */

> +

> +  long int __glibc_reserved1;

> +  long int __glibc_reserved2;

> +  long int __glibc_reserved3;

> +  long int __glibc_reserved4;


Why does it need the extra reserved fields?

> +};

>  #  endif

>  

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

>
Lukasz Majewski April 29, 2020, 9:28 p.m. | #2
Hi Adhemerval,

> On 26/04/2020 10:31, Lukasz Majewski wrote:

> > @@ -69,6 +70,19 @@ extern int __clock_adjtime64 (const clockid_t

> > clock_id, struct __timex64 *tx64); libc_hidden_proto

> > (__clock_adjtime64); extern int ___adjtimex64 (struct __timex64

> > *tx64); libc_hidden_proto (___adjtimex64)

> > +

> > +struct __ntptimeval64

> > +{

> > +  struct __timeval64 time;	/* current time (ro) */

> > +  long int maxerror;	/* maximum error (us) (ro) */

> > +  long int esterror;	/* estimated error (us) (ro) */

> > +  long int tai;		/* TAI offset (ro) */

> > +

> > +  long int __glibc_reserved1;

> > +  long int __glibc_reserved2;

> > +  long int __glibc_reserved3;

> > +  long int __glibc_reserved4;  

> 

> Why does it need the extra reserved fields?


I've followed the definition of in-glibc ntptimeval definition in
sysdeps/unix/sysv/linux/sys/timex.h

As the __ntptimeval64 is not passed to the kernel (it gets its values
based on struct __timex64), IMHO it would be safe to remove them.

> 

> > +};

> >  #  endif

> >  

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

> >   





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
Lukasz Majewski May 7, 2020, 6:32 p.m. | #3
Hi Adhemerval,

> Hi Adhemerval,

> 

> > On 26/04/2020 10:31, Lukasz Majewski wrote:  

> > > @@ -69,6 +70,19 @@ extern int __clock_adjtime64 (const clockid_t

> > > clock_id, struct __timex64 *tx64); libc_hidden_proto

> > > (__clock_adjtime64); extern int ___adjtimex64 (struct __timex64

> > > *tx64); libc_hidden_proto (___adjtimex64)

> > > +

> > > +struct __ntptimeval64

> > > +{

> > > +  struct __timeval64 time;	/* current time (ro) */

> > > +  long int maxerror;	/* maximum error (us) (ro) */

> > > +  long int esterror;	/* estimated error (us) (ro) */

> > > +  long int tai;		/* TAI offset (ro) */

> > > +

> > > +  long int __glibc_reserved1;

> > > +  long int __glibc_reserved2;

> > > +  long int __glibc_reserved3;

> > > +  long int __glibc_reserved4;    

> > 

> > Why does it need the extra reserved fields?  

> 

> I've followed the definition of in-glibc ntptimeval definition in

> sysdeps/unix/sysv/linux/sys/timex.h

> 

> As the __ntptimeval64 is not passed to the kernel (it gets its values

> based on struct __timex64), IMHO it would be safe to remove them.


Those fields are present and cleared in the legacy ntptimeval
structure exported to user programs. To avoid any odd regressions (who
knows how this is used in the legacy code) and to facilitate the
conversion to 64 bit time - I do think that the new struct
__ntptimeval64 shall have those as well.

> 

> >   

> > > +};

> > >  #  endif

> > >  

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

> > > */ 

> 

> 

> 

> 

> 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





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

Patch

diff --git a/sysdeps/unix/sysv/linux/include/sys/timex.h b/sysdeps/unix/sysv/linux/include/sys/timex.h
index fdfffe2f3a..73c9addb3e 100644
--- a/sysdeps/unix/sysv/linux/include/sys/timex.h
+++ b/sysdeps/unix/sysv/linux/include/sys/timex.h
@@ -32,6 +32,7 @@  libc_hidden_proto (__adjtimex)
 #   define __timex64 timex
 #   define __clock_adjtime64 __clock_adjtime
 #   define ___adjtimex64 ___adjtimex
+#   define __ntptimeval64 ntptimeval
 #  else
 
 struct __timex64
@@ -69,6 +70,19 @@  extern int __clock_adjtime64 (const clockid_t clock_id, struct __timex64 *tx64);
 libc_hidden_proto (__clock_adjtime64);
 extern int ___adjtimex64 (struct __timex64 *tx64);
 libc_hidden_proto (___adjtimex64)
+
+struct __ntptimeval64
+{
+  struct __timeval64 time;	/* current time (ro) */
+  long int maxerror;	/* maximum error (us) (ro) */
+  long int esterror;	/* estimated error (us) (ro) */
+  long int tai;		/* TAI offset (ro) */
+
+  long int __glibc_reserved1;
+  long int __glibc_reserved2;
+  long int __glibc_reserved3;
+  long int __glibc_reserved4;
+};
 #  endif
 
 /* Convert a known valid struct timex into a struct __timex64.  */