summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Larson <chris_larson@mentor.com>2013-11-25 20:05:13 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2013-12-03 17:45:53 +0000
commit44b2cf59e23e1d59947477ee0cffd2ca5a0c5a0f (patch)
tree84ed3c0bba83be258b874b885f42ac025dd60e97
parent4eab9d000fedbd37079c3e8cbeb324ab51fea529 (diff)
downloadpoky-44b2cf59e23e1d59947477ee0cffd2ca5a0c5a0f.tar.gz
qemu: handle CLOEXEC/NONBLOCK if unavailable on host
(From OE-Core rev: d60cf44deb297119f97d7e792eae5ab01977e2fc) Signed-off-by: Christopher Larson <kergoth@gmail.com> Signed-off-by: Saul Wold <sgw@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/recipes-devtools/qemu/files/linux-user-Handle-SOCK_CLOEXEC-NONBLOCK-if-unavailab.patch92
-rw-r--r--meta/recipes-devtools/qemu/qemu.inc1
2 files changed, 93 insertions, 0 deletions
diff --git a/meta/recipes-devtools/qemu/files/linux-user-Handle-SOCK_CLOEXEC-NONBLOCK-if-unavailab.patch b/meta/recipes-devtools/qemu/files/linux-user-Handle-SOCK_CLOEXEC-NONBLOCK-if-unavailab.patch
new file mode 100644
index 0000000000..eb638960dd
--- /dev/null
+++ b/meta/recipes-devtools/qemu/files/linux-user-Handle-SOCK_CLOEXEC-NONBLOCK-if-unavailab.patch
@@ -0,0 +1,92 @@
1Upstream-Status: Backport
2
3From 53d09b761f032f50c4424e8649396a9041070bae Mon Sep 17 00:00:00 2001
4From: "Edgar E. Iglesias" <edgar.iglesias@gmail.com>
5Date: Mon, 23 Sep 2013 14:11:53 +0200
6Subject: [PATCH] linux-user: Handle SOCK_CLOEXEC/NONBLOCK if unavailable on
7 host
8
9If the host lacks SOCK_CLOEXEC, bail out with -EINVAL.
10If the host lacks SOCK_ONONBLOCK, try to emulate it with fcntl()
11and O_NONBLOCK.
12
13Signed-off-by: Edgar E. Iglesias <edgar.iglesias@gmail.com>
14Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
15---
16 linux-user/syscall.c | 40 +++++++++++++++++++++++++++++++++++++---
17 1 file changed, 37 insertions(+), 3 deletions(-)
18
19diff --git a/linux-user/syscall.c b/linux-user/syscall.c
20index b3822b3..4a14a43 100644
21--- a/linux-user/syscall.c
22+++ b/linux-user/syscall.c
23@@ -1773,7 +1773,7 @@ static void unlock_iovec(struct iovec *vec, abi_ulong target_addr,
24 free(vec);
25 }
26
27-static inline void target_to_host_sock_type(int *type)
28+static inline int target_to_host_sock_type(int *type)
29 {
30 int host_type = 0;
31 int target_type = *type;
32@@ -1790,22 +1790,56 @@ static inline void target_to_host_sock_type(int *type)
33 break;
34 }
35 if (target_type & TARGET_SOCK_CLOEXEC) {
36+#if defined(SOCK_CLOEXEC)
37 host_type |= SOCK_CLOEXEC;
38+#else
39+ return -TARGET_EINVAL;
40+#endif
41 }
42 if (target_type & TARGET_SOCK_NONBLOCK) {
43+#if defined(SOCK_NONBLOCK)
44 host_type |= SOCK_NONBLOCK;
45+#elif !defined(O_NONBLOCK)
46+ return -TARGET_EINVAL;
47+#endif
48 }
49 *type = host_type;
50+ return 0;
51+}
52+
53+/* Try to emulate socket type flags after socket creation. */
54+static int sock_flags_fixup(int fd, int target_type)
55+{
56+#if !defined(SOCK_NONBLOCK) && defined(O_NONBLOCK)
57+ if (target_type & TARGET_SOCK_NONBLOCK) {
58+ int flags = fcntl(fd, F_GETFL);
59+ if (fcntl(fd, F_SETFL, O_NONBLOCK | flags) == -1) {
60+ close(fd);
61+ return -TARGET_EINVAL;
62+ }
63+ }
64+#endif
65+ return fd;
66 }
67
68 /* do_socket() Must return target values and target errnos. */
69 static abi_long do_socket(int domain, int type, int protocol)
70 {
71- target_to_host_sock_type(&type);
72+ int target_type = type;
73+ int ret;
74+
75+ ret = target_to_host_sock_type(&type);
76+ if (ret) {
77+ return ret;
78+ }
79
80 if (domain == PF_NETLINK)
81 return -EAFNOSUPPORT; /* do not NETLINK socket connections possible */
82- return get_errno(socket(domain, type, protocol));
83+ ret = get_errno(socket(domain, type, protocol));
84+ if (ret >= 0) {
85+ ret = sock_flags_fixup(ret, target_type);
86+ }
87+ return ret;
88 }
89
90 /* do_bind() Must return target values and target errnos. */
91--
921.8.2.1
diff --git a/meta/recipes-devtools/qemu/qemu.inc b/meta/recipes-devtools/qemu/qemu.inc
index 747d6b23e1..0852722df2 100644
--- a/meta/recipes-devtools/qemu/qemu.inc
+++ b/meta/recipes-devtools/qemu/qemu.inc
@@ -18,6 +18,7 @@ SRC_URI = "\
18 file://no-strip.patch \ 18 file://no-strip.patch \
19 file://larger_default_ram_size.patch \ 19 file://larger_default_ram_size.patch \
20 file://disable-grabs.patch \ 20 file://disable-grabs.patch \
21 file://linux-user-Handle-SOCK_CLOEXEC-NONBLOCK-if-unavailab.patch \
21 " 22 "
22 23
23SRC_URI_append_class-native = "\ 24SRC_URI_append_class-native = "\