Skip to content

Commit 5c90e3c

Browse files
committed
Allow nix to compile on aarch64-linux-android
1 parent 408aef4 commit 5c90e3c

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

src/sys/signal.rs

Lines changed: 16 additions & 1 deletion
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 {

src/sys/socket/consts.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,8 @@ mod os {
4040
pub const SO_LINGER: c_int = libc::SO_LINGER;
4141
pub const SO_MARK: c_int = libc::SO_MARK;
4242
pub const SO_OOBINLINE: c_int = libc::SO_OOBINLINE;
43-
#[cfg(not(target_arch="arm"))]
4443
pub const SO_PASSCRED: c_int = libc::SO_PASSCRED;
4544
pub const SO_PEEK_OFF: c_int = libc::SO_PEEK_OFF;
46-
#[cfg(not(target_arch="arm"))]
4745
pub const SO_PEERCRED: c_int = libc::SO_PEERCRED;
4846
pub const SO_PRIORITY: c_int = libc::SO_PRIORITY;
4947
pub const SO_PROTOCOL: c_int = libc::SO_PROTOCOL;
@@ -57,7 +55,6 @@ mod os {
5755
pub const SO_REUSEPORT: c_int = libc::SO_REUSEPORT;
5856
pub const SO_RXQ_OVFL: c_int = libc::SO_RXQ_OVFL;
5957
pub const SO_SNDBUF: c_int = libc::SO_SNDBUF;
60-
#[cfg(not(target_arch="arm"))]
6158
pub const SO_SNDBUFFORCE: c_int = libc::SO_SNDBUFFORCE;
6259
pub const SO_TIMESTAMP: c_int = libc::SO_TIMESTAMP;
6360
pub const SO_TYPE: c_int = libc::SO_TYPE;

src/sys/socket/mod.rs

Lines changed: 16 additions & 0 deletions
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)