From patchwork Tue May 8 16:36:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 910336 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 40gQBv4mR8z9ryk for ; Wed, 9 May 2018 02:37:42 +1000 (AEST) Received: from localhost ([::1]:52333 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fG5cP-0003GV-78 for incoming@patchwork.ozlabs.org; Tue, 08 May 2018 12:37:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55699) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fG5by-0003EL-53 for qemu-devel@nongnu.org; Tue, 08 May 2018 12:37:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fG5bt-0005R7-7O for qemu-devel@nongnu.org; Tue, 08 May 2018 12:37:10 -0400 Received: from mout.kundenserver.de ([212.227.126.134]:44059) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fG5bs-0005QY-UW for qemu-devel@nongnu.org; Tue, 08 May 2018 12:37:05 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue004 [212.227.15.167]) with ESMTPSA (Nemesis) id 0MXTpy-1emtN61u6g-00WZDf; Tue, 08 May 2018 18:36:50 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Tue, 8 May 2018 18:36:39 +0200 Message-Id: <20180508163639.7138-1-laurent@vivier.eu> X-Mailer: git-send-email 2.14.3 X-Provags-ID: V03:K1:hDn1ipTFRY4eQEkulrJmHaWwpvV0FAhjUXt6fJQX6e3KaMRdQd+ eK7zcC1JU3GlifUYK6Wv6jb2YrXcvHfq/OLyBzsSFLlMn1yPQtGi3MO5TJ4blUHSAltNhyp jpsmwr7DQt7FaCh0G2p7MTzlAVa2U7PGFiy/xyMXQ5t04SHMTyqacbGBlsbsPto197H6cMD n1fs6BjThLgTsy6sK7OJQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:GeF+xOA3JdI=:YkvNmX4xQ8pO+eJu2ecBek vrmFMEQmD/w46aazh7umdO+icAr1Pk7gBlg3zo6qR9ETfrmgzomQtRmFdVGpFtldbOoMnyIRD aWAyJfiSXICWCtzUOrq3cxsfqUMR+H1x4T1DXFBLnBXTbbbdcE7h8peUgs8n5Mo7HZtL7Gk6s +abwoA1retUSH3Ld5cJGId33ltyo3FPpv1TAVbo5Jhz6XRmylFpCgXylBY/Fe8bQjRnzGxEGk 4oswBBgVL4G46UTG3p8LtlJTCyofRVsWt8WJXmuOet8oWkBsbo7WiM0bWAJWZZx8HkcKjoXuY iWAbLDLyTnVCYMx7/GCmC2SESsNFuHUTLkmTWqqxv4wdC87u00bbPZHG004Gth/tUnsm2a8Km EXk0Ob/rLKZZWA3oN8w1tem8o7a0pgWl2OMVnRJeN/BjzdIQEf8DfqDScOh2lYhMKk6s/isT6 BkF2Wx18OGO2U2AuSXH9um2dVhfiPnU1R35mKI4N6DXaKUr9bkEPv3ItrlbMAy+Ob2JIr2ghn UOSU36IQjHolSvRb9YhyoHCXLbN0O8gQ/ev8OF6EmwJqzBi026Vwdyqj/Lk0NMWAEtjBohQ99 TFLeav1mQMugUVyV6csd6+XmquLg5/5DMBJVrjWzFw+aKWgDrmusDh89O9VnpbGfQSBX9LwTk xzK18HzYECu1kNB8G2bchk2SxrE+XQ9UYIcngUS3a6jrq1J5vReTbd+ZboVXqcjIgkuI= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.227.126.134 Subject: [Qemu-devel] [PATCH] 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);