Skip to content

Commit 7c609de

Browse files
committed
Allow nix to compile on aarch64-linux-android
1 parent 59d3938 commit 7c609de

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

Diff for: src/sys/signal.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,10 @@ libc_bitflags!{
211211
}
212212
}
213213

214+
// On 64-bit android, sa_flags is c_uint while on 32-bit android, it is
215+
// c_ulong.
214216
// FIXME: https://github.com/rust-lang/libc/pull/511
215-
#[cfg(target_os = "android")]
217+
#[cfg(all(target_os = "android", target_pointer_width = "32"))]
216218
libc_bitflags!{
217219
pub flags SaFlags: libc::c_ulong {
218220
SA_NOCLDSTOP as libc::c_ulong,
@@ -225,6 +227,19 @@ libc_bitflags!{
225227
}
226228
}
227229

230+
#[cfg(all(target_os = "android", target_pointer_width = "64"))]
231+
libc_bitflags!{
232+
pub flags SaFlags: libc::c_uint {
233+
SA_NOCLDSTOP as libc::c_uint,
234+
SA_NOCLDWAIT as libc::c_uint,
235+
SA_NODEFER as libc::c_uint,
236+
SA_ONSTACK as libc::c_uint,
237+
SA_RESETHAND as libc::c_uint,
238+
SA_RESTART as libc::c_uint,
239+
SA_SIGINFO as libc::c_uint,
240+
}
241+
}
242+
228243
#[repr(i32)]
229244
#[derive(Clone, Copy, PartialEq)]
230245
pub enum SigmaskHow {

Diff for: src/sys/socket/consts.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ mod os {
4040
pub const SO_LINGER: c_int = libc::SO_LINGER;
4141
pub const SO_MARK: c_int = 36;
4242
pub const SO_OOBINLINE: c_int = libc::SO_OOBINLINE;
43-
#[cfg(not(target_arch="arm"))]
43+
#[cfg(not(any(target_arch="arm", target_os="android")))]
4444
pub const SO_PASSCRED: c_int = libc::SO_PASSCRED;
4545
pub const SO_PEEK_OFF: c_int = 42;
46-
#[cfg(not(target_arch="arm"))]
46+
#[cfg(not(any(target_arch="arm", target_os="android")))]
4747
pub const SO_PEERCRED: c_int = libc::SO_PEERCRED;
4848
pub const SO_PRIORITY: c_int = 12;
4949
pub const SO_PROTOCOL: c_int = 38;
@@ -57,7 +57,7 @@ mod os {
5757
pub const SO_REUSEPORT: c_int = libc::SO_REUSEPORT;
5858
pub const SO_RXQ_OVFL: c_int = 40;
5959
pub const SO_SNDBUF: c_int = libc::SO_SNDBUF;
60-
#[cfg(not(target_arch="arm"))]
60+
#[cfg(not(any(target_arch="arm", target_os="android")))]
6161
pub const SO_SNDBUFFORCE: c_int = libc::SO_SNDBUFFORCE;
6262
pub const SO_TIMESTAMP: c_int = 29;
6363
pub const SO_TYPE: c_int = libc::SO_TYPE;

Diff for: src/sys/socket/mod.rs

+16
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ pub fn listen(sockfd: RawFd, backlog: usize) -> Result<()> {
394394
/// Bind a name to a socket
395395
///
396396
/// [Further reading](http://man7.org/linux/man-pages/man2/bind.2.html)
397+
#[cfg(not(all(target_os="android", target_pointer_width="64")))]
397398
pub fn bind(fd: RawFd, addr: &SockAddr) -> Result<()> {
398399
let res = unsafe {
399400
let (ptr, len) = addr.as_ffi_pair();
@@ -403,6 +404,21 @@ pub fn bind(fd: RawFd, addr: &SockAddr) -> Result<()> {
403404
Errno::result(res).map(drop)
404405
}
405406

407+
/// Bind a name to a socket
408+
///
409+
/// [Further reading](http://man7.org/linux/man-pages/man2/bind.2.html)
410+
// Android has some weirdness. Its 64-bit bind takes a c_int instead of a
411+
// socklen_t
412+
#[cfg(all(target_os="android", target_pointer_width="64"))]
413+
pub fn bind(fd: RawFd, addr: &SockAddr) -> Result<()> {
414+
let res = unsafe {
415+
let (ptr, len) = addr.as_ffi_pair();
416+
ffi::bind(fd, ptr, len as c_int)
417+
};
418+
419+
Errno::result(res).map(drop)
420+
}
421+
406422
/// Accept a connection on a socket
407423
///
408424
/// [Further reading](http://man7.org/linux/man-pages/man2/accept.2.html)

0 commit comments

Comments
 (0)