]> git.proxmox.com Git - cargo.git/blobdiff - vendor/libc/src/unix/linux_like/android/b32/x86/mod.rs
New upstream version 0.52.0
[cargo.git] / vendor / libc / src / unix / linux_like / android / b32 / x86 / mod.rs
index 879ea1a174d3886b91828edd9cdf7b68436e7527..6507cb4e07da3bbc59c3d2f7f753000820e0006c 100644 (file)
@@ -574,6 +574,35 @@ pub const REG_EFL: ::c_int = 16;
 pub const REG_UESP: ::c_int = 17;
 pub const REG_SS: ::c_int = 18;
 
+// socketcall values from linux/net.h (only the needed ones, and not public)
+const SYS_ACCEPT4: ::c_int = 18;
+
+f! {
+    // Sadly, Android before 5.0 (API level 21), the accept4 syscall is not
+    // exposed by the libc. As work-around, we implement it as raw syscall.
+    // Note that for x86, the `accept4` syscall is not available either,
+    // and we must use the `socketcall` syscall instead.
+    // This workaround can be removed if the minimum Android version 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 {
+        // Arguments are passed as array of `long int`
+        // (which is big enough on x86 for a pointer).
+        let mut args = [
+            fd as ::c_long,
+            addr as ::c_long,
+            len as ::c_long,
+            flg as ::c_long,
+        ];
+        ::syscall(SYS_socketcall, SYS_ACCEPT4, args[..].as_mut_ptr())
+    }
+}
+
 cfg_if! {
     if #[cfg(libc_align)] {
         mod align;