]> granicus.if.org Git - strace/blobdiff - io.c
tests: add ftruncate64.test and truncate64.test
[strace] / io.c
diff --git a/io.c b/io.c
index 3626c77633e87abd3b00ef8ffb2bf69125d9e794..5ee967c1bbee1cfd8e7e2540820a156d8cbb8fa3 100644 (file)
--- a/io.c
+++ b/io.c
 #include <fcntl.h>
 #include <sys/uio.h>
 
-int
-sys_read(struct tcb *tcp)
+SYS_FUNC(read)
 {
        if (entering(tcp)) {
                printfd(tcp, tcp->u_arg[0]);
                tprints(", ");
        } else {
                if (syserror(tcp))
-                       tprintf("%#lx", tcp->u_arg[1]);
+                       printaddr(tcp->u_arg[1]);
                else
                        printstr(tcp, tcp->u_arg[1], tcp->u_rval);
                tprintf(", %lu", tcp->u_arg[2]);
@@ -48,16 +47,14 @@ sys_read(struct tcb *tcp)
        return 0;
 }
 
-int
-sys_write(struct tcb *tcp)
+SYS_FUNC(write)
 {
-       if (entering(tcp)) {
-               printfd(tcp, tcp->u_arg[0]);
-               tprints(", ");
-               printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
-               tprintf(", %lu", tcp->u_arg[2]);
-       }
-       return 0;
+       printfd(tcp, tcp->u_arg[0]);
+       tprints(", ");
+       printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
+       tprintf(", %lu", tcp->u_arg[2]);
+
+       return RVAL_DECODED;
 }
 
 /*
@@ -67,25 +64,9 @@ sys_write(struct tcb *tcp)
 void
 tprint_iov_upto(struct tcb *tcp, unsigned long len, unsigned long addr, int decode_iov, unsigned long data_size)
 {
-#if SUPPORTED_PERSONALITIES > 1
-       union {
-               struct { u_int32_t base; u_int32_t len; } iov32;
-               struct { u_int64_t base; u_int64_t len; } iov64;
-       } iov;
-#define sizeof_iov \
-       (current_wordsize == 4 ? sizeof(iov.iov32) : sizeof(iov.iov64))
-#define iov_iov_base \
-       (current_wordsize == 4 ? (uint64_t) iov.iov32.base : iov.iov64.base)
-#define iov_iov_len \
-       (current_wordsize == 4 ? (uint64_t) iov.iov32.len : iov.iov64.len)
-#else
-       struct iovec iov;
-#define sizeof_iov sizeof(iov)
-#define iov_iov_base iov.iov_base
-#define iov_iov_len iov.iov_len
-#endif
+       unsigned long iov[2];
        unsigned long size, cur, end, abbrev_end;
-       int failed = 0;
+       const unsigned long sizeof_iov = current_wordsize * 2;
 
        if (!len) {
                tprints("[]");
@@ -93,8 +74,9 @@ tprint_iov_upto(struct tcb *tcp, unsigned long len, unsigned long addr, int deco
        }
        size = len * sizeof_iov;
        end = addr + size;
-       if (!verbose(tcp) || size / sizeof_iov != len || end < addr) {
-               tprintf("%#lx", addr);
+       if (!verbose(tcp) || (exiting(tcp) && syserror(tcp)) ||
+           !addr || size / sizeof_iov != len || end < addr) {
+               printaddr(addr);
                return;
        }
        if (abbrev(tcp)) {
@@ -112,28 +94,21 @@ tprint_iov_upto(struct tcb *tcp, unsigned long len, unsigned long addr, int deco
                        tprints("...");
                        break;
                }
-               if (umoven(tcp, cur, sizeof_iov, (char *) &iov) < 0) {
-                       tprints("?");
-                       failed = 1;
+               if (umove_ulong_array_or_printaddr(tcp, cur, iov,
+                                                  ARRAY_SIZE(iov)))
                        break;
-               }
                tprints("{");
                if (decode_iov) {
-                       unsigned long len = iov_iov_len;
+                       unsigned long len = iov[1];
                        if (len > data_size)
                                len = data_size;
                        data_size -= len;
-                       printstr(tcp, (long) iov_iov_base, len);
+                       printstr(tcp, iov[0], len);
                } else
-                       tprintf("%#lx", (long) iov_iov_base);
-               tprintf(", %lu}", (unsigned long)iov_iov_len);
+                       printaddr(iov[0]);
+               tprintf(", %lu}", iov[1]);
        }
        tprints("]");
-       if (failed)
-               tprintf(" %#lx", addr);
-#undef sizeof_iov
-#undef iov_iov_base
-#undef iov_iov_len
 }
 
 void
@@ -142,34 +117,26 @@ tprint_iov(struct tcb *tcp, unsigned long len, unsigned long addr, int decode_io
        tprint_iov_upto(tcp, len, addr, decode_iov, (unsigned long) -1L);
 }
 
-int
-sys_readv(struct tcb *tcp)
+SYS_FUNC(readv)
 {
        if (entering(tcp)) {
                printfd(tcp, tcp->u_arg[0]);
                tprints(", ");
        } else {
-               if (syserror(tcp)) {
-                       tprintf("%#lx, %lu",
-                                       tcp->u_arg[1], tcp->u_arg[2]);
-                       return 0;
-               }
                tprint_iov(tcp, tcp->u_arg[2], tcp->u_arg[1], 1);
                tprintf(", %lu", tcp->u_arg[2]);
        }
        return 0;
 }
 
-int
-sys_writev(struct tcb *tcp)
+SYS_FUNC(writev)
 {
-       if (entering(tcp)) {
-               printfd(tcp, tcp->u_arg[0]);
-               tprints(", ");
-               tprint_iov(tcp, tcp->u_arg[2], tcp->u_arg[1], 1);
-               tprintf(", %lu", tcp->u_arg[2]);
-       }
-       return 0;
+       printfd(tcp, tcp->u_arg[0]);
+       tprints(", ");
+       tprint_iov(tcp, tcp->u_arg[2], tcp->u_arg[1], 1);
+       tprintf(", %lu", tcp->u_arg[2]);
+
+       return RVAL_DECODED;
 }
 
 /* The SH4 ABI does allow long longs in odd-numbered registers, but
@@ -183,15 +150,14 @@ sys_writev(struct tcb *tcp)
 #define PREAD_OFFSET_ARG 3
 #endif
 
-int
-sys_pread(struct tcb *tcp)
+SYS_FUNC(pread)
 {
        if (entering(tcp)) {
                printfd(tcp, tcp->u_arg[0]);
                tprints(", ");
        } else {
                if (syserror(tcp))
-                       tprintf("%#lx", tcp->u_arg[1]);
+                       printaddr(tcp->u_arg[1]);
                else
                        printstr(tcp, tcp->u_arg[1], tcp->u_rval);
                tprintf(", %lu, ", tcp->u_arg[2]);
@@ -200,17 +166,15 @@ sys_pread(struct tcb *tcp)
        return 0;
 }
 
-int
-sys_pwrite(struct tcb *tcp)
+SYS_FUNC(pwrite)
 {
-       if (entering(tcp)) {
-               printfd(tcp, tcp->u_arg[0]);
-               tprints(", ");
-               printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
-               tprintf(", %lu, ", tcp->u_arg[2]);
-               printllval(tcp, "%llu", PREAD_OFFSET_ARG);
-       }
-       return 0;
+       printfd(tcp, tcp->u_arg[0]);
+       tprints(", ");
+       printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
+       tprintf(", %lu, ", tcp->u_arg[2]);
+       printllval(tcp, "%llu", PREAD_OFFSET_ARG);
+
+       return RVAL_DECODED;
 }
 
 static void
@@ -218,7 +182,11 @@ print_llu_from_low_high_val(struct tcb *tcp, int arg)
 {
 #if SIZEOF_LONG == SIZEOF_LONG_LONG
 # if SUPPORTED_PERSONALITIES > 1
+#  ifdef X86_64
+       if (current_personality != 1)
+#  else
        if (current_wordsize == sizeof(long))
+#  endif
 # endif
                tprintf("%lu", (unsigned long) tcp->u_arg[arg]);
 # if SUPPORTED_PERSONALITIES > 1
@@ -239,30 +207,12 @@ print_llu_from_low_high_val(struct tcb *tcp, int arg)
 #endif
 }
 
-int
-sys_preadv(struct tcb *tcp)
+SYS_FUNC(preadv)
 {
        if (entering(tcp)) {
                printfd(tcp, tcp->u_arg[0]);
                tprints(", ");
        } else {
-               if (syserror(tcp)) {
-                       tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
-                       return 0;
-               }
-               tprint_iov(tcp, tcp->u_arg[2], tcp->u_arg[1], 1);
-               tprintf(", %lu, ", tcp->u_arg[2]);
-               print_llu_from_low_high_val(tcp, 3);
-       }
-       return 0;
-}
-
-int
-sys_pwritev(struct tcb *tcp)
-{
-       if (entering(tcp)) {
-               printfd(tcp, tcp->u_arg[0]);
-               tprints(", ");
                tprint_iov(tcp, tcp->u_arg[2], tcp->u_arg[1], 1);
                tprintf(", %lu, ", tcp->u_arg[2]);
                print_llu_from_low_high_val(tcp, 3);
@@ -270,159 +220,67 @@ sys_pwritev(struct tcb *tcp)
        return 0;
 }
 
-static void
-print_off_t(struct tcb *tcp, long addr)
+SYS_FUNC(pwritev)
 {
-       unsigned long offset;
-
-       if (!addr) {
-               tprints("NULL");
-               return;
-       }
+       printfd(tcp, tcp->u_arg[0]);
+       tprints(", ");
+       tprint_iov(tcp, tcp->u_arg[2], tcp->u_arg[1], 1);
+       tprintf(", %lu, ", tcp->u_arg[2]);
+       print_llu_from_low_high_val(tcp, 3);
 
-#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
-       if (current_wordsize == 4) {
-               uint32_t off;
-
-               if (umove(tcp, addr, &off) < 0)
-                       tprintf("%#lx", addr);
-               else
-                       tprintf("[%u]", off);
-       } else
-#endif
-       if (umove(tcp, addr, &offset) < 0)
-               tprintf("%#lx", addr);
-       else
-               tprintf("[%lu]", offset);
-}
-
-int
-sys_sendfile(struct tcb *tcp)
-{
-       if (entering(tcp)) {
-               printfd(tcp, tcp->u_arg[0]);
-               tprints(", ");
-               printfd(tcp, tcp->u_arg[1]);
-               tprints(", ");
-               print_off_t(tcp, tcp->u_arg[2]);
-               tprintf(", %lu", tcp->u_arg[3]);
-       }
-       return 0;
-}
-
-void
-print_loff_t(struct tcb *tcp, long addr)
-{
-       loff_t offset;
-
-       if (!addr)
-               tprints("NULL");
-       else if (umove(tcp, addr, &offset) < 0)
-               tprintf("%#lx", addr);
-       else
-               tprintf("[%llu]", (unsigned long long int) offset);
-}
-
-int
-sys_sendfile64(struct tcb *tcp)
-{
-       if (entering(tcp)) {
-               printfd(tcp, tcp->u_arg[0]);
-               tprints(", ");
-               printfd(tcp, tcp->u_arg[1]);
-               tprints(", ");
-               print_loff_t(tcp, tcp->u_arg[2]);
-               tprintf(", %lu", tcp->u_arg[3]);
-       }
-       return 0;
+       return RVAL_DECODED;
 }
 
 #include "xlat/splice_flags.h"
 
-int
-sys_tee(struct tcb *tcp)
+SYS_FUNC(tee)
 {
-       if (entering(tcp)) {
-               /* int fd_in */
-               printfd(tcp, tcp->u_arg[0]);
-               tprints(", ");
-               /* int fd_out */
-               printfd(tcp, tcp->u_arg[1]);
-               tprints(", ");
-               /* size_t len */
-               tprintf("%lu, ", tcp->u_arg[2]);
-               /* unsigned int flags */
-               printflags(splice_flags, tcp->u_arg[3], "SPLICE_F_???");
-       }
-       return 0;
-}
+       /* int fd_in */
+       printfd(tcp, tcp->u_arg[0]);
+       tprints(", ");
+       /* int fd_out */
+       printfd(tcp, tcp->u_arg[1]);
+       tprints(", ");
+       /* size_t len */
+       tprintf("%lu, ", tcp->u_arg[2]);
+       /* unsigned int flags */
+       printflags(splice_flags, tcp->u_arg[3], "SPLICE_F_???");
 
-int
-sys_splice(struct tcb *tcp)
-{
-       if (entering(tcp)) {
-               /* int fd_in */
-               printfd(tcp, tcp->u_arg[0]);
-               tprints(", ");
-               /* loff_t *off_in */
-               print_loff_t(tcp, tcp->u_arg[1]);
-               tprints(", ");
-               /* int fd_out */
-               printfd(tcp, tcp->u_arg[2]);
-               tprints(", ");
-               /* loff_t *off_out */
-               print_loff_t(tcp, tcp->u_arg[3]);
-               tprints(", ");
-               /* size_t len */
-               tprintf("%lu, ", tcp->u_arg[4]);
-               /* unsigned int flags */
-               printflags(splice_flags, tcp->u_arg[5], "SPLICE_F_???");
-       }
-       return 0;
+       return RVAL_DECODED;
 }
 
-int
-sys_vmsplice(struct tcb *tcp)
+SYS_FUNC(splice)
 {
-       if (entering(tcp)) {
-               /* int fd */
-               printfd(tcp, tcp->u_arg[0]);
-               tprints(", ");
-               /* const struct iovec *iov, unsigned long nr_segs */
-               tprint_iov(tcp, tcp->u_arg[2], tcp->u_arg[1], 1);
-               tprintf(", %lu, ", tcp->u_arg[2]);
-               /* unsigned int flags */
-               printflags(splice_flags, tcp->u_arg[3], "SPLICE_F_???");
-       }
-       return 0;
+       /* int fd_in */
+       printfd(tcp, tcp->u_arg[0]);
+       tprints(", ");
+       /* loff_t *off_in */
+       printnum_int64(tcp, tcp->u_arg[1], "%" PRIu64);
+       tprints(", ");
+       /* int fd_out */
+       printfd(tcp, tcp->u_arg[2]);
+       tprints(", ");
+       /* loff_t *off_out */
+       printnum_int64(tcp, tcp->u_arg[3], "%" PRIu64);
+       tprints(", ");
+       /* size_t len */
+       tprintf("%lu, ", tcp->u_arg[4]);
+       /* unsigned int flags */
+       printflags(splice_flags, tcp->u_arg[5], "SPLICE_F_???");
+
+       return RVAL_DECODED;
 }
 
-int
-sys_ioctl(struct tcb *tcp)
+SYS_FUNC(vmsplice)
 {
-       const struct_ioctlent *iop;
+       /* int fd */
+       printfd(tcp, tcp->u_arg[0]);
+       tprints(", ");
+       /* const struct iovec *iov, unsigned long nr_segs */
+       tprint_iov(tcp, tcp->u_arg[2], tcp->u_arg[1], 1);
+       tprintf(", %lu, ", tcp->u_arg[2]);
+       /* unsigned int flags */
+       printflags(splice_flags, tcp->u_arg[3], "SPLICE_F_???");
 
-       if (entering(tcp)) {
-               printfd(tcp, tcp->u_arg[0]);
-               tprints(", ");
-               if (!ioctl_decode_command_number(tcp->u_arg[1])) {
-                       iop = ioctl_lookup(tcp->u_arg[1]);
-                       if (iop) {
-                               tprints(iop->symbol);
-                               while ((iop = ioctl_next_match(iop)))
-                                       tprintf(" or %s", iop->symbol);
-                       } else {
-                               ioctl_print_code(tcp->u_arg[1]);
-                       }
-               }
-               ioctl_decode(tcp, tcp->u_arg[1], tcp->u_arg[2]);
-       }
-       else {
-               int ret = ioctl_decode(tcp, tcp->u_arg[1], tcp->u_arg[2]);
-               if (!ret)
-                       tprintf(", %#lx", tcp->u_arg[2]);
-               else
-                       return ret - 1;
-       }
-       return 0;
+       return RVAL_DECODED;
 }