Patchwork [v2,1/3] linux-user: pass sockaddr from host to target

login
register
mail settings
Submitter Jing Huang
Date July 16, 2012, 10:13 a.m.
Message ID <1342433620-3302-1-git-send-email-jing.huang.pku@gmail.com>
Download mbox | patch
Permalink /patch/171114/
State New
Headers show

Comments

Jing Huang - July 16, 2012, 10:13 a.m.
This patch pass sockaddr from host to target.

Signed-off-by: Jing Huang <jing.huang.pku@gmail.com>
---
 linux-user/syscall.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)
Peter Maydell - July 16, 2012, 2:29 p.m.
On 16 July 2012 11:13, Jing Huang <jing.huang.pku@gmail.com> wrote:
> This patch pass sockaddr from host to target.
>
> Signed-off-by: Jing Huang <jing.huang.pku@gmail.com>
> ---
>  linux-user/syscall.c |   10 +++++++++-
>  1 files changed, 9 insertions(+), 1 deletions(-)
>
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 539af3f..28c8ba5 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -1873,8 +1873,16 @@ 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 = msg.msg_namelen;

You need to swap msg_namelen using tswap32().

> +                ret = host_to_target_sockaddr(tswapal(msgp->msg_name),
> +                                    msg.msg_name, msg.msg_namelen);

host_to_target_sockaddr assumes msg.msg_name isn't NULL, so you need
to enclose this in an if() to avoid that.

> +                if (ret) {
> +                    qemu_log("Failed to pass sockaddr to target guest");

Don't print any logging here -- we should only be logging
anything for (a) unimplemented features or (b) debug tracing
which is guarded by #ifdef DEBUG.

> +                    return ret;

Returning here bypasses the unlocking of the iovec and user struct.

> +                }
>                  ret = len;


...the above two points mean you wanted
  if (!is_error(ret)) {
      ret = len;
  }

here.

> +            }

-- PMM

Patch

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 539af3f..28c8ba5 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -1873,8 +1873,16 @@  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 = msg.msg_namelen;
+                ret = host_to_target_sockaddr(tswapal(msgp->msg_name),
+                                    msg.msg_name, msg.msg_namelen);
+                if (ret) {
+                    qemu_log("Failed to pass sockaddr to target guest");
+                    return ret;
+                }
                 ret = len;
+            }
         }
     }
     unlock_iovec(vec, target_vec, count, !send);