Skip to content

Commit 3c8fd95

Browse files
committed
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.
1 parent 4c0a7e5 commit 3c8fd95

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

src/unix/linux_like/android/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2391,6 +2391,19 @@ extern "C" {
23912391
len: ::size_t,
23922392
prot: ::c_int,
23932393
) -> ::c_int;
2394+
// Sadly, Android before 5.0 (API level 21), the accept4 syscall is not
2395+
// exposed by the libc. As work-around, we implement it through `syscall`
2396+
// directly. This workaround can be removed if the minimum version of
2397+
// Android is bumped. When the workaround is removed, `accept4` can be
2398+
// moved back to `linux_like/mod.rs`
2399+
pub unsafe fn accept4(
2400+
fd: ::c_int,
2401+
addr: *mut ::sockaddr,
2402+
len: *mut ::socklen_t,
2403+
flg: ::c_int,
2404+
) -> ::c_int {
2405+
syscall(SYS_accept4, fd, addr, len, flg) as ::c_int
2406+
}
23942407
pub fn recvfrom(
23952408
socket: ::c_int,
23962409
buf: *mut ::c_void,

src/unix/linux_like/emscripten/mod.rs

Lines changed: 6 additions & 0 deletions
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

Lines changed: 6 additions & 0 deletions
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

Lines changed: 0 additions & 6 deletions
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)