From nobody Sun May 5 23:12:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1488416138686524.4352442408891; Wed, 1 Mar 2017 16:55:38 -0800 (PST) Received: from localhost ([::1]:49526 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cjF1s-0004Re-4C for importer@patchew.org; Wed, 01 Mar 2017 19:55:36 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36010) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cjF1M-0004RV-HA for qemu-devel@nongnu.org; Wed, 01 Mar 2017 19:55:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cjF1J-0005id-8w for qemu-devel@nongnu.org; Wed, 01 Mar 2017 19:55:04 -0500 Received: from mout.kundenserver.de ([212.227.126.130]:51846) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cjF1I-0005g7-Pq for qemu-devel@nongnu.org; Wed, 01 Mar 2017 19:55:01 -0500 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue001 [212.227.15.167]) with ESMTPSA (Nemesis) id 0MOXED-1cdTih3wgP-005o8G; Thu, 02 Mar 2017 01:54:51 +0100 From: Laurent Vivier To: Riku Voipio Date: Thu, 2 Mar 2017 01:54:48 +0100 Message-Id: <20170302005448.21336-1-laurent@vivier.eu> X-Mailer: git-send-email 2.9.3 X-Provags-ID: V03:K0:ObNLG6cGPEFpbqfNcMwIH4RsXNm7Rii8GewpK8xv97BWVWE1oR1 0m5XKp0eyhU4eWpLzCqkBLOwae4/SxvyJpkVudU65S3vpIoMwGWwEMiVtFwUpQbdCXkFyV2 OAEnXhaXSAFMd3lqHSiQlLJXQ6Cl1Tyz2z1jyTsNMUW3gaW8gltC/SrjkSYlIxZwwUJEHAh Z/jAnUodpLJNXatRMPPdg== X-UI-Out-Filterresults: notjunk:1;V01:K0:9UFsxa8hUx0=:4eoQLaTdgw6TtlLKXSYMHR tvjeztSLsdZLShFF2GapR8RxCpZKyJQPJmPgK9mR1GHCB2x7GFiwTzlo+eN54Zebyi/BrknN4 3mhSBODA+EiFdM/wu/KgDAqnEP/Z7H2eZVR9cvfaob+JZkQ8MMcpajaXaFmOOr8YepQz7POw/ 15H8ZK5qTo0rcorU4PfvMjEFqFnEgHCQsxOxqvjM+ViQP6Gr6Y3lOe1iR6+pYhEkFV46l5y+5 df/mg6X5fIF7jvd0DDeqyT/YN8etHkekYavbfLqqriDFF8mVysYLHePE0NU3rT9xZrER8rCrj tEVOpvpoPTN6U4mBWcwmSdz3H0m6WhBdjAZeAAUrd8idZzcZcF89intHn0ryDmU62UNPnv6bm xgq/2bhSKPWgR+O+2rDENXjwdiuTZVVz11EK2CxOrcwoQkWCtdk1FMRIkVCv/SbY/prECXsoK ijRIoEqqBjW9Fw65GsoLgOaubDhQrGYxdHh+jogaf4cDEiNYMOPYUaEvpydbCOF2B31z47p9W WnyfiHyqVi27x6a3z8JP3xSel/78P3ykzLQSrzjuhSWMurNfwnXn8FKjj9LvAyVcCEyqwzsjS Nc2MM21mKNmRQ6fNnO7DSDB7gYSzEmGHKYORLQ+uYxrYGa9YaXaGNdvuJCX9Bmvd6GWhhWywf Iou2KISdeRxK6b0opuq7y0RXfH0mvlEC0lQ8ak3O1HSs5N6KD+OVk1eo7eE7zGJYuipc= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.227.126.130 Subject: [Qemu-devel] [PATCH] linux-user: fix inotify 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" When a fd is opened using inotify_init(), a read provides one or more inotify_event structures: struct inotify_event { int wd; uint32_t mask; uint32_t cookie; uint32_t len; char name[]; }; The integer fields must be byte-swapped to the target endianness. Signed-off-by: Laurent Vivier Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- linux-user/syscall.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index cec8428..c2c4f3a 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -7671,6 +7671,33 @@ static target_timer_t get_timer_id(abi_long arg) return timerid; } =20 +#if (defined(TARGET_NR_inotify_init) && defined(__NR_inotify_init)) || \ + (defined(CONFIG_INOTIFY1) && defined(TARGET_NR_inotify_init1) && \ + defined(__NR_inotify_init1)) +static abi_long host_to_target_data_inotify(void *buf, size_t len) +{ + struct inotify_event *ev; + int i; + uint32_t name_len; + + for (i =3D 0; i < len; i +=3D sizeof(struct inotify_event) + name_len)= { + ev =3D (struct inotify_event *)((char *)buf + i); + name_len =3D ev->len; + + ev->wd =3D tswap32(ev->wd); + ev->mask =3D tswap32(ev->mask); + ev->cookie =3D tswap32(ev->cookie); + ev->len =3D tswap32(name_len); + } + + return len; +} + +static TargetFdTrans target_inotify_trans =3D { + .host_to_target_data =3D host_to_target_data_inotify, +}; +#endif + /* 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_. */ @@ -11694,6 +11721,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_lon= g arg1, #if defined(TARGET_NR_inotify_init) && defined(__NR_inotify_init) case TARGET_NR_inotify_init: ret =3D get_errno(sys_inotify_init()); + fd_trans_register(ret, &target_inotify_trans); break; #endif #ifdef CONFIG_INOTIFY1 @@ -11701,6 +11729,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_lon= g arg1, case TARGET_NR_inotify_init1: ret =3D get_errno(sys_inotify_init1(target_to_host_bitmask(arg1, fcntl_flags_tbl))); + fd_trans_register(ret, &target_inotify_trans); break; #endif #endif --=20 2.9.3