Skip to content

Commit 8d54148

Browse files
jshearerThomasdezeeuw
authored andcommitted
Use accept() instead of accept4() on x86 Android
Description in, closes #1445
1 parent 139f7c4 commit 8d54148

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

src/sys/unix/tcp.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,12 @@ pub fn accept(listener: &net::TcpListener) -> io::Result<(net::TcpStream, Socket
429429
// On platforms that support it we can use `accept4(2)` to set `NONBLOCK`
430430
// and `CLOEXEC` in the call to accept the connection.
431431
#[cfg(any(
432-
target_os = "android",
432+
// Android x86's seccomp profile forbids calls to `accept4(2)`
433+
// See https://github.com/tokio-rs/mio/issues/1445 for details
434+
all(
435+
not(target_arch="x86"),
436+
target_os = "android"
437+
),
433438
target_os = "dragonfly",
434439
target_os = "freebsd",
435440
target_os = "illumos",
@@ -450,7 +455,15 @@ pub fn accept(listener: &net::TcpListener) -> io::Result<(net::TcpStream, Socket
450455
// But not all platforms have the `accept4(2)` call. Luckily BSD (derived)
451456
// OSes inherit the non-blocking flag from the listener, so we just have to
452457
// set `CLOEXEC`.
453-
#[cfg(any(target_os = "ios", target_os = "macos", target_os = "solaris"))]
458+
#[cfg(any(
459+
all(
460+
target_arch = "x86",
461+
target_os = "android"
462+
),
463+
target_os = "ios",
464+
target_os = "macos",
465+
target_os = "solaris"
466+
))]
454467
let stream = {
455468
syscall!(accept(
456469
listener.as_raw_fd(),

src/sys/unix/uds/listener.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,13 @@ pub(crate) fn accept(listener: &net::UnixListener) -> io::Result<(UnixStream, So
4242
target_os = "ios",
4343
target_os = "macos",
4444
target_os = "netbsd",
45-
target_os = "solaris"
45+
target_os = "solaris",
46+
// Android x86's seccomp profile forbids calls to `accept4(2)`
47+
// See https://github.com/tokio-rs/mio/issues/1445 for details
48+
all(
49+
target_arch = "x86",
50+
target_os = "android"
51+
)
4652
)))]
4753
let socket = {
4854
let flags = libc::SOCK_NONBLOCK | libc::SOCK_CLOEXEC;
@@ -59,7 +65,11 @@ pub(crate) fn accept(listener: &net::UnixListener) -> io::Result<(UnixStream, So
5965
target_os = "ios",
6066
target_os = "macos",
6167
target_os = "netbsd",
62-
target_os = "solaris"
68+
target_os = "solaris",
69+
all(
70+
target_arch = "x86",
71+
target_os = "android"
72+
)
6373
))]
6474
let socket = syscall!(accept(
6575
listener.as_raw_fd(),

0 commit comments

Comments
 (0)