Skip to content

Commit

Permalink
Allow nix to compile on aarch64-linux-android
Browse files Browse the repository at this point in the history
  • Loading branch information
roblabla committed Jun 28, 2017
1 parent 59d3938 commit 7c609de
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
17 changes: 16 additions & 1 deletion src/sys/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,10 @@ 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(target_os = "android")]
#[cfg(all(target_os = "android", target_pointer_width = "32"))]
libc_bitflags!{
pub flags SaFlags: libc::c_ulong {
SA_NOCLDSTOP as libc::c_ulong,
Expand All @@ -225,6 +227,19 @@ libc_bitflags!{
}
}

#[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 {
Expand Down
6 changes: 3 additions & 3 deletions src/sys/socket/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ mod os {
pub const SO_LINGER: c_int = libc::SO_LINGER;
pub const SO_MARK: c_int = 36;
pub const SO_OOBINLINE: c_int = libc::SO_OOBINLINE;
#[cfg(not(target_arch="arm"))]
#[cfg(not(any(target_arch="arm", target_os="android")))]
pub const SO_PASSCRED: c_int = libc::SO_PASSCRED;
pub const SO_PEEK_OFF: c_int = 42;
#[cfg(not(target_arch="arm"))]
#[cfg(not(any(target_arch="arm", target_os="android")))]
pub const SO_PEERCRED: c_int = libc::SO_PEERCRED;
pub const SO_PRIORITY: c_int = 12;
pub const SO_PROTOCOL: c_int = 38;
Expand All @@ -57,7 +57,7 @@ mod os {
pub const SO_REUSEPORT: c_int = libc::SO_REUSEPORT;
pub const SO_RXQ_OVFL: c_int = 40;
pub const SO_SNDBUF: c_int = libc::SO_SNDBUF;
#[cfg(not(target_arch="arm"))]
#[cfg(not(any(target_arch="arm", target_os="android")))]
pub const SO_SNDBUFFORCE: c_int = libc::SO_SNDBUFFORCE;
pub const SO_TIMESTAMP: c_int = 29;
pub const SO_TYPE: c_int = libc::SO_TYPE;
Expand Down
16 changes: 16 additions & 0 deletions src/sys/socket/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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)
Expand Down

0 comments on commit 7c609de

Please sign in to comment.