From nobody Wed Oct 29 22:59:56 2025 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.zohomail.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 152580857162249.30093720708703; Tue, 8 May 2018 12:42:51 -0700 (PDT) Received: from localhost ([::1]:53060 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fG8Ve-00087T-Rb for importer@patchew.org; Tue, 08 May 2018 15:42:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43185) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fG8Te-0006w5-Op for qemu-devel@nongnu.org; Tue, 08 May 2018 15:40:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fG8Tb-0002WQ-Ki for qemu-devel@nongnu.org; Tue, 08 May 2018 15:40:46 -0400 Received: from mout.kundenserver.de ([212.227.126.187]:40333) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fG8Tb-0002Tv-Bg for qemu-devel@nongnu.org; Tue, 08 May 2018 15:40:43 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue001 [212.227.15.167]) with ESMTPSA (Nemesis) id 0MU9x3-1epMHL0vxp-00Qllg; Tue, 08 May 2018 21:40:34 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Tue, 8 May 2018 21:40:25 +0200 Message-Id: <20180508194026.1281-5-laurent@vivier.eu> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180508194026.1281-1-laurent@vivier.eu> References: <20180508194026.1281-1-laurent@vivier.eu> X-Provags-ID: V03:K1:xMDbaDqeoGKMyd0pt0m0PK26DNCvzayx5BdqOKp2X1QIlih065T hpWbRkOy/qeHvKYdZjtvGJJD1WrsYh966laQNxo2cKc7z9JzGpbW2hxcCsF/v5NLnBCpshf eHqPb2HlWrQrle5/x0D9rg/fPW0gHjtza11Fzr8x2g4oTbeoKFMe3DKib7Dv60UnktMQ0rK y+r4v9c6Ar89Rg1gPbPxA== X-UI-Out-Filterresults: notjunk:1;V01:K0:vvO/MNHbWh0=:+gW4zZH48bwXC+u1kFAER3 sVur8J0Pr9njR7TOOmeqctwswilIijEM92qRl1zI+kUHVRs9IZ+jTQ4s+lHo01pwRlxybTlwW /6mSaoCh1oEeHvPUhiNH2ACJi4Suv1QYU9W8dEqBg424/kr355GiIyQr52/q4YZH8Q9oTAlUu t37dRFI9xLmkZcpE+sOw6Vgk0/YaUUA/s3dFKCHjxTQvaWHmEshm9nnpQD2oahXoeBBX/Qizc klMgHHywF59QJt1JO3QClHLgYTRTBRqzr9/lRwyX+39dBf9J1Q949GxLsOciu+CKZj/fhVZAU 1WCkNmt82fBpz9vBdgwGMcfZW5W0FXb0N9gLhGVE3ttkHLtbi8lLZ/ULqMclSKQT7j3+5qsYV c71x11bihgy1ZZsTp1iOL1B29ydc5o9i70WttH5hoSf5gUVzfbV4IbKU0oeJ/cJ/Hh66QGbxO Itdgp3mGIk41p0FU0goPS/vxP9109qdaHkhORWbW/Cs8uJQBRPxjexY+Z3ud9DF+Vnm94p8av nn+I623C3yY73zwls5aC0InoulkZ3CrZ5Dlxoyv5gjxYQp3x62TYocIFujQWj/2t0csv6B13G ke93GPijoxS5OPDFpjPZUIfPMqc2n1EUV1nrX6ICR8mlDP5oCD+NFRrvtoYFlrH9bRRxv0kzk TG9ComPVczq1lXLZuo/6B/nkUKZwKnH+vpoBoKyb55z9WW8GZ1ikLYGgGlGIYnm4XXFo= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.227.126.187 Subject: [Qemu-devel] [PATCH 4/5] linux-user: fix convertion of flock/flock64 l_type field 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: Riku Voipio , 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" As l_type values (F_RDLCK, F_WRLCK, F_UNLCK, F_EXLCK, F_SHLCK) are not bitmasks, we can't use target_to_host_bitmask() and host_to_target_bitmask() to convert them. Introduce target_to_host_flock() and host_to_target_flock() to convert values between host and target. Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 48 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index e4825747f9..fdf6766eca 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -6546,15 +6546,33 @@ static int target_to_host_fcntl_cmd(int cmd) return -TARGET_EINVAL; } =20 -#define TRANSTBL_CONVERT(a) { -1, TARGET_##a, -1, a } -static const bitmask_transtbl flock_tbl[] =3D { - TRANSTBL_CONVERT(F_RDLCK), - TRANSTBL_CONVERT(F_WRLCK), - TRANSTBL_CONVERT(F_UNLCK), - TRANSTBL_CONVERT(F_EXLCK), - TRANSTBL_CONVERT(F_SHLCK), - { 0, 0, 0, 0 } -}; +static unsigned int target_to_host_flock(unsigned int type) +{ + switch (type) { +#define TRANSTBL_CONVERT(a) case TARGET_##a: return a; + TRANSTBL_CONVERT(F_RDLCK) + TRANSTBL_CONVERT(F_WRLCK) + TRANSTBL_CONVERT(F_UNLCK) + TRANSTBL_CONVERT(F_EXLCK) + TRANSTBL_CONVERT(F_SHLCK) +#undef TRANSTBL_CONVERT + } + return type; +} + +static unsigned int host_to_target_flock(unsigned int type) +{ + switch (type) { +#define TRANSTBL_CONVERT(a) case a: return TARGET_##a; + TRANSTBL_CONVERT(F_RDLCK) + TRANSTBL_CONVERT(F_WRLCK) + TRANSTBL_CONVERT(F_UNLCK) + TRANSTBL_CONVERT(F_EXLCK) + TRANSTBL_CONVERT(F_SHLCK) +#undef TRANSTBL_CONVERT + } + return type; +} =20 static inline abi_long copy_from_user_flock(struct flock64 *fl, abi_ulong target_flock_addr) @@ -6567,7 +6585,7 @@ static inline abi_long copy_from_user_flock(struct fl= ock64 *fl, } =20 __get_user(l_type, &target_fl->l_type); - fl->l_type =3D target_to_host_bitmask(l_type, flock_tbl); + fl->l_type =3D target_to_host_flock(l_type); __get_user(fl->l_whence, &target_fl->l_whence); __get_user(fl->l_start, &target_fl->l_start); __get_user(fl->l_len, &target_fl->l_len); @@ -6586,7 +6604,7 @@ static inline abi_long copy_to_user_flock(abi_ulong t= arget_flock_addr, return -TARGET_EFAULT; } =20 - l_type =3D host_to_target_bitmask(fl->l_type, flock_tbl); + l_type =3D host_to_target_flock(fl->l_type); __put_user(l_type, &target_fl->l_type); __put_user(fl->l_whence, &target_fl->l_whence); __put_user(fl->l_start, &target_fl->l_start); @@ -6611,7 +6629,7 @@ static inline abi_long copy_from_user_oabi_flock64(st= ruct flock64 *fl, } =20 __get_user(l_type, &target_fl->l_type); - fl->l_type =3D target_to_host_bitmask(l_type, flock_tbl); + fl->l_type =3D target_to_host_flock(l_type); __get_user(fl->l_whence, &target_fl->l_whence); __get_user(fl->l_start, &target_fl->l_start); __get_user(fl->l_len, &target_fl->l_len); @@ -6630,7 +6648,7 @@ static inline abi_long copy_to_user_oabi_flock64(abi_= ulong target_flock_addr, return -TARGET_EFAULT; } =20 - l_type =3D host_to_target_bitmask(fl->l_type, flock_tbl); + l_type =3D host_to_target_flock(fl->l_type); __put_user(l_type, &target_fl->l_type); __put_user(fl->l_whence, &target_fl->l_whence); __put_user(fl->l_start, &target_fl->l_start); @@ -6652,7 +6670,7 @@ static inline abi_long copy_from_user_flock64(struct = flock64 *fl, } =20 __get_user(l_type, &target_fl->l_type); - fl->l_type =3D target_to_host_bitmask(l_type, flock_tbl); + fl->l_type =3D target_to_host_flock(l_type); __get_user(fl->l_whence, &target_fl->l_whence); __get_user(fl->l_start, &target_fl->l_start); __get_user(fl->l_len, &target_fl->l_len); @@ -6671,7 +6689,7 @@ static inline abi_long copy_to_user_flock64(abi_ulong= target_flock_addr, return -TARGET_EFAULT; } =20 - l_type =3D host_to_target_bitmask(fl->l_type, flock_tbl); + l_type =3D host_to_target_flock(fl->l_type); __put_user(l_type, &target_fl->l_type); __put_user(fl->l_whence, &target_fl->l_whence); __put_user(fl->l_start, &target_fl->l_start); --=20 2.14.3