Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LvdnC-0004Rm-7w for qemu-devel@nongnu.org; Sun, 19 Apr 2009 16:39:10 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LvdnB-0004RI-Iw for qemu-devel@nongnu.org; Sun, 19 Apr 2009 16:39:09 -0400 Received: from [199.232.76.173] (port=38993 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LvdnB-0004RF-G1 for qemu-devel@nongnu.org; Sun, 19 Apr 2009 16:39:09 -0400 Received: from lechat.rtp-net.org ([88.191.19.38]:43618) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LvdnA-0001c4-TX for qemu-devel@nongnu.org; Sun, 19 Apr 2009 16:39:09 -0400 Received: from lechat.rtp-net.org (localhost [127.0.0.1]) by lechat.rtp-net.org (Postfix) with ESMTP id 01D2910087 for ; Sun, 19 Apr 2009 22:45:39 +0200 (CEST) From: Arnaud Patard (Rtp) Date: Sun, 19 Apr 2009 22:45:39 +0200 Message-ID: <87r5zofk3w.fsf@lechat.rtp-net.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Subject: [Qemu-devel] [PATCH] fix fcntl support in linux-user. Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org --=-=-= The current code in do_fcntl is passing the target command as a host command. This is introducing 2 problems: - When building with "-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE", we may end up passing commands like F_GETFL instead of F_GETFL64. This is likely to return an error. - The F_*64 constants doesn't always have the same value between host and target. Without this patch locking is not working (My test-case was pwck with arm as target and mips as host). Signed-off-by: Arnaud Patard --- --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=fix_fcntl.patch diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 2d51d6b..2d876c1 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -3126,7 +3141,7 @@ static abi_long do_fcntl(int fd, int cmd, abi_ulong arg) fl.l_len = tswapl(target_fl->l_len); fl.l_pid = tswapl(target_fl->l_pid); unlock_user_struct(target_fl, arg, 0); - ret = get_errno(fcntl(fd, cmd, &fl)); + ret = get_errno(fcntl(fd, F_GETLK, &fl)); if (ret == 0) { if (!lock_user_struct(VERIFY_WRITE, target_fl, arg, 0)) return -TARGET_EFAULT; @@ -3149,7 +3164,7 @@ static abi_long do_fcntl(int fd, int cmd, abi_ulong arg) fl.l_len = tswapl(target_fl->l_len); fl.l_pid = tswapl(target_fl->l_pid); unlock_user_struct(target_fl, arg, 0); - ret = get_errno(fcntl(fd, cmd, &fl)); + ret = get_errno(fcntl(fd, F_SETLK+(cmd-TARGET_F_SETLK), &fl)); break; case TARGET_F_GETLK64: @@ -3161,7 +3176,7 @@ static abi_long do_fcntl(int fd, int cmd, abi_ulong arg) fl64.l_len = tswapl(target_fl64->l_len); fl64.l_pid = tswap16(target_fl64->l_pid); unlock_user_struct(target_fl64, arg, 0); - ret = get_errno(fcntl(fd, cmd >> 1, &fl64)); + ret = get_errno(fcntl(fd, F_GETLK64, &fl64)); if (ret == 0) { if (!lock_user_struct(VERIFY_WRITE, target_fl64, arg, 0)) return -TARGET_EFAULT; @@ -3183,7 +3198,7 @@ static abi_long do_fcntl(int fd, int cmd, abi_ulong arg) fl64.l_len = tswapl(target_fl64->l_len); fl64.l_pid = tswap16(target_fl64->l_pid); unlock_user_struct(target_fl64, arg, 0); - ret = get_errno(fcntl(fd, cmd >> 1, &fl64)); + ret = get_errno(fcntl(fd, F_SETLK64+(cmd-TARGET_F_SETLK64), &fl64)); break; case F_GETFL: @@ -6022,7 +6039,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, ret = get_errno(fcntl(arg1, cmd, &fl)); break; default: - ret = do_fcntl(arg1, cmd, arg3); + ret = do_fcntl(arg1, arg2, arg3); break; } break; --=-=-=--