]> granicus.if.org Git - strace/blobdiff - io.c
replace wimpy get64 by powerful LONG_LONG :-)
[strace] / io.c
diff --git a/io.c b/io.c
index 45c34135fc5529eb5d2f653118b75f370f98eab8..d38d1fe3fb5f62eeadc5e6bdac052adf65dbea80 100644 (file)
--- a/io.c
+++ b/io.c
 #include <fcntl.h>
 #include <sys/uio.h>
 
+#ifdef HAVE_LONG_LONG_OFF_T
+/*
+ * Hacks for systems that have a long long off_t
+ */
+
+#define sys_pread64    sys_pread
+#define sys_pwrite64   sys_pwrite
+#endif
+
 int
 sys_read(tcp)
 struct tcb *tcp;
@@ -63,13 +72,47 @@ struct tcb *tcp;
        return 0;
 }
 
+void
+tprint_iov(tcp, len, addr)
+struct tcb * tcp;
+int len;
+char * addr;
+{
+       struct iovec *iov;
+       int i;
+
+
+       if (!len) {
+               tprintf("[]");
+               return;
+       }
+         
+       if ((iov = (struct iovec *) malloc(len * sizeof *iov)) == NULL) {
+               fprintf(stderr, "No memory");
+               return;
+       }
+       if (umoven(tcp, (int) addr,
+                  len * sizeof *iov, (char *) iov) < 0) {
+               tprintf("%#lx", tcp->u_arg[1]);
+       } else {
+               tprintf("[");
+               for (i = 0; i < len; i++) {
+                       if (i)
+                               tprintf(", ");
+                       tprintf("{");
+                       printstr(tcp, (long) iov[i].iov_base,
+                               iov[i].iov_len);
+                       tprintf(", %lu}", (unsigned long)iov[i].iov_len);
+               }
+               tprintf("]");
+       }
+       free((char *) iov);
+}
+
 int
 sys_readv(tcp)
 struct tcb *tcp;
 {
-       struct iovec *iov;
-       int i, len;
-
        if (entering(tcp)) {
                tprintf("%ld, ", tcp->u_arg[0]);
        } else {
@@ -78,27 +121,7 @@ struct tcb *tcp;
                                        tcp->u_arg[1], tcp->u_arg[2]);
                        return 0;
                }
-               len = tcp->u_arg[2];
-               if ((iov = (struct iovec *) malloc(len * sizeof *iov)) == NULL) {
-                       fprintf(stderr, "No memory");
-                       return 0;
-               }
-               if (umoven(tcp, tcp->u_arg[1],
-                               len * sizeof *iov, (char *) iov) < 0) {
-                       tprintf("%#lx", tcp->u_arg[1]);
-               } else {
-                       tprintf("[");
-                       for (i = 0; i < len; i++) {
-                               if (i)
-                                       tprintf(", ");
-                               tprintf("{");
-                               printstr(tcp, (long) iov[i].iov_base,
-                                       iov[i].iov_len);
-                               tprintf(", %lu}", (unsigned long)iov[i].iov_len);
-                       }
-                       tprintf("]");
-               }
-               free((char *) iov);
+               tprint_iov(tcp, tcp->u_arg[2], tcp->u_arg[1]);
                tprintf(", %lu", tcp->u_arg[2]);
        }
        return 0;
@@ -108,39 +131,15 @@ int
 sys_writev(tcp)
 struct tcb *tcp;
 {
-       struct iovec *iov;
-       int i, len;
-
        if (entering(tcp)) {
                tprintf("%ld, ", tcp->u_arg[0]);
-               len = tcp->u_arg[2];
-               iov = (struct iovec *) malloc(len * sizeof *iov);
-               if (iov == NULL) {
-                       fprintf(stderr, "No memory");
-                       return 0;
-               }
-               if (umoven(tcp, tcp->u_arg[1],
-                               len * sizeof *iov, (char *) iov) < 0) {
-                       tprintf("%#lx", tcp->u_arg[1]);
-               } else {
-                       tprintf("[");
-                       for (i = 0; i < len; i++) {
-                               if (i)
-                                       tprintf(", ");
-                               tprintf("{");
-                               printstr(tcp, (long) iov[i].iov_base,
-                                       iov[i].iov_len);
-                               tprintf(", %lu}", (unsigned long)iov[i].iov_len);
-                       }
-                       tprintf("]");
-               }
-               free((char *) iov);
+               tprint_iov(tcp, tcp->u_arg[2], tcp->u_arg[1]);
                tprintf(", %lu", tcp->u_arg[2]);
        }
        return 0;
 }
 
-#ifdef SVR4
+#if defined(SVR4)
 
 int
 sys_pread(tcp)
@@ -185,6 +184,48 @@ struct tcb *tcp;
 }
 #endif /* SVR4 */
 
+#ifdef FREEBSD
+#include <sys/types.h>
+#include <sys/socket.h>
+
+int
+sys_sendfile(tcp)
+struct tcb *tcp;
+{
+       if (entering(tcp)) {
+               tprintf("%ld, %ld, %llu, %lu", tcp->u_arg[0], tcp->u_arg[1],
+                       (((unsigned long long) tcp->u_arg[3]) << 32 |
+                        tcp->u_arg[2]), tcp->u_arg[4]);
+       } else {
+               off_t offset;
+
+               if (!tcp->u_arg[5])
+                       tprintf(", NULL");
+               else {
+                       struct sf_hdtr hdtr;
+
+                       if (umove(tcp, tcp->u_arg[5], &hdtr) < 0)
+                               tprintf(", %#lx", tcp->u_arg[5]);
+                       else {
+                               tprintf(", { ");
+                               tprint_iov(tcp, hdtr.hdr_cnt, hdtr.headers);
+                               tprintf(", %u, ", hdtr.hdr_cnt);
+                               tprint_iov(tcp, hdtr.trl_cnt, hdtr.trailers);
+                               tprintf(", %u }", hdtr.hdr_cnt);
+                       }
+               }
+               if (!tcp->u_arg[6])
+                       tprintf(", NULL");
+               else if (umove(tcp, tcp->u_arg[6], &offset) < 0)
+                       tprintf(", %#lx", tcp->u_arg[6]);
+               else
+                       tprintf(", [%llu]", offset);
+               tprintf(", %lu", tcp->u_arg[7]);
+       }
+       return 0;
+}
+#endif /* FREEBSD */
+
 #ifdef LINUX
 int
 sys_pread(tcp)
@@ -237,6 +278,40 @@ struct tcb *tcp;
 
 #endif /* LINUX */
 
+#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
+int
+sys_pread64(tcp)
+struct tcb *tcp;
+{
+       if (entering(tcp)) {
+               tprintf("%ld, ", tcp->u_arg[0]);
+       } else {
+               ALIGN64 (tcp, 3);
+               if (syserror(tcp))
+                       tprintf("%#lx", tcp->u_arg[1]);
+               else
+                       printstr(tcp, tcp->u_arg[1], tcp->u_rval);
+               tprintf(", %lu, %#llx", tcp->u_arg[2],
+                       LONG_LONG(tcp->u_arg[3], tcp->u_arg[4]));
+       }
+       return 0;
+}
+
+int
+sys_pwrite64(tcp)
+struct tcb *tcp;
+{
+       if (entering(tcp)) {
+               ALIGN64 (tcp, 3);
+               tprintf("%ld, ", tcp->u_arg[0]);
+               printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
+               tprintf(", %lu, %#llx", tcp->u_arg[2],
+                       LONG_LONG(tcp->u_arg[3], tcp->u_arg[4]));
+       }
+       return 0;
+}
+#endif
 int
 sys_ioctl(tcp)
 struct tcb *tcp;