Skip to content

Commit

Permalink
Merge tag 'linux-user-fcntl64-pull-request' of https://github.com/hde…
Browse files Browse the repository at this point in the history
…ller/qemu-hppa into staging

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

# -----BEGIN PGP SIGNATURE-----
#
# iHUEABYKAB0WIQS86RI+GtKfB8BJu973ErUQojoPXwUCZKl5RQAKCRD3ErUQojoP
# X82sAQDnW53s7YkU4sZ1YREPWPVoCXZXgm587jTrmwT4v9AenQEAlbKdsw4hzzr/
# ptuKvgZfZaIp5QjBUl/Dh/CI5aVOLgc=
# =hd4O
# -----END PGP SIGNATURE-----
# gpg: Signature made Sat 08 Jul 2023 03:57:09 PM BST
# gpg:                using EDDSA key BCE9123E1AD29F07C049BBDEF712B510A23A0F5F
# gpg: Good signature from "Helge Deller <[email protected]>" [unknown]
# gpg:                 aka "Helge Deller <[email protected]>" [unknown]
# gpg: WARNING: This key is not certified with a trusted signature!
# gpg:          There is no indication that the signature belongs to the owner.
# Primary key fingerprint: 4544 8228 2CD9 10DB EF3D  25F8 3E5F 3D04 A7A2 4603
#      Subkey fingerprint: BCE9 123E 1AD2 9F07 C049  BBDE F712 B510 A23A 0F5F

* tag 'linux-user-fcntl64-pull-request' of https://github.com/hdeller/qemu-hppa:
  linux-user: Improve strace output of pread64() and pwrite64()
  linux-user: Fix accept4(SOCK_NONBLOCK) syscall
  linux-user: Fix fcntl() and fcntl64() to return O_LARGEFILE for 32-bit targets

Signed-off-by: Richard Henderson <[email protected]>
  • Loading branch information
rth7680 committed Jul 9, 2023
2 parents 9e7ce9e + 036cf16 commit fc61742
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
19 changes: 19 additions & 0 deletions linux-user/strace.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions linux-user/strace.list
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down Expand Up @@ -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 },
Expand Down
16 changes: 15 additions & 1 deletion linux-user/syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -7132,6 +7142,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;

Expand Down

0 comments on commit fc61742

Please sign in to comment.