]> granicus.if.org Git - strace/blobdiff - file.c
Fix ILP32 personality preadv/pwritev offset decoding on LP64 architectures
[strace] / file.c
diff --git a/file.c b/file.c
index ad85ef00d23460e0fdbcc5f60ea42681a12d4f8f..ae74d5ab82b78655c34a5cd6195499f2930a1fd5 100644 (file)
--- a/file.c
+++ b/file.c
 
 #include "defs.h"
 
-#if defined(SPARC) || defined(SPARC64)
-struct stat {
-       unsigned short  st_dev;
-       unsigned int    st_ino;
-       unsigned short  st_mode;
-       short           st_nlink;
-       unsigned short  st_uid;
-       unsigned short  st_gid;
-       unsigned short  st_rdev;
-       unsigned int    st_size;
-       int             st_atime;
-       unsigned int    __unused1;
-       int             st_mtime;
-       unsigned int    __unused2;
-       int             st_ctime;
-       unsigned int    __unused3;
-       int             st_blksize;
-       int             st_blocks;
-       unsigned int    __unused4[2];
-};
-# if defined(SPARC64)
-struct stat_sparc64 {
-       unsigned int    st_dev;
-       unsigned long   st_ino;
-       unsigned int    st_mode;
-       unsigned int    st_nlink;
-       unsigned int    st_uid;
-       unsigned int    st_gid;
-       unsigned int    st_rdev;
-       long            st_size;
-       long            st_atime;
-       long            st_mtime;
-       long            st_ctime;
-       long            st_blksize;
-       long            st_blocks;
-       unsigned long   __unused4[2];
-};
-# endif /* SPARC64 */
-# define stat kernel_stat
-# include <asm/stat.h>
-# undef stat
-#elif defined(X32)
-struct stat {
-       unsigned long long      st_dev;
-       unsigned long long      st_ino;
-       unsigned long long      st_nlink;
-
-       unsigned int            st_mode;
-       unsigned int            st_uid;
-       unsigned int            st_gid;
-       unsigned int            __pad0;
-       unsigned long long      st_rdev;
-       long long               st_size;
-       long long               st_blksize;
-       long long               st_blocks;
-
-       unsigned long long      st_atime;
-       unsigned long long      st_atime_nsec;
-       unsigned long long      st_mtime;
-       unsigned long long      st_mtime_nsec;
-       unsigned long long      st_ctime;
-       unsigned long long      st_ctime_nsec;
-       long long               __unused[3];
-};
-
-struct stat64 {
-       unsigned long long      st_dev;
-       unsigned char           __pad0[4];
-       unsigned long           __st_ino;
-       unsigned int            st_mode;
-       unsigned int            st_nlink;
-       unsigned long           st_uid;
-       unsigned long           st_gid;
-       unsigned long long      st_rdev;
-       unsigned char           __pad3[4];
-       long long               st_size;
-       unsigned long           st_blksize;
-       unsigned long long      st_blocks;
-       unsigned long           st_atime;
-       unsigned long           st_atime_nsec;
-       unsigned long           st_mtime;
-       unsigned int            st_mtime_nsec;
-       unsigned long           st_ctime;
-       unsigned long           st_ctime_nsec;
-       unsigned long long      st_ino;
-} __attribute__((packed));
-# define HAVE_STAT64   1
-
-struct __old_kernel_stat {
-       unsigned short st_dev;
-       unsigned short st_ino;
-       unsigned short st_mode;
-       unsigned short st_nlink;
-       unsigned short st_uid;
-       unsigned short st_gid;
-       unsigned short st_rdev;
-       unsigned int   st_size;
-       unsigned int   st_atime;
-       unsigned int   st_mtime;
-       unsigned int   st_ctime;
-};
-#else
-# undef dev_t
-# undef ino_t
-# undef mode_t
-# undef nlink_t
-# undef uid_t
-# undef gid_t
-# undef off_t
-# undef loff_t
-# define dev_t __kernel_dev_t
-# define ino_t __kernel_ino_t
-# define mode_t __kernel_mode_t
-# define nlink_t __kernel_nlink_t
-# define uid_t __kernel_uid_t
-# define gid_t __kernel_gid_t
-# define off_t __kernel_off_t
-# define loff_t __kernel_loff_t
-
-# include <asm/stat.h>
-
-# undef dev_t
-# undef ino_t
-# undef mode_t
-# undef nlink_t
-# undef uid_t
-# undef gid_t
-# undef off_t
-# undef loff_t
-# define dev_t dev_t
-# define ino_t ino_t
-# define mode_t mode_t
-# define nlink_t nlink_t
-# define uid_t uid_t
-# define gid_t gid_t
-# define off_t off_t
-# define loff_t loff_t
-#endif
-
+#undef dev_t
+#undef ino_t
+#undef mode_t
+#undef nlink_t
+#undef uid_t
+#undef gid_t
+#undef off_t
+#undef loff_t
+#define dev_t __kernel_dev_t
+#define ino_t __kernel_ino_t
+#define mode_t __kernel_mode_t
+#define nlink_t __kernel_nlink_t
+#define uid_t __kernel_uid_t
+#define gid_t __kernel_gid_t
+#define off_t __kernel_off_t
+#define loff_t __kernel_loff_t
+
+#include <asm/stat.h>
+
+#undef dev_t
+#undef ino_t
+#undef mode_t
+#undef nlink_t
+#undef uid_t
+#undef gid_t
+#undef off_t
+#undef loff_t
+#define dev_t dev_t
+#define ino_t ino_t
+#define mode_t mode_t
+#define nlink_t nlink_t
+#define uid_t uid_t
+#define gid_t gid_t
+#define off_t off_t
+#define loff_t loff_t
+
+/* for S_IFMT */
 #define stat libc_stat
 #define stat64 libc_stat64
 #include <sys/stat.h>
@@ -179,279 +77,46 @@ struct __old_kernel_stat {
 #undef st_mtime
 #undef st_ctime
 
-#include <fcntl.h>
-
-#ifdef MAJOR_IN_SYSMACROS
+#if defined MAJOR_IN_SYSMACROS
 # include <sys/sysmacros.h>
-#endif
-
-#ifdef MAJOR_IN_MKDEV
+#elif defined MAJOR_IN_MKDEV
 # include <sys/mkdev.h>
 #endif
 
-#ifdef O_LARGEFILE
-# if O_LARGEFILE == 0          /* biarch platforms in 64-bit mode */
-#  undef O_LARGEFILE
-#  ifdef SPARC64
-#   define O_LARGEFILE 0x40000
-#  elif defined X86_64 || defined S390X
-#   define O_LARGEFILE 0100000
-#  endif
-# endif
-#endif
-
-#include "xlat/open_access_modes.h"
-#include "xlat/open_mode_flags.h"
-
-#ifndef AT_FDCWD
-# define AT_FDCWD                -100
-#endif
-
-/* The fd is an "int", so when decoding x86 on x86_64, we need to force sign
- * extension to get the right value.  We do this by declaring fd as int here.
- */
-void
-print_dirfd(struct tcb *tcp, int fd)
-{
-       if (fd == AT_FDCWD)
-               tprints("AT_FDCWD, ");
-       else {
-               printfd(tcp, fd);
-               tprints(", ");
-       }
-}
-
-/*
- * low bits of the open(2) flags define access mode,
- * other bits are real flags.
- */
-const char *
-sprint_open_modes(int flags)
-{
-       static char outstr[(1 + ARRAY_SIZE(open_mode_flags)) * sizeof("O_LARGEFILE")];
-       char *p;
-       char sep;
-       const char *str;
-       const struct xlat *x;
-
-       sep = ' ';
-       p = stpcpy(outstr, "flags");
-       str = xlookup(open_access_modes, flags & 3);
-       if (str) {
-               *p++ = sep;
-               p = stpcpy(p, str);
-               flags &= ~3;
-               if (!flags)
-                       return outstr;
-               sep = '|';
-       }
-
-       for (x = open_mode_flags; x->str; x++) {
-               if ((flags & x->val) == x->val) {
-                       *p++ = sep;
-                       p = stpcpy(p, x->str);
-                       flags &= ~x->val;
-                       if (!flags)
-                               return outstr;
-                       sep = '|';
-               }
-       }
-       /* flags is still nonzero */
-       *p++ = sep;
-       sprintf(p, "%#x", flags);
-       return outstr;
-}
-
-void
-tprint_open_modes(int flags)
-{
-       tprints(sprint_open_modes(flags) + sizeof("flags"));
-}
-
-static int
-decode_open(struct tcb *tcp, int offset)
-{
-       if (entering(tcp)) {
-               printpath(tcp, tcp->u_arg[offset]);
-               tprints(", ");
-               /* flags */
-               tprint_open_modes(tcp->u_arg[offset + 1]);
-               if (tcp->u_arg[offset + 1] & O_CREAT) {
-                       /* mode */
-                       tprintf(", %#lo", tcp->u_arg[offset + 2]);
-               }
-       }
-       return RVAL_FD;
-}
-
-int
-sys_open(struct tcb *tcp)
-{
-       return decode_open(tcp, 0);
-}
-
-int
-sys_openat(struct tcb *tcp)
-{
-       if (entering(tcp))
-               print_dirfd(tcp, tcp->u_arg[0]);
-       return decode_open(tcp, 1);
-}
-
-#if defined(SPARC) || defined(SPARC64)
-#include "xlat/openmodessol.h"
-
-int
-solaris_open(struct tcb *tcp)
-{
-       if (entering(tcp)) {
-               printpath(tcp, tcp->u_arg[0]);
-               tprints(", ");
-               /* flags */
-               printflags(openmodessol, tcp->u_arg[1] + 1, "O_???");
-               if (tcp->u_arg[1] & 0x100) {
-                       /* mode */
-                       tprintf(", %#lo", tcp->u_arg[2]);
-               }
-       }
-       return 0;
-}
-
-#endif
-
-int
-sys_creat(struct tcb *tcp)
-{
-       if (entering(tcp)) {
-               printpath(tcp, tcp->u_arg[0]);
-               tprintf(", %#lo", tcp->u_arg[1]);
-       }
-       return RVAL_FD;
-}
-
 /* several stats */
 
-#if defined(SPARC) || defined(SPARC64)
-typedef struct {
-       int     tv_sec;
-       int     tv_nsec;
-} timestruct_t;
+#include "printstat.h"
 
-struct solstat {
-       unsigned        st_dev;
-       int             st_pad1[3];     /* network id */
-       unsigned        st_ino;
-       unsigned        st_mode;
-       unsigned        st_nlink;
-       unsigned        st_uid;
-       unsigned        st_gid;
-       unsigned        st_rdev;
-       int             st_pad2[2];
-       int             st_size;
-       int             st_pad3;        /* st_size, off_t expansion */
-       timestruct_t    st_atime;
-       timestruct_t    st_mtime;
-       timestruct_t    st_ctime;
-       int             st_blksize;
-       int             st_blocks;
-       char            st_fstype[16];
-       int             st_pad4[8];     /* expansion area */
+#undef STAT32_PERSONALITY
+#if SUPPORTED_PERSONALITIES > 1
+# if defined AARCH64 || defined X86_64 || defined X32
+struct stat32 {
+       unsigned int    st_dev;
+       unsigned int    st_ino;
+       unsigned short  st_mode;
+       unsigned short  st_nlink;
+       unsigned short  st_uid;
+       unsigned short  st_gid;
+       unsigned int    st_rdev;
+       unsigned int    st_size;
+       unsigned int    st_blksize;
+       unsigned int    st_blocks;
+       unsigned int    st_atime;
+       unsigned int    st_atime_nsec;
+       unsigned int    st_mtime;
+       unsigned int    st_mtime_nsec;
+       unsigned int    st_ctime;
+       unsigned int    st_ctime_nsec;
+       unsigned int    __unused4;
+       unsigned int    __unused5;
 };
-
-static void
-printstatsol(struct tcb *tcp, long addr)
-{
-       struct solstat statbuf;
-
-       if (umove(tcp, addr, &statbuf) < 0) {
-               tprints("{...}");
-               return;
-       }
-       if (!abbrev(tcp)) {
-               tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
-                       (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
-                       (unsigned long) (statbuf.st_dev & 0x3ffff),
-                       (unsigned long) statbuf.st_ino,
-                       sprintmode(statbuf.st_mode));
-               tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
-                       (unsigned long) statbuf.st_nlink,
-                       (unsigned long) statbuf.st_uid,
-                       (unsigned long) statbuf.st_gid);
-               tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
-               tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
-       }
-       else
-               tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
-       switch (statbuf.st_mode & S_IFMT) {
-       case S_IFCHR: case S_IFBLK:
-               tprintf("st_rdev=makedev(%lu, %lu), ",
-                       (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
-                       (unsigned long) (statbuf.st_rdev & 0x3ffff));
-               break;
-       default:
-               tprintf("st_size=%u, ", statbuf.st_size);
-               break;
-       }
-       if (!abbrev(tcp)) {
-               tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime.tv_sec));
-               tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime.tv_sec));
-               tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime.tv_sec));
-       }
-       else
-               tprints("...}");
-}
-
-# if defined(SPARC64)
-static void
-printstat_sparc64(struct tcb *tcp, long addr)
-{
-       struct stat_sparc64 statbuf;
-
-       if (umove(tcp, addr, &statbuf) < 0) {
-               tprints("{...}");
-               return;
-       }
-
-       if (!abbrev(tcp)) {
-               tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
-                       (unsigned long) major(statbuf.st_dev),
-                       (unsigned long) minor(statbuf.st_dev),
-                       (unsigned long) statbuf.st_ino,
-                       sprintmode(statbuf.st_mode));
-               tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
-                       (unsigned long) statbuf.st_nlink,
-                       (unsigned long) statbuf.st_uid,
-                       (unsigned long) statbuf.st_gid);
-               tprintf("st_blksize=%lu, ",
-                       (unsigned long) statbuf.st_blksize);
-               tprintf("st_blocks=%lu, ",
-                       (unsigned long) statbuf.st_blocks);
-       }
-       else
-               tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
-       switch (statbuf.st_mode & S_IFMT) {
-       case S_IFCHR: case S_IFBLK:
-               tprintf("st_rdev=makedev(%lu, %lu), ",
-                       (unsigned long) major(statbuf.st_rdev),
-                       (unsigned long) minor(statbuf.st_rdev));
-               break;
-       default:
-               tprintf("st_size=%lu, ", statbuf.st_size);
-               break;
-       }
-       if (!abbrev(tcp)) {
-               tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
-               tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
-               tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
-       }
-       else
-               tprints("...}");
-}
-# endif /* SPARC64 */
-#endif /* SPARC[64] */
-
-#if defined POWERPC64
-struct stat_powerpc32 {
+#  ifdef AARCH64
+#   define STAT32_PERSONALITY 0
+#  else
+#   define STAT32_PERSONALITY 1
+#  endif
+# elif defined POWERPC64
+struct stat32 {
        unsigned int    st_dev;
        unsigned int    st_ino;
        unsigned int    st_mode;
@@ -471,117 +136,109 @@ struct stat_powerpc32 {
        unsigned int    __unused4;
        unsigned int    __unused5;
 };
+#  define STAT32_PERSONALITY 1
+# elif defined SPARC64
+struct stat32 {
+       unsigned short  st_dev;
+       unsigned int    st_ino;
+       unsigned short  st_mode;
+       unsigned short  st_nlink;
+       unsigned short  st_uid;
+       unsigned short  st_gid;
+       unsigned short  st_rdev;
+       unsigned int    st_size;
+       unsigned int    st_atime;
+       unsigned int    st_atime_nsec;
+       unsigned int    st_mtime;
+       unsigned int    st_mtime_nsec;
+       unsigned int    st_ctime;
+       unsigned int    st_ctime_nsec;
+       unsigned int    st_blksize;
+       unsigned int    st_blocks;
+       unsigned int    __unused4[2];
+};
+#  define STAT32_PERSONALITY 0
+# elif defined SPARC
+#  /* no 64-bit personalities */
+# elif defined TILE
+#  /* no 32-bit stat */
+# else
+#  warning FIXME: check whether struct stat32 definition is needed for this architecture!
+# endif /* X86_64 || X32 || POWERPC64 */
+#endif /* SUPPORTED_PERSONALITIES > 1 */
+
+#ifdef STAT32_PERSONALITY
+# define DO_PRINTSTAT do_printstat32
+# define STRUCT_STAT struct stat32
+# undef HAVE_STRUCT_STAT_ST_FLAGS
+# undef HAVE_STRUCT_STAT_ST_FSTYPE
+# undef HAVE_STRUCT_STAT_ST_GEN
+# include "printstat.h"
 
 static void
-printstat_powerpc32(struct tcb *tcp, long addr)
+printstat32(struct tcb *tcp, long addr)
 {
-       struct stat_powerpc32 statbuf;
+       struct stat32 statbuf;
 
        if (umove(tcp, addr, &statbuf) < 0) {
                tprints("{...}");
                return;
        }
 
-       if (!abbrev(tcp)) {
-               tprintf("{st_dev=makedev(%u, %u), st_ino=%u, st_mode=%s, ",
-                       major(statbuf.st_dev), minor(statbuf.st_dev),
-                       statbuf.st_ino,
-                       sprintmode(statbuf.st_mode));
-               tprintf("st_nlink=%u, st_uid=%u, st_gid=%u, ",
-                       statbuf.st_nlink, statbuf.st_uid, statbuf.st_gid);
-               tprintf("st_blksize=%u, ", statbuf.st_blksize);
-               tprintf("st_blocks=%u, ", statbuf.st_blocks);
-       }
-       else
-               tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
-       switch (statbuf.st_mode & S_IFMT) {
-       case S_IFCHR: case S_IFBLK:
-               tprintf("st_rdev=makedev(%lu, %lu), ",
-                       (unsigned long) major(statbuf.st_rdev),
-                       (unsigned long) minor(statbuf.st_rdev));
-               break;
-       default:
-               tprintf("st_size=%u, ", statbuf.st_size);
-               break;
-       }
-       if (!abbrev(tcp)) {
-               tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
-               tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
-               tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
-       }
-       else
-               tprints("...}");
+       do_printstat32(tcp, &statbuf);
 }
-#endif /* POWERPC64 */
+#endif /* STAT32_PERSONALITY */
+
+#if defined(SPARC) || defined(SPARC64)
+
+struct solstat {
+       unsigned        st_dev;
+       unsigned int    st_pad1[3];     /* network id */
+       unsigned        st_ino;
+       unsigned        st_mode;
+       unsigned        st_nlink;
+       unsigned        st_uid;
+       unsigned        st_gid;
+       unsigned        st_rdev;
+       unsigned int    st_pad2[2];
+       unsigned int    st_size;
+       unsigned int    st_pad3;        /* st_size, off_t expansion */
+       unsigned int    st_atime;
+       unsigned int    st_atime_nsec;
+       unsigned int    st_mtime;
+       unsigned int    st_mtime_nsec;
+       unsigned int    st_ctime;
+       unsigned int    st_ctime_nsec;
+       unsigned int    st_blksize;
+       unsigned int    st_blocks;
+       char            st_fstype[16];
+       unsigned int    st_pad4[8];     /* expansion area */
+};
 
-#include "xlat/fileflags.h"
+# define DO_PRINTSTAT  do_printstat_sol
+# define STRUCT_STAT   struct solstat
+# define STAT_MAJOR(x) (((x) >> 18) & 0x3fff)
+# define STAT_MINOR(x) ((x) & 0x3ffff)
+# undef HAVE_STRUCT_STAT_ST_FLAGS
+# undef HAVE_STRUCT_STAT_ST_FSTYPE
+# undef HAVE_STRUCT_STAT_ST_GEN
+# include "printstat.h"
 
 static void
-realprintstat(struct tcb *tcp, struct stat *statbuf)
+printstatsol(struct tcb *tcp, long addr)
 {
-       if (!abbrev(tcp)) {
-               tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
-                       (unsigned long) major(statbuf->st_dev),
-                       (unsigned long) minor(statbuf->st_dev),
-                       (unsigned long) statbuf->st_ino,
-                       sprintmode(statbuf->st_mode));
-               tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
-                       (unsigned long) statbuf->st_nlink,
-                       (unsigned long) statbuf->st_uid,
-                       (unsigned long) statbuf->st_gid);
-#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
-               tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
-#endif
-#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
-               tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
-#endif
-       }
-       else
-               tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
-       switch (statbuf->st_mode & S_IFMT) {
-       case S_IFCHR: case S_IFBLK:
-#ifdef HAVE_STRUCT_STAT_ST_RDEV
-               tprintf("st_rdev=makedev(%lu, %lu), ",
-                       (unsigned long) major(statbuf->st_rdev),
-                       (unsigned long) minor(statbuf->st_rdev));
-#else /* !HAVE_STRUCT_STAT_ST_RDEV */
-               tprintf("st_size=makedev(%lu, %lu), ",
-                       (unsigned long) major(statbuf->st_size),
-                       (unsigned long) minor(statbuf->st_size));
-#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
-               break;
-       default:
-               tprintf("st_size=%lu, ", (unsigned long) statbuf->st_size);
-               break;
-       }
-       if (!abbrev(tcp)) {
-               tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
-               tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
-               tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
-#if HAVE_STRUCT_STAT_ST_FLAGS
-               tprints(", st_flags=");
-               printflags(fileflags, statbuf->st_flags, "UF_???");
-#endif
-#if HAVE_STRUCT_STAT_ST_ACLCNT
-               tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
-#endif
-#if HAVE_STRUCT_STAT_ST_LEVEL
-               tprintf(", st_level=%ld", statbuf->st_level);
-#endif
-#if HAVE_STRUCT_STAT_ST_FSTYPE
-               tprintf(", st_fstype=%.*s",
-                       (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
-#endif
-#if HAVE_STRUCT_STAT_ST_GEN
-               tprintf(", st_gen=%u", statbuf->st_gen);
-#endif
-               tprints("}");
+       struct solstat statbuf;
+
+       if (umove(tcp, addr, &statbuf) < 0) {
+               tprints("{...}");
+               return;
        }
-       else
-               tprints("...}");
+
+       do_printstat_sol(tcp, &statbuf);
 }
 
-#ifndef X32
+#endif /* SPARC || SPARC64 */
+
 static void
 printstat(struct tcb *tcp, long addr)
 {
@@ -596,47 +253,62 @@ printstat(struct tcb *tcp, long addr)
                return;
        }
 
-#if defined(SPARC) || defined(SPARC64)
-       if (current_personality == 1) {
-               printstatsol(tcp, addr);
-               return;
-       }
-#ifdef SPARC64
-       else if (current_personality == 2) {
-               printstat_sparc64(tcp, addr);
+#ifdef STAT32_PERSONALITY
+       if (current_personality == STAT32_PERSONALITY) {
+               printstat32(tcp, addr);
                return;
        }
 #endif
-#endif /* SPARC[64] */
 
-#if defined POWERPC64
+#if defined(SPARC) || defined(SPARC64)
        if (current_personality == 1) {
-               printstat_powerpc32(tcp, addr);
+               printstatsol(tcp, addr);
                return;
        }
-#endif
+#endif /* SPARC || SPARC64 */
 
        if (umove(tcp, addr, &statbuf) < 0) {
                tprints("{...}");
                return;
        }
 
-       realprintstat(tcp, &statbuf);
+       do_printstat(tcp, &statbuf);
+}
+
+int
+sys_stat(struct tcb *tcp)
+{
+       if (entering(tcp)) {
+               printpath(tcp, tcp->u_arg[0]);
+               tprints(", ");
+       } else {
+               printstat(tcp, tcp->u_arg[1]);
+       }
+       return 0;
 }
-#else /* X32 */
-# define printstat printstat64
-#endif
 
-#if !defined HAVE_STAT64 && (defined AARCH64 || defined X86_64)
+int
+sys_fstat(struct tcb *tcp)
+{
+       if (entering(tcp)) {
+               printfd(tcp, tcp->u_arg[0]);
+               tprints(", ");
+       } else {
+               printstat(tcp, tcp->u_arg[1]);
+       }
+       return 0;
+}
+
+#if defined STAT32_PERSONALITY && !defined HAVE_STRUCT_STAT64
+# if defined AARCH64 || defined X86_64 || defined X32
 /*
- * Linux x86_64 has unified `struct stat' but its i386 biarch needs
- * `struct stat64'.  Its <asm-i386/stat.h> definition expects 32-bit `long'.
- * <linux/include/asm-x86_64/ia32.h> is not in the public includes set.
+ * Linux x86_64 and x32 have unified `struct stat' but their i386 personality
+ * needs `struct stat64'.
+ * linux/arch/x86/include/uapi/asm/stat.h defines `struct stat64' only for i386.
  * __GNUC__ is needed for the required __attribute__ below.
  *
  * Similarly, aarch64 has a unified `struct stat' but its arm personality
- * needs `struct stat64' (which also expects a 32-bit `long' but which
- * shouldn't be packed).
+ * needs `struct stat64' (unlike x86, it shouldn't be packed).
  */
 struct stat64 {
        unsigned long long      st_dev;
@@ -659,29 +331,36 @@ struct stat64 {
        unsigned int    st_ctime_nsec;
        unsigned long long      st_ino;
 }
-# if defined X86_64
-   __attribute__((packed))
-#  define STAT64_SIZE  96
-#else
-#  define STAT64_SIZE  104
-# endif
+#  if defined X86_64 || defined X32
+  __attribute__((packed))
+#   define STAT64_SIZE 96
+#  else
+#   define STAT64_SIZE 104
+#  endif
 ;
-# define HAVE_STAT64   1
-#endif
+#  define HAVE_STRUCT_STAT64   1
+# else /* !(AARCH64 || X86_64 || X32) */
+#  warning FIXME: check whether struct stat64 definition is needed for this architecture!
+# endif
+#endif /* STAT32_PERSONALITY && !HAVE_STRUCT_STAT64 */
+
+#ifdef HAVE_STRUCT_STAT64
+
+# define DO_PRINTSTAT do_printstat64
+# define STRUCT_STAT struct stat64
+# undef HAVE_STRUCT_STAT_ST_FLAGS
+# undef HAVE_STRUCT_STAT_ST_FSTYPE
+# undef HAVE_STRUCT_STAT_ST_GEN
+# include "printstat.h"
 
-#ifdef HAVE_STAT64
 static void
 printstat64(struct tcb *tcp, long addr)
 {
-#ifdef X32
-       struct stat statbuf;
-#else
        struct stat64 statbuf;
-#endif
 
-#ifdef STAT64_SIZE
+# ifdef STAT64_SIZE
        (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
-#endif
+# endif
 
        if (!addr) {
                tprints("NULL");
@@ -692,105 +371,91 @@ printstat64(struct tcb *tcp, long addr)
                return;
        }
 
-#if defined(SPARC) || defined(SPARC64)
-       if (current_personality == 1) {
-               printstatsol(tcp, addr);
-               return;
-       }
-# ifdef SPARC64
-       else if (current_personality == 2) {
-               printstat_sparc64(tcp, addr);
-               return;
-       }
-# endif
-#endif /* SPARC[64] */
-
-#if defined AARCH64
-       if (current_personality != 0) {
-               printstat(tcp, addr);
-               return;
-       }
-#endif
-#if defined X86_64
-       if (current_personality != 1) {
+# ifdef STAT32_PERSONALITY
+       if (current_personality != STAT32_PERSONALITY) {
                printstat(tcp, addr);
                return;
        }
-#endif
+# endif /* STAT32_PERSONALITY */
 
        if (umove(tcp, addr, &statbuf) < 0) {
                tprints("{...}");
                return;
        }
 
-       if (!abbrev(tcp)) {
-               tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
-                       (unsigned long) major(statbuf.st_dev),
-                       (unsigned long) minor(statbuf.st_dev),
-                       (unsigned long long) statbuf.st_ino,
-                       sprintmode(statbuf.st_mode));
-               tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
-                       (unsigned long) statbuf.st_nlink,
-                       (unsigned long) statbuf.st_uid,
-                       (unsigned long) statbuf.st_gid);
-#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
-               tprintf("st_blksize=%lu, ",
-                       (unsigned long) statbuf.st_blksize);
-#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
-#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
-               tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
-#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
+       do_printstat64(tcp, &statbuf);
+}
+
+int
+sys_stat64(struct tcb *tcp)
+{
+       if (entering(tcp)) {
+               printpath(tcp, tcp->u_arg[0]);
+               tprints(", ");
+       } else {
+               printstat64(tcp, tcp->u_arg[1]);
        }
-       else
-               tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
-       switch (statbuf.st_mode & S_IFMT) {
-       case S_IFCHR: case S_IFBLK:
-#ifdef HAVE_STRUCT_STAT_ST_RDEV
-               tprintf("st_rdev=makedev(%lu, %lu), ",
-                       (unsigned long) major(statbuf.st_rdev),
-                       (unsigned long) minor(statbuf.st_rdev));
-#else /* !HAVE_STRUCT_STAT_ST_RDEV */
-               tprintf("st_size=makedev(%lu, %lu), ",
-                       (unsigned long) major(statbuf.st_size),
-                       (unsigned long) minor(statbuf.st_size));
-#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
-               break;
-       default:
-               tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
-               break;
+       return 0;
+}
+
+int
+sys_fstat64(struct tcb *tcp)
+{
+       if (entering(tcp)) {
+               printfd(tcp, tcp->u_arg[0]);
+               tprints(", ");
+       } else {
+               printstat64(tcp, tcp->u_arg[1]);
        }
-       if (!abbrev(tcp)) {
-               tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
-               tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
-               tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
-#if HAVE_STRUCT_STAT_ST_FLAGS
-               tprints(", st_flags=");
-               printflags(fileflags, statbuf.st_flags, "UF_???");
-#endif
-#if HAVE_STRUCT_STAT_ST_ACLCNT
-               tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
-#endif
-#if HAVE_STRUCT_STAT_ST_LEVEL
-               tprintf(", st_level=%ld", statbuf.st_level);
-#endif
-#if HAVE_STRUCT_STAT_ST_FSTYPE
-               tprintf(", st_fstype=%.*s",
-                       (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
-#endif
-#if HAVE_STRUCT_STAT_ST_GEN
-               tprintf(", st_gen=%u", statbuf.st_gen);
-#endif
-               tprints("}");
+       return 0;
+}
+
+#else
+
+int
+sys_stat64(struct tcb *tcp)
+{
+       return sys_stat(tcp);
+}
+
+int
+sys_fstat64(struct tcb *tcp)
+{
+       return sys_fstat(tcp);
+}
+
+#endif /* HAVE_STRUCT_STAT64 */
+
+int
+sys_newfstatat(struct tcb *tcp)
+{
+       if (entering(tcp)) {
+               print_dirfd(tcp, tcp->u_arg[0]);
+               printpath(tcp, tcp->u_arg[1]);
+               tprints(", ");
+       } else {
+#if defined STAT32_PERSONALITY
+               if (current_personality == STAT32_PERSONALITY)
+                       printstat64(tcp, tcp->u_arg[2]);
+               else
+                       printstat(tcp, tcp->u_arg[2]);
+#elif defined HAVE_STRUCT_STAT64
+               printstat64(tcp, tcp->u_arg[2]);
+#else
+               printstat(tcp, tcp->u_arg[2]);
+#endif /* STAT32_PERSONALITY || HAVE_STRUCT_STAT64 */
+               tprints(", ");
+               printflags(at_flags, tcp->u_arg[3], "AT_???");
        }
-       else
-               tprints("...}");
+       return 0;
 }
-#endif /* HAVE_STAT64 */
 
 #if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
+
 static void
 convertoldstat(const struct __old_kernel_stat *oldbuf, struct stat *newbuf)
 {
+       memset(newbuf, 0, sizeof(*newbuf));
        newbuf->st_dev = oldbuf->st_dev;
        newbuf->st_ino = oldbuf->st_ino;
        newbuf->st_mode = oldbuf->st_mode;
@@ -802,8 +467,6 @@ convertoldstat(const struct __old_kernel_stat *oldbuf, struct stat *newbuf)
        newbuf->st_atime = oldbuf->st_atime;
        newbuf->st_mtime = oldbuf->st_mtime;
        newbuf->st_ctime = oldbuf->st_ctime;
-       newbuf->st_blksize = 0; /* not supported in old_stat */
-       newbuf->st_blocks = 0; /* not supported in old_stat */
 }
 
 static void
@@ -834,124 +497,9 @@ printoldstat(struct tcb *tcp, long addr)
        }
 
        convertoldstat(&statbuf, &newstatbuf);
-       realprintstat(tcp, &newstatbuf);
+       do_printstat(tcp, &newstatbuf);
 }
-#endif
 
-int
-sys_stat(struct tcb *tcp)
-{
-       if (entering(tcp)) {
-               printpath(tcp, tcp->u_arg[0]);
-               tprints(", ");
-       } else {
-               printstat(tcp, tcp->u_arg[1]);
-       }
-       return 0;
-}
-
-#ifdef X32
-static void
-printstat64_x32(struct tcb *tcp, long addr)
-{
-       struct stat64 statbuf;
-
-       if (!addr) {
-               tprints("NULL");
-               return;
-       }
-       if (syserror(tcp) || !verbose(tcp)) {
-               tprintf("%#lx", addr);
-               return;
-       }
-
-       if (umove(tcp, addr, &statbuf) < 0) {
-               tprints("{...}");
-               return;
-       }
-
-       if (!abbrev(tcp)) {
-               tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
-                       (unsigned long) major(statbuf.st_dev),
-                       (unsigned long) minor(statbuf.st_dev),
-                       (unsigned long long) statbuf.st_ino,
-                       sprintmode(statbuf.st_mode));
-               tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
-                       (unsigned long) statbuf.st_nlink,
-                       (unsigned long) statbuf.st_uid,
-                       (unsigned long) statbuf.st_gid);
-               tprintf("st_blksize=%lu, ",
-                       (unsigned long) statbuf.st_blksize);
-               tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
-       }
-       else
-               tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
-       switch (statbuf.st_mode & S_IFMT) {
-       case S_IFCHR: case S_IFBLK:
-               tprintf("st_rdev=makedev(%lu, %lu), ",
-                       (unsigned long) major(statbuf.st_rdev),
-                       (unsigned long) minor(statbuf.st_rdev));
-               break;
-       default:
-               tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
-               break;
-       }
-       if (!abbrev(tcp)) {
-               tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
-               tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
-               tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
-               tprints("}");
-       }
-       else
-               tprints("...}");
-}
-#endif /* X32 */
-
-int
-sys_stat64(struct tcb *tcp)
-{
-#ifdef HAVE_STAT64
-       if (entering(tcp)) {
-               printpath(tcp, tcp->u_arg[0]);
-               tprints(", ");
-       } else {
-# ifdef X32
-               printstat64_x32(tcp, tcp->u_arg[1]);
-# else
-               printstat64(tcp, tcp->u_arg[1]);
-# endif
-       }
-       return 0;
-#else
-       return printargs(tcp);
-#endif
-}
-
-int
-sys_newfstatat(struct tcb *tcp)
-{
-       if (entering(tcp)) {
-               print_dirfd(tcp, tcp->u_arg[0]);
-               printpath(tcp, tcp->u_arg[1]);
-               tprints(", ");
-       } else {
-#ifdef POWERPC64
-               if (current_personality == 0)
-                       printstat(tcp, tcp->u_arg[2]);
-               else
-                       printstat64(tcp, tcp->u_arg[2]);
-#elif defined HAVE_STAT64
-               printstat64(tcp, tcp->u_arg[2]);
-#else
-               printstat(tcp, tcp->u_arg[2]);
-#endif
-               tprints(", ");
-               printflags(at_flags, tcp->u_arg[3], "AT_???");
-       }
-       return 0;
-}
-
-#if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
 int
 sys_oldstat(struct tcb *tcp)
 {
@@ -963,41 +511,7 @@ sys_oldstat(struct tcb *tcp)
        }
        return 0;
 }
-#endif
-
-int
-sys_fstat(struct tcb *tcp)
-{
-       if (entering(tcp)) {
-               printfd(tcp, tcp->u_arg[0]);
-               tprints(", ");
-       } else {
-               printstat(tcp, tcp->u_arg[1]);
-       }
-       return 0;
-}
 
-int
-sys_fstat64(struct tcb *tcp)
-{
-#ifdef HAVE_STAT64
-       if (entering(tcp)) {
-               printfd(tcp, tcp->u_arg[0]);
-               tprints(", ");
-       } else {
-# ifdef X32
-               printstat64_x32(tcp, tcp->u_arg[1]);
-# else
-               printstat64(tcp, tcp->u_arg[1]);
-# endif
-       }
-       return 0;
-#else
-       return printargs(tcp);
-#endif
-}
-
-#if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
 int
 sys_oldfstat(struct tcb *tcp)
 {
@@ -1009,7 +523,8 @@ sys_oldfstat(struct tcb *tcp)
        }
        return 0;
 }
-#endif
+
+#endif /* HAVE_STRUCT___OLD_KERNEL_STAT */
 
 #if defined(SPARC) || defined(SPARC64)
 
@@ -1021,11 +536,6 @@ sys_xstat(struct tcb *tcp)
                printpath(tcp, tcp->u_arg[1]);
                tprints(", ");
        } else {
-# ifdef _STAT64_VER
-               if (tcp->u_arg[0] == _STAT64_VER)
-                       printstat64(tcp, tcp->u_arg[2]);
-               else
-# endif
                printstat(tcp, tcp->u_arg[2]);
        }
        return 0;
@@ -1033,36 +543,15 @@ sys_xstat(struct tcb *tcp)
 
 int
 sys_fxstat(struct tcb *tcp)
-{
-       if (entering(tcp))
-               tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
-       else {
-# ifdef _STAT64_VER
-               if (tcp->u_arg[0] == _STAT64_VER)
-                       printstat64(tcp, tcp->u_arg[2]);
-               else
-# endif
-               printstat(tcp, tcp->u_arg[2]);
-       }
-       return 0;
-}
-
-int
-sys_lxstat(struct tcb *tcp)
 {
        if (entering(tcp)) {
                tprintf("%ld, ", tcp->u_arg[0]);
-               printpath(tcp, tcp->u_arg[1]);
+               printfd(tcp, tcp->u_arg[1]);
                tprints(", ");
        } else {
-# ifdef _STAT64_VER
-               if (tcp->u_arg[0] == _STAT64_VER)
-                       printstat64(tcp, tcp->u_arg[2]);
-               else
-# endif
                printstat(tcp, tcp->u_arg[2]);
        }
        return 0;
 }
 
-#endif /* SPARC[64] */
+#endif /* SPARC || SPARC64 */