qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] linux-user: pass correct host flags to accept4()
@ 2014-03-31 15:09 Petar Jovanovic
  2014-03-31 15:19 ` Peter Maydell
  0 siblings, 1 reply; 3+ messages in thread
From: Petar Jovanovic @ 2014-03-31 15:09 UTC (permalink / raw)
  To: qemu-devel; +Cc: riku.voipio, petar.jovanovic

From: Petar Jovanovic <petar.jovanovic@imgtec.com>

Flags NONBLOCK and CLOEXEC can have different values on the host and the
guest, so set correct host values before calling accept4().

This fixes several issues with accept4 system call and user-mode of QEMU.

Signed-off-by: Petar Jovanovic <petar.jovanovic@imgtec.com>
---
 linux-user/syscall.c |   13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 2eac6d5..3447419 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -2062,9 +2062,18 @@ static abi_long do_accept4(int fd, abi_ulong target_addr,
     socklen_t addrlen;
     void *addr;
     abi_long ret;
+    int host_flags;
+
+    host_flags = flags & (~(TARGET_O_NONBLOCK | TARGET_O_CLOEXEC));
+    if (flags & TARGET_O_NONBLOCK) {
+        host_flags |= O_NONBLOCK;
+    }
+    if (flags & TARGET_O_CLOEXEC) {
+        host_flags |= O_CLOEXEC;
+    }
 
     if (target_addr == 0) {
-        return get_errno(accept4(fd, NULL, NULL, flags));
+        return get_errno(accept4(fd, NULL, NULL, host_flags));
     }
 
     /* linux returns EINVAL if addrlen pointer is invalid */
@@ -2080,7 +2089,7 @@ static abi_long do_accept4(int fd, abi_ulong target_addr,
 
     addr = alloca(addrlen);
 
-    ret = get_errno(accept4(fd, addr, &addrlen, flags));
+    ret = get_errno(accept4(fd, addr, &addrlen, host_flags));
     if (!is_error(ret)) {
         host_to_target_sockaddr(target_addr, addr, addrlen);
         if (put_user_u32(addrlen, target_addrlen_addr))
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] linux-user: pass correct host flags to accept4()
  2014-03-31 15:09 [Qemu-devel] [PATCH] linux-user: pass correct host flags to accept4() Petar Jovanovic
@ 2014-03-31 15:19 ` Peter Maydell
  2014-03-31 15:36   ` Petar Jovanovic
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Maydell @ 2014-03-31 15:19 UTC (permalink / raw)
  To: Petar Jovanovic; +Cc: Riku Voipio, QEMU Developers, Petar Jovanovic

On 31 March 2014 16:09, Petar Jovanovic <petar.jovanovic@rt-rk.com> wrote:
> From: Petar Jovanovic <petar.jovanovic@imgtec.com>
>
> Flags NONBLOCK and CLOEXEC can have different values on the host and the
> guest, so set correct host values before calling accept4().
>
> This fixes several issues with accept4 system call and user-mode of QEMU.
>
> Signed-off-by: Petar Jovanovic <petar.jovanovic@imgtec.com>
> ---
>  linux-user/syscall.c |   13 +++++++++++--
>  1 file changed, 11 insertions(+), 2 deletions(-)
>
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 2eac6d5..3447419 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -2062,9 +2062,18 @@ static abi_long do_accept4(int fd, abi_ulong target_addr,
>      socklen_t addrlen;
>      void *addr;
>      abi_long ret;
> +    int host_flags;
> +
> +    host_flags = flags & (~(TARGET_O_NONBLOCK | TARGET_O_CLOEXEC));
> +    if (flags & TARGET_O_NONBLOCK) {
> +        host_flags |= O_NONBLOCK;
> +    }
> +    if (flags & TARGET_O_CLOEXEC) {
> +        host_flags |= O_CLOEXEC;
> +    }

We have a target_to_host_bitmask() utility for this
kind of thing. I think you can just use
    host_flags = target_to_host_bitmask(flags, fcntl_flags_tbl);

and rely on the host kernel to fail EINVAL if the
guest has set any of the other flags that fnctl_flags_tbl
supports.

thanks
-- PMM

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] linux-user: pass correct host flags to accept4()
  2014-03-31 15:19 ` Peter Maydell
@ 2014-03-31 15:36   ` Petar Jovanovic
  0 siblings, 0 replies; 3+ messages in thread
From: Petar Jovanovic @ 2014-03-31 15:36 UTC (permalink / raw)
  To: Peter Maydell, Petar Jovanovic; +Cc: Riku Voipio, QEMU Developers


________________________________________
From: Peter Maydell [peter.maydell@linaro.org]
Sent: Monday, March 31, 2014 5:19 PM
To: Petar Jovanovic
Cc: QEMU Developers; Riku Voipio; Petar Jovanovic
Subject: Re: [Qemu-devel] [PATCH] linux-user: pass correct host flags to accept4()

On 31 March 2014 16:09, Petar Jovanovic <petar.jovanovic@rt-rk.com> wrote:
> From: Petar Jovanovic <petar.jovanovic@imgtec.com>
>
> Flags NONBLOCK and CLOEXEC can have different values on the host and the
> guest, so set correct host values before calling accept4().
>
> This fixes several issues with accept4 system call and user-mode of QEMU.
>
> Signed-off-by: Petar Jovanovic <petar.jovanovic@imgtec.com>
> ---
>  linux-user/syscall.c |   13 +++++++++++--
>  1 file changed, 11 insertions(+), 2 deletions(-)
>
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 2eac6d5..3447419 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -2062,9 +2062,18 @@ static abi_long do_accept4(int fd, abi_ulong target_addr,
>      socklen_t addrlen;
>      void *addr;
>      abi_long ret;
> +    int host_flags;
> +
> +    host_flags = flags & (~(TARGET_O_NONBLOCK | TARGET_O_CLOEXEC));
> +    if (flags & TARGET_O_NONBLOCK) {
> +        host_flags |= O_NONBLOCK;
> +    }
> +    if (flags & TARGET_O_CLOEXEC) {
> +        host_flags |= O_CLOEXEC;
> +    }

> We have a target_to_host_bitmask() utility for this
> kind of thing. I think you can just use
>   host_flags = target_to_host_bitmask(flags, fcntl_flags_tbl);
> 
> and rely on the host kernel to fail EINVAL if the
> guest has set any of the other flags that fnctl_flags_tbl
> supports.

I can, though target_to_host_bitmask() does more work/iterration than what
I believe is really needed in this case.

I will send a modified patch nevertheless.

Regards,
Petar

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-03-31 15:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-31 15:09 [Qemu-devel] [PATCH] linux-user: pass correct host flags to accept4() Petar Jovanovic
2014-03-31 15:19 ` Peter Maydell
2014-03-31 15:36   ` Petar Jovanovic

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).