Delete duplicate types
Now that we use cbindgen differently :D
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use header::time::sigevent;
|
||||
use header::time::{timespec, sigevent};
|
||||
use platform::types::*;
|
||||
|
||||
pub struct aiocb {
|
||||
|
||||
@@ -4,10 +4,12 @@ use core::str::FromStr;
|
||||
use core::{ptr, slice, str};
|
||||
|
||||
use header::errno::*;
|
||||
use header::netinet_in::in_addr;
|
||||
use platform;
|
||||
use header::netinet_in::{in_addr, in_addr_t};
|
||||
use header::sys_socket::constants::*;
|
||||
use header::sys_socket::socklen_t;
|
||||
use platform::c_str;
|
||||
use platform::types::*;
|
||||
use platform;
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn htonl(hostlong: u32) -> u32 {
|
||||
|
||||
@@ -68,7 +68,7 @@ pub unsafe extern "C" fn readdir(dir: *mut DIR) -> *mut dirent {
|
||||
if (*dir).index >= (*dir).len {
|
||||
let read = Sys::getdents(
|
||||
(*dir).fd,
|
||||
(*dir).buf.as_mut_ptr() as *mut platform::types::dirent,
|
||||
(*dir).buf.as_mut_ptr() as *mut dirent,
|
||||
(*dir).buf.len(),
|
||||
);
|
||||
if read <= 0 {
|
||||
|
||||
@@ -21,15 +21,16 @@ use platform::c_str;
|
||||
|
||||
use self::dns::{Dns, DnsQuery};
|
||||
|
||||
use header::arpa_inet::{htons, ntohs, inet_aton};
|
||||
use header::arpa_inet::{htons, inet_aton};
|
||||
use header::errno::*;
|
||||
use header::fcntl::O_RDONLY;
|
||||
use header::netinet_in::{in_addr, IPPROTO_UDP, sockaddr_in};
|
||||
use header::stdlib::atoi;
|
||||
use header::strings::strcasecmp;
|
||||
use header::sys_socket;
|
||||
use header::sys_socket::{sockaddr, socklen_t};
|
||||
use header::sys_socket::constants::{SOCK_DGRAM, AF_INET};
|
||||
use header::sys_socket::{sockaddr, socklen_t};
|
||||
use header::sys_socket;
|
||||
use header::time::timespec;
|
||||
use header::time;
|
||||
use header::unistd::SEEK_SET;
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
//! pwd implementation for relibc
|
||||
|
||||
use alloc::vec::Vec;
|
||||
use core::ptr;
|
||||
|
||||
use c_str::CStr;
|
||||
@@ -8,7 +7,7 @@ use header::{errno, fcntl};
|
||||
use platform;
|
||||
use platform::types::*;
|
||||
use platform::{Line, RawFile, RawLineBuffer};
|
||||
use platform::{Pal, Sys};
|
||||
use platform::Sys;
|
||||
|
||||
#[repr(C)]
|
||||
pub struct passwd {
|
||||
|
||||
@@ -23,7 +23,6 @@ pub const SIG_BLOCK: c_int = 0;
|
||||
pub const SIG_UNBLOCK: c_int = 1;
|
||||
pub const SIG_SETMASK: c_int = 2;
|
||||
|
||||
// Need both here and in platform because cbindgen :(
|
||||
#[repr(C)]
|
||||
#[derive(Clone)]
|
||||
pub struct sigaction {
|
||||
@@ -66,11 +65,11 @@ pub unsafe extern "C" fn sigaction(
|
||||
let ptr = if !act.is_null() {
|
||||
_sigaction = Some((*act).clone());
|
||||
_sigaction.as_mut().unwrap().sa_flags |= SA_RESTORER as c_ulong;
|
||||
_sigaction.as_mut().unwrap() as *mut _ as *mut platform::types::sigaction
|
||||
_sigaction.as_mut().unwrap() as *mut _
|
||||
} else {
|
||||
ptr::null_mut()
|
||||
};
|
||||
Sys::sigaction(sig, ptr, oact as *mut platform::types::sigaction)
|
||||
Sys::sigaction(sig, ptr, oact)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
||||
@@ -11,6 +11,7 @@ use header::errno::*;
|
||||
use header::fcntl::*;
|
||||
use header::string::*;
|
||||
use header::time::constants::CLOCK_MONOTONIC;
|
||||
use header::time::timespec;
|
||||
use header::wchar::*;
|
||||
use header::{ctype, errno, unistd};
|
||||
use platform;
|
||||
|
||||
@@ -12,19 +12,20 @@ pub struct sgttyb {
|
||||
sg_flags: c_ushort,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Default)]
|
||||
pub struct winsize {
|
||||
ws_row: c_ushort,
|
||||
ws_col: c_ushort,
|
||||
ws_xpixel: c_ushort,
|
||||
ws_ypixel: c_ushort,
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
pub mod inner {
|
||||
use platform::types::*;
|
||||
use platform::{Pal, Sys};
|
||||
|
||||
#[repr(C)]
|
||||
pub struct winsize {
|
||||
ws_row: c_ushort,
|
||||
ws_col: c_ushort,
|
||||
ws_xpixel: c_ushort,
|
||||
ws_ypixel: c_ushort,
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn ioctl(fd: c_int, request: c_ulong, out: *mut c_void) -> c_int {
|
||||
// TODO: Somehow support varargs to syscall??
|
||||
|
||||
@@ -52,7 +52,7 @@ pub unsafe extern "C" fn getrlimit(resource: c_int, rlp: *mut rlimit) -> c_int {
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn getrusage(who: c_int, r_usage: *mut rusage) -> c_int {
|
||||
Sys::getrusage(who, r_usage as *mut platform::types::rusage)
|
||||
Sys::getrusage(who, r_usage)
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
|
||||
@@ -5,3 +5,8 @@ style = "Tag"
|
||||
|
||||
[enum]
|
||||
prefix_with_name = true
|
||||
|
||||
[export]
|
||||
# fd_set is also defined in C because cbindgen is incompatible with mem::size_of booo
|
||||
|
||||
exclude = ["FD_SETSIZE", "fd_set"]
|
||||
|
||||
@@ -1,9 +1,18 @@
|
||||
//! sys/select.h implementation
|
||||
|
||||
use core::mem;
|
||||
use header::sys_time::timeval;
|
||||
use platform::types::*;
|
||||
use platform::{Pal, Sys};
|
||||
|
||||
// fd_set is defined in C because cbindgen is incompatible with mem::size_of booo
|
||||
// fd_set is also defined in C because cbindgen is incompatible with mem::size_of booo
|
||||
|
||||
pub const FD_SETSIZE: usize = 1024;
|
||||
|
||||
#[repr(C)]
|
||||
pub struct fd_set {
|
||||
pub fds_bits: [c_ulong; FD_SETSIZE / (8 * mem::size_of::<c_ulong>())],
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn select(
|
||||
|
||||
@@ -2,14 +2,11 @@
|
||||
|
||||
use core::ptr;
|
||||
|
||||
use platform;
|
||||
use platform::types::*;
|
||||
use platform::{PalSocket, Sys};
|
||||
|
||||
pub mod constants;
|
||||
|
||||
pub type in_addr_t = [u8; 4];
|
||||
pub type in_port_t = u16;
|
||||
pub type sa_family_t = u16;
|
||||
pub type socklen_t = u32;
|
||||
|
||||
@@ -17,7 +14,7 @@ pub type socklen_t = u32;
|
||||
#[derive(Default)]
|
||||
pub struct sockaddr {
|
||||
pub sa_family: sa_family_t,
|
||||
data: [c_char; 14],
|
||||
pub data: [c_char; 14],
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -28,7 +25,7 @@ pub unsafe extern "C" fn accept(
|
||||
) -> c_int {
|
||||
Sys::accept(
|
||||
socket,
|
||||
address as *mut platform::types::sockaddr,
|
||||
address,
|
||||
address_len,
|
||||
)
|
||||
}
|
||||
@@ -41,7 +38,7 @@ pub unsafe extern "C" fn bind(
|
||||
) -> c_int {
|
||||
Sys::bind(
|
||||
socket,
|
||||
address as *const platform::types::sockaddr,
|
||||
address,
|
||||
address_len,
|
||||
)
|
||||
}
|
||||
@@ -54,7 +51,7 @@ pub unsafe extern "C" fn connect(
|
||||
) -> c_int {
|
||||
Sys::connect(
|
||||
socket,
|
||||
address as *const platform::types::sockaddr,
|
||||
address,
|
||||
address_len,
|
||||
)
|
||||
}
|
||||
@@ -67,7 +64,7 @@ pub unsafe extern "C" fn getpeername(
|
||||
) -> c_int {
|
||||
Sys::getpeername(
|
||||
socket,
|
||||
address as *mut platform::types::sockaddr,
|
||||
address,
|
||||
address_len,
|
||||
)
|
||||
}
|
||||
@@ -80,7 +77,7 @@ pub unsafe extern "C" fn getsockname(
|
||||
) -> c_int {
|
||||
Sys::getsockname(
|
||||
socket,
|
||||
address as *mut platform::types::sockaddr,
|
||||
address,
|
||||
address_len,
|
||||
)
|
||||
}
|
||||
@@ -132,7 +129,7 @@ pub unsafe extern "C" fn recvfrom(
|
||||
buffer,
|
||||
length,
|
||||
flags,
|
||||
address as *mut platform::types::sockaddr,
|
||||
address,
|
||||
address_len,
|
||||
)
|
||||
}
|
||||
@@ -161,7 +158,7 @@ pub unsafe extern "C" fn sendto(
|
||||
message,
|
||||
length,
|
||||
flags,
|
||||
dest_addr as *const platform::types::sockaddr,
|
||||
dest_addr,
|
||||
dest_len,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
use c_str::CStr;
|
||||
use header::fcntl::{O_NOFOLLOW, O_PATH};
|
||||
use header::time::timespec;
|
||||
use platform;
|
||||
use platform::types::*;
|
||||
use platform::{Pal, Sys};
|
||||
@@ -35,6 +36,7 @@ pub const S_ISGID: c_int = 0o2000;
|
||||
pub const S_ISVTX: c_int = 0o1000;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Default)]
|
||||
pub struct stat {
|
||||
pub st_dev: dev_t,
|
||||
pub st_ino: ino_t,
|
||||
@@ -69,12 +71,12 @@ pub extern "C" fn fchmod(fildes: c_int, mode: mode_t) -> c_int {
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn fstat(fildes: c_int, buf: *mut platform::types::stat) -> c_int {
|
||||
pub extern "C" fn fstat(fildes: c_int, buf: *mut stat) -> c_int {
|
||||
Sys::fstat(fildes, buf)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn __fxstat(_ver: c_int, fildes: c_int, buf: *mut platform::types::stat) -> c_int {
|
||||
pub extern "C" fn __fxstat(_ver: c_int, fildes: c_int, buf: *mut stat) -> c_int {
|
||||
fstat(fildes, buf)
|
||||
}
|
||||
|
||||
@@ -84,7 +86,7 @@ pub extern "C" fn futimens(fd: c_int, times: *const timespec) -> c_int {
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn lstat(path: *const c_char, buf: *mut platform::types::stat) -> c_int {
|
||||
pub extern "C" fn lstat(path: *const c_char, buf: *mut stat) -> c_int {
|
||||
let path = unsafe { CStr::from_ptr(path) };
|
||||
let fd = Sys::open(path, O_PATH | O_NOFOLLOW, 0);
|
||||
if fd < 0 {
|
||||
@@ -116,7 +118,7 @@ pub extern "C" fn mknod(path: *const c_char, mode: mode_t, dev: dev_t) -> c_int
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn stat(file: *const c_char, buf: *mut platform::types::stat) -> c_int {
|
||||
pub extern "C" fn stat(file: *const c_char, buf: *mut stat) -> c_int {
|
||||
let file = unsafe { CStr::from_ptr(file) };
|
||||
let fd = Sys::open(file, O_PATH, 0);
|
||||
if fd < 0 {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
//! sys/time implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/systime.h.html
|
||||
|
||||
use c_str::CStr;
|
||||
use platform;
|
||||
use platform::types::*;
|
||||
use platform::{Pal, Sys};
|
||||
use header::time::timespec;
|
||||
|
||||
pub const ITIMER_REAL: c_int = 0;
|
||||
pub const ITIMER_VIRTUAL: c_int = 1;
|
||||
@@ -35,7 +35,7 @@ pub struct fd_set {
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn getitimer(which: c_int, value: *mut itimerval) -> c_int {
|
||||
Sys::getitimer(which, value as *mut platform::types::itimerval)
|
||||
Sys::getitimer(which, value)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -46,16 +46,16 @@ pub extern "C" fn setitimer(
|
||||
) -> c_int {
|
||||
Sys::setitimer(
|
||||
which,
|
||||
value as *const platform::types::itimerval,
|
||||
ovalue as *mut platform::types::itimerval,
|
||||
value,
|
||||
ovalue,
|
||||
)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn gettimeofday(tp: *mut timeval, tzp: *mut timezone) -> c_int {
|
||||
Sys::gettimeofday(
|
||||
tp as *mut platform::types::timeval,
|
||||
tzp as *mut platform::types::timezone,
|
||||
tp,
|
||||
tzp,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -14,5 +14,5 @@ pub struct tms {
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn times(out: *mut tms) -> clock_t {
|
||||
Sys::times(out as *mut platform::types::tms)
|
||||
Sys::times(out)
|
||||
}
|
||||
|
||||
@@ -1,26 +1,27 @@
|
||||
//! sys/utsname implementation for linux, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/sysutsname.h.html
|
||||
|
||||
use platform::types::*;
|
||||
|
||||
pub const UTSLENGTH: usize = 65;
|
||||
|
||||
#[repr(C)]
|
||||
pub struct utsname {
|
||||
pub sysname: [c_char; UTSLENGTH],
|
||||
pub nodename: [c_char; UTSLENGTH],
|
||||
pub release: [c_char; UTSLENGTH],
|
||||
pub version: [c_char; UTSLENGTH],
|
||||
pub machine: [c_char; UTSLENGTH],
|
||||
pub domainname: [c_char; UTSLENGTH],
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
mod inner {
|
||||
use platform;
|
||||
use platform::types::*;
|
||||
use platform::{Pal, Sys};
|
||||
|
||||
const UTSLENGTH: usize = 65;
|
||||
|
||||
#[repr(C)]
|
||||
pub struct utsname {
|
||||
pub sysname: [c_char; UTSLENGTH],
|
||||
pub nodename: [c_char; UTSLENGTH],
|
||||
pub release: [c_char; UTSLENGTH],
|
||||
pub version: [c_char; UTSLENGTH],
|
||||
pub machine: [c_char; UTSLENGTH],
|
||||
pub domainname: [c_char; UTSLENGTH],
|
||||
}
|
||||
use super::*;
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn uname(uts: *mut utsname) -> c_int {
|
||||
Sys::uname(uts as *mut platform::types::utsname)
|
||||
Sys::uname(uts)
|
||||
}
|
||||
}
|
||||
#[cfg(target_os = "linux")]
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
//! termios implementation, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/termios.h.html
|
||||
|
||||
use platform;
|
||||
use platform::types::*;
|
||||
use platform::{Pal, Sys};
|
||||
|
||||
@@ -24,12 +23,12 @@ pub struct termios {
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn tcgetattr(fd: c_int, out: *mut termios) -> c_int {
|
||||
Sys::tcgetattr(fd, out as *mut platform::types::termios)
|
||||
Sys::tcgetattr(fd, out)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn tcsetattr(fd: c_int, act: c_int, value: *mut termios) -> c_int {
|
||||
Sys::tcsetattr(fd, act, value as *mut platform::types::termios)
|
||||
Sys::tcsetattr(fd, act, value)
|
||||
}
|
||||
|
||||
pub const VINTR: usize = 0;
|
||||
|
||||
+15
-4
@@ -15,11 +15,22 @@ mod helpers;
|
||||
mod strftime;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Default)]
|
||||
pub struct timespec {
|
||||
pub tv_sec: time_t,
|
||||
pub tv_nsec: c_long,
|
||||
}
|
||||
|
||||
#[cfg(target_os = "redox")]
|
||||
impl<'a> From<&'a timespec> for syscall::TimeSpec {
|
||||
fn from(tp: ×pec) -> Self {
|
||||
Self {
|
||||
tv_sec: tp.tv_sec,
|
||||
tv_nsec: tp.tv_nsec as i32,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct tm {
|
||||
pub tm_sec: c_int,
|
||||
@@ -118,7 +129,7 @@ pub extern "C" fn clock_getres(clock_id: clockid_t, res: *mut timespec) -> c_int
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn clock_gettime(clock_id: clockid_t, tp: *mut timespec) -> c_int {
|
||||
Sys::clock_gettime(clock_id, tp as *mut platform::types::timespec)
|
||||
Sys::clock_gettime(clock_id, tp)
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
@@ -326,8 +337,8 @@ pub unsafe extern "C" fn mktime(t: *mut tm) -> time_t {
|
||||
#[no_mangle]
|
||||
pub extern "C" fn nanosleep(rqtp: *const timespec, rmtp: *mut timespec) -> c_int {
|
||||
Sys::nanosleep(
|
||||
rqtp as *const platform::types::timespec,
|
||||
rmtp as *mut platform::types::timespec,
|
||||
rqtp,
|
||||
rmtp,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -357,7 +368,7 @@ pub extern "C" fn strptime(buf: *const c_char, format: *const c_char, tm: *mut t
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn time(tloc: *mut time_t) -> time_t {
|
||||
let mut ts: platform::types::timespec = Default::default();
|
||||
let mut ts = timespec::default();
|
||||
Sys::clock_gettime(CLOCK_REALTIME, &mut ts);
|
||||
unsafe {
|
||||
if !tloc.is_null() {
|
||||
|
||||
@@ -7,6 +7,7 @@ use header::sys_time;
|
||||
use platform;
|
||||
use platform::types::*;
|
||||
use platform::{Pal, Sys};
|
||||
use header::time::timespec;
|
||||
|
||||
pub use self::brk::*;
|
||||
pub use self::getopt::*;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
//! utime implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/utime.h.html
|
||||
|
||||
use c_str::CStr;
|
||||
use header::time::timespec;
|
||||
use platform::types::*;
|
||||
use platform::{Pal, Sys};
|
||||
|
||||
|
||||
@@ -4,19 +4,22 @@ use core::{mem, ptr};
|
||||
use super::types::*;
|
||||
use super::{errno, FileWriter, Pal};
|
||||
use c_str::CStr;
|
||||
use header::dirent::dirent;
|
||||
use header::errno::{EINVAL, ENOSYS};
|
||||
use header::signal::SIGCHLD;
|
||||
use header::sys_resource::rusage;
|
||||
use header::sys_select::fd_set;
|
||||
use header::sys_stat::stat;
|
||||
use header::sys_time::{itimerval, timeval, timezone};
|
||||
use header::sys_times::tms;
|
||||
use header::sys_utsname::utsname;
|
||||
use header::sys_ioctl::{winsize, TCGETS, TCSETS, TIOCGWINSZ};
|
||||
use header::termios::termios;
|
||||
use header::time::timespec;
|
||||
|
||||
mod signal;
|
||||
mod socket;
|
||||
|
||||
const EINVAL: c_int = 22;
|
||||
const ENOSYS: c_int = 38;
|
||||
|
||||
const SIGCHLD: usize = 17;
|
||||
|
||||
const TCGETS: c_ulong = 0x5401;
|
||||
const TCSETS: c_ulong = 0x5402;
|
||||
const TIOCGWINSZ: c_ulong = 0x5413;
|
||||
|
||||
const AT_FDCWD: c_int = -100;
|
||||
const AT_EMPTY_PATH: c_int = 0x1000;
|
||||
const AT_REMOVEDIR: c_int = 0x200;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use core::mem;
|
||||
|
||||
use header::signal::{sigaction, sigset_t};
|
||||
use super::super::types::*;
|
||||
use super::super::PalSignal;
|
||||
use super::{e, Sys};
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use header::sys_socket::{sockaddr, socklen_t};
|
||||
use super::super::types::*;
|
||||
use super::super::PalSocket;
|
||||
use super::{e, Sys};
|
||||
|
||||
@@ -2,6 +2,15 @@ use core::ptr;
|
||||
|
||||
use super::types::*;
|
||||
use c_str::CStr;
|
||||
use header::dirent::dirent;
|
||||
use header::sys_resource::rusage;
|
||||
use header::sys_select::fd_set;
|
||||
use header::sys_stat::stat;
|
||||
use header::sys_time::{itimerval, timeval, timezone};
|
||||
use header::sys_times::tms;
|
||||
use header::sys_utsname::utsname;
|
||||
use header::termios::termios;
|
||||
use header::time::timespec;
|
||||
|
||||
pub use self::signal::PalSignal;
|
||||
mod signal;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use header::signal::{sigaction, sigset_t};
|
||||
use super::super::types::*;
|
||||
use super::super::Pal;
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use header::sys_socket::{sockaddr, socklen_t};
|
||||
use super::super::types::*;
|
||||
use super::super::Pal;
|
||||
|
||||
|
||||
@@ -9,17 +9,26 @@ use syscall::data::TimeSpec as redox_timespec;
|
||||
use syscall::flag::*;
|
||||
use syscall::{self, Result};
|
||||
|
||||
use c_str::{CStr, CString};
|
||||
use header::dirent::dirent;
|
||||
use header::errno::{EINVAL, ENOSYS};
|
||||
use header::sys_mman::MAP_ANON;
|
||||
use header::sys_resource::rusage;
|
||||
use header::sys_select::fd_set;
|
||||
use header::sys_stat::stat;
|
||||
use header::sys_time::{itimerval, timeval, timezone};
|
||||
use header::sys_times::tms;
|
||||
use header::sys_utsname::utsname;
|
||||
use header::termios::termios;
|
||||
use header::time::timespec;
|
||||
use header::unistd::{F_OK, R_OK, W_OK, X_OK};
|
||||
|
||||
use super::types::*;
|
||||
use super::{errno, FileReader, FileWriter, Pal, RawFile, Read};
|
||||
use c_str::{CStr, CString};
|
||||
|
||||
mod signal;
|
||||
mod socket;
|
||||
|
||||
const EINVAL: c_int = 22;
|
||||
const ENOSYS: c_int = 38;
|
||||
const MAP_ANON: c_int = 1;
|
||||
|
||||
static ANONYMOUS_MAPS: Once<Mutex<BTreeMap<usize, usize>>> = Once::new();
|
||||
|
||||
fn anonymous_maps() -> MutexGuard<'static, BTreeMap<usize, usize>> {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use syscall;
|
||||
|
||||
use header::signal::{sigaction, sigset_t};
|
||||
use super::super::types::*;
|
||||
use super::super::{Pal, PalSignal};
|
||||
use super::{e, Sys};
|
||||
|
||||
@@ -2,6 +2,9 @@ use core::{mem, ptr, slice};
|
||||
use syscall::flag::*;
|
||||
use syscall::{self, Result};
|
||||
|
||||
use header::netinet_in::{in_addr_t, in_port_t, sockaddr_in};
|
||||
use header::sys_socket::constants::*;
|
||||
use header::sys_socket::{sockaddr, socklen_t};
|
||||
use super::super::types::*;
|
||||
use super::super::{errno, Pal, PalSocket};
|
||||
use super::{e, Sys};
|
||||
@@ -23,9 +26,16 @@ macro_rules! bind_or_connect {
|
||||
return -1;
|
||||
}
|
||||
let data = &*($address as *const sockaddr_in);
|
||||
let addr = &data.sin_addr.s_addr;
|
||||
let port = in_port_t::from_be(data.sin_port); // This is transmuted from bytes in BigEndian order
|
||||
let path = format!(bind_or_connect!($mode "{}.{}.{}.{}:{}"), addr[0], addr[1], addr[2], addr[3], port);
|
||||
let addr = data.sin_addr.s_addr;
|
||||
let port = data.sin_port;
|
||||
let path = format!(
|
||||
bind_or_connect!($mode "{}.{}.{}.{}:{}"),
|
||||
addr >> 8*3,
|
||||
addr >> 8*2 & 0xFF,
|
||||
addr >> 8 & 0xFF,
|
||||
addr & 0xFF,
|
||||
port
|
||||
);
|
||||
|
||||
// Duplicate the socket, and then duplicate the copy back to the original fd
|
||||
let fd = e(syscall::dup($socket as usize, path.as_bytes()));
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
use core::mem;
|
||||
#[cfg(target_os = "redox")]
|
||||
use syscall::data::TimeSpec as redox_timespec;
|
||||
// Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help enable
|
||||
// more optimization opportunities around it recognizing things like
|
||||
// malloc/free.
|
||||
@@ -68,195 +65,3 @@ pub type suseconds_t = c_int;
|
||||
pub type clock_t = c_long;
|
||||
pub type clockid_t = c_int;
|
||||
pub type timer_t = *mut c_void;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Default)]
|
||||
pub struct timespec {
|
||||
pub tv_sec: time_t,
|
||||
pub tv_nsec: c_long,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Default)]
|
||||
pub struct timeval {
|
||||
pub tv_sec: time_t,
|
||||
pub tv_usec: suseconds_t,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Default)]
|
||||
pub struct timezone {
|
||||
pub tz_minuteswest: c_int,
|
||||
pub tz_dsttime: c_int,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Default)]
|
||||
pub struct itimerval {
|
||||
pub it_interval: timeval,
|
||||
pub it_value: timeval,
|
||||
}
|
||||
|
||||
#[cfg(target_os = "redox")]
|
||||
impl<'a> From<&'a timespec> for redox_timespec {
|
||||
fn from(tp: ×pec) -> redox_timespec {
|
||||
redox_timespec {
|
||||
tv_sec: tp.tv_sec,
|
||||
tv_nsec: tp.tv_nsec as i32,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Default)]
|
||||
pub struct stat {
|
||||
pub st_dev: dev_t,
|
||||
pub st_ino: ino_t,
|
||||
pub st_nlink: nlink_t,
|
||||
pub st_mode: mode_t,
|
||||
pub st_uid: uid_t,
|
||||
pub st_gid: gid_t,
|
||||
pub st_rdev: dev_t,
|
||||
pub st_size: off_t,
|
||||
pub st_blksize: blksize_t,
|
||||
pub st_blocks: blkcnt_t,
|
||||
|
||||
pub st_atim: timespec,
|
||||
pub st_mtim: timespec,
|
||||
pub st_ctim: timespec,
|
||||
|
||||
// Compared to glibc, our struct is for some reason 24 bytes too small.
|
||||
// Accessing atime works, so clearly the struct isn't incorrect...
|
||||
// This works.
|
||||
pub _pad: [c_char; 24],
|
||||
}
|
||||
|
||||
pub const AF_INET: c_int = 2;
|
||||
pub const SOCK_STREAM: c_int = 1;
|
||||
pub const SOCK_DGRAM: c_int = 2;
|
||||
pub const SOCK_NONBLOCK: c_int = 0o4000;
|
||||
pub const SOCK_CLOEXEC: c_int = 0o2000000;
|
||||
|
||||
pub const SIG_BLOCK: c_int = 0;
|
||||
pub const SIG_UNBLOCK: c_int = 1;
|
||||
pub const SIG_SETMASK: c_int = 2;
|
||||
|
||||
pub type in_addr_t = [u8; 4];
|
||||
pub type in_port_t = u16;
|
||||
pub type sa_family_t = u16;
|
||||
pub type socklen_t = u32;
|
||||
|
||||
#[repr(C)]
|
||||
pub struct sockaddr {
|
||||
pub sa_family: sa_family_t,
|
||||
pub data: [c_char; 14],
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct in_addr {
|
||||
pub s_addr: in_addr_t,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct sockaddr_in {
|
||||
pub sin_family: sa_family_t,
|
||||
pub sin_port: in_port_t,
|
||||
pub sin_addr: in_addr,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct sigaction {
|
||||
pub sa_handler: Option<extern "C" fn(c_int)>,
|
||||
pub sa_flags: c_ulong,
|
||||
pub sa_restorer: Option<unsafe extern "C" fn()>,
|
||||
pub sa_mask: sigset_t,
|
||||
}
|
||||
|
||||
pub type sigset_t = c_ulong;
|
||||
|
||||
const UTSLENGTH: usize = 65;
|
||||
|
||||
#[repr(C)]
|
||||
pub struct utsname {
|
||||
pub sysname: [c_char; UTSLENGTH],
|
||||
pub nodename: [c_char; UTSLENGTH],
|
||||
pub release: [c_char; UTSLENGTH],
|
||||
pub version: [c_char; UTSLENGTH],
|
||||
pub machine: [c_char; UTSLENGTH],
|
||||
pub domainname: [c_char; UTSLENGTH],
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct dirent {
|
||||
pub d_ino: ino_t,
|
||||
pub d_off: off_t,
|
||||
pub d_reclen: c_ushort,
|
||||
pub d_type: c_uchar,
|
||||
pub d_name: [c_char; 256],
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Default)]
|
||||
pub struct winsize {
|
||||
ws_row: c_ushort,
|
||||
ws_col: c_ushort,
|
||||
ws_xpixel: c_ushort,
|
||||
ws_ypixel: c_ushort,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct rusage {
|
||||
pub ru_utime: timeval,
|
||||
pub ru_stime: timeval,
|
||||
pub ru_maxrss: c_long,
|
||||
pub ru_ixrss: c_long,
|
||||
pub ru_idrss: c_long,
|
||||
pub ru_isrss: c_long,
|
||||
pub ru_minflt: c_long,
|
||||
pub ru_majflt: c_long,
|
||||
pub ru_nswap: c_long,
|
||||
pub ru_inblock: c_long,
|
||||
pub ru_oublock: c_long,
|
||||
pub ru_msgsnd: c_long,
|
||||
pub ru_msgrcv: c_long,
|
||||
pub ru_nsignals: c_long,
|
||||
pub ru_nvcsw: c_long,
|
||||
pub ru_nivcsw: c_long,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct tms {
|
||||
tms_utime: clock_t,
|
||||
tms_stime: clock_t,
|
||||
tms_cutime: clock_t,
|
||||
tms_cstime: clock_t,
|
||||
}
|
||||
|
||||
pub const FD_SETSIZE: usize = 1024;
|
||||
#[repr(C)]
|
||||
pub struct fd_set {
|
||||
pub fds_bits: [c_ulong; FD_SETSIZE / (8 * mem::size_of::<c_ulong>())],
|
||||
}
|
||||
|
||||
pub const F_OK: c_int = 0;
|
||||
pub const R_OK: c_int = 4;
|
||||
pub const W_OK: c_int = 2;
|
||||
pub const X_OK: c_int = 1;
|
||||
|
||||
pub type cc_t = u8;
|
||||
pub type speed_t = u32;
|
||||
pub type tcflag_t = u32;
|
||||
|
||||
pub const NCCS: usize = 32;
|
||||
|
||||
#[repr(C)]
|
||||
pub struct termios {
|
||||
c_iflag: tcflag_t,
|
||||
c_oflag: tcflag_t,
|
||||
c_cflag: tcflag_t,
|
||||
c_lflag: tcflag_t,
|
||||
c_line: cc_t,
|
||||
c_cc: [cc_t; NCCS],
|
||||
__c_ispeed: speed_t,
|
||||
__c_ospeed: speed_t,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user