diff mbox series

[PULL,01/15] linux-user: call fd_trans_target_to_host_data() for write()

Message ID 04b9bcf911af2b4563b1f1b2e8a103b796dcc9eb.1496234766.git.riku.voipio@linaro.org
State Accepted
Commit 04b9bcf911af2b4563b1f1b2e8a103b796dcc9eb
Headers show
Series Misc linux-user updates | expand

Commit Message

Riku Voipio May 31, 2017, 1:08 p.m. UTC
From: Laurent Vivier <laurent@vivier.eu>


As for sendmsg() or sendto(), we must call the target to
host data translator if it is defined. This is needed for
eventfd(): the write() syscall allows to add a value to
the internal counter, and so, it must be byte-swapped to
the host order.

Signed-off-by: Laurent Vivier <laurent@vivier.eu>

Signed-off-by: Riku Voipio <riku.voipio@linaro.org>

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

-- 
2.11.0
diff mbox series

Patch

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index cec8428589..b2b563e388 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -7767,7 +7767,17 @@  abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
     case TARGET_NR_write:
         if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1)))
             goto efault;
-        ret = get_errno(safe_write(arg1, p, arg3));
+        if (fd_trans_target_to_host_data(arg1)) {
+            void *copy = g_malloc(arg3);
+            memcpy(copy, p, arg3);
+            ret = fd_trans_target_to_host_data(arg1)(copy, arg3);
+            if (ret >= 0) {
+                ret = get_errno(safe_write(arg1, copy, ret));
+            }
+            g_free(copy);
+        } else {
+            ret = get_errno(safe_write(arg1, p, arg3));
+        }
         unlock_user(p, arg2, 0);
         break;
 #ifdef TARGET_NR_open