Skip to content

Commit 1329b13

Browse files
committed
Auto merge of #1207 - redox-os:redox, r=gnzlbg
Redox module update This adds poll, mmap, and stat support
2 parents ab67803 + d4d3ef3 commit 1329b13

File tree

1 file changed

+102
-8
lines changed

1 file changed

+102
-8
lines changed

src/redox/mod.rs

+102-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
pub type int8_t = i8;
32
pub type int16_t = i16;
43
pub type int32_t = i32;
@@ -31,18 +30,66 @@ pub type c_char = i8;
3130
pub type c_long = i64;
3231
pub type c_ulong = u64;
3332

34-
pub type wchar_t = i16;
33+
pub type wchar_t = i32;
34+
pub type wint_t = u32;
35+
pub type wctype_t = i64;
3536

37+
pub type regoff_t = size_t;
3638
pub type off_t = c_long;
37-
pub type mode_t = u16;
38-
pub type time_t = i64;
39-
pub type pid_t = usize;
40-
pub type gid_t = usize;
41-
pub type uid_t = usize;
39+
pub type mode_t = c_int;
40+
pub type time_t = c_long;
41+
pub type pid_t = c_int;
42+
pub type id_t = c_uint;
43+
pub type gid_t = c_int;
44+
pub type uid_t = c_int;
45+
pub type dev_t = c_long;
46+
pub type ino_t = c_ulong;
47+
pub type nlink_t = c_ulong;
48+
pub type blksize_t = c_long;
49+
pub type blkcnt_t = c_ulong;
50+
51+
pub type fsblkcnt_t = c_ulong;
52+
pub type fsfilcnt_t = c_ulong;
53+
54+
pub type useconds_t = c_uint;
55+
pub type suseconds_t = c_int;
4256

43-
pub type suseconds_t = i64;
57+
pub type clock_t = c_long;
58+
pub type clockid_t = c_int;
59+
pub type timer_t = *mut c_void;
60+
61+
pub type nfds_t = c_ulong;
4462

4563
s! {
64+
pub struct fd_set {
65+
fds_bits: [::c_ulong; FD_SETSIZE / ULONG_SIZE],
66+
}
67+
68+
pub struct pollfd {
69+
pub fd: ::c_int,
70+
pub events: ::c_short,
71+
pub revents: ::c_short,
72+
}
73+
74+
pub struct stat {
75+
pub st_dev: ::dev_t,
76+
pub st_ino: ::ino_t,
77+
pub st_nlink: ::nlink_t,
78+
pub st_mode: ::mode_t,
79+
pub st_uid: ::uid_t,
80+
pub st_gid: ::gid_t,
81+
pub st_rdev: ::dev_t,
82+
pub st_size: ::off_t,
83+
pub st_blksize: ::blksize_t,
84+
pub st_blocks: ::blkcnt_t,
85+
86+
pub st_atime: ::timespec,
87+
pub st_mtime: ::timespec,
88+
pub st_ctime: ::timespec,
89+
90+
_pad: [c_char; 24],
91+
}
92+
4693
pub struct timeval {
4794
pub tv_sec: time_t,
4895
pub tv_usec: suseconds_t,
@@ -64,6 +111,27 @@ pub const STDERR_FILENO: ::c_int = 2;
64111
pub const EXIT_FAILURE: ::c_int = 1;
65112
pub const EXIT_SUCCESS: ::c_int = 0;
66113

114+
pub const FD_SETSIZE: usize = 1024;
115+
116+
pub const MAP_SHARED: ::c_int = 1;
117+
pub const MAP_PRIVATE: ::c_int = 2;
118+
pub const MAP_ANONYMOUS: ::c_int = 4;
119+
pub const MAP_ANON: ::c_int = MAP_ANONYMOUS;
120+
121+
pub const MAP_FAILED: *mut ::c_void = !0 as *mut ::c_void;
122+
123+
pub const POLLIN: ::c_short = 0x001;
124+
pub const POLLPRI: ::c_short = 0x002;
125+
pub const POLLOUT: ::c_short = 0x004;
126+
pub const POLLERR: ::c_short = 0x008;
127+
pub const POLLHUP: ::c_short = 0x010;
128+
pub const POLLNVAL: ::c_short = 0x020;
129+
130+
pub const PROT_NONE: ::c_int = 0;
131+
pub const PROT_EXEC: ::c_int = 1;
132+
pub const PROT_WRITE: ::c_int = 2;
133+
pub const PROT_READ: ::c_int = 4;
134+
67135
pub const S_ISUID: ::c_int = 0x800;
68136
pub const S_ISGID: ::c_int = 0x400;
69137
pub const S_ISVTX: ::c_int = 0x200;
@@ -98,6 +166,8 @@ pub const F_SETFD: ::c_int = 2;
98166
pub const F_GETFL: ::c_int = 3;
99167
pub const F_SETFL: ::c_int = 4;
100168

169+
pub const FD_CLOEXEC: ::c_int = 0x0100_0000;
170+
101171
pub const O_RDONLY: ::c_int = 0x0001_0000;
102172
pub const O_WRONLY: ::c_int = 0x0002_0000;
103173
pub const O_RDWR: ::c_int = 0x0003_0000;
@@ -152,6 +222,17 @@ pub const SIGSYS: ::c_int = 31;
152222
pub enum FILE {}
153223
pub enum fpos_t {} // TODO: fill this out with a struct
154224

225+
// intentionally not public, only used for fd_set
226+
cfg_if! {
227+
if #[cfg(target_pointer_width = "32")] {
228+
const ULONG_SIZE: usize = 32;
229+
} else if #[cfg(target_pointer_width = "64")] {
230+
const ULONG_SIZE: usize = 64;
231+
} else {
232+
// Unknown target_pointer_width
233+
}
234+
}
235+
155236
extern {
156237
pub fn isalnum(c: c_int) -> c_int;
157238
pub fn isalpha(c: c_int) -> c_int;
@@ -262,9 +343,22 @@ extern {
262343
pub fn close(fd: ::c_int) -> ::c_int;
263344
pub fn fchown(fd: ::c_int, uid: ::uid_t, gid: ::gid_t) -> ::c_int;
264345
pub fn fcntl(fd: ::c_int, cmd: ::c_int, ...) -> ::c_int;
346+
pub fn fstat(fd: ::c_int, buf: *mut stat) -> ::c_int;
347+
pub fn fsync(fd: ::c_int) -> ::c_int;
265348
pub fn gethostname(name: *mut ::c_char, len: ::size_t) -> ::c_int;
266349
pub fn getpid() -> pid_t;
267350
pub fn memalign(align: ::size_t, size: ::size_t) -> *mut ::c_void;
351+
pub fn mmap(addr: *mut ::c_void,
352+
len: ::size_t,
353+
prot: ::c_int,
354+
flags: ::c_int,
355+
fd: ::c_int,
356+
offset: off_t)
357+
-> *mut ::c_void;
358+
pub fn mprotect(addr: *mut ::c_void, len: ::size_t, prot: ::c_int)
359+
-> ::c_int;
360+
pub fn munmap(addr: *mut ::c_void, len: ::size_t) -> ::c_int;
361+
pub fn poll(fds: *mut pollfd, nfds: nfds_t, timeout: ::c_int) -> ::c_int;
268362
pub fn read(fd: ::c_int, buf: *mut ::c_void, count: ::size_t) -> ::ssize_t;
269363
pub fn setenv(name: *const c_char, val: *const c_char, overwrite: ::c_int)
270364
-> ::c_int;

0 commit comments

Comments
 (0)