diff mbox series

[1/2] y2038: Adjust struct __stat64_t64 to be usable by redirected {f}stat{at} calls

Message ID 20201013131603.12557-1-lukma@denx.de
State Dropped
Delegated to: Lukasz Majewski
Headers show
Series [1/2] y2038: Adjust struct __stat64_t64 to be usable by redirected {f}stat{at} calls | expand

Commit Message

Lukasz Majewski Oct. 13, 2020, 1:16 p.m. UTC
When glibc port with __WORDSIZE==32 and __TIMESIZE!=64 (e.g. armv7) will
use redirected calls to {f}stat{at}64_time64 functions, it will accept
the struct __stat64_t64 as its argument.

To avoid errors related to proper data placement after casting from
struct __stat64_t64 to struct stat{64} it is necessary to add some missing
padding and update type of {__}st_ino member.


By adding the unsigned int pads there is a possibility to extend struct
stat from: sysdeps/unix/sysv/linux/bits/struct_stat.h
with:
     unsigned short int __pad1;
+#ifdef __USE_TIME_BITS64
+    unsigned short int __timepad1;
+#endif

To have it binary compatible with struct __stat64_t64
---
 sysdeps/unix/sysv/linux/struct_stat_time64.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Joseph Myers Oct. 13, 2020, 10:17 p.m. UTC | #1
On Tue, 13 Oct 2020, Lukasz Majewski wrote:

> When glibc port with __WORDSIZE==32 and __TIMESIZE!=64 (e.g. armv7) will
> use redirected calls to {f}stat{at}64_time64 functions, it will accept
> the struct __stat64_t64 as its argument.
> 
> To avoid errors related to proper data placement after casting from
> struct __stat64_t64 to struct stat{64} it is necessary to add some missing
> padding and update type of {__}st_ino member.

When redirecting to those functions, the definitions of struct stat / 
struct stat64 should automatically change as a result of the _TIME_BITS=64 
definition so that they match the definitions of the __stat64_t64 type - 
just as _FILE_OFFSET_BITS=64 results in changes to the content of struct 
stat.

I believe the design is that __stat64_t64 has an architecture-independent 
layout that is never required to match any particular kernel layout 
because translation (typically from statx) will always occur in userspace.

Note that struct_stat_time64.h is currently an *uninstalled* header, 
despite the name of the multiple-include guard in the header, and despite 
the testing of feature test macros within the header (which only makes 
sense for installed headers); it's not a bits/ header at present.

Maybe there should be some indirection so that the installed version of 
struct_stat_time64.h defines a macro with all the contents of 
__stat64_t64, so that all the many architecture-specific 
bits/struct_stat.h headers can just use that macro to get the right 
contents when _TIME_BITS=64 rather than needing to duplicate the structure 
contents (at least twice per header, for both stat and stat64).  But I 
don't think any change to the layout of __stat64_t64 is indicated, because 
there should always be explicit conversions between different layouts.
Lukasz Majewski Oct. 14, 2020, 8:47 a.m. UTC | #2
Hi Joseph,

> On Tue, 13 Oct 2020, Lukasz Majewski wrote:
> 
> > When glibc port with __WORDSIZE==32 and __TIMESIZE!=64 (e.g. armv7)
> > will use redirected calls to {f}stat{at}64_time64 functions, it
> > will accept the struct __stat64_t64 as its argument.
> > 
> > To avoid errors related to proper data placement after casting from
> > struct __stat64_t64 to struct stat{64} it is necessary to add some
> > missing padding and update type of {__}st_ino member.  
> 
> When redirecting to those functions, the definitions of struct stat / 
> struct stat64 should automatically change as a result of the
> _TIME_BITS=64 definition so that they match the definitions of the
> __stat64_t64 type - just as _FILE_OFFSET_BITS=64 results in changes
> to the content of struct stat.

Thanks for the explanation. I will adjust exported struct stat{64]
accordingly.

> 
> I believe the design is that __stat64_t64 has an
> architecture-independent layout that is never required to match any
> particular kernel layout because translation (typically from statx)
> will always occur in userspace.
> 
> Note that struct_stat_time64.h is currently an *uninstalled* header, 
> despite the name of the multiple-include guard in the header, and
> despite the testing of feature test macros within the header (which
> only makes sense for installed headers); it's not a bits/ header at
> present.

The only change, that I'm going to do is to mode __ino64_t st_ino
member of struct __stat64_t64
(@ sysdeps/unix/sysv/linux/struct_stat_time64.h) to the end of this
structure (as it is in the exported struct stat{64} placed).

This would allow less #ifndef __USE_TIME_BITS64 in the exported struct
stat{64}.

> 
> Maybe there should be some indirection so that the installed version
> of struct_stat_time64.h defines a macro with all the contents of 
> __stat64_t64, so that all the many architecture-specific 
> bits/struct_stat.h headers can just use that macro to get the right 
> contents when _TIME_BITS=64 rather than needing to duplicate the
> structure contents (at least twice per header, for both stat and
> stat64).  But I don't think any change to the layout of __stat64_t64
> is indicated, because there should always be explicit conversions
> between different layouts.
> 


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
Joseph Myers Oct. 14, 2020, 1:09 p.m. UTC | #3
On Wed, 14 Oct 2020, Lukasz Majewski wrote:

> The only change, that I'm going to do is to mode __ino64_t st_ino
> member of struct __stat64_t64
> (@ sysdeps/unix/sysv/linux/struct_stat_time64.h) to the end of this
> structure (as it is in the exported struct stat{64} placed).
> 
> This would allow less #ifndef __USE_TIME_BITS64 in the exported struct
> stat{64}.

I don't think any reordering is needed.  I expect each header defining 
struct stat / struct stat64 to do something like

#if __GLIBC_USE (TIME_BITS64)
  __STAT64_T64_CONTENT
#else
  /* existing struct contents */
#endif

so just one #if in each such struct definition (given that you define 
__STAT64_T64_CONTENT in some installed bits/ header to avoid duplication).
diff mbox series

Patch

diff --git a/sysdeps/unix/sysv/linux/struct_stat_time64.h b/sysdeps/unix/sysv/linux/struct_stat_time64.h
index b85385b6f3..ca3f06c077 100644
--- a/sysdeps/unix/sysv/linux/struct_stat_time64.h
+++ b/sysdeps/unix/sysv/linux/struct_stat_time64.h
@@ -43,12 +43,14 @@ 
 struct __stat64_t64
   {
     __dev_t st_dev;			/* Device.  */
-    __ino64_t st_ino;			/* file serial number.	*/
+    unsigned int __pad1;
+    __ino_t __st_ino;			/* 32bit file serial number.	*/
     __mode_t st_mode;			/* File mode.  */
     __nlink_t st_nlink;			/* Link count.  */
     __uid_t st_uid;			/* User ID of the file's owner.	*/
     __gid_t st_gid;			/* Group ID of the file's group.*/
     __dev_t st_rdev;			/* Device number, if device.  */
+    unsigned int __pad2;
     __off64_t st_size;			/* Size of file, in bytes.  */
     __blksize_t st_blksize;		/* Optimal block size for I/O.  */
     __blkcnt64_t st_blocks;		/* Number 512-byte blocks allocated. */
@@ -70,6 +72,7 @@  struct __stat64_t64
     __fieldts64 (st_mtime);
     __fieldts64 (st_ctime);
 #   endif /* __USE_XOPEN2K8  */
+    __ino64_t st_ino;			/* file serial number.	*/
   };
 
 #   define _STATBUF_ST_BLKSIZE