[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 11/11] linux-user: Handle SOCK_CLOEXEC/NONBLOCK if u
From: |
riku . voipio |
Subject: |
[Qemu-devel] [PATCH 11/11] linux-user: Handle SOCK_CLOEXEC/NONBLOCK if unavailable on host |
Date: |
Fri, 27 Sep 2013 15:10:06 +0300 |
From: "Edgar E. Iglesias" <address@hidden>
If the host lacks SOCK_CLOEXEC, bail out with -EINVAL.
If the host lacks SOCK_ONONBLOCK, try to emulate it with fcntl()
and O_NONBLOCK.
Signed-off-by: Edgar E. Iglesias <address@hidden>
Signed-off-by: Riku Voipio <address@hidden>
---
linux-user/syscall.c | 40 +++++++++++++++++++++++++++++++++++++---
1 file changed, 37 insertions(+), 3 deletions(-)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index b3822b3..4a14a43 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -1773,7 +1773,7 @@ static void unlock_iovec(struct iovec *vec, abi_ulong
target_addr,
free(vec);
}
-static inline void target_to_host_sock_type(int *type)
+static inline int target_to_host_sock_type(int *type)
{
int host_type = 0;
int target_type = *type;
@@ -1790,22 +1790,56 @@ static inline void target_to_host_sock_type(int *type)
break;
}
if (target_type & TARGET_SOCK_CLOEXEC) {
+#if defined(SOCK_CLOEXEC)
host_type |= SOCK_CLOEXEC;
+#else
+ return -TARGET_EINVAL;
+#endif
}
if (target_type & TARGET_SOCK_NONBLOCK) {
+#if defined(SOCK_NONBLOCK)
host_type |= SOCK_NONBLOCK;
+#elif !defined(O_NONBLOCK)
+ return -TARGET_EINVAL;
+#endif
}
*type = host_type;
+ return 0;
+}
+
+/* Try to emulate socket type flags after socket creation. */
+static int sock_flags_fixup(int fd, int target_type)
+{
+#if !defined(SOCK_NONBLOCK) && defined(O_NONBLOCK)
+ if (target_type & TARGET_SOCK_NONBLOCK) {
+ int flags = fcntl(fd, F_GETFL);
+ if (fcntl(fd, F_SETFL, O_NONBLOCK | flags) == -1) {
+ close(fd);
+ return -TARGET_EINVAL;
+ }
+ }
+#endif
+ return fd;
}
/* do_socket() Must return target values and target errnos. */
static abi_long do_socket(int domain, int type, int protocol)
{
- target_to_host_sock_type(&type);
+ int target_type = type;
+ int ret;
+
+ ret = target_to_host_sock_type(&type);
+ if (ret) {
+ return ret;
+ }
if (domain == PF_NETLINK)
return -EAFNOSUPPORT; /* do not NETLINK socket connections possible */
- return get_errno(socket(domain, type, protocol));
+ ret = get_errno(socket(domain, type, protocol));
+ if (ret >= 0) {
+ ret = sock_flags_fixup(ret, target_type);
+ }
+ return ret;
}
/* do_bind() Must return target values and target errnos. */
--
1.8.1.2
- [Qemu-devel] [PULL] [PATCH 00/11] Linux-user updates, riku . voipio, 2013/09/27
- [Qemu-devel] [PATCH 01/11] alpha-linux-user: Fix umount syscall numbers, riku . voipio, 2013/09/27
- [Qemu-devel] [PATCH 03/11] linux-user: convert /proc/net/route when endianess differs, riku . voipio, 2013/09/27
- [Qemu-devel] [PATCH 05/11] linux-user: allow use of TIOCGSID, riku . voipio, 2013/09/27
- [Qemu-devel] [PATCH 02/11] mips-linux-user: Adjust names in mips_syscall_args, riku . voipio, 2013/09/27
- [Qemu-devel] [PATCH 04/11] linux-user: Add setsockopt(SO_ATTACH_FILTER), riku . voipio, 2013/09/27
- [Qemu-devel] [PATCH 08/11] linux-user: correct how SOL_SOCKET is converted from target to host and back, riku . voipio, 2013/09/27
- [Qemu-devel] [PATCH 09/11] linux-user: Check type of microMIPS break instruction, riku . voipio, 2013/09/27
- [Qemu-devel] [PATCH 10/11] [v2] linux-user: implement m68k atomic syscalls, riku . voipio, 2013/09/27
- [Qemu-devel] [PATCH 07/11] linux-user: add support of binfmt_misc 'O' flag, riku . voipio, 2013/09/27
- [Qemu-devel] [PATCH 11/11] linux-user: Handle SOCK_CLOEXEC/NONBLOCK if unavailable on host,
riku . voipio <=
- [Qemu-devel] [PATCH 06/11] linux-user: add some IPV6 commands in setsockop(), riku . voipio, 2013/09/27
- Re: [Qemu-devel] [PULL] [PATCH 00/11] Linux-user updates, Edgar E. Iglesias, 2013/09/27