From 11dae339cf8111ff326ecb3d6763c201e7aba757 Mon Sep 17 00:00:00 2001 From: roblabla Date: Tue, 4 Jul 2017 14:06:39 +0200 Subject: Allow nix to compile on android targets --- src/errno.rs | 8 +++++++- src/sys/signal.rs | 30 ++++++++++++++++++++++++++++++ src/sys/socket/consts.rs | 3 --- src/sys/socket/mod.rs | 16 ++++++++++++++++ src/sys/termios.rs | 1 - 5 files changed, 53 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/errno.rs b/src/errno.rs index a27abaa7..9102d7b1 100644 --- a/src/errno.rs +++ b/src/errno.rs @@ -35,12 +35,18 @@ unsafe fn errno_location() -> *mut c_int { __errno() } -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(target_os = "linux")] unsafe fn errno_location() -> *mut c_int { extern { fn __errno_location() -> *mut c_int; } __errno_location() } +#[cfg(target_os = "android")] +unsafe fn errno_location() -> *mut c_int { + extern { fn __errno() -> *mut c_int; } + __errno() +} + /// Sets the platform-specific errno to no-error unsafe fn clear() -> () { *errno_location() = 0; diff --git a/src/sys/signal.rs b/src/sys/signal.rs index e7978052..ee952369 100644 --- a/src/sys/signal.rs +++ b/src/sys/signal.rs @@ -198,6 +198,7 @@ pub const SIGIOT : Signal = SIGABRT; pub const SIGPOLL : Signal = SIGIO; pub const SIGUNUSED : Signal = SIGSYS; +#[cfg(not(target_os = "android"))] libc_bitflags!{ pub flags SaFlags: libc::c_int { SA_NOCLDSTOP, @@ -210,6 +211,35 @@ libc_bitflags!{ } } +// On 64-bit android, sa_flags is c_uint while on 32-bit android, it is +// c_ulong. +// FIXME: https://github.com/rust-lang/libc/pull/511 +#[cfg(all(target_os = "android", target_pointer_width = "32"))] +libc_bitflags!{ + pub flags SaFlags: libc::c_ulong { + SA_NOCLDSTOP as libc::c_ulong, + SA_NOCLDWAIT as libc::c_ulong, + SA_NODEFER as libc::c_ulong, + SA_ONSTACK as libc::c_ulong, + SA_RESETHAND as libc::c_ulong, + SA_RESTART as libc::c_ulong, + SA_SIGINFO as libc::c_ulong, + } +} + +#[cfg(all(target_os = "android", target_pointer_width = "64"))] +libc_bitflags!{ + pub flags SaFlags: libc::c_uint { + SA_NOCLDSTOP as libc::c_uint, + SA_NOCLDWAIT as libc::c_uint, + SA_NODEFER as libc::c_uint, + SA_ONSTACK as libc::c_uint, + SA_RESETHAND as libc::c_uint, + SA_RESTART as libc::c_uint, + SA_SIGINFO as libc::c_uint, + } +} + #[repr(i32)] #[derive(Clone, Copy, PartialEq)] pub enum SigmaskHow { diff --git a/src/sys/socket/consts.rs b/src/sys/socket/consts.rs index ef3d0252..ad9c522f 100644 --- a/src/sys/socket/consts.rs +++ b/src/sys/socket/consts.rs @@ -40,10 +40,8 @@ mod os { pub const SO_LINGER: c_int = libc::SO_LINGER; pub const SO_MARK: c_int = libc::SO_MARK; pub const SO_OOBINLINE: c_int = libc::SO_OOBINLINE; - #[cfg(not(target_arch="arm"))] pub const SO_PASSCRED: c_int = libc::SO_PASSCRED; pub const SO_PEEK_OFF: c_int = libc::SO_PEEK_OFF; - #[cfg(not(target_arch="arm"))] pub const SO_PEERCRED: c_int = libc::SO_PEERCRED; pub const SO_PRIORITY: c_int = libc::SO_PRIORITY; pub const SO_PROTOCOL: c_int = libc::SO_PROTOCOL; @@ -57,7 +55,6 @@ mod os { pub const SO_REUSEPORT: c_int = libc::SO_REUSEPORT; pub const SO_RXQ_OVFL: c_int = libc::SO_RXQ_OVFL; pub const SO_SNDBUF: c_int = libc::SO_SNDBUF; - #[cfg(not(target_arch="arm"))] pub const SO_SNDBUFFORCE: c_int = libc::SO_SNDBUFFORCE; pub const SO_TIMESTAMP: c_int = libc::SO_TIMESTAMP; pub const SO_TYPE: c_int = libc::SO_TYPE; diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs index 73cab9d5..a126f8b4 100644 --- a/src/sys/socket/mod.rs +++ b/src/sys/socket/mod.rs @@ -394,6 +394,7 @@ pub fn listen(sockfd: RawFd, backlog: usize) -> Result<()> { /// Bind a name to a socket /// /// [Further reading](http://man7.org/linux/man-pages/man2/bind.2.html) +#[cfg(not(all(target_os="android", target_pointer_width="64")))] pub fn bind(fd: RawFd, addr: &SockAddr) -> Result<()> { let res = unsafe { let (ptr, len) = addr.as_ffi_pair(); @@ -403,6 +404,21 @@ pub fn bind(fd: RawFd, addr: &SockAddr) -> Result<()> { Errno::result(res).map(drop) } +/// Bind a name to a socket +/// +/// [Further reading](http://man7.org/linux/man-pages/man2/bind.2.html) +// Android has some weirdness. Its 64-bit bind takes a c_int instead of a +// socklen_t +#[cfg(all(target_os="android", target_pointer_width="64"))] +pub fn bind(fd: RawFd, addr: &SockAddr) -> Result<()> { + let res = unsafe { + let (ptr, len) = addr.as_ffi_pair(); + ffi::bind(fd, ptr, len as c_int) + }; + + Errno::result(res).map(drop) +} + /// Accept a connection on a socket /// /// [Further reading](http://man7.org/linux/man-pages/man2/accept.2.html) diff --git a/src/sys/termios.rs b/src/sys/termios.rs index 65e7c01c..0f8bd6c9 100644 --- a/src/sys/termios.rs +++ b/src/sys/termios.rs @@ -39,7 +39,6 @@ mod ffi { pub use self::non_android::*; // On Android before 5.0, Bionic directly inline these to ioctl() calls. - #[inline] #[cfg(all(target_os = "android", not(target_arch = "mips")))] mod android { use libc; -- cgit v1.2.3