Skip to content

Commit 443b401

Browse files
committed
Add poll and mmap support
1 parent ab67803 commit 443b401

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

src/redox/mod.rs

+54
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ pub type uid_t = usize;
4343
pub type suseconds_t = i64;
4444

4545
s! {
46+
pub struct fd_set {
47+
fds_bits: [::c_ulong; FD_SETSIZE / ULONG_SIZE],
48+
}
49+
50+
pub struct pollfd {
51+
pub fd: ::c_int,
52+
pub events: ::c_short,
53+
pub revents: ::c_short,
54+
}
55+
4656
pub struct timeval {
4757
pub tv_sec: time_t,
4858
pub tv_usec: suseconds_t,
@@ -64,6 +74,27 @@ pub const STDERR_FILENO: ::c_int = 2;
6474
pub const EXIT_FAILURE: ::c_int = 1;
6575
pub const EXIT_SUCCESS: ::c_int = 0;
6676

77+
pub const FD_SETSIZE: usize = 1024;
78+
79+
pub const MAP_SHARED: ::c_int = 1;
80+
pub const MAP_PRIVATE: ::c_int = 2;
81+
pub const MAP_ANONYMOUS: ::c_int = 4;
82+
pub const MAP_ANON: ::c_int = MAP_ANONYMOUS;
83+
84+
pub const MAP_FAILED: *mut ::c_void = !0 as *mut ::c_void;
85+
86+
pub const POLLIN: ::c_short = 0x001;
87+
pub const POLLPRI: ::c_short = 0x002;
88+
pub const POLLOUT: ::c_short = 0x004;
89+
pub const POLLERR: ::c_short = 0x008;
90+
pub const POLLHUP: ::c_short = 0x010;
91+
pub const POLLNVAL: ::c_short = 0x020;
92+
93+
pub const PROT_NONE: ::c_int = 0;
94+
pub const PROT_EXEC: ::c_int = 1;
95+
pub const PROT_WRITE: ::c_int = 2;
96+
pub const PROT_READ: ::c_int = 4;
97+
6798
pub const S_ISUID: ::c_int = 0x800;
6899
pub const S_ISGID: ::c_int = 0x400;
69100
pub const S_ISVTX: ::c_int = 0x200;
@@ -152,6 +183,18 @@ pub const SIGSYS: ::c_int = 31;
152183
pub enum FILE {}
153184
pub enum fpos_t {} // TODO: fill this out with a struct
154185

186+
187+
// intentionally not public, only used for fd_set
188+
cfg_if! {
189+
if #[cfg(target_pointer_width = "32")] {
190+
const ULONG_SIZE: usize = 32;
191+
} else if #[cfg(target_pointer_width = "64")] {
192+
const ULONG_SIZE: usize = 64;
193+
} else {
194+
// Unknown target_pointer_width
195+
}
196+
}
197+
155198
extern {
156199
pub fn isalnum(c: c_int) -> c_int;
157200
pub fn isalpha(c: c_int) -> c_int;
@@ -262,9 +305,20 @@ extern {
262305
pub fn close(fd: ::c_int) -> ::c_int;
263306
pub fn fchown(fd: ::c_int, uid: ::uid_t, gid: ::gid_t) -> ::c_int;
264307
pub fn fcntl(fd: ::c_int, cmd: ::c_int, ...) -> ::c_int;
308+
pub fn fsync(fd: ::c_int) -> ::c_int;
265309
pub fn gethostname(name: *mut ::c_char, len: ::size_t) -> ::c_int;
266310
pub fn getpid() -> pid_t;
267311
pub fn memalign(align: ::size_t, size: ::size_t) -> *mut ::c_void;
312+
pub fn mmap(addr: *mut ::c_void,
313+
len: ::size_t,
314+
prot: ::c_int,
315+
flags: ::c_int,
316+
fd: ::c_int,
317+
offset: off_t)
318+
-> *mut ::c_void;
319+
pub fn mprotect(addr: *mut ::c_void, len: ::size_t, prot: ::c_int)
320+
-> ::c_int;
321+
pub fn munmap(addr: *mut ::c_void, len: ::size_t) -> ::c_int;
268322
pub fn read(fd: ::c_int, buf: *mut ::c_void, count: ::size_t) -> ::ssize_t;
269323
pub fn setenv(name: *const c_char, val: *const c_char, overwrite: ::c_int)
270324
-> ::c_int;

0 commit comments

Comments
 (0)