Skip to content

Commit dfae7aa

Browse files
authored
Fix several bugs in qemu. (#1148)
Fix the value of `TIOCGSID`. Translate the flags argument to `pidfd_open` from target to host flags, which fixes the value of `PIDFD_NONBLOCK` on platforms where the value differs, such as mips64. Define `TARGET_SO_INCOMING_CPU` and `TARGET_SO_COOKIE` for mips/mips64 in qemu.
1 parent b726837 commit dfae7aa

File tree

5 files changed

+58
-2
lines changed

5 files changed

+58
-2
lines changed

.github/workflows/main.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,9 @@ jobs:
482482
patch -p1 < $GITHUB_WORKSPACE/ci/s390x-stat-have-nsec.patch
483483
patch -p1 < $GITHUB_WORKSPACE/ci/aarch64-o-largefile.patch
484484
patch -p1 < $GITHUB_WORKSPACE/ci/tcgets2-tcsets2.patch
485+
patch -p1 < $GITHUB_WORKSPACE/ci/tiocgsid.patch
485486
patch -p1 < $GITHUB_WORKSPACE/ci/more-sockopts.patch
487+
patch -p1 < $GITHUB_WORKSPACE/ci/pidfd-open.patch
486488
./configure --target-list=${{ matrix.qemu_target }} --prefix=${{ runner.tool_cache }}/qemu --disable-tools --disable-slirp --disable-fdt --disable-capstone --disable-docs
487489
ninja -C build install
488490
if: matrix.qemu != '' && matrix.os == 'ubuntu-latest'
@@ -618,7 +620,9 @@ jobs:
618620
patch -p1 < $GITHUB_WORKSPACE/ci/s390x-stat-have-nsec.patch
619621
patch -p1 < $GITHUB_WORKSPACE/ci/aarch64-o-largefile.patch
620622
patch -p1 < $GITHUB_WORKSPACE/ci/tcgets2-tcsets2.patch
623+
patch -p1 < $GITHUB_WORKSPACE/ci/tiocgsid.patch
621624
patch -p1 < $GITHUB_WORKSPACE/ci/more-sockopts.patch
625+
patch -p1 < $GITHUB_WORKSPACE/ci/pidfd-open.patch
622626
./configure --target-list=${{ matrix.qemu_target }} --prefix=${{ runner.tool_cache }}/qemu --disable-tools --disable-slirp --disable-fdt --disable-capstone --disable-docs
623627
ninja -C build install
624628
if: matrix.qemu != '' && matrix.os == 'ubuntu-latest'
@@ -710,7 +714,9 @@ jobs:
710714
patch -p1 < $GITHUB_WORKSPACE/ci/s390x-stat-have-nsec.patch
711715
patch -p1 < $GITHUB_WORKSPACE/ci/aarch64-o-largefile.patch
712716
patch -p1 < $GITHUB_WORKSPACE/ci/tcgets2-tcsets2.patch
717+
patch -p1 < $GITHUB_WORKSPACE/ci/tiocgsid.patch
713718
patch -p1 < $GITHUB_WORKSPACE/ci/more-sockopts.patch
719+
patch -p1 < $GITHUB_WORKSPACE/ci/pidfd-open.patch
714720
./configure --target-list=${{ matrix.qemu_target }} --prefix=${{ runner.tool_cache }}/qemu --disable-tools --disable-slirp --disable-fdt --disable-capstone --disable-docs
715721
ninja -C build install
716722
if: matrix.qemu != '' && matrix.os == 'ubuntu-latest'

ci/more-sockopts.patch

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@ diff -ur -x roms -x build a/linux-user/generic/sockbits.h b/linux-user/generic/s
1818
+#define TARGET_SO_COOKIE 57
1919
+#endif
2020
#endif
21+
diff -ur -x roms -x build a/linux-user/mips/sockbits.h b/linux-user/mips/sockbits.h
22+
--- a/linux-user/mips/sockbits.h
23+
+++ b/linux-user/mips/sockbits.h
24+
@@ -73,6 +73,9 @@
25+
#define TARGET_SO_RCVBUFFORCE 33
26+
#define TARGET_SO_PASSSEC 34
27+
28+
+#define TARGET_SO_INCOMING_CPU 49
29+
+#define TARGET_SO_COOKIE 57
30+
+
31+
/** sock_type - Socket types
32+
*
33+
* Please notice that for binary compat reasons MIPS has to
2134
diff -ur -x roms -x build a/linux-user/syscall.c b/linux-user/syscall.c
2235
--- a/linux-user/syscall.c
2336
+++ b/linux-user/syscall.c

ci/pidfd-open.patch

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
From Dan Gohman <dev@sunfishcode.online>
2+
Subject: [PATCH] Fix the flags argument of `pidfd_open`.
3+
4+
This corrects the flags value of `pidfd_open` to avoid passing
5+
target flags to the host. Currently the only flag is `PIDFD_NONBLOCK`
6+
so we use the `fcntl_flags_tbl` to translate it.
7+
8+
--- a/linux-user/syscall.c
9+
+++ b/linux-user/syscall.c
10+
@@ -9477,7 +9477,8 @@
11+
#endif
12+
#if defined(__NR_pidfd_open) && defined(TARGET_NR_pidfd_open)
13+
case TARGET_NR_pidfd_open:
14+
- return get_errno(pidfd_open(arg1, arg2));
15+
+ return get_errno(pidfd_open(arg1,
16+
+ target_to_host_bitmask(arg2, fcntl_flags_tbl)));
17+
#endif
18+
#if defined(__NR_pidfd_send_signal) && defined(TARGET_NR_pidfd_send_signal)
19+
case TARGET_NR_pidfd_send_signal:

ci/tiocgsid.patch

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
From Dan Gohman <dev@sunfishcode.online>
2+
Subject: [PATCH] Fix the definition of `TIOCGSID`.
3+
4+
This corrects the value of `TIOCGSID`.
5+
6+
diff -ur a/linux-user/ioctls.h b/linux-user/ioctls.h
7+
--- a/linux-user/ioctls.h
8+
+++ b/linux-user/ioctls.h
9+
@@ -22,7 +28,7 @@
10+
IOCTL(TIOCSCTTY, 0, TYPE_INT)
11+
IOCTL(TIOCGPGRP, IOC_R, MK_PTR(TYPE_INT))
12+
IOCTL(TIOCSPGRP, IOC_W, MK_PTR(TYPE_INT))
13+
- IOCTL(TIOCGSID, IOC_W, MK_PTR(TYPE_INT))
14+
+ IOCTL(TIOCGSID, IOC_R, MK_PTR(TYPE_INT))
15+
IOCTL(TIOCOUTQ, IOC_R, MK_PTR(TYPE_INT))
16+
IOCTL(TIOCSTI, IOC_W, MK_PTR(TYPE_INT))
17+
IOCTL(TIOCMGET, IOC_R, MK_PTR(TYPE_INT))

tests/process/pidfd.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ fn test_pidfd_poll() {
7171
process::WaitId::PidFd(pidfd.as_fd()),
7272
process::WaitidOptions::EXITED,
7373
) {
74-
Err(e) if e == io::Errno::AGAIN => (),
75-
_ => panic!("unexpected result"),
74+
Err(io::Errno::AGAIN) => (),
75+
Err(e) => panic!("unexpected result: {:?}", e),
76+
Ok(_) => panic!("unexpected success"),
7677
}
7778

7879
// Wait for the child process to exit.

0 commit comments

Comments
 (0)