summaryrefslogtreecommitdiff
path: root/src/sys
diff options
context:
space:
mode:
authorkennytm <kennytm@gmail.com>2015-03-14 04:34:24 +0800
committerCarl Lerche <me@carllerche.com>2015-03-13 16:40:28 -0700
commitc5bc33200c8eb3563784c0e18dc37060049247cd (patch)
tree8715258b03eef8fcc6a62c82582b537ccb219e44 /src/sys
parent386dfd6f4770770b7721e7fa5195b4c993aa3e4b (diff)
downloadnix-c5bc33200c8eb3563784c0e18dc37060049247cd.zip
Amend some files to make it compile on arm-linux-androideabi.
Diffstat (limited to 'src/sys')
-rw-r--r--src/sys/epoll.rs16
-rw-r--r--src/sys/ioctl.rs3
-rw-r--r--src/sys/mman.rs2
-rw-r--r--src/sys/mod.rs8
-rw-r--r--src/sys/socket/consts.rs2
-rw-r--r--src/sys/socket/mod.rs4
-rw-r--r--src/sys/syscall.rs10
-rw-r--r--src/sys/termios.rs61
8 files changed, 96 insertions, 10 deletions
diff --git a/src/sys/epoll.rs b/src/sys/epoll.rs
index b9b31c9a..138680fe 100644
--- a/src/sys/epoll.rs
+++ b/src/sys/epoll.rs
@@ -78,6 +78,22 @@ pub enum EpollOp {
EpollCtlMod = 3
}
+#[cfg(all(target_os = "android", not(target_arch = "x86_64")))]
+#[derive(Copy)]
+#[repr(C)]
+pub struct EpollEvent {
+ pub events: EpollEventKind,
+ pub data: u64
+}
+
+#[cfg(all(target_os = "android", not(target_arch = "x86_64")))]
+#[test]
+fn test_epoll_event_size() {
+ use std::mem::size_of;
+ assert_eq!(size_of::<EpollEvent>(), 16);
+}
+
+#[cfg(any(not(target_os = "android"), target_arch = "x86_64"))]
#[derive(Copy)]
#[repr(C, packed)]
pub struct EpollEvent {
diff --git a/src/sys/ioctl.rs b/src/sys/ioctl.rs
index 847733f2..516b29bc 100644
--- a/src/sys/ioctl.rs
+++ b/src/sys/ioctl.rs
@@ -22,7 +22,8 @@ mod ffi {
pub const TIOCGWINSZ: c_ulong = 0x40087468;
}
- #[cfg(target_os = "linux")]
+ #[cfg(any(target_os = "linux",
+ all(target_os = "android", not(target_arch = "mips"))))]
pub mod os {
use libc::c_int;
pub const TIOCGWINSZ: c_int = 0x5413;
diff --git a/src/sys/mman.rs b/src/sys/mman.rs
index 1b94cc4b..60171a9e 100644
--- a/src/sys/mman.rs
+++ b/src/sys/mman.rs
@@ -6,7 +6,7 @@ use sys::stat::Mode;
pub use self::consts::*;
-#[cfg(target_os = "linux")]
+#[cfg(any(target_os = "linux", target_os = "android"))]
mod consts {
use libc::c_int;
diff --git a/src/sys/mod.rs b/src/sys/mod.rs
index 06688204..c14b02f2 100644
--- a/src/sys/mod.rs
+++ b/src/sys/mod.rs
@@ -1,11 +1,11 @@
-#[cfg(target_os = "linux")]
+#[cfg(any(target_os = "linux", target_os = "android"))]
pub mod epoll;
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub mod event;
-#[cfg(target_os = "linux")]
+#[cfg(any(target_os = "linux", target_os = "android"))]
pub mod eventfd;
#[cfg(not(target_os = "ios"))]
@@ -17,13 +17,13 @@ pub mod socket;
pub mod stat;
-#[cfg(target_os = "linux")]
+#[cfg(any(target_os = "linux", target_os = "android"))]
pub mod syscall;
#[cfg(not(target_os = "ios"))]
pub mod termios;
-#[cfg(target_os = "linux")]
+#[cfg(any(target_os = "linux", target_os = "android"))]
pub mod utsname;
pub mod wait;
diff --git a/src/sys/socket/consts.rs b/src/sys/socket/consts.rs
index 3131cfb8..481f133a 100644
--- a/src/sys/socket/consts.rs
+++ b/src/sys/socket/consts.rs
@@ -1,6 +1,6 @@
pub use self::os::*;
-#[cfg(target_os = "linux")]
+#[cfg(any(target_os = "linux", target_os = "android"))]
mod os {
use libc::{c_int, uint8_t};
diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs
index 6b317dec..0480a020 100644
--- a/src/sys/socket/mod.rs
+++ b/src/sys/socket/mod.rs
@@ -132,7 +132,7 @@ pub fn accept(sockfd: Fd) -> NixResult<Fd> {
/// Accept a connection on a socket
///
/// [Further reading](http://man7.org/linux/man-pages/man2/accept.2.html)
-#[cfg(not(any(target_os = "macos", target_os = "ios")))]
+#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "android")))]
pub fn accept4(sockfd: Fd, flags: SockFlag) -> NixResult<Fd> {
use libc::sockaddr;
@@ -162,7 +162,7 @@ pub fn accept4(sockfd: Fd, flags: SockFlag) -> NixResult<Fd> {
/// Accept a connection on a socket
///
/// [Further reading](http://man7.org/linux/man-pages/man2/accept.2.html)
-#[cfg(any(target_os = "macos", target_os = "ios"))]
+#[cfg(any(target_os = "macos", target_os = "ios", target_os = "android"))]
pub fn accept4(sockfd: Fd, flags: SockFlag) -> NixResult<Fd> {
accept4_polyfill(sockfd, flags)
}
diff --git a/src/sys/syscall.rs b/src/sys/syscall.rs
index cdf6c414..0f6a5e0b 100644
--- a/src/sys/syscall.rs
+++ b/src/sys/syscall.rs
@@ -22,6 +22,16 @@ mod arch {
pub static SYSPIVOTROOT: Syscall = 217;
}
+#[cfg(target_arch = "arm")]
+mod arch {
+ use libc::c_long;
+
+ pub type Syscall = c_long;
+
+ pub static SYSPIVOTROOT: Syscall = 218;
+}
+
+
extern {
pub fn syscall(num: Syscall, ...) -> c_int;
}
diff --git a/src/sys/termios.rs b/src/sys/termios.rs
index 56beca2e..7ef2ca57 100644
--- a/src/sys/termios.rs
+++ b/src/sys/termios.rs
@@ -17,6 +17,7 @@ mod ffi {
// `Termios` contains bitflags which are not considered
// `foreign-function-safe` by the compiler.
#[allow(improper_ctypes)]
+ #[cfg(any(target_os = "macos", target_os = "linux"))]
extern {
pub fn cfgetispeed(termios: *const Termios) -> speed_t;
pub fn cfgetospeed(termios: *const Termios) -> speed_t;
@@ -32,6 +33,62 @@ mod ffi {
pub fn tcsendbreak(fd: c_int, duration: c_int) -> c_int;
}
+ // 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::funcs::bsd44::ioctl;
+ use libc::c_int;
+ use super::consts::*;
+
+ const TCGETS: c_int = 0x5401;
+ const TCSBRK: c_int = 0x5409;
+ const TCXONC: c_int = 0x540a;
+ const TCFLSH: c_int = 0x540b;
+ const TCSBRKP: c_int = 0x5425;
+
+ pub unsafe fn cfgetispeed(termios: *const Termios) -> speed_t {
+ ((*termios).c_cflag & CBAUD).bits() as speed_t
+ }
+ pub unsafe fn cfgetospeed(termios: *const Termios) -> speed_t {
+ ((*termios).c_cflag & CBAUD).bits() as speed_t
+ }
+ pub unsafe fn cfsetispeed(termios: *mut Termios, speed: speed_t) -> c_int {
+ (*termios).c_cflag.remove(CBAUD);
+ (*termios).c_cflag.insert(ControlFlags::from_bits_truncate(speed) & CBAUD);
+ 0
+ }
+ pub unsafe fn cfsetospeed(termios: *mut Termios, speed: speed_t) -> c_int {
+ (*termios).c_cflag.remove(CBAUD);
+ (*termios).c_cflag.insert(ControlFlags::from_bits_truncate(speed) & CBAUD);
+ 0
+ }
+ pub unsafe fn tcgetattr(fd: c_int, termios: *mut Termios) -> c_int {
+ ioctl(fd, TCGETS, termios)
+ }
+ pub unsafe fn tcsetattr(fd: c_int,
+ optional_actions: c_int,
+ termios: *const Termios) -> c_int {
+ ioctl(fd, optional_actions, termios)
+ }
+ pub unsafe fn tcdrain(fd: c_int) -> c_int {
+ ioctl(fd, TCSBRK, 1)
+ }
+ pub unsafe fn tcflow(fd: c_int, action: c_int) -> c_int {
+ ioctl(fd, TCXONC, action)
+ }
+ pub unsafe fn tcflush(fd: c_int, action: c_int) -> c_int {
+ ioctl(fd, TCFLSH, action)
+ }
+ pub unsafe fn tcsendbreak(fd: c_int, duration: c_int) -> c_int {
+ ioctl(fd, TCSBRKP, duration)
+ }
+ }
+
+ #[cfg(target_os = "android")]
+ pub use self::android::*;
+
+
#[cfg(target_os = "macos")]
pub mod consts {
use libc::{c_int, c_ulong, c_uchar};
@@ -198,7 +255,7 @@ mod ffi {
}
}
- #[cfg(target_os = "linux")]
+ #[cfg(any(target_os = "linux", target_os = "android"))]
pub mod consts {
use libc::{c_int, c_uint, c_uchar};
@@ -277,6 +334,8 @@ mod ffi {
const HUPCL = 0x00000400,
const CLOCAL = 0x00000800,
const CRTSCTS = 0x80000000,
+ #[cfg(target_os = "android")]
+ const CBAUD = 0o0010017,
}
}