Linux user fcntl64 patches
The following changes since commit 97c81ef4b8e203d9620fd46e7eb77004563e3675:
Merge tag 'pull-9p-20230706' of https://github.com/cschoenebeck/qemu into staging (2023-07-06 18:19:42 +0100)
are available in the Git repository at:
https://github.com/hdeller/qemu-hppa.git tags/linux-user-fcntl64-pull-request
for you to fetch changes up to 036cf169a3484eeca5e17cfbee1f6988043ddd0e:
linux-user: Improve strace output of pread64() and pwrite64() (2023-07-08 16:55:08 +0200)
----------------------------------------------------------------
linux-user: Fix fcntl64() and accept4() for 32-bit targets
A set of 3 patches:
The first two patches fix fcntl64() and accept4().
the 3rd patch enhances the strace output for pread64/pwrite64().
This pull request does not includes Richard's mmap2 patch:
https://patchew.org/QEMU/[email protected]/[email protected]/
Changes:
v3:
- added r-b from Richard to patches #1 and #2
v2:
- rephrased commmit logs
- return O_LARGFILE for fcntl() syscall too
- dropped #ifdefs in accept4() patch
- Dropped my mmap2() patch (former patch #3)
- added r-b from Richard to 3rd patch
Helge
----------------------------------------------------------------
Helge Deller (3):
linux-user: Fix fcntl() and fcntl64() to return O_LARGEFILE for 32-bit
targets
linux-user: Fix accept4(SOCK_NONBLOCK) syscall
linux-user: Improve strace output of pread64() and pwrite64()
linux-user/strace.c | 19 +++++++++++++++++++ linux-user/strace.list | 4 ++-- linux-user/syscall.c | 16 +++++++++++++++- 3 files changed, 36 insertions(+), 3 deletions(-)
--
2.41.0
[PULL 1/3] linux-user: Fix fcntl() and fcntl64() to return O_LARGEFILE for 32-bit targets
When running a 32-bit guest on a 64-bit host, fcntl[64](F_GETFL) should return with the TARGET_O_LARGEFILE flag set, because all 64-bit hosts support large files unconditionally.
But on 64-bit hosts, O_LARGEFILE has the value 0, so the flag translation can't be done with the fcntl_flags_tbl[]. Instead add the TARGET_O_LARGEFILE flag afterwards.
Note that for 64-bit guests the compiler will optimize away this code, since TARGET_O_LARGEFILE is zero.
--- linux-user/syscall.c | 4 ++++ 1 file changed, 4 insertions(+)
linux-user/syscall.c +4 -0
@@ -7132,6 +7132,10 @@ static abi_long do_fcntl(int fd, int cmd, abi_ulong arg) ret =get_errno (safe_fcntl (fd, host_cmd, arg));if (ret >=0 ) { ret =host_to_target_bitmask (ret, fcntl_flags_tbl); +/* tell 32-bit guests it uses largefile on 64-bit hosts: */ +if (O_LARGEFILE ==0 &&HOST_LONG_BITS ==64 ) { + ret |=TARGET_O_LARGEFILE ; + } }break ;
--
2.41.0
[PULL 2/3] linux-user: Fix accept4(SOCK_NONBLOCK) syscall
In reply to Helge DellerThe Linux accept4() syscall allows two flags only: SOCK_NONBLOCK and SOCK_CLOEXEC, and returns -EINVAL if any other bits have been set.
Change the qemu implementation accordingly, which means we can not use the fcntl_flags_tbl[] translation table which allows too many other values.
Beside the correction in behaviour, this actually fixes the accept4() emulation for hppa, mips and alpha targets for which SOCK_NONBLOCK is different than TARGET_SOCK_NONBLOCK (aka O_NONBLOCK).
The fix can be verified with the testcase of the debian lwt package, which hangs forever in a read() syscall without this patch.
--- linux-user/syscall.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
linux-user/syscall.c +11 -1
@@ -3440,7 +3440,17 @@ static abi_long do_accept4(int fd, abi_ulong target_addr,abi_long ret;int host_flags; - host_flags =target_to_host_bitmask (flags, fcntl_flags_tbl); +if (flags & ~(TARGET_SOCK_CLOEXEC |TARGET_SOCK_NONBLOCK )) { +return -TARGET_EINVAL ; + } + + host_flags =0 ; +if (flags &TARGET_SOCK_NONBLOCK ) { + host_flags |=SOCK_NONBLOCK ; + } +if (flags &TARGET_SOCK_CLOEXEC ) { + host_flags |=SOCK_CLOEXEC ; + }if (target_addr ==0 ) {return get_errno (safe_accept4 (fd,NULL ,NULL , host_flags));
--
2.41.0
[PULL 3/3] linux-user: Improve strace output of pread64() and pwrite64()
In reply to Helge DellerMake the strace look nicer for those two syscalls.
--- linux-user/strace.c | 19 +++++++++++++++++++ linux-user/strace.list | 4 ++-- 2 files changed, 21 insertions(+), 2 deletions(-)
linux-user/strace.c +19 -0
@@ -3999,6 +3999,25 @@ print_tgkill(CPUArchState *cpu_env, const struct syscallname *name, }#endif +#if defined(TARGET_NR_pread64) || defined(TARGET_NR_pwrite64) +static void +print_pread64 (CPUArchState *cpu_env,const struct syscallname *name, +abi_long arg0,abi_long arg1,abi_long arg2, +abi_long arg3,abi_long arg4,abi_long arg5) +{ +if (regpairs_aligned (cpu_env, TARGET_NR_pread64)) { + arg3 = arg4; + arg4 = arg5; + } +print_syscall_prologue (name); +print_raw_param ("%d" , arg0,0 ); +print_pointer (arg1,0 ); +print_raw_param ("%d" , arg2,0 ); +print_raw_param ("%" PRIu64,target_offset64 (arg3, arg4),1 ); +print_syscall_epilogue (name); +} +#endif +#ifdef TARGET_NR_statx static void print_statx(CPUArchState *cpu_env, const struct syscallname *name,
linux-user/strace.list +2 -2
@@ -1068,7 +1068,7 @@ { TARGET_NR_prctl, "prctl" , NULL, NULL, NULL }, #endif #ifdef TARGET_NR_pread64 -{ TARGET_NR_pread64, "pread64" , NULL, NULL, NULL }, +{ TARGET_NR_pread64, "pread64" , NULL, print_pread64, NULL }, #endif #ifdef TARGET_NR_preadv { TARGET_NR_preadv, "preadv" , NULL, NULL, NULL },
@@ -1099,7 +1099,7 @@ { TARGET_NR_putpmsg, "putpmsg" , NULL, NULL, NULL }, #endif #ifdef TARGET_NR_pwrite64 -{ TARGET_NR_pwrite64, "pwrite64" , NULL, NULL, NULL }, +{ TARGET_NR_pwrite64, "pwrite64" , NULL, print_pread64, NULL }, #endif #ifdef TARGET_NR_pwritev { TARGET_NR_pwritev, "pwritev" , NULL, NULL, NULL },
--
2.41.0
Richard Henderson
AppliedQuoted 11 lines · Helge Deller
The following changes since commit
97c81ef4b8e203d9620fd46e7eb77004563e3675:Merge tag 'pull-9p-20230706' ofhttps://github.com/cschoenebeck/qemu into staging (2023-07-06 18:19:42 +0100)are available in the Git repository at:
https://github.com/hdeller/qemu-hppa.git tags/linux-user-fcntl64-pull-request
for you to fetch changes up to
036cf169a3484eeca5e17cfbee1f6988043ddd0e:linux-user: Improve strace output of pread64() and pwrite64() (2023-07-08 16:55:08 +0200)
Applied, thanks. Please update https://wiki.qemu.org/ChangeLog/8.1 as appropriate.
r~