Skip to content

Commit

Permalink
Implement accept4 on Android as raw syscall.
Browse files Browse the repository at this point in the history
This avoids relying on Android 5.0 / API level 21. The Linux kernel used
by Android supports the syscall (except in truly ancient Android
versions), but the Android libc did not expose a wrapper.
  • Loading branch information
de-vri-es committed Oct 31, 2020
1 parent 4c0a7e5 commit 5bcac36
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
14 changes: 14 additions & 0 deletions src/unix/linux_like/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2349,6 +2349,20 @@ f! {
pub fn SO_EE_OFFENDER(ee: *const ::sock_extended_err) -> *mut ::sockaddr {
ee.offset(1) as *mut ::sockaddr
}

// Sadly, Android before 5.0 (API level 21), the accept4 syscall is not
// exposed by the libc. As work-around, we implement it through `syscall`
// directly. This workaround can be removed if the minimum version of
// Android is bumped. When the workaround is removed, `accept4` can be
// moved back to `linux_like/mod.rs`
pub unsafe fn accept4(
fd: ::c_int,
addr: *mut ::sockaddr,
len: *mut ::socklen_t,
flg: ::c_int,
) -> ::c_int {
syscall(SYS_accept4, fd, addr, len, flg) as ::c_int
}
}

extern "C" {
Expand Down
6 changes: 6 additions & 0 deletions src/unix/linux_like/emscripten/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1851,6 +1851,12 @@ extern "C" {
) -> ::c_int;
pub fn nl_langinfo_l(item: ::nl_item, locale: ::locale_t)
-> *mut ::c_char;
pub fn accept4(
fd: ::c_int,
addr: *mut ::sockaddr,
len: *mut ::socklen_t,
flg: ::c_int,
) -> ::c_int;
pub fn getnameinfo(
sa: *const ::sockaddr,
salen: ::socklen_t,
Expand Down
6 changes: 6 additions & 0 deletions src/unix/linux_like/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2997,6 +2997,12 @@ extern "C" {
pub fn sigwaitinfo(set: *const sigset_t, info: *mut siginfo_t) -> ::c_int;
pub fn nl_langinfo_l(item: ::nl_item, locale: ::locale_t)
-> *mut ::c_char;
pub fn accept4(
fd: ::c_int,
addr: *mut ::sockaddr,
len: *mut ::socklen_t,
flg: ::c_int,
) -> ::c_int;
pub fn getnameinfo(
sa: *const ::sockaddr,
salen: ::socklen_t,
Expand Down
6 changes: 0 additions & 6 deletions src/unix/linux_like/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1581,12 +1581,6 @@ extern "C" {
attr: *mut pthread_condattr_t,
pshared: ::c_int,
) -> ::c_int;
pub fn accept4(
fd: ::c_int,
addr: *mut ::sockaddr,
len: *mut ::socklen_t,
flg: ::c_int,
) -> ::c_int;
pub fn pthread_mutexattr_setpshared(
attr: *mut pthread_mutexattr_t,
pshared: ::c_int,
Expand Down

0 comments on commit 5bcac36

Please sign in to comment.