]> granicus.if.org Git - strace/commitdiff
Implement sendmmsg syscall decoder
authorDmitry V. Levin <ldv@altlinux.org>
Sun, 11 Mar 2012 23:59:29 +0000 (23:59 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Sun, 11 Mar 2012 23:59:29 +0000 (23:59 +0000)
* linux/dummy.h (sys_sendmmsg): Remove.
* linux/syscall.h (sys_sendmmsg): New prototype.
* net.c (printmmsghdr): Add index argument specifying the element in
mmsghdr array to print.
(decode_mmsg): New function, prints the whole mmsghdr array, its length
and message flags.
(sys_sendmmsg): New function.
(sys_recvmmsg): Use decode_mmsg to fix mmsghdr array decoding.

linux/dummy.h
linux/syscall.h
net.c

index 88e3ba99a255aebbffe860e5e91900a82b49122e..f22a8d32f41bcc69dea194be21ad5ec5cbd89d3e 100644 (file)
@@ -45,7 +45,6 @@
 #define        sys_prlimit64           printargs
 #define        sys_request_key         printargs
 #define        sys_rt_tgsigqueueinfo   printargs
-#define        sys_sendmmsg            printargs
 #define        sys_sync_file_range     printargs
 #define        sys_sysfs               printargs
 #define        sys_syslog              printargs
index f5b0ef6a3b8aecffdeab8178d826dc75a4e5674c..180397039d4a38c46347d47fe0ba1dc139e9e802 100644 (file)
@@ -220,6 +220,7 @@ int sys_semtimedop();
 int sys_send();
 int sys_sendfile();
 int sys_sendfile64();
+int sys_sendmmsg();
 int sys_sendmsg();
 int sys_sendto();
 int sys_set_mempolicy();
diff --git a/net.c b/net.c
index 266d9c17f525b556d9ba784369b9245b8fa2fb24..e7c7b2bbcbf65a83453f5a5de74605aabac66e1e 100644 (file)
--- a/net.c
+++ b/net.c
@@ -1447,13 +1447,14 @@ printmsghdr(struct tcb *tcp, long addr)
 }
 
 static void
-printmmsghdr(struct tcb *tcp, long addr)
+printmmsghdr(struct tcb *tcp, long addr, unsigned int idx)
 {
        struct mmsghdr {
                struct msghdr msg_hdr;
                unsigned msg_len;
        } mmsg;
 
+       addr += sizeof(mmsg) * idx;
        if (umove(tcp, addr, &mmsg) < 0) {
                tprintf("%#lx", addr);
                return;
@@ -1463,6 +1464,30 @@ printmmsghdr(struct tcb *tcp, long addr)
        tprintf(", %u}", mmsg.msg_len);
 }
 
+static void
+decode_mmsg(struct tcb *tcp)
+{
+       /* mmsgvec */
+       if (syserror(tcp)) {
+               tprintf("%#lx", tcp->u_arg[1]);
+       } else {
+               unsigned int len = tcp->u_rval;
+               unsigned int i;
+
+               tprints("{");
+               for (i = 0; i < len; ++i) {
+                       if (i)
+                               tprints(", ");
+                       printmmsghdr(tcp, tcp->u_arg[1], i);
+               }
+               tprints("}");
+       }
+       /* vlen */
+       tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
+       /* flags */
+       printflags(msg_flags, tcp->u_arg[3], "MSG_???");
+}
+
 #endif /* HAVE_SENDMSG */
 
 /*
@@ -1627,6 +1652,24 @@ sys_sendmsg(struct tcb *tcp)
        return 0;
 }
 
+int
+sys_sendmmsg(struct tcb *tcp)
+{
+       if (entering(tcp)) {
+               /* sockfd */
+               tprintf("%d, ", (int) tcp->u_arg[0]);
+               if (!verbose(tcp)) {
+                       tprintf("%#lx, %u, ",
+                               tcp->u_arg[1], (unsigned int) tcp->u_arg[2]);
+                       printflags(msg_flags, tcp->u_arg[3], "MSG_???");
+               }
+       } else {
+               if (verbose(tcp))
+                       decode_mmsg(tcp);
+       }
+       return 0;
+}
+
 #endif /* HAVE_SENDMSG */
 
 int
@@ -1732,13 +1775,7 @@ sys_recvmmsg(struct tcb *tcp)
                return 0;
        } else {
                if (verbose(tcp)) {
-                       if (syserror(tcp))
-                               tprintf("%#lx", tcp->u_arg[1]);
-                       else
-                               printmmsghdr(tcp, tcp->u_arg[1]);
-                       tprintf(", %ld, ", tcp->u_arg[2]);
-                       /* flags */
-                       printflags(msg_flags, tcp->u_arg[3], "MSG_???");
+                       decode_mmsg(tcp);
                        /* timeout on entrance */
                        tprintf(", %s", tcp->auxstr ? tcp->auxstr : "{...}");
                        free((void *) tcp->auxstr);