Skip to content

Commit 1cb2bc9

Browse files
committed
Auto merge of #1968 - de-vri-es:accept4-old-android, r=JohnTitor
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.
2 parents 338eebb + 5bcac36 commit 1cb2bc9

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

src/unix/linux_like/android/mod.rs

+14
Original file line numberDiff line numberDiff line change
@@ -2349,6 +2349,20 @@ f! {
23492349
pub fn SO_EE_OFFENDER(ee: *const ::sock_extended_err) -> *mut ::sockaddr {
23502350
ee.offset(1) as *mut ::sockaddr
23512351
}
2352+
2353+
// Sadly, Android before 5.0 (API level 21), the accept4 syscall is not
2354+
// exposed by the libc. As work-around, we implement it through `syscall`
2355+
// directly. This workaround can be removed if the minimum version of
2356+
// Android is bumped. When the workaround is removed, `accept4` can be
2357+
// moved back to `linux_like/mod.rs`
2358+
pub unsafe fn accept4(
2359+
fd: ::c_int,
2360+
addr: *mut ::sockaddr,
2361+
len: *mut ::socklen_t,
2362+
flg: ::c_int,
2363+
) -> ::c_int {
2364+
syscall(SYS_accept4, fd, addr, len, flg) as ::c_int
2365+
}
23522366
}
23532367

23542368
extern "C" {

src/unix/linux_like/emscripten/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1851,6 +1851,12 @@ extern "C" {
18511851
) -> ::c_int;
18521852
pub fn nl_langinfo_l(item: ::nl_item, locale: ::locale_t)
18531853
-> *mut ::c_char;
1854+
pub fn accept4(
1855+
fd: ::c_int,
1856+
addr: *mut ::sockaddr,
1857+
len: *mut ::socklen_t,
1858+
flg: ::c_int,
1859+
) -> ::c_int;
18541860
pub fn getnameinfo(
18551861
sa: *const ::sockaddr,
18561862
salen: ::socklen_t,

src/unix/linux_like/linux/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -2997,6 +2997,12 @@ extern "C" {
29972997
pub fn sigwaitinfo(set: *const sigset_t, info: *mut siginfo_t) -> ::c_int;
29982998
pub fn nl_langinfo_l(item: ::nl_item, locale: ::locale_t)
29992999
-> *mut ::c_char;
3000+
pub fn accept4(
3001+
fd: ::c_int,
3002+
addr: *mut ::sockaddr,
3003+
len: *mut ::socklen_t,
3004+
flg: ::c_int,
3005+
) -> ::c_int;
30003006
pub fn getnameinfo(
30013007
sa: *const ::sockaddr,
30023008
salen: ::socklen_t,

src/unix/linux_like/mod.rs

-6
Original file line numberDiff line numberDiff line change
@@ -1581,12 +1581,6 @@ extern "C" {
15811581
attr: *mut pthread_condattr_t,
15821582
pshared: ::c_int,
15831583
) -> ::c_int;
1584-
pub fn accept4(
1585-
fd: ::c_int,
1586-
addr: *mut ::sockaddr,
1587-
len: *mut ::socklen_t,
1588-
flg: ::c_int,
1589-
) -> ::c_int;
15901584
pub fn pthread_mutexattr_setpshared(
15911585
attr: *mut pthread_mutexattr_t,
15921586
pshared: ::c_int,

0 commit comments

Comments
 (0)