Skip to content

Implement accept4 on Android as raw syscall. #1968

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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