From patchwork Wed Mar 1 09:37:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 734155 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 3vY9PT3Vfvz9s7p for ; Wed, 1 Mar 2017 20:38:53 +1100 (AEDT) Received: from localhost ([::1]:39317 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cj0ig-0006YO-9A for incoming@patchwork.ozlabs.org; Wed, 01 Mar 2017 04:38:50 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33556) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cj0hz-0006XN-6w for qemu-devel@nongnu.org; Wed, 01 Mar 2017 04:38:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cj0hu-0006q1-9g for qemu-devel@nongnu.org; Wed, 01 Mar 2017 04:38:07 -0500 Received: from mout.kundenserver.de ([217.72.192.75]:53763) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cj0hu-0006pR-03 for qemu-devel@nongnu.org; Wed, 01 Mar 2017 04:38:02 -0500 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue102 [212.227.15.183]) with ESMTPSA (Nemesis) id 0MSao8-1cqoAt1Lfg-00Rb7z; Wed, 01 Mar 2017 10:37:51 +0100 From: Laurent Vivier To: Riku Voipio Date: Wed, 1 Mar 2017 10:37:48 +0100 Message-Id: <20170301093748.28033-3-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:iINZ8dArog/LxcGXXcdjm2QI0l9fZoBoScUJam4q4Wf4/0f3TVQ s79DvAftATll7DwRMEDN1Z46yAgsTLY42zeWDC+R39bNPDJnsrH96Jcj+SUkjqRFpV6uh2/ vBx8I175H7Jr4PFjTWE+blX5/nWFXXdbFN58d1ySXi5b7V+hSRChpXtEThY3/Dkd3WSHt/t k78IILVwI+nKiDJXTt3NQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:hOQHhRYpxWw=:jSySVA356pcFTtTXujEzch sn4P2DAXCRh6UI8yjPy53zXsnv3Rf84s7rJPC/3P4V8GFP7cIlLc4CotX3pZjFQ2jQ3CiQ2ad EWLoVqoGARLN6xh4VnkKo2/Mauic57677nEt2L1tIwdptb7xDf+r/jUWhwnFSUcCLLSnJrzia d1Hq/pC7TE9w/zTD/PIFUgEldjQBuqqZcWMQN6Fnzf7WblwspS12aIEr8LNvW1E6gK5FkViol oHPLcPm9OI6wBKbpc1xbE2cxE+py23mCPOyC6YjbonqsbZytDzuQOEYrfVeOLQnx5/StaEo0x CXJpu0mk6y4Jb48BL5OEXKdBVNsZw1Wc4nPDXRdkVWIt9/K01f4ww6S+OkitQwS1ImEgKnYOp 3Y/U+YVXli/gf+g8rN+TpnHAiK+YCktwB2le3CAVGKEKcIfXRpF/YYn/O1OJbgaekMv5vphyW BnkzT7LcFbENZZa7/EAZmkDdH7pjdokWcmuAZ58v2bv7HvPfXxD1/2349mPULNj7c+r2x9sED BC9Flve4YJVs3e9rDldqEJGS1Xtuj5V041NfwbUonQkZLFz52Ajcv+BHg+hBXjxM4OVkIODzu epZBTm074EXyF4WowWVW6i7bbtYN0PDirWAHkJ7KOh4hLU1nc+0SA00JO+ZAykX+E86AVp0+J M0KWlaC3QkYOgSA0xWwYTrfhKJ6PX7BWysOeGGMRpbtIAF7rs+dE34W4FzfF+kc4IVTs= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 217.72.192.75 Subject: [Qemu-devel] [PATCH 2/2] linux-user: fix eventfd 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" When a fd is opened using eventfd(), a read provides a 64bit counter in the host byte order, and a write increase the internal counter by the provided 64bit value. Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index b2b563e..2da8426 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -7671,6 +7671,28 @@ static target_timer_t get_timer_id(abi_long arg) return timerid; } +static abi_long swap_data_eventfd(void *buf, size_t len) +{ + uint64_t *counter = buf; + int i; + + if (len < sizeof(uint64_t)) { + return -EINVAL; + } + + for (i = 0; i < len; i += sizeof(uint64_t)) { + *counter = tswap64(*counter); + counter++; + } + + return len; +} + +static TargetFdTrans target_eventfd_trans = { + .host_to_target_data = swap_data_eventfd, + .target_to_host_data = swap_data_eventfd, +}; + /* do_syscall() should always have a single exit point at the end so that actions, such as logging of syscall results, can be performed. All errnos that do_syscall() returns must be -TARGET_. */ @@ -11876,7 +11898,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, #if defined(TARGET_NR_eventfd) case TARGET_NR_eventfd: ret = get_errno(eventfd(arg1, 0)); - fd_trans_unregister(ret); + fd_trans_register(ret, &target_eventfd_trans); break; #endif #if defined(TARGET_NR_eventfd2) @@ -11890,7 +11912,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, host_flags |= O_CLOEXEC; } ret = get_errno(eventfd(arg1, host_flags)); - fd_trans_unregister(ret); + fd_trans_register(ret, &target_eventfd_trans); break; } #endif