Skip to contentSkip to conversation

linux-user: pass sockaddr from host to target

PATCH Superseded Jing Huang 2 participants 2 messages Jul 23, 2012

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Jing Huang

author
#0 lore raw

PATCH v4 1/3 linux-user: pass sockaddr from host to target

---
 linux-user/syscall.c |   15 +++++++++++++--
 1 files changed, 13 insertions(+), 2 deletions(-)
linux-user/syscall.c +13 -2
index 539af3f..3319bb8 100644
@@ -1256,7 +1256,6 @@ static inline abi_long host_to_target_sockaddr(abi_ulong target_addr,
     return 0;
 }
 
-/* ??? Should this also swap msgh->name?  */
 static inline abi_long target_to_host_cmsg(struct msghdr *msgh,
                                            struct target_msghdr *target_msgh)
 {
@@ -1873,10 +1872,22 @@ static abi_long do_sendrecvmsg(int fd, abi_ulong target_msg,
         if (!is_error(ret)) {
             len = ret;
             ret = host_to_target_cmsg(msgp, &msg);
-            if (!is_error(ret))
+            if (!is_error(ret)) {
+                msgp->msg_namelen = tswap32(msg.msg_namelen);
+                if (msg.msg_name != NULL) {
+                    ret = host_to_target_sockaddr(tswapal(msgp->msg_name),
+                                                msg.msg_name, msg.msg_namelen);
+                    if (ret) {
+                        goto out;
+                    }
+                }
+
                 ret = len;
+            }
         }
     }
+
+out:
     unlock_iovec(vec, target_vec, count, !send);
     unlock_user_struct(msgp, target_msg, send ? 0 : 1);
     return ret;
Signature · 1 line
1.7.8.6
#1 lore raw
Quoted 12 lines · Jing Huang
---
 linux-user/syscall.c |   15 +++++++++++++--
 1 files changed, 13 insertions(+), 2 deletions(-)
linux-user/syscall.c +0 -0
index 539af3f..3319bb8 100644

linux-user/syscall.c static inline abi_long host_to_target_sockaddr(abi_ulong target_addr, · line 1261

Quoted 7 lines
linux-user/syscall.c +0 -1
@@ -1256,7 +1256,6 @@ static inline abi_long host_to_target_sockaddr(abi_ulong target_addr,
     return 0;
 }
 
-/* ??? Should this also swap msgh->name?  */
 static inline abi_long target_to_host_cmsg(struct msghdr *msgh,
                                            struct target_msghdr *target_msgh)
 {

This is removing the comment from the wrong function: there's an identical one over host_to_target_cmsg() which is the one most immediately addressed by this patch. You can remove both comments, though.

Quoted 25 lines
linux-user/syscall.c +13 -2
@@ -1873,10 +1872,22 @@ static abi_long do_sendrecvmsg(int fd, abi_ulong target_msg,
         if (!is_error(ret)) {
             len = ret;
             ret = host_to_target_cmsg(msgp, &msg);
-            if (!is_error(ret))
+            if (!is_error(ret)) {
+                msgp->msg_namelen = tswap32(msg.msg_namelen);
+                if (msg.msg_name != NULL) {
+                    ret = host_to_target_sockaddr(tswapal(msgp->msg_name),
+                                                msg.msg_name, msg.msg_namelen);
+                    if (ret) {
+                        goto out;
+                    }
+                }
+
                 ret = len;
+            }
         }
     }
+
+out:
     unlock_iovec(vec, target_vec, count, !send);
     unlock_user_struct(msgp, target_msg, send ? 0 : 1);
     return ret;
--
Quoted 2 lines

1.7.8.6

-- PMM