From nobody Sun Nov 24 06:27:40 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1725779831579807.5885612793796; Sun, 8 Sep 2024 00:17:11 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1snC9m-0006bs-QQ; Sun, 08 Sep 2024 03:16:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1snC9l-0006aM-4X; Sun, 08 Sep 2024 03:16:21 -0400 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1snC9j-0000Lp-3w; Sun, 08 Sep 2024 03:16:20 -0400 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 6DEAA8CC3E; Sun, 8 Sep 2024 10:16:04 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id B35AE1374D6; Sun, 8 Sep 2024 10:16:05 +0300 (MSK) Received: (nullmailer pid 430447 invoked by uid 1000); Sun, 08 Sep 2024 07:16:05 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org Cc: qemu-trivial@nongnu.org, Peter Maydell , Michael Tokarev Subject: [PATCH trvivial] linux-user/syscall.c: replace function pointers for flock64 fcntl with macros Date: Sun, 8 Sep 2024 10:16:00 +0300 Message-Id: <20240908071600.430410-1-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1725779840658116600 Content-Type: text/plain; charset="utf-8" For 32bit ARM fcntl64 syscall there are 2 possible argument types, depending on cpu_env->eabi. For other architectures, it is plain struct flock64 in all cases. In order to solve this, old code used to take address of the conversion function and and run it through this pointer. Instead, introduce 2 helper macros for the flock64 conversion, and define them in the same block where the oabi conversion functions are defined, and use these helpers directly in the actual code, making each part more self-contained and easier to read. Also add comment to the block of code which itroduces the oabi conversion functions. Note also there was an inconsistency in the old code: different the differences in single place we eliminate this difference. While at it, replace tabs with spaces in nearby code. Signed-off-by: Michael Tokarev --- linux-user/syscall.c | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index d418e2864a..03250316df 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -6880,10 +6880,12 @@ static inline abi_long copy_to_user_flock(abi_ulong= target_flock_addr, return 0; } =20 -typedef abi_long from_flock64_fn(struct flock *fl, abi_ulong target_addr); -typedef abi_long to_flock64_fn(abi_ulong target_addr, const struct flock *= fl); - #if defined(TARGET_ARM) && TARGET_ABI_BITS =3D=3D 32 +/* + * For 32bit arm flock64 syscall there are 2 variants of target_flock + * depending on eabi + */ + struct target_oabi_flock64 { abi_short l_type; abi_short l_whence; @@ -6935,6 +6937,19 @@ static inline abi_long copy_to_user_oabi_flock64(abi= _ulong target_flock_addr, unlock_user_struct(target_fl, target_flock_addr, 1); return 0; } + +#define copy_from_user_flock64_2abi(cpu_env, fl, target_flock_addr) \ + (cpu_env->eabi ? copy_from_user_flock64(fl, target_flock_addr) := \ + copy_from_user_oabi_flock64(fl, target_flock_ad= dr)) +#define copy_to_user_flock64_2abi(cpu_env, target_flock_addr, fl) \ + (cpu_env->eabi ? copy_to_user_flock64(target_flock_addr, fl) \ + copy_to_user_oabi_flock64(target_flock_addr, fl= )) +#else + +#define copy_from_user_flock64_2abi(cpu_env, fl, target_flock_addr) \ + copy_from_user_flock64(fl, target_flock_addr) +#define copy_to_user_flock64_2abi(cpu_env, target_flock_addr, fl) \ + copy_to_user_flock64(target_flock_addr, fl) #endif =20 static inline abi_long copy_from_user_flock64(struct flock *fl, @@ -12402,15 +12417,6 @@ static abi_long do_syscall1(CPUArchState *cpu_env,= int num, abi_long arg1, { int cmd; struct flock fl; - from_flock64_fn *copyfrom =3D copy_from_user_flock64; - to_flock64_fn *copyto =3D copy_to_user_flock64; - -#ifdef TARGET_ARM - if (!cpu_env->eabi) { - copyfrom =3D copy_from_user_oabi_flock64; - copyto =3D copy_to_user_oabi_flock64; - } -#endif =20 cmd =3D target_to_host_fcntl_cmd(arg2); if (cmd =3D=3D -TARGET_EINVAL) { @@ -12419,24 +12425,24 @@ static abi_long do_syscall1(CPUArchState *cpu_env= , int num, abi_long arg1, =20 switch(arg2) { case TARGET_F_GETLK64: - ret =3D copyfrom(&fl, arg3); + ret =3D copy_from_user_flock64_2abi(cpu_env, &fl, arg3); if (ret) { break; } ret =3D get_errno(safe_fcntl(arg1, cmd, &fl)); if (ret =3D=3D 0) { - ret =3D copyto(arg3, &fl); + ret =3D copy_to_user_flock64_2abi(cpu_env, arg3, &fl); } - break; + break; =20 case TARGET_F_SETLK64: case TARGET_F_SETLKW64: - ret =3D copyfrom(&fl, arg3); + ret =3D copy_from_user_flock64_2abi(cpu_env, &fl, arg3); if (ret) { break; } ret =3D get_errno(safe_fcntl(arg1, cmd, &fl)); - break; + break; default: ret =3D do_fcntl(arg1, arg2, arg3); break; --=20 2.39.2