summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Soller <jeremy@system76.com>2019-01-01 09:02:54 -0700
committerJeremy Soller <jeremy@system76.com>2019-01-13 14:46:30 -0700
commit443b401dacc4f976955c563b5c7aee3bcc467313 (patch)
treeec1e9ca9fb27f66d0c3507006feb6a28b116718f
parentab67803a55eefb809e290a9ae961067ed415c860 (diff)
downloadrust-libc-443b401dacc4f976955c563b5c7aee3bcc467313.tar.gz
Add poll and mmap support
-rw-r--r--src/redox/mod.rs54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/redox/mod.rs b/src/redox/mod.rs
index 9f68632a0f..d329514294 100644
--- a/src/redox/mod.rs
+++ b/src/redox/mod.rs
@@ -43,6 +43,16 @@ pub type uid_t = usize;
pub type suseconds_t = i64;
s! {
+ pub struct fd_set {
+ fds_bits: [::c_ulong; FD_SETSIZE / ULONG_SIZE],
+ }
+
+ pub struct pollfd {
+ pub fd: ::c_int,
+ pub events: ::c_short,
+ pub revents: ::c_short,
+ }
+
pub struct timeval {
pub tv_sec: time_t,
pub tv_usec: suseconds_t,
@@ -64,6 +74,27 @@ pub const STDERR_FILENO: ::c_int = 2;
pub const EXIT_FAILURE: ::c_int = 1;
pub const EXIT_SUCCESS: ::c_int = 0;
+pub const FD_SETSIZE: usize = 1024;
+
+pub const MAP_SHARED: ::c_int = 1;
+pub const MAP_PRIVATE: ::c_int = 2;
+pub const MAP_ANONYMOUS: ::c_int = 4;
+pub const MAP_ANON: ::c_int = MAP_ANONYMOUS;
+
+pub const MAP_FAILED: *mut ::c_void = !0 as *mut ::c_void;
+
+pub const POLLIN: ::c_short = 0x001;
+pub const POLLPRI: ::c_short = 0x002;
+pub const POLLOUT: ::c_short = 0x004;
+pub const POLLERR: ::c_short = 0x008;
+pub const POLLHUP: ::c_short = 0x010;
+pub const POLLNVAL: ::c_short = 0x020;
+
+pub const PROT_NONE: ::c_int = 0;
+pub const PROT_EXEC: ::c_int = 1;
+pub const PROT_WRITE: ::c_int = 2;
+pub const PROT_READ: ::c_int = 4;
+
pub const S_ISUID: ::c_int = 0x800;
pub const S_ISGID: ::c_int = 0x400;
pub const S_ISVTX: ::c_int = 0x200;
@@ -152,6 +183,18 @@ pub const SIGSYS: ::c_int = 31;
pub enum FILE {}
pub enum fpos_t {} // TODO: fill this out with a struct
+
+// intentionally not public, only used for fd_set
+cfg_if! {
+ if #[cfg(target_pointer_width = "32")] {
+ const ULONG_SIZE: usize = 32;
+ } else if #[cfg(target_pointer_width = "64")] {
+ const ULONG_SIZE: usize = 64;
+ } else {
+ // Unknown target_pointer_width
+ }
+}
+
extern {
pub fn isalnum(c: c_int) -> c_int;
pub fn isalpha(c: c_int) -> c_int;
@@ -262,9 +305,20 @@ extern {
pub fn close(fd: ::c_int) -> ::c_int;
pub fn fchown(fd: ::c_int, uid: ::uid_t, gid: ::gid_t) -> ::c_int;
pub fn fcntl(fd: ::c_int, cmd: ::c_int, ...) -> ::c_int;
+ pub fn fsync(fd: ::c_int) -> ::c_int;
pub fn gethostname(name: *mut ::c_char, len: ::size_t) -> ::c_int;
pub fn getpid() -> pid_t;
pub fn memalign(align: ::size_t, size: ::size_t) -> *mut ::c_void;
+ pub fn mmap(addr: *mut ::c_void,
+ len: ::size_t,
+ prot: ::c_int,
+ flags: ::c_int,
+ fd: ::c_int,
+ offset: off_t)
+ -> *mut ::c_void;
+ pub fn mprotect(addr: *mut ::c_void, len: ::size_t, prot: ::c_int)
+ -> ::c_int;
+ pub fn munmap(addr: *mut ::c_void, len: ::size_t) -> ::c_int;
pub fn read(fd: ::c_int, buf: *mut ::c_void, count: ::size_t) -> ::ssize_t;
pub fn setenv(name: *const c_char, val: *const c_char, overwrite: ::c_int)
-> ::c_int;