Introduce a separate function to copy from msghdr32 to msghdr
authorMasatake YAMATO <yamato@redhat.com>
Thu, 6 Nov 2014 16:23:24 +0000 (01:23 +0900)
committerDmitry V. Levin <ldv@altlinux.org>
Tue, 11 Nov 2014 15:41:37 +0000 (15:41 +0000)
This patch is an initial step for supporting "-e write=set" and
"-e read=set" option for sendmmsg and recvmmsg system calls.

Coverting a data of msghdr32 to msghdr is needed both for
{send,recv}msg and {send,recv}mmsg to decode parameters.
To share the copying code in both decoders, a separate
function named copy_from_msghdr32 is introduced.

* net.c [SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4]
(copy_from_msghdr32): New function.
(extractmsghdr) [SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4]: Use it.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
net.c

diff --git a/net.c b/net.c
index c38b1101e011d33c5f9406f64c6285ba937f55fd..41c55c667fad34cf1b8c820161f81aadb3f7e095 100644 (file)
--- a/net.c
+++ b/net.c
@@ -429,6 +429,20 @@ struct mmsghdr32 {
        uint32_t /* unsigned */ msg_len;
 };
 
+#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
+static void
+copy_from_msghdr32(struct msghdr *to_msg, struct msghdr32 *from_msg32)
+{
+       to_msg->msg_name       = (void*)(long)from_msg32->msg_name;
+       to_msg->msg_namelen    =              from_msg32->msg_namelen;
+       to_msg->msg_iov        = (void*)(long)from_msg32->msg_iov;
+       to_msg->msg_iovlen     =              from_msg32->msg_iovlen;
+       to_msg->msg_control    = (void*)(long)from_msg32->msg_control;
+       to_msg->msg_controllen =              from_msg32->msg_controllen;
+       to_msg->msg_flags      =              from_msg32->msg_flags;
+}
+#endif
+
 static bool
 extractmsghdr(struct tcb *tcp, long addr, struct msghdr *msg)
 {
@@ -438,13 +452,7 @@ extractmsghdr(struct tcb *tcp, long addr, struct msghdr *msg)
 
                if (umove(tcp, addr, &msg32) < 0)
                        return false;
-               msg->msg_name       = (void*)(long)msg32.msg_name;
-               msg->msg_namelen    =              msg32.msg_namelen;
-               msg->msg_iov        = (void*)(long)msg32.msg_iov;
-               msg->msg_iovlen     =              msg32.msg_iovlen;
-               msg->msg_control    = (void*)(long)msg32.msg_control;
-               msg->msg_controllen =              msg32.msg_controllen;
-               msg->msg_flags      =              msg32.msg_flags;
+               copy_from_msghdr32(msg, &msg32);
        } else
 #endif
        if (umove(tcp, addr, msg) < 0)