Skip to content

Commit

Permalink
Auto merge of #1968 - de-vri-es:accept4-old-android, r=JohnTitor
Browse files Browse the repository at this point in the history
Implement accept4 on Android as raw syscall.

This PR implements `accept4()` on Android using `syscall()` instead of the `accept4()` wrapper.

This is done because the `accept4()` wrapper wasn't added to Androids `libc` until version 5.0 (API level 21). By using `syscall` directly, `accept4` will also work on older  Android versions.

The kernel itself has supported it since Linux 2.6.28, which was shipped with stock Android since version 1.6 already: https://en.wikipedia.org/wiki/Android_version_history#Android_1.6_Donut_(API_4)

At the moment, the CI for the rust repo still uses API level 14. Although I also opened a PR to bump that too: rust-lang/rust#78601. However, it might make sense to keep the old API level in CI if this is merged.
  • Loading branch information
bors committed Nov 2, 2020
2 parents 338eebb + 5bcac36 commit 1cb2bc9
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 1cb2bc9

Please sign in to comment.