From patchwork Wed Mar 1 09:37:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 734154 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vY9PS1rKnz9s7s for ; Wed, 1 Mar 2017 20:38:51 +1100 (AEDT) Received: from localhost ([::1]:39316 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cj0if-0006Y6-8G for incoming@patchwork.ozlabs.org; Wed, 01 Mar 2017 04:38:49 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33541) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cj0hy-0006XL-Cf for qemu-devel@nongnu.org; Wed, 01 Mar 2017 04:38:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cj0ht-0006pi-Iy for qemu-devel@nongnu.org; Wed, 01 Mar 2017 04:38:06 -0500 Received: from mout.kundenserver.de ([217.72.192.74]:62166) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cj0ht-0006p8-A0 for qemu-devel@nongnu.org; Wed, 01 Mar 2017 04:38:01 -0500 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue102 [212.227.15.183]) with ESMTPSA (Nemesis) id 0LpfUc-1c3bPk3NHq-00fR0r; Wed, 01 Mar 2017 10:37:51 +0100 From: Laurent Vivier To: Riku Voipio Date: Wed, 1 Mar 2017 10:37:47 +0100 Message-Id: <20170301093748.28033-2-laurent@vivier.eu> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170301093748.28033-1-laurent@vivier.eu> References: <20170301093748.28033-1-laurent@vivier.eu> X-Provags-ID: V03:K0:CaJrGISoSwrFbeIGOnf6kqoWHDEB+thcA0Wf9CY3a4X0d+vfZrW LS5AjufLzZPN3Mt1IkfElwYkGGc1BB+Fp5Dxk9gr/kvRxEZFxVRA1bA/x0cWQRELY3MjE4G pjLIpi7gNGto3tuLveezlnKlNLGMMrj2Gfi9qxc0VQb4pJ+VfqK8Ud5E9LxQN9Pe+flyIBV jypzAQublNRDF6ainIvUQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:lQIu/PTXxHs=:TcCacSI8bOI0yRNamDO7L4 H5qitNdHmeRMp4JB3Oc+/1A4bdW3pML/dybUtDkF3RMRm8XH142VGbHoXrKdz24OOfIE6Fnv9 R46ekaym6JrbWPdyfJ/M3cNh6kWhCC1PyFlykzESfjMkwtQ/WYFUwDHUdXUTdKTW90CWJ5WTC oVsHUVYipOTkLQScsr/FKO+m6J069M3fbOp7wh2+OkVcjUhJKmYEACrwPvTyOl4OcwPi9X9Dg ctMMTsfsUqNPLIajmiiuu0BfFS0QfXZFKfJqgp1Dw8gUtQvXflHoHshWoR35k6Yo24L4/VUOk 3OQieyY9P47KzP6wFgf73RVGGwtJWgqrsW7srBb9enzPCo2KjXUlMolK+T7yc0g+6EbwyH6/7 MefHiy9ynF6YKQkLA7icqsGsZaR9JMXhAUs3lpTb8Fpwu/TnhLkoznzKa6rKo9fxntbJ4ku4/ vl+ET+Ajm8fqr3nZbWu3a96JEGT54k//nxaQASyxFI0GDyGLTX3h2jpslisXoApDIy5PjkHxg X/f19LJz9Q9k37nTOM/TYrxPbm1I0FpW2LVwUkgHPzq7xyO/40W/lTbVbbJdnhVDcPmttHggz tgokMFlJIA71fd7mmeE35MYV23xLW/iJvFWsHO+K4O2mcR2xvKGaKwPvWEuHkr9c8GrMdDR9o BrnetppuuLccNLxfemgtQ2FhmpUe91W/EKllz/PoaIZdc6r7ESKu3fXXB5Scx2J8ltWM= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 217.72.192.74 Subject: [Qemu-devel] [PATCH 1/2] linux-user: call fd_trans_target_to_host_data() for write() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org, Laurent Vivier Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 --- linux-user/syscall.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index cec8428..b2b563e 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