Import lots of the stdlib
diff --git a/libc-test/build.rs b/libc-test/build.rs
index 41c1759..3bc7782 100644
--- a/libc-test/build.rs
+++ b/libc-test/build.rs
@@ -8,6 +8,7 @@
     let target = env::var("TARGET").unwrap();
     let windows = target.contains("windows");
     let mingw = target.contains("windows-gnu");
+    let linux = target.contains("unknown-linux");
     let mut cfg = ctest::TestGenerator::new();
 
     // Pull in extra goodies on linux/mingw
@@ -78,6 +79,8 @@
         cfg.header("sys/wait.h");
         cfg.header("unistd.h");
         cfg.header("utime.h");
+        cfg.header("pwd.h");
+        cfg.header("grp.h");
 
         if target.contains("android") {
             cfg.header("arpa/inet.h");
@@ -86,16 +89,23 @@
             cfg.header("ifaddrs.h");
             cfg.header("sys/sysctl.h");
         }
+
+    }
+    if target.contains("linux") {
+        cfg.header("sys/prctl.h");
     }
 
     cfg.type_name(move |ty, is_struct| {
         match ty {
             // Just pass all these through, no need for a "struct" prefix
-            "glob_t" |
             "FILE" |
-            "DIR" |
-            "fpos_t" => ty.to_string(),
-            t if t.starts_with("pthread") => t.to_string(),
+            "DIR" => ty.to_string(),
+
+            // Fixup a few types on windows that don't actually exist.
+            "time64_t" if windows => "__time64_t".to_string(),
+            "ssize_t" if windows => "SSIZE_T".to_string(),
+
+            t if t.ends_with("_t") => t.to_string(),
 
             // Windows uppercase structs don't have `struct` in front, there's a
             // few special cases for windows, and then otherwise put `struct` in
@@ -112,10 +122,6 @@
                 }
             }
 
-            // Fixup a few types on windows that don't actually exist.
-            "time64_t" if windows => "__time64_t".to_string(),
-            "ssize_t" if windows => "SSIZE_T".to_string(),
-
             t => t.to_string(),
         }
     });
@@ -163,30 +169,33 @@
         }
     });
 
-    // Apparently these don't exist in mingw headers?
     cfg.skip_const(move |name| {
         match name {
+            // Apparently these don't exist in mingw headers?
             "MEM_RESET_UNDO" |
             "FILE_ATTRIBUTE_NO_SCRUB_DATA" |
             "FILE_ATTRIBUTE_INTEGRITY_STREAM" |
             "ERROR_NOTHING_TO_TERMINATE" if mingw => true,
+
             "SIG_IGN" => true, // sighandler_t weirdness
+
             _ => false,
         }
     });
 
-    cfg.skip_fn(|name| {
+    cfg.skip_fn(move |name| {
+        // skip those that are manually verifiedmanually verified
         match name {
-            // manually verified
-            "execv" |
+            "execv" |       // crazy stuff with const/mut
             "execve" |
             "execvp" |
-            "execvpe" |
-            "glob" |
-            "getrlimit" |
-            "setrlimit" |
-            "signal" |
-            "getopt" => true,
+            "execvpe" => true,
+
+            "getrlimit" |                    // non-int in 1st arg
+            "setrlimit" |                    // non-int in 1st arg
+            "gettimeofday" |                 // typed 2nd arg on linux
+            "strerror_r" if linux => true,   // actually xpg-something-or-other
+
             _ => false,
         }
     });
@@ -196,7 +205,15 @@
 
     cfg.skip_field_type(|struct_, field| {
         // This is a weird union, don't check the type.
-        struct_ == "ifaddrs" && field == "ifa_ifu"
+        (struct_ == "ifaddrs" && field == "ifa_ifu") ||
+        // sighandler_t type is super weird
+        (struct_ == "sigaction" && field == "sa_sigaction")
+    });
+
+    cfg.skip_field(|struct_, field| {
+        // this is actually a union on linux, so we can't represent it well and
+        // just insert some padding.
+        (struct_ == "siginfo_t" && field == "_pad")
     });
 
     cfg.generate("../src/lib.rs", "all.rs");
diff --git a/libc-test/src/main.rs b/libc-test/src/main.rs
index e4cb8fe..fff188d 100644
--- a/libc-test/src/main.rs
+++ b/libc-test/src/main.rs
@@ -1,4 +1,4 @@
-#![allow(bad_style)]
+#![allow(bad_style, improper_ctypes)]
 extern crate libc;
 
 use libc::*;
diff --git a/src/unix/bsd/apple/b32.rs b/src/unix/bsd/apple/b32.rs
index 62caa5f..293822e 100644
--- a/src/unix/bsd/apple/b32.rs
+++ b/src/unix/bsd/apple/b32.rs
@@ -7,6 +7,10 @@
 pub type intptr_t = i32;
 pub type uintptr_t = u32;
 
+pub const __PTHREAD_MUTEX_SIZE__: usize = 40;
+pub const __PTHREAD_COND_SIZE__: usize = 24;
+pub const __PTHREAD_RWLOCK_SIZE__: usize = 124;
+
 s! {
     pub struct pthread_attr_t {
         __sig: c_long,
diff --git a/src/unix/bsd/apple/b64.rs b/src/unix/bsd/apple/b64.rs
index 1a79be3..fb9f58c 100644
--- a/src/unix/bsd/apple/b64.rs
+++ b/src/unix/bsd/apple/b64.rs
@@ -7,6 +7,10 @@
 pub type intptr_t = i64;
 pub type uintptr_t = u64;
 
+pub const __PTHREAD_MUTEX_SIZE__: usize = 56;
+pub const __PTHREAD_COND_SIZE__: usize = 40;
+pub const __PTHREAD_RWLOCK_SIZE__: usize = 192;
+
 s! {
     pub struct pthread_attr_t {
         __sig: c_long,
diff --git a/src/unix/bsd/apple/mod.rs b/src/unix/bsd/apple/mod.rs
index 71b24a6..173788d 100644
--- a/src/unix/bsd/apple/mod.rs
+++ b/src/unix/bsd/apple/mod.rs
@@ -41,6 +41,8 @@
 pub type rlim_t = u64;
 pub type sighandler_t = size_t;
 pub type mach_timebase_info_data_t = mach_timebase_info;
+pub type pthread_key_t = c_ulong;
+pub type sigset_t = u32;
 
 pub enum timezone {}
 
@@ -120,6 +122,41 @@
         pub st_qspare: [::int64_t; 2],
     }
 
+
+    pub struct pthread_mutex_t {
+        __sig: libc::c_long,
+        __opaque: [u8; __PTHREAD_MUTEX_SIZE__],
+    }
+    pub struct pthread_mutexattr_t {
+        __sig: libc::c_long,
+        __opaque: [u8; 16],
+    }
+
+    pub struct pthread_cond_t {
+        __sig: libc::c_long,
+        __opaque: [u8; __PTHREAD_COND_SIZE__],
+    }
+
+    pub struct pthread_rwlock_t {
+        __sig: libc::c_long,
+        __opaque: [u8; __PTHREAD_RWLOCK_SIZE__],
+    }
+
+    pub struct siginfo_t {
+        pub _signo: ::c_int,
+        pub _errno: ::c_int,
+        pub _code: ::c_int,
+        pub _pid: ::pid_t,
+        pub _uid: ::uid_t,
+        pub _status: ::c_int,
+        pub si_addr: *mut ::c_void
+    }
+
+    pub struct sigaction {
+        pub sa_sigaction: sighandler_t,
+        pub sa_mask: sigset_t,
+        pub sa_flags: ::c_int,
+    }
 }
 
 pub const EXIT_FAILURE: c_int = 1;
@@ -334,7 +371,6 @@
 pub const O_ACCMODE: c_int = 3;
 
 pub const SIGTRAP: c_int = 5;
-pub const SIG_IGN: size_t = 1;
 
 pub const GLOB_APPEND  : c_int = 0x0001;
 pub const GLOB_DOOFFS  : c_int = 0x0002;
@@ -601,9 +637,30 @@
 pub const _SC_TRACE_USER_EVENT_MAX: c_int = 130;
 pub const _SC_PASS_MAX: c_int = 131;
 
+
+pub const PTHREAD_MUTEX_RECURSIVE: ::c_int = 2;
+pub const _PTHREAD_MUTEX_SIG_INIT: ::c_long = 0x32AAABA7;
+pub const _PTHREAD_COND_SIG_INIT: ::c_long = 0x3CB0B1BB;
+pub const _PTHREAD_RWLOCK_SIG_INIT: ::c_long = 0x2DA8B3B4;
+pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t {
+    __sig: _PTHREAD_MUTEX_SIG_INIT,
+    __opaque: [0; __PTHREAD_MUTEX_SIZE__],
+};
+pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t {
+    __sig: _PTHREAD_COND_SIG_INIT,
+    __opaque: [0; __PTHREAD_COND_SIZE__],
+};
+pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t {
+    __sig: _PTHREAD_RWLOCK_SIG_INIT,
+    __opaque: [0; __PTHREAD_RWLOCK_SIZE__],
+};
+
 extern {
     pub fn _NSGetExecutablePath(buf: *mut ::c_char,
                                 bufsize: *mut ::uint32_t) -> ::c_int;
+    pub fn _NSGetArgc() -> *mut c_int;
+    pub fn _NSGetArgv() -> *mut *mut *mut c_char;
+    pub fn _NSGetEnviron() -> *mut *const *const c_char;
     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
                link_name = "mprotect$UNIX2003")]
     pub fn mprotect(addr: *mut ::c_void, len: ::size_t, prot: ::c_int)
@@ -622,6 +679,14 @@
                         newp: *mut ::c_void,
                         newlen: ::size_t)
                         -> ::c_int;
+    pub fn _tlv_atexit(dtor: unsafe extern fn(*mut u8),
+                       arg: *mut u8);
+    pub fn mach_absolute_time() -> u64;
+    pub fn mach_timebase_info(info: *mut ::mach_timebase_info) -> ::c_int;
+    pub fn pthread_setname_np(name: *const ::c_char) -> ::c_int;
+    pub fn pthread_get_stackaddr_np(thread: pthread_t) -> *mut ::c_void;
+    pub fn pthread_get_stacksize_np(thread: pthread_t) -> ::size_t;
+    pub fn __error() -> *const ::c_int;
 }
 
 cfg_if! {
diff --git a/src/unix/bsd/freebsdlike/dragonfly.rs b/src/unix/bsd/freebsdlike/dragonfly.rs
index a677d1a..f158cda 100644
--- a/src/unix/bsd/freebsdlike/dragonfly.rs
+++ b/src/unix/bsd/freebsdlike/dragonfly.rs
@@ -1,2 +1,6 @@
 pub const PTHREAD_STACK_MIN: ::size_t = 1024;
 pub const KERN_PROC_PATHNAME: ::c_int = 9;
+
+extern {
+    pub fn __dfly_error() -> *const ::c_int;
+}
diff --git a/src/unix/bsd/freebsdlike/freebsd.rs b/src/unix/bsd/freebsdlike/freebsd.rs
index c499837..808f6ea 100644
--- a/src/unix/bsd/freebsdlike/freebsd.rs
+++ b/src/unix/bsd/freebsdlike/freebsd.rs
@@ -1,2 +1,6 @@
 pub const PTHREAD_STACK_MIN: ::size_t = 2048;
 pub const KERN_PROC_PATHNAME: ::c_int = 12;
+
+extern {
+    pub fn __error() -> *const ::c_int;
+}
diff --git a/src/unix/bsd/freebsdlike/mod.rs b/src/unix/bsd/freebsdlike/mod.rs
index fc50c22..4ca588f 100644
--- a/src/unix/bsd/freebsdlike/mod.rs
+++ b/src/unix/bsd/freebsdlike/mod.rs
@@ -5,6 +5,11 @@
 pub type sa_family_t = u8;
 pub type in_port_t = u16;
 pub type in_addr_t = u32;
+pub type pthread_mutex_t = *mut ::c_void;
+pub type pthread_mutexattr_t = *mut ::c_void;
+pub type pthread_cond_t = *mut ::c_void;
+pub type pthread_rwlock_t = *mut ::c_void;
+pub type pthread_key_t = ::c_int;
 
 pub enum timezone {}
 
@@ -53,6 +58,26 @@
         pub ifa_dstaddr: *mut ::sockaddr,
         pub ifa_data: *mut ::c_void
     }
+
+    pub struct sigset_t {
+        bits: [u32; 4],
+    }
+
+    pub struct siginfo_t {
+        pub _signo: ::c_int,
+        pub _errno: ::c_int,
+        pub _code: ::c_int,
+        pub _pid: ::pid_t,
+        pub _uid: ::uid_t,
+        pub _status: ::c_int,
+        pub si_addr: *mut ::c_void
+    }
+
+    pub struct sigaction {
+        pub sa_sigaction: sighandler_t,
+        pub sa_flags: ::c_int,
+        pub sa_mask: sigset_t,
+    }
 }
 
 pub const EXIT_FAILURE: ::c_int = 1;
@@ -247,7 +272,6 @@
 pub const F_SETFL: ::c_int = 4;
 
 pub const SIGTRAP: ::c_int = 5;
-pub const SIG_IGN: size_t = 1;
 
 pub const GLOB_APPEND  : ::c_int = 0x0001;
 pub const GLOB_DOOFFS  : ::c_int = 0x0002;
@@ -462,6 +486,11 @@
 pub const _SC_SIGQUEUE_MAX: ::c_int = 51;
 pub const _SC_TIMER_MAX: ::c_int = 52;
 
+pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = 0 as *mut _;
+pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = 0 as *mut _;
+pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = 0 as *mut _;
+pub const PTHREAD_MUTEX_RECURSIVE: ::c_int = 2;
+
 extern {
     pub fn mprotect(addr: *const ::c_void, len: size_t, prot: c_int)
                     -> c_int;
@@ -480,6 +509,8 @@
                         newp: *const ::c_void,
                         newlen: size_t)
                         -> c_int;
+    pub fn clock_gettime(clk_id: ::c_int, tp: *mut ::timespec) -> ::c_int;
+    pub fn pthread_set_name_np(tid: ::pthread_t, name: *const ::c_char);
 }
 
 cfg_if! {
diff --git a/src/unix/bsd/mod.rs b/src/unix/bsd/mod.rs
index d55c781..5dd2fb7 100644
--- a/src/unix/bsd/mod.rs
+++ b/src/unix/bsd/mod.rs
@@ -27,8 +27,36 @@
         pub sun_family: sa_family_t,
         pub sun_path: [c_char; 104]
     }
+
+    pub struct passwd {
+        pub pw_name: *mut ::c_char,
+        pub pw_passwd: *mut ::c_char,
+        pub pw_uid: ::uid_t,
+        pub pw_gid: ::gid_t,
+        pub pw_change: ::time_t,
+        pub pw_class: *mut ::c_char,
+        pub pw_gecos: *mut ::c_char,
+        pub pw_dir: *mut ::c_char,
+        pub pw_shell: *mut ::c_char,
+        pub pw_expire: ::time_t,
+    }
+
+    pub struct sigaltstack {
+        pub ss_sp: *mut ::c_void,
+        pub ss_size: ::size_t,
+        pub ss_flags: ::c_int,
+    }
 }
 
+pub const FIOCLEX: c_ulong = 0x20006601;
+
+pub const SA_ONSTACK: ::c_int = 0x0001;
+pub const SA_SIGINFO: ::c_int = 0x0040;
+
+pub const SIGSTKSZ: ::size_t = 131072;
+pub const SIGBUS: ::c_int = 10;
+pub const SIG_SETMASK: ::c_int = 3;
+
 extern {
     pub fn mincore(addr: *const ::c_void, len: size_t,
                    vec: *mut c_char) -> c_int;
diff --git a/src/unix/bsd/openbsdlike/mod.rs b/src/unix/bsd/openbsdlike/mod.rs
index f003630..ef40db4 100644
--- a/src/unix/bsd/openbsdlike/mod.rs
+++ b/src/unix/bsd/openbsdlike/mod.rs
@@ -1,3 +1,21 @@
+    pub type sigset_t = libc::c_uint;
+pub type pthread_key_t = ::c_int;
+        struct stack_t {
+            ss_sp: *mut libc::c_void,
+            ss_size: libc::size_t,
+            ss_flags: libc::c_int,
+        }
+    pub struct siginfo_t {
+        pub si_signo: libc::c_int,
+        pub si_code: libc::c_int,
+        pub si_errno: libc::c_int,
+        pub si_addr: *mut libc::c_void
+    }
+    pub struct sigaction {
+        pub sa_sigaction: sighandler_t,
+        pub sa_mask: sigset_t,
+        pub sa_flags: libc::c_int,
+    }
 
     #[cfg(any(target_os = "bitrig", target_os = "netbsd", target_os ="openbsd"))]
     pub mod os {
@@ -497,7 +515,6 @@
             pub const F_DUPFD_CLOEXEC : c_int = 10;
 
             pub const SIGTRAP : c_int = 5;
-            pub const SIG_IGN: size_t = 1;
 
             pub const GLOB_APPEND   : c_int = 0x0001;
             pub const GLOB_DOOFFS   : c_int = 0x0002;
@@ -710,6 +727,15 @@
             pub const _SC_TIMERS : c_int = 94;
         }
     }
+    pub type pthread_mutex_t = *mut libc::c_void;
+    pub type pthread_mutexattr_t = *mut libc::c_void;
+    pub type pthread_cond_t = *mut libc::c_void;
+    pub type pthread_rwlock_t = *mut libc::c_void;
+
+    pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = ptr::null_mut();
+    pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = ptr::null_mut();
+    pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = ptr::null_mut();
+    pub const PTHREAD_MUTEX_RECURSIVE: libc::c_int = 2;
 extern {
     pub fn mprotect(addr: *const ::c_void, len: size_t, prot: c_int)
                     -> c_int;
@@ -728,4 +754,10 @@
                         newp: *mut ::c_void,
                         newlen: size_t)
                         -> c_int;
+    pub fn clock_gettime(clk_id: ::c_int, tp: *mut ::timespec) -> ::c_int;
+    pub fn pthread_set_name_np(tid: ::pthread_t, name: *const ::c_char);
+    pub fn pthread_main_np() -> ::c_uint;
+    pub fn pthread_stackseg_np(thread: pthread_t,
+                               sinfo: *mut stack_t) -> ::c_uint;
+    pub fn __errno() -> *const ::c_int;
 }
diff --git a/src/unix/mod.rs b/src/unix/mod.rs
index f05e633..2dabfd1 100644
--- a/src/unix/mod.rs
+++ b/src/unix/mod.rs
@@ -66,9 +66,14 @@
     }
 }
 
+pub const WNOHANG: c_int = 1;
+pub const SIG_DFL: sighandler_t = 0 as sighandler_t;
+pub const SIG_IGN: sighandler_t = 1 as sighandler_t;
+pub const SIG_ERR: sighandler_t = !0 as sighandler_t;
+
 cfg_if! {
     if #[cfg(feature = "default")] {
-        // cargo build, don't pull in anything extra as the libstd libc dep
+        // cargo build, don't pull in anything extra as the libstd  dep
         // already pulls in all libs.
     } else if #[cfg(target_env = "musl")] {
         #[link(name = "c", kind = "static")]
@@ -193,9 +198,7 @@
     pub fn getgroups(ngroups_max: c_int, groups: *mut gid_t)
                      -> c_int;
     pub fn getlogin() -> *mut c_char;
-    // GNU getopt(3) modifies its arguments despite the
-    // char * const [] prototype; see the manpage.
-    pub fn getopt(argc: c_int, argv: *mut *mut c_char,
+    pub fn getopt(argc: c_int, argv: *const *mut c_char,
                   optstr: *const c_char) -> c_int;
     pub fn getpgrp() -> pid_t;
     pub fn getpid() -> pid_t;
@@ -303,8 +306,8 @@
 
     pub fn getdtablesize() -> c_int;
     #[cfg_attr(target_os = "macos", link_name = "realpath$DARWIN_EXTSN")]
-    pub fn realpath(pathname: *const c_char, resolved: *mut c_char)
-                    -> *mut c_char;
+    pub fn realpath(pathname: *const ::c_char, resolved: *mut ::c_char)
+                    -> *mut ::c_char;
 
     pub fn flock(fd: c_int, operation: c_int) -> c_int;
 }
@@ -318,7 +321,7 @@
                 flags: c_int,
                 errfunc: ::dox::Option<extern "C" fn(epath: *const c_char,
                                                      errno: c_int) -> c_int>,
-                pglob: *mut glob_t);
+                pglob: *mut glob_t) -> c_int;
     pub fn globfree(pglob: *mut glob_t);
 
     pub fn posix_madvise(addr: *mut ::c_void, len: size_t, advice: c_int)
@@ -371,6 +374,88 @@
     pub fn recv(socket: c_int, buf: *mut ::c_void, len: size_t,
                 flags: c_int) -> ssize_t;
     pub fn mkfifo(path: *const c_char, mode: mode_t) -> c_int;
+    pub fn gettimeofday(tp: *mut ::timeval,
+                        tz: *mut ::c_void) -> ::c_int;
+
+    pub fn pthread_self() -> ::pthread_t;
+    pub fn pthread_create(native: *mut ::pthread_t,
+                          attr: *const ::pthread_attr_t,
+                          f: extern fn(*mut ::c_void) -> *mut ::c_void,
+                          value: *mut ::c_void) -> ::c_int;
+    pub fn pthread_join(native: ::pthread_t,
+                        value: *mut *mut ::c_void) -> ::c_int;
+    pub fn pthread_attr_init(attr: *mut ::pthread_attr_t) -> ::c_int;
+    pub fn pthread_attr_destroy(attr: *mut ::pthread_attr_t) -> ::c_int;
+    pub fn pthread_attr_setstacksize(attr: *mut ::pthread_attr_t,
+                                     stack_size: ::size_t) -> ::c_int;
+    pub fn pthread_attr_setdetachstate(attr: *mut ::pthread_attr_t,
+                                       state: ::c_int) -> ::c_int;
+    pub fn pthread_detach(thread: ::pthread_t) -> ::c_int;
+    pub fn sched_yield() -> ::c_int;
+    pub fn pthread_key_create(key: *mut pthread_key_t,
+                              dtor: Option<unsafe extern fn(*mut ::c_void)>)
+                              -> c_int;
+    pub fn pthread_key_delete(key: pthread_key_t) -> c_int;
+    pub fn pthread_getspecific(key: pthread_key_t) -> *mut ::c_void;
+    pub fn pthread_setspecific(key: pthread_key_t, value: *const ::c_void)
+                               -> c_int;
+    pub fn pthread_mutex_init(lock: *mut pthread_mutex_t,
+                              attr: *const pthread_mutexattr_t) -> ::c_int;
+    pub fn pthread_mutex_destroy(lock: *mut pthread_mutex_t) -> ::c_int;
+    pub fn pthread_mutex_lock(lock: *mut pthread_mutex_t) -> ::c_int;
+    pub fn pthread_mutex_trylock(lock: *mut pthread_mutex_t) -> ::c_int;
+    pub fn pthread_mutex_unlock(lock: *mut pthread_mutex_t) -> ::c_int;
+
+    pub fn pthread_mutexattr_init(attr: *mut pthread_mutexattr_t) -> ::c_int;
+    pub fn pthread_mutexattr_destroy(attr: *mut pthread_mutexattr_t) -> ::c_int;
+    pub fn pthread_mutexattr_settype(attr: *mut pthread_mutexattr_t,
+                                     _type: ::c_int) -> ::c_int;
+
+    pub fn pthread_cond_wait(cond: *mut pthread_cond_t,
+                             lock: *mut pthread_mutex_t) -> ::c_int;
+    pub fn pthread_cond_timedwait(cond: *mut pthread_cond_t,
+                              lock: *mut pthread_mutex_t,
+                              abstime: *const ::timespec) -> ::c_int;
+    pub fn pthread_cond_signal(cond: *mut pthread_cond_t) -> ::c_int;
+    pub fn pthread_cond_broadcast(cond: *mut pthread_cond_t) -> ::c_int;
+    pub fn pthread_cond_destroy(cond: *mut pthread_cond_t) -> ::c_int;
+    pub fn pthread_rwlock_destroy(lock: *mut pthread_rwlock_t) -> ::c_int;
+    pub fn pthread_rwlock_rdlock(lock: *mut pthread_rwlock_t) -> ::c_int;
+    pub fn pthread_rwlock_tryrdlock(lock: *mut pthread_rwlock_t) -> ::c_int;
+    pub fn pthread_rwlock_wrlock(lock: *mut pthread_rwlock_t) -> ::c_int;
+    pub fn pthread_rwlock_trywrlock(lock: *mut pthread_rwlock_t) -> ::c_int;
+    pub fn pthread_rwlock_unlock(lock: *mut pthread_rwlock_t) -> ::c_int;
+    pub fn pthread_sigmask(how: ::c_int, set: *const sigset_t,
+                           oldset: *mut sigset_t) -> ::c_int;
+
+    // #[cfg_attr(target_os = "linux", link_name = "__xpg_strerror_r")]
+    pub fn strerror_r(errnum: c_int, buf: *mut c_char,
+                      buflen: size_t) -> c_int;
+
+    pub fn getsockopt(sockfd: ::c_int,
+                      level: ::c_int,
+                      optname: ::c_int,
+                      optval: *mut ::c_void,
+                      optlen: *mut ::socklen_t) -> ::c_int;
+    pub fn raise(signum: ::c_int) -> ::c_int;
+    pub fn sigaction(signum: ::c_int,
+                     act: *const sigaction,
+                     oldact: *mut sigaction) -> ::c_int;
+    pub fn sigaltstack(ss: *const sigaltstack,
+                       oss: *mut sigaltstack) -> ::c_int;
+    pub fn sigemptyset(set: *mut sigset_t) -> ::c_int;
+
+    pub fn getpwuid_r(uid: ::uid_t,
+                      pwd: *mut passwd,
+                      buf: *mut ::c_char,
+                      buflen: ::size_t,
+                      result: *mut *mut passwd) -> ::c_int;
+
+    pub fn utimes(filename: *const ::c_char,
+                  times: *const ::timeval) -> ::c_int;
+    pub fn gai_strerror(errcode: ::c_int) -> *const ::c_char;
+    pub fn setgroups(ngroups: ::size_t,
+                     ptr: *const ::gid_t) -> ::c_int;
 }
 
 cfg_if! {
diff --git a/src/unix/notbsd/android.rs b/src/unix/notbsd/android.rs
index 96fdc20..6f4833c 100644
--- a/src/unix/notbsd/android.rs
+++ b/src/unix/notbsd/android.rs
@@ -22,6 +22,8 @@
 pub type useconds_t = i32;
 pub type socklen_t = i32;
 pub type pthread_t = c_long;
+pub type pthread_mutexattr_t = ::c_long;
+pub type sigset_t = c_ulong;
 
 s! {
     pub struct stat {
@@ -54,6 +56,63 @@
         pub sched_policy: ::int32_t,
         pub sched_priority: ::int32_t,
     }
+
+    pub struct pthread_mutex_t { value: ::c_int }
+
+    pub struct pthread_cond_t { value: ::c_int }
+
+    pub struct pthread_rwlock_t {
+        lock: pthread_mutex_t,
+        cond: pthread_cond_t,
+        numLocks: ::c_int,
+        writerThreadId: ::c_int,
+        pendingReaders: ::c_int,
+        pendingWriters: ::c_int,
+        reserved: [*mut ::c_void; 4],
+    }
+
+    pub struct passwd {
+        pub pw_name: *mut ::c_char,
+        pub pw_passwd: *mut ::c_char,
+        pub pw_uid: ::uid_t,
+        pub pw_gid: ::gid_t,
+        pub pw_dir: *mut ::c_char,
+        pub pw_shell: *mut ::c_char,
+    }
+
+    pub struct sigaltstack {
+        pub ss_sp: *mut ::c_void,
+        pub ss_flags: ::c_int,
+        pub ss_size: ::size_t
+    }
+
+    pub struct siginfo_t {
+        pub si_signo: ::c_int,
+        pub si_errno: ::c_int,
+        pub si_code: ::c_int,
+        pub _pad: [::c_int; 29],
+        _align: [u64; 0],
+    }
+}
+
+#[cfg(target_pointer_width = "32")]
+s!{
+    pub struct sigaction {
+        pub sa_sigaction: sighandler_t,
+        pub sa_flags: libc::c_ulong,
+        _restorer: *mut libc::c_void,
+        pub sa_mask: sigset_t,
+    }
+}
+
+#[cfg(target_pointer_width = "64")]
+s!{
+    pub struct sigaction {
+        pub sa_flags: libc::c_uint,
+        pub sa_sigaction: sighandler_t,
+        pub sa_mask: sigset_t,
+        _restorer: *mut libc::c_void,
+    }
 }
 
 pub const BUFSIZ: ::c_uint = 1024;
@@ -121,9 +180,33 @@
 pub const _SC_THREAD_SAFE_FUNCTIONS: ::c_int = 85;
 
 pub const PTHREAD_STACK_MIN: ::size_t = 8192;
+pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t {
+    value: 0,
+};
+pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t {
+    value: 0,
+};
+pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t {
+    lock: PTHREAD_MUTEX_INITIALIZER,
+    cond: PTHREAD_COND_INITIALIZER,
+    numLocks: 0,
+    writerThreadId: 0,
+    pendingReaders: 0,
+    pendingWriters: 0,
+    reserved: [0 as *mut _; 4],
+};
+pub const PTHREAD_MUTEX_RECURSIVE: ::c_int = 1;
 
 pub const O_SYNC: ::c_int = 0x1000;
 
+pub const FIOCLEX: ::c_ulong = 0x5451;
+
+pub const SA_ONSTACK: ::c_ulong = 0x08000000;
+pub const SA_SIGINFO: ::c_ulong = 0x00000004;
+
+pub const SIGBUS: ::c_int = 7;
+pub const SIG_SETMASK: ::c_int = 2;
+
 extern {
     pub fn madvise(addr: *const ::c_void, len: ::size_t, advice: ::c_int)
                    -> ::c_int;
diff --git a/src/unix/notbsd/linux/mips.rs b/src/unix/notbsd/linux/mips.rs
index 75125d4..8364e7b 100644
--- a/src/unix/notbsd/linux/mips.rs
+++ b/src/unix/notbsd/linux/mips.rs
@@ -44,6 +44,31 @@
     pub struct pthread_attr_t {
         __size: [u32; 9]
     }
+
+    pub struct sigaction {
+        pub sa_flags: ::c_uint,
+        pub sa_sigaction: ::sighandler_t,
+        pub sa_mask: sigset_t,
+        _restorer: *mut ::c_void,
+        _resv: [::c_int; 1],
+    }
+
+    pub struct sigaltstack {
+        pub ss_sp: *mut ::c_void,
+        pub ss_size: ::size_t,
+        pub ss_flags: ::c_int,
+    }
+
+    pub struct sigset_t {
+        __val: [::c_ulong; 32],
+    }
+
+    pub struct siginfo_t {
+        pub si_signo: ::c_int,
+        pub si_code: ::c_int,
+        pub si_errno: ::c_int,
+        pub _pad: [::c_int; 29],
+    }
 }
 
 pub const RLIMIT_NOFILE: ::c_int = 5;
@@ -177,3 +202,15 @@
 pub const SO_RCVTIMEO: ::c_int = 4102;
 pub const SO_SNDTIMEO: ::c_int = 4101;
 pub const SO_ACCEPTCONN: ::c_int = 4105;
+
+pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 24;
+pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 32;
+
+pub const FIOCLEX: ::c_ulong = 0x6601;
+
+pub const SA_ONSTACK: ::c_ulong = 0x08000000;
+pub const SA_SIGINFO: ::c_ulong = 0x00000008;
+
+pub const SIGBUS: ::c_int = 10;
+
+pub const SIG_SETMASK: ::c_int = 3;
diff --git a/src/unix/notbsd/linux/mod.rs b/src/unix/notbsd/linux/mod.rs
index d17f330..e119bbd 100644
--- a/src/unix/notbsd/linux/mod.rs
+++ b/src/unix/notbsd/linux/mod.rs
@@ -28,6 +28,46 @@
         pub ifa_ifu: *mut ::sockaddr, // FIXME This should be a union
         pub ifa_data: *mut ::c_void
     }
+
+    pub struct pthread_mutex_t {
+        #[cfg(any(target_arch = "mips", target_arch = "mipsel",
+                  target_arch = "arm"))]
+        __align: [::c_long; 0],
+        #[cfg(not(any(target_arch = "mips", target_arch = "mipsel",
+                      target_arch = "arm")))]
+        __align: [::c_longlong; 0],
+        size: [u8; __SIZEOF_PTHREAD_MUTEX_T],
+    }
+
+    pub struct pthread_rwlock_t {
+        #[cfg(any(target_arch = "mips", target_arch = "mipsel",
+                  target_arch = "arm"))]
+        __align: [::c_long; 0],
+        #[cfg(not(any(target_arch = "mips", target_arch = "mipsel",
+                      target_arch = "arm")))]
+        __align: [::c_longlong; 0],
+        size: [u8; __SIZEOF_PTHREAD_RWLOCK_T],
+    }
+
+    pub struct pthread_mutexattr_t {
+        __align: [::c_int; 0],
+        size: [u8; __SIZEOF_PTHREAD_MUTEXATTR_T],
+    }
+
+    pub struct pthread_cond_t {
+        __align: [::c_longlong; 0],
+        size: [u8; __SIZEOF_PTHREAD_COND_T],
+    }
+
+    pub struct passwd {
+        pub pw_name: *mut ::c_char,
+        pub pw_passwd: *mut ::c_char,
+        pub pw_uid: ::uid_t,
+        pub pw_gid: ::gid_t,
+        pub pw_gecos: *mut ::c_char,
+        pub pw_dir: *mut ::c_char,
+        pub pw_shell: *mut ::c_char,
+    }
 }
 
 pub const BUFSIZ: ::c_uint = 8192;
@@ -160,6 +200,22 @@
 
 pub const TCP_MD5SIG: ::c_int = 14;
 
+pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t {
+    __align: [],
+    size: [0; __SIZEOF_PTHREAD_MUTEX_T],
+};
+pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t {
+    __align: [],
+    size: [0; __SIZEOF_PTHREAD_COND_T],
+};
+pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t {
+    __align: [],
+    size: [0; __SIZEOF_PTHREAD_RWLOCK_T],
+};
+pub const PTHREAD_MUTEX_RECURSIVE: ::c_int = 1;
+pub const __SIZEOF_PTHREAD_COND_T: usize = 48;
+pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;
+
 extern {
     pub fn shm_open(name: *const c_char, oflag: ::c_int,
                     mode: mode_t) -> ::c_int;
@@ -173,6 +229,7 @@
                   -> ::c_int;
     pub fn mprotect(addr: *mut ::c_void, len: ::size_t, prot: ::c_int)
                     -> ::c_int;
+    pub fn __errno_location() -> *mut ::c_int;
 }
 
 cfg_if! {
diff --git a/src/unix/notbsd/linux/notmips/b32/mod.rs b/src/unix/notbsd/linux/notmips/b32/mod.rs
index 6928962..fcf75da 100644
--- a/src/unix/notbsd/linux/notmips/b32/mod.rs
+++ b/src/unix/notbsd/linux/notmips/b32/mod.rs
@@ -17,6 +17,9 @@
 pub type mode_t = u32;
 pub type nlink_t = u32;
 
+pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 24;
+pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 32;
+
 s! {
     pub struct stat {
         pub st_dev: ::dev_t,
@@ -44,6 +47,10 @@
     pub struct pthread_attr_t {
         __size: [u32; 9]
     }
+
+    pub struct sigset_t {
+        __val: [::c_ulong; 32],
+    }
 }
 
 cfg_if! {
diff --git a/src/unix/notbsd/linux/notmips/b64/aarch64.rs b/src/unix/notbsd/linux/notmips/b64/aarch64.rs
index 4bc5293..cf23b3f 100644
--- a/src/unix/notbsd/linux/notmips/b64/aarch64.rs
+++ b/src/unix/notbsd/linux/notmips/b64/aarch64.rs
@@ -5,6 +5,8 @@
 pub type blksize_t = i32;
 pub type wchar_t = u32;
 
+pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 48;
+
 s! {
     pub struct stat {
         pub st_dev: ::dev_t,
diff --git a/src/unix/notbsd/linux/notmips/b64/mod.rs b/src/unix/notbsd/linux/notmips/b64/mod.rs
index 582895b..8f55e09 100644
--- a/src/unix/notbsd/linux/notmips/b64/mod.rs
+++ b/src/unix/notbsd/linux/notmips/b64/mod.rs
@@ -15,6 +15,14 @@
 pub type ssize_t = i64;
 pub type blkcnt_t = i64;
 
+s! {
+    pub struct sigset_t {
+        __val: [::c_ulong; 16],
+    }
+}
+
+pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56;
+
 cfg_if! {
     if #[cfg(target_arch = "aarch64")] {
         mod aarch64;
diff --git a/src/unix/notbsd/linux/notmips/b64/x86_64.rs b/src/unix/notbsd/linux/notmips/b64/x86_64.rs
index 22d0acc..fec4a92 100644
--- a/src/unix/notbsd/linux/notmips/b64/x86_64.rs
+++ b/src/unix/notbsd/linux/notmips/b64/x86_64.rs
@@ -5,6 +5,8 @@
 pub type blksize_t = i64;
 pub type wchar_t = i32;
 
+pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40;
+
 s! {
     pub struct stat {
         pub st_dev: ::dev_t,
diff --git a/src/unix/notbsd/linux/notmips/mod.rs b/src/unix/notbsd/linux/notmips/mod.rs
index 3b3109c..d836971 100644
--- a/src/unix/notbsd/linux/notmips/mod.rs
+++ b/src/unix/notbsd/linux/notmips/mod.rs
@@ -1,3 +1,25 @@
+s! {
+    pub struct sigaction {
+        pub sa_sigaction: ::sighandler_t,
+        pub sa_mask: ::sigset_t,
+        pub sa_flags: ::c_int,
+        _restorer: *mut ::c_void,
+    }
+
+    pub struct sigaltstack {
+        pub ss_sp: *mut ::c_void,
+        pub ss_flags: ::c_int,
+        pub ss_size: ::size_t
+    }
+
+    pub struct siginfo_t {
+        pub si_signo: ::c_int,
+        pub si_errno: ::c_int,
+        pub si_code: ::c_int,
+        pub _pad: [::c_int; 29],
+        _align: [usize; 0],
+    }
+}
 
 pub const RLIMIT_RSS: ::c_int = 5;
 pub const RLIMIT_NOFILE: ::c_int = 7;
@@ -147,6 +169,14 @@
 
 pub const SO_REUSEPORT: ::c_int = 15;
 
+pub const FIOCLEX: ::c_ulong = 0x5451;
+
+pub const SA_ONSTACK: ::c_ulong = 0x08000000;
+pub const SA_SIGINFO: ::c_ulong = 0x00000004;
+
+pub const SIGBUS: ::c_int = 7;
+pub const SIG_SETMASK: ::c_int = 2;
+
 cfg_if! {
     if #[cfg(any(target_arch = "x86", target_arch = "arm"))] {
         mod b32;
diff --git a/src/unix/notbsd/mod.rs b/src/unix/notbsd/mod.rs
index 8591420..9cd3f45 100644
--- a/src/unix/notbsd/mod.rs
+++ b/src/unix/notbsd/mod.rs
@@ -18,6 +18,7 @@
 pub type rlim_t = c_ulong;
 pub type sa_family_t = u16;
 pub type sighandler_t = size_t;
+pub type pthread_key_t = c_uint;
 
 pub enum timezone {}
 
@@ -68,7 +69,7 @@
 
         pub ai_canonname: *mut c_char,
 
-        #[cfg(any(target_os = "android", target_os = "nacl"))]
+        #[cfg(target_os = "android")]
         pub ai_addr: *mut ::sockaddr,
 
         pub ai_next: *mut addrinfo,
@@ -105,7 +106,6 @@
 pub const O_ACCMODE: c_int = 3;
 
 pub const SIGTRAP: c_int = 5;
-pub const SIG_IGN: size_t = 1;
 
 pub const PTHREAD_CREATE_JOINABLE: c_int = 0;
 pub const PTHREAD_CREATE_DETACHED: c_int = 1;
@@ -303,10 +303,21 @@
 pub const LOCK_NB: ::c_int = 4;
 pub const LOCK_UN: ::c_int = 8;
 
+pub const SIGSTKSZ: ::size_t = 8192;
+
 extern {
     pub fn fdatasync(fd: ::c_int) -> ::c_int;
     pub fn mincore(addr: *mut ::c_void, len: ::size_t,
                    vec: *mut ::c_uchar) -> ::c_int;
+    pub fn clock_gettime(clk_id: ::c_int, tp: *mut ::timespec) -> ::c_int;
+    pub fn prctl(option: ::c_int, ...) -> ::c_int;
+    pub fn pthread_getattr_np(native: ::pthread_t,
+                              attr: *mut ::pthread_attr_t) -> ::c_int;
+    pub fn pthread_attr_getguardsize(attr: *const ::pthread_attr_t,
+                                     guardsize: *mut ::size_t) -> ::c_int;
+    pub fn pthread_attr_getstack(attr: *const ::pthread_attr_t,
+                                 stackaddr: *mut *mut ::c_void,
+                                 stacksize: *mut ::size_t) -> ::c_int;
 }
 
 cfg_if! {