Mpersify parsers of struct stat and struct stat64

On many architectures that support multiple personalities,
struct stat differ between personalities.  While old code could handle
these differences, there are some architectures, e.g. sparc64, that also
have different struct stat64.  Rewrite parsers using mpers functionality
to fix these issues.

* fetch_struct_stat.c: New file.
* fetch_struct_stat64.c: Likewise.
* print_struct_stat.c: Likewise.
* oldstat.c: Likewise.
* stat.c: Likewise.
* stat.h: Likewise.
* stat64.c: Likewise.
* file.c: Remove.
* printstat.h: Likewise.
* linux/aarch64/stat32.h: Likewise.
* linux/powerpc64/stat32.h: Likewise.
* linux/riscv/stat32.h: Likewise.
* linux/sparc64/stat32.h: Likewise.
* linux/tile/stat32.h: Likewise.
* linux/x32/stat32.h: Likewise.
* linux/x86_64/stat32.h: Likewise.
* Makefile.am (strace_SOURCES): Add fetch_struct_stat.c,
fetch_struct_stat64.c, print_struct_stat.c, oldstat.c, stat.c, stat.h,
and stat64.c.  Remove file.c, printstat.h, linux/aarch64/stat32.h,
linux/powerpc64/stat32.h, linux/riscv/stat32.h, linux/sparc64/stat32.h,
linux/tile/stat32.h, linux/x32/stat32.h, and linux/x86_64/stat32.h.
* configure.ac (AC_CHECK_MEMBERS): Add struct stat64.st_mtime_nsec.
* defs.h (struct strace_stat): New declaration.
(print_struct_stat): New prototype.
* linux/dummy.h (sys_fstatat64): Remove.
This commit is contained in:
Дмитрий Левин 2016-08-24 00:29:40 +00:00
parent c778f7aff6
commit a7c4ee41ff
19 changed files with 527 additions and 445 deletions

View File

@ -112,8 +112,9 @@ strace_SOURCES = \
fetch_struct_flock.c \
fetch_struct_mmsghdr.c \
fetch_struct_msghdr.c \
fetch_struct_stat.c \
fetch_struct_stat64.c \
fetch_struct_statfs.c \
file.c \
file_handle.c \
file_ioctl.c \
fs_x_ioctl.c \
@ -166,6 +167,7 @@ strace_SOURCES = \
net.c \
netlink.c \
numa.c \
oldstat.c \
open.c \
or1k_atomic.c \
pathtrace.c \
@ -177,13 +179,13 @@ strace_SOURCES = \
print_msgbuf.c \
print_sigevent.c \
print_statfs.c \
print_struct_stat.c \
print_time.c \
print_timex.c \
printmode.c \
printrusage.c \
printsiginfo.c \
printsiginfo.h \
printstat.h \
process.c \
process_vm.c \
ptp.c \
@ -210,6 +212,9 @@ strace_SOURCES = \
sockaddr.c \
socketutils.c \
sram_alloc.c \
stat.c \
stat.h \
stat64.c \
statfs.c \
statfs.h \
strace.c \
@ -303,7 +308,6 @@ EXTRA_DIST = \
linux/aarch64/ioctls_inc0.h \
linux/aarch64/ioctls_inc1.h \
linux/aarch64/signalent1.h \
linux/aarch64/stat32.h \
linux/aarch64/syscallent.h \
linux/aarch64/syscallent1.h \
linux/alpha/arch_getrval2.c \
@ -495,7 +499,6 @@ EXTRA_DIST = \
linux/powerpc64/ioctls_inc0.h \
linux/powerpc64/ioctls_inc1.h \
linux/powerpc64/signalent1.h \
linux/powerpc64/stat32.h \
linux/powerpc64/syscallent.h \
linux/powerpc64/syscallent1.h \
linux/powerpc64/userent.h \
@ -510,7 +513,6 @@ EXTRA_DIST = \
linux/riscv/ioctls_inc0.h \
linux/riscv/ioctls_inc1.h \
linux/riscv/signalent1.h \
linux/riscv/stat32.h \
linux/riscv/syscallent.h \
linux/riscv/syscallent1.h \
linux/s390/arch_regs.c \
@ -587,7 +589,6 @@ EXTRA_DIST = \
linux/sparc64/ioctls_inc1.h \
linux/sparc64/signalent.h \
linux/sparc64/signalent1.h \
linux/sparc64/stat32.h \
linux/sparc64/syscallent.h \
linux/sparc64/syscallent1.h \
linux/sparc64/userent.h \
@ -605,7 +606,6 @@ EXTRA_DIST = \
linux/tile/ioctls_inc0.h \
linux/tile/ioctls_inc1.h \
linux/tile/signalent1.h \
linux/tile/stat32.h \
linux/tile/syscallent.h \
linux/tile/syscallent1.h \
linux/tile/userent.h \
@ -625,7 +625,6 @@ EXTRA_DIST = \
linux/x32/ioctls_inc0.h \
linux/x32/ioctls_inc1.h \
linux/x32/signalent1.h \
linux/x32/stat32.h \
linux/x32/syscallent.h \
linux/x32/syscallent1.h \
linux/x32/userent.h \
@ -647,7 +646,6 @@ EXTRA_DIST = \
linux/x86_64/ioctls_inc2.h \
linux/x86_64/signalent1.h \
linux/x86_64/signalent2.h \
linux/x86_64/stat32.h \
linux/x86_64/syscallent.h \
linux/x86_64/syscallent1.h \
linux/x86_64/syscallent2.h \

View File

@ -325,7 +325,7 @@ AC_CHECK_TYPES([struct stat64, struct __old_kernel_stat],,,
[#include <sys/types.h>
#include <asm/stat.h>])
AC_CHECK_MEMBERS([struct stat.st_mtime_nsec],,,
AC_CHECK_MEMBERS([struct stat.st_mtime_nsec, struct stat64.st_mtime_nsec],,,
[#include <sys/types.h>
#include <asm/stat.h>])

3
defs.h
View File

@ -631,6 +631,9 @@ extern const char *sprint_open_modes(unsigned int);
extern void print_seccomp_filter(struct tcb *, unsigned long);
extern void print_seccomp_fprog(struct tcb *, unsigned long, unsigned short);
struct strace_stat;
extern void print_struct_stat(struct tcb *tcp, const struct strace_stat *const st);
struct strace_statfs;
extern void print_struct_statfs(struct tcb *tcp, long);
extern void print_struct_statfs64(struct tcb *tcp, long, unsigned long);

102
fetch_struct_stat.c Normal file
View File

@ -0,0 +1,102 @@
/*
* Copyright (c) 2014-2016 Dmitry V. Levin <ldv@altlinux.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "defs.h"
#include DEF_MPERS_TYPE(struct_stat)
#include "asm_stat.h"
#if defined MPERS_IS_m32
# undef HAVE_STRUCT_STAT
# undef HAVE_STRUCT_STAT_ST_MTIME_NSEC
# ifdef HAVE_M32_STRUCT_STAT
# define HAVE_STRUCT_STAT 1
# ifdef HAVE_M32_STRUCT_STAT_ST_MTIME_NSEC
# define HAVE_STRUCT_STAT_ST_MTIME_NSEC 1
# endif /* HAVE_M32_STRUCT_STAT_ST_MTIME_NSEC */
# endif /* HAVE_M32_STRUCT_STAT */
#elif defined MPERS_IS_mx32
# undef HAVE_STRUCT_STAT
# undef HAVE_STRUCT_STAT_ST_MTIME_NSEC
# ifdef HAVE_MX32_STRUCT_STAT
# define HAVE_STRUCT_STAT 1
# ifdef HAVE_MX32_STRUCT_STAT_ST_MTIME_NSEC
# define HAVE_STRUCT_STAT_ST_MTIME_NSEC 1
# endif /* HAVE_MX32_STRUCT_STAT_ST_MTIME_NSEC */
# endif /* HAVE_MX32_STRUCT_STAT */
#else /* !MPERS_IS_m32 && !MPERS_IS_mx32 */
# define HAVE_STRUCT_STAT 1
#endif
#ifndef HAVE_STRUCT_STAT
struct stat {};
#endif
typedef struct stat struct_stat;
#include MPERS_DEFS
#include "stat.h"
#ifdef HAVE_STRUCT_STAT_ST_MTIME_NSEC
# define TIME_NSEC(arg) zero_extend_signed_to_ull(arg)
#else
# define TIME_NSEC(arg) 0
#endif
MPERS_PRINTER_DECL(bool, fetch_struct_stat,
struct tcb *tcp, const unsigned long addr,
struct strace_stat *const dst)
{
#ifdef HAVE_STRUCT_STAT
struct_stat buf;
if (umove_or_printaddr(tcp, addr, &buf))
return false;
dst->dev = zero_extend_signed_to_ull(buf.st_dev);
dst->ino = zero_extend_signed_to_ull(buf.st_ino);
dst->rdev = zero_extend_signed_to_ull(buf.st_rdev);
dst->size = zero_extend_signed_to_ull(buf.st_size);
dst->blocks = zero_extend_signed_to_ull(buf.st_blocks);
dst->blksize = zero_extend_signed_to_ull(buf.st_blksize);
dst->mode = zero_extend_signed_to_ull(buf.st_mode);
dst->nlink = zero_extend_signed_to_ull(buf.st_nlink);
dst->uid = zero_extend_signed_to_ull(buf.st_uid);
dst->gid = zero_extend_signed_to_ull(buf.st_gid);
dst->atime = sign_extend_unsigned_to_ll(buf.st_atime);
dst->ctime = sign_extend_unsigned_to_ll(buf.st_ctime);
dst->mtime = sign_extend_unsigned_to_ll(buf.st_mtime);
dst->atime_nsec = TIME_NSEC(buf.st_atime_nsec);
dst->ctime_nsec = TIME_NSEC(buf.st_ctime_nsec);
dst->mtime_nsec = TIME_NSEC(buf.st_mtime_nsec);
return true;
#else /* !HAVE_STRUCT_STAT */
printaddr(addr);
return false;
#endif
}

100
fetch_struct_stat64.c Normal file
View File

@ -0,0 +1,100 @@
/*
* Copyright (c) 2014-2016 Dmitry V. Levin <ldv@altlinux.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "defs.h"
#include DEF_MPERS_TYPE(struct_stat64)
#include "asm_stat.h"
#if defined MPERS_IS_m32
# undef HAVE_STRUCT_STAT64
# undef HAVE_STRUCT_STAT64_ST_MTIME_NSEC
# ifdef HAVE_M32_STRUCT_STAT64
# define HAVE_STRUCT_STAT64 1
# ifdef HAVE_M32_STRUCT_STAT64_ST_MTIME_NSEC
# define HAVE_STRUCT_STAT64_ST_MTIME_NSEC 1
# endif /* HAVE_M32_STRUCT_STAT64_ST_MTIME_NSEC */
# endif /* HAVE_M32_STRUCT_STAT64 */
#elif defined MPERS_IS_mx32
# undef HAVE_STRUCT_STAT64
# undef HAVE_STRUCT_STAT64_ST_MTIME_NSEC
# ifdef HAVE_MX32_STRUCT_STAT64
# define HAVE_STRUCT_STAT64 1
# ifdef HAVE_MX32_STRUCT_STAT64_ST_MTIME_NSEC
# define HAVE_STRUCT_STAT64_ST_MTIME_NSEC 1
# endif /* HAVE_MX32_STRUCT_STAT64_ST_MTIME_NSEC */
# endif /* HAVE_MX32_STRUCT_STAT64 */
#endif /* MPERS_IS_m32 || MPERS_IS_mx32 */
#ifndef HAVE_STRUCT_STAT64
struct stat64 {};
#endif
typedef struct stat64 struct_stat64;
#include MPERS_DEFS
#include "stat.h"
#ifdef HAVE_STRUCT_STAT64_ST_MTIME_NSEC
# define TIME_NSEC(arg) zero_extend_signed_to_ull(arg)
#else
# define TIME_NSEC(arg) 0
#endif
MPERS_PRINTER_DECL(bool, fetch_struct_stat64,
struct tcb *tcp, const unsigned long addr,
struct strace_stat *const dst)
{
#ifdef HAVE_STRUCT_STAT64
struct_stat64 buf;
if (umove_or_printaddr(tcp, addr, &buf))
return false;
dst->dev = zero_extend_signed_to_ull(buf.st_dev);
dst->ino = zero_extend_signed_to_ull(buf.st_ino);
dst->rdev = zero_extend_signed_to_ull(buf.st_rdev);
dst->size = zero_extend_signed_to_ull(buf.st_size);
dst->blocks = zero_extend_signed_to_ull(buf.st_blocks);
dst->blksize = zero_extend_signed_to_ull(buf.st_blksize);
dst->mode = zero_extend_signed_to_ull(buf.st_mode);
dst->nlink = zero_extend_signed_to_ull(buf.st_nlink);
dst->uid = zero_extend_signed_to_ull(buf.st_uid);
dst->gid = zero_extend_signed_to_ull(buf.st_gid);
dst->atime = sign_extend_unsigned_to_ll(buf.st_atime);
dst->ctime = sign_extend_unsigned_to_ll(buf.st_ctime);
dst->mtime = sign_extend_unsigned_to_ll(buf.st_mtime);
dst->atime_nsec = TIME_NSEC(buf.st_atime_nsec);
dst->ctime_nsec = TIME_NSEC(buf.st_ctime_nsec);
dst->mtime_nsec = TIME_NSEC(buf.st_mtime_nsec);
return true;
#else /* !HAVE_STRUCT_STAT64 */
printaddr(addr);
return false;
#endif
}

293
file.c
View File

@ -1,293 +0,0 @@
/*
* Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
* Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
* Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
* Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "defs.h"
#include "asm_stat.h"
/* for S_IFMT */
#define stat libc_stat
#define stat64 libc_stat64
#include <sys/stat.h>
#undef stat
#undef stat64
/* These might be macros. */
#undef st_atime
#undef st_mtime
#undef st_ctime
#if defined MAJOR_IN_SYSMACROS
# include <sys/sysmacros.h>
#elif defined MAJOR_IN_MKDEV
# include <sys/mkdev.h>
#endif
/* several stats */
#include "printstat.h"
/* all locally defined structures provide these fields */
#undef HAVE_STRUCT_STAT_ST_MTIME_NSEC
#define HAVE_STRUCT_STAT_ST_MTIME_NSEC 1
#undef STAT32_PERSONALITY
#if SUPPORTED_PERSONALITIES > 1
# include "stat32.h"
#endif
#ifdef STAT32_PERSONALITY
# define DO_PRINTSTAT do_printstat32
# define STRUCT_STAT struct stat32
# include "printstat.h"
#endif /* STAT32_PERSONALITY */
static void
printstat(struct tcb *tcp, long addr)
{
struct stat statbuf;
#ifdef STAT32_PERSONALITY
if (current_personality == STAT32_PERSONALITY) {
struct stat32 statbuf;
if (!umove_or_printaddr(tcp, addr, &statbuf))
do_printstat32(tcp, &statbuf);
return;
}
#endif
if (!umove_or_printaddr(tcp, addr, &statbuf))
do_printstat(tcp, &statbuf);
}
SYS_FUNC(stat)
{
if (entering(tcp)) {
printpath(tcp, tcp->u_arg[0]);
tprints(", ");
} else {
printstat(tcp, tcp->u_arg[1]);
}
return 0;
}
SYS_FUNC(fstat)
{
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 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.
*
* Similarly, aarch64 has a unified `struct stat' but its arm personality
* needs `struct stat64' (unlike x86, it shouldn't be packed).
*/
struct stat64 {
unsigned long long st_dev;
unsigned char __pad0[4];
unsigned int __st_ino;
unsigned int st_mode;
unsigned int st_nlink;
unsigned int st_uid;
unsigned int st_gid;
unsigned long long st_rdev;
unsigned char __pad3[4];
long long st_size;
unsigned int st_blksize;
unsigned long long 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 long long st_ino;
}
# if defined X86_64 || defined X32
ATTRIBUTE_PACKED
# define STAT64_SIZE 96
# else
# define STAT64_SIZE 104
# 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
# include "printstat.h"
static void
printstat64(struct tcb *tcp, long addr)
{
struct stat64 statbuf;
# ifdef STAT64_SIZE
(void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
# endif
# if defined STAT32_PERSONALITY && !defined SPARC64
if (current_personality != STAT32_PERSONALITY) {
printstat(tcp, addr);
return;
}
# endif /* STAT32_PERSONALITY && !SPARC64 */
if (!umove_or_printaddr(tcp, addr, &statbuf))
do_printstat64(tcp, &statbuf);
}
SYS_FUNC(stat64)
{
if (entering(tcp)) {
printpath(tcp, tcp->u_arg[0]);
tprints(", ");
} else {
printstat64(tcp, tcp->u_arg[1]);
}
return 0;
}
SYS_FUNC(fstat64)
{
if (entering(tcp)) {
printfd(tcp, tcp->u_arg[0]);
tprints(", ");
} else {
printstat64(tcp, tcp->u_arg[1]);
}
return 0;
}
#else
SYS_FUNC(stat64)
{
return sys_stat(tcp);
}
SYS_FUNC(fstat64)
{
return sys_fstat(tcp);
}
#endif /* HAVE_STRUCT_STAT64 */
SYS_FUNC(newfstatat)
{
if (entering(tcp)) {
print_dirfd(tcp, tcp->u_arg[0]);
printpath(tcp, tcp->u_arg[1]);
tprints(", ");
} else {
#if defined STAT32_PERSONALITY && !defined SPARC64
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_???");
}
return 0;
}
#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;
newbuf->st_nlink = oldbuf->st_nlink;
newbuf->st_uid = oldbuf->st_uid;
newbuf->st_gid = oldbuf->st_gid;
newbuf->st_rdev = oldbuf->st_rdev;
newbuf->st_size = oldbuf->st_size;
newbuf->st_atime = oldbuf->st_atime;
newbuf->st_mtime = oldbuf->st_mtime;
newbuf->st_ctime = oldbuf->st_ctime;
}
static void
printoldstat(struct tcb *tcp, long addr)
{
struct __old_kernel_stat statbuf;
struct stat newstatbuf;
if (!umove_or_printaddr(tcp, addr, &statbuf)) {
convertoldstat(&statbuf, &newstatbuf);
do_printstat(tcp, &newstatbuf);
}
}
SYS_FUNC(oldstat)
{
if (entering(tcp)) {
printpath(tcp, tcp->u_arg[0]);
tprints(", ");
} else {
printoldstat(tcp, tcp->u_arg[1]);
}
return 0;
}
SYS_FUNC(oldfstat)
{
if (entering(tcp)) {
printfd(tcp, tcp->u_arg[0]);
tprints(", ");
} else {
printoldstat(tcp, tcp->u_arg[1]);
}
return 0;
}
#endif /* HAVE_STRUCT___OLD_KERNEL_STAT */

View File

@ -1 +0,0 @@
#include "x86_64/stat32.h"

View File

@ -59,7 +59,6 @@
#define sys_connect sys_bind
#define sys_fchdir sys_close
#define sys_fdatasync sys_close
#define sys_fstatat64 sys_newfstatat
#define sys_fsync sys_close
#define sys_getegid sys_getuid
#define sys_getegid16 sys_geteuid16

View File

@ -1,26 +0,0 @@
#ifndef STRACE_STAT32_H
#define STRACE_STAT32_H
struct stat32 {
unsigned int st_dev;
unsigned int st_ino;
unsigned int st_mode;
unsigned short st_nlink;
unsigned int st_uid;
unsigned int 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[2];
};
# define STAT32_PERSONALITY 1
#endif /* !STRACE_STAT32_H */

View File

@ -1 +0,0 @@
/* no 32-bit stat */

View File

@ -1,26 +0,0 @@
#ifndef STRACE_STAT32_H
#define STRACE_STAT32_H
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 1
#endif /* !STRACE_STAT32_H */

View File

@ -1 +0,0 @@
/* no 32-bit stat */

View File

@ -1 +0,0 @@
#include "x86_64/stat32.h"

View File

@ -1,26 +0,0 @@
#ifndef STRACE_STAT32_H
#define STRACE_STAT32_H
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[2];
};
# define STAT32_PERSONALITY 1
#endif /* !STRACE_STAT32_H */

84
oldstat.c Normal file
View File

@ -0,0 +1,84 @@
/*
* Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
* Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
* Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
* Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
* Copyright (c) 2005-2015 Dmitry V. Levin <ldv@altlinux.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "defs.h"
#include "asm_stat.h"
#include "stat.h"
#ifdef HAVE_STRUCT___OLD_KERNEL_STAT
static void
print_old_kernel_stat(struct tcb *tcp, const unsigned long addr)
{
struct __old_kernel_stat buf;
if (umove_or_printaddr(tcp, addr, &buf))
return;
struct strace_stat st = {
.dev = zero_extend_signed_to_ull(buf.st_dev),
.ino = zero_extend_signed_to_ull(buf.st_ino),
.rdev = zero_extend_signed_to_ull(buf.st_rdev),
.size = zero_extend_signed_to_ull(buf.st_size),
.mode = zero_extend_signed_to_ull(buf.st_mode),
.nlink = zero_extend_signed_to_ull(buf.st_nlink),
.uid = zero_extend_signed_to_ull(buf.st_uid),
.gid = zero_extend_signed_to_ull(buf.st_gid),
.atime = sign_extend_unsigned_to_ll(buf.st_atime),
.ctime = sign_extend_unsigned_to_ll(buf.st_ctime),
.mtime = sign_extend_unsigned_to_ll(buf.st_mtime)
};
print_struct_stat(tcp, &st);
}
SYS_FUNC(oldstat)
{
if (entering(tcp)) {
printpath(tcp, tcp->u_arg[0]);
tprints(", ");
} else {
print_old_kernel_stat(tcp, tcp->u_arg[1]);
}
return 0;
}
SYS_FUNC(oldfstat)
{
if (entering(tcp)) {
printfd(tcp, tcp->u_arg[0]);
tprints(", ");
} else {
print_old_kernel_stat(tcp, tcp->u_arg[1]);
}
return 0;
}
#endif /* HAVE_STRUCT___OLD_KERNEL_STAT */

View File

@ -6,7 +6,7 @@
* Copyright (c) 2009 Denys Vlasenko <dvlasenk@redhat.com>
* Copyright (c) 2009-2010 Andreas Schwab <schwab@linux-m68k.org>
* Copyright (c) 2012 H.J. Lu <hongjiu.lu@intel.com>
* Copyright (c) 2005-2015 Dmitry V. Levin <ldv@altlinux.org>
* Copyright (c) 2005-2016 Dmitry V. Levin <ldv@altlinux.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -32,87 +32,60 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef DO_PRINTSTAT
# define DO_PRINTSTAT do_printstat
#include "defs.h"
#include <sys/stat.h>
#include "stat.h"
#if defined MAJOR_IN_SYSMACROS
# include <sys/sysmacros.h>
#elif defined MAJOR_IN_MKDEV
# include <sys/mkdev.h>
#endif
#ifndef STRUCT_STAT
# define STRUCT_STAT struct stat
#endif
#ifndef STAT_MAJOR
# define STAT_MAJOR(x) major(x)
#endif
#ifndef STAT_MINOR
# define STAT_MINOR(x) minor(x)
#endif
static void
DO_PRINTSTAT(struct tcb *tcp, const STRUCT_STAT *statbuf)
void
print_struct_stat(struct tcb *tcp, const struct strace_stat *const st)
{
tprints("{");
if (!abbrev(tcp)) {
tprintf("st_dev=makedev(%u, %u), st_ino=%llu, st_mode=",
(unsigned int) STAT_MAJOR(statbuf->st_dev),
(unsigned int) STAT_MINOR(statbuf->st_dev),
zero_extend_signed_to_ull(statbuf->st_ino));
print_symbolic_mode_t(statbuf->st_mode);
tprintf(", st_nlink=%u, st_uid=%u, st_gid=%u",
(unsigned int) statbuf->st_nlink,
(unsigned int) statbuf->st_uid,
(unsigned int) statbuf->st_gid);
tprintf(", st_blksize=%u", (unsigned int) statbuf->st_blksize);
tprintf(", st_blocks=%llu",
zero_extend_signed_to_ull(statbuf->st_blocks));
(unsigned int) major(st->dev),
(unsigned int) minor(st->dev),
st->ino);
print_symbolic_mode_t(st->mode);
tprintf(", st_nlink=%llu, st_uid=%llu, st_gid=%llu",
st->nlink, st->uid, st->gid);
tprintf(", st_blksize=%llu", st->blksize);
tprintf(", st_blocks=%llu", st->blocks);
} else {
tprints("st_mode=");
print_symbolic_mode_t(statbuf->st_mode);
print_symbolic_mode_t(st->mode);
}
switch (statbuf->st_mode & S_IFMT) {
switch (st->mode & S_IFMT) {
case S_IFCHR: case S_IFBLK:
tprintf(", st_rdev=makedev(%u, %u)",
(unsigned int) STAT_MAJOR(statbuf->st_rdev),
(unsigned int) STAT_MINOR(statbuf->st_rdev));
(unsigned int) major(st->rdev),
(unsigned int) minor(st->rdev));
break;
default:
tprintf(", st_size=%llu",
zero_extend_signed_to_ull(statbuf->st_size));
tprintf(", st_size=%llu", st->size);
break;
}
if (!abbrev(tcp)) {
const bool cast = sizeof(statbuf->st_atime) == sizeof(int);
tprints(", st_atime=");
tprints(sprinttime(cast ? (time_t) (int) statbuf->st_atime:
(time_t) statbuf->st_atime));
#ifdef HAVE_STRUCT_STAT_ST_MTIME_NSEC
if (statbuf->st_atime_nsec)
tprintf(".%09lu", (unsigned long) statbuf->st_atime_nsec);
#endif
tprints(sprinttime(st->atime));
if (st->atime_nsec)
tprintf(".%09llu", st->atime_nsec);
tprints(", st_mtime=");
tprints(sprinttime(cast ? (time_t) (int) statbuf->st_mtime:
(time_t) statbuf->st_mtime));
#ifdef HAVE_STRUCT_STAT_ST_MTIME_NSEC
if (statbuf->st_mtime_nsec)
tprintf(".%09lu", (unsigned long) statbuf->st_mtime_nsec);
#endif
tprints(sprinttime(st->mtime));
if (st->mtime_nsec)
tprintf(".%09llu", st->mtime_nsec);
tprints(", st_ctime=");
tprints(sprinttime(cast ? (time_t) (int) statbuf->st_ctime:
(time_t) statbuf->st_ctime));
#ifdef HAVE_STRUCT_STAT_ST_MTIME_NSEC
if (statbuf->st_ctime_nsec)
tprintf(".%09lu", (unsigned long) statbuf->st_ctime_nsec);
#endif
tprints(sprinttime(st->ctime));
if (st->ctime_nsec)
tprintf(".%09llu", st->ctime_nsec);
} else {
tprints(", ...");
}
tprints("}");
}
#undef STAT_MINOR
#undef STAT_MAJOR
#undef STRUCT_STAT
#undef DO_PRINTSTAT

74
stat.c Normal file
View File

@ -0,0 +1,74 @@
/*
* Copyright (c) 2005-2015 Dmitry V. Levin <ldv@altlinux.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "defs.h"
#include "stat.h"
static void
decode_struct_stat(struct tcb *tcp, const unsigned long addr)
{
struct strace_stat st;
if (fetch_struct_stat(tcp, addr, &st))
print_struct_stat(tcp, &st);
}
SYS_FUNC(stat)
{
if (entering(tcp)) {
printpath(tcp, tcp->u_arg[0]);
tprints(", ");
} else {
decode_struct_stat(tcp, tcp->u_arg[1]);
}
return 0;
}
SYS_FUNC(fstat)
{
if (entering(tcp)) {
printfd(tcp, tcp->u_arg[0]);
tprints(", ");
} else {
decode_struct_stat(tcp, tcp->u_arg[1]);
}
return 0;
}
SYS_FUNC(newfstatat)
{
if (entering(tcp)) {
print_dirfd(tcp, tcp->u_arg[0]);
printpath(tcp, tcp->u_arg[1]);
tprints(", ");
} else {
decode_struct_stat(tcp, tcp->u_arg[2]);
tprints(", ");
printflags(at_flags, tcp->u_arg[3], "AT_???");
}
return 0;
}

50
stat.h Normal file
View File

@ -0,0 +1,50 @@
/*
* Copyright (c) 2016 Dmitry V. Levin <ldv@altlinux.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef STRACE_STAT_H
#define STRACE_STAT_H
struct strace_stat {
unsigned long long dev;
unsigned long long ino;
unsigned long long rdev;
unsigned long long size;
unsigned long long blocks;
unsigned long long blksize;
unsigned long long mode;
unsigned long long nlink;
unsigned long long uid;
unsigned long long gid;
long long atime;
long long ctime;
long long mtime;
unsigned long long atime_nsec;
unsigned long long ctime_nsec;
unsigned long long mtime_nsec;
};
#endif /* !STRACE_STAT_H */

74
stat64.c Normal file
View File

@ -0,0 +1,74 @@
/*
* Copyright (c) 2005-2015 Dmitry V. Levin <ldv@altlinux.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "defs.h"
#include "stat.h"
static void
decode_struct_stat64(struct tcb *tcp, const unsigned long addr)
{
struct strace_stat st;
if (fetch_struct_stat64(tcp, addr, &st))
print_struct_stat(tcp, &st);
}
SYS_FUNC(stat64)
{
if (entering(tcp)) {
printpath(tcp, tcp->u_arg[0]);
tprints(", ");
} else {
decode_struct_stat64(tcp, tcp->u_arg[1]);
}
return 0;
}
SYS_FUNC(fstat64)
{
if (entering(tcp)) {
printfd(tcp, tcp->u_arg[0]);
tprints(", ");
} else {
decode_struct_stat64(tcp, tcp->u_arg[1]);
}
return 0;
}
SYS_FUNC(fstatat64)
{
if (entering(tcp)) {
print_dirfd(tcp, tcp->u_arg[0]);
printpath(tcp, tcp->u_arg[1]);
tprints(", ");
} else {
decode_struct_stat64(tcp, tcp->u_arg[2]);
tprints(", ");
printflags(at_flags, tcp->u_arg[3], "AT_???");
}
return 0;
}