summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaarten de Vries <maarten@de-vri.es>2020-10-31 17:48:03 +0100
committerMaarten de Vries <maarten@de-vri.es>2020-11-03 10:17:51 +0100
commit36affa26b8ecd83e8f1fabc7107c2fdf59a0e9ea (patch)
treec72e2594939edc0b0a1994fee001f0248c3c604d
parent338eebb3022d74d5610af30ffe4277519786aec7 (diff)
downloadrust-libc-36affa26b8ecd83e8f1fabc7107c2fdf59a0e9ea.tar.gz
Implement accept4 on Android as raw syscall.
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.
-rw-r--r--src/unix/linux_like/android/mod.rs14
-rw-r--r--src/unix/linux_like/emscripten/mod.rs6
-rw-r--r--src/unix/linux_like/linux/mod.rs6
-rw-r--r--src/unix/linux_like/mod.rs6
4 files changed, 26 insertions, 6 deletions
diff --git a/src/unix/linux_like/android/mod.rs b/src/unix/linux_like/android/mod.rs
index 1240e208be..77bb6ac2de 100644
--- a/src/unix/linux_like/android/mod.rs
+++ b/src/unix/linux_like/android/mod.rs
@@ -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" {
diff --git a/src/unix/linux_like/emscripten/mod.rs b/src/unix/linux_like/emscripten/mod.rs
index 945efeea74..9599e1992f 100644
--- a/src/unix/linux_like/emscripten/mod.rs
+++ b/src/unix/linux_like/emscripten/mod.rs
@@ -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,
diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs
index 249c98bce2..90face2e95 100644
--- a/src/unix/linux_like/linux/mod.rs
+++ b/src/unix/linux_like/linux/mod.rs
@@ -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,
diff --git a/src/unix/linux_like/mod.rs b/src/unix/linux_like/mod.rs
index 80c4f5bc0b..d5299b2c38 100644
--- a/src/unix/linux_like/mod.rs
+++ b/src/unix/linux_like/mod.rs
@@ -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,