[PATCHv3 1/2] Add functions for dumping iovecs in mmsghdr used in sendmmsg and recvmmsg

Masatake YAMATO yamato at redhat.com
Fri Nov 7 11:16:02 UTC 2014


This patch is similar to what I did in commit
02f9f6b386741a52f58e1b31ad4e7fff60781ef8.  The commit was for sendmsg
and recvmsg system calls. This one is for sendmmsg and recvmmsg system
calls.

        $ ./strace -f -e write=all tests/mmsg
	...
	[pid  6730] sendmmsg(3,  <unfinished ...>
	...
	[pid  6730] <... sendmmsg resumed> ...
	 = 2 buffers in vector 0
	 * 3 bytes in buffer 0
	 | 00000  6f 6e 65                                          one              |
	 * 3 bytes in buffer 1
	 | 00000  74 77 6f                                          two              |
	 = 1 buffers in vector 1
	 * 5 bytes in buffer 0
	 | 00000  74 68 72 65 65                                    three            |
	...

        $ ./strace -f -e read=all tests/mmsg
        ...
	[pid  6819] recvmmsg(4,  <unfinished ...>
	[pid  6820] sendmmsg(3,  <unfinished ...>
	[pid  6819] <... recvmmsg resumed> ...
	 = 2 buffers in vector 0
	 * 3 bytes in buffer 0
	 | 00000  6f 6e 65                                          one              |
	 * 3 bytes in buffer 1
	 | 00000  74 77 6f                                          two              |
	 = 1 buffers in vector 1
	 * 5 bytes in buffer 0
	 | 00000  74 68 72 65 65                                    three            |
        ...

* configure.ac (sendmmsg): Check sendmmsg system call.

* defs.h (dumpiov_in_mmsghdr): New declaration.

* net.c (extractmmsghdr): New helper functions do the
  same as extractmsghdr but for mmsghdr.

  (extractmsghdr): Use copy_from_msghdr32.

  (dumpiov_in_mmsghdr): Do the same as dumpiov_in_msghdr but for mmsghdr.

  (printmmsghdr): Simplified with using extractmmsghdr.

* syscall.c (dumpio): call dumpiov_in_mmsghdr if revmmsg or sendmmsg is
  called.

In v2 patch, extractmmsghdr0, a helper function of helper funcition is
unified to extractmmsghdr. Suggested by ldv.

In v3 patch, move the definition of `dumpiov_in_mmsghdr' function after
the definitions of `printmmsghdr' and `decode_mmsg'. Use only HAVE_SENDMSG
condtion for `calling dumpiov_in_mmsghdr'. Both are suggested by ldv.

Signed-off-by: Masatake YAMATO <yamato at redhat.com>
---
 configure.ac |  1 +
 defs.h       |  1 +
 net.c        | 71 +++++++++++++++++++++++++++++++++++++-----------------------
 syscall.c    |  4 ++++
 4 files changed, 50 insertions(+), 27 deletions(-)

diff --git a/configure.ac b/configure.ac
index 45c7f3f..e69b52c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -219,6 +219,7 @@ AC_CHECK_FUNCS(m4_normalize([
 	process_vm_readv
 	pwritev
 	sendmsg
+	sendmmsg
 	sigaction
 	stpcpy
 	strerror
diff --git a/defs.h b/defs.h
index 8a10e03..708adf6 100644
--- a/defs.h
+++ b/defs.h
@@ -673,6 +673,7 @@ extern void addflags(const struct xlat *, int);
 extern int printflags(const struct xlat *, int, const char *);
 extern const char *sprintflags(const char *, const struct xlat *, int);
 extern void dumpiov_in_msghdr(struct tcb *, long);
+extern void dumpiov_in_mmsghdr(struct tcb *, long);
 extern void dumpiov(struct tcb *, int, long);
 extern void dumpstr(struct tcb *, long, int);
 extern void printstr(struct tcb *, long, long);
diff --git a/net.c b/net.c
index 9e9e159..20f649c 100644
--- a/net.c
+++ b/net.c
@@ -467,6 +467,30 @@ extractmsghdr(struct tcb *tcp, long addr, struct msghdr *msg)
 	return true;
 }
 
+static bool
+extractmmsghdr(struct tcb *tcp, long addr, unsigned int idx, struct mmsghdr *mmsg)
+{
+#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
+	if (current_wordsize == 4) {
+		struct mmsghdr32 mmsg32;
+
+		addr += sizeof(struct mmsghdr32) * idx;
+		if (umove(tcp, addr, &mmsg32) < 0)
+			return false;
+
+		copy_from_msghdr32(&mmsg->msg_hdr, &mmsg32.msg_hdr);
+		mmsg->msg_len = mmsg32.msg_len;
+	}
+	else
+#endif
+	{
+		addr += sizeof(*mmsg) * idx;
+		if (umove(tcp, addr, mmsg) < 0)
+			return false;
+	}
+	return true;
+}
+
 static void
 printmsghdr(struct tcb *tcp, long addr, unsigned long data_size)
 {
@@ -492,35 +516,14 @@ printmmsghdr(struct tcb *tcp, long addr, unsigned int idx, unsigned long msg_len
 {
 	struct mmsghdr mmsg;
 
-#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
-	if (current_wordsize == 4) {
-		struct mmsghdr32 mmsg32;
-
-		addr += sizeof(mmsg32) * idx;
-		if (umove(tcp, addr, &mmsg32) < 0) {
-			tprintf("%#lx", addr);
-			return;
-		}
-		mmsg.msg_hdr.msg_name       = (void*)(long)mmsg32.msg_hdr.msg_name;
-		mmsg.msg_hdr.msg_namelen    =              mmsg32.msg_hdr.msg_namelen;
-		mmsg.msg_hdr.msg_iov        = (void*)(long)mmsg32.msg_hdr.msg_iov;
-		mmsg.msg_hdr.msg_iovlen     =              mmsg32.msg_hdr.msg_iovlen;
-		mmsg.msg_hdr.msg_control    = (void*)(long)mmsg32.msg_hdr.msg_control;
-		mmsg.msg_hdr.msg_controllen =              mmsg32.msg_hdr.msg_controllen;
-		mmsg.msg_hdr.msg_flags      =              mmsg32.msg_hdr.msg_flags;
-		mmsg.msg_len                =              mmsg32.msg_len;
-	} else
-#endif
+	if (extractmmsghdr(tcp, addr, idx, &mmsg))
 	{
-		addr += sizeof(mmsg) * idx;
-		if (umove(tcp, addr, &mmsg) < 0) {
-			tprintf("%#lx", addr);
-			return;
-		}
+		tprints("{");
+		do_msghdr(tcp, &mmsg.msg_hdr, msg_len ? msg_len : mmsg.msg_len);
+		tprintf(", %u}", mmsg.msg_len);
 	}
-	tprints("{");
-	do_msghdr(tcp, &mmsg.msg_hdr, msg_len ? msg_len : mmsg.msg_len);
-	tprintf(", %u}", mmsg.msg_len);
+	else
+		tprintf("%#lx", addr);
 }
 
 static void
@@ -547,6 +550,20 @@ decode_mmsg(struct tcb *tcp, unsigned long msg_len)
 	printflags(msg_flags, tcp->u_arg[3], "MSG_???");
 }
 
+void
+dumpiov_in_mmsghdr(struct tcb *tcp, long addr)
+{
+	unsigned int len = tcp->u_rval;
+	unsigned int i;
+	struct mmsghdr mmsg;
+
+	for (i = 0; i < len; ++i) {
+		if (extractmmsghdr(tcp, addr, i, &mmsg)) {
+			tprintf(" = %lu buffers in vector %u\n", mmsg.msg_hdr.msg_iovlen, i);
+			dumpiov(tcp, mmsg.msg_hdr.msg_iovlen, (long)mmsg.msg_hdr.msg_iov);
+		}
+	}
+}
 #endif /* HAVE_SENDMSG */
 
 /*
diff --git a/syscall.c b/syscall.c
index fa761a9..091626c 100644
--- a/syscall.c
+++ b/syscall.c
@@ -2500,6 +2500,8 @@ dumpio(struct tcb *tcp)
 #if HAVE_SENDMSG
 		else if (func == sys_recvmsg)
 			dumpiov_in_msghdr(tcp, tcp->u_arg[1]);
+		else if (func == sys_recvmmsg)
+			dumpiov_in_mmsghdr(tcp, tcp->u_arg[1]);
 #endif
 		return;
 	}
@@ -2514,6 +2516,8 @@ dumpio(struct tcb *tcp)
 #if HAVE_SENDMSG
 		else if (func == sys_sendmsg)
 			dumpiov_in_msghdr(tcp, tcp->u_arg[1]);
+		else if (func == sys_sendmmsg)
+			dumpiov_in_mmsghdr(tcp, tcp->u_arg[1]);
 #endif
 		return;
 	}
-- 
1.9.3





More information about the Strace-devel mailing list