Snap for 6533464 from 3a29882427f9839c10017a4827646d3d56d4192c to sdk-release

Change-Id: I97a4e3eb79be36cd93451736951033f154820dd1
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json
index 608dc16..1e7f6c0 100644
--- a/.cargo_vcs_info.json
+++ b/.cargo_vcs_info.json
@@ -1,5 +1,5 @@
 {
   "git": {
-    "sha1": "d833b6b2d6ae19a2bf0c1c5f876e0b36c36386de"
+    "sha1": "8712132baa9c487b229ff1489859f3ea21c70432"
   }
 }
diff --git a/Android.bp b/Android.bp
index 41843b1..3c4711c 100644
--- a/Android.bp
+++ b/Android.bp
@@ -1,5 +1,52 @@
 // This file is generated by cargo2android.py.
 
+rust_test_host {
+    name: "libc_tests_const_fn",
+    crate_name: "const_fn",
+    srcs: ["tests/const_fn.rs"],
+    test_suites: ["general-tests"],
+    auto_gen_config: true,
+    edition: "2015",
+    features: [
+        "default",
+        "std",
+    ],
+    flags: [
+        "--cfg freebsd11",
+        "--cfg libc_align",
+        "--cfg libc_const_size_of",
+        "--cfg libc_core_cvoid",
+        "--cfg libc_packedN",
+        "--cfg libc_priv_mod_use",
+        "--cfg libc_union",
+    ],
+    rlibs: [
+        "liblibc",
+    ],
+}
+
+rust_test_host {
+    name: "libc_tests_libc",
+    crate_name: "libc",
+    srcs: ["src/lib.rs"],
+    test_suites: ["general-tests"],
+    auto_gen_config: true,
+    edition: "2015",
+    features: [
+        "default",
+        "std",
+    ],
+    flags: [
+        "--cfg freebsd11",
+        "--cfg libc_align",
+        "--cfg libc_const_size_of",
+        "--cfg libc_core_cvoid",
+        "--cfg libc_packedN",
+        "--cfg libc_priv_mod_use",
+        "--cfg libc_union",
+    ],
+}
+
 rust_library_rlib {
     name: "liblibc",
     host_supported: true,
diff --git a/Cargo.toml b/Cargo.toml
index d36fa77..841a824 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -12,7 +12,7 @@
 
 [package]
 name = "libc"
-version = "0.2.69"
+version = "0.2.71"
 authors = ["The Rust Project Developers"]
 build = "build.rs"
 exclude = ["/ci/*", "/azure-pipelines.yml"]
diff --git a/Cargo.toml.orig b/Cargo.toml.orig
index eeb8542..f5a0d47 100644
--- a/Cargo.toml.orig
+++ b/Cargo.toml.orig
@@ -1,6 +1,6 @@
 [package]
 name = "libc"
-version = "0.2.69"
+version = "0.2.71"
 authors = ["The Rust Project Developers"]
 license = "MIT OR Apache-2.0"
 readme = "README.md"
diff --git a/METADATA b/METADATA
index c3ccb47..3bfc011 100644
--- a/METADATA
+++ b/METADATA
@@ -9,11 +9,11 @@
     type: GIT
     value: "https://github.com/rust-lang/libc"
   }
-  version: "0.2.69"
+  version: "0.2.71"
   license_type: NOTICE
   last_upgrade_date {
     year: 2020
-    month: 4
-    day: 13
+    month: 5
+    day: 26
   }
 }
diff --git a/TEST_MAPPING b/TEST_MAPPING
new file mode 100644
index 0000000..299cdd0
--- /dev/null
+++ b/TEST_MAPPING
@@ -0,0 +1,12 @@
+{
+  "presubmit": [
+    {
+      "name": "libc_tests_const_fn",
+      "host": true
+    },
+    {
+      "name": "libc_tests_libc",
+      "host": true
+    }
+  ]
+}
diff --git a/src/lib.rs b/src/lib.rs
index 171591e..6c4cbf7 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -39,6 +39,8 @@
         #[allow(unused_imports)]
         use core::iter;
         #[allow(unused_imports)]
+        use core::ops;
+        #[allow(unused_imports)]
         use core::option;
     }
 }
@@ -115,6 +117,12 @@
 
         mod switch;
         pub use switch::*;
+    } else if #[cfg(target_os = "psp")] {
+        mod fixed_width_ints;
+        pub use fixed_width_ints::*;
+
+        mod psp;
+        pub use psp::*;
     } else if #[cfg(target_os = "vxworks")] {
         mod fixed_width_ints;
         pub use fixed_width_ints::*;
diff --git a/src/psp.rs b/src/psp.rs
new file mode 100644
index 0000000..4b3ec9b
--- /dev/null
+++ b/src/psp.rs
@@ -0,0 +1,47 @@
+//! PSP C type definitions
+
+pub type c_schar = i8;
+pub type c_uchar = u8;
+pub type c_short = i16;
+pub type c_ushort = u16;
+pub type c_int = i32;
+pub type c_uint = u32;
+pub type c_float = f32;
+pub type c_double = f64;
+pub type c_longlong = i64;
+pub type c_ulonglong = u64;
+pub type intmax_t = i64;
+pub type uintmax_t = u64;
+
+pub type size_t = usize;
+pub type ptrdiff_t = isize;
+pub type intptr_t = isize;
+pub type uintptr_t = usize;
+pub type ssize_t = isize;
+
+pub type c_char = u8;
+pub type c_long = i64;
+pub type c_ulong = u64;
+
+pub const INT_MIN: c_int = -2147483648;
+pub const INT_MAX: c_int = 2147483647;
+
+cfg_if! {
+    if #[cfg(libc_core_cvoid)] {
+        pub use ::ffi::c_void;
+    } else {
+        // Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help
+        // enable more optimization opportunities around it recognizing things
+        // like malloc/free.
+        #[repr(u8)]
+        #[allow(missing_copy_implementations)]
+        #[allow(missing_debug_implementations)]
+        pub enum c_void {
+            // Two dummy variants so the #[repr] attribute can be used.
+            #[doc(hidden)]
+            __variant1,
+            #[doc(hidden)]
+            __variant2,
+        }
+    }
+}
diff --git a/src/unix/bsd/apple/mod.rs b/src/unix/bsd/apple/mod.rs
index 485cf17..c03c644 100644
--- a/src/unix/bsd/apple/mod.rs
+++ b/src/unix/bsd/apple/mod.rs
@@ -1760,8 +1760,6 @@
 pub const TIOCSETD: ::c_ulong = 0x8004741b;
 pub const TIOCIXON: ::c_uint = 0x20007481;
 pub const TIOCIXOFF: ::c_uint = 0x20007480;
-pub const TIOCSBRK: ::c_uint = 0x2000747b;
-pub const TIOCCBRK: ::c_uint = 0x2000747a;
 pub const TIOCSDTR: ::c_uint = 0x20007479;
 pub const TIOCCDTR: ::c_uint = 0x20007478;
 pub const TIOCGPGRP: ::c_ulong = 0x40047477;
@@ -2249,14 +2247,18 @@
 pub const IP_RECVTOS: ::c_int = 27;
 pub const IPV6_JOIN_GROUP: ::c_int = 12;
 pub const IPV6_LEAVE_GROUP: ::c_int = 13;
+pub const IPV6_CHECKSUM: ::c_int = 26;
 pub const IPV6_RECVTCLASS: ::c_int = 35;
 pub const IPV6_TCLASS: ::c_int = 36;
 pub const IPV6_PKTINFO: ::c_int = 46;
+pub const IPV6_HOPLIMIT: ::c_int = 47;
 pub const IPV6_RECVPKTINFO: ::c_int = 61;
 
 pub const TCP_NOPUSH: ::c_int = 4;
 pub const TCP_NOOPT: ::c_int = 8;
 pub const TCP_KEEPALIVE: ::c_int = 0x10;
+pub const TCP_KEEPINTVL: ::c_int = 0x101;
+pub const TCP_KEEPCNT: ::c_int = 0x102;
 /// Enable/Disable TCP Fastopen on this socket
 pub const TCP_FASTOPEN: ::c_int = 0x105;
 
diff --git a/src/unix/bsd/freebsdlike/freebsd/mod.rs b/src/unix/bsd/freebsdlike/freebsd/mod.rs
index 1b714b7..db36184 100644
--- a/src/unix/bsd/freebsdlike/freebsd/mod.rs
+++ b/src/unix/bsd/freebsdlike/freebsd/mod.rs
@@ -107,6 +107,15 @@
         pub msg_hdr: ::msghdr,
         pub msg_len: ::ssize_t,
     }
+
+    pub struct sockcred {
+        pub sc_uid: ::uid_t,
+        pub sc_euid: ::uid_t,
+        pub sc_gid: ::gid_t,
+        pub sc_egid: ::gid_t,
+        pub sc_ngroups: ::c_int,
+        pub sc_groups: [::gid_t; 1],
+    }
 }
 
 s_no_extra_traits! {
@@ -340,6 +349,13 @@
 #[deprecated(since = "0.2.64", note = "Not stable across OS versions")]
 pub const RLIM_NLIMITS: ::rlim_t = 15;
 
+pub const NI_NOFQDN: ::c_int = 0x00000001;
+pub const NI_NUMERICHOST: ::c_int = 0x00000002;
+pub const NI_NAMEREQD: ::c_int = 0x00000004;
+pub const NI_NUMERICSERV: ::c_int = 0x00000008;
+pub const NI_DGRAM: ::c_int = 0x00000010;
+pub const NI_NUMERICSCOPE: ::c_int = 0x00000020;
+
 pub const Q_GETQUOTA: ::c_int = 0x700;
 pub const Q_SETQUOTA: ::c_int = 0x800;
 
@@ -1136,6 +1152,15 @@
             as ::c_uint
     }
 
+    pub fn SOCKCREDSIZE(ngrps: usize) -> usize {
+        let ngrps = if ngrps > 0 {
+            ngrps - 1
+        } else {
+            0
+        };
+        ::mem::size_of::<sockcred>() + ::mem::size_of::<::gid_t>() * ngrps
+    }
+
     pub fn uname(buf: *mut ::utsname) -> ::c_int {
         __xuname(256, buf as *mut ::c_void)
     }
diff --git a/src/unix/bsd/freebsdlike/mod.rs b/src/unix/bsd/freebsdlike/mod.rs
index 509bf8c..44457c3 100644
--- a/src/unix/bsd/freebsdlike/mod.rs
+++ b/src/unix/bsd/freebsdlike/mod.rs
@@ -738,6 +738,7 @@
 pub const MSG_EOF: ::c_int = 0x00000100;
 
 pub const SCM_TIMESTAMP: ::c_int = 0x02;
+pub const SCM_CREDS: ::c_int = 0x03;
 
 pub const SOCK_STREAM: ::c_int = 1;
 pub const SOCK_DGRAM: ::c_int = 2;
@@ -756,8 +757,10 @@
 pub const IP_RECVIF: ::c_int = 20;
 pub const IPV6_JOIN_GROUP: ::c_int = 12;
 pub const IPV6_LEAVE_GROUP: ::c_int = 13;
+pub const IPV6_CHECKSUM: ::c_int = 26;
 pub const IPV6_RECVPKTINFO: ::c_int = 36;
 pub const IPV6_PKTINFO: ::c_int = 46;
+pub const IPV6_HOPLIMIT: ::c_int = 47;
 pub const IPV6_RECVTCLASS: ::c_int = 57;
 pub const IPV6_TCLASS: ::c_int = 61;
 
@@ -1042,8 +1045,6 @@
 pub const TIOCGPGRP: ::c_uint = 0x40047477;
 pub const TIOCCDTR: ::c_uint = 0x20007478;
 pub const TIOCSDTR: ::c_uint = 0x20007479;
-pub const TIOCCBRK: ::c_uint = 0x2000747a;
-pub const TIOCSBRK: ::c_uint = 0x2000747b;
 pub const TTYDISC: ::c_int = 0x0;
 pub const SLIPDISC: ::c_int = 0x4;
 pub const PPPDISC: ::c_int = 0x5;
diff --git a/src/unix/bsd/mod.rs b/src/unix/bsd/mod.rs
index a421458..a70c1d9 100644
--- a/src/unix/bsd/mod.rs
+++ b/src/unix/bsd/mod.rs
@@ -498,6 +498,13 @@
 pub const REG_LARGE: ::c_int = 0o01000;
 pub const REG_BACKR: ::c_int = 0o02000;
 
+pub const TIOCCBRK: ::c_uint = 0x2000747a;
+pub const TIOCSBRK: ::c_uint = 0x2000747b;
+
+pub const PRIO_PROCESS: ::c_int = 0;
+pub const PRIO_PGRP: ::c_int = 1;
+pub const PRIO_USER: ::c_int = 2;
+
 f! {
     pub fn CMSG_FIRSTHDR(mhdr: *const ::msghdr) -> *mut ::cmsghdr {
         if (*mhdr).msg_controllen as usize >= ::mem::size_of::<::cmsghdr>() {
diff --git a/src/unix/bsd/netbsdlike/mod.rs b/src/unix/bsd/netbsdlike/mod.rs
index 0441a0f..976b95c 100644
--- a/src/unix/bsd/netbsdlike/mod.rs
+++ b/src/unix/bsd/netbsdlike/mod.rs
@@ -621,8 +621,6 @@
 
 pub const TIMER_ABSTIME: ::c_int = 1;
 
-pub const REG_ENOSYS: ::c_int = 17;
-
 #[link(name = "util")]
 extern "C" {
     pub fn setgrent();
diff --git a/src/unix/bsd/netbsdlike/netbsd/mod.rs b/src/unix/bsd/netbsdlike/netbsd/mod.rs
index 09dfb22..8b3ce3e 100644
--- a/src/unix/bsd/netbsdlike/netbsd/mod.rs
+++ b/src/unix/bsd/netbsdlike/netbsd/mod.rs
@@ -1646,6 +1646,8 @@
 
 pub const SIGSTKSZ: ::size_t = 40960;
 
+pub const REG_ENOSYS: ::c_int = 17;
+
 pub const PT_DUMPCORE: ::c_int = 12;
 pub const PT_LWPINFO: ::c_int = 13;
 pub const PT_SYSCALL: ::c_int = 14;
diff --git a/src/unix/bsd/netbsdlike/openbsd/mod.rs b/src/unix/bsd/netbsdlike/openbsd/mod.rs
index f77a424..47a5585 100644
--- a/src/unix/bsd/netbsdlike/openbsd/mod.rs
+++ b/src/unix/bsd/netbsdlike/openbsd/mod.rs
@@ -1150,12 +1150,14 @@
 pub const KERN_OSVERSION: ::c_int = 27;
 pub const KERN_SOMAXCONN: ::c_int = 28;
 pub const KERN_SOMINCONN: ::c_int = 29;
+#[deprecated(since = "0.2.71", note = "Removed in OpenBSD 6.0")]
 pub const KERN_USERMOUNT: ::c_int = 30;
 pub const KERN_NOSUIDCOREDUMP: ::c_int = 32;
 pub const KERN_FSYNC: ::c_int = 33;
 pub const KERN_SYSVMSG: ::c_int = 34;
 pub const KERN_SYSVSEM: ::c_int = 35;
 pub const KERN_SYSVSHM: ::c_int = 36;
+#[deprecated(since = "0.2.71", note = "Removed in OpenBSD 6.0")]
 pub const KERN_ARND: ::c_int = 37;
 pub const KERN_MSGBUFSIZE: ::c_int = 38;
 pub const KERN_MALLOCSTATS: ::c_int = 39;
diff --git a/src/unix/haiku/mod.rs b/src/unix/haiku/mod.rs
index 970efb3..e7b104e 100644
--- a/src/unix/haiku/mod.rs
+++ b/src/unix/haiku/mod.rs
@@ -790,7 +790,7 @@
 pub const IFF_CONFIGURING: ::c_int = 0x4000;
 pub const IFF_MULTICAST: ::c_int = 0x8000; // supports multicast
 
-pub const AF_UNSEC: ::c_int = 0;
+pub const AF_UNSPEC: ::c_int = 0;
 pub const AF_INET: ::c_int = 1;
 pub const AF_APPLETALK: ::c_int = 2;
 pub const AF_ROUTE: ::c_int = 3;
@@ -1206,6 +1206,10 @@
 pub const TIOCMBIS: ::c_int = TCGETA + 22;
 pub const TIOCMBIC: ::c_int = TCGETA + 23;
 
+pub const PRIO_PROCESS: ::c_int = 0;
+pub const PRIO_PGRP: ::c_int = 1;
+pub const PRIO_USER: ::c_int = 2;
+
 f! {
     pub fn FD_CLR(fd: ::c_int, set: *mut fd_set) -> () {
         let fd = fd as usize;
diff --git a/src/unix/hermit/mod.rs b/src/unix/hermit/mod.rs
index 66ee653..ae3fa22 100644
--- a/src/unix/hermit/mod.rs
+++ b/src/unix/hermit/mod.rs
@@ -939,6 +939,10 @@
 
 pub const WNOHANG: ::c_int = 0x00000001;
 
+pub const PRIO_PROCESS: ::c_int = 0;
+pub const PRIO_PGRP: ::c_int = 1;
+pub const PRIO_USER: ::c_int = 2;
+
 f! {
     pub fn WEXITSTATUS(status: ::c_int) -> ::c_int {
         (status >> 8) & 0xff
diff --git a/src/unix/linux_like/android/mod.rs b/src/unix/linux_like/android/mod.rs
index 8a41911..9cc1c77 100644
--- a/src/unix/linux_like/android/mod.rs
+++ b/src/unix/linux_like/android/mod.rs
@@ -1116,6 +1116,11 @@
 pub const RLIMIT_DATA: ::c_int = 2;
 pub const RLIMIT_STACK: ::c_int = 3;
 pub const RLIMIT_CORE: ::c_int = 4;
+pub const RLIMIT_RSS: ::c_int = 5;
+pub const RLIMIT_NPROC: ::c_int = 6;
+pub const RLIMIT_NOFILE: ::c_int = 7;
+pub const RLIMIT_MEMLOCK: ::c_int = 8;
+pub const RLIMIT_AS: ::c_int = 9;
 pub const RLIMIT_LOCKS: ::c_int = 10;
 pub const RLIMIT_SIGPENDING: ::c_int = 11;
 pub const RLIMIT_MSGQUEUE: ::c_int = 12;
@@ -1155,6 +1160,8 @@
 pub const TIOCMSET: ::c_int = 0x5418;
 pub const FIONREAD: ::c_int = 0x541B;
 pub const TIOCCONS: ::c_int = 0x541D;
+pub const TIOCSBRK: ::c_int = 0x5427;
+pub const TIOCCBRK: ::c_int = 0x5428;
 
 pub const ST_RDONLY: ::c_ulong = 1;
 pub const ST_NOSUID: ::c_ulong = 2;
@@ -2137,6 +2144,10 @@
 pub const ERANGE: ::c_int = 34;
 pub const EWOULDBLOCK: ::c_int = EAGAIN;
 
+pub const PRIO_PROCESS: ::c_int = 0;
+pub const PRIO_PGRP: ::c_int = 1;
+pub const PRIO_USER: ::c_int = 2;
+
 f! {
     pub fn CMSG_NXTHDR(mhdr: *const msghdr,
                        cmsg: *const cmsghdr) -> *mut cmsghdr {
diff --git a/src/unix/linux_like/emscripten/mod.rs b/src/unix/linux_like/emscripten/mod.rs
index ead0ea1..7817021 100644
--- a/src/unix/linux_like/emscripten/mod.rs
+++ b/src/unix/linux_like/emscripten/mod.rs
@@ -1680,6 +1680,10 @@
 pub const ARPD_FLUSH: ::c_ushort = 0x03;
 pub const ATF_MAGIC: ::c_int = 0x80;
 
+pub const PRIO_PROCESS: ::c_int = 0;
+pub const PRIO_PGRP: ::c_int = 1;
+pub const PRIO_USER: ::c_int = 2;
+
 f! {
     pub fn CMSG_NXTHDR(mhdr: *const msghdr,
                        cmsg: *const cmsghdr) -> *mut cmsghdr {
diff --git a/src/unix/linux_like/linux/gnu/b32/mod.rs b/src/unix/linux_like/linux/gnu/b32/mod.rs
index ab8d943..2eab8dd 100644
--- a/src/unix/linux_like/linux/gnu/b32/mod.rs
+++ b/src/unix/linux_like/linux/gnu/b32/mod.rs
@@ -241,6 +241,9 @@
 pub const PTRACE_GETREGS: ::c_uint = 12;
 pub const PTRACE_SETREGS: ::c_uint = 13;
 
+pub const TIOCSBRK: ::c_int = 0x5427;
+pub const TIOCCBRK: ::c_int = 0x5428;
+
 #[link(name = "util")]
 extern "C" {
     pub fn sysctl(
diff --git a/src/unix/linux_like/linux/gnu/b32/x86/mod.rs b/src/unix/linux_like/linux/gnu/b32/x86/mod.rs
index 1d29ac2..b1d306c 100644
--- a/src/unix/linux_like/linux/gnu/b32/x86/mod.rs
+++ b/src/unix/linux_like/linux/gnu/b32/x86/mod.rs
@@ -543,6 +543,8 @@
 
 pub const PTRACE_GETFPXREGS: ::c_uint = 18;
 pub const PTRACE_SETFPXREGS: ::c_uint = 19;
+pub const PTRACE_SYSEMU: ::c_uint = 31;
+pub const PTRACE_SYSEMU_SINGLESTEP: ::c_uint = 32;
 
 pub const MCL_CURRENT: ::c_int = 0x0001;
 pub const MCL_FUTURE: ::c_int = 0x0002;
diff --git a/src/unix/linux_like/linux/gnu/b64/aarch64/mod.rs b/src/unix/linux_like/linux/gnu/b64/aarch64/mod.rs
index bf2e1c9..2c2f568 100644
--- a/src/unix/linux_like/linux/gnu/b64/aarch64/mod.rs
+++ b/src/unix/linux_like/linux/gnu/b64/aarch64/mod.rs
@@ -212,11 +212,6 @@
 pub const RTLD_GLOBAL: ::c_int = 0x100;
 pub const RTLD_NOLOAD: ::c_int = 0x4;
 
-pub const TIOCGSOFTCAR: ::c_ulong = 0x5419;
-pub const TIOCSSOFTCAR: ::c_ulong = 0x541A;
-pub const TIOCGRS485: ::c_int = 0x542E;
-pub const TIOCSRS485: ::c_int = 0x542F;
-
 pub const RLIMIT_RSS: ::__rlimit_resource_t = 5;
 pub const RLIMIT_AS: ::__rlimit_resource_t = 9;
 pub const RLIMIT_MEMLOCK: ::__rlimit_resource_t = 8;
@@ -447,7 +442,13 @@
 pub const TIOCMBIS: ::c_ulong = 0x5416;
 pub const TIOCMBIC: ::c_ulong = 0x5417;
 pub const TIOCMSET: ::c_ulong = 0x5418;
+pub const TIOCGSOFTCAR: ::c_ulong = 0x5419;
+pub const TIOCSSOFTCAR: ::c_ulong = 0x541A;
 pub const TIOCCONS: ::c_ulong = 0x541D;
+pub const TIOCSBRK: ::c_ulong = 0x5427;
+pub const TIOCCBRK: ::c_ulong = 0x5428;
+pub const TIOCGRS485: ::c_int = 0x542E;
+pub const TIOCSRS485: ::c_int = 0x542F;
 
 pub const TIOCM_ST: ::c_int = 0x008;
 pub const TIOCM_SR: ::c_int = 0x010;
diff --git a/src/unix/linux_like/linux/gnu/b64/mips64/mod.rs b/src/unix/linux_like/linux/gnu/b64/mips64/mod.rs
index d27ebc9..2e0d78e 100644
--- a/src/unix/linux_like/linux/gnu/b64/mips64/mod.rs
+++ b/src/unix/linux_like/linux/gnu/b64/mips64/mod.rs
@@ -874,6 +874,8 @@
 pub const TCSBRK: ::c_ulong = 0x5405;
 pub const TCXONC: ::c_ulong = 0x5406;
 pub const TCFLSH: ::c_ulong = 0x5407;
+pub const TIOCSBRK: ::c_ulong = 0x5427;
+pub const TIOCCBRK: ::c_ulong = 0x5428;
 pub const TIOCGSOFTCAR: ::c_ulong = 0x5481;
 pub const TIOCSSOFTCAR: ::c_ulong = 0x5482;
 pub const TIOCINQ: ::c_ulong = 0x467f;
diff --git a/src/unix/linux_like/linux/gnu/b64/powerpc64/mod.rs b/src/unix/linux_like/linux/gnu/b64/powerpc64/mod.rs
index d77c6fa..9cf0b21 100644
--- a/src/unix/linux_like/linux/gnu/b64/powerpc64/mod.rs
+++ b/src/unix/linux_like/linux/gnu/b64/powerpc64/mod.rs
@@ -441,6 +441,8 @@
 pub const TIOCMBIC: ::c_ulong = 0x5417;
 pub const TIOCMSET: ::c_ulong = 0x5418;
 pub const TIOCCONS: ::c_ulong = 0x541D;
+pub const TIOCSBRK: ::c_ulong = 0x5427;
+pub const TIOCCBRK: ::c_ulong = 0x5428;
 pub const TIOCGRS485: ::c_int = 0x542E;
 pub const TIOCSRS485: ::c_int = 0x542F;
 
diff --git a/src/unix/linux_like/linux/gnu/b64/riscv64/mod.rs b/src/unix/linux_like/linux/gnu/b64/riscv64/mod.rs
index 047505f..9fa0f0a 100644
--- a/src/unix/linux_like/linux/gnu/b64/riscv64/mod.rs
+++ b/src/unix/linux_like/linux/gnu/b64/riscv64/mod.rs
@@ -4,23 +4,10 @@
 pub type c_long = i64;
 pub type c_ulong = u64;
 pub type wchar_t = ::c_int;
-pub type time_t = ::c_long;
 
-pub type dev_t = ::c_ulong;
-pub type uid_t = ::c_uint;
-pub type gid_t = ::c_uint;
-pub type ino_t = ::c_ulong;
-pub type ino64_t = ::c_ulong;
-pub type mode_t = ::c_uint;
 pub type nlink_t = ::c_uint;
-pub type off_t = ::c_long;
-pub type off64_t = ::c_long;
-pub type pid_t = ::c_int;
 pub type blksize_t = ::c_int;
-pub type blkcnt_t = ::c_long;
-pub type fsblkcnt_t = ::c_ulong;
 pub type fsblkcnt64_t = ::c_ulong;
-pub type fsfilcnt_t = ::c_ulong;
 pub type fsfilcnt64_t = ::c_ulong;
 pub type suseconds_t = i64;
 pub type __u64 = ::c_ulonglong;
@@ -30,63 +17,58 @@
         __size: [::c_ulong; 7],
     }
 
-    pub struct timespec {
-        pub tv_sec: time_t,
-        pub tv_nsec: ::c_long,
-    }
-
     pub struct stat {
-        pub st_dev: dev_t,
-        pub st_ino: ino_t,
-        pub st_mode: mode_t,
-        pub st_nlink: nlink_t,
-        pub st_uid: uid_t,
-        pub st_gid: gid_t,
-        pub st_rdev: dev_t,
-        pub __pad1: dev_t,
-        pub st_size: off_t,
-        pub st_blksize: blksize_t,
+        pub st_dev: ::dev_t,
+        pub st_ino: ::ino_t,
+        pub st_mode: ::mode_t,
+        pub st_nlink: ::nlink_t,
+        pub st_uid: ::uid_t,
+        pub st_gid: ::gid_t,
+        pub st_rdev: ::dev_t,
+        pub __pad1: ::dev_t,
+        pub st_size: ::off_t,
+        pub st_blksize: ::blksize_t,
         pub __pad2: ::c_int,
-        pub st_blocks: blkcnt_t,
-        pub st_atime: time_t,
+        pub st_blocks: ::blkcnt_t,
+        pub st_atime: ::time_t,
         pub st_atime_nsec: ::c_long,
-        pub st_mtime: time_t,
+        pub st_mtime: ::time_t,
         pub st_mtime_nsec: ::c_long,
-        pub st_ctime: time_t,
+        pub st_ctime: ::time_t,
         pub st_ctime_nsec: ::c_long,
-        pub __unused: [::c_int; 2usize],
+        __unused: [::c_int; 2usize],
     }
 
     pub struct stat64 {
-        pub st_dev: dev_t,
-        pub st_ino: ino64_t,
-        pub st_mode: mode_t,
-        pub st_nlink: nlink_t,
-        pub st_uid: uid_t,
-        pub st_gid: gid_t,
-        pub st_rdev: dev_t,
-        pub __pad1: dev_t,
-        pub st_size: off64_t,
-        pub st_blksize: blksize_t,
+        pub st_dev: ::dev_t,
+        pub st_ino: ::ino64_t,
+        pub st_mode: ::mode_t,
+        pub st_nlink: ::nlink_t,
+        pub st_uid: ::uid_t,
+        pub st_gid: ::gid_t,
+        pub st_rdev: ::dev_t,
+        pub __pad1: ::dev_t,
+        pub st_size: ::off64_t,
+        pub st_blksize: ::blksize_t,
         pub __pad2: ::c_int,
-        pub st_blocks: blkcnt_t,
-        pub st_atime: time_t,
+        pub st_blocks: ::blkcnt_t,
+        pub st_atime: ::time_t,
         pub st_atime_nsec: ::c_long,
-        pub st_mtime: time_t,
+        pub st_mtime: ::time_t,
         pub st_mtime_nsec: ::c_long,
-        pub st_ctime: time_t,
+        pub st_ctime: ::time_t,
         pub st_ctime_nsec: ::c_long,
-        pub __unused: [::c_int; 2],
+        __unused: [::c_int; 2],
     }
 
     pub struct statfs {
         pub f_type: ::c_long,
         pub f_bsize: ::c_long,
-        pub f_blocks: fsblkcnt_t,
-        pub f_bfree: fsblkcnt_t,
-        pub f_bavail: fsblkcnt_t,
-        pub f_files: fsfilcnt_t,
-        pub f_ffree: fsfilcnt_t,
+        pub f_blocks: ::fsblkcnt_t,
+        pub f_bfree: ::fsblkcnt_t,
+        pub f_bavail: ::fsblkcnt_t,
+        pub f_files: ::fsfilcnt_t,
+        pub f_ffree: ::fsfilcnt_t,
         pub f_fsid: ::fsid_t,
         pub f_namelen: ::c_long,
         pub f_frsize: ::c_long,
@@ -97,11 +79,11 @@
     pub struct statfs64 {
         pub f_type: ::c_long,
         pub f_bsize: ::c_long,
-        pub f_blocks: fsblkcnt64_t,
-        pub f_bfree: fsblkcnt64_t,
-        pub f_bavail: fsblkcnt64_t,
-        pub f_files: fsfilcnt64_t,
-        pub f_ffree: fsfilcnt64_t,
+        pub f_blocks: ::fsblkcnt64_t,
+        pub f_bfree: ::fsblkcnt64_t,
+        pub f_bavail: ::fsblkcnt64_t,
+        pub f_files: ::fsfilcnt64_t,
+        pub f_ffree: ::fsfilcnt64_t,
         pub f_fsid: ::fsid_t,
         pub f_namelen: ::c_long,
         pub f_frsize: ::c_long,
@@ -112,12 +94,12 @@
     pub struct statvfs {
         pub f_bsize: ::c_ulong,
         pub f_frsize: ::c_ulong,
-        pub f_blocks: fsblkcnt_t,
-        pub f_bfree: fsblkcnt_t,
-        pub f_bavail: fsblkcnt_t,
-        pub f_files: fsfilcnt_t,
-        pub f_ffree: fsfilcnt_t,
-        pub f_favail: fsfilcnt_t,
+        pub f_blocks: ::fsblkcnt_t,
+        pub f_bfree: ::fsblkcnt_t,
+        pub f_bavail: ::fsblkcnt_t,
+        pub f_files: ::fsfilcnt_t,
+        pub f_ffree: ::fsfilcnt_t,
+        pub f_favail: ::fsfilcnt_t,
         pub f_fsid: ::c_ulong,
         pub f_flag: ::c_ulong,
         pub f_namemax: ::c_ulong,
@@ -127,12 +109,12 @@
     pub struct statvfs64 {
         pub f_bsize: ::c_ulong,
         pub f_frsize: ::c_ulong,
-        pub f_blocks: fsblkcnt64_t,
-        pub f_bfree: fsblkcnt64_t,
-        pub f_bavail: fsblkcnt64_t,
-        pub f_files: fsfilcnt64_t,
-        pub f_ffree: fsfilcnt64_t,
-        pub f_favail: fsfilcnt64_t,
+        pub f_blocks: ::fsblkcnt64_t,
+        pub f_bfree: ::fsblkcnt64_t,
+        pub f_bavail: ::fsblkcnt64_t,
+        pub f_files: ::fsfilcnt64_t,
+        pub f_ffree: ::fsfilcnt64_t,
+        pub f_favail: ::fsfilcnt64_t,
         pub f_fsid: ::c_ulong,
         pub f_flag: ::c_ulong,
         pub f_namemax: ::c_ulong,
@@ -167,35 +149,31 @@
         pub sa_restorer: ::Option<unsafe extern "C" fn()>,
     }
 
-    pub struct sigset_t {
-        pub __val: [::c_ulong; 16],
-    }
-
     pub struct ipc_perm {
         pub __key: ::key_t,
-        pub uid: uid_t,
-        pub gid: gid_t,
-        pub cuid: uid_t,
-        pub cgid: gid_t,
+        pub uid: ::uid_t,
+        pub gid: ::gid_t,
+        pub cuid: ::uid_t,
+        pub cgid: ::gid_t,
         pub mode: ::c_ushort,
-        pub __pad1: ::c_ushort,
+        __pad1: ::c_ushort,
         pub __seq: ::c_ushort,
-        pub __pad2: ::c_ushort,
-        pub __unused1: ::c_ulong,
-        pub __unused2: ::c_ulong,
+        __pad2: ::c_ushort,
+        __unused1: ::c_ulong,
+        __unused2: ::c_ulong,
     }
 
     pub struct shmid_ds {
-        pub shm_perm: ipc_perm,
+        pub shm_perm: ::ipc_perm,
         pub shm_segsz: ::size_t,
-        pub shm_atime: time_t,
-        pub shm_dtime: time_t,
-        pub shm_ctime: time_t,
-        pub shm_cpid: pid_t,
-        pub shm_lpid: pid_t,
+        pub shm_atime: ::time_t,
+        pub shm_dtime: ::time_t,
+        pub shm_ctime: ::time_t,
+        pub shm_cpid: ::pid_t,
+        pub shm_lpid: ::pid_t,
         pub shm_nattch: ::shmatt_t,
-        pub __unused5: ::c_ulong,
-        pub __unused6: ::c_ulong,
+        __unused5: ::c_ulong,
+        __unused6: ::c_ulong,
     }
 
     pub struct flock {
@@ -225,6 +203,11 @@
 pub const TIOCSSOFTCAR: ::c_ulong = 21530;
 pub const TIOCGRS485: ::c_int = 21550;
 pub const TIOCSRS485: ::c_int = 21551;
+pub const RLIMIT_RSS: ::__rlimit_resource_t = 5;
+pub const RLIMIT_AS: ::__rlimit_resource_t = 9;
+pub const RLIMIT_MEMLOCK: ::__rlimit_resource_t = 8;
+pub const RLIMIT_NOFILE: ::__rlimit_resource_t = 7;
+pub const RLIMIT_NPROC: ::__rlimit_resource_t = 6;
 pub const O_APPEND: ::c_int = 1024;
 pub const O_CREAT: ::c_int = 64;
 pub const O_EXCL: ::c_int = 128;
diff --git a/src/unix/linux_like/linux/gnu/b64/s390x.rs b/src/unix/linux_like/linux/gnu/b64/s390x.rs
index e2f3b9b..906a44a 100644
--- a/src/unix/linux_like/linux/gnu/b64/s390x.rs
+++ b/src/unix/linux_like/linux/gnu/b64/s390x.rs
@@ -575,6 +575,8 @@
 pub const TIOCMSET: ::c_ulong = 0x5418;
 pub const FIONREAD: ::c_ulong = 0x541B;
 pub const TIOCCONS: ::c_ulong = 0x541D;
+pub const TIOCSBRK: ::c_ulong = 0x5427;
+pub const TIOCCBRK: ::c_ulong = 0x5428;
 
 pub const TCSANOW: ::c_int = 0;
 pub const TCSADRAIN: ::c_int = 1;
diff --git a/src/unix/linux_like/linux/gnu/b64/sparc64/mod.rs b/src/unix/linux_like/linux/gnu/b64/sparc64/mod.rs
index 3e08ebe..e7d6239 100644
--- a/src/unix/linux_like/linux/gnu/b64/sparc64/mod.rs
+++ b/src/unix/linux_like/linux/gnu/b64/sparc64/mod.rs
@@ -416,13 +416,15 @@
 pub const TIOCGSERIAL: ::c_ulong = 0x541E;
 pub const TIOCEXCL: ::c_ulong = 0x2000740d;
 pub const TIOCNXCL: ::c_ulong = 0x2000740e;
-pub const TIOCSCTTY: ::c_ulong = 0x20007484;
-pub const TIOCSTI: ::c_ulong = 0x80017472;
-pub const TIOCMGET: ::c_ulong = 0x4004746a;
-pub const TIOCMBIS: ::c_ulong = 0x8004746c;
-pub const TIOCMBIC: ::c_ulong = 0x8004746b;
-pub const TIOCMSET: ::c_ulong = 0x8004746d;
 pub const TIOCCONS: ::c_ulong = 0x20007424;
+pub const TIOCMGET: ::c_ulong = 0x4004746a;
+pub const TIOCMBIC: ::c_ulong = 0x8004746b;
+pub const TIOCMBIS: ::c_ulong = 0x8004746c;
+pub const TIOCMSET: ::c_ulong = 0x8004746d;
+pub const TIOCSTI: ::c_ulong = 0x80017472;
+pub const TIOCCBRK: ::c_ulong = 0x2000747a;
+pub const TIOCSBRK: ::c_ulong = 0x2000747b;
+pub const TIOCSCTTY: ::c_ulong = 0x20007484;
 
 pub const TIOCM_ST: ::c_int = 0x008;
 pub const TIOCM_SR: ::c_int = 0x010;
diff --git a/src/unix/linux_like/linux/gnu/b64/x86_64/mod.rs b/src/unix/linux_like/linux/gnu/b64/x86_64/mod.rs
index 4f53138..f48d659 100644
--- a/src/unix/linux_like/linux/gnu/b64/x86_64/mod.rs
+++ b/src/unix/linux_like/linux/gnu/b64/x86_64/mod.rs
@@ -721,6 +721,8 @@
 pub const PTRACE_GETREGS: ::c_uint = 12;
 pub const PTRACE_SETREGS: ::c_uint = 13;
 pub const PTRACE_PEEKSIGINFO_SHARED: ::c_uint = 1;
+pub const PTRACE_SYSEMU: ::c_uint = 31;
+pub const PTRACE_SYSEMU_SINGLESTEP: ::c_uint = 32;
 
 pub const MCL_CURRENT: ::c_int = 0x0001;
 pub const MCL_FUTURE: ::c_int = 0x0002;
@@ -839,6 +841,8 @@
 pub const TIOCGWINSZ: ::c_ulong = 0x5413;
 pub const TIOCSWINSZ: ::c_ulong = 0x5414;
 pub const FIONREAD: ::c_ulong = 0x541B;
+pub const TIOCSBRK: ::c_ulong = 0x5427;
+pub const TIOCCBRK: ::c_ulong = 0x5428;
 
 // offsets in user_regs_structs, from sys/reg.h
 pub const R15: ::c_int = 0;
diff --git a/src/unix/linux_like/linux/gnu/mod.rs b/src/unix/linux_like/linux/gnu/mod.rs
index 7c8208e..da9890e 100644
--- a/src/unix/linux_like/linux/gnu/mod.rs
+++ b/src/unix/linux_like/linux/gnu/mod.rs
@@ -465,6 +465,10 @@
 pub const RLIMIT_RTTIME: ::__rlimit_resource_t = 15;
 pub const RLIMIT_NLIMITS: ::__rlimit_resource_t = 16;
 
+pub const PRIO_PROCESS: ::__priority_which_t = 0;
+pub const PRIO_PGRP: ::__priority_which_t = 1;
+pub const PRIO_USER: ::__priority_which_t = 2;
+
 pub const MS_RMT_MASK: ::c_ulong = 0x02800051;
 
 pub const __UT_LINESIZE: usize = 32;
diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs
index 1879eec..27d5ab2 100644
--- a/src/unix/linux_like/linux/mod.rs
+++ b/src/unix/linux_like/linux/mod.rs
@@ -2620,6 +2620,12 @@
         }
     }
 
+    pub fn CPU_ALLOC_SIZE(count: ::c_int) -> ::size_t {
+        let _dummy: cpu_set_t = ::mem::zeroed();
+        let size_in_bits = 8 * ::mem::size_of_val(&_dummy.bits[0]);
+        ((count as ::size_t + size_in_bits - 1) / 8) as ::size_t
+    }
+
     pub fn CPU_ZERO(cpuset: &mut cpu_set_t) -> () {
         for slot in cpuset.bits.iter_mut() {
             *slot = 0;
@@ -2648,6 +2654,19 @@
         0 != (cpuset.bits[idx] & (1 << offset))
     }
 
+    pub fn CPU_COUNT_S(size: usize, cpuset: &cpu_set_t) -> ::c_int {
+        let mut s: u32 = 0;
+        let size_of_mask = ::mem::size_of_val(&cpuset.bits[0]);
+        for i in cpuset.bits[..(size / size_of_mask)].iter() {
+            s += i.count_ones();
+        };
+        s as ::c_int
+    }
+
+    pub fn CPU_COUNT(cpuset: &cpu_set_t) -> ::c_int {
+        CPU_COUNT_S(::mem::size_of::<cpu_set_t>(), cpuset)
+    }
+
     pub fn CPU_EQUAL(set1: &cpu_set_t, set2: &cpu_set_t) -> bool {
         set1.bits == set2.bits
     }
diff --git a/src/unix/linux_like/linux/musl/b32/hexagon.rs b/src/unix/linux_like/linux/musl/b32/hexagon.rs
index 4a89679..8124e4b 100644
--- a/src/unix/linux_like/linux/musl/b32/hexagon.rs
+++ b/src/unix/linux_like/linux/musl/b32/hexagon.rs
@@ -725,7 +725,6 @@
 pub const TCSETXF: ::c_int = 21556;
 pub const TCSETXW: ::c_int = 21557;
 pub const TCXONC: ::c_int = 21514;
-pub const TIOCCBRK: ::c_int = 21544;
 pub const TIOCCONS: ::c_int = 21533;
 pub const TIOCEXCL: ::c_int = 21516;
 pub const TIOCGETD: ::c_int = 21540;
@@ -769,7 +768,6 @@
 pub const TIOCPKT_NOSTOP: ::c_int = 16;
 pub const TIOCPKT_START: ::c_int = 8;
 pub const TIOCPKT_STOP: ::c_int = 4;
-pub const TIOCSBRK: ::c_int = 21543;
 pub const TIOCSCTTY: ::c_int = 21518;
 pub const TIOCSERCONFIG: ::c_int = 21587;
 pub const TIOCSERGETLSR: ::c_int = 21593;
diff --git a/src/unix/linux_like/linux/musl/mod.rs b/src/unix/linux_like/linux/musl/mod.rs
index fda4720..b251383 100644
--- a/src/unix/linux_like/linux/musl/mod.rs
+++ b/src/unix/linux_like/linux/musl/mod.rs
@@ -117,6 +117,27 @@
         __nsub2: ::size_t,
         __padding2: ::c_char,
     }
+
+    pub struct rtentry {
+        pub rt_pad1: ::c_ulong,
+        pub rt_dst: ::sockaddr,
+        pub rt_gateway: ::sockaddr,
+        pub rt_genmask: ::sockaddr,
+        pub rt_flags: ::c_ushort,
+        pub rt_pad2: ::c_short,
+        pub rt_pad3: ::c_ulong,
+        pub rt_tos: ::c_uchar,
+        pub rt_class: ::c_uchar,
+        #[cfg(target_pointer_width = "64")]
+        pub rt_pad4: [::c_short; 3usize],
+        #[cfg(not(target_pointer_width = "64"))]
+        pub rt_pad4: [::c_short; 1usize],
+        pub rt_metric: ::c_short,
+        pub rt_dev: *mut ::c_char,
+        pub rt_mtu: ::c_ulong,
+        pub rt_window: ::c_ulong,
+        pub rt_irtt: ::c_ushort,
+    }
 }
 
 s_no_extra_traits! {
@@ -401,6 +422,13 @@
 
 pub const REG_OK: ::c_int = 0;
 
+pub const TIOCSBRK: ::c_int = 0x5427;
+pub const TIOCCBRK: ::c_int = 0x5428;
+
+pub const PRIO_PROCESS: ::c_int = 0;
+pub const PRIO_PGRP: ::c_int = 1;
+pub const PRIO_USER: ::c_int = 2;
+
 extern "C" {
     pub fn sendmmsg(
         sockfd: ::c_int,
diff --git a/src/unix/linux_like/mod.rs b/src/unix/linux_like/mod.rs
index fa93386..df71ecb 100644
--- a/src/unix/linux_like/mod.rs
+++ b/src/unix/linux_like/mod.rs
@@ -50,6 +50,8 @@
         pub sin6_scope_id: u32,
     }
 
+    // The order of the `ai_addr` field in this struct is crucial
+    // for converting between the Rust and C types.
     pub struct addrinfo {
         pub ai_flags: ::c_int,
         pub ai_family: ::c_int,
@@ -805,6 +807,7 @@
 pub const IPV6_LEAVE_ANYCAST: ::c_int = 28;
 pub const IPV6_RECVPKTINFO: ::c_int = 49;
 pub const IPV6_PKTINFO: ::c_int = 50;
+pub const IPV6_HOPLIMIT: ::c_int = 52;
 pub const IPV6_RECVTCLASS: ::c_int = 66;
 pub const IPV6_TCLASS: ::c_int = 67;
 
diff --git a/src/unix/mod.rs b/src/unix/mod.rs
index 1084d9a..55b892f 100644
--- a/src/unix/mod.rs
+++ b/src/unix/mod.rs
@@ -269,10 +269,6 @@
 pub const LOG_PRIMASK: ::c_int = 7;
 pub const LOG_FACMASK: ::c_int = 0x3f8;
 
-pub const PRIO_PROCESS: ::c_int = 0;
-pub const PRIO_PGRP: ::c_int = 1;
-pub const PRIO_USER: ::c_int = 2;
-
 pub const PRIO_MIN: ::c_int = -20;
 pub const PRIO_MAX: ::c_int = 20;
 
diff --git a/src/unix/newlib/aarch64/mod.rs b/src/unix/newlib/aarch64/mod.rs
index 7e1b2bb..3a68bf4 100644
--- a/src/unix/newlib/aarch64/mod.rs
+++ b/src/unix/newlib/aarch64/mod.rs
@@ -1,3 +1,4 @@
+pub type clock_t = ::c_long;
 pub type c_char = u8;
 pub type wchar_t = u32;
 
@@ -29,5 +30,13 @@
     }
 }
 
+pub const FIONBIO: ::c_ulong = 1;
+
+pub const POLLIN: ::c_short = 0x1;
+pub const POLLPRI: ::c_short = 0x2;
 pub const POLLOUT: ::c_short = 0x4;
+pub const POLLERR: ::c_short = 0x8;
 pub const POLLHUP: ::c_short = 0x10;
+pub const POLLNVAL: ::c_short = 0x20;
+
+pub const SOL_SOCKET: ::c_int = 65535;
diff --git a/src/unix/newlib/arm/mod.rs b/src/unix/newlib/arm/mod.rs
index 39cb425..27274f7 100644
--- a/src/unix/newlib/arm/mod.rs
+++ b/src/unix/newlib/arm/mod.rs
@@ -1,3 +1,4 @@
+pub type clock_t = ::c_long;
 pub type c_char = u8;
 pub type wchar_t = u32;
 
@@ -31,5 +32,13 @@
     }
 }
 
-pub const POLLOUT: ::c_short = 0x10;
+pub const FIONBIO: ::c_ulong = 1;
+
+pub const POLLIN: ::c_short = 0x1;
+pub const POLLPRI: ::c_short = 0x2;
 pub const POLLHUP: ::c_short = 0x4;
+pub const POLLERR: ::c_short = 0x8;
+pub const POLLOUT: ::c_short = 0x10;
+pub const POLLNVAL: ::c_short = 0x20;
+
+pub const SOL_SOCKET: ::c_int = 65535;
diff --git a/src/unix/newlib/mod.rs b/src/unix/newlib/mod.rs
index 0823f3b..5f53f61 100644
--- a/src/unix/newlib/mod.rs
+++ b/src/unix/newlib/mod.rs
@@ -1,6 +1,5 @@
 pub type blkcnt_t = i32;
 pub type blksize_t = i32;
-pub type clock_t = i32;
 pub type clockid_t = ::c_ulong;
 pub type dev_t = u32;
 pub type fsblkcnt_t = u64;
@@ -25,14 +24,23 @@
 pub type useconds_t = u32;
 
 s! {
+    // The order of the `ai_addr` field in this struct is crucial
+    // for converting between the Rust and C types.
     pub struct addrinfo {
         pub ai_flags: ::c_int,
         pub ai_family: ::c_int,
         pub ai_socktype: ::c_int,
         pub ai_protocol: ::c_int,
         pub ai_addrlen: socklen_t,
-        pub ai_canonname: *mut ::c_char,
+
+        #[cfg(target_arch = "xtensa")]
         pub ai_addr: *mut sockaddr,
+
+        pub ai_canonname: *mut ::c_char,
+
+        #[cfg(not(target_arch = "xtensa"))]
+        pub ai_addr: *mut sockaddr,
+
         pub ai_next: *mut addrinfo,
     }
 
@@ -364,11 +372,6 @@
 pub const O_ACCMODE: ::c_int = 3;
 pub const O_CLOEXEC: ::c_int = 0x80000;
 
-pub const POLLIN: ::c_short = 0x1;
-pub const POLLPRI: ::c_short = 0x2;
-pub const POLLERR: ::c_short = 0x8;
-pub const POLLNVAL: ::c_short = 0x20;
-
 pub const RTLD_LAZY: ::c_int = 0x1;
 
 pub const STDIN_FILENO: ::c_int = 0;
@@ -379,7 +382,6 @@
 pub const SEEK_CUR: ::c_int = 1;
 pub const SEEK_END: ::c_int = 2;
 
-pub const FIONBIO: ::c_ulong = 1;
 pub const FIOCLEX: ::c_ulong = 0x20006601;
 pub const FIONCLEX: ::c_ulong = 0x20006602;
 
@@ -406,7 +408,6 @@
 pub const S_IWOTH: ::mode_t = 2;
 pub const S_IXOTH: ::mode_t = 1;
 
-pub const SOL_SOCKET: ::c_int = 65535;
 pub const SOL_TCP: ::c_int = 6;
 
 pub const PF_UNSPEC: ::c_int = 0;
@@ -547,6 +548,13 @@
 pub const EAI_NONAME: ::c_int = -305;
 pub const EAI_SOCKTYPE: ::c_int = -307;
 
+pub const EXIT_SUCCESS: ::c_int = 0;
+pub const EXIT_FAILURE: ::c_int = 1;
+
+pub const PRIO_PROCESS: ::c_int = 0;
+pub const PRIO_PGRP: ::c_int = 1;
+pub const PRIO_USER: ::c_int = 2;
+
 f! {
     pub fn FD_CLR(fd: ::c_int, set: *mut fd_set) -> () {
         let bits = ::mem::size_of_val(&(*set).fds_bits[0]) * 8;
@@ -698,6 +706,9 @@
     } else if #[cfg(target_arch = "aarch64")] {
         mod aarch64;
         pub use self::aarch64::*;
+    } else if #[cfg(target_arch = "xtensa")] {
+        mod xtensa;
+        pub use self::xtensa::*;
     } else {
         // Only tested on ARM so far. Other platforms might have different
         // definitions for types and constants.
diff --git a/src/unix/newlib/xtensa/mod.rs b/src/unix/newlib/xtensa/mod.rs
new file mode 100644
index 0000000..bf95d9c
--- /dev/null
+++ b/src/unix/newlib/xtensa/mod.rs
@@ -0,0 +1,97 @@
+pub type clock_t = ::c_ulong;
+pub type c_char = i8;
+pub type wchar_t = u32;
+
+pub type c_long = i32;
+pub type c_ulong = u32;
+
+s! {
+    pub struct cmsghdr {
+        pub cmsg_len: ::socklen_t,
+        pub cmsg_level: ::c_int,
+        pub cmsg_type: ::c_int,
+    }
+
+    pub struct msghdr {
+        pub msg_name: *mut ::c_void,
+        pub msg_namelen: ::socklen_t,
+        pub msg_iov: *mut ::iovec,
+        pub msg_iovlen: ::c_int,
+        pub msg_control: *mut ::c_void,
+        pub msg_controllen: ::socklen_t,
+        pub msg_flags: ::c_int,
+    }
+
+    pub struct sockaddr_un {
+        pub sun_family: ::sa_family_t,
+        pub sun_path: [::c_char; 108],
+    }
+
+    pub struct sockaddr {
+        pub sa_len: u8,
+        pub sa_family: ::sa_family_t,
+        pub sa_data: [::c_char; 14],
+    }
+
+    pub struct sockaddr_in6 {
+        pub sin6_len: u8,
+        pub sin6_family: ::sa_family_t,
+        pub sin6_port: ::in_port_t,
+        pub sin6_flowinfo: u32,
+        pub sin6_addr: ::in6_addr,
+        pub sin6_scope_id: u32,
+    }
+
+    pub struct sockaddr_in {
+        pub sin_len: u8,
+        pub sin_family: ::sa_family_t,
+        pub sin_port: ::in_port_t,
+        pub sin_addr: ::in_addr,
+        pub sin_zero: [::c_char; 8],
+    }
+
+    pub struct sockaddr_storage {
+        pub s2_len: u8,
+        pub ss_family: ::sa_family_t,
+        pub s2_data1: [::c_char; 2],
+        pub s2_data2: [u32; 3],
+        pub s2_data3: [u32; 3],
+    }
+}
+
+pub const AF_UNIX: ::c_int = 1;
+
+pub const FIONBIO: ::c_ulong = 2147772030;
+
+pub const POLLIN: ::c_short = 1 << 0;
+pub const POLLRDNORM: ::c_short = 1 << 1;
+pub const POLLRDBAND: ::c_short = 1 << 2;
+pub const POLLPRI: ::c_short = POLLRDBAND;
+pub const POLLOUT: ::c_short = 1 << 3;
+pub const POLLWRNORM: ::c_short = POLLOUT;
+pub const POLLWRBAND: ::c_short = 1 << 4;
+pub const POLLERR: ::c_short = 1 << 5;
+pub const POLLHUP: ::c_short = 1 << 6;
+
+pub const SOL_SOCKET: ::c_int = 0xfff;
+
+extern "C" {
+    pub fn sendmsg(
+        s: ::c_int,
+        msg: *const ::msghdr,
+        flags: ::c_int,
+    ) -> ::ssize_t;
+    pub fn recvmsg(
+        s: ::c_int,
+        msg: *mut ::msghdr,
+        flags: ::c_int,
+    ) -> ::ssize_t;
+
+    pub fn writev(s: ::c_int, iov: *const ::iovec, iovcnt: ::c_int)
+        -> ::c_int;
+    pub fn readv(
+        fd: ::c_int,
+        iov: *const ::iovec,
+        iovcnt: ::c_int,
+    ) -> ::ssize_t;
+}
diff --git a/src/unix/redox/mod.rs b/src/unix/redox/mod.rs
index 7f66f1b..55f64ee 100644
--- a/src/unix/redox/mod.rs
+++ b/src/unix/redox/mod.rs
@@ -587,6 +587,23 @@
 pub const TIOCGWINSZ: ::c_ulong = 0x5413;
 pub const TIOCSWINSZ: ::c_ulong = 0x5414;
 
+// sys/mman.h
+pub const PROT_NONE: ::c_int = 0x0000;
+pub const PROT_READ: ::c_int = 0x0004;
+pub const PROT_WRITE: ::c_int = 0x0002;
+pub const PROT_EXEC: ::c_int = 0x0001;
+
+pub const MAP_SHARED: ::c_int = 0x0001;
+pub const MAP_PRIVATE: ::c_int = 0x0002;
+pub const MAP_ANON: ::c_int = 0x0020;
+pub const MAP_ANONYMOUS: ::c_int = MAP_ANON;
+pub const MAP_FIXED: ::c_int = 0x0010;
+pub const MAP_FAILED: *mut ::c_void = !0 as _;
+
+pub const MS_ASYNC: ::c_int = 0x0001;
+pub const MS_INVALIDATE: ::c_int = 0x0002;
+pub const MS_SYNC: ::c_int = 0x0004;
+
 // sys/select.h
 pub const FD_SETSIZE: usize = 1024;
 
@@ -806,6 +823,10 @@
 pub const _PC_SYMLINK_MAX: ::c_int = 19;
 pub const _PC_2_SYMLINKS: ::c_int = 20;
 
+pub const PRIO_PROCESS: ::c_int = 0;
+pub const PRIO_PGRP: ::c_int = 1;
+pub const PRIO_USER: ::c_int = 2;
+
 // wait.h
 f! {
     pub fn WIFSTOPPED(status: ::c_int) -> bool {
@@ -934,6 +955,24 @@
     // sys/ioctl.h
     pub fn ioctl(fd: ::c_int, request: ::c_ulong, ...) -> ::c_int;
 
+    // sys/mman.h
+    pub fn msync(
+        addr: *mut ::c_void,
+        len: ::size_t,
+        flags: ::c_int,
+    ) -> ::c_int;
+    pub fn mprotect(
+        addr: *mut ::c_void,
+        len: ::size_t,
+        prot: ::c_int,
+    ) -> ::c_int;
+    pub fn shm_open(
+        name: *const c_char,
+        oflag: ::c_int,
+        mode: mode_t,
+    ) -> ::c_int;
+    pub fn shm_unlink(name: *const ::c_char) -> ::c_int;
+
     // sys/resource.h
     pub fn getrlimit(resource: ::c_int, rlim: *mut ::rlimit) -> ::c_int;
     pub fn setrlimit(resource: ::c_int, rlim: *const ::rlimit) -> ::c_int;
diff --git a/src/unix/solarish/mod.rs b/src/unix/solarish/mod.rs
index ba959a7..b0eecf1 100644
--- a/src/unix/solarish/mod.rs
+++ b/src/unix/solarish/mod.rs
@@ -1995,6 +1995,10 @@
 pub const TIME_WAIT: i32 = 4;
 pub const TIME_ERROR: i32 = 5;
 
+pub const PRIO_PROCESS: ::c_int = 0;
+pub const PRIO_PGRP: ::c_int = 1;
+pub const PRIO_USER: ::c_int = 2;
+
 f! {
     pub fn FD_CLR(fd: ::c_int, set: *mut fd_set) -> () {
         let bits = ::mem::size_of_val(&(*set).fds_bits[0]) * 8;
diff --git a/src/unix/uclibc/mod.rs b/src/unix/uclibc/mod.rs
index e57c43d..a68cb7a 100644
--- a/src/unix/uclibc/mod.rs
+++ b/src/unix/uclibc/mod.rs
@@ -1503,6 +1503,10 @@
 
 pub const FILENAME_MAX: ::c_uint = 4095;
 
+pub const PRIO_PROCESS: ::c_int = 0;
+pub const PRIO_PGRP: ::c_int = 1;
+pub const PRIO_USER: ::c_int = 2;
+
 f! {
     pub fn FD_CLR(fd: ::c_int, set: *mut fd_set) -> () {
         let fd = fd as usize;