Rollup merge of #40317 - malbarbo:update-libc, r=alexcrichton

Update libc to 0.2.21

Update to include android aarch64 and x86 improvements.
This commit is contained in:
Alex Crichton 2017-03-27 15:24:11 -05:00 committed by GitHub
commit e857e296c1
6 changed files with 36 additions and 11 deletions

@ -1 +1 @@
Subproject commit 64d954c6a76e896fbf7ed5c17e77c40e388abe84 Subproject commit 05a2d197356ef253dfd985166576619ac9b6947f

View File

@ -14,22 +14,24 @@
use fmt; use fmt;
#[cfg(any(target_os = "android", #[cfg(any(target_os = "emscripten",
target_os = "emscripten",
all(target_os = "linux", any(target_arch = "aarch64", all(target_os = "linux", any(target_arch = "aarch64",
target_arch = "arm", target_arch = "arm",
target_arch = "powerpc", target_arch = "powerpc",
target_arch = "powerpc64", target_arch = "powerpc64",
target_arch = "s390x")), target_arch = "s390x")),
all(target_os = "android", any(target_arch = "aarch64",
target_arch = "arm")),
all(target_os = "fuchsia", target_arch = "aarch64")))] all(target_os = "fuchsia", target_arch = "aarch64")))]
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_char = u8; #[stable(feature = "raw_os", since = "1.1.0")] pub type c_char = u8;
#[cfg(not(any(target_os = "android", #[cfg(not(any(target_os = "emscripten",
target_os = "emscripten",
all(target_os = "linux", any(target_arch = "aarch64", all(target_os = "linux", any(target_arch = "aarch64",
target_arch = "arm", target_arch = "arm",
target_arch = "powerpc", target_arch = "powerpc",
target_arch = "powerpc64", target_arch = "powerpc64",
target_arch = "s390x")), target_arch = "s390x")),
all(target_os = "android", any(target_arch = "aarch64",
target_arch = "arm")),
all(target_os = "fuchsia", target_arch = "aarch64"))))] all(target_os = "fuchsia", target_arch = "aarch64"))))]
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_char = i8; #[stable(feature = "raw_os", since = "1.1.0")] pub type c_char = i8;
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_schar = i8; #[stable(feature = "raw_os", since = "1.1.0")] pub type c_schar = i8;

View File

@ -641,7 +641,7 @@ fn inner(path: &Path) -> io::Result<UnixListener> {
let inner = Socket::new_raw(libc::AF_UNIX, libc::SOCK_STREAM)?; let inner = Socket::new_raw(libc::AF_UNIX, libc::SOCK_STREAM)?;
let (addr, len) = sockaddr_un(path)?; let (addr, len) = sockaddr_un(path)?;
cvt(libc::bind(*inner.as_inner(), &addr as *const _ as *const _, len))?; cvt(libc::bind(*inner.as_inner(), &addr as *const _ as *const _, len as _))?;
cvt(libc::listen(*inner.as_inner(), 128))?; cvt(libc::listen(*inner.as_inner(), 128))?;
Ok(UnixListener(inner)) Ok(UnixListener(inner))
@ -920,7 +920,7 @@ fn inner(path: &Path) -> io::Result<UnixDatagram> {
let socket = UnixDatagram::unbound()?; let socket = UnixDatagram::unbound()?;
let (addr, len) = sockaddr_un(path)?; let (addr, len) = sockaddr_un(path)?;
cvt(libc::bind(*socket.0.as_inner(), &addr as *const _ as *const _, len))?; cvt(libc::bind(*socket.0.as_inner(), &addr as *const _ as *const _, len as _))?;
Ok(socket) Ok(socket)
} }

View File

@ -417,12 +417,26 @@ macro_rules! t {
} }
} }
// Android with api less than 21 define sig* functions inline, so it is not
// available for dynamic link. Implementing sigemptyset and sigaddset allow us
// to support older Android version (independent of libc version).
// The following implementations are based on https://git.io/vSkNf
#[cfg(not(target_os = "android"))] #[cfg(not(target_os = "android"))]
extern { extern {
#[cfg_attr(target_os = "netbsd", link_name = "__sigemptyset14")]
fn sigemptyset(set: *mut libc::sigset_t) -> libc::c_int;
#[cfg_attr(target_os = "netbsd", link_name = "__sigaddset14")] #[cfg_attr(target_os = "netbsd", link_name = "__sigaddset14")]
fn sigaddset(set: *mut libc::sigset_t, signum: libc::c_int) -> libc::c_int; fn sigaddset(set: *mut libc::sigset_t, signum: libc::c_int) -> libc::c_int;
} }
#[cfg(target_os = "android")]
unsafe fn sigemptyset(set: *mut libc::sigset_t) -> libc::c_int {
libc::memset(set as *mut _, 0, mem::size_of::<libc::sigset_t>());
return 0;
}
#[cfg(target_os = "android")] #[cfg(target_os = "android")]
unsafe fn sigaddset(set: *mut libc::sigset_t, signum: libc::c_int) -> libc::c_int { unsafe fn sigaddset(set: *mut libc::sigset_t, signum: libc::c_int) -> libc::c_int {
use slice; use slice;
@ -450,7 +464,7 @@ fn test_process_mask() {
let mut set: libc::sigset_t = mem::uninitialized(); let mut set: libc::sigset_t = mem::uninitialized();
let mut old_set: libc::sigset_t = mem::uninitialized(); let mut old_set: libc::sigset_t = mem::uninitialized();
t!(cvt(libc::sigemptyset(&mut set))); t!(cvt(sigemptyset(&mut set)));
t!(cvt(sigaddset(&mut set, libc::SIGINT))); t!(cvt(sigaddset(&mut set, libc::SIGINT)));
t!(cvt(libc::pthread_sigmask(libc::SIG_SETMASK, &set, &mut old_set))); t!(cvt(libc::pthread_sigmask(libc::SIG_SETMASK, &set, &mut old_set)));

View File

@ -193,7 +193,16 @@ macro_rules! t {
// need to clean things up now to avoid confusing the program // need to clean things up now to avoid confusing the program
// we're about to run. // we're about to run.
let mut set: libc::sigset_t = mem::uninitialized(); let mut set: libc::sigset_t = mem::uninitialized();
t!(cvt(libc::sigemptyset(&mut set))); if cfg!(target_os = "android") {
// Implementing sigemptyset allow us to support older Android
// versions. See the comment about Android and sig* functions in
// process_common.rs
libc::memset(&mut set as *mut _ as *mut _,
0,
mem::size_of::<libc::sigset_t>());
} else {
t!(cvt(libc::sigemptyset(&mut set)));
}
t!(cvt(libc::pthread_sigmask(libc::SIG_SETMASK, &set, t!(cvt(libc::pthread_sigmask(libc::SIG_SETMASK, &set,
ptr::null_mut()))); ptr::null_mut())));
let ret = sys::signal(libc::SIGPIPE, libc::SIG_DFL); let ret = sys::signal(libc::SIGPIPE, libc::SIG_DFL);

View File

@ -339,7 +339,7 @@ pub fn bind(addr: &SocketAddr) -> io::Result<TcpListener> {
// Bind our new socket // Bind our new socket
let (addrp, len) = addr.into_inner(); let (addrp, len) = addr.into_inner();
cvt(unsafe { c::bind(*sock.as_inner(), addrp, len) })?; cvt(unsafe { c::bind(*sock.as_inner(), addrp, len as _) })?;
// Start listening // Start listening
cvt(unsafe { c::listen(*sock.as_inner(), 128) })?; cvt(unsafe { c::listen(*sock.as_inner(), 128) })?;
@ -430,7 +430,7 @@ pub fn bind(addr: &SocketAddr) -> io::Result<UdpSocket> {
let sock = Socket::new(addr, c::SOCK_DGRAM)?; let sock = Socket::new(addr, c::SOCK_DGRAM)?;
let (addrp, len) = addr.into_inner(); let (addrp, len) = addr.into_inner();
cvt(unsafe { c::bind(*sock.as_inner(), addrp, len) })?; cvt(unsafe { c::bind(*sock.as_inner(), addrp, len as _) })?;
Ok(UdpSocket { inner: sock }) Ok(UdpSocket { inner: sock })
} }