From patchwork Tue May 8 19:40:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 910433 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=vivier.eu 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 40gVHC0sz1z9s3G for ; Wed, 9 May 2018 05:41:43 +1000 (AEST) Received: from localhost ([::1]:53055 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fG8UW-000717-MP for incoming@patchwork.ozlabs.org; Tue, 08 May 2018 15:41:40 -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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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; } -#define TRANSTBL_CONVERT(a) { -1, TARGET_##a, -1, a } -static const bitmask_transtbl flock_tbl[] = { - 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; +} 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 flock64 *fl, } __get_user(l_type, &target_fl->l_type); - fl->l_type = target_to_host_bitmask(l_type, flock_tbl); + fl->l_type = 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 target_flock_addr, return -TARGET_EFAULT; } - l_type = host_to_target_bitmask(fl->l_type, flock_tbl); + l_type = 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(struct flock64 *fl, } __get_user(l_type, &target_fl->l_type); - fl->l_type = target_to_host_bitmask(l_type, flock_tbl); + fl->l_type = 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; } - l_type = host_to_target_bitmask(fl->l_type, flock_tbl); + l_type = 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, } __get_user(l_type, &target_fl->l_type); - fl->l_type = target_to_host_bitmask(l_type, flock_tbl); + fl->l_type = 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; } - l_type = host_to_target_bitmask(fl->l_type, flock_tbl); + l_type = 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);