Skip to contentSkip to conversation

linux-user: pass correct host flags to eventfd2 call

PATCH Applied Petar Jovanovic 3 participants 3 messages Apr 8, 2013 – Apr 12, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux-user: pass correct host flags to eventfd2 call

This change makes conversion of TARGET_O_NONBLOCK and TARGET_O_CLOEXEC flags to host flags before calling eventfd for TARGET_NR_eventfd2.

---
 linux-user/syscall.c |   11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
linux-user/syscall.c +10 -1
index ee82a2d..1f07621 100644
@@ -8823,8 +8823,17 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
 #endif
 #if defined(TARGET_NR_eventfd2)
     case TARGET_NR_eventfd2:
-        ret = get_errno(eventfd(arg1, arg2));
+    {
+        int host_flags = arg2 & (~(TARGET_O_NONBLOCK | TARGET_O_CLOEXEC));
+        if (arg2 & TARGET_O_NONBLOCK) {
+            host_flags |= O_NONBLOCK;
+        }
+        if (arg2 & TARGET_O_CLOEXEC) {
+            host_flags |= O_CLOEXEC;
+        }
+        ret = get_errno(eventfd(arg1, host_flags));
         break;
+    }
 #endif
 #endif /* CONFIG_EVENTFD  */
 #if defined(CONFIG_FALLOCATE) && defined(TARGET_NR_fallocate)
Signature · 1 line
1.7.9.5
Reviewed-by on v1 1/1
#1 lore raw
Quoted 16 lines · Petar Jovanovic

This change makes conversion of TARGET_O_NONBLOCK and TARGET_O_CLOEXEC flags to host flags before calling eventfd for TARGET_NR_eventfd2.

---
 linux-user/syscall.c |   11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
linux-user/syscall.c +0 -0
index ee82a2d..1f07621 100644
@@ -8823,8 +8823,17 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
 #endif
 #if defined(TARGET_NR_eventfd2)
     case TARGET_NR_eventfd2:

linux-user/syscall.c abi_long do_syscall(void *cpu_env, int num, abi_long arg1, · line 8834

Quoted 10 lines
linux-user/syscall.c +9 -1
-        ret = get_errno(eventfd(arg1, arg2));
+    {
+        int host_flags = arg2 & (~(TARGET_O_NONBLOCK | TARGET_O_CLOEXEC));
+        if (arg2 & TARGET_O_NONBLOCK) {
+            host_flags |= O_NONBLOCK;
+        }
+        if (arg2 & TARGET_O_CLOEXEC) {
+            host_flags |= O_CLOEXEC;
+        }
+        ret = get_errno(eventfd(arg1, host_flags));

I had to look it up, but this is OK because eventfd flags come in two flavours: (a) those shared with the O_* fcntl flags, which is just O_NONBLOCK and O_CLOEXEC at the moment and (b) those which are not shared with the fcntl flags, which are the same value on all targets. So it's correct to convert the two shared flags and leave the rest alone.

-- PMM

#2 lore raw
In reply to Petar Jovanovic
Quoted 7 lines · Petar Jovanovic

This change makes conversion of TARGET_O_NONBLOCK and TARGET_O_CLOEXEC flags to host flags before calling eventfd for TARGET_NR_eventfd2.

---
 linux-user/syscall.c |   11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

Thanks, applied to the trivial patches tree:
https://github.com/stefanha/qemu/commits/trivial-patches

Stefan