From e6f163823c95e53969fbcca81dff32f3a2003e92 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Fri, 24 Aug 2018 20:13:07 -0600 Subject: [PATCH 01/19] WIP: platform abstraction layer --- src/platform/src/lib.rs | 4 + src/platform/src/linux/mod.rs | 859 +++++++++++++++++----------------- src/platform/src/pal.rs | 370 +++++++++++++++ src/sys_resource/src/lib.rs | 2 +- src/sys_times/src/lib.rs | 2 +- 5 files changed, 808 insertions(+), 429 deletions(-) create mode 100644 src/platform/src/pal.rs diff --git a/src/platform/src/lib.rs b/src/platform/src/lib.rs index 2a634a4eef..60331812ec 100644 --- a/src/platform/src/lib.rs +++ b/src/platform/src/lib.rs @@ -26,6 +26,10 @@ mod allocator; #[path = "allocator/ralloc.rs"] mod allocator; +pub use pal::Pal; + +mod pal; + pub use sys::*; #[cfg(all(not(feature = "no_std"), target_os = "linux"))] diff --git a/src/platform/src/linux/mod.rs b/src/platform/src/linux/mod.rs index 5446a52f1a..f1c941af36 100644 --- a/src/platform/src/linux/mod.rs +++ b/src/platform/src/linux/mod.rs @@ -1,5 +1,6 @@ use core::{mem, ptr}; +use Pal; use errno; use types::*; @@ -27,459 +28,463 @@ fn e(sys: usize) -> usize { } } -pub unsafe fn accept(socket: c_int, address: *mut sockaddr, address_len: *mut socklen_t) -> c_int { - e(syscall!(ACCEPT, socket, address, address_len)) as c_int -} +pub struct Sys; -pub fn access(path: *const c_char, mode: c_int) -> c_int { - e(unsafe { syscall!(ACCESS, path, mode) }) as c_int -} - -pub unsafe fn bind(socket: c_int, address: *const sockaddr, address_len: socklen_t) -> c_int { - e(syscall!(BIND, socket, address, address_len)) as c_int -} - -pub fn brk(addr: *mut c_void) -> *mut c_void { - unsafe { syscall!(BRK, addr) as *mut c_void } -} - -pub fn chdir(path: *const c_char) -> c_int { - e(unsafe { syscall!(CHDIR, path) }) as c_int -} - -pub fn chmod(path: *const c_char, mode: mode_t) -> c_int { - e(unsafe { syscall!(FCHMODAT, AT_FDCWD, path, mode, 0) }) as c_int -} - -pub fn chown(path: *const c_char, owner: uid_t, group: gid_t) -> c_int { - e(unsafe { syscall!(FCHOWNAT, AT_FDCWD, path, owner as u32, group as u32) }) as c_int -} - -pub fn close(fildes: c_int) -> c_int { - e(unsafe { syscall!(CLOSE, fildes) }) as c_int -} - -pub unsafe fn connect(socket: c_int, address: *const sockaddr, address_len: socklen_t) -> c_int { - e(syscall!(CONNECT, socket, address, address_len)) as c_int -} - -pub fn dup(fildes: c_int) -> c_int { - e(unsafe { syscall!(DUP, fildes) }) as c_int -} - -pub fn dup2(fildes: c_int, fildes2: c_int) -> c_int { - e(unsafe { syscall!(DUP3, fildes, fildes2, 0) }) as c_int -} - -pub fn execve(path: *const c_char, argv: *const *mut c_char, envp: *const *mut c_char) -> c_int { - e(unsafe { syscall!(EXECVE, path, argv, envp) }) as c_int -} - -pub fn exit(status: c_int) -> ! { - unsafe { - syscall!(EXIT, status); +impl Pal for Sys { + unsafe fn accept(socket: c_int, address: *mut sockaddr, address_len: *mut socklen_t) -> c_int { + e(syscall!(ACCEPT, socket, address, address_len)) as c_int } - loop {} -} -pub fn fchdir(fildes: c_int) -> c_int { - e(unsafe { syscall!(FCHDIR, fildes) }) as c_int -} - -pub fn fchmod(fildes: c_int, mode: mode_t) -> c_int { - e(unsafe { syscall!(FCHMOD, fildes, mode) }) as c_int -} - -pub fn fchown(fildes: c_int, owner: uid_t, group: gid_t) -> c_int { - e(unsafe { syscall!(FCHOWN, fildes, owner, group) }) as c_int -} - -pub fn flock(fd: c_int, operation: c_int) -> c_int { - e(unsafe { syscall!(FLOCK, fd, operation) }) as c_int -} - -pub fn fstat(fildes: c_int, buf: *mut stat) -> c_int { - let empty_cstr: *const c_char = unsafe { ::cstr_from_bytes_with_nul_unchecked(b"\0") }; - e(unsafe { syscall!(NEWFSTATAT, fildes, empty_cstr, buf, AT_EMPTY_PATH) }) as c_int -} - -pub fn fcntl(fildes: c_int, cmd: c_int, arg: c_int) -> c_int { - e(unsafe { syscall!(FCNTL, fildes, cmd, arg) }) as c_int -} - -pub fn fork() -> pid_t { - e(unsafe { syscall!(CLONE, SIGCHLD, 0) }) as pid_t -} - -pub fn fsync(fildes: c_int) -> c_int { - e(unsafe { syscall!(FSYNC, fildes) }) as c_int -} - -pub fn ftruncate(fildes: c_int, length: off_t) -> c_int { - e(unsafe { syscall!(FTRUNCATE, fildes, length) }) as c_int -} - -pub fn futimens(fd: c_int, times: *const timespec) -> c_int { - e(unsafe { syscall!(UTIMENSAT, fd, ptr::null::(), times, 0) }) as c_int -} - -pub fn utimens(path: *const c_char, times: *const timespec) -> c_int { - e(unsafe { syscall!(UTIMENSAT, AT_FDCWD, path, times, 0) }) as c_int -} - -pub fn getcwd(buf: *mut c_char, size: size_t) -> *mut c_char { - if e(unsafe { syscall!(GETCWD, buf, size) }) == !0 { - ptr::null_mut() - } else { - buf + fn access(path: *const c_char, mode: c_int) -> c_int { + e(unsafe { syscall!(ACCESS, path, mode) }) as c_int } -} -pub fn getdents(fd: c_int, dirents: *mut dirent, bytes: usize) -> c_int { - unsafe { syscall!(GETDENTS64, fd, dirents, bytes) as c_int } -} - -pub fn getegid() -> gid_t { - e(unsafe { syscall!(GETEGID) }) as gid_t -} - -pub fn geteuid() -> uid_t { - e(unsafe { syscall!(GETEUID) }) as uid_t -} - -pub fn getgid() -> gid_t { - e(unsafe { syscall!(GETGID) }) as gid_t -} - -pub fn getrusage(who: c_int, r_usage: *mut rusage) -> c_int { - e(unsafe { syscall!(GETRUSAGE, who, r_usage) }) as c_int -} - -pub unsafe fn gethostname(mut name: *mut c_char, len: size_t) -> c_int { - // len only needs to be mutable on linux - let mut len = len; - - let mut uts = mem::uninitialized(); - let err = uname(&mut uts); - if err < 0 { - mem::forget(uts); - return err; + unsafe fn bind(socket: c_int, address: *const sockaddr, address_len: socklen_t) -> c_int { + e(syscall!(BIND, socket, address, address_len)) as c_int } - for c in uts.nodename.iter() { - if len == 0 { - break; - } - len -= 1; - *name = *c; - - if *name == 0 { - // We do want to copy the zero also, so we check this after the copying. - break; - } - - name = name.offset(1); + fn brk(addr: *mut c_void) -> *mut c_void { + unsafe { syscall!(BRK, addr) as *mut c_void } } - 0 -} -pub fn getitimer(which: c_int, out: *mut itimerval) -> c_int { - e(unsafe { syscall!(GETITIMER, which, out) }) as c_int -} + fn chdir(path: *const c_char) -> c_int { + e(unsafe { syscall!(CHDIR, path) }) as c_int + } -pub unsafe fn getpeername( - socket: c_int, - address: *mut sockaddr, - address_len: *mut socklen_t, -) -> c_int { - e(syscall!(GETPEERNAME, socket, address, address_len)) as c_int -} + fn chmod(path: *const c_char, mode: mode_t) -> c_int { + e(unsafe { syscall!(FCHMODAT, AT_FDCWD, path, mode, 0) }) as c_int + } -pub fn getpgid(pid: pid_t) -> pid_t { - e(unsafe { syscall!(GETPGID, pid) }) as pid_t -} + fn chown(path: *const c_char, owner: uid_t, group: gid_t) -> c_int { + e(unsafe { syscall!(FCHOWNAT, AT_FDCWD, path, owner as u32, group as u32) }) as c_int + } -pub fn getpid() -> pid_t { - e(unsafe { syscall!(GETPID) }) as pid_t -} + fn clock_gettime(clk_id: clockid_t, tp: *mut timespec) -> c_int { + e(unsafe { syscall!(CLOCK_GETTIME, clk_id, tp) }) as c_int + } -pub fn getppid() -> pid_t { - e(unsafe { syscall!(GETPPID) }) as pid_t -} + fn close(fildes: c_int) -> c_int { + e(unsafe { syscall!(CLOSE, fildes) }) as c_int + } -pub unsafe fn getsockname( - socket: c_int, - address: *mut sockaddr, - address_len: *mut socklen_t, -) -> c_int { - e(syscall!(GETSOCKNAME, socket, address, address_len)) as c_int -} + unsafe fn connect(socket: c_int, address: *const sockaddr, address_len: socklen_t) -> c_int { + e(syscall!(CONNECT, socket, address, address_len)) as c_int + } -pub fn getsockopt( - socket: c_int, - level: c_int, - option_name: c_int, - option_value: *mut c_void, - option_len: *mut socklen_t, -) -> c_int { - e(unsafe { - syscall!( - GETSOCKOPT, - socket, - level, - option_name, - option_value, - option_len - ) - }) as c_int -} + fn dup(fildes: c_int) -> c_int { + e(unsafe { syscall!(DUP, fildes) }) as c_int + } -pub fn gettimeofday(tp: *mut timeval, tzp: *mut timezone) -> c_int { - e(unsafe { syscall!(GETTIMEOFDAY, tp, tzp) }) as c_int -} + fn dup2(fildes: c_int, fildes2: c_int) -> c_int { + e(unsafe { syscall!(DUP3, fildes, fildes2, 0) }) as c_int + } -pub fn getuid() -> uid_t { - e(unsafe { syscall!(GETUID) }) as uid_t -} + fn execve(path: *const c_char, argv: *const *mut c_char, envp: *const *mut c_char) -> c_int { + e(unsafe { syscall!(EXECVE, path, argv, envp) }) as c_int + } -pub fn ioctl(fd: c_int, request: c_ulong, out: *mut c_void) -> c_int { - // TODO: Somehow support varargs to syscall?? - e(unsafe { syscall!(IOCTL, fd, request, out) }) as c_int -} - -pub fn isatty(fd: c_int) -> c_int { - let mut winsize = winsize::default(); - (ioctl(fd, TIOCGWINSZ, &mut winsize as *mut _ as *mut c_void) == 0) as c_int -} - -pub fn kill(pid: pid_t, sig: c_int) -> c_int { - e(unsafe { syscall!(KILL, pid, sig) }) as c_int -} - -pub fn killpg(pgrp: pid_t, sig: c_int) -> c_int { - e(unsafe { syscall!(KILL, -(pgrp as isize) as pid_t, sig) }) as c_int -} - -pub fn link(path1: *const c_char, path2: *const c_char) -> c_int { - e(unsafe { syscall!(LINKAT, AT_FDCWD, path1, AT_FDCWD, path2, 0) }) as c_int -} - -pub fn listen(socket: c_int, backlog: c_int) -> c_int { - e(unsafe { syscall!(LISTEN, socket, backlog) }) as c_int -} - -pub fn lseek(fildes: c_int, offset: off_t, whence: c_int) -> off_t { - e(unsafe { syscall!(LSEEK, fildes, offset, whence) }) as off_t -} - -pub fn lstat(file: *const c_char, buf: *mut stat) -> c_int { - e(unsafe { syscall!(NEWFSTATAT, AT_FDCWD, file, buf, AT_SYMLINK_NOFOLLOW) }) as c_int -} - -pub fn mkdir(path: *const c_char, mode: mode_t) -> c_int { - e(unsafe { syscall!(MKDIRAT, AT_FDCWD, path, mode) }) as c_int -} - -pub fn mkfifo(path: *const c_char, mode: mode_t) -> c_int { - e(unsafe { syscall!(MKNODAT, AT_FDCWD, path, mode, 0) }) as c_int -} - -pub unsafe fn mmap( - addr: *mut c_void, - len: usize, - prot: c_int, - flags: c_int, - fildes: c_int, - off: off_t, -) -> *mut c_void { - e(syscall!(MMAP, addr, len, prot, flags, fildes, off)) as *mut c_void -} - -pub unsafe fn munmap(addr: *mut c_void, len: usize) -> c_int { - e(syscall!(MUNMAP, addr, len)) as c_int -} - -pub fn nanosleep(rqtp: *const timespec, rmtp: *mut timespec) -> c_int { - e(unsafe { syscall!(NANOSLEEP, rqtp, rmtp) }) as c_int -} - -pub fn open(path: *const c_char, oflag: c_int, mode: mode_t) -> c_int { - e(unsafe { syscall!(OPENAT, AT_FDCWD, path, oflag, mode) }) as c_int -} - -pub fn pipe(fildes: &mut [c_int]) -> c_int { - e(unsafe { syscall!(PIPE2, fildes.as_mut_ptr(), 0) }) as c_int -} - -pub fn raise(sig: c_int) -> c_int { - let tid = e(unsafe { syscall!(GETTID) }) as pid_t; - let ret = if tid == !0 { - -1 - } else { - e(unsafe { syscall!(TKILL, tid, sig) }) as c_int - }; - - ret -} - -pub fn read(fildes: c_int, buf: &mut [u8]) -> ssize_t { - e(unsafe { syscall!(READ, fildes, buf.as_mut_ptr(), buf.len()) }) as ssize_t -} - -pub unsafe fn recvfrom( - socket: c_int, - buf: *mut c_void, - len: size_t, - flags: c_int, - address: *mut sockaddr, - address_len: *mut socklen_t, -) -> ssize_t { - e(syscall!( - RECVFROM, - socket, - buf, - len, - flags, - address, - address_len - )) as ssize_t -} - -pub fn rename(old: *const c_char, new: *const c_char) -> c_int { - e(unsafe { syscall!(RENAMEAT, AT_FDCWD, old, AT_FDCWD, new) }) as c_int -} - -pub fn rmdir(path: *const c_char) -> c_int { - e(unsafe { syscall!(UNLINKAT, AT_FDCWD, path, AT_REMOVEDIR) }) as c_int -} - -pub fn select( - nfds: c_int, - readfds: *mut fd_set, - writefds: *mut fd_set, - exceptfds: *mut fd_set, - timeout: *mut timeval, -) -> c_int { - e(unsafe { syscall!(SELECT, nfds, readfds, writefds, exceptfds, timeout) }) as c_int -} - -pub unsafe fn sendto( - socket: c_int, - buf: *const c_void, - len: size_t, - flags: c_int, - dest_addr: *const sockaddr, - dest_len: socklen_t, -) -> ssize_t { - e(syscall!( - SENDTO, socket, buf, len, flags, dest_addr, dest_len - )) as ssize_t -} - -pub fn setitimer(which: c_int, new: *const itimerval, old: *mut itimerval) -> c_int { - e(unsafe { syscall!(SETITIMER, which, new, old) }) as c_int -} - -pub fn setpgid(pid: pid_t, pgid: pid_t) -> c_int { - e(unsafe { syscall!(SETPGID, pid, pgid) }) as c_int -} - -pub fn setregid(rgid: gid_t, egid: gid_t) -> c_int { - e(unsafe { syscall!(SETREGID, rgid, egid) }) as c_int -} - -pub fn setreuid(ruid: uid_t, euid: uid_t) -> c_int { - e(unsafe { syscall!(SETREUID, ruid, euid) }) as c_int -} - -pub fn setsockopt( - socket: c_int, - level: c_int, - option_name: c_int, - option_value: *const c_void, - option_len: socklen_t, -) -> c_int { - e(unsafe { - syscall!( - SETSOCKOPT, - socket, - level, - option_name, - option_value, - option_len - ) - }) as c_int -} - -pub fn shutdown(socket: c_int, how: c_int) -> c_int { - e(unsafe { syscall!(SHUTDOWN, socket, how) }) as c_int -} - -pub unsafe fn sigaction(sig: c_int, act: *const sigaction, oact: *mut sigaction) -> c_int { - e(syscall!( - RT_SIGACTION, - sig, - act, - oact, - mem::size_of::() - )) as c_int -} - -pub fn sigprocmask(how: c_int, set: *const sigset_t, oset: *mut sigset_t) -> c_int { - e(unsafe { syscall!(RT_SIGPROCMASK, how, set, oset, mem::size_of::()) }) as c_int -} - -pub fn stat(file: *const c_char, buf: *mut stat) -> c_int { - e(unsafe { syscall!(NEWFSTATAT, AT_FDCWD, file, buf, 0) }) as c_int -} - -pub fn socket(domain: c_int, kind: c_int, protocol: c_int) -> c_int { - e(unsafe { syscall!(SOCKET, domain, kind, protocol) }) as c_int -} - -pub fn socketpair(domain: c_int, kind: c_int, protocol: c_int, socket_vector: *mut c_int) -> c_int { - e(unsafe { syscall!(SOCKETPAIR, domain, kind, protocol, socket_vector) }) as c_int -} - -pub fn tcgetattr(fd: c_int, out: *mut termios) -> c_int { - ioctl(fd, TCGETS, out as *mut c_void) -} - -pub fn tcsetattr(fd: c_int, act: c_int, value: *const termios) -> c_int { - if act < 0 || act > 2 { + fn exit(status: c_int) -> ! { unsafe { - errno = EINVAL; + syscall!(EXIT, status); } - return -1; + loop {} } - // This is safe because ioctl shouldn't modify the value - ioctl(fd, TCSETS + act as c_ulong, value as *mut c_void) -} -pub fn times(out: *mut tms) -> clock_t { - unsafe { syscall!(TIMES, out) as clock_t } -} + fn fchdir(fildes: c_int) -> c_int { + e(unsafe { syscall!(FCHDIR, fildes) }) as c_int + } -pub fn umask(mask: mode_t) -> mode_t { - unsafe { syscall!(UMASK, mask) as mode_t } -} + fn fchmod(fildes: c_int, mode: mode_t) -> c_int { + e(unsafe { syscall!(FCHMOD, fildes, mode) }) as c_int + } -pub fn uname(utsname: *mut utsname) -> c_int { - e(unsafe { syscall!(UNAME, utsname, 0) }) as c_int -} + fn fchown(fildes: c_int, owner: uid_t, group: gid_t) -> c_int { + e(unsafe { syscall!(FCHOWN, fildes, owner, group) }) as c_int + } -pub fn unlink(path: *const c_char) -> c_int { - e(unsafe { syscall!(UNLINKAT, AT_FDCWD, path, 0) }) as c_int -} + fn flock(fd: c_int, operation: c_int) -> c_int { + e(unsafe { syscall!(FLOCK, fd, operation) }) as c_int + } -pub fn waitpid(pid: pid_t, stat_loc: *mut c_int, options: c_int) -> pid_t { - e(unsafe { syscall!(WAIT4, pid, stat_loc, options, 0) }) as pid_t -} + fn fstat(fildes: c_int, buf: *mut stat) -> c_int { + let empty_cstr: *const c_char = unsafe { ::cstr_from_bytes_with_nul_unchecked(b"\0") }; + e(unsafe { syscall!(NEWFSTATAT, fildes, empty_cstr, buf, AT_EMPTY_PATH) }) as c_int + } -pub fn write(fildes: c_int, buf: &[u8]) -> ssize_t { - e(unsafe { syscall!(WRITE, fildes, buf.as_ptr(), buf.len()) }) as ssize_t -} + fn fcntl(fildes: c_int, cmd: c_int, arg: c_int) -> c_int { + e(unsafe { syscall!(FCNTL, fildes, cmd, arg) }) as c_int + } -pub fn clock_gettime(clk_id: clockid_t, tp: *mut timespec) -> c_int { - e(unsafe { syscall!(CLOCK_GETTIME, clk_id, tp) }) as c_int + fn fork() -> pid_t { + e(unsafe { syscall!(CLONE, SIGCHLD, 0) }) as pid_t + } + + fn fsync(fildes: c_int) -> c_int { + e(unsafe { syscall!(FSYNC, fildes) }) as c_int + } + + fn ftruncate(fildes: c_int, length: off_t) -> c_int { + e(unsafe { syscall!(FTRUNCATE, fildes, length) }) as c_int + } + + fn futimens(fd: c_int, times: *const timespec) -> c_int { + e(unsafe { syscall!(UTIMENSAT, fd, ptr::null::(), times, 0) }) as c_int + } + + fn utimens(path: *const c_char, times: *const timespec) -> c_int { + e(unsafe { syscall!(UTIMENSAT, AT_FDCWD, path, times, 0) }) as c_int + } + + fn getcwd(buf: *mut c_char, size: size_t) -> *mut c_char { + if e(unsafe { syscall!(GETCWD, buf, size) }) == !0 { + ptr::null_mut() + } else { + buf + } + } + + fn getdents(fd: c_int, dirents: *mut dirent, bytes: usize) -> c_int { + unsafe { syscall!(GETDENTS64, fd, dirents, bytes) as c_int } + } + + fn getegid() -> gid_t { + e(unsafe { syscall!(GETEGID) }) as gid_t + } + + fn geteuid() -> uid_t { + e(unsafe { syscall!(GETEUID) }) as uid_t + } + + fn getgid() -> gid_t { + e(unsafe { syscall!(GETGID) }) as gid_t + } + + fn getrusage(who: c_int, r_usage: *mut rusage) -> c_int { + e(unsafe { syscall!(GETRUSAGE, who, r_usage) }) as c_int + } + + unsafe fn gethostname(mut name: *mut c_char, len: size_t) -> c_int { + // len only needs to be mutable on linux + let mut len = len; + + let mut uts = mem::uninitialized(); + let err = uname(&mut uts); + if err < 0 { + mem::forget(uts); + return err; + } + for c in uts.nodename.iter() { + if len == 0 { + break; + } + len -= 1; + + *name = *c; + + if *name == 0 { + // We do want to copy the zero also, so we check this after the copying. + break; + } + + name = name.offset(1); + } + 0 + } + + fn getitimer(which: c_int, out: *mut itimerval) -> c_int { + e(unsafe { syscall!(GETITIMER, which, out) }) as c_int + } + + unsafe fn getpeername( + socket: c_int, + address: *mut sockaddr, + address_len: *mut socklen_t, + ) -> c_int { + e(syscall!(GETPEERNAME, socket, address, address_len)) as c_int + } + + fn getpgid(pid: pid_t) -> pid_t { + e(unsafe { syscall!(GETPGID, pid) }) as pid_t + } + + fn getpid() -> pid_t { + e(unsafe { syscall!(GETPID) }) as pid_t + } + + fn getppid() -> pid_t { + e(unsafe { syscall!(GETPPID) }) as pid_t + } + + unsafe fn getsockname( + socket: c_int, + address: *mut sockaddr, + address_len: *mut socklen_t, + ) -> c_int { + e(syscall!(GETSOCKNAME, socket, address, address_len)) as c_int + } + + fn getsockopt( + socket: c_int, + level: c_int, + option_name: c_int, + option_value: *mut c_void, + option_len: *mut socklen_t, + ) -> c_int { + e(unsafe { + syscall!( + GETSOCKOPT, + socket, + level, + option_name, + option_value, + option_len + ) + }) as c_int + } + + fn gettimeofday(tp: *mut timeval, tzp: *mut timezone) -> c_int { + e(unsafe { syscall!(GETTIMEOFDAY, tp, tzp) }) as c_int + } + + fn getuid() -> uid_t { + e(unsafe { syscall!(GETUID) }) as uid_t + } + + fn ioctl(fd: c_int, request: c_ulong, out: *mut c_void) -> c_int { + // TODO: Somehow support varargs to syscall?? + e(unsafe { syscall!(IOCTL, fd, request, out) }) as c_int + } + + fn isatty(fd: c_int) -> c_int { + let mut winsize = winsize::default(); + (Self::ioctl(fd, TIOCGWINSZ, &mut winsize as *mut _ as *mut c_void) == 0) as c_int + } + + fn kill(pid: pid_t, sig: c_int) -> c_int { + e(unsafe { syscall!(KILL, pid, sig) }) as c_int + } + + fn killpg(pgrp: pid_t, sig: c_int) -> c_int { + e(unsafe { syscall!(KILL, -(pgrp as isize) as pid_t, sig) }) as c_int + } + + fn link(path1: *const c_char, path2: *const c_char) -> c_int { + e(unsafe { syscall!(LINKAT, AT_FDCWD, path1, AT_FDCWD, path2, 0) }) as c_int + } + + fn listen(socket: c_int, backlog: c_int) -> c_int { + e(unsafe { syscall!(LISTEN, socket, backlog) }) as c_int + } + + fn lseek(fildes: c_int, offset: off_t, whence: c_int) -> off_t { + e(unsafe { syscall!(LSEEK, fildes, offset, whence) }) as off_t + } + + fn lstat(file: *const c_char, buf: *mut stat) -> c_int { + e(unsafe { syscall!(NEWFSTATAT, AT_FDCWD, file, buf, AT_SYMLINK_NOFOLLOW) }) as c_int + } + + fn mkdir(path: *const c_char, mode: mode_t) -> c_int { + e(unsafe { syscall!(MKDIRAT, AT_FDCWD, path, mode) }) as c_int + } + + fn mkfifo(path: *const c_char, mode: mode_t) -> c_int { + e(unsafe { syscall!(MKNODAT, AT_FDCWD, path, mode, 0) }) as c_int + } + + unsafe fn mmap( + addr: *mut c_void, + len: usize, + prot: c_int, + flags: c_int, + fildes: c_int, + off: off_t, + ) -> *mut c_void { + e(syscall!(MMAP, addr, len, prot, flags, fildes, off)) as *mut c_void + } + + unsafe fn munmap(addr: *mut c_void, len: usize) -> c_int { + e(syscall!(MUNMAP, addr, len)) as c_int + } + + fn nanosleep(rqtp: *const timespec, rmtp: *mut timespec) -> c_int { + e(unsafe { syscall!(NANOSLEEP, rqtp, rmtp) }) as c_int + } + + fn open(path: *const c_char, oflag: c_int, mode: mode_t) -> c_int { + e(unsafe { syscall!(OPENAT, AT_FDCWD, path, oflag, mode) }) as c_int + } + + fn pipe(fildes: &mut [c_int]) -> c_int { + e(unsafe { syscall!(PIPE2, fildes.as_mut_ptr(), 0) }) as c_int + } + + fn raise(sig: c_int) -> c_int { + let tid = e(unsafe { syscall!(GETTID) }) as pid_t; + let ret = if tid == !0 { + -1 + } else { + e(unsafe { syscall!(TKILL, tid, sig) }) as c_int + }; + + ret + } + + fn read(fildes: c_int, buf: &mut [u8]) -> ssize_t { + e(unsafe { syscall!(READ, fildes, buf.as_mut_ptr(), buf.len()) }) as ssize_t + } + + unsafe fn recvfrom( + socket: c_int, + buf: *mut c_void, + len: size_t, + flags: c_int, + address: *mut sockaddr, + address_len: *mut socklen_t, + ) -> ssize_t { + e(syscall!( + RECVFROM, + socket, + buf, + len, + flags, + address, + address_len + )) as ssize_t + } + + fn rename(old: *const c_char, new: *const c_char) -> c_int { + e(unsafe { syscall!(RENAMEAT, AT_FDCWD, old, AT_FDCWD, new) }) as c_int + } + + fn rmdir(path: *const c_char) -> c_int { + e(unsafe { syscall!(UNLINKAT, AT_FDCWD, path, AT_REMOVEDIR) }) as c_int + } + + fn select( + nfds: c_int, + readfds: *mut fd_set, + writefds: *mut fd_set, + exceptfds: *mut fd_set, + timeout: *mut timeval, + ) -> c_int { + e(unsafe { syscall!(SELECT, nfds, readfds, writefds, exceptfds, timeout) }) as c_int + } + + unsafe fn sendto( + socket: c_int, + buf: *const c_void, + len: size_t, + flags: c_int, + dest_addr: *const sockaddr, + dest_len: socklen_t, + ) -> ssize_t { + e(syscall!( + SENDTO, socket, buf, len, flags, dest_addr, dest_len + )) as ssize_t + } + + fn setitimer(which: c_int, new: *const itimerval, old: *mut itimerval) -> c_int { + e(unsafe { syscall!(SETITIMER, which, new, old) }) as c_int + } + + fn setpgid(pid: pid_t, pgid: pid_t) -> c_int { + e(unsafe { syscall!(SETPGID, pid, pgid) }) as c_int + } + + fn setregid(rgid: gid_t, egid: gid_t) -> c_int { + e(unsafe { syscall!(SETREGID, rgid, egid) }) as c_int + } + + fn setreuid(ruid: uid_t, euid: uid_t) -> c_int { + e(unsafe { syscall!(SETREUID, ruid, euid) }) as c_int + } + + fn setsockopt( + socket: c_int, + level: c_int, + option_name: c_int, + option_value: *const c_void, + option_len: socklen_t, + ) -> c_int { + e(unsafe { + syscall!( + SETSOCKOPT, + socket, + level, + option_name, + option_value, + option_len + ) + }) as c_int + } + + fn shutdown(socket: c_int, how: c_int) -> c_int { + e(unsafe { syscall!(SHUTDOWN, socket, how) }) as c_int + } + + unsafe fn sigaction(sig: c_int, act: *const sigaction, oact: *mut sigaction) -> c_int { + e(syscall!( + RT_SIGACTION, + sig, + act, + oact, + mem::size_of::() + )) as c_int + } + + fn sigprocmask(how: c_int, set: *const sigset_t, oset: *mut sigset_t) -> c_int { + e(unsafe { syscall!(RT_SIGPROCMASK, how, set, oset, mem::size_of::()) }) as c_int + } + + fn stat(file: *const c_char, buf: *mut stat) -> c_int { + e(unsafe { syscall!(NEWFSTATAT, AT_FDCWD, file, buf, 0) }) as c_int + } + + fn socket(domain: c_int, kind: c_int, protocol: c_int) -> c_int { + e(unsafe { syscall!(SOCKET, domain, kind, protocol) }) as c_int + } + + fn socketpair(domain: c_int, kind: c_int, protocol: c_int, socket_vector: *mut c_int) -> c_int { + e(unsafe { syscall!(SOCKETPAIR, domain, kind, protocol, socket_vector) }) as c_int + } + + fn tcgetattr(fd: c_int, out: *mut termios) -> c_int { + Self::ioctl(fd, TCGETS, out as *mut c_void) + } + + fn tcsetattr(fd: c_int, act: c_int, value: *const termios) -> c_int { + if act < 0 || act > 2 { + unsafe { + errno = EINVAL; + } + return -1; + } + // This is safe because ioctl shouldn't modify the value + Self::ioctl(fd, TCSETS + act as c_ulong, value as *mut c_void) + } + + fn times(out: *mut tms) -> clock_t { + unsafe { syscall!(TIMES, out) as clock_t } + } + + fn umask(mask: mode_t) -> mode_t { + unsafe { syscall!(UMASK, mask) as mode_t } + } + + fn uname(utsname: *mut utsname) -> c_int { + e(unsafe { syscall!(UNAME, utsname, 0) }) as c_int + } + + fn unlink(path: *const c_char) -> c_int { + e(unsafe { syscall!(UNLINKAT, AT_FDCWD, path, 0) }) as c_int + } + + fn waitpid(pid: pid_t, stat_loc: *mut c_int, options: c_int) -> pid_t { + e(unsafe { syscall!(WAIT4, pid, stat_loc, options, 0) }) as pid_t + } + + fn write(fildes: c_int, buf: &[u8]) -> ssize_t { + e(unsafe { syscall!(WRITE, fildes, buf.as_ptr(), buf.len()) }) as ssize_t + } } diff --git a/src/platform/src/pal.rs b/src/platform/src/pal.rs new file mode 100644 index 0000000000..67081b439e --- /dev/null +++ b/src/platform/src/pal.rs @@ -0,0 +1,370 @@ +use types::*; + +pub trait Pal { + fn no_pal(name: &str) -> T; + + unsafe fn accept(socket: c_int, address: *mut sockaddr, address_len: *mut socklen_t) -> c_int { + Self::no_pal("accept") + } + + fn access(path: *const c_char, mode: c_int) -> c_int { + Self::no_pal("access") + } + + unsafe fn bind(socket: c_int, address: *const sockaddr, address_len: socklen_t) -> c_int { + Self::no_pal("bind") + } + + fn brk(addr: *mut c_void) -> *mut c_void { + Self::no_pal("brk") + } + + fn chdir(path: *const c_char) -> c_int { + Self::no_pal("chdir") + } + + fn chmod(path: *const c_char, mode: mode_t) -> c_int { + Self::no_pal("chmod") + } + + fn chown(path: *const c_char, owner: uid_t, group: gid_t) -> c_int { + Self::no_pal("chown") + } + + fn clock_gettime(clk_id: clockid_t, tp: *mut timespec) -> c_int { + Self::no_pal("clock_gettime") + } + + fn close(fildes: c_int) -> c_int { + Self::no_pal("close") + } + + unsafe fn connect(socket: c_int, address: *const sockaddr, address_len: socklen_t) -> c_int { + Self::no_pal("connect") + } + + fn dup(fildes: c_int) -> c_int { + Self::no_pal("dup") + } + + fn dup2(fildes: c_int, fildes2: c_int) -> c_int { + Self::no_pal("dup2") + } + + fn execve(path: *const c_char, argv: *const *mut c_char, envp: *const *mut c_char) -> c_int { + Self::no_pal("execve") + } + + fn exit(status: c_int) -> !; + + fn fchdir(fildes: c_int) -> c_int { + Self::no_pal("fchdir") + } + + fn fchmod(fildes: c_int, mode: mode_t) -> c_int { + Self::no_pal("fchmod") + } + + fn fchown(fildes: c_int, owner: uid_t, group: gid_t) -> c_int { + Self::no_pal("fchown") + } + + fn flock(fd: c_int, operation: c_int) -> c_int { + Self::no_pal("flock") + } + + fn fstat(fildes: c_int, buf: *mut stat) -> c_int { + Self::no_pal("fstat") + } + + fn fcntl(fildes: c_int, cmd: c_int, arg: c_int) -> c_int { + Self::no_pal("fcntl") + } + + fn fork() -> pid_t { + Self::no_pal("fork") + } + + fn fsync(fildes: c_int) -> c_int { + Self::no_pal("fsync") + } + + fn ftruncate(fildes: c_int, length: off_t) -> c_int { + Self::no_pal("ftruncate") + } + + fn futimens(fd: c_int, times: *const timespec) -> c_int { + Self::no_pal("futimens") + } + + fn utimens(path: *const c_char, times: *const timespec) -> c_int { + Self::no_pal("utimens") + } + + fn getcwd(buf: *mut c_char, size: size_t) -> *mut c_char { + Self::no_pal("getcwd") + } + + fn getdents(fd: c_int, dirents: *mut dirent, bytes: usize) -> c_int { + Self::no_pal("getdents") + } + + fn getegid() -> gid_t { + Self::no_pal("getegid") + } + + fn geteuid() -> uid_t { + Self::no_pal("geteuid") + } + + fn getgid() -> gid_t { + Self::no_pal("getgid") + } + + fn getrusage(who: c_int, r_usage: *mut rusage) -> c_int { + Self::no_pal("getrusage") + } + + unsafe fn gethostname(mut name: *mut c_char, len: size_t) -> c_int { + Self::no_pal("gethostname") + } + + fn getitimer(which: c_int, out: *mut itimerval) -> c_int { + Self::no_pal("getitimer") + } + + unsafe fn getpeername(socket: c_int, address: *mut sockaddr, address_len: *mut socklen_t) -> c_int { + Self::no_pal("getpeername") + } + + fn getpgid(pid: pid_t) -> pid_t { + Self::no_pal("getpgid") + } + + fn getpid() -> pid_t { + Self::no_pal("getpid") + } + + fn getppid() -> pid_t { + Self::no_pal("getppid") + } + + unsafe fn getsockname(socket: c_int, address: *mut sockaddr, address_len: *mut socklen_t) -> c_int { + Self::no_pal("getsockname") + } + + fn getsockopt( + socket: c_int, + level: c_int, + option_name: c_int, + option_value: *mut c_void, + option_len: *mut socklen_t, + ) -> c_int { + Self::no_pal("getsockopt") + } + + fn gettimeofday(tp: *mut timeval, tzp: *mut timezone) -> c_int { + Self::no_pal("gettimeofday") + } + + fn getuid() -> uid_t { + Self::no_pal("getuid") + } + + fn ioctl(fd: c_int, request: c_ulong, out: *mut c_void) -> c_int { + Self::no_pal("ioctl") + } + + fn isatty(fd: c_int) -> c_int { + Self::no_pal("isatty") + } + + fn kill(pid: pid_t, sig: c_int) -> c_int { + Self::no_pal("kill") + } + + fn killpg(pgrp: pid_t, sig: c_int) -> c_int { + Self::no_pal("killpg") + } + + fn link(path1: *const c_char, path2: *const c_char) -> c_int { + Self::no_pal("link") + } + + fn listen(socket: c_int, backlog: c_int) -> c_int { + Self::no_pal("listen") + } + + fn lseek(fildes: c_int, offset: off_t, whence: c_int) -> off_t { + Self::no_pal("lseek") + } + + fn lstat(file: *const c_char, buf: *mut stat) -> c_int { + Self::no_pal("lstat") + } + + fn mkdir(path: *const c_char, mode: mode_t) -> c_int { + Self::no_pal("mkdir") + } + + fn mkfifo(path: *const c_char, mode: mode_t) -> c_int { + Self::no_pal("mkfifo") + } + + unsafe fn mmap( + addr: *mut c_void, + len: usize, + prot: c_int, + flags: c_int, + fildes: c_int, + off: off_t, + ) -> *mut c_void { + Self::no_pal("mmap") + } + + unsafe fn munmap(addr: *mut c_void, len: usize) -> c_int { + Self::no_pal("munmap") + } + + fn nanosleep(rqtp: *const timespec, rmtp: *mut timespec) -> c_int { + Self::no_pal("nanosleep") + } + + fn open(path: *const c_char, oflag: c_int, mode: mode_t) -> c_int { + Self::no_pal("open") + } + + fn pipe(fildes: &mut [c_int]) -> c_int { + Self::no_pal("pipe") + } + + fn raise(sig: c_int) -> c_int { + Self::no_pal("raise") + } + + fn read(fildes: c_int, buf: &mut [u8]) -> ssize_t { + Self::no_pal("read") + } + + unsafe fn recvfrom( + socket: c_int, + buf: *mut c_void, + len: size_t, + flags: c_int, + address: *mut sockaddr, + address_len: *mut socklen_t, + ) -> ssize_t { + Self::no_pal("recvfrom") + } + + fn rename(old: *const c_char, new: *const c_char) -> c_int { + Self::no_pal("rename") + } + + fn rmdir(path: *const c_char) -> c_int { + Self::no_pal("rmdir") + } + + fn select( + nfds: c_int, + readfds: *mut fd_set, + writefds: *mut fd_set, + exceptfds: *mut fd_set, + timeout: *mut timeval, + ) -> c_int { + Self::no_pal("select") + } + + unsafe fn sendto( + socket: c_int, + buf: *const c_void, + len: size_t, + flags: c_int, + dest_addr: *const sockaddr, + dest_len: socklen_t, + ) -> ssize_t { + Self::no_pal("sendto") + } + + fn setitimer(which: c_int, new: *const itimerval, old: *mut itimerval) -> c_int { + Self::no_pal("setitimer") + } + + fn setpgid(pid: pid_t, pgid: pid_t) -> c_int { + Self::no_pal("setpgid") + } + + fn setregid(rgid: gid_t, egid: gid_t) -> c_int { + Self::no_pal("setregid") + } + + fn setreuid(ruid: uid_t, euid: uid_t) -> c_int { + Self::no_pal("setreuid") + } + + fn setsockopt( + socket: c_int, + level: c_int, + option_name: c_int, + option_value: *const c_void, + option_len: socklen_t, + ) -> c_int { + Self::no_pal("setsockopt") + } + + fn shutdown(socket: c_int, how: c_int) -> c_int { + Self::no_pal("shutdown") + } + + unsafe fn sigaction(sig: c_int, act: *const sigaction, oact: *mut sigaction) -> c_int { + Self::no_pal("sigaction") + } + + fn sigprocmask(how: c_int, set: *const sigset_t, oset: *mut sigset_t) -> c_int { + Self::no_pal("sigprocmask") + } + + fn stat(file: *const c_char, buf: *mut stat) -> c_int { + Self::no_pal("stat") + } + + fn socket(domain: c_int, kind: c_int, protocol: c_int) -> c_int { + Self::no_pal("socket") + } + + fn socketpair(domain: c_int, kind: c_int, protocol: c_int, socket_vector: *mut c_int) -> c_int { + Self::no_pal("socketpair") + } + + fn tcgetattr(fd: c_int, out: *mut termios) -> c_int { + Self::no_pal("tcgetattr") + } + + fn tcsetattr(fd: c_int, act: c_int, value: *const termios) -> c_int { + Self::no_pal("tcsetattr") + } + + fn times(out: *mut tms) -> clock_t { + Self::no_pal("times") + } + + fn umask(mask: mode_t) -> mode_t { + Self::no_pal("umask") + } + + fn uname(utsname: *mut utsname) -> c_int { + Self::no_pal("uname") + } + + fn unlink(path: *const c_char) -> c_int { + Self::no_pal("unlink") + } + + fn waitpid(pid: pid_t, stat_loc: *mut c_int, options: c_int) -> pid_t { + Self::no_pal("waitpid") + } + + fn write(fildes: c_int, buf: &[u8]) -> ssize_t { + Self::no_pal("write") + } +} diff --git a/src/sys_resource/src/lib.rs b/src/sys_resource/src/lib.rs index 228f26fc7d..f919012588 100644 --- a/src/sys_resource/src/lib.rs +++ b/src/sys_resource/src/lib.rs @@ -53,7 +53,7 @@ pub unsafe extern "C" fn getrlimit(resource: c_int, rlp: *mut rlimit) -> c_int { unimplemented!(); } -#[no_mangle] +//#[no_mangle] pub unsafe extern "C" fn getrusage(who: c_int, r_usage: *mut rusage) -> c_int { platform::getrusage(who, r_usage as *mut platform::types::rusage) } diff --git a/src/sys_times/src/lib.rs b/src/sys_times/src/lib.rs index 3d8b7f8903..965e75a33b 100644 --- a/src/sys_times/src/lib.rs +++ b/src/sys_times/src/lib.rs @@ -14,7 +14,7 @@ pub struct tms { tms_cstime: clock_t, } -#[no_mangle] +//#[no_mangle] pub extern "C" fn times(out: *mut tms) -> clock_t { platform::times(out as *mut platform::types::tms) } From 729709a8e6955461589fcc771ac5ee812c0d265f Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sat, 25 Aug 2018 08:42:57 -0600 Subject: [PATCH 02/19] Update all modules to new Pal mechanism --- Makefile | 3 + src/crt0/src/lib.rs | 7 +- src/dirent/src/lib.rs | 7 +- src/fcntl/src/lib.rs | 12 +- src/lib.rs | 8 +- src/platform/src/lib.rs | 8 +- src/platform/src/linux/mod.rs | 159 ++---------------------- src/platform/src/linux/signal.rs | 40 ++++++ src/platform/src/linux/socket.rs | 119 ++++++++++++++++++ src/platform/src/{pal.rs => pal/mod.rs} | 128 +++---------------- src/platform/src/pal/signal.rs | 24 ++++ src/platform/src/pal/socket.rs | 82 ++++++++++++ src/platform/src/rawfile.rs | 9 +- src/pwd/src/lib.rs | 3 +- src/signal/src/lib.rs | 11 +- src/stdio/src/lib.rs | 30 +++-- src/stdlib/src/lib.rs | 11 +- src/sys_ioctl/src/lib.rs | 3 +- src/sys_mman/src/lib.rs | 5 +- src/sys_resource/src/lib.rs | 3 +- src/sys_select/src/lib.rs | 3 +- src/sys_socket/src/lib.rs | 27 ++-- src/sys_stat/src/lib.rs | 19 +-- src/sys_time/src/lib.rs | 9 +- src/sys_times/src/lib.rs | 3 +- src/sys_utsname/src/lib.rs | 3 +- src/sys_wait/src/lib.rs | 3 +- src/termios/src/lib.rs | 5 +- src/time/src/lib.rs | 7 +- src/unistd/src/brk.rs | 7 +- src/unistd/src/lib.rs | 77 ++++++------ src/utime/src/lib.rs | 3 +- 32 files changed, 452 insertions(+), 386 deletions(-) create mode 100644 src/platform/src/linux/signal.rs create mode 100644 src/platform/src/linux/socket.rs rename src/platform/src/{pal.rs => pal/mod.rs} (67%) create mode 100644 src/platform/src/pal/signal.rs create mode 100644 src/platform/src/pal/socket.rs diff --git a/Makefile b/Makefile index cf37919e0a..25aef80ebe 100644 --- a/Makefile +++ b/Makefile @@ -28,6 +28,9 @@ clean: cargo clean make -C tests clean +check: + cargo check + fmt: ./fmt.sh diff --git a/src/crt0/src/lib.rs b/src/crt0/src/lib.rs index e790ec60d0..02db0186d4 100644 --- a/src/crt0/src/lib.rs +++ b/src/crt0/src/lib.rs @@ -14,6 +14,7 @@ extern crate stdio; use alloc::Vec; use core::ptr; +use platform::{Pal, Sys}; use platform::types::*; #[no_mangle] @@ -95,7 +96,7 @@ pub unsafe extern "C" fn _start_rust(sp: &'static Stack) -> ! { stdio::stdout = stdio::default_stdout.get(); stdio::stderr = stdio::default_stderr.get(); - platform::exit(main( + Sys::exit(main( argc, argv, // not envp, because programs like bash try to modify this *const* @@ -113,7 +114,7 @@ pub extern "C" fn rust_begin_unwind(pi: &::core::panic::PanicInfo) -> ! { let mut w = platform::FileWriter(2); let _ = w.write_fmt(format_args!("RELIBC CRT0 PANIC: {}\n", pi)); - platform::exit(1); + Sys::exit(1); } #[lang = "oom"] @@ -129,5 +130,5 @@ pub extern "C" fn rust_oom(layout: ::core::alloc::Layout) -> ! { layout.align() )); - platform::exit(1); + Sys::exit(1); } diff --git a/src/dirent/src/lib.rs b/src/dirent/src/lib.rs index 62edcf9a39..029081c005 100644 --- a/src/dirent/src/lib.rs +++ b/src/dirent/src/lib.rs @@ -12,6 +12,7 @@ extern crate unistd; use alloc::boxed::Box; use core::{mem, ptr}; +use platform::{Pal, Sys}; use platform::types::*; const DIR_BUF_SIZE: usize = mem::size_of::() * 3; @@ -41,7 +42,7 @@ pub struct dirent { #[no_mangle] pub extern "C" fn opendir(path: *const c_char) -> *mut DIR { - let fd = platform::open( + let fd = Sys::open( path, fcntl::O_RDONLY | fcntl::O_DIRECTORY | fcntl::O_CLOEXEC, 0, @@ -62,7 +63,7 @@ pub extern "C" fn opendir(path: *const c_char) -> *mut DIR { #[no_mangle] pub unsafe extern "C" fn closedir(dir: *mut DIR) -> c_int { - let ret = platform::close((*dir).fd); + let ret = Sys::close((*dir).fd); Box::from_raw(dir); ret } @@ -70,7 +71,7 @@ pub unsafe extern "C" fn closedir(dir: *mut DIR) -> c_int { #[no_mangle] pub unsafe extern "C" fn readdir(dir: *mut DIR) -> *mut dirent { if (*dir).index >= (*dir).len { - let read = platform::getdents( + let read = Sys::getdents( (*dir).fd, (*dir).buf.as_mut_ptr() as *mut platform::types::dirent, (*dir).buf.len(), diff --git a/src/fcntl/src/lib.rs b/src/fcntl/src/lib.rs index 0c0fa43ce2..f9c78930e9 100644 --- a/src/fcntl/src/lib.rs +++ b/src/fcntl/src/lib.rs @@ -4,6 +4,7 @@ extern crate platform; +use platform::{Pal, Sys}; use platform::types::*; pub use sys::*; @@ -38,17 +39,10 @@ pub extern "C" fn creat(path: *const c_char, mode: mode_t) -> c_int { #[no_mangle] pub extern "C" fn sys_fcntl(fildes: c_int, cmd: c_int, arg: c_int) -> c_int { - platform::fcntl(fildes, cmd, arg) + Sys::fcntl(fildes, cmd, arg) } #[no_mangle] pub extern "C" fn sys_open(path: *const c_char, oflag: c_int, mode: mode_t) -> c_int { - platform::open(path, oflag, mode) + Sys::open(path, oflag, mode) } - -/* -#[no_mangle] -pub extern "C" fn func(args) -> c_int { - unimplemented!(); -} -*/ diff --git a/src/lib.rs b/src/lib.rs index 0cffd0abeb..37cc9ea0c8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -43,6 +43,8 @@ pub extern crate utime; pub extern crate wchar; pub extern crate wctype; +use platform::{Pal, Sys}; + #[cfg(not(test))] #[panic_implementation] #[linkage = "weak"] @@ -53,7 +55,7 @@ pub extern "C" fn rust_begin_unwind(pi: &::core::panic::PanicInfo) -> ! { let mut w = platform::FileWriter(2); let _ = w.write_fmt(format_args!("RELIBC PANIC: {}\n", pi)); - platform::exit(1); + Sys::exit(1); } #[cfg(not(test))] @@ -76,7 +78,7 @@ pub extern "C" fn rust_oom(layout: ::core::alloc::Layout) -> ! { layout.align() )); - platform::exit(1); + Sys::exit(1); } #[cfg(not(test))] @@ -89,5 +91,5 @@ pub extern "C" fn _Unwind_Resume() -> ! { let mut w = platform::FileWriter(2); let _ = w.write_str("_Unwind_Resume\n"); - platform::exit(1); + Sys::exit(1); } diff --git a/src/platform/src/lib.rs b/src/platform/src/lib.rs index 60331812ec..bed373141c 100644 --- a/src/platform/src/lib.rs +++ b/src/platform/src/lib.rs @@ -26,11 +26,11 @@ mod allocator; #[path = "allocator/ralloc.rs"] mod allocator; -pub use pal::Pal; +pub use pal::{Pal, PalSignal, PalSocket}; mod pal; -pub use sys::*; +pub use sys::Sys; #[cfg(all(not(feature = "no_std"), target_os = "linux"))] #[path = "linux/mod.rs"] @@ -149,7 +149,7 @@ pub struct FileWriter(pub c_int); impl FileWriter { pub fn write(&mut self, buf: &[u8]) -> isize { - write(self.0, buf) + Sys::write(self.0, buf) } } @@ -171,7 +171,7 @@ pub struct FileReader(pub c_int); impl FileReader { pub fn read(&mut self, buf: &mut [u8]) -> isize { - read(self.0, buf) + Sys::read(self.0, buf) } } diff --git a/src/platform/src/linux/mod.rs b/src/platform/src/linux/mod.rs index f1c941af36..276a18bcb8 100644 --- a/src/platform/src/linux/mod.rs +++ b/src/platform/src/linux/mod.rs @@ -1,10 +1,16 @@ use core::{mem, ptr}; +use core::fmt::Write; +use FileWriter; use Pal; use errno; use types::*; +mod signal; +mod socket; + const EINVAL: c_int = 22; +const ENOSYS: c_int = 38; const SIGCHLD: usize = 17; @@ -31,18 +37,18 @@ fn e(sys: usize) -> usize { pub struct Sys; impl Pal for Sys { - unsafe fn accept(socket: c_int, address: *mut sockaddr, address_len: *mut socklen_t) -> c_int { - e(syscall!(ACCEPT, socket, address, address_len)) as c_int + fn no_pal(name: &str) -> c_int { + let _ = writeln!(FileWriter(2), "relibc: no_pal: {}", name); + unsafe { + errno = ENOSYS; + } + -1 } fn access(path: *const c_char, mode: c_int) -> c_int { e(unsafe { syscall!(ACCESS, path, mode) }) as c_int } - unsafe fn bind(socket: c_int, address: *const sockaddr, address_len: socklen_t) -> c_int { - e(syscall!(BIND, socket, address, address_len)) as c_int - } - fn brk(addr: *mut c_void) -> *mut c_void { unsafe { syscall!(BRK, addr) as *mut c_void } } @@ -67,10 +73,6 @@ impl Pal for Sys { e(unsafe { syscall!(CLOSE, fildes) }) as c_int } - unsafe fn connect(socket: c_int, address: *const sockaddr, address_len: socklen_t) -> c_int { - e(syscall!(CONNECT, socket, address, address_len)) as c_int - } - fn dup(fildes: c_int) -> c_int { e(unsafe { syscall!(DUP, fildes) }) as c_int } @@ -168,7 +170,7 @@ impl Pal for Sys { let mut len = len; let mut uts = mem::uninitialized(); - let err = uname(&mut uts); + let err = Sys::uname(&mut uts); if err < 0 { mem::forget(uts); return err; @@ -195,14 +197,6 @@ impl Pal for Sys { e(unsafe { syscall!(GETITIMER, which, out) }) as c_int } - unsafe fn getpeername( - socket: c_int, - address: *mut sockaddr, - address_len: *mut socklen_t, - ) -> c_int { - e(syscall!(GETPEERNAME, socket, address, address_len)) as c_int - } - fn getpgid(pid: pid_t) -> pid_t { e(unsafe { syscall!(GETPGID, pid) }) as pid_t } @@ -215,33 +209,6 @@ impl Pal for Sys { e(unsafe { syscall!(GETPPID) }) as pid_t } - unsafe fn getsockname( - socket: c_int, - address: *mut sockaddr, - address_len: *mut socklen_t, - ) -> c_int { - e(syscall!(GETSOCKNAME, socket, address, address_len)) as c_int - } - - fn getsockopt( - socket: c_int, - level: c_int, - option_name: c_int, - option_value: *mut c_void, - option_len: *mut socklen_t, - ) -> c_int { - e(unsafe { - syscall!( - GETSOCKOPT, - socket, - level, - option_name, - option_value, - option_len - ) - }) as c_int - } - fn gettimeofday(tp: *mut timeval, tzp: *mut timezone) -> c_int { e(unsafe { syscall!(GETTIMEOFDAY, tp, tzp) }) as c_int } @@ -260,22 +227,10 @@ impl Pal for Sys { (Self::ioctl(fd, TIOCGWINSZ, &mut winsize as *mut _ as *mut c_void) == 0) as c_int } - fn kill(pid: pid_t, sig: c_int) -> c_int { - e(unsafe { syscall!(KILL, pid, sig) }) as c_int - } - - fn killpg(pgrp: pid_t, sig: c_int) -> c_int { - e(unsafe { syscall!(KILL, -(pgrp as isize) as pid_t, sig) }) as c_int - } - fn link(path1: *const c_char, path2: *const c_char) -> c_int { e(unsafe { syscall!(LINKAT, AT_FDCWD, path1, AT_FDCWD, path2, 0) }) as c_int } - fn listen(socket: c_int, backlog: c_int) -> c_int { - e(unsafe { syscall!(LISTEN, socket, backlog) }) as c_int - } - fn lseek(fildes: c_int, offset: off_t, whence: c_int) -> off_t { e(unsafe { syscall!(LSEEK, fildes, offset, whence) }) as off_t } @@ -319,40 +274,10 @@ impl Pal for Sys { e(unsafe { syscall!(PIPE2, fildes.as_mut_ptr(), 0) }) as c_int } - fn raise(sig: c_int) -> c_int { - let tid = e(unsafe { syscall!(GETTID) }) as pid_t; - let ret = if tid == !0 { - -1 - } else { - e(unsafe { syscall!(TKILL, tid, sig) }) as c_int - }; - - ret - } - fn read(fildes: c_int, buf: &mut [u8]) -> ssize_t { e(unsafe { syscall!(READ, fildes, buf.as_mut_ptr(), buf.len()) }) as ssize_t } - unsafe fn recvfrom( - socket: c_int, - buf: *mut c_void, - len: size_t, - flags: c_int, - address: *mut sockaddr, - address_len: *mut socklen_t, - ) -> ssize_t { - e(syscall!( - RECVFROM, - socket, - buf, - len, - flags, - address, - address_len - )) as ssize_t - } - fn rename(old: *const c_char, new: *const c_char) -> c_int { e(unsafe { syscall!(RENAMEAT, AT_FDCWD, old, AT_FDCWD, new) }) as c_int } @@ -371,19 +296,6 @@ impl Pal for Sys { e(unsafe { syscall!(SELECT, nfds, readfds, writefds, exceptfds, timeout) }) as c_int } - unsafe fn sendto( - socket: c_int, - buf: *const c_void, - len: size_t, - flags: c_int, - dest_addr: *const sockaddr, - dest_len: socklen_t, - ) -> ssize_t { - e(syscall!( - SENDTO, socket, buf, len, flags, dest_addr, dest_len - )) as ssize_t - } - fn setitimer(which: c_int, new: *const itimerval, old: *mut itimerval) -> c_int { e(unsafe { syscall!(SETITIMER, which, new, old) }) as c_int } @@ -400,55 +312,10 @@ impl Pal for Sys { e(unsafe { syscall!(SETREUID, ruid, euid) }) as c_int } - fn setsockopt( - socket: c_int, - level: c_int, - option_name: c_int, - option_value: *const c_void, - option_len: socklen_t, - ) -> c_int { - e(unsafe { - syscall!( - SETSOCKOPT, - socket, - level, - option_name, - option_value, - option_len - ) - }) as c_int - } - - fn shutdown(socket: c_int, how: c_int) -> c_int { - e(unsafe { syscall!(SHUTDOWN, socket, how) }) as c_int - } - - unsafe fn sigaction(sig: c_int, act: *const sigaction, oact: *mut sigaction) -> c_int { - e(syscall!( - RT_SIGACTION, - sig, - act, - oact, - mem::size_of::() - )) as c_int - } - - fn sigprocmask(how: c_int, set: *const sigset_t, oset: *mut sigset_t) -> c_int { - e(unsafe { syscall!(RT_SIGPROCMASK, how, set, oset, mem::size_of::()) }) as c_int - } - fn stat(file: *const c_char, buf: *mut stat) -> c_int { e(unsafe { syscall!(NEWFSTATAT, AT_FDCWD, file, buf, 0) }) as c_int } - fn socket(domain: c_int, kind: c_int, protocol: c_int) -> c_int { - e(unsafe { syscall!(SOCKET, domain, kind, protocol) }) as c_int - } - - fn socketpair(domain: c_int, kind: c_int, protocol: c_int, socket_vector: *mut c_int) -> c_int { - e(unsafe { syscall!(SOCKETPAIR, domain, kind, protocol, socket_vector) }) as c_int - } - fn tcgetattr(fd: c_int, out: *mut termios) -> c_int { Self::ioctl(fd, TCGETS, out as *mut c_void) } diff --git a/src/platform/src/linux/signal.rs b/src/platform/src/linux/signal.rs new file mode 100644 index 0000000000..1d29bc3d41 --- /dev/null +++ b/src/platform/src/linux/signal.rs @@ -0,0 +1,40 @@ +use core::mem; + +use super::{e, Sys}; +use PalSignal; +use types::*; + +impl PalSignal for Sys { + fn kill(pid: pid_t, sig: c_int) -> c_int { + e(unsafe { syscall!(KILL, pid, sig) }) as c_int + } + + fn killpg(pgrp: pid_t, sig: c_int) -> c_int { + e(unsafe { syscall!(KILL, -(pgrp as isize) as pid_t, sig) }) as c_int + } + + fn raise(sig: c_int) -> c_int { + let tid = e(unsafe { syscall!(GETTID) }) as pid_t; + let ret = if tid == !0 { + -1 + } else { + e(unsafe { syscall!(TKILL, tid, sig) }) as c_int + }; + + ret + } + + unsafe fn sigaction(sig: c_int, act: *const sigaction, oact: *mut sigaction) -> c_int { + e(syscall!( + RT_SIGACTION, + sig, + act, + oact, + mem::size_of::() + )) as c_int + } + + fn sigprocmask(how: c_int, set: *const sigset_t, oset: *mut sigset_t) -> c_int { + e(unsafe { syscall!(RT_SIGPROCMASK, how, set, oset, mem::size_of::()) }) as c_int + } +} diff --git a/src/platform/src/linux/socket.rs b/src/platform/src/linux/socket.rs new file mode 100644 index 0000000000..c29f2b51ca --- /dev/null +++ b/src/platform/src/linux/socket.rs @@ -0,0 +1,119 @@ +use super::{e, Sys}; +use PalSocket; +use types::*; + +impl PalSocket for Sys { + unsafe fn accept(socket: c_int, address: *mut sockaddr, address_len: *mut socklen_t) -> c_int { + e(syscall!(ACCEPT, socket, address, address_len)) as c_int + } + + unsafe fn bind(socket: c_int, address: *const sockaddr, address_len: socklen_t) -> c_int { + e(syscall!(BIND, socket, address, address_len)) as c_int + } + + unsafe fn connect(socket: c_int, address: *const sockaddr, address_len: socklen_t) -> c_int { + e(syscall!(CONNECT, socket, address, address_len)) as c_int + } + + unsafe fn getpeername( + socket: c_int, + address: *mut sockaddr, + address_len: *mut socklen_t, + ) -> c_int { + e(syscall!(GETPEERNAME, socket, address, address_len)) as c_int + } + + unsafe fn getsockname( + socket: c_int, + address: *mut sockaddr, + address_len: *mut socklen_t, + ) -> c_int { + e(syscall!(GETSOCKNAME, socket, address, address_len)) as c_int + } + + fn getsockopt( + socket: c_int, + level: c_int, + option_name: c_int, + option_value: *mut c_void, + option_len: *mut socklen_t, + ) -> c_int { + e(unsafe { + syscall!( + GETSOCKOPT, + socket, + level, + option_name, + option_value, + option_len + ) + }) as c_int + } + + fn listen(socket: c_int, backlog: c_int) -> c_int { + e(unsafe { syscall!(LISTEN, socket, backlog) }) as c_int + } + + unsafe fn recvfrom( + socket: c_int, + buf: *mut c_void, + len: size_t, + flags: c_int, + address: *mut sockaddr, + address_len: *mut socklen_t, + ) -> ssize_t { + e(syscall!( + RECVFROM, + socket, + buf, + len, + flags, + address, + address_len + )) as ssize_t + } + + unsafe fn sendto( + socket: c_int, + buf: *const c_void, + len: size_t, + flags: c_int, + dest_addr: *const sockaddr, + dest_len: socklen_t, + ) -> ssize_t { + e(syscall!( + SENDTO, socket, buf, len, flags, dest_addr, dest_len + )) as ssize_t + } + + fn setsockopt( + socket: c_int, + level: c_int, + option_name: c_int, + option_value: *const c_void, + option_len: socklen_t, + ) -> c_int { + e(unsafe { + syscall!( + SETSOCKOPT, + socket, + level, + option_name, + option_value, + option_len + ) + }) as c_int + } + + fn shutdown(socket: c_int, how: c_int) -> c_int { + e(unsafe { syscall!(SHUTDOWN, socket, how) }) as c_int + } + + fn socket(domain: c_int, kind: c_int, protocol: c_int) -> c_int { + e(unsafe { syscall!(SOCKET, domain, kind, protocol) }) as c_int + } + + fn socketpair(domain: c_int, kind: c_int, protocol: c_int, socket_vector: *mut c_int) -> c_int { + e(unsafe { syscall!(SOCKETPAIR, domain, kind, protocol, socket_vector) }) as c_int + } +} diff --git a/src/platform/src/pal.rs b/src/platform/src/pal/mod.rs similarity index 67% rename from src/platform/src/pal.rs rename to src/platform/src/pal/mod.rs index 67081b439e..752ba78052 100644 --- a/src/platform/src/pal.rs +++ b/src/platform/src/pal/mod.rs @@ -1,23 +1,21 @@ +use core::ptr; + use types::*; -pub trait Pal { - fn no_pal(name: &str) -> T; +pub use self::signal::PalSignal; +mod signal; - unsafe fn accept(socket: c_int, address: *mut sockaddr, address_len: *mut socklen_t) -> c_int { - Self::no_pal("accept") - } +pub use self::socket::PalSocket; +mod socket; + +pub trait Pal { + fn no_pal(name: &str) -> c_int; fn access(path: *const c_char, mode: c_int) -> c_int { Self::no_pal("access") } - unsafe fn bind(socket: c_int, address: *const sockaddr, address_len: socklen_t) -> c_int { - Self::no_pal("bind") - } - - fn brk(addr: *mut c_void) -> *mut c_void { - Self::no_pal("brk") - } + fn brk(addr: *mut c_void) -> *mut c_void; fn chdir(path: *const c_char) -> c_int { Self::no_pal("chdir") @@ -39,10 +37,6 @@ pub trait Pal { Self::no_pal("close") } - unsafe fn connect(socket: c_int, address: *const sockaddr, address_len: socklen_t) -> c_int { - Self::no_pal("connect") - } - fn dup(fildes: c_int) -> c_int { Self::no_pal("dup") } @@ -102,7 +96,8 @@ pub trait Pal { } fn getcwd(buf: *mut c_char, size: size_t) -> *mut c_char { - Self::no_pal("getcwd") + Self::no_pal("getcwd"); + ptr::null_mut() } fn getdents(fd: c_int, dirents: *mut dirent, bytes: usize) -> c_int { @@ -133,10 +128,6 @@ pub trait Pal { Self::no_pal("getitimer") } - unsafe fn getpeername(socket: c_int, address: *mut sockaddr, address_len: *mut socklen_t) -> c_int { - Self::no_pal("getpeername") - } - fn getpgid(pid: pid_t) -> pid_t { Self::no_pal("getpgid") } @@ -149,20 +140,6 @@ pub trait Pal { Self::no_pal("getppid") } - unsafe fn getsockname(socket: c_int, address: *mut sockaddr, address_len: *mut socklen_t) -> c_int { - Self::no_pal("getsockname") - } - - fn getsockopt( - socket: c_int, - level: c_int, - option_name: c_int, - option_value: *mut c_void, - option_len: *mut socklen_t, - ) -> c_int { - Self::no_pal("getsockopt") - } - fn gettimeofday(tp: *mut timeval, tzp: *mut timezone) -> c_int { Self::no_pal("gettimeofday") } @@ -179,24 +156,12 @@ pub trait Pal { Self::no_pal("isatty") } - fn kill(pid: pid_t, sig: c_int) -> c_int { - Self::no_pal("kill") - } - - fn killpg(pgrp: pid_t, sig: c_int) -> c_int { - Self::no_pal("killpg") - } - fn link(path1: *const c_char, path2: *const c_char) -> c_int { Self::no_pal("link") } - fn listen(socket: c_int, backlog: c_int) -> c_int { - Self::no_pal("listen") - } - fn lseek(fildes: c_int, offset: off_t, whence: c_int) -> off_t { - Self::no_pal("lseek") + Self::no_pal("lseek") as off_t } fn lstat(file: *const c_char, buf: *mut stat) -> c_int { @@ -219,7 +184,7 @@ pub trait Pal { fildes: c_int, off: off_t, ) -> *mut c_void { - Self::no_pal("mmap") + Self::no_pal("mmap") as *mut c_void } unsafe fn munmap(addr: *mut c_void, len: usize) -> c_int { @@ -238,23 +203,8 @@ pub trait Pal { Self::no_pal("pipe") } - fn raise(sig: c_int) -> c_int { - Self::no_pal("raise") - } - fn read(fildes: c_int, buf: &mut [u8]) -> ssize_t { - Self::no_pal("read") - } - - unsafe fn recvfrom( - socket: c_int, - buf: *mut c_void, - len: size_t, - flags: c_int, - address: *mut sockaddr, - address_len: *mut socklen_t, - ) -> ssize_t { - Self::no_pal("recvfrom") + Self::no_pal("read") as ssize_t } fn rename(old: *const c_char, new: *const c_char) -> c_int { @@ -275,17 +225,6 @@ pub trait Pal { Self::no_pal("select") } - unsafe fn sendto( - socket: c_int, - buf: *const c_void, - len: size_t, - flags: c_int, - dest_addr: *const sockaddr, - dest_len: socklen_t, - ) -> ssize_t { - Self::no_pal("sendto") - } - fn setitimer(which: c_int, new: *const itimerval, old: *mut itimerval) -> c_int { Self::no_pal("setitimer") } @@ -302,40 +241,10 @@ pub trait Pal { Self::no_pal("setreuid") } - fn setsockopt( - socket: c_int, - level: c_int, - option_name: c_int, - option_value: *const c_void, - option_len: socklen_t, - ) -> c_int { - Self::no_pal("setsockopt") - } - - fn shutdown(socket: c_int, how: c_int) -> c_int { - Self::no_pal("shutdown") - } - - unsafe fn sigaction(sig: c_int, act: *const sigaction, oact: *mut sigaction) -> c_int { - Self::no_pal("sigaction") - } - - fn sigprocmask(how: c_int, set: *const sigset_t, oset: *mut sigset_t) -> c_int { - Self::no_pal("sigprocmask") - } - fn stat(file: *const c_char, buf: *mut stat) -> c_int { Self::no_pal("stat") } - fn socket(domain: c_int, kind: c_int, protocol: c_int) -> c_int { - Self::no_pal("socket") - } - - fn socketpair(domain: c_int, kind: c_int, protocol: c_int, socket_vector: *mut c_int) -> c_int { - Self::no_pal("socketpair") - } - fn tcgetattr(fd: c_int, out: *mut termios) -> c_int { Self::no_pal("tcgetattr") } @@ -345,11 +254,12 @@ pub trait Pal { } fn times(out: *mut tms) -> clock_t { - Self::no_pal("times") + Self::no_pal("times") as clock_t } fn umask(mask: mode_t) -> mode_t { - Self::no_pal("umask") + Self::no_pal("umask"); + 0 } fn uname(utsname: *mut utsname) -> c_int { @@ -365,6 +275,6 @@ pub trait Pal { } fn write(fildes: c_int, buf: &[u8]) -> ssize_t { - Self::no_pal("write") + Self::no_pal("write") as ssize_t } } diff --git a/src/platform/src/pal/signal.rs b/src/platform/src/pal/signal.rs new file mode 100644 index 0000000000..50176b913c --- /dev/null +++ b/src/platform/src/pal/signal.rs @@ -0,0 +1,24 @@ +use Pal; +use types::*; + +pub trait PalSignal: Pal { + fn kill(pid: pid_t, sig: c_int) -> c_int { + Self::no_pal("kill") + } + + fn killpg(pgrp: pid_t, sig: c_int) -> c_int { + Self::no_pal("killpg") + } + + fn raise(sig: c_int) -> c_int { + Self::no_pal("raise") + } + + unsafe fn sigaction(sig: c_int, act: *const sigaction, oact: *mut sigaction) -> c_int { + Self::no_pal("sigaction") + } + + fn sigprocmask(how: c_int, set: *const sigset_t, oset: *mut sigset_t) -> c_int { + Self::no_pal("sigprocmask") + } +} diff --git a/src/platform/src/pal/socket.rs b/src/platform/src/pal/socket.rs new file mode 100644 index 0000000000..8a4c72ad53 --- /dev/null +++ b/src/platform/src/pal/socket.rs @@ -0,0 +1,82 @@ +use Pal; +use types::*; + +pub trait PalSocket: Pal { + unsafe fn accept(socket: c_int, address: *mut sockaddr, address_len: *mut socklen_t) -> c_int { + Self::no_pal("accept") + } + + unsafe fn bind(socket: c_int, address: *const sockaddr, address_len: socklen_t) -> c_int { + Self::no_pal("bind") + } + + unsafe fn connect(socket: c_int, address: *const sockaddr, address_len: socklen_t) -> c_int { + Self::no_pal("connect") + } + + unsafe fn getpeername(socket: c_int, address: *mut sockaddr, address_len: *mut socklen_t) -> c_int { + Self::no_pal("getpeername") + } + + unsafe fn getsockname(socket: c_int, address: *mut sockaddr, address_len: *mut socklen_t) -> c_int { + Self::no_pal("getsockname") + } + + fn getsockopt( + socket: c_int, + level: c_int, + option_name: c_int, + option_value: *mut c_void, + option_len: *mut socklen_t, + ) -> c_int { + Self::no_pal("getsockopt") + } + + fn listen(socket: c_int, backlog: c_int) -> c_int { + Self::no_pal("listen") + } + + unsafe fn recvfrom( + socket: c_int, + buf: *mut c_void, + len: size_t, + flags: c_int, + address: *mut sockaddr, + address_len: *mut socklen_t, + ) -> ssize_t { + Self::no_pal("recvfrom") as ssize_t + } + + unsafe fn sendto( + socket: c_int, + buf: *const c_void, + len: size_t, + flags: c_int, + dest_addr: *const sockaddr, + dest_len: socklen_t, + ) -> ssize_t { + Self::no_pal("sendto") as ssize_t + } + + fn setsockopt( + socket: c_int, + level: c_int, + option_name: c_int, + option_value: *const c_void, + option_len: socklen_t, + ) -> c_int { + Self::no_pal("setsockopt") + } + + fn shutdown(socket: c_int, how: c_int) -> c_int { + Self::no_pal("shutdown") + } + + fn socket(domain: c_int, kind: c_int, protocol: c_int) -> c_int { + Self::no_pal("socket") + } + + fn socketpair(domain: c_int, kind: c_int, protocol: c_int, socket_vector: *mut c_int) -> c_int { + Self::no_pal("socketpair") + } +} diff --git a/src/platform/src/rawfile.rs b/src/platform/src/rawfile.rs index 2efc20d484..58d870123c 100644 --- a/src/platform/src/rawfile.rs +++ b/src/platform/src/rawfile.rs @@ -1,18 +1,19 @@ -use super::{close, dup, open, types::*}; use core::ops::Deref; +use {Pal, Sys, types::*}; + pub struct RawFile(c_int); impl RawFile { pub fn open(path: *const c_char, oflag: c_int, mode: mode_t) -> Result { - match open(path, oflag, mode) { + match Sys::open(path, oflag, mode) { -1 => Err(()), n => Ok(RawFile(n)), } } pub fn dup(&self) -> Result { - match dup(self.0) { + match Sys::dup(self.0) { -1 => Err(()), n => Ok(RawFile(n)), } @@ -33,7 +34,7 @@ impl RawFile { impl Drop for RawFile { fn drop(&mut self) { - let _ = close(self.0); + let _ = Sys::close(self.0); } } diff --git a/src/pwd/src/lib.rs b/src/pwd/src/lib.rs index 6d82a1f9dd..db1225092f 100644 --- a/src/pwd/src/lib.rs +++ b/src/pwd/src/lib.rs @@ -10,6 +10,7 @@ extern crate platform; use alloc::vec::Vec; use core::ptr; +use platform::{Pal, Sys}; use platform::types::*; use platform::RawFile; @@ -90,7 +91,7 @@ where buf.set_len(capacity); } - let read = platform::read(*file, &mut buf[len..]); + let read = Sys::read(*file, &mut buf[len..]); unsafe { buf.set_len(len + read as usize); diff --git a/src/signal/src/lib.rs b/src/signal/src/lib.rs index 1a463beeff..eeff480dfc 100644 --- a/src/signal/src/lib.rs +++ b/src/signal/src/lib.rs @@ -17,6 +17,7 @@ pub mod sys; pub use sys::*; use core::{mem, ptr}; +use platform::{PalSignal, Sys}; use platform::types::*; const SIG_ERR: usize = !0; @@ -45,17 +46,17 @@ pub type sigset_t = c_ulong; #[no_mangle] pub extern "C" fn kill(pid: pid_t, sig: c_int) -> c_int { - platform::kill(pid, sig) + Sys::kill(pid, sig) } #[no_mangle] pub extern "C" fn killpg(pgrp: pid_t, sig: c_int) -> c_int { - platform::killpg(pgrp, sig) + Sys::killpg(pgrp, sig) } #[no_mangle] pub extern "C" fn raise(sig: c_int) -> c_int { - platform::raise(sig) + Sys::raise(sig) } #[no_mangle] @@ -72,7 +73,7 @@ pub unsafe extern "C" fn sigaction( } else { ptr::null_mut() }; - platform::sigaction(sig, ptr, oact as *mut platform::types::sigaction) + Sys::sigaction(sig, ptr, oact as *mut platform::types::sigaction) } #[no_mangle] @@ -176,7 +177,7 @@ pub extern "C" fn sigpending(set: *mut sigset_t) -> c_int { #[no_mangle] pub extern "C" fn sigprocmask(how: c_int, set: *const sigset_t, oset: *mut sigset_t) -> c_int { - platform::sigprocmask(how, set, oset) + Sys::sigprocmask(how, set, oset) } // #[no_mangle] diff --git a/src/stdio/src/lib.rs b/src/stdio/src/lib.rs index 0b7700fc0e..8790159170 100644 --- a/src/stdio/src/lib.rs +++ b/src/stdio/src/lib.rs @@ -22,6 +22,7 @@ use core::{ptr, str}; use alloc::vec::Vec; use errno::STR_ERROR; +use platform::{Pal, Sys}; use platform::types::*; use platform::{c_str, errno, Read, Write}; use vl::VaList as va_list; @@ -110,6 +111,7 @@ impl FILE { }; return true; } + pub fn write(&mut self, to_write: &[u8]) -> usize { if let Some((wbase, wpos, _)) = self.write { let len = wpos - wbase; @@ -119,9 +121,9 @@ impl FILE { let mut rem = f_buf.len() + to_write.len(); loop { let mut count = if f_filled { - platform::write(self.fd, &f_buf[advance..]) + Sys::write(self.fd, &f_buf[advance..]) } else { - platform::write(self.fd, &f_buf[advance..]) + platform::write(self.fd, to_write) + Sys::write(self.fd, &f_buf[advance..]) + Sys::write(self.fd, to_write) }; if count == rem as isize { self.write = if self.buf.len() == 0 { @@ -152,13 +154,14 @@ impl FILE { // -- Tommoa (20/6/2018) unreachable!() } + pub fn read(&mut self, buf: &mut [u8]) -> usize { let adj = if self.buf.len() > 0 { 0 } else { 1 }; let mut file_buf = &mut self.buf[self.unget..]; let count = if buf.len() <= 1 - adj { - platform::read(self.fd, &mut file_buf) + Sys::read(self.fd, &mut file_buf) } else { - platform::read(self.fd, buf) + platform::read(self.fd, &mut file_buf) + Sys::read(self.fd, buf) + Sys::read(self.fd, &mut file_buf) }; if count <= 0 { self.flags |= if count == 0 { @@ -182,8 +185,9 @@ impl FILE { } buf.len() } + pub fn seek(&self, off: off_t, whence: c_int) -> off_t { - platform::lseek(self.fd, off, whence) + Sys::lseek(self.fd, off, whence) } pub fn lock(&mut self) -> LockGuard { @@ -266,7 +270,7 @@ pub extern "C" fn cuserid(_s: *mut c_char) -> *mut c_char { #[no_mangle] pub extern "C" fn fclose(stream: &mut FILE) -> c_int { flockfile(stream); - let r = helpers::fflush_unlocked(stream) | platform::close(stream.fd); + let r = helpers::fflush_unlocked(stream) | Sys::close(stream.fd); if stream.flags & constants::F_PERM == 0 { // Not one of stdin, stdout or stderr unsafe { @@ -444,7 +448,7 @@ pub extern "C" fn fopen(filename: *const c_char, mode: *const c_char) -> *mut FI if let Some(f) = unsafe { helpers::_fdopen(fd, mode) } { f } else { - platform::close(fd); + Sys::close(fd); ptr::null_mut() } } @@ -555,7 +559,7 @@ pub extern "C" fn freopen( let new = unsafe { &mut *new }; // Should be safe, new is not null if new.fd == stream.fd { new.fd = -1; - } else if platform::dup2(new.fd, stream.fd) < 0 + } else if Sys::dup2(new.fd, stream.fd) < 0 || fcntl::sys_fcntl(stream.fd, fcntl::F_SETFL, flags & fcntl::O_CLOEXEC) < 0 { fclose(new); @@ -824,9 +828,9 @@ pub extern "C" fn putw(w: c_int, stream: &mut FILE) -> c_int { /// Delete file or directory `path` #[no_mangle] pub extern "C" fn remove(path: *const c_char) -> c_int { - let r = platform::unlink(path); + let r = Sys::unlink(path); if r == -errno::EISDIR { - platform::rmdir(path) + Sys::rmdir(path) } else { r } @@ -834,7 +838,7 @@ pub extern "C" fn remove(path: *const c_char) -> c_int { #[no_mangle] pub extern "C" fn rename(oldpath: *const c_char, newpath: *const c_char) -> c_int { - platform::rename(oldpath, newpath) + Sys::rename(oldpath, newpath) } /// Rewind `stream` back to the beginning of it @@ -908,10 +912,10 @@ pub extern "C" fn tmpfile() -> *mut FILE { } let fp = fdopen(fd, b"w+".as_ptr() as *const i8); - platform::unlink(file_name); + Sys::unlink(file_name); if fp == ptr::null_mut() { - platform::close(fd); + Sys::close(fd); } fp diff --git a/src/stdlib/src/lib.rs b/src/stdlib/src/lib.rs index b171747806..485e991244 100644 --- a/src/stdlib/src/lib.rs +++ b/src/stdlib/src/lib.rs @@ -23,6 +23,7 @@ use wchar::*; use errno::*; use fcntl::*; +use platform::{Pal, Sys}; use platform::types::*; mod sort; @@ -235,7 +236,7 @@ pub unsafe extern "C" fn exit(status: c_int) { } } - platform::exit(status); + Sys::exit(status); } // #[no_mangle] @@ -446,7 +447,7 @@ where pub extern "C" fn mktemp(name: *mut c_char) -> *mut c_char { if inner_mktemp(name, 0, || unsafe { let mut st: stat = mem::uninitialized(); - let ret = if platform::stat(name, &mut st) != 0 && platform::errno == ENOENT { + let ret = if Sys::stat(name, &mut st) != 0 && platform::errno == ENOENT { Some(()) } else { None @@ -466,7 +467,7 @@ fn get_nstime() -> u64 { use core::mem; use time::constants::CLOCK_MONOTONIC; let mut ts: timespec = unsafe { mem::uninitialized() }; - platform::clock_gettime(CLOCK_MONOTONIC, &mut ts); + Sys::clock_gettime(CLOCK_MONOTONIC, &mut ts); ts.tv_nsec as u64 } @@ -476,7 +477,7 @@ pub extern "C" fn mkostemps(name: *mut c_char, suffix_len: c_int, mut flags: c_i flags |= O_RDWR | O_CREAT | O_EXCL; inner_mktemp(name, suffix_len, || { - let fd = platform::open(name, flags, 0600); + let fd = Sys::open(name, flags, 0600); if fd >= 0 { Some(fd) @@ -1004,7 +1005,7 @@ pub unsafe extern "C" fn system(command: *const c_char) -> c_int { unreachable!(); } else { let mut wstatus = 0; - if platform::waitpid(child_pid, &mut wstatus, 0) == !0 { + if Sys::waitpid(child_pid, &mut wstatus, 0) == !0 { return -1; } diff --git a/src/sys_ioctl/src/lib.rs b/src/sys_ioctl/src/lib.rs index 40b0427bfd..6c155363b4 100644 --- a/src/sys_ioctl/src/lib.rs +++ b/src/sys_ioctl/src/lib.rs @@ -4,6 +4,7 @@ extern crate platform; +use platform::{Pal, Sys}; use platform::types::*; // This is used from sgtty @@ -31,7 +32,7 @@ pub mod inner { #[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?? - platform::ioctl(fd, request, out) + Sys::ioctl(fd, request, out) } pub const TCGETS: c_ulong = 0x5401; diff --git a/src/sys_mman/src/lib.rs b/src/sys_mman/src/lib.rs index c2151e4036..cbe789d043 100644 --- a/src/sys_mman/src/lib.rs +++ b/src/sys_mman/src/lib.rs @@ -2,6 +2,7 @@ extern crate platform; +use platform::{Pal, Sys}; use platform::types::*; pub use sys::*; @@ -33,7 +34,7 @@ pub unsafe extern "C" fn mmap( fildes: c_int, off: off_t, ) -> *mut c_void { - platform::mmap(addr, len, prot, flags, fildes, off) + Sys::mmap(addr, len, prot, flags, fildes, off) } // #[no_mangle] @@ -58,7 +59,7 @@ pub extern "C" fn munlockall() -> c_int { #[no_mangle] pub unsafe extern "C" fn munmap(addr: *mut c_void, len: usize) -> c_int { - platform::munmap(addr, len) + Sys::munmap(addr, len) } // #[no_mangle] diff --git a/src/sys_resource/src/lib.rs b/src/sys_resource/src/lib.rs index f919012588..29612c7298 100644 --- a/src/sys_resource/src/lib.rs +++ b/src/sys_resource/src/lib.rs @@ -6,6 +6,7 @@ extern crate platform; extern crate sys_time; +use platform::{Pal, Sys}; use platform::types::*; use sys_time::timeval; @@ -55,7 +56,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 { - platform::getrusage(who, r_usage as *mut platform::types::rusage) + Sys::getrusage(who, r_usage as *mut platform::types::rusage) } // #[no_mangle] diff --git a/src/sys_select/src/lib.rs b/src/sys_select/src/lib.rs index 8b63fe29f1..0c67e3406b 100644 --- a/src/sys_select/src/lib.rs +++ b/src/sys_select/src/lib.rs @@ -4,6 +4,7 @@ extern crate platform; use core::mem; +use platform::{Pal, Sys}; use platform::types::*; // fd_set is defined in C because cbindgen is incompatible with mem::size_of booo @@ -16,5 +17,5 @@ pub extern "C" fn select( exceptfds: *mut fd_set, timeout: *mut timeval, ) -> c_int { - platform::select(nfds, readfds, writefds, exceptfds, timeout) + Sys::select(nfds, readfds, writefds, exceptfds, timeout) } diff --git a/src/sys_socket/src/lib.rs b/src/sys_socket/src/lib.rs index 7354e1b6e5..4990133c4e 100644 --- a/src/sys_socket/src/lib.rs +++ b/src/sys_socket/src/lib.rs @@ -6,6 +6,7 @@ extern crate platform; use core::ptr; +use platform::{PalSocket, Sys}; use platform::types::*; mod constants; @@ -28,7 +29,7 @@ pub unsafe extern "C" fn accept( address: *mut sockaddr, address_len: *mut socklen_t, ) -> c_int { - platform::accept( + Sys::accept( socket, address as *mut platform::types::sockaddr, address_len, @@ -41,7 +42,7 @@ pub unsafe extern "C" fn bind( address: *const sockaddr, address_len: socklen_t, ) -> c_int { - platform::bind( + Sys::bind( socket, address as *const platform::types::sockaddr, address_len, @@ -54,7 +55,7 @@ pub unsafe extern "C" fn connect( address: *const sockaddr, address_len: socklen_t, ) -> c_int { - platform::connect( + Sys::connect( socket, address as *const platform::types::sockaddr, address_len, @@ -67,7 +68,7 @@ pub unsafe extern "C" fn getpeername( address: *mut sockaddr, address_len: *mut socklen_t, ) -> c_int { - platform::getpeername( + Sys::getpeername( socket, address as *mut platform::types::sockaddr, address_len, @@ -80,7 +81,7 @@ pub unsafe extern "C" fn getsockname( address: *mut sockaddr, address_len: *mut socklen_t, ) -> c_int { - platform::getsockname( + Sys::getsockname( socket, address as *mut platform::types::sockaddr, address_len, @@ -95,12 +96,12 @@ pub unsafe extern "C" fn getsockopt( option_value: *mut c_void, option_len: *mut socklen_t, ) -> c_int { - platform::getsockopt(socket, level, option_name, option_value, option_len) + Sys::getsockopt(socket, level, option_name, option_value, option_len) } #[no_mangle] pub unsafe extern "C" fn listen(socket: c_int, backlog: c_int) -> c_int { - platform::listen(socket, backlog) + Sys::listen(socket, backlog) } #[no_mangle] @@ -129,7 +130,7 @@ pub unsafe extern "C" fn recvfrom( address: *mut sockaddr, address_len: *mut socklen_t, ) -> ssize_t { - platform::recvfrom( + Sys::recvfrom( socket, buffer, length, @@ -158,7 +159,7 @@ pub unsafe extern "C" fn sendto( dest_addr: *const sockaddr, dest_len: socklen_t, ) -> ssize_t { - platform::sendto( + Sys::sendto( socket, message, length, @@ -176,17 +177,17 @@ pub unsafe extern "C" fn setsockopt( option_value: *const c_void, option_len: socklen_t, ) -> c_int { - platform::setsockopt(socket, level, option_name, option_value, option_len) + Sys::setsockopt(socket, level, option_name, option_value, option_len) } #[no_mangle] pub unsafe extern "C" fn shutdown(socket: c_int, how: c_int) -> c_int { - platform::shutdown(socket, how) + Sys::shutdown(socket, how) } #[no_mangle] pub unsafe extern "C" fn socket(domain: c_int, kind: c_int, protocol: c_int) -> c_int { - platform::socket(domain, kind, protocol) + Sys::socket(domain, kind, protocol) } #[no_mangle] @@ -196,5 +197,5 @@ pub unsafe extern "C" fn socketpair( protocol: c_int, socket_vector: *mut c_int, ) -> c_int { - platform::socketpair(domain, kind, protocol, socket_vector) + Sys::socketpair(domain, kind, protocol, socket_vector) } diff --git a/src/sys_stat/src/lib.rs b/src/sys_stat/src/lib.rs index 17c793e5e6..459ea5406b 100644 --- a/src/sys_stat/src/lib.rs +++ b/src/sys_stat/src/lib.rs @@ -4,6 +4,7 @@ extern crate platform; +use platform::{Pal, Sys}; use platform::types::*; pub const S_IFMT: c_int = 0o0170000; @@ -59,17 +60,17 @@ pub struct stat { #[no_mangle] pub extern "C" fn chmod(path: *const c_char, mode: mode_t) -> c_int { - platform::chmod(path, mode) + Sys::chmod(path, mode) } #[no_mangle] pub extern "C" fn fchmod(fildes: c_int, mode: mode_t) -> c_int { - platform::fchmod(fildes, mode) + Sys::fchmod(fildes, mode) } #[no_mangle] pub extern "C" fn fstat(fildes: c_int, buf: *mut platform::types::stat) -> c_int { - platform::fstat(fildes, buf) + Sys::fstat(fildes, buf) } #[no_mangle] @@ -79,22 +80,22 @@ pub extern "C" fn __fxstat(_ver: c_int, fildes: c_int, buf: *mut platform::types #[no_mangle] pub extern "C" fn futimens(fd: c_int, times: *const timespec) -> c_int { - platform::futimens(fd, times) + Sys::futimens(fd, times) } #[no_mangle] pub extern "C" fn lstat(path: *const c_char, buf: *mut platform::types::stat) -> c_int { - platform::lstat(path, buf) + Sys::lstat(path, buf) } #[no_mangle] pub extern "C" fn mkdir(path: *const c_char, mode: mode_t) -> c_int { - platform::mkdir(path, mode) + Sys::mkdir(path, mode) } #[no_mangle] pub extern "C" fn mkfifo(path: *const c_char, mode: mode_t) -> c_int { - platform::mkfifo(path, mode) + Sys::mkfifo(path, mode) } // #[no_mangle] @@ -104,12 +105,12 @@ 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 { - platform::stat(file, buf) + Sys::stat(file, buf) } #[no_mangle] pub extern "C" fn umask(mask: mode_t) -> mode_t { - platform::umask(mask) + Sys::umask(mask) } /* diff --git a/src/sys_time/src/lib.rs b/src/sys_time/src/lib.rs index fae8bfddc9..dc1dfddb79 100644 --- a/src/sys_time/src/lib.rs +++ b/src/sys_time/src/lib.rs @@ -4,6 +4,7 @@ extern crate platform; +use platform::{Pal, Sys}; use platform::types::*; pub const ITIMER_REAL: c_int = 0; @@ -36,7 +37,7 @@ pub struct fd_set { #[no_mangle] pub extern "C" fn getitimer(which: c_int, value: *mut itimerval) -> c_int { - platform::getitimer(which, value as *mut platform::types::itimerval) + Sys::getitimer(which, value as *mut platform::types::itimerval) } #[no_mangle] @@ -45,7 +46,7 @@ pub extern "C" fn setitimer( value: *const itimerval, ovalue: *mut itimerval, ) -> c_int { - platform::setitimer( + Sys::setitimer( which, value as *const platform::types::itimerval, ovalue as *mut platform::types::itimerval, @@ -54,7 +55,7 @@ pub extern "C" fn setitimer( #[no_mangle] pub extern "C" fn gettimeofday(tp: *mut timeval, tzp: *mut timezone) -> c_int { - platform::gettimeofday( + Sys::gettimeofday( tp as *mut platform::types::timeval, tzp as *mut platform::types::timezone, ) @@ -83,7 +84,7 @@ pub unsafe extern "C" fn utimes(path: *const c_char, times: *const timeval) -> c tv_nsec: ((*times.offset(1)).tv_usec as i64) * 1000, }, ]; - platform::utimens(path, times_spec.as_ptr()) + Sys::utimens(path, times_spec.as_ptr()) } /* diff --git a/src/sys_times/src/lib.rs b/src/sys_times/src/lib.rs index 965e75a33b..ebceafbd12 100644 --- a/src/sys_times/src/lib.rs +++ b/src/sys_times/src/lib.rs @@ -4,6 +4,7 @@ extern crate platform; +use platform::{Pal, Sys}; use platform::types::*; #[repr(C)] @@ -16,5 +17,5 @@ pub struct tms { //#[no_mangle] pub extern "C" fn times(out: *mut tms) -> clock_t { - platform::times(out as *mut platform::types::tms) + Sys::times(out as *mut platform::types::tms) } diff --git a/src/sys_utsname/src/lib.rs b/src/sys_utsname/src/lib.rs index 916ed56e0f..0bb394d52f 100644 --- a/src/sys_utsname/src/lib.rs +++ b/src/sys_utsname/src/lib.rs @@ -6,6 +6,7 @@ mod inner { extern crate platform; + use self::platform::{Pal, Sys}; use self::platform::types::*; const UTSLENGTH: usize = 65; @@ -22,7 +23,7 @@ mod inner { #[no_mangle] pub unsafe extern "C" fn uname(uts: *mut utsname) -> c_int { - platform::uname(uts as *mut platform::types::utsname) + Sys::uname(uts as *mut platform::types::utsname) } } #[cfg(target_os = "linux")] diff --git a/src/sys_wait/src/lib.rs b/src/sys_wait/src/lib.rs index 311678c138..f0f4655dd4 100644 --- a/src/sys_wait/src/lib.rs +++ b/src/sys_wait/src/lib.rs @@ -6,6 +6,7 @@ extern crate platform; extern crate sys_resource; +use platform::{Pal, Sys}; use platform::types::*; use sys_resource::rusage; @@ -51,5 +52,5 @@ pub unsafe extern "C" fn wait3( #[no_mangle] pub unsafe extern "C" fn waitpid(pid: pid_t, stat_loc: *mut c_int, options: c_int) -> pid_t { - platform::waitpid(pid, stat_loc, options) + Sys::waitpid(pid, stat_loc, options) } diff --git a/src/termios/src/lib.rs b/src/termios/src/lib.rs index e7306f76fc..b0001158d8 100644 --- a/src/termios/src/lib.rs +++ b/src/termios/src/lib.rs @@ -3,6 +3,7 @@ extern crate platform; +use platform::{Pal, Sys}; use platform::types::*; pub type cc_t = u8; @@ -25,12 +26,12 @@ pub struct termios { #[no_mangle] pub extern "C" fn tcgetattr(fd: c_int, out: *mut termios) -> c_int { - platform::tcgetattr(fd, out as *mut platform::types::termios) + Sys::tcgetattr(fd, out as *mut platform::types::termios) } #[no_mangle] pub extern "C" fn tcsetattr(fd: c_int, act: c_int, value: *mut termios) -> c_int { - platform::tcsetattr(fd, act, value as *mut platform::types::termios) + Sys::tcsetattr(fd, act, value as *mut platform::types::termios) } pub const VINTR: usize = 0; diff --git a/src/time/src/lib.rs b/src/time/src/lib.rs index 69ca7dcc9b..75aae5ffd1 100644 --- a/src/time/src/lib.rs +++ b/src/time/src/lib.rs @@ -15,6 +15,7 @@ use constants::*; use core::mem::transmute; use errno::EIO; use helpers::*; +use platform::{Pal, Sys}; use platform::types::*; #[repr(C)] @@ -121,7 +122,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 { - platform::clock_gettime(clock_id, tp as *mut platform::types::timespec) + Sys::clock_gettime(clock_id, tp as *mut platform::types::timespec) } // #[no_mangle] @@ -328,7 +329,7 @@ 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 { - platform::nanosleep( + Sys::nanosleep( rqtp as *const platform::types::timespec, rmtp as *mut platform::types::timespec, ) @@ -361,7 +362,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(); - platform::clock_gettime(CLOCK_REALTIME, &mut ts); + Sys::clock_gettime(CLOCK_REALTIME, &mut ts); unsafe { if !tloc.is_null() { *tloc = ts.tv_sec diff --git a/src/unistd/src/brk.rs b/src/unistd/src/brk.rs index bd186f8eba..78ece98354 100644 --- a/src/unistd/src/brk.rs +++ b/src/unistd/src/brk.rs @@ -2,13 +2,14 @@ use core::ptr; use errno::ENOMEM; use platform; +use platform::{Pal, Sys}; use platform::types::*; static mut BRK: *mut c_void = ptr::null_mut(); #[no_mangle] pub unsafe extern "C" fn brk(addr: *mut c_void) -> c_int { - BRK = platform::brk(addr); + BRK = Sys::brk(addr); if BRK < addr { platform::errno = ENOMEM; @@ -21,7 +22,7 @@ pub unsafe extern "C" fn brk(addr: *mut c_void) -> c_int { #[no_mangle] pub unsafe extern "C" fn sbrk(incr: intptr_t) -> *mut c_void { if BRK == ptr::null_mut() { - BRK = platform::brk(ptr::null_mut()); + BRK = Sys::brk(ptr::null_mut()); } let old_brk = BRK; @@ -29,7 +30,7 @@ pub unsafe extern "C" fn sbrk(incr: intptr_t) -> *mut c_void { if incr != 0 { let addr = old_brk.offset(incr); - BRK = platform::brk(addr); + BRK = Sys::brk(addr); if BRK < addr { platform::errno = ENOMEM; diff --git a/src/unistd/src/lib.rs b/src/unistd/src/lib.rs index 944d972669..aef969838c 100644 --- a/src/unistd/src/lib.rs +++ b/src/unistd/src/lib.rs @@ -10,6 +10,7 @@ extern crate sys_time; use core::{ptr, slice}; +use platform::{Pal, Sys}; use platform::types::*; pub use brk::*; @@ -42,12 +43,12 @@ const PATH_MAX: usize = 4096; #[no_mangle] pub extern "C" fn _exit(status: c_int) { - platform::exit(status) + Sys::exit(status) } #[no_mangle] pub extern "C" fn access(path: *const c_char, mode: c_int) -> c_int { - platform::access(path, mode) + Sys::access(path, mode) } #[no_mangle] @@ -74,7 +75,7 @@ pub extern "C" fn alarm(seconds: c_uint) -> c_uint { #[no_mangle] pub extern "C" fn chdir(path: *const c_char) -> c_int { - platform::chdir(path) + Sys::chdir(path) } // #[no_mangle] @@ -84,12 +85,12 @@ pub extern "C" fn chroot(path: *const c_char) -> c_int { #[no_mangle] pub extern "C" fn chown(path: *const c_char, owner: uid_t, group: gid_t) -> c_int { - platform::chown(path, owner, group) + Sys::chown(path, owner, group) } #[no_mangle] pub extern "C" fn close(fildes: c_int) -> c_int { - platform::close(fildes) + Sys::close(fildes) } // #[no_mangle] @@ -104,12 +105,12 @@ pub extern "C" fn crypt(key: *const c_char, salt: *const c_char) -> *mut c_char #[no_mangle] pub extern "C" fn dup(fildes: c_int) -> c_int { - platform::dup(fildes) + Sys::dup(fildes) } #[no_mangle] pub extern "C" fn dup2(fildes: c_int, fildes2: c_int) -> c_int { - platform::dup2(fildes, fildes2) + Sys::dup2(fildes, fildes2) } // #[no_mangle] @@ -147,7 +148,7 @@ pub unsafe extern "C" fn execve( argv: *const *mut c_char, envp: *const *mut c_char, ) -> c_int { - platform::execve(path, argv, envp) + Sys::execve(path, argv, envp) } // #[no_mangle] @@ -157,12 +158,12 @@ pub extern "C" fn execvp(file: *const c_char, argv: *const *mut c_char) -> c_int #[no_mangle] pub extern "C" fn fchown(fildes: c_int, owner: uid_t, group: gid_t) -> c_int { - platform::fchown(fildes, owner, group) + Sys::fchown(fildes, owner, group) } #[no_mangle] pub extern "C" fn fchdir(fildes: c_int) -> c_int { - platform::fchdir(fildes) + Sys::fchdir(fildes) } // #[no_mangle] @@ -172,17 +173,17 @@ pub extern "C" fn fdatasync(fildes: c_int) -> c_int { #[no_mangle] pub extern "C" fn fork() -> pid_t { - platform::fork() + Sys::fork() } #[no_mangle] pub extern "C" fn fsync(fildes: c_int) -> c_int { - platform::fsync(fildes) + Sys::fsync(fildes) } #[no_mangle] pub extern "C" fn ftruncate(fildes: c_int, length: off_t) -> c_int { - platform::ftruncate(fildes, length) + Sys::ftruncate(fildes, length) } #[no_mangle] @@ -194,7 +195,7 @@ pub extern "C" fn getcwd(mut buf: *mut c_char, mut size: size_t) -> *mut c_char size = stack_buf.len(); } - let ret = platform::getcwd(buf, size); + let ret = Sys::getcwd(buf, size); if ret == ptr::null_mut() { return ptr::null_mut(); } @@ -220,17 +221,17 @@ pub extern "C" fn getdtablesize() -> c_int { #[no_mangle] pub extern "C" fn getegid() -> gid_t { - platform::getegid() + Sys::getegid() } #[no_mangle] pub extern "C" fn geteuid() -> uid_t { - platform::geteuid() + Sys::geteuid() } #[no_mangle] pub extern "C" fn getgid() -> gid_t { - platform::getgid() + Sys::getgid() } // #[no_mangle] @@ -245,7 +246,7 @@ pub extern "C" fn gethostid() -> c_long { #[no_mangle] pub unsafe extern "C" fn gethostname(name: *mut c_char, len: size_t) -> c_int { - platform::gethostname(name, len) + Sys::gethostname(name, len) } // #[no_mangle] @@ -270,22 +271,22 @@ pub extern "C" fn getpass(prompt: *const c_char) -> *mut c_char { #[no_mangle] pub extern "C" fn getpgid(pid: pid_t) -> pid_t { - platform::getpgid(pid) + Sys::getpgid(pid) } #[no_mangle] pub extern "C" fn getpgrp() -> pid_t { - platform::getpgid(platform::getpid()) + Sys::getpgid(Sys::getpid()) } #[no_mangle] pub extern "C" fn getpid() -> pid_t { - platform::getpid() + Sys::getpid() } #[no_mangle] pub extern "C" fn getppid() -> pid_t { - platform::getppid() + Sys::getppid() } // #[no_mangle] @@ -295,7 +296,7 @@ pub extern "C" fn getsid(pid: pid_t) -> pid_t { #[no_mangle] pub extern "C" fn getuid() -> uid_t { - platform::getuid() + Sys::getuid() } #[no_mangle] @@ -305,7 +306,7 @@ pub extern "C" fn getwd(path_name: *mut c_char) -> *mut c_char { #[no_mangle] pub extern "C" fn isatty(fd: c_int) -> c_int { - platform::isatty(fd) + Sys::isatty(fd) } // #[no_mangle] @@ -315,7 +316,7 @@ pub extern "C" fn lchown(path: *const c_char, owner: uid_t, group: gid_t) -> c_i #[no_mangle] pub extern "C" fn link(path1: *const c_char, path2: *const c_char) -> c_int { - platform::link(path1, path2) + Sys::link(path1, path2) } // #[no_mangle] @@ -325,7 +326,7 @@ pub extern "C" fn lockf(fildes: c_int, function: c_int, size: off_t) -> c_int { #[no_mangle] pub extern "C" fn lseek(fildes: c_int, offset: off_t, whence: c_int) -> off_t { - platform::lseek(fildes, offset, whence) + Sys::lseek(fildes, offset, whence) } // #[no_mangle] @@ -340,7 +341,7 @@ pub extern "C" fn pause() -> c_int { #[no_mangle] pub unsafe extern "C" fn pipe(fildes: *mut c_int) -> c_int { - platform::pipe(slice::from_raw_parts_mut(fildes, 2)) + Sys::pipe(slice::from_raw_parts_mut(fildes, 2)) } // #[no_mangle] @@ -371,7 +372,7 @@ pub extern "C" fn pwrite( pub extern "C" fn read(fildes: c_int, buf: *const c_void, nbyte: size_t) -> ssize_t { use core::slice; let buf = unsafe { slice::from_raw_parts_mut(buf as *mut u8, nbyte as usize) }; - platform::read(fildes, buf) + Sys::read(fildes, buf) } // #[no_mangle] @@ -381,17 +382,17 @@ pub extern "C" fn readlink(path: *const c_char, buf: *mut c_char, bufsize: size_ #[no_mangle] pub extern "C" fn rmdir(path: *const c_char) -> c_int { - platform::rmdir(path) + Sys::rmdir(path) } #[no_mangle] pub extern "C" fn setgid(gid: gid_t) -> c_int { - platform::setregid(gid, gid) + Sys::setregid(gid, gid) } #[no_mangle] pub extern "C" fn setpgid(pid: pid_t, pgid: pid_t) -> c_int { - platform::setpgid(pid, pgid) + Sys::setpgid(pid, pgid) } // #[no_mangle] @@ -401,12 +402,12 @@ pub extern "C" fn setpgrp() -> pid_t { #[no_mangle] pub extern "C" fn setregid(rgid: gid_t, egid: gid_t) -> c_int { - platform::setregid(rgid, egid) + Sys::setregid(rgid, egid) } #[no_mangle] pub extern "C" fn setreuid(ruid: uid_t, euid: uid_t) -> c_int { - platform::setreuid(ruid, euid) + Sys::setreuid(ruid, euid) } // #[no_mangle] @@ -416,7 +417,7 @@ pub extern "C" fn setsid() -> pid_t { #[no_mangle] pub extern "C" fn setuid(uid: uid_t) -> c_int { - platform::setreuid(uid, uid) + Sys::setreuid(uid, uid) } #[no_mangle] @@ -426,7 +427,7 @@ pub extern "C" fn sleep(seconds: c_uint) -> c_uint { tv_nsec: 0, }; let rmtp = ptr::null_mut(); - platform::nanosleep(&rqtp, rmtp); + Sys::nanosleep(&rqtp, rmtp); 0 } @@ -502,7 +503,7 @@ pub extern "C" fn ualarm(value: useconds_t, interval: useconds_t) -> useconds_t #[no_mangle] pub extern "C" fn unlink(path: *const c_char) -> c_int { - platform::unlink(path) + Sys::unlink(path) } #[no_mangle] @@ -512,7 +513,7 @@ pub extern "C" fn usleep(useconds: useconds_t) -> c_int { tv_nsec: ((useconds % 1000) * 1000) as i64, }; let rmtp = ptr::null_mut(); - platform::nanosleep(&rqtp, rmtp) + Sys::nanosleep(&rqtp, rmtp) } // #[no_mangle] @@ -525,7 +526,7 @@ pub extern "C" fn write(fildes: c_int, buf: *const c_void, nbyte: size_t) -> ssi use core::slice; let buf = unsafe { slice::from_raw_parts(buf as *const u8, nbyte as usize) }; - platform::write(fildes, buf) + Sys::write(fildes, buf) } /* diff --git a/src/utime/src/lib.rs b/src/utime/src/lib.rs index cea8b06f8d..16ad0348f7 100644 --- a/src/utime/src/lib.rs +++ b/src/utime/src/lib.rs @@ -4,6 +4,7 @@ extern crate platform; +use platform::{Pal, Sys}; use platform::types::*; #[repr(C)] @@ -25,5 +26,5 @@ pub unsafe extern "C" fn utime(filename: *const c_char, times: *const utimbuf) - tv_nsec: 0, }, ]; - platform::utimens(filename, times_spec.as_ptr()) + Sys::utimens(filename, times_spec.as_ptr()) } From 165f099c6bdff303bfc3de004c8583f39036aec5 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sat, 25 Aug 2018 09:07:35 -0600 Subject: [PATCH 03/19] Update Redox platform to pal --- src/platform/src/linux/mod.rs | 8 +- src/platform/src/pal/mod.rs | 2 +- src/platform/src/redox/mod.rs | 1689 ++++++++++++------------------ src/platform/src/redox/signal.rs | 47 + src/platform/src/redox/socket.rs | 180 ++++ 5 files changed, 908 insertions(+), 1018 deletions(-) create mode 100644 src/platform/src/redox/signal.rs create mode 100644 src/platform/src/redox/socket.rs diff --git a/src/platform/src/linux/mod.rs b/src/platform/src/linux/mod.rs index 276a18bcb8..ccdd0f9b49 100644 --- a/src/platform/src/linux/mod.rs +++ b/src/platform/src/linux/mod.rs @@ -1,9 +1,7 @@ use core::{mem, ptr}; use core::fmt::Write; -use FileWriter; -use Pal; -use errno; +use {errno, FileWriter, Pal}; use types::*; mod signal; @@ -81,8 +79,8 @@ impl Pal for Sys { e(unsafe { syscall!(DUP3, fildes, fildes2, 0) }) as c_int } - fn execve(path: *const c_char, argv: *const *mut c_char, envp: *const *mut c_char) -> c_int { - e(unsafe { syscall!(EXECVE, path, argv, envp) }) as c_int + unsafe fn execve(path: *const c_char, argv: *const *mut c_char, envp: *const *mut c_char) -> c_int { + e(syscall!(EXECVE, path, argv, envp)) as c_int } fn exit(status: c_int) -> ! { diff --git a/src/platform/src/pal/mod.rs b/src/platform/src/pal/mod.rs index 752ba78052..92410c3882 100644 --- a/src/platform/src/pal/mod.rs +++ b/src/platform/src/pal/mod.rs @@ -45,7 +45,7 @@ pub trait Pal { Self::no_pal("dup2") } - fn execve(path: *const c_char, argv: *const *mut c_char, envp: *const *mut c_char) -> c_int { + unsafe fn execve(path: *const c_char, argv: *const *mut c_char, envp: *const *mut c_char) -> c_int { Self::no_pal("execve") } diff --git a/src/platform/src/redox/mod.rs b/src/platform/src/redox/mod.rs index 1f4b996ace..41750b7893 100644 --- a/src/platform/src/redox/mod.rs +++ b/src/platform/src/redox/mod.rs @@ -1,18 +1,19 @@ //! sys/socket implementation, following http://pubs.opengroup.org/onlinepubs/009696699/basedefs/sys/socket.h.html use alloc::btree_map::BTreeMap; -use core::fmt::Write; use core::{mem, ptr, slice}; +use core::fmt::Write; use spin::{Once, Mutex, MutexGuard}; use syscall::data::Stat as redox_stat; use syscall::data::TimeSpec as redox_timespec; use syscall::flag::*; use syscall::{self, Result}; +use {c_str, errno, FileReader, FileWriter, Pal, RawFile, Read}; use types::*; -use *; const EINVAL: c_int = 22; +const ENOSYS: c_int = 38; const MAP_ANON: c_int = 1; #[thread_local] @@ -42,1073 +43,737 @@ fn e(sys: Result) -> usize { } } -macro_rules! bind_or_connect { - (bind $path:expr) => { - concat!("/", $path) - }; - (connect $path:expr) => { - $path - }; - ($mode:ident $socket:expr, $address:expr, $address_len:expr) => {{ - if (*$address).sa_family as c_int != AF_INET { - errno = syscall::EAFNOSUPPORT; - return -1; - } - if ($address_len as usize) < mem::size_of::() { - errno = syscall::EINVAL; - 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); +pub struct Sys; - // Duplicate the socket, and then duplicate the copy back to the original fd - let fd = e(syscall::dup($socket as usize, path.as_bytes())); - if (fd as c_int) < 0 { - return -1; - } - let result = syscall::dup2(fd, $socket as usize, &[]); - let _ = syscall::close(fd); - if (e(result) as c_int) < 0 { - return -1; - } - 0 - }} -} - -pub unsafe fn accept(socket: c_int, address: *mut sockaddr, address_len: *mut socklen_t) -> c_int { - let stream = e(syscall::dup(socket as usize, b"listen")) as c_int; - if stream < 0 { - return -1; - } - if address != ptr::null_mut() - && address_len != ptr::null_mut() - && getpeername(stream, address, address_len) < 0 - { - return -1; - } - stream -} - -pub fn access(path: *const c_char, mode: c_int) -> c_int { - let fd = match RawFile::open(path, 0, 0) { - Ok(fd) => fd, - Err(_) => return -1 - }; - if mode == F_OK { - return 0; - } - - let mut stat = syscall::Stat::default(); - - if e(syscall::fstat(*fd as usize, &mut stat)) == !0 { - return -1; - } - - let uid = e(syscall::getuid()); - if uid == !0 { - return -1; - } - let gid = e(syscall::getgid()); - if gid == !0 { - return -1; - } - - let perms = if stat.st_uid as usize == uid { - // octal has max 7 characters, binary has max two. And we're interested - // in the 3rd digit - stat.st_mode >> ((7 / 2) * 2 & 0o7) - } else if stat.st_gid as usize == gid { - stat.st_mode >> ((7 / 2) & 0o7) - } else { - stat.st_mode & 0o7 - }; - if (mode & R_OK == R_OK && perms & 0o4 != 0o4) - || (mode & W_OK == W_OK && perms & 0o2 != 0o2) - || (mode & X_OK == X_OK && perms & 0o1 != 0o1) { +impl Pal for Sys { + fn no_pal(name: &str) -> c_int { + let _ = writeln!(FileWriter(2), "relibc: no_pal: {}", name); unsafe { - errno = EINVAL; + errno = ENOSYS; } - return -1; + -1 } - 0 -} - -pub unsafe fn bind(socket: c_int, address: *const sockaddr, address_len: socklen_t) -> c_int { - bind_or_connect!(bind socket, address, address_len) -} - -pub fn brk(addr: *mut c_void) -> *mut c_void { - unsafe { syscall::brk(addr as usize).unwrap_or(0) as *mut c_void } -} - -pub fn chdir(path: *const c_char) -> c_int { - let path = unsafe { c_str(path) }; - e(syscall::chdir(path)) as c_int -} - -pub fn chmod(path: *const c_char, mode: mode_t) -> c_int { - let path = unsafe { c_str(path) }; - match syscall::open(path, O_WRONLY) { - Err(err) => e(Err(err)) as c_int, - Ok(fd) => { - let res = syscall::fchmod(fd as usize, mode as u16); - let _ = syscall::close(fd); - e(res) as c_int + fn access(path: *const c_char, mode: c_int) -> c_int { + let fd = match RawFile::open(path, 0, 0) { + Ok(fd) => fd, + Err(_) => return -1 + }; + if mode == F_OK { + return 0; } - } -} -pub fn chown(path: *const c_char, owner: uid_t, group: gid_t) -> c_int { - let path = unsafe { c_str(path) }; - match syscall::open(path, O_WRONLY) { - Err(err) => e(Err(err)) as c_int, - Ok(fd) => { - let res = syscall::fchown(fd as usize, owner as u32, group as u32); - let _ = syscall::close(fd); - e(res) as c_int + let mut stat = syscall::Stat::default(); + + if e(syscall::fstat(*fd as usize, &mut stat)) == !0 { + return -1; } - } -} -pub fn close(fd: c_int) -> c_int { - e(syscall::close(fd as usize)) as c_int -} - -pub unsafe fn connect(socket: c_int, address: *const sockaddr, address_len: socklen_t) -> c_int { - bind_or_connect!(connect socket, address, address_len) -} - -pub fn dup(fd: c_int) -> c_int { - e(syscall::dup(fd as usize, &[])) as c_int -} - -pub fn dup2(fd1: c_int, fd2: c_int) -> c_int { - e(syscall::dup2(fd1 as usize, fd2 as usize, &[])) as c_int -} - -pub fn exit(status: c_int) -> ! { - let _ = syscall::exit(status as usize); - loop {} -} - -pub unsafe extern "C" fn execve( - path: *const c_char, - mut argv: *const *mut c_char, - mut envp: *const *mut c_char, -) -> c_int { - use alloc::Vec; - - let fd = match RawFile::open(path, O_RDONLY as c_int, 0) { - Ok(fd) => fd, - Err(_) => return -1 - }; - - let mut len = 0; - while !(*argv.offset(len)).is_null() { - len += 1; - } - - let mut args: Vec<[usize; 2]> = Vec::with_capacity(len as usize); - while !(*argv).is_null() { - let arg = *argv; - - let mut len = 0; - while *arg.offset(len) != 0 { - len += 1; + let uid = e(syscall::getuid()); + if uid == !0 { + return -1; } - args.push([arg as usize, len as usize]); - argv = argv.offset(1); - } - - let mut len = 0; - while !(*envp.offset(len)).is_null() { - len += 1; - } - - let mut envs: Vec<[usize; 2]> = Vec::with_capacity(len as usize); - while !(*envp).is_null() { - let env = *envp; - - let mut len = 0; - while *env.offset(len) != 0 { - len += 1; + let gid = e(syscall::getgid()); + if gid == !0 { + return -1; } - envs.push([env as usize, len as usize]); - envp = envp.offset(1); + + let perms = if stat.st_uid as usize == uid { + // octal has max 7 characters, binary has max two. And we're interested + // in the 3rd digit + stat.st_mode >> ((7 / 2) * 2 & 0o7) + } else if stat.st_gid as usize == gid { + stat.st_mode >> ((7 / 2) & 0o7) + } else { + stat.st_mode & 0o7 + }; + if (mode & R_OK == R_OK && perms & 0o4 != 0o4) + || (mode & W_OK == W_OK && perms & 0o2 != 0o2) + || (mode & X_OK == X_OK && perms & 0o1 != 0o1) { + unsafe { + errno = EINVAL; + } + return -1; + } + + 0 } - e(syscall::fexec(*fd as usize, &args, &envs)) as c_int -} + fn brk(addr: *mut c_void) -> *mut c_void { + unsafe { syscall::brk(addr as usize).unwrap_or(0) as *mut c_void } + } -pub fn fchdir(fd: c_int) -> c_int { - let path: &mut [u8] = &mut [0; 4096]; - if e(syscall::fpath(fd as usize, path)) == !0 { - !0 - } else { + fn chdir(path: *const c_char) -> c_int { + let path = unsafe { c_str(path) }; e(syscall::chdir(path)) as c_int } -} -pub fn fchmod(fd: c_int, mode: mode_t) -> c_int { - e(syscall::fchmod(fd as usize, mode as u16)) as c_int -} - -pub fn fchown(fd: c_int, owner: uid_t, group: gid_t) -> c_int { - e(syscall::fchown(fd as usize, owner as u32, group as u32)) as c_int -} - -pub fn fcntl(fd: c_int, cmd: c_int, args: c_int) -> c_int { - e(syscall::fcntl(fd as usize, cmd as usize, args as usize)) as c_int -} - -pub fn flock(_fd: c_int, _operation: c_int) -> c_int { - // TODO: Redox does not have file locking yet - 0 -} - -pub fn fork() -> pid_t { - e(unsafe { syscall::clone(0) }) as pid_t -} - -pub fn fstat(fildes: c_int, buf: *mut stat) -> c_int { - let mut redox_buf: redox_stat = redox_stat::default(); - match e(syscall::fstat(fildes as usize, &mut redox_buf)) { - 0 => { - unsafe { - if !buf.is_null() { - (*buf).st_dev = redox_buf.st_dev as dev_t; - (*buf).st_ino = redox_buf.st_ino as ino_t; - (*buf).st_nlink = redox_buf.st_nlink as nlink_t; - (*buf).st_mode = redox_buf.st_mode as mode_t; - (*buf).st_uid = redox_buf.st_uid as uid_t; - (*buf).st_gid = redox_buf.st_gid as gid_t; - // TODO st_rdev - (*buf).st_rdev = 0; - (*buf).st_size = redox_buf.st_size as off_t; - (*buf).st_blksize = redox_buf.st_blksize as blksize_t; - (*buf).st_atim = timespec { - tv_sec: redox_buf.st_atime as time_t, - tv_nsec: redox_buf.st_atime_nsec as c_long, - }; - (*buf).st_mtim = timespec { - tv_sec: redox_buf.st_mtime as time_t, - tv_nsec: redox_buf.st_mtime_nsec as c_long, - }; - (*buf).st_ctim = timespec { - tv_sec: redox_buf.st_ctime as time_t, - tv_nsec: redox_buf.st_ctime_nsec as c_long, - }; - } + fn chmod(path: *const c_char, mode: mode_t) -> c_int { + let path = unsafe { c_str(path) }; + match syscall::open(path, O_WRONLY) { + Err(err) => e(Err(err)) as c_int, + Ok(fd) => { + let res = syscall::fchmod(fd as usize, mode as u16); + let _ = syscall::close(fd); + e(res) as c_int } - 0 - } - _ => -1, - } -} - -pub fn fsync(fd: c_int) -> c_int { - e(syscall::fsync(fd as usize)) as c_int -} - -pub fn ftruncate(fd: c_int, len: off_t) -> c_int { - e(syscall::ftruncate(fd as usize, len as usize)) as c_int -} - -pub fn futimens(fd: c_int, times: *const timespec) -> c_int { - let times = [unsafe { redox_timespec::from(&*times) }, unsafe { - redox_timespec::from(&*times.offset(1)) - }]; - e(syscall::futimens(fd as usize, ×)) as c_int -} - -pub fn utimens(path: *const c_char, times: *const timespec) -> c_int { - let path = unsafe { c_str(path) }; - match syscall::open(path, O_STAT) { - Err(err) => e(Err(err)) as c_int, - Ok(fd) => { - let res = futimens(fd as c_int, times); - let _ = syscall::close(fd); - res } } -} -pub fn getcwd(buf: *mut c_char, size: size_t) -> *mut c_char { - let buf_slice = unsafe { slice::from_raw_parts_mut(buf as *mut u8, size as usize - 1) }; - let read = e(syscall::getcwd(buf_slice)); - if read == !0 { - ptr::null_mut() - } else { - unsafe { - *buf.offset(read as isize + 1) = 0; + fn chown(path: *const c_char, owner: uid_t, group: gid_t) -> c_int { + let path = unsafe { c_str(path) }; + match syscall::open(path, O_WRONLY) { + Err(err) => e(Err(err)) as c_int, + Ok(fd) => { + let res = syscall::fchown(fd as usize, owner as u32, group as u32); + let _ = syscall::close(fd); + e(res) as c_int + } } - buf } -} -pub fn getdents(fd: c_int, mut dirents: *mut dirent, mut bytes: usize) -> c_int { - let mut amount = 0; - - let mut buf = [0; 1024]; - let mut bindex = 0; - let mut blen = 0; - - let mut name = [0; 256]; - let mut nindex = 0; - - loop { - if bindex >= blen { - bindex = 0; - blen = match syscall::read(fd as usize, &mut buf) { - Ok(0) => return amount, - Ok(n) => n, - Err(err) => return -err.errno, - }; - } - - if buf[bindex] == b'\n' { - // Put a NUL byte either at the end, or if it's too big, at where it's truncated. - name[nindex.min(name.len() - 1)] = 0; - unsafe { - *dirents = dirent { - d_ino: 0, - d_off: 0, - d_reclen: mem::size_of::() as c_ushort, - d_type: 0, - d_name: name, + fn clock_gettime(clk_id: clockid_t, tp: *mut timespec) -> c_int { + let mut redox_tp = unsafe { redox_timespec::from(&*tp) }; + match e(syscall::clock_gettime(clk_id as usize, &mut redox_tp)) as c_int { + -1 => -1, + _ => { + unsafe { + (*tp).tv_sec = redox_tp.tv_sec; + (*tp).tv_nsec = redox_tp.tv_nsec as i64; }; - dirents = dirents.offset(1); + 0 } - amount += 1; - if bytes <= mem::size_of::() { - return amount; + } + } + + fn close(fd: c_int) -> c_int { + e(syscall::close(fd as usize)) as c_int + } + + fn dup(fd: c_int) -> c_int { + e(syscall::dup(fd as usize, &[])) as c_int + } + + fn dup2(fd1: c_int, fd2: c_int) -> c_int { + e(syscall::dup2(fd1 as usize, fd2 as usize, &[])) as c_int + } + + fn exit(status: c_int) -> ! { + let _ = syscall::exit(status as usize); + loop {} + } + + unsafe fn execve( + path: *const c_char, + mut argv: *const *mut c_char, + mut envp: *const *mut c_char, + ) -> c_int { + use alloc::Vec; + + let fd = match RawFile::open(path, O_RDONLY as c_int, 0) { + Ok(fd) => fd, + Err(_) => return -1 + }; + + let mut len = 0; + while !(*argv.offset(len)).is_null() { + len += 1; + } + + let mut args: Vec<[usize; 2]> = Vec::with_capacity(len as usize); + while !(*argv).is_null() { + let arg = *argv; + + let mut len = 0; + while *arg.offset(len) != 0 { + len += 1; } - bytes -= mem::size_of::(); + args.push([arg as usize, len as usize]); + argv = argv.offset(1); + } + + let mut len = 0; + while !(*envp.offset(len)).is_null() { + len += 1; + } + + let mut envs: Vec<[usize; 2]> = Vec::with_capacity(len as usize); + while !(*envp).is_null() { + let env = *envp; + + let mut len = 0; + while *env.offset(len) != 0 { + len += 1; + } + envs.push([env as usize, len as usize]); + envp = envp.offset(1); + } + + e(syscall::fexec(*fd as usize, &args, &envs)) as c_int + } + + fn fchdir(fd: c_int) -> c_int { + let path: &mut [u8] = &mut [0; 4096]; + if e(syscall::fpath(fd as usize, path)) == !0 { + !0 } else { - if nindex < name.len() { - name[nindex] = buf[bindex] as c_char; + e(syscall::chdir(path)) as c_int + } + } + + fn fchmod(fd: c_int, mode: mode_t) -> c_int { + e(syscall::fchmod(fd as usize, mode as u16)) as c_int + } + + fn fchown(fd: c_int, owner: uid_t, group: gid_t) -> c_int { + e(syscall::fchown(fd as usize, owner as u32, group as u32)) as c_int + } + + fn fcntl(fd: c_int, cmd: c_int, args: c_int) -> c_int { + e(syscall::fcntl(fd as usize, cmd as usize, args as usize)) as c_int + } + + fn flock(_fd: c_int, _operation: c_int) -> c_int { + // TODO: Redox does not have file locking yet + 0 + } + + fn fork() -> pid_t { + e(unsafe { syscall::clone(0) }) as pid_t + } + + fn fstat(fildes: c_int, buf: *mut stat) -> c_int { + let mut redox_buf: redox_stat = redox_stat::default(); + match e(syscall::fstat(fildes as usize, &mut redox_buf)) { + 0 => { + unsafe { + if !buf.is_null() { + (*buf).st_dev = redox_buf.st_dev as dev_t; + (*buf).st_ino = redox_buf.st_ino as ino_t; + (*buf).st_nlink = redox_buf.st_nlink as nlink_t; + (*buf).st_mode = redox_buf.st_mode as mode_t; + (*buf).st_uid = redox_buf.st_uid as uid_t; + (*buf).st_gid = redox_buf.st_gid as gid_t; + // TODO st_rdev + (*buf).st_rdev = 0; + (*buf).st_size = redox_buf.st_size as off_t; + (*buf).st_blksize = redox_buf.st_blksize as blksize_t; + (*buf).st_atim = timespec { + tv_sec: redox_buf.st_atime as time_t, + tv_nsec: redox_buf.st_atime_nsec as c_long, + }; + (*buf).st_mtim = timespec { + tv_sec: redox_buf.st_mtime as time_t, + tv_nsec: redox_buf.st_mtime_nsec as c_long, + }; + (*buf).st_ctim = timespec { + tv_sec: redox_buf.st_ctime as time_t, + tv_nsec: redox_buf.st_ctime_nsec as c_long, + }; + } + } + 0 } - nindex += 1; - bindex += 1; + _ => -1, } } -} -pub fn getegid() -> gid_t { - e(syscall::getegid()) as gid_t -} - -pub fn geteuid() -> uid_t { - e(syscall::geteuid()) as uid_t -} - -pub fn getgid() -> gid_t { - e(syscall::getgid()) as gid_t -} - -pub fn getrusage(who: c_int, r_usage: *mut rusage) -> c_int { - let _ = writeln!( - FileWriter(2), - "unimplemented: getrusage({}, {:p})", - who, - r_usage - ); - -1 -} - -pub unsafe fn gethostname(mut name: *mut c_char, len: size_t) -> c_int { - let fd = e(syscall::open("/etc/hostname", O_RDONLY)) as i32; - if fd < 0 { - return fd; + fn fsync(fd: c_int) -> c_int { + e(syscall::fsync(fd as usize)) as c_int } - let mut reader = FileReader(fd); - for _ in 0..len { - match reader.read_u8() { - Ok(Some(b)) => { - *name = b as c_char; - name = name.offset(1); - }, - Ok(None) => { - *name = 0; - break; - }, - Err(()) => return -1 + + fn ftruncate(fd: c_int, len: off_t) -> c_int { + e(syscall::ftruncate(fd as usize, len as usize)) as c_int + } + + fn futimens(fd: c_int, times: *const timespec) -> c_int { + let times = [unsafe { redox_timespec::from(&*times) }, unsafe { + redox_timespec::from(&*times.offset(1)) + }]; + e(syscall::futimens(fd as usize, ×)) as c_int + } + + fn utimens(path: *const c_char, times: *const timespec) -> c_int { + let path = unsafe { c_str(path) }; + match syscall::open(path, O_STAT) { + Err(err) => e(Err(err)) as c_int, + Ok(fd) => { + let res = Self::futimens(fd as c_int, times); + let _ = syscall::close(fd); + res + } } } - 0 -} -unsafe fn inner_get_name( - local: bool, - socket: c_int, - address: *mut sockaddr, - address_len: *mut socklen_t, -) -> Result { - // 32 should probably be large enough. - // Format: tcp:remote/local - // and since we only yet support IPv4 (I think)... - let mut buf = [0; 32]; - let len = syscall::fpath(socket as usize, &mut buf)?; - let buf = &buf[..len]; - assert!(&buf[..4] == b"tcp:" || &buf[..4] == b"udp:"); - let buf = &buf[4..]; - - let mut parts = buf.split(|c| *c == b'/'); - if local { - // Skip the remote part - parts.next(); - } - let part = parts.next().expect("Invalid reply from netstack"); - - let data = slice::from_raw_parts_mut( - &mut (*address).data as *mut _ as *mut u8, - (*address).data.len(), - ); - - let len = data.len().min(part.len()); - data[..len].copy_from_slice(&part[..len]); - - *address_len = len as socklen_t; - Ok(0) -} - -pub fn getitimer(which: c_int, out: *mut itimerval) -> c_int { - let _ = writeln!( - FileWriter(2), - "unimplemented: getitimer({}, {:p})", - which, - out - ); - - unsafe { - *out = itimerval::default(); - } - 0 -} - -pub unsafe fn getpeername( - socket: c_int, - address: *mut sockaddr, - address_len: *mut socklen_t, -) -> c_int { - e(inner_get_name(false, socket, address, address_len)) as c_int -} - -pub fn getpgid(pid: pid_t) -> pid_t { - e(syscall::getpgid(pid as usize)) as pid_t -} - -pub fn getpid() -> pid_t { - e(syscall::getpid()) as pid_t -} - -pub fn getppid() -> pid_t { - e(syscall::getppid()) as pid_t -} - -pub unsafe fn getsockname( - socket: c_int, - address: *mut sockaddr, - address_len: *mut socklen_t, -) -> c_int { - e(inner_get_name(true, socket, address, address_len)) as c_int -} - -pub fn getsockopt( - socket: c_int, - level: c_int, - option_name: c_int, - option_value: *mut c_void, - option_len: *mut socklen_t, -) -> c_int { - let _ = writeln!( - FileWriter(2), - "unimplemented: getsockopt({}, {}, {}, {:p}, {:p})", - socket, - level, - option_name, - option_value, - option_len - ); - -1 -} - -pub fn gettimeofday(tp: *mut timeval, tzp: *mut timezone) -> c_int { - let mut redox_tp = redox_timespec::default(); - let err = e(syscall::clock_gettime( - syscall::CLOCK_REALTIME, - &mut redox_tp, - )) as c_int; - if err < 0 { - return err; - } - unsafe { - (*tp).tv_sec = redox_tp.tv_sec as time_t; - (*tp).tv_usec = (redox_tp.tv_nsec / 1000) as suseconds_t; - - if !tzp.is_null() { - (*tzp).tz_minuteswest = 0; - (*tzp).tz_dsttime = 0; - } - } - 0 -} - -pub fn getuid() -> uid_t { - e(syscall::getuid()) as pid_t -} - -pub fn isatty(fd: c_int) -> c_int { - syscall::dup(fd as usize, b"termios") - .map(|fd| { - let _ = syscall::close(fd); - 1 - }) - .unwrap_or(0) -} - -pub fn kill(pid: pid_t, sig: c_int) -> c_int { - e(syscall::kill(pid as usize, sig as usize)) as c_int -} - -pub fn killpg(pgrp: pid_t, sig: c_int) -> c_int { - e(syscall::kill(-(pgrp as isize) as usize, sig as usize)) as c_int -} - -pub fn link(path1: *const c_char, path2: *const c_char) -> c_int { - let path1 = unsafe { c_str(path1) }; - let path2 = unsafe { c_str(path2) }; - e(unsafe { syscall::link(path1.as_ptr(), path2.as_ptr()) }) as c_int -} - -pub fn listen(_socket: c_int, _backlog: c_int) -> c_int { - // TODO - 0 -} - -pub fn lseek(fd: c_int, offset: off_t, whence: c_int) -> off_t { - e(syscall::lseek( - fd as usize, - offset as isize, - whence as usize, - )) as off_t -} - -pub fn lstat(path: *const c_char, buf: *mut stat) -> c_int { - let path = unsafe { c_str(path) }; - match syscall::open(path, O_STAT | O_NOFOLLOW) { - Err(err) => e(Err(err)) as c_int, - Ok(fd) => { - let res = fstat(fd as i32, buf); - let _ = syscall::close(fd); - res - } - } -} - -pub fn mkdir(path: *const c_char, mode: mode_t) -> c_int { - let flags = O_CREAT | O_EXCL | O_CLOEXEC | O_DIRECTORY | mode as usize & 0o777; - let path = unsafe { c_str(path) }; - match syscall::open(path, flags) { - Ok(fd) => { - let _ = syscall::close(fd); - 0 - } - Err(err) => e(Err(err)) as c_int, - } -} - -pub fn mkfifo(path: *const c_char, mode: mode_t) -> c_int { - let flags = O_CREAT | MODE_FIFO as usize | mode as usize & 0o777; - let path = unsafe { c_str(path) }; - match syscall::open(path, flags) { - Ok(fd) => { - let _ = syscall::close(fd); - 0 - } - Err(err) => e(Err(err)) as c_int, - } -} - -pub unsafe fn mmap( - _addr: *mut c_void, - len: usize, - _prot: c_int, - flags: c_int, - fildes: c_int, - off: off_t, -) -> *mut c_void { - if flags & MAP_ANON == MAP_ANON { - let fd = e(syscall::open("memory:", 0)); // flags don't matter currently - if fd == !0 { - return !0 as *mut c_void; - } - - let addr = e(syscall::fmap(fd, off as usize, len as usize)); - if addr == !0 { - let _ = syscall::close(fd); - return !0 as *mut c_void; - } - - anonymous_maps().insert(addr as usize, fd); - addr as *mut c_void - } else { - e(syscall::fmap(fildes as usize, off as usize, len as usize)) as *mut c_void - } -} - -pub unsafe fn munmap(addr: *mut c_void, _len: usize) -> c_int { - if e(syscall::funmap(addr as usize)) == !0 { - return !0; - } - if let Some(fd) = anonymous_maps().remove(&(addr as usize)) { - let _ = syscall::close(fd); - } - 0 -} - -pub fn nanosleep(rqtp: *const timespec, rmtp: *mut timespec) -> c_int { - let redox_rqtp = unsafe { redox_timespec::from(&*rqtp) }; - let mut redox_rmtp: redox_timespec; - if rmtp.is_null() { - redox_rmtp = redox_timespec::default(); - } else { - redox_rmtp = unsafe { redox_timespec::from(&*rmtp) }; - } - match e(syscall::nanosleep(&redox_rqtp, &mut redox_rmtp)) as c_int { - -1 => -1, - _ => { + fn getcwd(buf: *mut c_char, size: size_t) -> *mut c_char { + let buf_slice = unsafe { slice::from_raw_parts_mut(buf as *mut u8, size as usize - 1) }; + let read = e(syscall::getcwd(buf_slice)); + if read == !0 { + ptr::null_mut() + } else { unsafe { - if !rmtp.is_null() { - (*rmtp).tv_sec = redox_rmtp.tv_sec; - (*rmtp).tv_nsec = redox_rmtp.tv_nsec as i64; - } + *buf.offset(read as isize + 1) = 0; } - 0 + buf } } -} -pub fn open(path: *const c_char, oflag: c_int, mode: mode_t) -> c_int { - let path = unsafe { c_str(path) }; - e(syscall::open(path, (oflag as usize) | (mode as usize))) as c_int -} + fn getdents(fd: c_int, mut dirents: *mut dirent, mut bytes: usize) -> c_int { + let mut amount = 0; -pub fn pipe(fds: &mut [c_int]) -> c_int { - let mut usize_fds: [usize; 2] = [0; 2]; - let res = e(syscall::pipe2(&mut usize_fds, 0)); - fds[0] = usize_fds[0] as c_int; - fds[1] = usize_fds[1] as c_int; - res as c_int -} + let mut buf = [0; 1024]; + let mut bindex = 0; + let mut blen = 0; -pub fn raise(sig: c_int) -> c_int { - kill(getpid(), sig) -} + let mut name = [0; 256]; + let mut nindex = 0; -pub fn read(fd: c_int, buf: &mut [u8]) -> ssize_t { - e(syscall::read(fd as usize, buf)) as ssize_t -} + loop { + if bindex >= blen { + bindex = 0; + blen = match syscall::read(fd as usize, &mut buf) { + Ok(0) => return amount, + Ok(n) => n, + Err(err) => return -err.errno, + }; + } -pub unsafe fn recvfrom( - socket: c_int, - buf: *mut c_void, - len: size_t, - flags: c_int, - address: *mut sockaddr, - address_len: *mut socklen_t, -) -> ssize_t { - if flags != 0 { - errno = syscall::EOPNOTSUPP; - return -1; - } - if address != ptr::null_mut() - && address_len != ptr::null_mut() - && getpeername(socket, address, address_len) < 0 - { - return -1; - } - read(socket, slice::from_raw_parts_mut(buf as *mut u8, len)) -} - -pub fn rename(oldpath: *const c_char, newpath: *const c_char) -> c_int { - let (oldpath, newpath) = unsafe { (c_str(oldpath), c_str(newpath)) }; - match syscall::open(oldpath, O_WRONLY) { - Ok(fd) => { - let retval = syscall::frename(fd, newpath); - let _ = syscall::close(fd); - e(retval) as c_int - } - err => e(err) as c_int, - } -} - -pub fn rmdir(path: *const c_char) -> c_int { - let path = unsafe { c_str(path) }; - e(syscall::rmdir(path)) as c_int -} - -pub fn select( - nfds: c_int, - readfds: *mut fd_set, - writefds: *mut fd_set, - exceptfds: *mut fd_set, - timeout: *mut timeval, -) -> c_int { - fn isset(set: *mut fd_set, fd: usize) -> bool { - if set.is_null() { - return false; - } - - let mask = 1 << (fd & (8 * mem::size_of::() - 1)); - unsafe { (*set).fds_bits[fd / (8 * mem::size_of::())] & mask == mask } - } - - let event_file = match RawFile::open("event:\0".as_ptr() as *const c_char, 0, 0) { - Ok(file) => file, - Err(_) => return -1, - }; - - let mut total = 0; - - for fd in 0..nfds as usize { - macro_rules! register { - ($fd:expr, $flags:expr) => { - if write( - *event_file, - &syscall::Event { - id: $fd, - flags: $flags, - data: 0, - }, - ) < 0 - { - return -1; + if buf[bindex] == b'\n' { + // Put a NUL byte either at the end, or if it's too big, at where it's truncated. + name[nindex.min(name.len() - 1)] = 0; + unsafe { + *dirents = dirent { + d_ino: 0, + d_off: 0, + d_reclen: mem::size_of::() as c_ushort, + d_type: 0, + d_name: name, + }; + dirents = dirents.offset(1); } - }; - } - if isset(readfds, fd) { - register!(fd, syscall::EVENT_READ); - total += 1; - } - if isset(writefds, fd) { - register!(fd, syscall::EVENT_WRITE); - total += 1; - } - if isset(exceptfds, fd) { - total += 1; + amount += 1; + if bytes <= mem::size_of::() { + return amount; + } + bytes -= mem::size_of::(); + } else { + if nindex < name.len() { + name[nindex] = buf[bindex] as c_char; + } + nindex += 1; + bindex += 1; + } } } - const TIMEOUT_TOKEN: usize = 1; + fn getegid() -> gid_t { + e(syscall::getegid()) as gid_t + } - let timeout_file = if timeout.is_null() { - None - } else { - let timeout_file = match RawFile::open( - format!("time:{}\0", syscall::CLOCK_MONOTONIC).as_ptr() as *const c_char, - 0, - 0, - ) { + fn geteuid() -> uid_t { + e(syscall::geteuid()) as uid_t + } + + fn getgid() -> gid_t { + e(syscall::getgid()) as gid_t + } + + unsafe fn gethostname(mut name: *mut c_char, len: size_t) -> c_int { + let fd = e(syscall::open("/etc/hostname", O_RDONLY)) as i32; + if fd < 0 { + return fd; + } + let mut reader = FileReader(fd); + for _ in 0..len { + match reader.read_u8() { + Ok(Some(b)) => { + *name = b as c_char; + name = name.offset(1); + }, + Ok(None) => { + *name = 0; + break; + }, + Err(()) => return -1 + } + } + 0 + } + + fn getpgid(pid: pid_t) -> pid_t { + e(syscall::getpgid(pid as usize)) as pid_t + } + + fn getpid() -> pid_t { + e(syscall::getpid()) as pid_t + } + + fn getppid() -> pid_t { + e(syscall::getppid()) as pid_t + } + + fn gettimeofday(tp: *mut timeval, tzp: *mut timezone) -> c_int { + let mut redox_tp = redox_timespec::default(); + let err = e(syscall::clock_gettime( + syscall::CLOCK_REALTIME, + &mut redox_tp, + )) as c_int; + if err < 0 { + return err; + } + unsafe { + (*tp).tv_sec = redox_tp.tv_sec as time_t; + (*tp).tv_usec = (redox_tp.tv_nsec / 1000) as suseconds_t; + + if !tzp.is_null() { + (*tzp).tz_minuteswest = 0; + (*tzp).tz_dsttime = 0; + } + } + 0 + } + + fn getuid() -> uid_t { + e(syscall::getuid()) as pid_t + } + + fn isatty(fd: c_int) -> c_int { + syscall::dup(fd as usize, b"termios") + .map(|fd| { + let _ = syscall::close(fd); + 1 + }) + .unwrap_or(0) + } + + fn link(path1: *const c_char, path2: *const c_char) -> c_int { + let path1 = unsafe { c_str(path1) }; + let path2 = unsafe { c_str(path2) }; + e(unsafe { syscall::link(path1.as_ptr(), path2.as_ptr()) }) as c_int + } + + fn lseek(fd: c_int, offset: off_t, whence: c_int) -> off_t { + e(syscall::lseek( + fd as usize, + offset as isize, + whence as usize, + )) as off_t + } + + fn lstat(path: *const c_char, buf: *mut stat) -> c_int { + let path = unsafe { c_str(path) }; + match syscall::open(path, O_STAT | O_NOFOLLOW) { + Err(err) => e(Err(err)) as c_int, + Ok(fd) => { + let res = Self::fstat(fd as i32, buf); + let _ = syscall::close(fd); + res + } + } + } + + fn mkdir(path: *const c_char, mode: mode_t) -> c_int { + let flags = O_CREAT | O_EXCL | O_CLOEXEC | O_DIRECTORY | mode as usize & 0o777; + let path = unsafe { c_str(path) }; + match syscall::open(path, flags) { + Ok(fd) => { + let _ = syscall::close(fd); + 0 + } + Err(err) => e(Err(err)) as c_int, + } + } + + fn mkfifo(path: *const c_char, mode: mode_t) -> c_int { + let flags = O_CREAT | MODE_FIFO as usize | mode as usize & 0o777; + let path = unsafe { c_str(path) }; + match syscall::open(path, flags) { + Ok(fd) => { + let _ = syscall::close(fd); + 0 + } + Err(err) => e(Err(err)) as c_int, + } + } + + unsafe fn mmap( + _addr: *mut c_void, + len: usize, + _prot: c_int, + flags: c_int, + fildes: c_int, + off: off_t, + ) -> *mut c_void { + if flags & MAP_ANON == MAP_ANON { + let fd = e(syscall::open("memory:", 0)); // flags don't matter currently + if fd == !0 { + return !0 as *mut c_void; + } + + let addr = e(syscall::fmap(fd, off as usize, len as usize)); + if addr == !0 { + let _ = syscall::close(fd); + return !0 as *mut c_void; + } + + anonymous_maps().insert(addr as usize, fd); + addr as *mut c_void + } else { + e(syscall::fmap(fildes as usize, off as usize, len as usize)) as *mut c_void + } + } + + unsafe fn munmap(addr: *mut c_void, _len: usize) -> c_int { + if e(syscall::funmap(addr as usize)) == !0 { + return !0; + } + if let Some(fd) = anonymous_maps().remove(&(addr as usize)) { + let _ = syscall::close(fd); + } + 0 + } + + fn nanosleep(rqtp: *const timespec, rmtp: *mut timespec) -> c_int { + let redox_rqtp = unsafe { redox_timespec::from(&*rqtp) }; + let mut redox_rmtp: redox_timespec; + if rmtp.is_null() { + redox_rmtp = redox_timespec::default(); + } else { + redox_rmtp = unsafe { redox_timespec::from(&*rmtp) }; + } + match e(syscall::nanosleep(&redox_rqtp, &mut redox_rmtp)) as c_int { + -1 => -1, + _ => { + unsafe { + if !rmtp.is_null() { + (*rmtp).tv_sec = redox_rmtp.tv_sec; + (*rmtp).tv_nsec = redox_rmtp.tv_nsec as i64; + } + } + 0 + } + } + } + + fn open(path: *const c_char, oflag: c_int, mode: mode_t) -> c_int { + let path = unsafe { c_str(path) }; + e(syscall::open(path, (oflag as usize) | (mode as usize))) as c_int + } + + fn pipe(fds: &mut [c_int]) -> c_int { + let mut usize_fds: [usize; 2] = [0; 2]; + let res = e(syscall::pipe2(&mut usize_fds, 0)); + fds[0] = usize_fds[0] as c_int; + fds[1] = usize_fds[1] as c_int; + res as c_int + } + + fn read(fd: c_int, buf: &mut [u8]) -> ssize_t { + e(syscall::read(fd as usize, buf)) as ssize_t + } + + fn rename(oldpath: *const c_char, newpath: *const c_char) -> c_int { + let (oldpath, newpath) = unsafe { (c_str(oldpath), c_str(newpath)) }; + match syscall::open(oldpath, O_WRONLY) { + Ok(fd) => { + let retval = syscall::frename(fd, newpath); + let _ = syscall::close(fd); + e(retval) as c_int + } + err => e(err) as c_int, + } + } + + fn rmdir(path: *const c_char) -> c_int { + let path = unsafe { c_str(path) }; + e(syscall::rmdir(path)) as c_int + } + + fn select( + nfds: c_int, + readfds: *mut fd_set, + writefds: *mut fd_set, + exceptfds: *mut fd_set, + timeout: *mut timeval, + ) -> c_int { + fn isset(set: *mut fd_set, fd: usize) -> bool { + if set.is_null() { + return false; + } + + let mask = 1 << (fd & (8 * mem::size_of::() - 1)); + unsafe { (*set).fds_bits[fd / (8 * mem::size_of::())] & mask == mask } + } + + let event_file = match RawFile::open("event:\0".as_ptr() as *const c_char, 0, 0) { Ok(file) => file, Err(_) => return -1, }; - let timeout = unsafe { &*timeout }; - if write( - *timeout_file, - &syscall::TimeSpec { - tv_sec: timeout.tv_sec, - tv_nsec: timeout.tv_usec * 1000, - }, - ) < 0 - { - return -1; - } - if write( - *event_file, - &syscall::Event { - id: *timeout_file as usize, - flags: syscall::EVENT_READ, - data: TIMEOUT_TOKEN, - }, - ) < 0 - { - return -1; + + let mut total = 0; + + for fd in 0..nfds as usize { + macro_rules! register { + ($fd:expr, $flags:expr) => { + if Self::write( + *event_file, + &syscall::Event { + id: $fd, + flags: $flags, + data: 0, + }, + ) < 0 + { + return -1; + } + }; + } + if isset(readfds, fd) { + register!(fd, syscall::EVENT_READ); + total += 1; + } + if isset(writefds, fd) { + register!(fd, syscall::EVENT_WRITE); + total += 1; + } + if isset(exceptfds, fd) { + total += 1; + } } - Some(timeout_file) - }; + const TIMEOUT_TOKEN: usize = 1; - let mut event = syscall::Event::default(); - if read(*event_file, &mut event) < 0 { - return -1; - } - - if timeout_file.is_some() && event.data == TIMEOUT_TOKEN { - return 0; - } - - // I really don't get why, but select wants me to return the total number - // of file descriptors that was inputted. I'm confused. - total -} - -pub unsafe fn sendto( - socket: c_int, - buf: *const c_void, - len: size_t, - flags: c_int, - dest_addr: *const sockaddr, - dest_len: socklen_t, -) -> ssize_t { - if dest_addr != ptr::null() || dest_len != 0 { - errno = syscall::EISCONN; - return -1; - } - if flags != 0 { - errno = syscall::EOPNOTSUPP; - return -1; - } - write(socket, slice::from_raw_parts(buf as *const u8, len)) -} - -pub fn setitimer(which: c_int, new: *const itimerval, old: *mut itimerval) -> c_int { - let _ = writeln!( - FileWriter(2), - "unimplemented: setitimer({}, {:p}, {:p})", - which, - new, - old - ); - - unsafe { - *old = itimerval::default(); - } - 0 -} - -pub fn setpgid(pid: pid_t, pgid: pid_t) -> c_int { - e(syscall::setpgid(pid as usize, pgid as usize)) as c_int -} - -pub fn setregid(rgid: gid_t, egid: gid_t) -> c_int { - e(syscall::setregid(rgid as usize, egid as usize)) as c_int -} - -pub fn setreuid(ruid: uid_t, euid: uid_t) -> c_int { - e(syscall::setreuid(ruid as usize, euid as usize)) as c_int -} - -pub fn setsockopt( - socket: c_int, - level: c_int, - option_name: c_int, - option_value: *const c_void, - option_len: socklen_t, -) -> c_int { - let _ = writeln!( - FileWriter(2), - "unimplemented: setsockopt({}, {}, {}, {:p}, {})", - socket, - level, - option_name, - option_value, - option_len - ); - -1 -} - -pub fn shutdown(socket: c_int, how: c_int) -> c_int { - let _ = writeln!( - FileWriter(2), - "unimplemented: shutdown({}, {})", - socket, - how - ); - -1 -} - -pub unsafe fn sigaction(sig: c_int, act: *const sigaction, oact: *mut sigaction) -> c_int { - if !oact.is_null() { - // Assumes the last sigaction() call was made by relibc and not a different one - if SIG_HANDLER.is_some() { - (*oact).sa_handler = SIG_HANDLER; - } - } - let act = if act.is_null() { - None - } else { - SIG_HANDLER = (*act).sa_handler; - let m = (*act).sa_mask; - Some(syscall::SigAction { - sa_handler: sig_handler, - sa_mask: [0, m as u64], - sa_flags: (*act).sa_flags as usize, - }) - }; - let mut old = syscall::SigAction::default(); - let ret = e(syscall::sigaction( - sig as usize, - act.as_ref(), - if oact.is_null() { None } else { Some(&mut old) }, - )) as c_int; - if !oact.is_null() { - let m = old.sa_mask; - (*oact).sa_mask = m[1] as c_ulong; - (*oact).sa_flags = old.sa_flags as c_ulong; - } - ret -} - -pub fn sigprocmask(how: c_int, set: *const sigset_t, oset: *mut sigset_t) -> c_int { - let _ = writeln!( - FileWriter(2), - "unimplemented: sigprocmask({}, {:p}, {:p})", - how, - set, - oset - ); - -1 -} - -pub fn stat(path: *const c_char, buf: *mut stat) -> c_int { - let path = unsafe { c_str(path) }; - match syscall::open(path, O_STAT) { - Err(err) => e(Err(err)) as c_int, - Ok(fd) => { - let res = fstat(fd as i32, buf); - let _ = syscall::close(fd); - res - } - } -} - -pub unsafe fn socket(domain: c_int, mut kind: c_int, protocol: c_int) -> c_int { - if domain != AF_INET { - errno = syscall::EAFNOSUPPORT; - return -1; - } - if protocol != 0 { - errno = syscall::EPROTONOSUPPORT; - return -1; - } - - let mut flags = O_RDWR; - if kind & SOCK_NONBLOCK == SOCK_NONBLOCK { - kind &= !SOCK_NONBLOCK; - flags |= O_NONBLOCK; - } - if kind & SOCK_CLOEXEC == SOCK_CLOEXEC { - kind &= !SOCK_CLOEXEC; - flags |= O_CLOEXEC; - } - - // The tcp: and udp: schemes allow using no path, - // and later specifying one using `dup`. - match kind { - SOCK_STREAM => e(syscall::open("tcp:", flags)) as c_int, - SOCK_DGRAM => e(syscall::open("udp:", flags)) as c_int, - _ => { - errno = syscall::EPROTOTYPE; - -1 - } - } -} - -pub fn socketpair(domain: c_int, kind: c_int, protocol: c_int, socket_vector: *mut c_int) -> c_int { - let _ = writeln!( - FileWriter(2), - "unimplemented: socketpair({}, {}, {}, {:p})", - domain, - kind, - protocol, - socket_vector - ); - -1 -} - -pub fn tcgetattr(fd: c_int, out: *mut termios) -> c_int { - let dup = e(syscall::dup(fd as usize, b"termios")); - if dup == !0 { - return -1; - } - - let read = e(syscall::read(dup, unsafe { slice::from_raw_parts_mut( - out as *mut u8, - mem::size_of::() - ) })); - let _ = syscall::close(dup); - - if read == !0 { - return -1; - } - 0 -} - -pub fn tcsetattr(fd: c_int, _act: c_int, value: *const termios) -> c_int { - let dup = e(syscall::dup(fd as usize, b"termios")); - if dup == !0 { - return -1; - } - - let write = e(syscall::write(dup, unsafe { slice::from_raw_parts( - value as *const u8, - mem::size_of::() - ) })); - let _ = syscall::close(dup); - - if write == !0 { - return -1; - } - 0 -} - -pub fn times(out: *mut tms) -> clock_t { - let _ = writeln!(FileWriter(2), "unimplemented: times({:p})", out); - !0 -} - -pub fn umask(mask: mode_t) -> mode_t { - let _ = writeln!(FileWriter(2), "unimplemented: umask({})", mask); - 0 -} - -pub fn unlink(path: *const c_char) -> c_int { - let path = unsafe { c_str(path) }; - e(syscall::unlink(path)) as c_int -} - -pub fn waitpid(mut pid: pid_t, stat_loc: *mut c_int, options: c_int) -> pid_t { - if pid == !0 { - pid = 0; - } - unsafe { - let mut temp: usize = 0; - let res = e(syscall::waitpid(pid as usize, &mut temp, options as usize)); - if !stat_loc.is_null() { - *stat_loc = temp as c_int; - } - res as pid_t - } -} - -pub fn write(fd: c_int, buf: &[u8]) -> ssize_t { - e(syscall::write(fd as usize, buf)) as ssize_t -} - -pub fn clock_gettime(clk_id: clockid_t, tp: *mut timespec) -> c_int { - let mut redox_tp = unsafe { redox_timespec::from(&*tp) }; - match e(syscall::clock_gettime(clk_id as usize, &mut redox_tp)) as c_int { - -1 => -1, - _ => { - unsafe { - (*tp).tv_sec = redox_tp.tv_sec; - (*tp).tv_nsec = redox_tp.tv_nsec as i64; + let timeout_file = if timeout.is_null() { + None + } else { + let timeout_file = match RawFile::open( + format!("time:{}\0", syscall::CLOCK_MONOTONIC).as_ptr() as *const c_char, + 0, + 0, + ) { + Ok(file) => file, + Err(_) => return -1, }; - 0 + let timeout = unsafe { &*timeout }; + if Self::write( + *timeout_file, + &syscall::TimeSpec { + tv_sec: timeout.tv_sec, + tv_nsec: timeout.tv_usec * 1000, + }, + ) < 0 + { + return -1; + } + if Self::write( + *event_file, + &syscall::Event { + id: *timeout_file as usize, + flags: syscall::EVENT_READ, + data: TIMEOUT_TOKEN, + }, + ) < 0 + { + return -1; + } + + Some(timeout_file) + }; + + let mut event = syscall::Event::default(); + if Self::read(*event_file, &mut event) < 0 { + return -1; + } + + if timeout_file.is_some() && event.data == TIMEOUT_TOKEN { + return 0; + } + + // I really don't get why, but select wants me to return the total number + // of file descriptors that was inputted. I'm confused. + total + } + + fn setpgid(pid: pid_t, pgid: pid_t) -> c_int { + e(syscall::setpgid(pid as usize, pgid as usize)) as c_int + } + + fn setregid(rgid: gid_t, egid: gid_t) -> c_int { + e(syscall::setregid(rgid as usize, egid as usize)) as c_int + } + + fn setreuid(ruid: uid_t, euid: uid_t) -> c_int { + e(syscall::setreuid(ruid as usize, euid as usize)) as c_int + } + + fn stat(path: *const c_char, buf: *mut stat) -> c_int { + let path = unsafe { c_str(path) }; + match syscall::open(path, O_STAT) { + Err(err) => e(Err(err)) as c_int, + Ok(fd) => { + let res = Self::fstat(fd as i32, buf); + let _ = syscall::close(fd); + res + } } } + + fn tcgetattr(fd: c_int, out: *mut termios) -> c_int { + let dup = e(syscall::dup(fd as usize, b"termios")); + if dup == !0 { + return -1; + } + + let read = e(syscall::read(dup, unsafe { slice::from_raw_parts_mut( + out as *mut u8, + mem::size_of::() + ) })); + let _ = syscall::close(dup); + + if read == !0 { + return -1; + } + 0 + } + + fn tcsetattr(fd: c_int, _act: c_int, value: *const termios) -> c_int { + let dup = e(syscall::dup(fd as usize, b"termios")); + if dup == !0 { + return -1; + } + + let write = e(syscall::write(dup, unsafe { slice::from_raw_parts( + value as *const u8, + mem::size_of::() + ) })); + let _ = syscall::close(dup); + + if write == !0 { + return -1; + } + 0 + } + + fn unlink(path: *const c_char) -> c_int { + let path = unsafe { c_str(path) }; + e(syscall::unlink(path)) as c_int + } + + fn waitpid(mut pid: pid_t, stat_loc: *mut c_int, options: c_int) -> pid_t { + if pid == !0 { + pid = 0; + } + unsafe { + let mut temp: usize = 0; + let res = e(syscall::waitpid(pid as usize, &mut temp, options as usize)); + if !stat_loc.is_null() { + *stat_loc = temp as c_int; + } + res as pid_t + } + } + + fn write(fd: c_int, buf: &[u8]) -> ssize_t { + e(syscall::write(fd as usize, buf)) as ssize_t + } } diff --git a/src/platform/src/redox/signal.rs b/src/platform/src/redox/signal.rs new file mode 100644 index 0000000000..2c80345f85 --- /dev/null +++ b/src/platform/src/redox/signal.rs @@ -0,0 +1,47 @@ +impl PalSignal for Sys { + fn kill(pid: pid_t, sig: c_int) -> c_int { + e(syscall::kill(pid as usize, sig as usize)) as c_int + } + + fn killpg(pgrp: pid_t, sig: c_int) -> c_int { + e(syscall::kill(-(pgrp as isize) as usize, sig as usize)) as c_int + } + + fn raise(sig: c_int) -> c_int { + kill(getpid(), sig) + } + + unsafe fn sigaction(sig: c_int, act: *const sigaction, oact: *mut sigaction) -> c_int { + if !oact.is_null() { + // Assumes the last sigaction() call was made by relibc and not a different one + if SIG_HANDLER.is_some() { + (*oact).sa_handler = SIG_HANDLER; + } + } + let act = if act.is_null() { + None + } else { + SIG_HANDLER = (*act).sa_handler; + let m = (*act).sa_mask; + Some(syscall::SigAction { + sa_handler: sig_handler, + sa_mask: [0, m as u64], + sa_flags: (*act).sa_flags as usize, + }) + }; + let mut old = syscall::SigAction::default(); + let ret = e(syscall::sigaction( + sig as usize, + act.as_ref(), + if oact.is_null() { None } else { Some(&mut old) }, + )) as c_int; + if !oact.is_null() { + let m = old.sa_mask; + (*oact).sa_mask = m[1] as c_ulong; + (*oact).sa_flags = old.sa_flags as c_ulong; + } + ret + } + + //fn sigprocmask(how: c_int, set: *const sigset_t, oset: *mut sigset_t) -> c_int; +} diff --git a/src/platform/src/redox/socket.rs b/src/platform/src/redox/socket.rs new file mode 100644 index 0000000000..6437eeb049 --- /dev/null +++ b/src/platform/src/redox/socket.rs @@ -0,0 +1,180 @@ +macro_rules! bind_or_connect { + (bind $path:expr) => { + concat!("/", $path) + }; + (connect $path:expr) => { + $path + }; + ($mode:ident $socket:expr, $address:expr, $address_len:expr) => {{ + if (*$address).sa_family as c_int != AF_INET { + errno = syscall::EAFNOSUPPORT; + return -1; + } + if ($address_len as usize) < mem::size_of::() { + errno = syscall::EINVAL; + 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); + + // Duplicate the socket, and then duplicate the copy back to the original fd + let fd = e(syscall::dup($socket as usize, path.as_bytes())); + if (fd as c_int) < 0 { + return -1; + } + let result = syscall::dup2(fd, $socket as usize, &[]); + let _ = syscall::close(fd); + if (e(result) as c_int) < 0 { + return -1; + } + 0 + }} +} + +unsafe fn inner_get_name( + local: bool, + socket: c_int, + address: *mut sockaddr, + address_len: *mut socklen_t, +) -> Result { + // 32 should probably be large enough. + // Format: tcp:remote/local + // and since we only yet support IPv4 (I think)... + let mut buf = [0; 32]; + let len = syscall::fpath(socket as usize, &mut buf)?; + let buf = &buf[..len]; + assert!(&buf[..4] == b"tcp:" || &buf[..4] == b"udp:"); + let buf = &buf[4..]; + + let mut parts = buf.split(|c| *c == b'/'); + if local { + // Skip the remote part + parts.next(); + } + let part = parts.next().expect("Invalid reply from netstack"); + + let data = slice::from_raw_parts_mut( + &mut (*address).data as *mut _ as *mut u8, + (*address).data.len(), + ); + + let len = data.len().min(part.len()); + data[..len].copy_from_slice(&part[..len]); + + *address_len = len as socklen_t; + Ok(0) +} + +impl PalSocket for Sys { + unsafe fn accept(socket: c_int, address: *mut sockaddr, address_len: *mut socklen_t) -> c_int { + let stream = e(syscall::dup(socket as usize, b"listen")) as c_int; + if stream < 0 { + return -1; + } + if address != ptr::null_mut() + && address_len != ptr::null_mut() + && getpeername(stream, address, address_len) < 0 + { + return -1; + } + stream + } + + unsafe fn bind(socket: c_int, address: *const sockaddr, address_len: socklen_t) -> c_int { + bind_or_connect!(bind socket, address, address_len) + } + + unsafe fn connect(socket: c_int, address: *const sockaddr, address_len: socklen_t) -> c_int { + bind_or_connect!(connect socket, address, address_len) + } + + unsafe fn getpeername( + socket: c_int, + address: *mut sockaddr, + address_len: *mut socklen_t, + ) -> c_int { + e(inner_get_name(false, socket, address, address_len)) as c_int + } + + unsafe fn getsockname( + socket: c_int, + address: *mut sockaddr, + address_len: *mut socklen_t, + ) -> c_int { + e(inner_get_name(true, socket, address, address_len)) as c_int + } + + unsafe fn recvfrom( + socket: c_int, + buf: *mut c_void, + len: size_t, + flags: c_int, + address: *mut sockaddr, + address_len: *mut socklen_t, + ) -> ssize_t { + if flags != 0 { + errno = syscall::EOPNOTSUPP; + return -1; + } + if address != ptr::null_mut() + && address_len != ptr::null_mut() + && getpeername(socket, address, address_len) < 0 + { + return -1; + } + read(socket, slice::from_raw_parts_mut(buf as *mut u8, len)) + } + + unsafe fn sendto( + socket: c_int, + buf: *const c_void, + len: size_t, + flags: c_int, + dest_addr: *const sockaddr, + dest_len: socklen_t, + ) -> ssize_t { + if dest_addr != ptr::null() || dest_len != 0 { + errno = syscall::EISCONN; + return -1; + } + if flags != 0 { + errno = syscall::EOPNOTSUPP; + return -1; + } + write(socket, slice::from_raw_parts(buf as *const u8, len)) + } + + unsafe fn socket(domain: c_int, mut kind: c_int, protocol: c_int) -> c_int { + if domain != AF_INET { + errno = syscall::EAFNOSUPPORT; + return -1; + } + if protocol != 0 { + errno = syscall::EPROTONOSUPPORT; + return -1; + } + + let mut flags = O_RDWR; + if kind & SOCK_NONBLOCK == SOCK_NONBLOCK { + kind &= !SOCK_NONBLOCK; + flags |= O_NONBLOCK; + } + if kind & SOCK_CLOEXEC == SOCK_CLOEXEC { + kind &= !SOCK_CLOEXEC; + flags |= O_CLOEXEC; + } + + // The tcp: and udp: schemes allow using no path, + // and later specifying one using `dup`. + match kind { + SOCK_STREAM => e(syscall::open("tcp:", flags)) as c_int, + SOCK_DGRAM => e(syscall::open("udp:", flags)) as c_int, + _ => { + errno = syscall::EPROTOTYPE; + -1 + } + } + } +} From d1dabccdceaa80eb231ced77a2bcb5f72b9c0dec Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sat, 25 Aug 2018 09:14:02 -0600 Subject: [PATCH 04/19] Fix missing modules in Redox platform --- src/platform/src/redox/mod.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/platform/src/redox/mod.rs b/src/platform/src/redox/mod.rs index 41750b7893..ac74cf4179 100644 --- a/src/platform/src/redox/mod.rs +++ b/src/platform/src/redox/mod.rs @@ -12,6 +12,9 @@ use syscall::{self, Result}; use {c_str, errno, FileReader, FileWriter, Pal, RawFile, Read}; use types::*; +mod signal; +mod socket; + const EINVAL: c_int = 22; const ENOSYS: c_int = 38; const MAP_ANON: c_int = 1; From 34f5f572136989e206f99752b5bce7c09f91f12c Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sat, 25 Aug 2018 09:21:08 -0600 Subject: [PATCH 05/19] Fix signal and socket pal implementations on Redox --- src/platform/src/linux/socket.rs | 4 ++-- src/platform/src/pal/socket.rs | 2 +- src/platform/src/redox/mod.rs | 9 --------- src/platform/src/redox/signal.rs | 17 ++++++++++++++++- src/platform/src/redox/socket.rs | 16 ++++++++++++---- 5 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/platform/src/linux/socket.rs b/src/platform/src/linux/socket.rs index c29f2b51ca..f222a6e365 100644 --- a/src/platform/src/linux/socket.rs +++ b/src/platform/src/linux/socket.rs @@ -109,8 +109,8 @@ impl PalSocket for Sys { e(unsafe { syscall!(SHUTDOWN, socket, how) }) as c_int } - fn socket(domain: c_int, kind: c_int, protocol: c_int) -> c_int { - e(unsafe { syscall!(SOCKET, domain, kind, protocol) }) as c_int + unsafe fn socket(domain: c_int, kind: c_int, protocol: c_int) -> c_int { + e(syscall!(SOCKET, domain, kind, protocol)) as c_int } fn socketpair(domain: c_int, kind: c_int, protocol: c_int, socket_vector: *mut c_int) -> c_int { diff --git a/src/platform/src/pal/socket.rs b/src/platform/src/pal/socket.rs index 8a4c72ad53..a1329d6026 100644 --- a/src/platform/src/pal/socket.rs +++ b/src/platform/src/pal/socket.rs @@ -72,7 +72,7 @@ pub trait PalSocket: Pal { Self::no_pal("shutdown") } - fn socket(domain: c_int, kind: c_int, protocol: c_int) -> c_int { + unsafe fn socket(domain: c_int, kind: c_int, protocol: c_int) -> c_int { Self::no_pal("socket") } diff --git a/src/platform/src/redox/mod.rs b/src/platform/src/redox/mod.rs index ac74cf4179..1129b3b4c5 100644 --- a/src/platform/src/redox/mod.rs +++ b/src/platform/src/redox/mod.rs @@ -19,21 +19,12 @@ const EINVAL: c_int = 22; const ENOSYS: c_int = 38; const MAP_ANON: c_int = 1; -#[thread_local] -static mut SIG_HANDLER: Option = None; - static ANONYMOUS_MAPS: Once>> = Once::new(); fn anonymous_maps() -> MutexGuard<'static, BTreeMap> { ANONYMOUS_MAPS.call_once(|| Mutex::new(BTreeMap::new())).lock() } -extern "C" fn sig_handler(sig: usize) { - if let Some(ref callback) = unsafe { SIG_HANDLER } { - callback(sig as c_int); - } -} - fn e(sys: Result) -> usize { match sys { Ok(ok) => ok, diff --git a/src/platform/src/redox/signal.rs b/src/platform/src/redox/signal.rs index 2c80345f85..612b04f2ef 100644 --- a/src/platform/src/redox/signal.rs +++ b/src/platform/src/redox/signal.rs @@ -1,3 +1,18 @@ +use syscall; + +use super::{e, Sys}; +use {Pal, PalSignal}; +use types::*; + +#[thread_local] +static mut SIG_HANDLER: Option = None; + +extern "C" fn sig_handler(sig: usize) { + if let Some(ref callback) = unsafe { SIG_HANDLER } { + callback(sig as c_int); + } +} + impl PalSignal for Sys { fn kill(pid: pid_t, sig: c_int) -> c_int { e(syscall::kill(pid as usize, sig as usize)) as c_int @@ -8,7 +23,7 @@ impl PalSignal for Sys { } fn raise(sig: c_int) -> c_int { - kill(getpid(), sig) + Self::kill(Self::getpid(), sig) } unsafe fn sigaction(sig: c_int, act: *const sigaction, oact: *mut sigaction) -> c_int { diff --git a/src/platform/src/redox/socket.rs b/src/platform/src/redox/socket.rs index 6437eeb049..bd78eafc90 100644 --- a/src/platform/src/redox/socket.rs +++ b/src/platform/src/redox/socket.rs @@ -1,3 +1,11 @@ +use core::{mem, ptr, slice}; +use syscall::{self, Result}; +use syscall::flag::*; + +use super::{e, Sys}; +use {errno, Pal, PalSocket}; +use types::*; + macro_rules! bind_or_connect { (bind $path:expr) => { concat!("/", $path) @@ -75,7 +83,7 @@ impl PalSocket for Sys { } if address != ptr::null_mut() && address_len != ptr::null_mut() - && getpeername(stream, address, address_len) < 0 + && Self::getpeername(stream, address, address_len) < 0 { return -1; } @@ -120,11 +128,11 @@ impl PalSocket for Sys { } if address != ptr::null_mut() && address_len != ptr::null_mut() - && getpeername(socket, address, address_len) < 0 + && Self::getpeername(socket, address, address_len) < 0 { return -1; } - read(socket, slice::from_raw_parts_mut(buf as *mut u8, len)) + Self::read(socket, slice::from_raw_parts_mut(buf as *mut u8, len)) } unsafe fn sendto( @@ -143,7 +151,7 @@ impl PalSocket for Sys { errno = syscall::EOPNOTSUPP; return -1; } - write(socket, slice::from_raw_parts(buf as *const u8, len)) + Self::write(socket, slice::from_raw_parts(buf as *const u8, len)) } unsafe fn socket(domain: c_int, mut kind: c_int, protocol: c_int) -> c_int { From ff32c8cbbd2074d73493a92c945c2454643cd6fa Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sat, 25 Aug 2018 10:13:58 -0600 Subject: [PATCH 06/19] Remove stat and lstat, which can be replaced with open and fstat --- Cargo.lock | 1 + src/fcntl/src/linux.rs | 12 +++++++----- src/fcntl/src/redox.rs | 2 +- src/platform/src/linux/mod.rs | 8 -------- src/platform/src/pal/mod.rs | 8 -------- src/platform/src/redox/mod.rs | 24 ------------------------ src/stdlib/src/lib.rs | 2 +- src/sys_resource/src/lib.rs | 2 +- src/sys_stat/Cargo.toml | 1 + src/sys_stat/src/lib.rs | 24 ++++++++++++++++++++++-- src/sys_times/src/lib.rs | 2 +- 11 files changed, 35 insertions(+), 51 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2ba1307728..d329b0c9ef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -586,6 +586,7 @@ name = "sys_stat" version = "0.1.0" dependencies = [ "cbindgen 0.5.2", + "fcntl 0.1.0", "platform 0.1.0", ] diff --git a/src/fcntl/src/linux.rs b/src/fcntl/src/linux.rs index 05948a6da5..7b0af1982f 100644 --- a/src/fcntl/src/linux.rs +++ b/src/fcntl/src/linux.rs @@ -4,10 +4,12 @@ pub const O_RDONLY: c_int = 0x0000; pub const O_WRONLY: c_int = 0x0001; pub const O_RDWR: c_int = 0x0002; pub const O_CREAT: c_int = 0x0040; +pub const O_EXCL: c_int = 0x0080; pub const O_TRUNC: c_int = 0x0200; +pub const O_APPEND: c_int = 0x0400; +pub const O_NONBLOCK: c_int = 0x0800; +pub const O_DIRECTORY: c_int = 0x1_0000; +pub const O_NOFOLLOW: c_int = 0x2_0000; +pub const O_CLOEXEC: c_int = 0x8_0000; +pub const O_PATH: c_int = 0x20_0000; pub const O_ACCMODE: c_int = O_RDONLY | O_WRONLY | O_RDWR; -pub const O_APPEND: c_int = 0o2000; -pub const O_CLOEXEC: c_int = 0o2_000_000; -pub const O_DIRECTORY: c_int = 0o200_000; -pub const O_EXCL: c_int = 0o200; -pub const O_NONBLOCK: c_int = 0o4000; diff --git a/src/fcntl/src/redox.rs b/src/fcntl/src/redox.rs index 1ea3ca45de..95f2da5570 100644 --- a/src/fcntl/src/redox.rs +++ b/src/fcntl/src/redox.rs @@ -14,7 +14,7 @@ pub const O_CREAT: c_int = 0x0200_0000; pub const O_TRUNC: c_int = 0x0400_0000; pub const O_EXCL: c_int = 0x0800_0000; pub const O_DIRECTORY: c_int = 0x1000_0000; -pub const O_STAT: c_int = 0x2000_0000; +pub const O_PATH: c_int = 0x2000_0000; pub const O_SYMLINK: c_int = 0x4000_0000; pub const O_NOFOLLOW: c_int = 0x8000_0000; pub const O_ACCMODE: c_int = O_RDONLY | O_WRONLY | O_RDWR; diff --git a/src/platform/src/linux/mod.rs b/src/platform/src/linux/mod.rs index ccdd0f9b49..a11f13da22 100644 --- a/src/platform/src/linux/mod.rs +++ b/src/platform/src/linux/mod.rs @@ -233,10 +233,6 @@ impl Pal for Sys { e(unsafe { syscall!(LSEEK, fildes, offset, whence) }) as off_t } - fn lstat(file: *const c_char, buf: *mut stat) -> c_int { - e(unsafe { syscall!(NEWFSTATAT, AT_FDCWD, file, buf, AT_SYMLINK_NOFOLLOW) }) as c_int - } - fn mkdir(path: *const c_char, mode: mode_t) -> c_int { e(unsafe { syscall!(MKDIRAT, AT_FDCWD, path, mode) }) as c_int } @@ -310,10 +306,6 @@ impl Pal for Sys { e(unsafe { syscall!(SETREUID, ruid, euid) }) as c_int } - fn stat(file: *const c_char, buf: *mut stat) -> c_int { - e(unsafe { syscall!(NEWFSTATAT, AT_FDCWD, file, buf, 0) }) as c_int - } - fn tcgetattr(fd: c_int, out: *mut termios) -> c_int { Self::ioctl(fd, TCGETS, out as *mut c_void) } diff --git a/src/platform/src/pal/mod.rs b/src/platform/src/pal/mod.rs index 92410c3882..45f13c053a 100644 --- a/src/platform/src/pal/mod.rs +++ b/src/platform/src/pal/mod.rs @@ -164,10 +164,6 @@ pub trait Pal { Self::no_pal("lseek") as off_t } - fn lstat(file: *const c_char, buf: *mut stat) -> c_int { - Self::no_pal("lstat") - } - fn mkdir(path: *const c_char, mode: mode_t) -> c_int { Self::no_pal("mkdir") } @@ -241,10 +237,6 @@ pub trait Pal { Self::no_pal("setreuid") } - fn stat(file: *const c_char, buf: *mut stat) -> c_int { - Self::no_pal("stat") - } - fn tcgetattr(fd: c_int, out: *mut termios) -> c_int { Self::no_pal("tcgetattr") } diff --git a/src/platform/src/redox/mod.rs b/src/platform/src/redox/mod.rs index 1129b3b4c5..bbe4920bcb 100644 --- a/src/platform/src/redox/mod.rs +++ b/src/platform/src/redox/mod.rs @@ -454,18 +454,6 @@ impl Pal for Sys { )) as off_t } - fn lstat(path: *const c_char, buf: *mut stat) -> c_int { - let path = unsafe { c_str(path) }; - match syscall::open(path, O_STAT | O_NOFOLLOW) { - Err(err) => e(Err(err)) as c_int, - Ok(fd) => { - let res = Self::fstat(fd as i32, buf); - let _ = syscall::close(fd); - res - } - } - } - fn mkdir(path: *const c_char, mode: mode_t) -> c_int { let flags = O_CREAT | O_EXCL | O_CLOEXEC | O_DIRECTORY | mode as usize & 0o777; let path = unsafe { c_str(path) }; @@ -700,18 +688,6 @@ impl Pal for Sys { e(syscall::setreuid(ruid as usize, euid as usize)) as c_int } - fn stat(path: *const c_char, buf: *mut stat) -> c_int { - let path = unsafe { c_str(path) }; - match syscall::open(path, O_STAT) { - Err(err) => e(Err(err)) as c_int, - Ok(fd) => { - let res = Self::fstat(fd as i32, buf); - let _ = syscall::close(fd); - res - } - } - } - fn tcgetattr(fd: c_int, out: *mut termios) -> c_int { let dup = e(syscall::dup(fd as usize, b"termios")); if dup == !0 { diff --git a/src/stdlib/src/lib.rs b/src/stdlib/src/lib.rs index 485e991244..e166f4ce8d 100644 --- a/src/stdlib/src/lib.rs +++ b/src/stdlib/src/lib.rs @@ -447,7 +447,7 @@ where pub extern "C" fn mktemp(name: *mut c_char) -> *mut c_char { if inner_mktemp(name, 0, || unsafe { let mut st: stat = mem::uninitialized(); - let ret = if Sys::stat(name, &mut st) != 0 && platform::errno == ENOENT { + let ret = if Sys::access(name, 0) != 0 && platform::errno == ENOENT { Some(()) } else { None diff --git a/src/sys_resource/src/lib.rs b/src/sys_resource/src/lib.rs index 29612c7298..584dfaa7a8 100644 --- a/src/sys_resource/src/lib.rs +++ b/src/sys_resource/src/lib.rs @@ -54,7 +54,7 @@ pub unsafe extern "C" fn getrlimit(resource: c_int, rlp: *mut rlimit) -> c_int { unimplemented!(); } -//#[no_mangle] +#[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) } diff --git a/src/sys_stat/Cargo.toml b/src/sys_stat/Cargo.toml index 4d04bee7d8..23e1253120 100644 --- a/src/sys_stat/Cargo.toml +++ b/src/sys_stat/Cargo.toml @@ -8,4 +8,5 @@ build = "build.rs" cbindgen = { path = "../../cbindgen" } [dependencies] +fcntl = { path = "../fcntl" } platform = { path = "../platform" } diff --git a/src/sys_stat/src/lib.rs b/src/sys_stat/src/lib.rs index 459ea5406b..81fb68623f 100644 --- a/src/sys_stat/src/lib.rs +++ b/src/sys_stat/src/lib.rs @@ -2,8 +2,10 @@ #![no_std] +extern crate fcntl; extern crate platform; +use fcntl::{O_PATH, O_NOFOLLOW}; use platform::{Pal, Sys}; use platform::types::*; @@ -85,7 +87,16 @@ 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 { - Sys::lstat(path, buf) + let fd = Sys::open(path, O_PATH | O_NOFOLLOW, 0); + if fd < 0 { + return -1; + } + + let res = Sys::fstat(fd, buf); + + Sys::close(fd); + + res } #[no_mangle] @@ -105,7 +116,16 @@ 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 { - Sys::stat(file, buf) + let fd = Sys::open(file, O_PATH, 0); + if fd < 0 { + return -1; + } + + let res = Sys::fstat(fd, buf); + + Sys::close(fd); + + res } #[no_mangle] diff --git a/src/sys_times/src/lib.rs b/src/sys_times/src/lib.rs index ebceafbd12..713fa6f18c 100644 --- a/src/sys_times/src/lib.rs +++ b/src/sys_times/src/lib.rs @@ -15,7 +15,7 @@ pub struct tms { tms_cstime: clock_t, } -//#[no_mangle] +#[no_mangle] pub extern "C" fn times(out: *mut tms) -> clock_t { Sys::times(out as *mut platform::types::tms) } From c20ce5ffeda68f117746eea6aed70f6f7c92c4cc Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sun, 26 Aug 2018 08:11:35 -0600 Subject: [PATCH 07/19] Large reorganization of headers (WIP) --- Cargo.lock | 417 +----------------- Cargo.toml | 55 +-- Makefile | 5 + build.rs | 30 +- header.sh | 16 + src/arpainet/Cargo.toml | 14 - src/arpainet/build.rs | 11 - src/crt0/Cargo.toml | 3 +- src/crt0/src/lib.rs | 6 +- src/ctype/Cargo.toml | 11 - src/ctype/build.rs | 11 - src/dirent/Cargo.toml | 15 - src/dirent/build.rs | 11 - src/errno/Cargo.toml | 11 - src/errno/build.rs | 11 - src/fcntl/Cargo.toml | 11 - src/fcntl/build.rs | 11 - src/fenv/Cargo.toml | 10 - src/fenv/build.rs | 11 - src/float/Cargo.toml | 11 - src/float/build.rs | 11 - src/fnmatch/Cargo.toml | 10 - src/fnmatch/build.rs | 11 - src/grp/Cargo.toml | 11 - src/grp/build.rs | 11 - .../_template}/cbindgen.toml | 0 .../src/lib.rs => header/_template/mod.rs} | 0 src/{todo => header/_todo}/aio/lib.rs | 0 .../_todo}/oldlib/dns/answer.rs | 0 src/{todo => header/_todo}/oldlib/dns/mod.rs | 0 .../_todo}/oldlib/dns/query.rs | 0 src/{todo => header/_todo}/oldlib/event.rs | 0 src/{todo => header/_todo}/oldlib/file.rs | 0 src/{todo => header/_todo}/oldlib/folder.rs | 0 src/{todo => header/_todo}/oldlib/hostname.rs | 0 src/{todo => header/_todo}/oldlib/lib.rs | 0 src/{todo => header/_todo}/oldlib/macros.rs | 0 .../_todo}/oldlib/mallocnull.rs | 0 src/{todo => header/_todo}/oldlib/netdb.rs | 0 src/{todo => header/_todo}/oldlib/process.rs | 0 src/{todo => header/_todo}/oldlib/rawfile.rs | 0 src/{todo => header/_todo}/oldlib/redox.rs | 0 src/{todo => header/_todo}/oldlib/socket.rs | 0 src/{todo => header/_todo}/oldlib/termios.rs | 0 src/{todo => header/_todo}/oldlib/time.rs | 0 src/{todo => header/_todo}/oldlib/types.rs | 0 src/{todo => header/_todo}/oldlib/unimpl.rs | 0 src/{todo => header/_todo}/oldlib/user.rs | 0 src/{todo => header/_todo}/pthread/lib.rs | 0 src/{todo => header/_todo}/wctype/lib.rs | 0 .../arpa_inet}/cbindgen.toml | 2 +- .../src/lib.rs => header/arpa_inet/mod.rs} | 20 +- src/{ => header}/ctype/cbindgen.toml | 0 src/{ctype/src/lib.rs => header/ctype/mod.rs} | 5 +- src/{ => header}/dirent/cbindgen.toml | 0 .../src/lib.rs => header/dirent/mod.rs} | 12 +- src/{ => header}/errno/cbindgen.toml | 0 src/{errno/src/lib.rs => header/errno/mod.rs} | 5 +- src/{ => header}/fcntl/cbindgen.toml | 0 src/{fcntl/src => header/fcntl}/linux.rs | 0 src/{fcntl/src/lib.rs => header/fcntl/mod.rs} | 5 +- src/{fcntl/src => header/fcntl}/redox.rs | 0 src/{ => header}/fenv/cbindgen.toml | 0 src/{fenv/src/lib.rs => header/fenv/mod.rs} | 5 +- src/{ => header}/float/cbindgen.toml | 0 src/{float/src/lib.rs => header/float/mod.rs} | 8 +- src/{ => header}/fnmatch/cbindgen.toml | 0 .../src/lib.rs => header/fnmatch/mod.rs} | 7 +- src/{ => header}/grp/cbindgen.toml | 0 src/{grp/src/lib.rs => header/grp/mod.rs} | 5 +- src/{ => header}/inttypes/cbindgen.toml | 0 .../src/lib.rs => header/inttypes/mod.rs} | 12 +- src/{ => header}/locale/cbindgen.toml | 0 .../src/lib.rs => header/locale/mod.rs} | 7 +- src/header/mod.rs | 38 ++ src/{netinet => header/netinet_in}/Cargo.toml | 0 .../in => header/netinet_in}/cbindgen.toml | 0 .../src/lib.rs => header/netinet_in/mod.rs} | 8 +- src/{ => header}/pwd/cbindgen.toml | 0 src/{pwd/src/lib.rs => header/pwd/mod.rs} | 11 +- src/{ => header}/semaphore/cbindgen.toml | 0 .../src/lib.rs => header/semaphore/mod.rs} | 5 +- src/{ => header}/setjmp/Cargo.toml | 0 src/{ => header}/setjmp/src/impl/README.md | 0 .../setjmp/src/impl/aarch64/longjmp.s | 0 .../setjmp/src/impl/aarch64/setjmp.s | 0 .../setjmp/src/impl/arm/longjmp.s | 0 src/{ => header}/setjmp/src/impl/arm/setjmp.s | 0 .../setjmp/src/impl/i386/longjmp.s | 0 .../setjmp/src/impl/i386/setjmp.s | 0 .../setjmp/src/impl/m68k/longjmp.s | 0 .../setjmp/src/impl/m68k/setjmp.s | 0 .../setjmp/src/impl/microblaze/longjmp.s | 0 .../setjmp/src/impl/microblaze/setjmp.s | 0 .../setjmp/src/impl/mips/longjmp.S | 0 .../setjmp/src/impl/mips/setjmp.S | 0 .../setjmp/src/impl/mips64/longjmp.S | 0 .../setjmp/src/impl/mips64/setjmp.S | 0 .../setjmp/src/impl/mipsn32/longjmp.S | 0 .../setjmp/src/impl/mipsn32/setjmp.S | 0 .../setjmp/src/impl/or1k/longjmp.s | 0 .../setjmp/src/impl/or1k/setjmp.s | 0 .../setjmp/src/impl/powerpc/longjmp.S | 0 .../setjmp/src/impl/powerpc/setjmp.S | 0 .../setjmp/src/impl/powerpc64/longjmp.s | 0 .../setjmp/src/impl/powerpc64/setjmp.s | 0 .../setjmp/src/impl/s390x/longjmp.s | 0 .../setjmp/src/impl/s390x/setjmp.s | 0 src/{ => header}/setjmp/src/impl/sh/longjmp.S | 0 src/{ => header}/setjmp/src/impl/sh/setjmp.S | 0 .../setjmp/src/impl/x32/longjmp.s | 0 src/{ => header}/setjmp/src/impl/x32/setjmp.s | 0 .../setjmp/src/impl/x86_64/longjmp.s | 0 .../setjmp/src/impl/x86_64/setjmp.s | 0 src/{ => header}/setjmp/src/lib.rs | 0 src/{ => header}/sgtty/cbindgen.toml | 0 src/{sgtty/src/lib.rs => header/sgtty/mod.rs} | 8 +- src/{ => header}/signal/cbindgen.toml | 0 src/{signal/src => header/signal}/linux.rs | 0 .../src/lib.rs => header/signal/mod.rs} | 9 +- src/{signal/src => header/signal}/redox.rs | 0 src/{ => header}/stdio/cbindgen.toml | 0 src/{stdio/src => header/stdio}/constants.rs | 0 src/{stdio/src => header/stdio}/default.rs | 0 src/{stdio/src => header/stdio}/helpers.rs | 0 src/{stdio/src => header/stdio}/internal.rs | 0 src/{stdio/src/lib.rs => header/stdio/mod.rs} | 23 +- src/{stdio/src => header/stdio}/printf.rs | 0 src/{stdio/src => header/stdio}/scanf.rs | 0 src/{ => header}/stdlib/cbindgen.toml | 0 .../src/lib.rs => header/stdlib/mod.rs} | 23 +- src/{stdlib/src => header/stdlib}/sort.rs | 0 src/{ => header}/string/cbindgen.toml | 0 .../src/lib.rs => header/string/mod.rs} | 10 +- src/{ => header}/strings/cbindgen.toml | 0 .../src/lib.rs => header/strings/mod.rs} | 7 +- src/{ => header}/sys_file/cbindgen.toml | 0 .../src/lib.rs => header/sys_file/mod.rs} | 5 +- src/{ => header}/sys_ioctl/cbindgen.toml | 0 .../src/lib.rs => header/sys_ioctl/mod.rs} | 5 +- src/{ => header}/sys_mman/cbindgen.toml | 0 .../src => header/sys_mman}/linux.rs | 0 .../src/lib.rs => header/sys_mman/mod.rs} | 5 +- .../src => header/sys_mman}/redox.rs | 0 src/{ => header}/sys_resource/cbindgen.toml | 0 .../src/lib.rs => header/sys_resource/mod.rs} | 8 +- src/{ => header}/sys_select/cbindgen.toml | 0 .../src/lib.rs => header/sys_select/mod.rs} | 5 +- src/{ => header}/sys_socket/cbindgen.toml | 0 .../src => header/sys_socket}/constants.rs | 0 .../src/lib.rs => header/sys_socket/mod.rs} | 7 +- src/{ => header}/sys_stat/cbindgen.toml | 0 .../src/lib.rs => header/sys_stat/mod.rs} | 8 +- src/{ => header}/sys_time/cbindgen.toml | 0 .../src/lib.rs => header/sys_time/mod.rs} | 5 +- src/{ => header}/sys_times/cbindgen.toml | 0 .../src/lib.rs => header/sys_times/mod.rs} | 5 +- src/{ => header}/sys_un/cbindgen.toml | 0 .../src/lib.rs => header/sys_un/mod.rs} | 6 +- src/{ => header}/sys_utsname/cbindgen.toml | 0 .../src/lib.rs => header/sys_utsname/mod.rs} | 9 +- src/{ => header}/sys_wait/cbindgen.toml | 0 .../src/lib.rs => header/sys_wait/mod.rs} | 8 +- src/{ => header}/termios/cbindgen.toml | 0 .../src/lib.rs => header/termios/mod.rs} | 4 +- src/{ => header}/time/cbindgen.toml | 0 src/{time/src => header/time}/constants.rs | 0 src/{time/src => header/time}/helpers.rs | 0 src/{time/src => header/time}/linux.rs | 0 src/{time/src/lib.rs => header/time/mod.rs} | 21 +- src/{time/src => header/time}/redox.rs | 0 src/{time/src => header/time}/strftime.rs | 0 src/{unistd/src => header/unistd}/brk.rs | 0 src/{ => header}/unistd/cbindgen.toml | 0 src/{unistd/src => header/unistd}/getopt.rs | 0 .../src/lib.rs => header/unistd/mod.rs} | 10 +- src/{unistd/src => header/unistd}/pathconf.rs | 0 src/{ => header}/utime/cbindgen.toml | 0 src/{utime/src/lib.rs => header/utime/mod.rs} | 5 +- src/{ => header}/wchar/cbindgen.toml | 0 src/{wchar/src/lib.rs => header/wchar/mod.rs} | 18 +- src/{wchar/src => header/wchar}/utf8.rs | 9 +- src/{ => header}/wctype/cbindgen.toml | 0 .../src/lib.rs => header/wctype/mod.rs} | 5 +- src/inttypes/Cargo.toml | 14 - src/inttypes/build.rs | 11 - src/lib.rs | 62 +-- src/locale/Cargo.toml | 11 - src/locale/build.rs | 11 - src/netinet/in/Cargo.toml | 12 - src/netinet/in/build.rs | 12 - src/netinet/src/lib.rs | 3 - src/platform/Cargo.toml | 16 - src/platform/{src => }/allocator/dlmalloc.rs | 0 src/platform/{src => }/allocator/ralloc.rs | 0 src/platform/{src => }/linux/mod.rs | 0 src/platform/{src => }/linux/signal.rs | 0 src/platform/{src => }/linux/socket.rs | 0 src/platform/{src/lib.rs => mod.rs} | 18 - src/platform/{src => }/pal/mod.rs | 0 src/platform/{src => }/pal/signal.rs | 0 src/platform/{src => }/pal/socket.rs | 0 src/platform/{src => }/rawfile.rs | 0 src/platform/{src => }/redox/mod.rs | 0 src/platform/{src => }/redox/signal.rs | 0 src/platform/{src => }/redox/socket.rs | 0 src/platform/{src => }/types.rs | 0 src/pwd/Cargo.toml | 12 - src/pwd/build.rs | 11 - src/semaphore/Cargo.toml | 11 - src/semaphore/build.rs | 11 - src/sgtty/Cargo.toml | 11 - src/sgtty/build.rs | 11 - src/signal/Cargo.toml | 12 - src/signal/build.rs | 11 - src/stdio/Cargo.toml | 16 - src/stdio/build.rs | 11 - src/stdlib/Cargo.toml | 19 - src/stdlib/build.rs | 11 - src/string/Cargo.toml | 13 - src/string/build.rs | 11 - src/strings/Cargo.toml | 11 - src/strings/build.rs | 11 - src/sys_file/Cargo.toml | 10 - src/sys_file/build.rs | 11 - src/sys_ioctl/Cargo.toml | 10 - src/sys_ioctl/build.rs | 11 - src/sys_mman/Cargo.toml | 11 - src/sys_mman/build.rs | 11 - src/sys_resource/Cargo.toml | 11 - src/sys_resource/build.rs | 11 - src/sys_select/Cargo.toml | 10 - src/sys_select/build.rs | 11 - src/sys_socket/Cargo.toml | 11 - src/sys_socket/build.rs | 11 - src/sys_stat/Cargo.toml | 12 - src/sys_stat/build.rs | 11 - src/sys_time/Cargo.toml | 11 - src/sys_time/build.rs | 11 - src/sys_times/Cargo.toml | 10 - src/sys_times/build.rs | 11 - src/sys_un/Cargo.toml | 12 - src/sys_un/build.rs | 11 - src/sys_utsname/Cargo.toml | 11 - src/sys_utsname/build.rs | 11 - src/sys_wait/Cargo.toml | 11 - src/sys_wait/build.rs | 11 - src/template/Cargo.toml | 11 - src/template/build.rs | 11 - src/termios/Cargo.toml | 10 - src/termios/build.rs | 11 - src/time/Cargo.toml | 12 - src/time/build.rs | 11 - src/unistd/Cargo.toml | 15 - src/unistd/build.rs | 11 - src/utime/Cargo.toml | 11 - src/utime/build.rs | 11 - src/wchar/Cargo.toml | 18 - src/wchar/build.rs | 11 - src/wctype/Cargo.toml | 11 - src/wctype/build.rs | 11 - 261 files changed, 236 insertions(+), 1672 deletions(-) create mode 100755 header.sh delete mode 100644 src/arpainet/Cargo.toml delete mode 100644 src/arpainet/build.rs delete mode 100644 src/ctype/Cargo.toml delete mode 100644 src/ctype/build.rs delete mode 100644 src/dirent/Cargo.toml delete mode 100644 src/dirent/build.rs delete mode 100644 src/errno/Cargo.toml delete mode 100644 src/errno/build.rs delete mode 100644 src/fcntl/Cargo.toml delete mode 100644 src/fcntl/build.rs delete mode 100644 src/fenv/Cargo.toml delete mode 100644 src/fenv/build.rs delete mode 100644 src/float/Cargo.toml delete mode 100644 src/float/build.rs delete mode 100644 src/fnmatch/Cargo.toml delete mode 100644 src/fnmatch/build.rs delete mode 100644 src/grp/Cargo.toml delete mode 100644 src/grp/build.rs rename src/{template => header/_template}/cbindgen.toml (100%) rename src/{template/src/lib.rs => header/_template/mod.rs} (100%) rename src/{todo => header/_todo}/aio/lib.rs (100%) rename src/{todo => header/_todo}/oldlib/dns/answer.rs (100%) rename src/{todo => header/_todo}/oldlib/dns/mod.rs (100%) rename src/{todo => header/_todo}/oldlib/dns/query.rs (100%) rename src/{todo => header/_todo}/oldlib/event.rs (100%) rename src/{todo => header/_todo}/oldlib/file.rs (100%) rename src/{todo => header/_todo}/oldlib/folder.rs (100%) rename src/{todo => header/_todo}/oldlib/hostname.rs (100%) rename src/{todo => header/_todo}/oldlib/lib.rs (100%) rename src/{todo => header/_todo}/oldlib/macros.rs (100%) rename src/{todo => header/_todo}/oldlib/mallocnull.rs (100%) rename src/{todo => header/_todo}/oldlib/netdb.rs (100%) rename src/{todo => header/_todo}/oldlib/process.rs (100%) rename src/{todo => header/_todo}/oldlib/rawfile.rs (100%) rename src/{todo => header/_todo}/oldlib/redox.rs (100%) rename src/{todo => header/_todo}/oldlib/socket.rs (100%) rename src/{todo => header/_todo}/oldlib/termios.rs (100%) rename src/{todo => header/_todo}/oldlib/time.rs (100%) rename src/{todo => header/_todo}/oldlib/types.rs (100%) rename src/{todo => header/_todo}/oldlib/unimpl.rs (100%) rename src/{todo => header/_todo}/oldlib/user.rs (100%) rename src/{todo => header/_todo}/pthread/lib.rs (100%) rename src/{todo => header/_todo}/wctype/lib.rs (100%) rename src/{arpainet => header/arpa_inet}/cbindgen.toml (79%) rename src/{arpainet/src/lib.rs => header/arpa_inet/mod.rs} (90%) rename src/{ => header}/ctype/cbindgen.toml (100%) rename src/{ctype/src/lib.rs => header/ctype/mod.rs} (98%) rename src/{ => header}/dirent/cbindgen.toml (100%) rename src/{dirent/src/lib.rs => header/dirent/mod.rs} (95%) rename src/{ => header}/errno/cbindgen.toml (100%) rename src/{errno/src/lib.rs => header/errno/mod.rs} (99%) rename src/{ => header}/fcntl/cbindgen.toml (100%) rename src/{fcntl/src => header/fcntl}/linux.rs (100%) rename src/{fcntl/src/lib.rs => header/fcntl/mod.rs} (96%) rename src/{fcntl/src => header/fcntl}/redox.rs (100%) rename src/{ => header}/fenv/cbindgen.toml (100%) rename src/{fenv/src/lib.rs => header/fenv/mod.rs} (97%) rename src/{ => header}/float/cbindgen.toml (100%) rename src/{float/src/lib.rs => header/float/mod.rs} (77%) rename src/{ => header}/fnmatch/cbindgen.toml (100%) rename src/{fnmatch/src/lib.rs => header/fnmatch/mod.rs} (98%) rename src/{ => header}/grp/cbindgen.toml (100%) rename src/{grp/src/lib.rs => header/grp/mod.rs} (97%) rename src/{ => header}/inttypes/cbindgen.toml (100%) rename src/{inttypes/src/lib.rs => header/inttypes/mod.rs} (91%) rename src/{ => header}/locale/cbindgen.toml (100%) rename src/{locale/src/lib.rs => header/locale/mod.rs} (97%) create mode 100644 src/header/mod.rs rename src/{netinet => header/netinet_in}/Cargo.toml (100%) rename src/{netinet/in => header/netinet_in}/cbindgen.toml (100%) rename src/{netinet/in/src/lib.rs => header/netinet_in/mod.rs} (93%) rename src/{ => header}/pwd/cbindgen.toml (100%) rename src/{pwd/src/lib.rs => header/pwd/mod.rs} (98%) rename src/{ => header}/semaphore/cbindgen.toml (100%) rename src/{semaphore/src/lib.rs => header/semaphore/mod.rs} (97%) rename src/{ => header}/setjmp/Cargo.toml (100%) rename src/{ => header}/setjmp/src/impl/README.md (100%) rename src/{ => header}/setjmp/src/impl/aarch64/longjmp.s (100%) rename src/{ => header}/setjmp/src/impl/aarch64/setjmp.s (100%) rename src/{ => header}/setjmp/src/impl/arm/longjmp.s (100%) rename src/{ => header}/setjmp/src/impl/arm/setjmp.s (100%) rename src/{ => header}/setjmp/src/impl/i386/longjmp.s (100%) rename src/{ => header}/setjmp/src/impl/i386/setjmp.s (100%) rename src/{ => header}/setjmp/src/impl/m68k/longjmp.s (100%) rename src/{ => header}/setjmp/src/impl/m68k/setjmp.s (100%) rename src/{ => header}/setjmp/src/impl/microblaze/longjmp.s (100%) rename src/{ => header}/setjmp/src/impl/microblaze/setjmp.s (100%) rename src/{ => header}/setjmp/src/impl/mips/longjmp.S (100%) rename src/{ => header}/setjmp/src/impl/mips/setjmp.S (100%) rename src/{ => header}/setjmp/src/impl/mips64/longjmp.S (100%) rename src/{ => header}/setjmp/src/impl/mips64/setjmp.S (100%) rename src/{ => header}/setjmp/src/impl/mipsn32/longjmp.S (100%) rename src/{ => header}/setjmp/src/impl/mipsn32/setjmp.S (100%) rename src/{ => header}/setjmp/src/impl/or1k/longjmp.s (100%) rename src/{ => header}/setjmp/src/impl/or1k/setjmp.s (100%) rename src/{ => header}/setjmp/src/impl/powerpc/longjmp.S (100%) rename src/{ => header}/setjmp/src/impl/powerpc/setjmp.S (100%) rename src/{ => header}/setjmp/src/impl/powerpc64/longjmp.s (100%) rename src/{ => header}/setjmp/src/impl/powerpc64/setjmp.s (100%) rename src/{ => header}/setjmp/src/impl/s390x/longjmp.s (100%) rename src/{ => header}/setjmp/src/impl/s390x/setjmp.s (100%) rename src/{ => header}/setjmp/src/impl/sh/longjmp.S (100%) rename src/{ => header}/setjmp/src/impl/sh/setjmp.S (100%) rename src/{ => header}/setjmp/src/impl/x32/longjmp.s (100%) rename src/{ => header}/setjmp/src/impl/x32/setjmp.s (100%) rename src/{ => header}/setjmp/src/impl/x86_64/longjmp.s (100%) rename src/{ => header}/setjmp/src/impl/x86_64/setjmp.s (100%) rename src/{ => header}/setjmp/src/lib.rs (100%) rename src/{ => header}/sgtty/cbindgen.toml (100%) rename src/{sgtty/src/lib.rs => header/sgtty/mod.rs} (80%) rename src/{ => header}/signal/cbindgen.toml (100%) rename src/{signal/src => header/signal}/linux.rs (100%) rename src/{signal/src/lib.rs => header/signal/mod.rs} (98%) rename src/{signal/src => header/signal}/redox.rs (100%) rename src/{ => header}/stdio/cbindgen.toml (100%) rename src/{stdio/src => header/stdio}/constants.rs (100%) rename src/{stdio/src => header/stdio}/default.rs (100%) rename src/{stdio/src => header/stdio}/helpers.rs (100%) rename src/{stdio/src => header/stdio}/internal.rs (100%) rename src/{stdio/src/lib.rs => header/stdio/mod.rs} (98%) rename src/{stdio/src => header/stdio}/printf.rs (100%) rename src/{stdio/src => header/stdio}/scanf.rs (100%) rename src/{ => header}/stdlib/cbindgen.toml (100%) rename src/{stdlib/src/lib.rs => header/stdlib/mod.rs} (98%) rename src/{stdlib/src => header/stdlib}/sort.rs (100%) rename src/{ => header}/string/cbindgen.toml (100%) rename src/{string/src/lib.rs => header/string/mod.rs} (99%) rename src/{ => header}/strings/cbindgen.toml (100%) rename src/{strings/src/lib.rs => header/strings/mod.rs} (97%) rename src/{ => header}/sys_file/cbindgen.toml (100%) rename src/{sys_file/src/lib.rs => header/sys_file/mod.rs} (91%) rename src/{ => header}/sys_ioctl/cbindgen.toml (100%) rename src/{sys_ioctl/src/lib.rs => header/sys_ioctl/mod.rs} (99%) rename src/{ => header}/sys_mman/cbindgen.toml (100%) rename src/{sys_mman/src => header/sys_mman}/linux.rs (100%) rename src/{sys_mman/src/lib.rs => header/sys_mman/mod.rs} (97%) rename src/{sys_mman/src => header/sys_mman}/redox.rs (100%) rename src/{ => header}/sys_resource/cbindgen.toml (100%) rename src/{sys_resource/src/lib.rs => header/sys_resource/mod.rs} (94%) rename src/{ => header}/sys_select/cbindgen.toml (100%) rename src/{sys_select/src/lib.rs => header/sys_select/mod.rs} (92%) rename src/{ => header}/sys_socket/cbindgen.toml (100%) rename src/{sys_socket/src => header/sys_socket}/constants.rs (100%) rename src/{sys_socket/src/lib.rs => header/sys_socket/mod.rs} (98%) rename src/{ => header}/sys_stat/cbindgen.toml (100%) rename src/{sys_stat/src/lib.rs => header/sys_stat/mod.rs} (97%) rename src/{ => header}/sys_time/cbindgen.toml (100%) rename src/{sys_time/src/lib.rs => header/sys_time/mod.rs} (98%) rename src/{ => header}/sys_times/cbindgen.toml (100%) rename src/{sys_times/src/lib.rs => header/sys_times/mod.rs} (90%) rename src/{ => header}/sys_un/cbindgen.toml (100%) rename src/{sys_un/src/lib.rs => header/sys_un/mod.rs} (63%) rename src/{ => header}/sys_utsname/cbindgen.toml (100%) rename src/{sys_utsname/src/lib.rs => header/sys_utsname/mod.rs} (86%) rename src/{ => header}/sys_wait/cbindgen.toml (100%) rename src/{sys_wait/src/lib.rs => header/sys_wait/mod.rs} (92%) rename src/{ => header}/termios/cbindgen.toml (100%) rename src/{termios/src/lib.rs => header/termios/mod.rs} (99%) rename src/{ => header}/time/cbindgen.toml (100%) rename src/{time/src => header/time}/constants.rs (100%) rename src/{time/src => header/time}/helpers.rs (100%) rename src/{time/src => header/time}/linux.rs (100%) rename src/{time/src/lib.rs => header/time/mod.rs} (98%) rename src/{time/src => header/time}/redox.rs (100%) rename src/{time/src => header/time}/strftime.rs (100%) rename src/{unistd/src => header/unistd}/brk.rs (100%) rename src/{ => header}/unistd/cbindgen.toml (100%) rename src/{unistd/src => header/unistd}/getopt.rs (100%) rename src/{unistd/src/lib.rs => header/unistd/mod.rs} (98%) rename src/{unistd/src => header/unistd}/pathconf.rs (100%) rename src/{ => header}/utime/cbindgen.toml (100%) rename src/{utime/src/lib.rs => header/utime/mod.rs} (94%) rename src/{ => header}/wchar/cbindgen.toml (100%) rename src/{wchar/src/lib.rs => header/wchar/mod.rs} (98%) rename src/{wchar/src => header/wchar}/utf8.rs (97%) rename src/{ => header}/wctype/cbindgen.toml (100%) rename src/{wctype/src/lib.rs => header/wctype/mod.rs} (97%) delete mode 100644 src/inttypes/Cargo.toml delete mode 100644 src/inttypes/build.rs delete mode 100644 src/locale/Cargo.toml delete mode 100644 src/locale/build.rs delete mode 100644 src/netinet/in/Cargo.toml delete mode 100644 src/netinet/in/build.rs delete mode 100644 src/netinet/src/lib.rs delete mode 100644 src/platform/Cargo.toml rename src/platform/{src => }/allocator/dlmalloc.rs (100%) rename src/platform/{src => }/allocator/ralloc.rs (100%) rename src/platform/{src => }/linux/mod.rs (100%) rename src/platform/{src => }/linux/signal.rs (100%) rename src/platform/{src => }/linux/socket.rs (100%) rename src/platform/{src/lib.rs => mod.rs} (94%) rename src/platform/{src => }/pal/mod.rs (100%) rename src/platform/{src => }/pal/signal.rs (100%) rename src/platform/{src => }/pal/socket.rs (100%) rename src/platform/{src => }/rawfile.rs (100%) rename src/platform/{src => }/redox/mod.rs (100%) rename src/platform/{src => }/redox/signal.rs (100%) rename src/platform/{src => }/redox/socket.rs (100%) rename src/platform/{src => }/types.rs (100%) delete mode 100644 src/pwd/Cargo.toml delete mode 100644 src/pwd/build.rs delete mode 100644 src/semaphore/Cargo.toml delete mode 100644 src/semaphore/build.rs delete mode 100644 src/sgtty/Cargo.toml delete mode 100644 src/sgtty/build.rs delete mode 100644 src/signal/Cargo.toml delete mode 100644 src/signal/build.rs delete mode 100644 src/stdio/Cargo.toml delete mode 100644 src/stdio/build.rs delete mode 100644 src/stdlib/Cargo.toml delete mode 100644 src/stdlib/build.rs delete mode 100644 src/string/Cargo.toml delete mode 100644 src/string/build.rs delete mode 100644 src/strings/Cargo.toml delete mode 100644 src/strings/build.rs delete mode 100644 src/sys_file/Cargo.toml delete mode 100644 src/sys_file/build.rs delete mode 100644 src/sys_ioctl/Cargo.toml delete mode 100644 src/sys_ioctl/build.rs delete mode 100644 src/sys_mman/Cargo.toml delete mode 100644 src/sys_mman/build.rs delete mode 100644 src/sys_resource/Cargo.toml delete mode 100644 src/sys_resource/build.rs delete mode 100644 src/sys_select/Cargo.toml delete mode 100644 src/sys_select/build.rs delete mode 100644 src/sys_socket/Cargo.toml delete mode 100644 src/sys_socket/build.rs delete mode 100644 src/sys_stat/Cargo.toml delete mode 100644 src/sys_stat/build.rs delete mode 100644 src/sys_time/Cargo.toml delete mode 100644 src/sys_time/build.rs delete mode 100644 src/sys_times/Cargo.toml delete mode 100644 src/sys_times/build.rs delete mode 100644 src/sys_un/Cargo.toml delete mode 100644 src/sys_un/build.rs delete mode 100644 src/sys_utsname/Cargo.toml delete mode 100644 src/sys_utsname/build.rs delete mode 100644 src/sys_wait/Cargo.toml delete mode 100644 src/sys_wait/build.rs delete mode 100644 src/template/Cargo.toml delete mode 100644 src/template/build.rs delete mode 100644 src/termios/Cargo.toml delete mode 100644 src/termios/build.rs delete mode 100644 src/time/Cargo.toml delete mode 100644 src/time/build.rs delete mode 100644 src/unistd/Cargo.toml delete mode 100644 src/unistd/build.rs delete mode 100644 src/utime/Cargo.toml delete mode 100644 src/utime/build.rs delete mode 100644 src/wchar/Cargo.toml delete mode 100644 src/wchar/build.rs delete mode 100644 src/wctype/Cargo.toml delete mode 100644 src/wctype/build.rs diff --git a/Cargo.lock b/Cargo.lock index d329b0c9ef..3ecbfa7830 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6,17 +6,6 @@ dependencies = [ "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "arpainet" -version = "0.1.0" -dependencies = [ - "cbindgen 0.5.2", - "errno 0.1.0", - "netinet 0.1.0", - "platform 0.1.0", - "sys_socket 0.1.0", -] - [[package]] name = "atty" version = "0.2.10" @@ -79,28 +68,7 @@ source = "git+https://github.com/rust-lang-nursery/compiler-builtins.git#5d370bb name = "crt0" version = "0.1.0" dependencies = [ - "platform 0.1.0", - "stdio 0.1.0", -] - -[[package]] -name = "ctype" -version = "0.1.0" -dependencies = [ - "cbindgen 0.5.2", - "platform 0.1.0", -] - -[[package]] -name = "dirent" -version = "0.1.0" -dependencies = [ - "cbindgen 0.5.2", - "errno 0.1.0", - "fcntl 0.1.0", - "platform 0.1.0", - "stdio 0.1.0", - "unistd 0.1.0", + "relibc 0.1.0", ] [[package]] @@ -108,47 +76,6 @@ name = "dtoa" version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "errno" -version = "0.1.0" -dependencies = [ - "cbindgen 0.5.2", - "platform 0.1.0", -] - -[[package]] -name = "fcntl" -version = "0.1.0" -dependencies = [ - "cbindgen 0.5.2", - "platform 0.1.0", -] - -[[package]] -name = "fenv" -version = "0.1.0" -dependencies = [ - "cbindgen 0.5.2", - "platform 0.1.0", -] - -[[package]] -name = "float" -version = "0.1.0" -dependencies = [ - "cbindgen 0.5.2", - "fenv 0.1.0", - "platform 0.1.0", -] - -[[package]] -name = "fnmatch" -version = "0.1.0" -dependencies = [ - "cbindgen 0.5.2", - "platform 0.1.0", -] - [[package]] name = "fuchsia-zircon" version = "0.3.3" @@ -163,34 +90,6 @@ name = "fuchsia-zircon-sys" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "grp" -version = "0.1.0" -dependencies = [ - "cbindgen 0.5.2", - "platform 0.1.0", -] - -[[package]] -name = "in_h" -version = "0.1.0" -dependencies = [ - "cbindgen 0.5.2", - "platform 0.1.0", - "sys_socket 0.1.0", -] - -[[package]] -name = "inttypes" -version = "0.1.0" -dependencies = [ - "cbindgen 0.5.2", - "ctype 0.1.0", - "errno 0.1.0", - "platform 0.1.0", - "stdlib 0.1.0", -] - [[package]] name = "itoa" version = "0.4.2" @@ -198,10 +97,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "lazy_static" -version = "1.0.2" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "spin 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "spin 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", + "version_check 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -209,14 +109,6 @@ name = "libc" version = "0.2.42" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "locale" -version = "0.1.0" -dependencies = [ - "cbindgen 0.5.2", - "platform 0.1.0", -] - [[package]] name = "log" version = "0.3.9" @@ -233,23 +125,6 @@ dependencies = [ "cfg-if 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "netinet" -version = "0.1.0" -dependencies = [ - "in_h 0.1.0", -] - -[[package]] -name = "platform" -version = "0.1.0" -dependencies = [ - "ralloc 1.0.0", - "redox_syscall 0.1.40 (git+https://gitlab.redox-os.org/redox-os/syscall.git?branch=relibc)", - "sc 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "spin 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "proc-macro2" version = "0.2.3" @@ -258,16 +133,6 @@ dependencies = [ "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "pwd" -version = "0.1.0" -dependencies = [ - "cbindgen 0.5.2", - "errno 0.1.0", - "fcntl 0.1.0", - "platform 0.1.0", -] - [[package]] name = "quote" version = "0.3.15" @@ -301,7 +166,7 @@ dependencies = [ [[package]] name = "rand" -version = "0.5.4" +version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "rand_core 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -334,46 +199,15 @@ dependencies = [ name = "relibc" version = "0.1.0" dependencies = [ - "arpainet 0.1.0", "cc 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)", "compiler_builtins 0.1.0 (git+https://github.com/rust-lang-nursery/compiler-builtins.git)", - "ctype 0.1.0", - "dirent 0.1.0", - "errno 0.1.0", - "fcntl 0.1.0", - "fenv 0.1.0", - "float 0.1.0", - "fnmatch 0.1.0", - "grp 0.1.0", - "inttypes 0.1.0", - "locale 0.1.0", - "netinet 0.1.0", - "platform 0.1.0", - "pwd 0.1.0", - "semaphore 0.1.0", - "setjmp 0.1.0", - "signal 0.1.0", - "stdio 0.1.0", - "stdlib 0.1.0", - "string 0.1.0", - "strings 0.1.0", - "sys_ioctl 0.1.0", - "sys_mman 0.1.0", - "sys_resource 0.1.0", - "sys_select 0.1.0", - "sys_socket 0.1.0", - "sys_stat 0.1.0", - "sys_time 0.1.0", - "sys_times 0.1.0", - "sys_un 0.1.0", - "sys_utsname 0.1.0", - "sys_wait 0.1.0", - "termios 0.1.0", - "time 0.1.0", - "unistd 0.1.0", - "utime 0.1.0", - "wchar 0.1.0", - "wctype 0.1.0", + "lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "ralloc 1.0.0", + "rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.40 (git+https://gitlab.redox-os.org/redox-os/syscall.git?branch=relibc)", + "sc 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "spin 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", + "va_list 0.1.0", ] [[package]] @@ -389,14 +223,6 @@ name = "sc" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "semaphore" -version = "0.1.0" -dependencies = [ - "cbindgen 0.5.2", - "platform 0.1.0", -] - [[package]] name = "serde" version = "1.0.70" @@ -434,22 +260,9 @@ dependencies = [ "serde 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "setjmp" -version = "0.1.0" - -[[package]] -name = "signal" -version = "0.1.0" -dependencies = [ - "cbindgen 0.5.2", - "errno 0.1.0", - "platform 0.1.0", -] - [[package]] name = "spin" -version = "0.4.8" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -470,53 +283,6 @@ dependencies = [ "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "stdio" -version = "0.1.0" -dependencies = [ - "cbindgen 0.5.2", - "errno 0.1.0", - "fcntl 0.1.0", - "lazy_static 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "platform 0.1.0", - "string 0.1.0", - "va_list 0.1.0", -] - -[[package]] -name = "stdlib" -version = "0.1.0" -dependencies = [ - "cbindgen 0.5.2", - "ctype 0.1.0", - "errno 0.1.0", - "fcntl 0.1.0", - "platform 0.1.0", - "rand 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", - "string 0.1.0", - "time 0.1.0", - "unistd 0.1.0", - "wchar 0.1.0", -] - -[[package]] -name = "string" -version = "0.1.0" -dependencies = [ - "cbindgen 0.5.2", - "errno 0.1.0", - "platform 0.1.0", - "signal 0.1.0", -] - -[[package]] -name = "strings" -version = "0.1.0" -dependencies = [ - "cbindgen 0.5.2", - "platform 0.1.0", -] - [[package]] name = "strsim" version = "0.7.0" @@ -540,98 +306,6 @@ dependencies = [ "unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "sys_ioctl" -version = "0.1.0" -dependencies = [ - "cbindgen 0.5.2", - "platform 0.1.0", -] - -[[package]] -name = "sys_mman" -version = "0.1.0" -dependencies = [ - "cbindgen 0.5.2", - "platform 0.1.0", -] - -[[package]] -name = "sys_resource" -version = "0.1.0" -dependencies = [ - "cbindgen 0.5.2", - "platform 0.1.0", - "sys_time 0.1.0", -] - -[[package]] -name = "sys_select" -version = "0.1.0" -dependencies = [ - "cbindgen 0.5.2", - "platform 0.1.0", -] - -[[package]] -name = "sys_socket" -version = "0.1.0" -dependencies = [ - "cbindgen 0.5.2", - "platform 0.1.0", -] - -[[package]] -name = "sys_stat" -version = "0.1.0" -dependencies = [ - "cbindgen 0.5.2", - "fcntl 0.1.0", - "platform 0.1.0", -] - -[[package]] -name = "sys_time" -version = "0.1.0" -dependencies = [ - "cbindgen 0.5.2", - "platform 0.1.0", -] - -[[package]] -name = "sys_times" -version = "0.1.0" -dependencies = [ - "cbindgen 0.5.2", - "platform 0.1.0", -] - -[[package]] -name = "sys_un" -version = "0.1.0" -dependencies = [ - "cbindgen 0.5.2", - "platform 0.1.0", - "sys_socket 0.1.0", -] - -[[package]] -name = "sys_utsname" -version = "0.1.0" -dependencies = [ - "cbindgen 0.5.2", - "platform 0.1.0", -] - -[[package]] -name = "sys_wait" -version = "0.1.0" -dependencies = [ - "cbindgen 0.5.2", - "platform 0.1.0", - "sys_resource 0.1.0", -] - [[package]] name = "tempdir" version = "0.3.7" @@ -651,14 +325,6 @@ dependencies = [ "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "termios" -version = "0.1.0" -dependencies = [ - "cbindgen 0.5.2", - "platform 0.1.0", -] - [[package]] name = "textwrap" version = "0.10.0" @@ -667,15 +333,6 @@ dependencies = [ "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "time" -version = "0.1.0" -dependencies = [ - "cbindgen 0.5.2", - "errno 0.1.0", - "platform 0.1.0", -] - [[package]] name = "toml" version = "0.4.6" @@ -704,26 +361,6 @@ name = "unicode-xid" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "unistd" -version = "0.1.0" -dependencies = [ - "cbindgen 0.5.2", - "errno 0.1.0", - "platform 0.1.0", - "stdio 0.1.0", - "string 0.1.0", - "sys_time 0.1.0", -] - -[[package]] -name = "utime" -version = "0.1.0" -dependencies = [ - "cbindgen 0.5.2", - "platform 0.1.0", -] - [[package]] name = "va_list" version = "0.1.0" @@ -744,24 +381,9 @@ version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] -name = "wchar" -version = "0.1.0" -dependencies = [ - "cbindgen 0.5.2", - "errno 0.1.0", - "platform 0.1.0", - "stdio 0.1.0", - "time 0.1.0", - "va_list 0.1.0", -] - -[[package]] -name = "wctype" -version = "0.1.0" -dependencies = [ - "cbindgen 0.5.2", - "platform 0.1.0", -] +name = "version_check" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "winapi" @@ -794,14 +416,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" "checksum itoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5adb58558dcd1d786b5f0bd15f3226ee23486e24b7b58304b60f64dc68e62606" -"checksum lazy_static 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "fb497c35d362b6a331cfd94956a07fc2c78a4604cdbee844a81170386b996dd3" +"checksum lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca488b89a5657b0a2ecd45b95609b3e848cf1755da332a0da46e2b2b1cb371a7" "checksum libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)" = "b685088df2b950fccadf07a7187c8ef846a959c142338a48f9dc0b94517eb5f1" "checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" "checksum log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "61bd98ae7f7b754bc53dca7d44b604f733c6bba044ea6f41bc8d89272d8161d2" "checksum proc-macro2 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cd07deb3c6d1d9ff827999c7f9b04cdfd66b1b17ae508e14fe47b620f2282ae0" "checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a" "checksum rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eba5f8cb59cc50ed56be8880a5c7b496bfd9bd26394e176bc67884094145c2c5" -"checksum rand 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "12397506224b2f93e6664ffc4f664b29be8208e5157d3d90b44f09b5fae470ea" +"checksum rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e464cd887e869cddcae8792a4ee31d23c7edd516700695608f5b98c67ee0131c" "checksum rand_core 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "edecf0f94da5551fc9b492093e30b041a891657db7940ee221f9d2f66e82eef2" "checksum redox_syscall 0.1.40 (git+https://gitlab.redox-os.org/redox-os/syscall.git?branch=relibc)" = "" "checksum redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "c214e91d3ecf43e9a4e41e578973adeb14b474f2bee858742d127af75a0112b1" @@ -812,7 +434,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum serde_derive 1.0.21 (registry+https://github.com/rust-lang/crates.io-index)" = "652bc323d694dc925829725ec6c890156d8e70ae5202919869cb00fe2eff3788" "checksum serde_derive_internals 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)" = "32f1926285523b2db55df263d2aa4eb69ddcfa7a7eade6430323637866b513ab" "checksum serde_json 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)" = "c3c6908c7b925cd6c590358a4034de93dbddb20c45e1d021931459fd419bf0e2" -"checksum spin 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14db77c5b914df6d6173dda9a3b3f5937bd802934fa5edaf934df06a3491e56f" +"checksum spin 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)" = "37b5646825922b96b5d7d676b5bb3458a54498e96ed7b0ce09dc43a07038fea4" "checksum standalone-quote 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dcedac1d6d98e7e9d1d6e628f5635af9566688ae5f6cea70a3976f495ae8d839" "checksum standalone-syn 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "115808f5187c07c23cb93eee49d542fae54c6e8285d3a24c6ff683fcde9243db" "checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550" @@ -827,6 +449,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc" "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" "checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" +"checksum version_check 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "7716c242968ee87e5542f8021178248f267f295a5c4803beae8b8b7fd9bc6051" "checksum winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "773ef9dcc5f24b7d850d0ff101e542ff24c3b090a9768e03ff889fdef41f00fd" "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml index 41e6711aec..0736e52eeb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,56 +8,33 @@ name = "c" crate-type = ["staticlib"] [workspace] -members = ["src/crt0"] +members = ["src/crt0", "cbindgen"] [build-dependencies] cc = "1.0.17" [dependencies] -arpainet = { path = "src/arpainet" } -ctype = { path = "src/ctype" } -dirent = { path = "src/dirent" } -errno = { path = "src/errno" } -fcntl = { path = "src/fcntl" } -fenv = { path = "src/fenv" } -float = { path = "src/float" } -fnmatch = { path = "src/fnmatch" } -grp = { path = "src/grp" } -inttypes = { path = "src/inttypes" } -locale = { path = "src/locale" } -netinet = { path = "src/netinet" } -platform = { path = "src/platform" } -pwd = { path = "src/pwd" } -semaphore = { path = "src/semaphore" } -setjmp = { path = "src/setjmp" } -signal = { path = "src/signal" } -stdio = { path = "src/stdio" } -stdlib = { path = "src/stdlib" } -string = { path = "src/string" } -strings = { path = "src/strings" } -sys_ioctl = { path = "src/sys_ioctl" } -sys_mman = { path = "src/sys_mman" } -sys_resource = { path = "src/sys_resource" } -sys_select = { path = "src/sys_select" } -sys_socket = { path = "src/sys_socket" } -sys_stat = { path = "src/sys_stat" } -sys_time = { path = "src/sys_time" } -sys_times = { path = "src/sys_times" } -sys_un = { path = "src/sys_un" } -sys_utsname = { path = "src/sys_utsname" } -sys_wait = { path = "src/sys_wait" } -termios = { path = "src/termios" } -time = { path = "src/time" } -unistd = { path = "src/unistd" } -utime = { path = "src/utime" } -wchar = { path = "src/wchar" } -wctype = { path = "src/wctype" } +lazy_static = { version = "*", features = ["nightly", "spin_no_std"] } +rand = { version = "0.5.2", default-features = false } +va_list = { path = "va_list", features = ["no_std"] } [dependencies.compiler_builtins] git = "https://github.com/rust-lang-nursery/compiler-builtins.git" default-features = false features = ["no-lang-items", "mangled-names"] +[dependencies.ralloc] +path = "ralloc" +default-features = false +optional = true + +[target.'cfg(target_os = "linux")'.dependencies] +sc = "0.2" + +[target.'cfg(target_os = "redox")'.dependencies] +redox_syscall = { git = "https://gitlab.redox-os.org/redox-os/syscall.git", branch = "relibc" } +spin = "0.4" + [profile.dev] panic = "abort" diff --git a/Makefile b/Makefile index 25aef80ebe..c30f02b7db 100644 --- a/Makefile +++ b/Makefile @@ -45,6 +45,11 @@ install: all cp -rv "openlibm/src"/*.h "$(DESTDIR)/include" cp -v "$(BUILD)/openlibm/libopenlibm.a" "$(DESTDIR)/lib/libm.a" +header: + mkdir -p header + ./header.sh + touch header + libc: $(BUILD)/release/libc.a $(BUILD)/release/crt0.o libm: $(BUILD)/openlibm/libopenlibm.a diff --git a/build.rs b/build.rs index 8f61a6d4b2..345db4fc47 100644 --- a/build.rs +++ b/build.rs @@ -1,22 +1,22 @@ extern crate cc; -use std::env; +// use std::env; fn main() { - let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); - - cc::Build::new() - .flag("-nostdinc") - .flag("-nostdlib") - .flag("-I") - .flag(&format!("{}/include", crate_dir)) - .flag("-fno-stack-protector") - .file("src/c/dlmalloc.c") - .file("src/c/fcntl.c") - .file("src/c/stack_chk.c") - .file("src/c/stdio.c") - .file("src/c/unistd.c") - .compile("relibc_c"); + // let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); + // + // cc::Build::new() + // .flag("-nostdinc") + // .flag("-nostdlib") + // .flag("-I") + // .flag(&format!("{}/include", crate_dir)) + // .flag("-fno-stack-protector") + // .file("src/c/dlmalloc.c") + // .file("src/c/fcntl.c") + // .file("src/c/stack_chk.c") + // .file("src/c/stdio.c") + // .file("src/c/unistd.c") + // .compile("relibc_c"); println!("cargo:rustc-link-lib=static=relibc_c"); } diff --git a/header.sh b/header.sh new file mode 100755 index 0000000000..2c835809c2 --- /dev/null +++ b/header.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +set -ex + +header="$(realpath header)" +cbindgen="$(realpath cbindgen)" + +for config in src/header/*/cbindgen.toml +do + dir="$(dirname "$config")" + name="$(basename "$dir")" + pushd "$dir" + cargo run --release --manifest-path "$cbindgen/Cargo.toml" -- \ + -c cbindgen.toml -o "$header/$name.h" mod.rs + popd +done diff --git a/src/arpainet/Cargo.toml b/src/arpainet/Cargo.toml deleted file mode 100644 index 5a01556751..0000000000 --- a/src/arpainet/Cargo.toml +++ /dev/null @@ -1,14 +0,0 @@ -[package] -name = "arpainet" -version = "0.1.0" -authors = ["Jeremy Soller "] -build = "build.rs" - -[build-dependencies] -cbindgen = { path = "../../cbindgen" } - -[dependencies] -platform = { path = "../platform" } -errno = { path = "../errno" } -sys_socket = { path = "../sys_socket" } -netinet = { path = "../netinet" } diff --git a/src/arpainet/build.rs b/src/arpainet/build.rs deleted file mode 100644 index ad73b43495..0000000000 --- a/src/arpainet/build.rs +++ /dev/null @@ -1,11 +0,0 @@ -extern crate cbindgen; - -use std::{env, fs}; - -fn main() { - let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); - fs::create_dir_all("../../target/include").expect("failed to create include directory"); - cbindgen::generate(crate_dir) - .expect("failed to generate bindings") - .write_to_file("../../target/include/arpa/inet.h"); -} diff --git a/src/crt0/Cargo.toml b/src/crt0/Cargo.toml index 9133360068..9b6c91a2bf 100644 --- a/src/crt0/Cargo.toml +++ b/src/crt0/Cargo.toml @@ -8,5 +8,4 @@ name = "crt0" crate-type = ["staticlib"] [dependencies] -platform = { path = "../platform" } -stdio = { path = "../stdio" } +relibc = { path = "../.." } diff --git a/src/crt0/src/lib.rs b/src/crt0/src/lib.rs index 02db0186d4..fa788eebbb 100644 --- a/src/crt0/src/lib.rs +++ b/src/crt0/src/lib.rs @@ -9,8 +9,10 @@ #![feature(lang_items)] extern crate alloc; -extern crate platform; -extern crate stdio; +extern crate relibc; + +use relibc::platform; +use relibc::header::stdio; use alloc::Vec; use core::ptr; diff --git a/src/ctype/Cargo.toml b/src/ctype/Cargo.toml deleted file mode 100644 index f8f98d9295..0000000000 --- a/src/ctype/Cargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "ctype" -version = "0.1.0" -authors = ["Jeremy Soller "] -build = "build.rs" - -[build-dependencies] -cbindgen = { path = "../../cbindgen" } - -[dependencies] -platform = { path = "../platform" } diff --git a/src/ctype/build.rs b/src/ctype/build.rs deleted file mode 100644 index 9b1ee3aecb..0000000000 --- a/src/ctype/build.rs +++ /dev/null @@ -1,11 +0,0 @@ -extern crate cbindgen; - -use std::{env, fs}; - -fn main() { - let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); - fs::create_dir_all("../../target/include").expect("failed to create include directory"); - cbindgen::generate(crate_dir) - .expect("failed to generate bindings") - .write_to_file("../../target/include/ctype.h"); -} diff --git a/src/dirent/Cargo.toml b/src/dirent/Cargo.toml deleted file mode 100644 index fb799207a8..0000000000 --- a/src/dirent/Cargo.toml +++ /dev/null @@ -1,15 +0,0 @@ -[package] -name = "dirent" -version = "0.1.0" -authors = ["jD91mZM2 "] -build = "build.rs" - -[build-dependencies] -cbindgen = { path = "../../cbindgen" } - -[dependencies] -errno = { path = "../errno" } -fcntl = { path = "../fcntl" } -platform = { path = "../platform" } -stdio = { path = "../stdio" } -unistd = { path = "../unistd" } diff --git a/src/dirent/build.rs b/src/dirent/build.rs deleted file mode 100644 index 252c1648cb..0000000000 --- a/src/dirent/build.rs +++ /dev/null @@ -1,11 +0,0 @@ -extern crate cbindgen; - -use std::{env, fs}; - -fn main() { - let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); - fs::create_dir_all("../../target/include").expect("failed to create include directory"); - cbindgen::generate(crate_dir) - .expect("failed to generate bindings") - .write_to_file("../../target/include/dirent.h"); -} diff --git a/src/errno/Cargo.toml b/src/errno/Cargo.toml deleted file mode 100644 index cfaaad8465..0000000000 --- a/src/errno/Cargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "errno" -version = "0.1.0" -authors = ["Alex Lyon "] -build = "build.rs" - -[build-dependencies] -cbindgen = { path = "../../cbindgen" } - -[dependencies] -platform = { path = "../platform" } diff --git a/src/errno/build.rs b/src/errno/build.rs deleted file mode 100644 index 5de392d433..0000000000 --- a/src/errno/build.rs +++ /dev/null @@ -1,11 +0,0 @@ -extern crate cbindgen; - -use std::{env, fs}; - -fn main() { - let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); - fs::create_dir_all("../../target/include").expect("failed to create include directory"); - cbindgen::generate(crate_dir) - .expect("failed to generate bindings") - .write_to_file("../../target/include/errno.h"); -} diff --git a/src/fcntl/Cargo.toml b/src/fcntl/Cargo.toml deleted file mode 100644 index c2b0198c38..0000000000 --- a/src/fcntl/Cargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "fcntl" -version = "0.1.0" -authors = ["Jeremy Soller "] -build = "build.rs" - -[build-dependencies] -cbindgen = { path = "../../cbindgen" } - -[dependencies] -platform = { path = "../platform" } diff --git a/src/fcntl/build.rs b/src/fcntl/build.rs deleted file mode 100644 index fb1647837e..0000000000 --- a/src/fcntl/build.rs +++ /dev/null @@ -1,11 +0,0 @@ -extern crate cbindgen; - -use std::{env, fs}; - -fn main() { - let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); - fs::create_dir_all("../../target/include").expect("failed to create include directory"); - cbindgen::generate(crate_dir) - .expect("failed to generate bindings") - .write_to_file("../../target/include/fcntl.h"); -} diff --git a/src/fenv/Cargo.toml b/src/fenv/Cargo.toml deleted file mode 100644 index ed3b2142f1..0000000000 --- a/src/fenv/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "fenv" -version = "0.1.0" -authors = ["Dan Robertson "] - -[build-dependencies] -cbindgen = { path = "../../cbindgen" } - -[dependencies] -platform = { path = "../platform" } diff --git a/src/fenv/build.rs b/src/fenv/build.rs deleted file mode 100644 index a79287ee76..0000000000 --- a/src/fenv/build.rs +++ /dev/null @@ -1,11 +0,0 @@ -extern crate cbindgen; - -use std::{env, fs}; - -fn main() { - let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); - fs::create_dir_all("../../target/include").expect("failed to create include directory"); - cbindgen::generate(crate_dir) - .expect("failed to generate bindings") - .write_to_file("../../target/include/fenv.h"); -} diff --git a/src/float/Cargo.toml b/src/float/Cargo.toml deleted file mode 100644 index 3ae7acb3fe..0000000000 --- a/src/float/Cargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "float" -version = "0.1.0" -authors = ["Dan Robertson "] - -[build-dependencies] -cbindgen = { path = "../../cbindgen" } - -[dependencies] -platform = { path = "../platform" } -fenv = { path = "../fenv" } diff --git a/src/float/build.rs b/src/float/build.rs deleted file mode 100644 index e9b224fd13..0000000000 --- a/src/float/build.rs +++ /dev/null @@ -1,11 +0,0 @@ -extern crate cbindgen; - -use std::{env, fs}; - -fn main() { - let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); - fs::create_dir_all("../../target/include").expect("failed to create include directory"); - cbindgen::generate(crate_dir) - .expect("failed to generate bindings") - .write_to_file("../../target/include/float.h"); -} diff --git a/src/fnmatch/Cargo.toml b/src/fnmatch/Cargo.toml deleted file mode 100644 index 9d9a891de3..0000000000 --- a/src/fnmatch/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "fnmatch" -version = "0.1.0" -authors = ["jD91mZM2 "] - -[build-dependencies] -cbindgen = { path = "../../cbindgen" } - -[dependencies] -platform = { path = "../platform" } diff --git a/src/fnmatch/build.rs b/src/fnmatch/build.rs deleted file mode 100644 index 2b6e70c118..0000000000 --- a/src/fnmatch/build.rs +++ /dev/null @@ -1,11 +0,0 @@ -extern crate cbindgen; - -use std::{env, fs}; - -fn main() { - let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); - fs::create_dir_all("../../target/include").expect("failed to create include directory"); - cbindgen::generate(crate_dir) - .expect("failed to generate bindings") - .write_to_file("../../target/include/fnmatch.h"); -} diff --git a/src/grp/Cargo.toml b/src/grp/Cargo.toml deleted file mode 100644 index d9eb91db9e..0000000000 --- a/src/grp/Cargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "grp" -version = "0.1.0" -authors = ["Jeremy Soller "] -build = "build.rs" - -[build-dependencies] -cbindgen = { path = "../../cbindgen" } - -[dependencies] -platform = { path = "../platform" } diff --git a/src/grp/build.rs b/src/grp/build.rs deleted file mode 100644 index 196206d6c4..0000000000 --- a/src/grp/build.rs +++ /dev/null @@ -1,11 +0,0 @@ -extern crate cbindgen; - -use std::{env, fs}; - -fn main() { - let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); - fs::create_dir_all("../../target/include").expect("failed to create include directory"); - cbindgen::generate(crate_dir) - .expect("failed to generate bindings") - .write_to_file("../../target/include/grp.h"); -} diff --git a/src/template/cbindgen.toml b/src/header/_template/cbindgen.toml similarity index 100% rename from src/template/cbindgen.toml rename to src/header/_template/cbindgen.toml diff --git a/src/template/src/lib.rs b/src/header/_template/mod.rs similarity index 100% rename from src/template/src/lib.rs rename to src/header/_template/mod.rs diff --git a/src/todo/aio/lib.rs b/src/header/_todo/aio/lib.rs similarity index 100% rename from src/todo/aio/lib.rs rename to src/header/_todo/aio/lib.rs diff --git a/src/todo/oldlib/dns/answer.rs b/src/header/_todo/oldlib/dns/answer.rs similarity index 100% rename from src/todo/oldlib/dns/answer.rs rename to src/header/_todo/oldlib/dns/answer.rs diff --git a/src/todo/oldlib/dns/mod.rs b/src/header/_todo/oldlib/dns/mod.rs similarity index 100% rename from src/todo/oldlib/dns/mod.rs rename to src/header/_todo/oldlib/dns/mod.rs diff --git a/src/todo/oldlib/dns/query.rs b/src/header/_todo/oldlib/dns/query.rs similarity index 100% rename from src/todo/oldlib/dns/query.rs rename to src/header/_todo/oldlib/dns/query.rs diff --git a/src/todo/oldlib/event.rs b/src/header/_todo/oldlib/event.rs similarity index 100% rename from src/todo/oldlib/event.rs rename to src/header/_todo/oldlib/event.rs diff --git a/src/todo/oldlib/file.rs b/src/header/_todo/oldlib/file.rs similarity index 100% rename from src/todo/oldlib/file.rs rename to src/header/_todo/oldlib/file.rs diff --git a/src/todo/oldlib/folder.rs b/src/header/_todo/oldlib/folder.rs similarity index 100% rename from src/todo/oldlib/folder.rs rename to src/header/_todo/oldlib/folder.rs diff --git a/src/todo/oldlib/hostname.rs b/src/header/_todo/oldlib/hostname.rs similarity index 100% rename from src/todo/oldlib/hostname.rs rename to src/header/_todo/oldlib/hostname.rs diff --git a/src/todo/oldlib/lib.rs b/src/header/_todo/oldlib/lib.rs similarity index 100% rename from src/todo/oldlib/lib.rs rename to src/header/_todo/oldlib/lib.rs diff --git a/src/todo/oldlib/macros.rs b/src/header/_todo/oldlib/macros.rs similarity index 100% rename from src/todo/oldlib/macros.rs rename to src/header/_todo/oldlib/macros.rs diff --git a/src/todo/oldlib/mallocnull.rs b/src/header/_todo/oldlib/mallocnull.rs similarity index 100% rename from src/todo/oldlib/mallocnull.rs rename to src/header/_todo/oldlib/mallocnull.rs diff --git a/src/todo/oldlib/netdb.rs b/src/header/_todo/oldlib/netdb.rs similarity index 100% rename from src/todo/oldlib/netdb.rs rename to src/header/_todo/oldlib/netdb.rs diff --git a/src/todo/oldlib/process.rs b/src/header/_todo/oldlib/process.rs similarity index 100% rename from src/todo/oldlib/process.rs rename to src/header/_todo/oldlib/process.rs diff --git a/src/todo/oldlib/rawfile.rs b/src/header/_todo/oldlib/rawfile.rs similarity index 100% rename from src/todo/oldlib/rawfile.rs rename to src/header/_todo/oldlib/rawfile.rs diff --git a/src/todo/oldlib/redox.rs b/src/header/_todo/oldlib/redox.rs similarity index 100% rename from src/todo/oldlib/redox.rs rename to src/header/_todo/oldlib/redox.rs diff --git a/src/todo/oldlib/socket.rs b/src/header/_todo/oldlib/socket.rs similarity index 100% rename from src/todo/oldlib/socket.rs rename to src/header/_todo/oldlib/socket.rs diff --git a/src/todo/oldlib/termios.rs b/src/header/_todo/oldlib/termios.rs similarity index 100% rename from src/todo/oldlib/termios.rs rename to src/header/_todo/oldlib/termios.rs diff --git a/src/todo/oldlib/time.rs b/src/header/_todo/oldlib/time.rs similarity index 100% rename from src/todo/oldlib/time.rs rename to src/header/_todo/oldlib/time.rs diff --git a/src/todo/oldlib/types.rs b/src/header/_todo/oldlib/types.rs similarity index 100% rename from src/todo/oldlib/types.rs rename to src/header/_todo/oldlib/types.rs diff --git a/src/todo/oldlib/unimpl.rs b/src/header/_todo/oldlib/unimpl.rs similarity index 100% rename from src/todo/oldlib/unimpl.rs rename to src/header/_todo/oldlib/unimpl.rs diff --git a/src/todo/oldlib/user.rs b/src/header/_todo/oldlib/user.rs similarity index 100% rename from src/todo/oldlib/user.rs rename to src/header/_todo/oldlib/user.rs diff --git a/src/todo/pthread/lib.rs b/src/header/_todo/pthread/lib.rs similarity index 100% rename from src/todo/pthread/lib.rs rename to src/header/_todo/pthread/lib.rs diff --git a/src/todo/wctype/lib.rs b/src/header/_todo/wctype/lib.rs similarity index 100% rename from src/todo/wctype/lib.rs rename to src/header/_todo/wctype/lib.rs diff --git a/src/arpainet/cbindgen.toml b/src/header/arpa_inet/cbindgen.toml similarity index 79% rename from src/arpainet/cbindgen.toml rename to src/header/arpa_inet/cbindgen.toml index 661140fa0b..4e00706ff5 100644 --- a/src/arpainet/cbindgen.toml +++ b/src/header/arpa_inet/cbindgen.toml @@ -1,5 +1,5 @@ sys_includes = ["stddef.h", "sys/socket.h", "netinet/in.h"] -include_guard = "_ARPAINET_H" +include_guard = "_ARPA_INET_H" language = "C" style = "Tag" diff --git a/src/arpainet/src/lib.rs b/src/header/arpa_inet/mod.rs similarity index 90% rename from src/arpainet/src/lib.rs rename to src/header/arpa_inet/mod.rs index 632cb39667..8c7018127d 100644 --- a/src/arpainet/src/lib.rs +++ b/src/header/arpa_inet/mod.rs @@ -1,20 +1,12 @@ -//! arpainet implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/arpainet.h.html - -#![no_std] -#![feature(alloc)] - -#[macro_use] -extern crate alloc; - -extern crate errno; -extern crate netinet; -extern crate platform; -extern crate sys_socket; +//! arpa/inet implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/arpainet.h.html use core::str::FromStr; use core::{mem, ptr, slice, str}; -use errno::*; -use netinet::in_h::in_addr; + +use header::errno::*; +use header::netinet_in::in_addr; +use header::sys_socket; +use platform; use platform::c_str; use platform::types::*; diff --git a/src/ctype/cbindgen.toml b/src/header/ctype/cbindgen.toml similarity index 100% rename from src/ctype/cbindgen.toml rename to src/header/ctype/cbindgen.toml diff --git a/src/ctype/src/lib.rs b/src/header/ctype/mod.rs similarity index 98% rename from src/ctype/src/lib.rs rename to src/header/ctype/mod.rs index a9f602043f..f1be73a556 100644 --- a/src/ctype/src/lib.rs +++ b/src/header/ctype/mod.rs @@ -1,9 +1,6 @@ //! ctype implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/ctype.h.html -#![no_std] - -extern crate platform; - +use platform; use platform::types::*; #[no_mangle] diff --git a/src/dirent/cbindgen.toml b/src/header/dirent/cbindgen.toml similarity index 100% rename from src/dirent/cbindgen.toml rename to src/header/dirent/cbindgen.toml diff --git a/src/dirent/src/lib.rs b/src/header/dirent/mod.rs similarity index 95% rename from src/dirent/src/lib.rs rename to src/header/dirent/mod.rs index 029081c005..abdb433b06 100644 --- a/src/dirent/src/lib.rs +++ b/src/header/dirent/mod.rs @@ -1,17 +1,9 @@ //! dirent implementation following http://pubs.opengroup.org/onlinepubs/009695399/basedefs/dirent.h.html -#![no_std] -#![feature(alloc)] - -extern crate alloc; -extern crate errno; -extern crate fcntl; -extern crate platform; -extern crate stdio; -extern crate unistd; - use alloc::boxed::Box; use core::{mem, ptr}; + +use header::{errno, fcntl, stdio, unistd}; use platform::{Pal, Sys}; use platform::types::*; diff --git a/src/errno/cbindgen.toml b/src/header/errno/cbindgen.toml similarity index 100% rename from src/errno/cbindgen.toml rename to src/header/errno/cbindgen.toml diff --git a/src/errno/src/lib.rs b/src/header/errno/mod.rs similarity index 99% rename from src/errno/src/lib.rs rename to src/header/errno/mod.rs index b961059634..e39fb205e5 100644 --- a/src/errno/src/lib.rs +++ b/src/header/errno/mod.rs @@ -1,9 +1,6 @@ //! errno implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/errno.h.html -#![no_std] - -extern crate platform; - +use platform; use platform::types::*; #[no_mangle] diff --git a/src/fcntl/cbindgen.toml b/src/header/fcntl/cbindgen.toml similarity index 100% rename from src/fcntl/cbindgen.toml rename to src/header/fcntl/cbindgen.toml diff --git a/src/fcntl/src/linux.rs b/src/header/fcntl/linux.rs similarity index 100% rename from src/fcntl/src/linux.rs rename to src/header/fcntl/linux.rs diff --git a/src/fcntl/src/lib.rs b/src/header/fcntl/mod.rs similarity index 96% rename from src/fcntl/src/lib.rs rename to src/header/fcntl/mod.rs index f9c78930e9..4237e905ad 100644 --- a/src/fcntl/src/lib.rs +++ b/src/header/fcntl/mod.rs @@ -1,9 +1,6 @@ //! fcntl implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/fcntl.h.html -#![no_std] - -extern crate platform; - +use platform; use platform::{Pal, Sys}; use platform::types::*; diff --git a/src/fcntl/src/redox.rs b/src/header/fcntl/redox.rs similarity index 100% rename from src/fcntl/src/redox.rs rename to src/header/fcntl/redox.rs diff --git a/src/fenv/cbindgen.toml b/src/header/fenv/cbindgen.toml similarity index 100% rename from src/fenv/cbindgen.toml rename to src/header/fenv/cbindgen.toml diff --git a/src/fenv/src/lib.rs b/src/header/fenv/mod.rs similarity index 97% rename from src/fenv/src/lib.rs rename to src/header/fenv/mod.rs index 116293c1c0..f7c837a029 100644 --- a/src/fenv/src/lib.rs +++ b/src/header/fenv/mod.rs @@ -1,10 +1,7 @@ //! fenv.h implementation for Redox, following //! http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/fenv.h.html -#![no_std] - -extern crate platform; - +use platform; use platform::types::*; pub const FE_ALL_EXCEPT: c_int = 0; diff --git a/src/float/cbindgen.toml b/src/header/float/cbindgen.toml similarity index 100% rename from src/float/cbindgen.toml rename to src/header/float/cbindgen.toml diff --git a/src/float/src/lib.rs b/src/header/float/mod.rs similarity index 77% rename from src/float/src/lib.rs rename to src/header/float/mod.rs index 4a355c0b78..6b0c4ea6a9 100644 --- a/src/float/src/lib.rs +++ b/src/header/float/mod.rs @@ -1,12 +1,8 @@ //! float.h implementation for Redox, following //! http://pubs.opengroup.org/onlinepubs/7908799/xsh/float.h.html -#![no_std] - -extern crate fenv; -extern crate platform; - -use fenv::{fegetround, FE_TONEAREST}; +use header::fenv::{fegetround, FE_TONEAREST}; +use platform; use platform::types::*; pub const FLT_RADIX: c_int = 2; diff --git a/src/fnmatch/cbindgen.toml b/src/header/fnmatch/cbindgen.toml similarity index 100% rename from src/fnmatch/cbindgen.toml rename to src/header/fnmatch/cbindgen.toml diff --git a/src/fnmatch/src/lib.rs b/src/header/fnmatch/mod.rs similarity index 98% rename from src/fnmatch/src/lib.rs rename to src/header/fnmatch/mod.rs index ff60a80fd3..7ad988c63c 100644 --- a/src/fnmatch/src/lib.rs +++ b/src/header/fnmatch/mod.rs @@ -1,11 +1,8 @@ //! fnmatch implementation -#![no_std] -#![feature(alloc)] - -extern crate alloc; -extern crate platform; use alloc::vec::Vec; + +use platform; use platform::types::*; pub const FNM_NOMATCH: c_int = 1; diff --git a/src/grp/cbindgen.toml b/src/header/grp/cbindgen.toml similarity index 100% rename from src/grp/cbindgen.toml rename to src/header/grp/cbindgen.toml diff --git a/src/grp/src/lib.rs b/src/header/grp/mod.rs similarity index 97% rename from src/grp/src/lib.rs rename to src/header/grp/mod.rs index 1d93b1dbf4..9040e4a38c 100644 --- a/src/grp/src/lib.rs +++ b/src/header/grp/mod.rs @@ -1,9 +1,6 @@ //! grp implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/grp.h.html -#![no_std] - -extern crate platform; - +use platform; use platform::types::*; #[repr(C)] diff --git a/src/inttypes/cbindgen.toml b/src/header/inttypes/cbindgen.toml similarity index 100% rename from src/inttypes/cbindgen.toml rename to src/header/inttypes/cbindgen.toml diff --git a/src/inttypes/src/lib.rs b/src/header/inttypes/mod.rs similarity index 91% rename from src/inttypes/src/lib.rs rename to src/header/inttypes/mod.rs index c4d1ab545e..a5780290f2 100644 --- a/src/inttypes/src/lib.rs +++ b/src/header/inttypes/mod.rs @@ -1,12 +1,6 @@ -#![no_std] - -#[macro_use] -extern crate stdlib; -extern crate ctype; -extern crate errno; -extern crate platform; - -use errno::*; +use header::{ctype, stdlib}; +use header::errno::*; +use platform; use platform::types::*; #[no_mangle] diff --git a/src/locale/cbindgen.toml b/src/header/locale/cbindgen.toml similarity index 100% rename from src/locale/cbindgen.toml rename to src/header/locale/cbindgen.toml diff --git a/src/locale/src/lib.rs b/src/header/locale/mod.rs similarity index 97% rename from src/locale/src/lib.rs rename to src/header/locale/mod.rs index a9bb89d11a..d90be57da3 100644 --- a/src/locale/src/lib.rs +++ b/src/header/locale/mod.rs @@ -1,11 +1,8 @@ //! locale implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/locale.h.html -#![no_std] -#![feature(alloc)] - -extern crate platform; - use core::ptr; + +use platform; use platform::types::*; const EMPTY_PTR: *const c_char = "\0" as *const _ as *const c_char; diff --git a/src/header/mod.rs b/src/header/mod.rs new file mode 100644 index 0000000000..6f65ca7526 --- /dev/null +++ b/src/header/mod.rs @@ -0,0 +1,38 @@ +pub mod arpa_inet; +pub mod ctype; +pub mod dirent; +pub mod errno; +pub mod fcntl; +pub mod fenv; +pub mod float; +pub mod fnmatch; +pub mod grp; +pub mod inttypes; +pub mod locale; +pub mod netinet_in; +pub mod pwd; +pub mod semaphore; +pub mod sgtty; +pub mod signal; +pub mod stdio; +pub mod stdlib; +pub mod string; +pub mod strings; +pub mod sys_file; +pub mod sys_ioctl; +pub mod sys_mman; +pub mod sys_resource; +pub mod sys_select; +pub mod sys_socket; +pub mod sys_stat; +pub mod sys_time; +pub mod sys_times; +pub mod sys_un; +pub mod sys_utsname; +pub mod sys_wait; +pub mod termios; +pub mod time; +pub mod unistd; +pub mod utime; +pub mod wchar; +pub mod wctype; diff --git a/src/netinet/Cargo.toml b/src/header/netinet_in/Cargo.toml similarity index 100% rename from src/netinet/Cargo.toml rename to src/header/netinet_in/Cargo.toml diff --git a/src/netinet/in/cbindgen.toml b/src/header/netinet_in/cbindgen.toml similarity index 100% rename from src/netinet/in/cbindgen.toml rename to src/header/netinet_in/cbindgen.toml diff --git a/src/netinet/in/src/lib.rs b/src/header/netinet_in/mod.rs similarity index 93% rename from src/netinet/in/src/lib.rs rename to src/header/netinet_in/mod.rs index 2f909a3d75..7872fc99f2 100644 --- a/src/netinet/in/src/lib.rs +++ b/src/header/netinet_in/mod.rs @@ -1,12 +1,8 @@ -#![no_std] - #![allow(non_camel_case_types)] -extern crate platform; -extern crate sys_socket; - +use header::sys_socket::{self, sa_family_t, sockaddr}; +use platform; use platform::types::*; -use sys_socket::{sa_family_t, sockaddr}; pub type in_addr_t = u32; pub type in_port_t = u16; diff --git a/src/pwd/cbindgen.toml b/src/header/pwd/cbindgen.toml similarity index 100% rename from src/pwd/cbindgen.toml rename to src/header/pwd/cbindgen.toml diff --git a/src/pwd/src/lib.rs b/src/header/pwd/mod.rs similarity index 98% rename from src/pwd/src/lib.rs rename to src/header/pwd/mod.rs index db1225092f..f455e40c62 100644 --- a/src/pwd/src/lib.rs +++ b/src/header/pwd/mod.rs @@ -1,15 +1,10 @@ //! pwd implementation for relibc -#![no_std] -#![feature(alloc)] - -extern crate alloc; -extern crate errno; -extern crate fcntl; -extern crate platform; - use alloc::vec::Vec; use core::ptr; + +use header::{errno, fcntl}; +use platform; use platform::{Pal, Sys}; use platform::types::*; use platform::RawFile; diff --git a/src/semaphore/cbindgen.toml b/src/header/semaphore/cbindgen.toml similarity index 100% rename from src/semaphore/cbindgen.toml rename to src/header/semaphore/cbindgen.toml diff --git a/src/semaphore/src/lib.rs b/src/header/semaphore/mod.rs similarity index 97% rename from src/semaphore/src/lib.rs rename to src/header/semaphore/mod.rs index 0204358a37..9d3d64ad6b 100644 --- a/src/semaphore/src/lib.rs +++ b/src/header/semaphore/mod.rs @@ -1,7 +1,4 @@ -#![no_std] - -extern crate platform; - +use platform; use platform::types::*; #[repr(C)] diff --git a/src/setjmp/Cargo.toml b/src/header/setjmp/Cargo.toml similarity index 100% rename from src/setjmp/Cargo.toml rename to src/header/setjmp/Cargo.toml diff --git a/src/setjmp/src/impl/README.md b/src/header/setjmp/src/impl/README.md similarity index 100% rename from src/setjmp/src/impl/README.md rename to src/header/setjmp/src/impl/README.md diff --git a/src/setjmp/src/impl/aarch64/longjmp.s b/src/header/setjmp/src/impl/aarch64/longjmp.s similarity index 100% rename from src/setjmp/src/impl/aarch64/longjmp.s rename to src/header/setjmp/src/impl/aarch64/longjmp.s diff --git a/src/setjmp/src/impl/aarch64/setjmp.s b/src/header/setjmp/src/impl/aarch64/setjmp.s similarity index 100% rename from src/setjmp/src/impl/aarch64/setjmp.s rename to src/header/setjmp/src/impl/aarch64/setjmp.s diff --git a/src/setjmp/src/impl/arm/longjmp.s b/src/header/setjmp/src/impl/arm/longjmp.s similarity index 100% rename from src/setjmp/src/impl/arm/longjmp.s rename to src/header/setjmp/src/impl/arm/longjmp.s diff --git a/src/setjmp/src/impl/arm/setjmp.s b/src/header/setjmp/src/impl/arm/setjmp.s similarity index 100% rename from src/setjmp/src/impl/arm/setjmp.s rename to src/header/setjmp/src/impl/arm/setjmp.s diff --git a/src/setjmp/src/impl/i386/longjmp.s b/src/header/setjmp/src/impl/i386/longjmp.s similarity index 100% rename from src/setjmp/src/impl/i386/longjmp.s rename to src/header/setjmp/src/impl/i386/longjmp.s diff --git a/src/setjmp/src/impl/i386/setjmp.s b/src/header/setjmp/src/impl/i386/setjmp.s similarity index 100% rename from src/setjmp/src/impl/i386/setjmp.s rename to src/header/setjmp/src/impl/i386/setjmp.s diff --git a/src/setjmp/src/impl/m68k/longjmp.s b/src/header/setjmp/src/impl/m68k/longjmp.s similarity index 100% rename from src/setjmp/src/impl/m68k/longjmp.s rename to src/header/setjmp/src/impl/m68k/longjmp.s diff --git a/src/setjmp/src/impl/m68k/setjmp.s b/src/header/setjmp/src/impl/m68k/setjmp.s similarity index 100% rename from src/setjmp/src/impl/m68k/setjmp.s rename to src/header/setjmp/src/impl/m68k/setjmp.s diff --git a/src/setjmp/src/impl/microblaze/longjmp.s b/src/header/setjmp/src/impl/microblaze/longjmp.s similarity index 100% rename from src/setjmp/src/impl/microblaze/longjmp.s rename to src/header/setjmp/src/impl/microblaze/longjmp.s diff --git a/src/setjmp/src/impl/microblaze/setjmp.s b/src/header/setjmp/src/impl/microblaze/setjmp.s similarity index 100% rename from src/setjmp/src/impl/microblaze/setjmp.s rename to src/header/setjmp/src/impl/microblaze/setjmp.s diff --git a/src/setjmp/src/impl/mips/longjmp.S b/src/header/setjmp/src/impl/mips/longjmp.S similarity index 100% rename from src/setjmp/src/impl/mips/longjmp.S rename to src/header/setjmp/src/impl/mips/longjmp.S diff --git a/src/setjmp/src/impl/mips/setjmp.S b/src/header/setjmp/src/impl/mips/setjmp.S similarity index 100% rename from src/setjmp/src/impl/mips/setjmp.S rename to src/header/setjmp/src/impl/mips/setjmp.S diff --git a/src/setjmp/src/impl/mips64/longjmp.S b/src/header/setjmp/src/impl/mips64/longjmp.S similarity index 100% rename from src/setjmp/src/impl/mips64/longjmp.S rename to src/header/setjmp/src/impl/mips64/longjmp.S diff --git a/src/setjmp/src/impl/mips64/setjmp.S b/src/header/setjmp/src/impl/mips64/setjmp.S similarity index 100% rename from src/setjmp/src/impl/mips64/setjmp.S rename to src/header/setjmp/src/impl/mips64/setjmp.S diff --git a/src/setjmp/src/impl/mipsn32/longjmp.S b/src/header/setjmp/src/impl/mipsn32/longjmp.S similarity index 100% rename from src/setjmp/src/impl/mipsn32/longjmp.S rename to src/header/setjmp/src/impl/mipsn32/longjmp.S diff --git a/src/setjmp/src/impl/mipsn32/setjmp.S b/src/header/setjmp/src/impl/mipsn32/setjmp.S similarity index 100% rename from src/setjmp/src/impl/mipsn32/setjmp.S rename to src/header/setjmp/src/impl/mipsn32/setjmp.S diff --git a/src/setjmp/src/impl/or1k/longjmp.s b/src/header/setjmp/src/impl/or1k/longjmp.s similarity index 100% rename from src/setjmp/src/impl/or1k/longjmp.s rename to src/header/setjmp/src/impl/or1k/longjmp.s diff --git a/src/setjmp/src/impl/or1k/setjmp.s b/src/header/setjmp/src/impl/or1k/setjmp.s similarity index 100% rename from src/setjmp/src/impl/or1k/setjmp.s rename to src/header/setjmp/src/impl/or1k/setjmp.s diff --git a/src/setjmp/src/impl/powerpc/longjmp.S b/src/header/setjmp/src/impl/powerpc/longjmp.S similarity index 100% rename from src/setjmp/src/impl/powerpc/longjmp.S rename to src/header/setjmp/src/impl/powerpc/longjmp.S diff --git a/src/setjmp/src/impl/powerpc/setjmp.S b/src/header/setjmp/src/impl/powerpc/setjmp.S similarity index 100% rename from src/setjmp/src/impl/powerpc/setjmp.S rename to src/header/setjmp/src/impl/powerpc/setjmp.S diff --git a/src/setjmp/src/impl/powerpc64/longjmp.s b/src/header/setjmp/src/impl/powerpc64/longjmp.s similarity index 100% rename from src/setjmp/src/impl/powerpc64/longjmp.s rename to src/header/setjmp/src/impl/powerpc64/longjmp.s diff --git a/src/setjmp/src/impl/powerpc64/setjmp.s b/src/header/setjmp/src/impl/powerpc64/setjmp.s similarity index 100% rename from src/setjmp/src/impl/powerpc64/setjmp.s rename to src/header/setjmp/src/impl/powerpc64/setjmp.s diff --git a/src/setjmp/src/impl/s390x/longjmp.s b/src/header/setjmp/src/impl/s390x/longjmp.s similarity index 100% rename from src/setjmp/src/impl/s390x/longjmp.s rename to src/header/setjmp/src/impl/s390x/longjmp.s diff --git a/src/setjmp/src/impl/s390x/setjmp.s b/src/header/setjmp/src/impl/s390x/setjmp.s similarity index 100% rename from src/setjmp/src/impl/s390x/setjmp.s rename to src/header/setjmp/src/impl/s390x/setjmp.s diff --git a/src/setjmp/src/impl/sh/longjmp.S b/src/header/setjmp/src/impl/sh/longjmp.S similarity index 100% rename from src/setjmp/src/impl/sh/longjmp.S rename to src/header/setjmp/src/impl/sh/longjmp.S diff --git a/src/setjmp/src/impl/sh/setjmp.S b/src/header/setjmp/src/impl/sh/setjmp.S similarity index 100% rename from src/setjmp/src/impl/sh/setjmp.S rename to src/header/setjmp/src/impl/sh/setjmp.S diff --git a/src/setjmp/src/impl/x32/longjmp.s b/src/header/setjmp/src/impl/x32/longjmp.s similarity index 100% rename from src/setjmp/src/impl/x32/longjmp.s rename to src/header/setjmp/src/impl/x32/longjmp.s diff --git a/src/setjmp/src/impl/x32/setjmp.s b/src/header/setjmp/src/impl/x32/setjmp.s similarity index 100% rename from src/setjmp/src/impl/x32/setjmp.s rename to src/header/setjmp/src/impl/x32/setjmp.s diff --git a/src/setjmp/src/impl/x86_64/longjmp.s b/src/header/setjmp/src/impl/x86_64/longjmp.s similarity index 100% rename from src/setjmp/src/impl/x86_64/longjmp.s rename to src/header/setjmp/src/impl/x86_64/longjmp.s diff --git a/src/setjmp/src/impl/x86_64/setjmp.s b/src/header/setjmp/src/impl/x86_64/setjmp.s similarity index 100% rename from src/setjmp/src/impl/x86_64/setjmp.s rename to src/header/setjmp/src/impl/x86_64/setjmp.s diff --git a/src/setjmp/src/lib.rs b/src/header/setjmp/src/lib.rs similarity index 100% rename from src/setjmp/src/lib.rs rename to src/header/setjmp/src/lib.rs diff --git a/src/sgtty/cbindgen.toml b/src/header/sgtty/cbindgen.toml similarity index 100% rename from src/sgtty/cbindgen.toml rename to src/header/sgtty/cbindgen.toml diff --git a/src/sgtty/src/lib.rs b/src/header/sgtty/mod.rs similarity index 80% rename from src/sgtty/src/lib.rs rename to src/header/sgtty/mod.rs index eece192334..c8950c506b 100644 --- a/src/sgtty/src/lib.rs +++ b/src/header/sgtty/mod.rs @@ -1,12 +1,10 @@ //! sgtty implementation that won't work on redox because no ioctl -#![no_std] - -extern crate platform; -extern crate sys_ioctl; use core::fmt::Write; + +use platform; use platform::types::*; -use sys_ioctl::*; +use header::sys_ioctl::*; #[no_mangle] pub extern "C" fn gtty(fd: c_int, out: *mut sgttyb) -> c_int { diff --git a/src/signal/cbindgen.toml b/src/header/signal/cbindgen.toml similarity index 100% rename from src/signal/cbindgen.toml rename to src/header/signal/cbindgen.toml diff --git a/src/signal/src/linux.rs b/src/header/signal/linux.rs similarity index 100% rename from src/signal/src/linux.rs rename to src/header/signal/linux.rs diff --git a/src/signal/src/lib.rs b/src/header/signal/mod.rs similarity index 98% rename from src/signal/src/lib.rs rename to src/header/signal/mod.rs index eeff480dfc..c37e81e456 100644 --- a/src/signal/src/lib.rs +++ b/src/header/signal/mod.rs @@ -1,11 +1,5 @@ //! signal implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/signal.h.html -#![no_std] -#![feature(asm, const_fn, core_intrinsics, global_asm)] - -extern crate errno; -extern crate platform; - #[cfg(target_os = "linux")] #[path = "linux.rs"] pub mod sys; @@ -17,6 +11,9 @@ pub mod sys; pub use sys::*; use core::{mem, ptr}; + +use header::errno; +use platform; use platform::{PalSignal, Sys}; use platform::types::*; diff --git a/src/signal/src/redox.rs b/src/header/signal/redox.rs similarity index 100% rename from src/signal/src/redox.rs rename to src/header/signal/redox.rs diff --git a/src/stdio/cbindgen.toml b/src/header/stdio/cbindgen.toml similarity index 100% rename from src/stdio/cbindgen.toml rename to src/header/stdio/cbindgen.toml diff --git a/src/stdio/src/constants.rs b/src/header/stdio/constants.rs similarity index 100% rename from src/stdio/src/constants.rs rename to src/header/stdio/constants.rs diff --git a/src/stdio/src/default.rs b/src/header/stdio/default.rs similarity index 100% rename from src/stdio/src/default.rs rename to src/header/stdio/default.rs diff --git a/src/stdio/src/helpers.rs b/src/header/stdio/helpers.rs similarity index 100% rename from src/stdio/src/helpers.rs rename to src/header/stdio/helpers.rs diff --git a/src/stdio/src/internal.rs b/src/header/stdio/internal.rs similarity index 100% rename from src/stdio/src/internal.rs rename to src/header/stdio/internal.rs diff --git a/src/stdio/src/lib.rs b/src/header/stdio/mod.rs similarity index 98% rename from src/stdio/src/lib.rs rename to src/header/stdio/mod.rs index 8790159170..77b879f5c2 100644 --- a/src/stdio/src/lib.rs +++ b/src/header/stdio/mod.rs @@ -1,31 +1,18 @@ //! stdio implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/stdio.h.html -#![no_std] -// For Vec -#![feature(alloc)] -#![feature(const_fn)] - -#[macro_use] -extern crate alloc; -extern crate errno; -extern crate fcntl; -#[macro_use] -extern crate lazy_static; -extern crate platform; -extern crate string; -extern crate va_list as vl; - +use alloc::vec::Vec; use core::fmt::Write as WriteFmt; use core::fmt::{self, Error}; use core::sync::atomic::{AtomicBool, Ordering}; use core::{ptr, str}; +use va_list::VaList as va_list; -use alloc::vec::Vec; -use errno::STR_ERROR; +use header::errno::{self, STR_ERROR}; +use header::{fcntl, string}; +use platform; use platform::{Pal, Sys}; use platform::types::*; use platform::{c_str, errno, Read, Write}; -use vl::VaList as va_list; mod printf; mod scanf; diff --git a/src/stdio/src/printf.rs b/src/header/stdio/printf.rs similarity index 100% rename from src/stdio/src/printf.rs rename to src/header/stdio/printf.rs diff --git a/src/stdio/src/scanf.rs b/src/header/stdio/scanf.rs similarity index 100% rename from src/stdio/src/scanf.rs rename to src/header/stdio/scanf.rs diff --git a/src/stdlib/cbindgen.toml b/src/header/stdlib/cbindgen.toml similarity index 100% rename from src/stdlib/cbindgen.toml rename to src/header/stdlib/cbindgen.toml diff --git a/src/stdlib/src/lib.rs b/src/header/stdlib/mod.rs similarity index 98% rename from src/stdlib/src/lib.rs rename to src/header/stdlib/mod.rs index e166f4ce8d..c64612d368 100644 --- a/src/stdlib/src/lib.rs +++ b/src/header/stdlib/mod.rs @@ -1,28 +1,17 @@ //! stdlib implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/stdlib.h.html -#![no_std] -#![feature(core_intrinsics)] - -extern crate ctype; -extern crate errno; -extern crate fcntl; -extern crate platform; -extern crate rand; -extern crate string; -extern crate time; -extern crate unistd; -extern crate wchar; - use core::{iter, mem, ptr, slice, str}; use rand::distributions::Alphanumeric; use rand::prng::XorShiftRng; use rand::rngs::JitterRng; use rand::{Rng, SeedableRng}; -use string::*; -use wchar::*; -use errno::*; -use fcntl::*; +use header::{ctype, time, unistd, wchar}; +use header::errno::*; +use header::fcntl::*; +use header::string::*; +use header::wchar::*; +use platform; use platform::{Pal, Sys}; use platform::types::*; diff --git a/src/stdlib/src/sort.rs b/src/header/stdlib/sort.rs similarity index 100% rename from src/stdlib/src/sort.rs rename to src/header/stdlib/sort.rs diff --git a/src/string/cbindgen.toml b/src/header/string/cbindgen.toml similarity index 100% rename from src/string/cbindgen.toml rename to src/header/string/cbindgen.toml diff --git a/src/string/src/lib.rs b/src/header/string/mod.rs similarity index 99% rename from src/string/src/lib.rs rename to src/header/string/mod.rs index 7960febbce..6f506f05d3 100644 --- a/src/string/src/lib.rs +++ b/src/header/string/mod.rs @@ -1,15 +1,13 @@ //! string implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/string.h.html -#![no_std] - -extern crate errno; -extern crate platform; -extern crate signal; use core::cmp; use core::mem; use core::ptr; use core::usize; -use errno::*; + +use header::signal; +use header::errno::*; +use platform; use platform::types::*; #[no_mangle] diff --git a/src/strings/cbindgen.toml b/src/header/strings/cbindgen.toml similarity index 100% rename from src/strings/cbindgen.toml rename to src/header/strings/cbindgen.toml diff --git a/src/strings/src/lib.rs b/src/header/strings/mod.rs similarity index 97% rename from src/strings/src/lib.rs rename to src/header/strings/mod.rs index 5737face26..a20501bc49 100644 --- a/src/strings/src/lib.rs +++ b/src/header/strings/mod.rs @@ -1,12 +1,9 @@ //! strings implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/strings.h.html -#![no_std] -#![feature(alloc)] - -extern crate alloc; -extern crate platform; use alloc::Vec; use core::ptr; + +use platform; use platform::types::*; #[no_mangle] diff --git a/src/sys_file/cbindgen.toml b/src/header/sys_file/cbindgen.toml similarity index 100% rename from src/sys_file/cbindgen.toml rename to src/header/sys_file/cbindgen.toml diff --git a/src/sys_file/src/lib.rs b/src/header/sys_file/mod.rs similarity index 91% rename from src/sys_file/src/lib.rs rename to src/header/sys_file/mod.rs index a12bcc2a0b..098dddc1b4 100644 --- a/src/sys_file/src/lib.rs +++ b/src/header/sys_file/mod.rs @@ -1,9 +1,6 @@ //! sys/file.h implementation -#![no_std] - -extern crate platform; - +use platform; use platform::types::*; pub const LOCK_SH: usize = 1; diff --git a/src/sys_ioctl/cbindgen.toml b/src/header/sys_ioctl/cbindgen.toml similarity index 100% rename from src/sys_ioctl/cbindgen.toml rename to src/header/sys_ioctl/cbindgen.toml diff --git a/src/sys_ioctl/src/lib.rs b/src/header/sys_ioctl/mod.rs similarity index 99% rename from src/sys_ioctl/src/lib.rs rename to src/header/sys_ioctl/mod.rs index 6c155363b4..f6c1e44d32 100644 --- a/src/sys_ioctl/src/lib.rs +++ b/src/header/sys_ioctl/mod.rs @@ -1,9 +1,6 @@ //! ioctl implementation for linux -#![no_std] - -extern crate platform; - +use platform; use platform::{Pal, Sys}; use platform::types::*; diff --git a/src/sys_mman/cbindgen.toml b/src/header/sys_mman/cbindgen.toml similarity index 100% rename from src/sys_mman/cbindgen.toml rename to src/header/sys_mman/cbindgen.toml diff --git a/src/sys_mman/src/linux.rs b/src/header/sys_mman/linux.rs similarity index 100% rename from src/sys_mman/src/linux.rs rename to src/header/sys_mman/linux.rs diff --git a/src/sys_mman/src/lib.rs b/src/header/sys_mman/mod.rs similarity index 97% rename from src/sys_mman/src/lib.rs rename to src/header/sys_mman/mod.rs index cbe789d043..e346a2f6e4 100644 --- a/src/sys_mman/src/lib.rs +++ b/src/header/sys_mman/mod.rs @@ -1,7 +1,4 @@ -#![no_std] - -extern crate platform; - +use platform; use platform::{Pal, Sys}; use platform::types::*; diff --git a/src/sys_mman/src/redox.rs b/src/header/sys_mman/redox.rs similarity index 100% rename from src/sys_mman/src/redox.rs rename to src/header/sys_mman/redox.rs diff --git a/src/sys_resource/cbindgen.toml b/src/header/sys_resource/cbindgen.toml similarity index 100% rename from src/sys_resource/cbindgen.toml rename to src/header/sys_resource/cbindgen.toml diff --git a/src/sys_resource/src/lib.rs b/src/header/sys_resource/mod.rs similarity index 94% rename from src/sys_resource/src/lib.rs rename to src/header/sys_resource/mod.rs index 584dfaa7a8..1b8dae9258 100644 --- a/src/sys_resource/src/lib.rs +++ b/src/header/sys_resource/mod.rs @@ -1,14 +1,10 @@ //! sys/resource.h implementation for Redox, following //! http://pubs.opengroup.org/onlinepubs/7908799/xsh/sysresource.h.html -#![no_std] - -extern crate platform; -extern crate sys_time; - +use header::sys_time::timeval; +use platform; use platform::{Pal, Sys}; use platform::types::*; -use sys_time::timeval; // Exported in bits file const RUSAGE_SELF: c_int = 0; diff --git a/src/sys_select/cbindgen.toml b/src/header/sys_select/cbindgen.toml similarity index 100% rename from src/sys_select/cbindgen.toml rename to src/header/sys_select/cbindgen.toml diff --git a/src/sys_select/src/lib.rs b/src/header/sys_select/mod.rs similarity index 92% rename from src/sys_select/src/lib.rs rename to src/header/sys_select/mod.rs index 0c67e3406b..e1ad11c760 100644 --- a/src/sys_select/src/lib.rs +++ b/src/header/sys_select/mod.rs @@ -1,9 +1,8 @@ //! sys/select.h implementation -#![no_std] - -extern crate platform; use core::mem; + +use platform; use platform::{Pal, Sys}; use platform::types::*; diff --git a/src/sys_socket/cbindgen.toml b/src/header/sys_socket/cbindgen.toml similarity index 100% rename from src/sys_socket/cbindgen.toml rename to src/header/sys_socket/cbindgen.toml diff --git a/src/sys_socket/src/constants.rs b/src/header/sys_socket/constants.rs similarity index 100% rename from src/sys_socket/src/constants.rs rename to src/header/sys_socket/constants.rs diff --git a/src/sys_socket/src/lib.rs b/src/header/sys_socket/mod.rs similarity index 98% rename from src/sys_socket/src/lib.rs rename to src/header/sys_socket/mod.rs index 4990133c4e..1d5fe32409 100644 --- a/src/sys_socket/src/lib.rs +++ b/src/header/sys_socket/mod.rs @@ -1,11 +1,8 @@ //! socket implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xns/syssocket.h.html -#![no_std] -#![allow(non_camel_case_types)] - -extern crate platform; - use core::ptr; + +use platform; use platform::{PalSocket, Sys}; use platform::types::*; diff --git a/src/sys_stat/cbindgen.toml b/src/header/sys_stat/cbindgen.toml similarity index 100% rename from src/sys_stat/cbindgen.toml rename to src/header/sys_stat/cbindgen.toml diff --git a/src/sys_stat/src/lib.rs b/src/header/sys_stat/mod.rs similarity index 97% rename from src/sys_stat/src/lib.rs rename to src/header/sys_stat/mod.rs index 81fb68623f..3e393d570f 100644 --- a/src/sys_stat/src/lib.rs +++ b/src/header/sys_stat/mod.rs @@ -1,11 +1,7 @@ //! stat implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/sysstat.h.html -#![no_std] - -extern crate fcntl; -extern crate platform; - -use fcntl::{O_PATH, O_NOFOLLOW}; +use header::fcntl::{O_PATH, O_NOFOLLOW}; +use platform; use platform::{Pal, Sys}; use platform::types::*; diff --git a/src/sys_time/cbindgen.toml b/src/header/sys_time/cbindgen.toml similarity index 100% rename from src/sys_time/cbindgen.toml rename to src/header/sys_time/cbindgen.toml diff --git a/src/sys_time/src/lib.rs b/src/header/sys_time/mod.rs similarity index 98% rename from src/sys_time/src/lib.rs rename to src/header/sys_time/mod.rs index dc1dfddb79..163f9c01fb 100644 --- a/src/sys_time/src/lib.rs +++ b/src/header/sys_time/mod.rs @@ -1,9 +1,6 @@ //! sys/time implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/systime.h.html -#![no_std] - -extern crate platform; - +use platform; use platform::{Pal, Sys}; use platform::types::*; diff --git a/src/sys_times/cbindgen.toml b/src/header/sys_times/cbindgen.toml similarity index 100% rename from src/sys_times/cbindgen.toml rename to src/header/sys_times/cbindgen.toml diff --git a/src/sys_times/src/lib.rs b/src/header/sys_times/mod.rs similarity index 90% rename from src/sys_times/src/lib.rs rename to src/header/sys_times/mod.rs index 713fa6f18c..57d149da53 100644 --- a/src/sys_times/src/lib.rs +++ b/src/header/sys_times/mod.rs @@ -1,9 +1,6 @@ //! sys/times.h implementation -#![no_std] - -extern crate platform; - +use platform; use platform::{Pal, Sys}; use platform::types::*; diff --git a/src/sys_un/cbindgen.toml b/src/header/sys_un/cbindgen.toml similarity index 100% rename from src/sys_un/cbindgen.toml rename to src/header/sys_un/cbindgen.toml diff --git a/src/sys_un/src/lib.rs b/src/header/sys_un/mod.rs similarity index 63% rename from src/sys_un/src/lib.rs rename to src/header/sys_un/mod.rs index 19a75443a4..744e686c1d 100644 --- a/src/sys_un/src/lib.rs +++ b/src/header/sys_un/mod.rs @@ -1,10 +1,8 @@ #![no_std] -extern crate platform; -extern crate sys_socket; - +use header::sys_socket::sa_family_t; +use platform; use platform::types::*; -use sys_socket::sa_family_t; #[repr(C)] pub struct sockaddr_un { diff --git a/src/sys_utsname/cbindgen.toml b/src/header/sys_utsname/cbindgen.toml similarity index 100% rename from src/sys_utsname/cbindgen.toml rename to src/header/sys_utsname/cbindgen.toml diff --git a/src/sys_utsname/src/lib.rs b/src/header/sys_utsname/mod.rs similarity index 86% rename from src/sys_utsname/src/lib.rs rename to src/header/sys_utsname/mod.rs index 0bb394d52f..a20924b598 100644 --- a/src/sys_utsname/src/lib.rs +++ b/src/header/sys_utsname/mod.rs @@ -1,13 +1,10 @@ //! sys/utsname implementation for linux, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/sysutsname.h.html -#![no_std] - #[cfg(target_os = "linux")] mod inner { - extern crate platform; - - use self::platform::{Pal, Sys}; - use self::platform::types::*; + use platform; + use platform::{Pal, Sys}; + use platform::types::*; const UTSLENGTH: usize = 65; diff --git a/src/sys_wait/cbindgen.toml b/src/header/sys_wait/cbindgen.toml similarity index 100% rename from src/sys_wait/cbindgen.toml rename to src/header/sys_wait/cbindgen.toml diff --git a/src/sys_wait/src/lib.rs b/src/header/sys_wait/mod.rs similarity index 92% rename from src/sys_wait/src/lib.rs rename to src/header/sys_wait/mod.rs index f0f4655dd4..8f83468d62 100644 --- a/src/sys_wait/src/lib.rs +++ b/src/header/sys_wait/mod.rs @@ -1,14 +1,10 @@ //! sys/wait.h implementation for Redox, following //! http://pubs.opengroup.org/onlinepubs/7908799/xsh/syswait.h.html -#![no_std] - -extern crate platform; -extern crate sys_resource; - +use header::sys_resource::rusage; +use platform; use platform::{Pal, Sys}; use platform::types::*; -use sys_resource::rusage; pub const WNOHANG: c_int = 1; pub const WUNTRACED: c_int = 2; diff --git a/src/termios/cbindgen.toml b/src/header/termios/cbindgen.toml similarity index 100% rename from src/termios/cbindgen.toml rename to src/header/termios/cbindgen.toml diff --git a/src/termios/src/lib.rs b/src/header/termios/mod.rs similarity index 99% rename from src/termios/src/lib.rs rename to src/header/termios/mod.rs index b0001158d8..fe8988f340 100644 --- a/src/termios/src/lib.rs +++ b/src/header/termios/mod.rs @@ -1,8 +1,6 @@ //! termios implementation, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/termios.h.html -#![no_std] - -extern crate platform; +use platform; use platform::{Pal, Sys}; use platform::types::*; diff --git a/src/time/cbindgen.toml b/src/header/time/cbindgen.toml similarity index 100% rename from src/time/cbindgen.toml rename to src/header/time/cbindgen.toml diff --git a/src/time/src/constants.rs b/src/header/time/constants.rs similarity index 100% rename from src/time/src/constants.rs rename to src/header/time/constants.rs diff --git a/src/time/src/helpers.rs b/src/header/time/helpers.rs similarity index 100% rename from src/time/src/helpers.rs rename to src/header/time/helpers.rs diff --git a/src/time/src/linux.rs b/src/header/time/linux.rs similarity index 100% rename from src/time/src/linux.rs rename to src/header/time/linux.rs diff --git a/src/time/src/lib.rs b/src/header/time/mod.rs similarity index 98% rename from src/time/src/lib.rs rename to src/header/time/mod.rs index 75aae5ffd1..09ba1e1617 100644 --- a/src/time/src/lib.rs +++ b/src/header/time/mod.rs @@ -1,23 +1,20 @@ //! time implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/time.h.html -#![no_std] -#![feature(alloc, const_fn)] +use core::mem::transmute; -extern crate alloc; -extern crate errno; -extern crate platform; +use header::errno; +use header::errno::EIO; +use platform; +use platform::{Pal, Sys}; +use platform::types::*; + +use constants::*; +use helpers::*; pub mod constants; mod helpers; mod strftime; -use constants::*; -use core::mem::transmute; -use errno::EIO; -use helpers::*; -use platform::{Pal, Sys}; -use platform::types::*; - #[repr(C)] pub struct timespec { pub tv_sec: time_t, diff --git a/src/time/src/redox.rs b/src/header/time/redox.rs similarity index 100% rename from src/time/src/redox.rs rename to src/header/time/redox.rs diff --git a/src/time/src/strftime.rs b/src/header/time/strftime.rs similarity index 100% rename from src/time/src/strftime.rs rename to src/header/time/strftime.rs diff --git a/src/unistd/src/brk.rs b/src/header/unistd/brk.rs similarity index 100% rename from src/unistd/src/brk.rs rename to src/header/unistd/brk.rs diff --git a/src/unistd/cbindgen.toml b/src/header/unistd/cbindgen.toml similarity index 100% rename from src/unistd/cbindgen.toml rename to src/header/unistd/cbindgen.toml diff --git a/src/unistd/src/getopt.rs b/src/header/unistd/getopt.rs similarity index 100% rename from src/unistd/src/getopt.rs rename to src/header/unistd/getopt.rs diff --git a/src/unistd/src/lib.rs b/src/header/unistd/mod.rs similarity index 98% rename from src/unistd/src/lib.rs rename to src/header/unistd/mod.rs index aef969838c..7765abd7f6 100644 --- a/src/unistd/src/lib.rs +++ b/src/header/unistd/mod.rs @@ -1,15 +1,9 @@ //! unistd implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/unistd.h.html -#![no_std] - -extern crate errno; -extern crate platform; -extern crate stdio; -extern crate string; -extern crate sys_time; - use core::{ptr, slice}; +use header::{errno, stdio, string, sys_time}; +use platform; use platform::{Pal, Sys}; use platform::types::*; diff --git a/src/unistd/src/pathconf.rs b/src/header/unistd/pathconf.rs similarity index 100% rename from src/unistd/src/pathconf.rs rename to src/header/unistd/pathconf.rs diff --git a/src/utime/cbindgen.toml b/src/header/utime/cbindgen.toml similarity index 100% rename from src/utime/cbindgen.toml rename to src/header/utime/cbindgen.toml diff --git a/src/utime/src/lib.rs b/src/header/utime/mod.rs similarity index 94% rename from src/utime/src/lib.rs rename to src/header/utime/mod.rs index 16ad0348f7..01dedc0ece 100644 --- a/src/utime/src/lib.rs +++ b/src/header/utime/mod.rs @@ -1,9 +1,6 @@ //! utime implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/utime.h.html -#![no_std] - -extern crate platform; - +use platform; use platform::{Pal, Sys}; use platform::types::*; diff --git a/src/wchar/cbindgen.toml b/src/header/wchar/cbindgen.toml similarity index 100% rename from src/wchar/cbindgen.toml rename to src/header/wchar/cbindgen.toml diff --git a/src/wchar/src/lib.rs b/src/header/wchar/mod.rs similarity index 98% rename from src/wchar/src/lib.rs rename to src/header/wchar/mod.rs index fdeb25becf..bcdbd58cb2 100644 --- a/src/wchar/src/lib.rs +++ b/src/header/wchar/mod.rs @@ -1,19 +1,13 @@ //! wchar implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/wchar.h.html -#![no_std] -#![feature(str_internals)] - -extern crate errno; -extern crate platform; -extern crate stdio; -extern crate time; -extern crate va_list as vl; - use core::ptr; +use va_list::VaList as va_list; + +use header::errno; +use header::stdio::*; +use header::time::*; +use platform; use platform::types::*; -use stdio::*; -use time::*; -use vl::VaList as va_list; mod utf8; diff --git a/src/wchar/src/utf8.rs b/src/header/wchar/utf8.rs similarity index 97% rename from src/wchar/src/utf8.rs rename to src/header/wchar/utf8.rs index d9a23380ff..f3ef32dd66 100644 --- a/src/wchar/src/utf8.rs +++ b/src/header/wchar/utf8.rs @@ -1,13 +1,14 @@ //UTF implementation parts for wchar.h. //Partially ported from the Sortix libc -extern crate errno; -extern crate platform; - use core::{char, slice, str, usize}; -use mbstate_t; + +use header::errno; +use platform; use platform::types::*; +use mbstate_t; + //It's guaranteed that we don't have any nullpointers here pub unsafe fn mbrtowc(pwc: *mut wchar_t, s: *const c_char, n: usize, ps: *mut mbstate_t) -> usize { let mut size = str::utf8_char_width(*s as u8); diff --git a/src/wctype/cbindgen.toml b/src/header/wctype/cbindgen.toml similarity index 100% rename from src/wctype/cbindgen.toml rename to src/header/wctype/cbindgen.toml diff --git a/src/wctype/src/lib.rs b/src/header/wctype/mod.rs similarity index 97% rename from src/wctype/src/lib.rs rename to src/header/wctype/mod.rs index fc6e4b9cb0..80d49c3e66 100644 --- a/src/wctype/src/lib.rs +++ b/src/header/wctype/mod.rs @@ -1,9 +1,6 @@ //! wctype implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/wctype.h.html -#![no_std] - -extern crate platform; - +use platform; use platform::types::*; // #[no_mangle] diff --git a/src/inttypes/Cargo.toml b/src/inttypes/Cargo.toml deleted file mode 100644 index 68a991073e..0000000000 --- a/src/inttypes/Cargo.toml +++ /dev/null @@ -1,14 +0,0 @@ -[package] -name = "inttypes" -version = "0.1.0" -authors = ["jD91mZM2 "] -build = "build.rs" - -[build-dependencies] -cbindgen = { path = "../../cbindgen" } - -[dependencies] -ctype = { path = "../ctype" } -errno = { path = "../errno" } -platform = { path = "../platform" } -stdlib = { path = "../stdlib" } diff --git a/src/inttypes/build.rs b/src/inttypes/build.rs deleted file mode 100644 index 483201ff82..0000000000 --- a/src/inttypes/build.rs +++ /dev/null @@ -1,11 +0,0 @@ -extern crate cbindgen; - -use std::{env, fs}; - -fn main() { - let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); - fs::create_dir_all("../../target/include").expect("failed to create include directory"); - cbindgen::generate(crate_dir) - .expect("failed to generate bindings") - .write_to_file("../../target/include/inttypes.h"); -} diff --git a/src/lib.rs b/src/lib.rs index 37cc9ea0c8..866cc2db26 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,47 +1,33 @@ #![no_std] +#![allow(non_camel_case_types)] +#![feature(alloc)] +#![feature(allocator_api)] +#![feature(const_vec_new)] +#![feature(global_asm)] #![feature(lang_items)] #![feature(linkage)] #![feature(panic_implementation)] +#![feature(thread_local)] -//extern crate compiler_builtins; -extern crate platform; +#[macro_use] +extern crate alloc; +#[macro_use] +extern crate lazy_static; +extern crate rand; +extern crate va_list; -pub extern crate arpainet; -pub extern crate ctype; -pub extern crate dirent; -pub extern crate errno; -pub extern crate fcntl; -pub extern crate fenv; -pub extern crate float; -pub extern crate fnmatch; -pub extern crate grp; -pub extern crate locale; -pub extern crate netinet; -pub extern crate pwd; -pub extern crate semaphore; -pub extern crate setjmp; -pub extern crate signal; -pub extern crate stdio; -pub extern crate stdlib; -pub extern crate string; -pub extern crate strings; -pub extern crate sys_ioctl; -pub extern crate sys_mman; -pub extern crate sys_resource; -pub extern crate sys_select; -pub extern crate sys_socket; -pub extern crate sys_stat; -pub extern crate sys_time; -pub extern crate sys_times; -pub extern crate sys_un; -pub extern crate sys_utsname; -pub extern crate sys_wait; -pub extern crate termios; -pub extern crate time; -pub extern crate unistd; -pub extern crate utime; -pub extern crate wchar; -pub extern crate wctype; +#[cfg(target_os = "linux")] +#[macro_use] +extern crate sc; + +#[cfg(target_os = "redox")] +extern crate syscall; + +#[cfg(target_os = "redox")] +extern crate spin; + +pub mod header; +pub mod platform; use platform::{Pal, Sys}; diff --git a/src/locale/Cargo.toml b/src/locale/Cargo.toml deleted file mode 100644 index 1840ba8f90..0000000000 --- a/src/locale/Cargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "locale" -version = "0.1.0" -authors = ["Jeremy Soller "] -build = "build.rs" - -[build-dependencies] -cbindgen = { path = "../../cbindgen" } - -[dependencies] -platform = { path = "../platform" } diff --git a/src/locale/build.rs b/src/locale/build.rs deleted file mode 100644 index 60404ed885..0000000000 --- a/src/locale/build.rs +++ /dev/null @@ -1,11 +0,0 @@ -extern crate cbindgen; - -use std::{env, fs}; - -fn main() { - let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); - fs::create_dir_all("../../target/include").expect("failed to create include directory"); - cbindgen::generate(crate_dir) - .expect("failed to generate bindings") - .write_to_file("../../target/include/locale.h"); -} diff --git a/src/netinet/in/Cargo.toml b/src/netinet/in/Cargo.toml deleted file mode 100644 index b6f5356c0b..0000000000 --- a/src/netinet/in/Cargo.toml +++ /dev/null @@ -1,12 +0,0 @@ -[package] -name = "in_h" -version = "0.1.0" -authors = ["Dan Robertson "] -build = "build.rs" - -[build-dependencies] -cbindgen = { path = "../../../cbindgen" } - -[dependencies] -platform = { path = "../../platform" } -sys_socket = { path = "../../sys_socket" } diff --git a/src/netinet/in/build.rs b/src/netinet/in/build.rs deleted file mode 100644 index f9df3f1a78..0000000000 --- a/src/netinet/in/build.rs +++ /dev/null @@ -1,12 +0,0 @@ -extern crate cbindgen; - -use std::{env, fs}; - -fn main() { - let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); - fs::create_dir_all("../../../target/include").expect("failed to create include directory"); - fs::create_dir_all("../../../target/include/netinet").expect("failed to create include directory"); - cbindgen::generate(crate_dir) - .expect("failed to generate bindings") - .write_to_file("../../../target/include/netinet/in.h"); -} diff --git a/src/netinet/src/lib.rs b/src/netinet/src/lib.rs deleted file mode 100644 index 86a0d5a081..0000000000 --- a/src/netinet/src/lib.rs +++ /dev/null @@ -1,3 +0,0 @@ -#![no_std] - -pub extern crate in_h; diff --git a/src/platform/Cargo.toml b/src/platform/Cargo.toml deleted file mode 100644 index 7a313fea47..0000000000 --- a/src/platform/Cargo.toml +++ /dev/null @@ -1,16 +0,0 @@ -[package] -name = "platform" -version = "0.1.0" -authors = ["Jeremy Soller "] - -[dependencies.ralloc] -path = "../../ralloc" -default-features = false -optional = true - -[target.'cfg(target_os = "linux")'.dependencies] -sc = "0.2" - -[target.'cfg(target_os = "redox")'.dependencies] -redox_syscall = { git = "https://gitlab.redox-os.org/redox-os/syscall.git", branch = "relibc" } -spin = "0.4" diff --git a/src/platform/src/allocator/dlmalloc.rs b/src/platform/allocator/dlmalloc.rs similarity index 100% rename from src/platform/src/allocator/dlmalloc.rs rename to src/platform/allocator/dlmalloc.rs diff --git a/src/platform/src/allocator/ralloc.rs b/src/platform/allocator/ralloc.rs similarity index 100% rename from src/platform/src/allocator/ralloc.rs rename to src/platform/allocator/ralloc.rs diff --git a/src/platform/src/linux/mod.rs b/src/platform/linux/mod.rs similarity index 100% rename from src/platform/src/linux/mod.rs rename to src/platform/linux/mod.rs diff --git a/src/platform/src/linux/signal.rs b/src/platform/linux/signal.rs similarity index 100% rename from src/platform/src/linux/signal.rs rename to src/platform/linux/signal.rs diff --git a/src/platform/src/linux/socket.rs b/src/platform/linux/socket.rs similarity index 100% rename from src/platform/src/linux/socket.rs rename to src/platform/linux/socket.rs diff --git a/src/platform/src/lib.rs b/src/platform/mod.rs similarity index 94% rename from src/platform/src/lib.rs rename to src/platform/mod.rs index bed373141c..918c19f59a 100644 --- a/src/platform/src/lib.rs +++ b/src/platform/mod.rs @@ -1,21 +1,3 @@ -#![no_std] -#![allow(non_camel_case_types)] -#![feature(alloc, allocator_api, const_vec_new)] -#![cfg_attr(target_os = "redox", feature(thread_local))] - -#[cfg_attr(target_os = "redox", macro_use)] -extern crate alloc; - -#[cfg(target_os = "linux")] -#[macro_use] -extern crate sc; - -#[cfg(target_os = "redox")] -extern crate syscall; - -#[cfg(target_os = "redox")] -extern crate spin; - pub use allocator::*; #[cfg(not(feature = "ralloc"))] diff --git a/src/platform/src/pal/mod.rs b/src/platform/pal/mod.rs similarity index 100% rename from src/platform/src/pal/mod.rs rename to src/platform/pal/mod.rs diff --git a/src/platform/src/pal/signal.rs b/src/platform/pal/signal.rs similarity index 100% rename from src/platform/src/pal/signal.rs rename to src/platform/pal/signal.rs diff --git a/src/platform/src/pal/socket.rs b/src/platform/pal/socket.rs similarity index 100% rename from src/platform/src/pal/socket.rs rename to src/platform/pal/socket.rs diff --git a/src/platform/src/rawfile.rs b/src/platform/rawfile.rs similarity index 100% rename from src/platform/src/rawfile.rs rename to src/platform/rawfile.rs diff --git a/src/platform/src/redox/mod.rs b/src/platform/redox/mod.rs similarity index 100% rename from src/platform/src/redox/mod.rs rename to src/platform/redox/mod.rs diff --git a/src/platform/src/redox/signal.rs b/src/platform/redox/signal.rs similarity index 100% rename from src/platform/src/redox/signal.rs rename to src/platform/redox/signal.rs diff --git a/src/platform/src/redox/socket.rs b/src/platform/redox/socket.rs similarity index 100% rename from src/platform/src/redox/socket.rs rename to src/platform/redox/socket.rs diff --git a/src/platform/src/types.rs b/src/platform/types.rs similarity index 100% rename from src/platform/src/types.rs rename to src/platform/types.rs diff --git a/src/pwd/Cargo.toml b/src/pwd/Cargo.toml deleted file mode 100644 index 6273ec82ed..0000000000 --- a/src/pwd/Cargo.toml +++ /dev/null @@ -1,12 +0,0 @@ -[package] -name = "pwd" -version = "0.1.0" -authors = ["jD91mZM2 "] - -[build-dependencies] -cbindgen = { path = "../../cbindgen" } - -[dependencies] -errno = { path = "../errno" } -fcntl = { path = "../fcntl" } -platform = { path = "../platform" } diff --git a/src/pwd/build.rs b/src/pwd/build.rs deleted file mode 100644 index 52d329c6ee..0000000000 --- a/src/pwd/build.rs +++ /dev/null @@ -1,11 +0,0 @@ -extern crate cbindgen; - -use std::{env, fs}; - -fn main() { - let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); - fs::create_dir_all("../../target/include").expect("failed to create include directory"); - cbindgen::generate(crate_dir) - .expect("failed to generate bindings") - .write_to_file("../../target/include/pwd.h"); -} diff --git a/src/semaphore/Cargo.toml b/src/semaphore/Cargo.toml deleted file mode 100644 index a4e0960d99..0000000000 --- a/src/semaphore/Cargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "semaphore" -version = "0.1.0" -authors = ["Jeremy Soller "] -build = "build.rs" - -[build-dependencies] -cbindgen = { path = "../../cbindgen" } - -[dependencies] -platform = { path = "../platform" } diff --git a/src/semaphore/build.rs b/src/semaphore/build.rs deleted file mode 100644 index a5eba23b85..0000000000 --- a/src/semaphore/build.rs +++ /dev/null @@ -1,11 +0,0 @@ -extern crate cbindgen; - -use std::{env, fs}; - -fn main() { - let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); - fs::create_dir_all("../../target/include").expect("failed to create include directory"); - cbindgen::generate(crate_dir) - .expect("failed to generate bindings") - .write_to_file("../../target/include/semaphore.h"); -} diff --git a/src/sgtty/Cargo.toml b/src/sgtty/Cargo.toml deleted file mode 100644 index d26f1d54ff..0000000000 --- a/src/sgtty/Cargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "sgtty" -version = "0.1.0" -authors = ["jD91mZM2 "] - -[build-dependencies] -cbindgen = { path = "../../cbindgen" } - -[dependencies] -platform = { path = "../platform" } -sys_ioctl = { path = "../sys_ioctl" } diff --git a/src/sgtty/build.rs b/src/sgtty/build.rs deleted file mode 100644 index 7357fa95fb..0000000000 --- a/src/sgtty/build.rs +++ /dev/null @@ -1,11 +0,0 @@ -extern crate cbindgen; - -use std::{env, fs}; - -fn main() { - let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); - fs::create_dir_all("../../target/include").expect("failed to create include directory"); - cbindgen::generate(crate_dir) - .expect("failed to generate bindings") - .write_to_file("../../target/include/sgtty.h"); -} diff --git a/src/signal/Cargo.toml b/src/signal/Cargo.toml deleted file mode 100644 index c2a3bc9388..0000000000 --- a/src/signal/Cargo.toml +++ /dev/null @@ -1,12 +0,0 @@ -[package] -name = "signal" -version = "0.1.0" -authors = ["Dan Robertson "] -build = "build.rs" - -[build-dependencies] -cbindgen = { path = "../../cbindgen" } - -[dependencies] -errno = { path = "../errno" } -platform = { path = "../platform" } diff --git a/src/signal/build.rs b/src/signal/build.rs deleted file mode 100644 index 011ccd1588..0000000000 --- a/src/signal/build.rs +++ /dev/null @@ -1,11 +0,0 @@ -extern crate cbindgen; - -use std::{env, fs}; - -fn main() { - let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); - fs::create_dir_all("../../target/include").expect("failed to create include directory"); - cbindgen::generate(crate_dir) - .expect("failed to generate bindings") - .write_to_file("../../target/include/signal.h"); -} diff --git a/src/stdio/Cargo.toml b/src/stdio/Cargo.toml deleted file mode 100644 index 9931ddd6fd..0000000000 --- a/src/stdio/Cargo.toml +++ /dev/null @@ -1,16 +0,0 @@ -[package] -name = "stdio" -version = "0.1.0" -authors = ["Jeremy Soller "] -build = "build.rs" - -[build-dependencies] -cbindgen = { path = "../../cbindgen" } - -[dependencies] -errno = { path = "../errno"} -fcntl = { path = "../fcntl" } -lazy_static = { version = "*", features = ["nightly", "spin_no_std"] } -platform = { path = "../platform" } -string = { path = "../string" } -va_list = { path = "../../va_list", features = ["no_std"] } diff --git a/src/stdio/build.rs b/src/stdio/build.rs deleted file mode 100644 index 1689fbc565..0000000000 --- a/src/stdio/build.rs +++ /dev/null @@ -1,11 +0,0 @@ -extern crate cbindgen; - -use std::{env, fs}; - -fn main() { - let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); - fs::create_dir_all("../../target/include").expect("failed to create include directory"); - cbindgen::generate(crate_dir) - .expect("failed to generate bindings") - .write_to_file("../../target/include/stdio.h"); -} diff --git a/src/stdlib/Cargo.toml b/src/stdlib/Cargo.toml deleted file mode 100644 index 61b603425d..0000000000 --- a/src/stdlib/Cargo.toml +++ /dev/null @@ -1,19 +0,0 @@ -[package] -name = "stdlib" -version = "0.1.0" -authors = ["Jeremy Soller "] -build = "build.rs" - -[build-dependencies] -cbindgen = { path = "../../cbindgen" } - -[dependencies] -platform = { path = "../platform" } -ctype = { path = "../ctype" } -errno = { path = "../errno" } -rand = { version = "0.5.2", default-features = false } -string = { path = "../string" } -time = { path = "../time" } -unistd = { path = "../unistd" } -wchar = { path = "../wchar" } -fcntl = { path = "../fcntl" } diff --git a/src/stdlib/build.rs b/src/stdlib/build.rs deleted file mode 100644 index 44430ddae6..0000000000 --- a/src/stdlib/build.rs +++ /dev/null @@ -1,11 +0,0 @@ -extern crate cbindgen; - -use std::{env, fs}; - -fn main() { - let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); - fs::create_dir_all("../../target/include").expect("failed to create include directory"); - cbindgen::generate(crate_dir) - .expect("failed to generate bindings") - .write_to_file("../../target/include/stdlib.h"); -} diff --git a/src/string/Cargo.toml b/src/string/Cargo.toml deleted file mode 100644 index 69a3f03d74..0000000000 --- a/src/string/Cargo.toml +++ /dev/null @@ -1,13 +0,0 @@ -[package] -name = "string" -version = "0.1.0" -authors = ["Jeremy Soller "] -build = "build.rs" - -[build-dependencies] -cbindgen = { path = "../../cbindgen" } - -[dependencies] -errno = { path = "../errno" } -platform = { path = "../platform" } -signal = { path = "../signal" } diff --git a/src/string/build.rs b/src/string/build.rs deleted file mode 100644 index ce8ad27c5e..0000000000 --- a/src/string/build.rs +++ /dev/null @@ -1,11 +0,0 @@ -extern crate cbindgen; - -use std::{env, fs}; - -fn main() { - let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); - fs::create_dir_all("../../target/include").expect("failed to create include directory"); - cbindgen::generate(crate_dir) - .expect("failed to generate bindings") - .write_to_file("../../target/include/string.h"); -} diff --git a/src/strings/Cargo.toml b/src/strings/Cargo.toml deleted file mode 100644 index 24e75867a8..0000000000 --- a/src/strings/Cargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "strings" -version = "0.1.0" -authors = ["jD91mZM2 "] -build = "build.rs" - -[build-dependencies] -cbindgen = { path = "../../cbindgen" } - -[dependencies] -platform = { path = "../platform" } diff --git a/src/strings/build.rs b/src/strings/build.rs deleted file mode 100644 index 574237034f..0000000000 --- a/src/strings/build.rs +++ /dev/null @@ -1,11 +0,0 @@ -extern crate cbindgen; - -use std::{env, fs}; - -fn main() { - let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); - fs::create_dir_all("../../target/include").expect("failed to create include directory"); - cbindgen::generate(crate_dir) - .expect("failed to generate bindings") - .write_to_file("../../target/include/strings.h"); -} diff --git a/src/sys_file/Cargo.toml b/src/sys_file/Cargo.toml deleted file mode 100644 index 1853666e93..0000000000 --- a/src/sys_file/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "sys_file" -version = "0.1.0" -authors = ["jD91mZM2 "] - -[build-dependencies] -cbindgen = { path = "../../cbindgen" } - -[dependencies] -platform = { path = "../platform" } diff --git a/src/sys_file/build.rs b/src/sys_file/build.rs deleted file mode 100644 index 1009eaeebb..0000000000 --- a/src/sys_file/build.rs +++ /dev/null @@ -1,11 +0,0 @@ -extern crate cbindgen; - -use std::{env, fs}; - -fn main() { - let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); - fs::create_dir_all("../../target/include").expect("failed to create include directory"); - cbindgen::generate(crate_dir) - .expect("failed to generate bindings") - .write_to_file("../../target/include/sys/file.h"); -} diff --git a/src/sys_ioctl/Cargo.toml b/src/sys_ioctl/Cargo.toml deleted file mode 100644 index 6f868b8c34..0000000000 --- a/src/sys_ioctl/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "sys_ioctl" -version = "0.1.0" -authors = ["jD91mZM2 "] - -[build-dependencies] -cbindgen = { path = "../../cbindgen" } - -[dependencies] -platform = { path = "../platform" } diff --git a/src/sys_ioctl/build.rs b/src/sys_ioctl/build.rs deleted file mode 100644 index e82221d0b3..0000000000 --- a/src/sys_ioctl/build.rs +++ /dev/null @@ -1,11 +0,0 @@ -extern crate cbindgen; - -use std::{env, fs}; - -fn main() { - let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); - fs::create_dir_all("../../target/include").expect("failed to create include directory"); - cbindgen::generate(crate_dir) - .expect("failed to generate bindings") - .write_to_file("../../target/include/sys/ioctl.h"); -} diff --git a/src/sys_mman/Cargo.toml b/src/sys_mman/Cargo.toml deleted file mode 100644 index 4f7c08b1e4..0000000000 --- a/src/sys_mman/Cargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "sys_mman" -version = "0.1.0" -authors = ["Jeremy Soller "] -build = "build.rs" - -[build-dependencies] -cbindgen = { path = "../../cbindgen" } - -[dependencies] -platform = { path = "../platform" } diff --git a/src/sys_mman/build.rs b/src/sys_mman/build.rs deleted file mode 100644 index 19d21bd491..0000000000 --- a/src/sys_mman/build.rs +++ /dev/null @@ -1,11 +0,0 @@ -extern crate cbindgen; - -use std::{env, fs}; - -fn main() { - let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); - fs::create_dir_all("../../target/include").expect("failed to create include directory"); - cbindgen::generate(crate_dir) - .expect("failed to generate bindings") - .write_to_file("../../target/include/sys/mman.h"); -} diff --git a/src/sys_resource/Cargo.toml b/src/sys_resource/Cargo.toml deleted file mode 100644 index a1bea8424e..0000000000 --- a/src/sys_resource/Cargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "sys_resource" -version = "0.1.0" -authors = ["Dan Robertson "] - -[build-dependencies] -cbindgen = { path = "../../cbindgen" } - -[dependencies] -platform = { path = "../platform" } -sys_time = { path = "../sys_time" } diff --git a/src/sys_resource/build.rs b/src/sys_resource/build.rs deleted file mode 100644 index a8c03a627e..0000000000 --- a/src/sys_resource/build.rs +++ /dev/null @@ -1,11 +0,0 @@ -extern crate cbindgen; - -use std::{env, fs}; - -fn main() { - let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); - fs::create_dir_all("../../target/include").expect("failed to create include directory"); - cbindgen::generate(crate_dir) - .expect("failed to generate bindings") - .write_to_file("../../target/include/sys/resource.h"); -} diff --git a/src/sys_select/Cargo.toml b/src/sys_select/Cargo.toml deleted file mode 100644 index 09d7dcae7c..0000000000 --- a/src/sys_select/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "sys_select" -version = "0.1.0" -authors = ["jD91mZM2 "] - -[build-dependencies] -cbindgen = { path = "../../cbindgen" } - -[dependencies] -platform = { path = "../platform" } diff --git a/src/sys_select/build.rs b/src/sys_select/build.rs deleted file mode 100644 index 5314b67db9..0000000000 --- a/src/sys_select/build.rs +++ /dev/null @@ -1,11 +0,0 @@ -extern crate cbindgen; - -use std::{env, fs}; - -fn main() { - let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); - fs::create_dir_all("../../target/include").expect("failed to create include directory"); - cbindgen::generate(crate_dir) - .expect("failed to generate bindings") - .write_to_file("../../target/include/sys/select.h"); -} diff --git a/src/sys_socket/Cargo.toml b/src/sys_socket/Cargo.toml deleted file mode 100644 index 0c3cc667e1..0000000000 --- a/src/sys_socket/Cargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "sys_socket" -version = "0.1.0" -authors = ["Dan Robertson "] -build = "build.rs" - -[build-dependencies] -cbindgen = { path = "../../cbindgen" } - -[dependencies] -platform = { path = "../platform" } diff --git a/src/sys_socket/build.rs b/src/sys_socket/build.rs deleted file mode 100644 index ad891ecb68..0000000000 --- a/src/sys_socket/build.rs +++ /dev/null @@ -1,11 +0,0 @@ -extern crate cbindgen; - -use std::{env, fs}; - -fn main() { - let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); - fs::create_dir_all("../../target/include").expect("failed to create include directory"); - cbindgen::generate(crate_dir) - .expect("failed to generate bindings") - .write_to_file("../../target/include/sys/socket.h"); -} diff --git a/src/sys_stat/Cargo.toml b/src/sys_stat/Cargo.toml deleted file mode 100644 index 23e1253120..0000000000 --- a/src/sys_stat/Cargo.toml +++ /dev/null @@ -1,12 +0,0 @@ -[package] -name = "sys_stat" -version = "0.1.0" -authors = ["Jeremy Soller "] -build = "build.rs" - -[build-dependencies] -cbindgen = { path = "../../cbindgen" } - -[dependencies] -fcntl = { path = "../fcntl" } -platform = { path = "../platform" } diff --git a/src/sys_stat/build.rs b/src/sys_stat/build.rs deleted file mode 100644 index 0d79f3cce8..0000000000 --- a/src/sys_stat/build.rs +++ /dev/null @@ -1,11 +0,0 @@ -extern crate cbindgen; - -use std::{env, fs}; - -fn main() { - let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); - fs::create_dir_all("../../target/include").expect("failed to create include directory"); - cbindgen::generate(crate_dir) - .expect("failed to generate bindings") - .write_to_file("../../target/include/sys/stat.h"); -} diff --git a/src/sys_time/Cargo.toml b/src/sys_time/Cargo.toml deleted file mode 100644 index 20b3ac9c6f..0000000000 --- a/src/sys_time/Cargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "sys_time" -version = "0.1.0" -authors = ["Jeremy Soller "] -build = "build.rs" - -[build-dependencies] -cbindgen = { path = "../../cbindgen" } - -[dependencies] -platform = { path = "../platform" } diff --git a/src/sys_time/build.rs b/src/sys_time/build.rs deleted file mode 100644 index 9d087ef9c1..0000000000 --- a/src/sys_time/build.rs +++ /dev/null @@ -1,11 +0,0 @@ -extern crate cbindgen; - -use std::{env, fs}; - -fn main() { - let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); - fs::create_dir_all("../../target/include").expect("failed to create include directory"); - cbindgen::generate(crate_dir) - .expect("failed to generate bindings") - .write_to_file("../../target/include/sys/time.h"); -} diff --git a/src/sys_times/Cargo.toml b/src/sys_times/Cargo.toml deleted file mode 100644 index 31f1646396..0000000000 --- a/src/sys_times/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "sys_times" -version = "0.1.0" -authors = ["jD91mZM2 "] - -[build-dependencies] -cbindgen = { path = "../../cbindgen" } - -[dependencies] -platform = { path = "../platform" } diff --git a/src/sys_times/build.rs b/src/sys_times/build.rs deleted file mode 100644 index d93c16000a..0000000000 --- a/src/sys_times/build.rs +++ /dev/null @@ -1,11 +0,0 @@ -extern crate cbindgen; - -use std::{env, fs}; - -fn main() { - let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); - fs::create_dir_all("../../target/include").expect("failed to create include directory"); - cbindgen::generate(crate_dir) - .expect("failed to generate bindings") - .write_to_file("../../target/include/sys/times.h"); -} diff --git a/src/sys_un/Cargo.toml b/src/sys_un/Cargo.toml deleted file mode 100644 index be0e821f65..0000000000 --- a/src/sys_un/Cargo.toml +++ /dev/null @@ -1,12 +0,0 @@ -[package] -name = "sys_un" -version = "0.1.0" -authors = ["jD91mZM2 "] -build = "build.rs" - -[build-dependencies] -cbindgen = { path = "../../cbindgen" } - -[dependencies] -platform = { path = "../platform" } -sys_socket = { path = "../sys_socket" } diff --git a/src/sys_un/build.rs b/src/sys_un/build.rs deleted file mode 100644 index fcf990a9ff..0000000000 --- a/src/sys_un/build.rs +++ /dev/null @@ -1,11 +0,0 @@ -extern crate cbindgen; - -use std::{env, fs}; - -fn main() { - let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); - fs::create_dir_all("../../target/include").expect("failed to create include directory"); - cbindgen::generate(crate_dir) - .expect("failed to generate bindings") - .write_to_file("../../target/include/sys/un.h"); -} diff --git a/src/sys_utsname/Cargo.toml b/src/sys_utsname/Cargo.toml deleted file mode 100644 index 69edfcfea9..0000000000 --- a/src/sys_utsname/Cargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "sys_utsname" -version = "0.1.0" -authors = ["jD91mZM2 "] -build = "build.rs" - -[build-dependencies] -cbindgen = { path = "../../cbindgen" } - -[target.'cfg(target_os = "linux")'.dependencies] -platform = { path = "../platform" } diff --git a/src/sys_utsname/build.rs b/src/sys_utsname/build.rs deleted file mode 100644 index 2f45974eee..0000000000 --- a/src/sys_utsname/build.rs +++ /dev/null @@ -1,11 +0,0 @@ -extern crate cbindgen; - -use std::{env, fs}; - -fn main() { - let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); - fs::create_dir_all("../../target/include").expect("failed to create include directory"); - cbindgen::generate(crate_dir) - .expect("failed to generate bindings") - .write_to_file("../../target/include/sys/utsname.h"); -} diff --git a/src/sys_wait/Cargo.toml b/src/sys_wait/Cargo.toml deleted file mode 100644 index 44250ca7f7..0000000000 --- a/src/sys_wait/Cargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "sys_wait" -version = "0.1.0" -authors = ["Dan Robertson "] - -[build-dependencies] -cbindgen = { path = "../../cbindgen" } - -[dependencies] -platform = { path = "../platform" } -sys_resource = { path = "../sys_resource" } diff --git a/src/sys_wait/build.rs b/src/sys_wait/build.rs deleted file mode 100644 index 53a786af45..0000000000 --- a/src/sys_wait/build.rs +++ /dev/null @@ -1,11 +0,0 @@ -extern crate cbindgen; - -use std::{env, fs}; - -fn main() { - let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); - fs::create_dir_all("../../target/include").expect("failed to create include directory"); - cbindgen::generate(crate_dir) - .expect("failed to generate bindings") - .write_to_file("../../target/include/sys/wait.h"); -} diff --git a/src/template/Cargo.toml b/src/template/Cargo.toml deleted file mode 100644 index 844bcb55eb..0000000000 --- a/src/template/Cargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "template" -version = "0.1.0" -authors = ["Jeremy Soller "] -build = "build.rs" - -[build-dependencies] -cbindgen = { path = "../../cbindgen" } - -[dependencies] -platform = { path = "../platform" } diff --git a/src/template/build.rs b/src/template/build.rs deleted file mode 100644 index 35b5d3bd87..0000000000 --- a/src/template/build.rs +++ /dev/null @@ -1,11 +0,0 @@ -extern crate cbindgen; - -use std::{env, fs}; - -fn main() { - let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); - fs::create_dir_all("../../target/include").expect("failed to create include directory"); - cbindgen::generate(crate_dir) - .expect("failed to generate bindings") - .write_to_file("../../target/include/template.h"); -} diff --git a/src/termios/Cargo.toml b/src/termios/Cargo.toml deleted file mode 100644 index 4fa692f2ff..0000000000 --- a/src/termios/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "termios" -version = "0.1.0" -authors = ["jD91mZM2 "] - -[build-dependencies] -cbindgen = { path = "../../cbindgen" } - -[dependencies] -platform = { path = "../platform" } diff --git a/src/termios/build.rs b/src/termios/build.rs deleted file mode 100644 index da15d4a9b4..0000000000 --- a/src/termios/build.rs +++ /dev/null @@ -1,11 +0,0 @@ -extern crate cbindgen; - -use std::{env, fs}; - -fn main() { - let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); - fs::create_dir_all("../../target/include").expect("failed to create include directory"); - cbindgen::generate(crate_dir) - .expect("failed to generate bindings") - .write_to_file("../../target/include/termios.h"); -} diff --git a/src/time/Cargo.toml b/src/time/Cargo.toml deleted file mode 100644 index 1521354550..0000000000 --- a/src/time/Cargo.toml +++ /dev/null @@ -1,12 +0,0 @@ -[package] -name = "time" -version = "0.1.0" -authors = ["Jeremy Soller "] -build = "build.rs" - -[build-dependencies] -cbindgen = { path = "../../cbindgen" } - -[dependencies] -platform = { path = "../platform" } -errno = { path = "../errno" } diff --git a/src/time/build.rs b/src/time/build.rs deleted file mode 100644 index 7bc136af55..0000000000 --- a/src/time/build.rs +++ /dev/null @@ -1,11 +0,0 @@ -extern crate cbindgen; - -use std::{env, fs}; - -fn main() { - let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); - fs::create_dir_all("../../target/include").expect("failed to create include directory"); - cbindgen::generate(crate_dir) - .expect("failed to generate bindings") - .write_to_file("../../target/include/time.h"); -} diff --git a/src/unistd/Cargo.toml b/src/unistd/Cargo.toml deleted file mode 100644 index 138a8209f9..0000000000 --- a/src/unistd/Cargo.toml +++ /dev/null @@ -1,15 +0,0 @@ -[package] -name = "unistd" -version = "0.1.0" -authors = ["Jeremy Soller "] -build = "build.rs" - -[build-dependencies] -cbindgen = { path = "../../cbindgen" } - -[dependencies] -errno = { path = "../errno" } -platform = { path = "../platform" } -stdio = { path = "../stdio" } -string = { path = "../string" } -sys_time = { path = "../sys_time" } diff --git a/src/unistd/build.rs b/src/unistd/build.rs deleted file mode 100644 index ca19204932..0000000000 --- a/src/unistd/build.rs +++ /dev/null @@ -1,11 +0,0 @@ -extern crate cbindgen; - -use std::{env, fs}; - -fn main() { - let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); - fs::create_dir_all("../../target/include").expect("failed to create include directory"); - cbindgen::generate(crate_dir) - .expect("failed to generate bindings") - .write_to_file("../../target/include/unistd.h"); -} diff --git a/src/utime/Cargo.toml b/src/utime/Cargo.toml deleted file mode 100644 index 81bcd75cb3..0000000000 --- a/src/utime/Cargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "utime" -version = "0.1.0" -authors = ["Jeremy Soller "] -build = "build.rs" - -[build-dependencies] -cbindgen = { path = "../../cbindgen" } - -[dependencies] -platform = { path = "../platform" } diff --git a/src/utime/build.rs b/src/utime/build.rs deleted file mode 100644 index eb7b3b921b..0000000000 --- a/src/utime/build.rs +++ /dev/null @@ -1,11 +0,0 @@ -extern crate cbindgen; - -use std::{env, fs}; - -fn main() { - let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); - fs::create_dir_all("../../target/include").expect("failed to create include directory"); - cbindgen::generate(crate_dir) - .expect("failed to generate bindings") - .write_to_file("../../target/include/utime.h"); -} diff --git a/src/wchar/Cargo.toml b/src/wchar/Cargo.toml deleted file mode 100644 index 97e412f20d..0000000000 --- a/src/wchar/Cargo.toml +++ /dev/null @@ -1,18 +0,0 @@ -[package] -name = "wchar" -version = "0.1.0" -authors = ["Stephan Vedder "] -build = "build.rs" - -[build-dependencies] -cbindgen = { path = "../../cbindgen" } - -[features] -str_internals = [] - -[dependencies] -platform = { path = "../platform" } -stdio = { path = "../stdio" } -errno = { path = "../errno" } -time = { path = "../time" } -va_list = { path = "../../va_list", features = ["no_std"] } \ No newline at end of file diff --git a/src/wchar/build.rs b/src/wchar/build.rs deleted file mode 100644 index 5b64a17833..0000000000 --- a/src/wchar/build.rs +++ /dev/null @@ -1,11 +0,0 @@ -extern crate cbindgen; - -use std::{env, fs}; - -fn main() { - let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); - fs::create_dir_all("../../target/include").expect("failed to create include directory"); - cbindgen::generate(crate_dir) - .expect("failed to generate bindings") - .write_to_file("../../target/include/wchar.h"); -} diff --git a/src/wctype/Cargo.toml b/src/wctype/Cargo.toml deleted file mode 100644 index abb1ba562f..0000000000 --- a/src/wctype/Cargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "wctype" -version = "0.1.0" -authors = ["Dan Robertson "] -build = "build.rs" - -[build-dependencies] -cbindgen = { path = "../../cbindgen" } - -[dependencies] -platform = { path = "../platform" } diff --git a/src/wctype/build.rs b/src/wctype/build.rs deleted file mode 100644 index d0b0702cea..0000000000 --- a/src/wctype/build.rs +++ /dev/null @@ -1,11 +0,0 @@ -extern crate cbindgen; - -use std::{env, fs}; - -fn main() { - let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); - fs::create_dir_all("../../target/include").expect("failed to create include directory"); - cbindgen::generate(crate_dir) - .expect("failed to generate bindings") - .write_to_file("../../target/include/wctype.h"); -} From 277b9abcd5e3a9618ab2fd7436527e478b2e31b3 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sun, 26 Aug 2018 08:56:02 -0600 Subject: [PATCH 08/19] Fix build, mostly --- build.rs | 30 ++++---- src/header/_template/mod.rs | 4 - src/header/dirent/mod.rs | 1 + src/header/fcntl/mod.rs | 2 +- src/header/inttypes/mod.rs | 3 +- src/header/signal/mod.rs | 18 ++--- src/header/stdio/helpers.rs | 13 ++-- src/header/stdio/mod.rs | 4 +- src/header/stdio/printf.rs | 2 +- src/header/stdio/scanf.rs | 2 +- src/header/stdlib/mod.rs | 115 +---------------------------- src/header/sys_file/mod.rs | 4 +- src/header/sys_ioctl/mod.rs | 4 +- src/header/sys_mman/mod.rs | 2 +- src/header/sys_socket/mod.rs | 2 +- src/header/sys_utsname/mod.rs | 2 +- src/header/time/constants.rs | 7 +- src/header/time/helpers.rs | 3 +- src/header/time/mod.rs | 4 +- src/header/time/strftime.rs | 8 +- src/header/unistd/brk.rs | 2 +- src/header/unistd/getopt.rs | 3 +- src/header/unistd/mod.rs | 6 +- src/header/wchar/utf8.rs | 2 +- src/lib.rs | 11 ++- src/macros.rs | 103 ++++++++++++++++++++++++++ src/platform/allocator/dlmalloc.rs | 2 +- src/platform/linux/mod.rs | 6 +- src/platform/linux/signal.rs | 4 +- src/platform/linux/socket.rs | 4 +- src/platform/mod.rs | 23 +++--- src/platform/pal/mod.rs | 2 +- src/platform/pal/signal.rs | 4 +- src/platform/pal/socket.rs | 4 +- src/platform/rawfile.rs | 2 +- src/platform/redox/mod.rs | 4 +- src/platform/redox/signal.rs | 4 +- src/platform/redox/socket.rs | 4 +- 38 files changed, 210 insertions(+), 210 deletions(-) create mode 100644 src/macros.rs diff --git a/build.rs b/build.rs index 345db4fc47..8f61a6d4b2 100644 --- a/build.rs +++ b/build.rs @@ -1,22 +1,22 @@ extern crate cc; -// use std::env; +use std::env; fn main() { - // let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); - // - // cc::Build::new() - // .flag("-nostdinc") - // .flag("-nostdlib") - // .flag("-I") - // .flag(&format!("{}/include", crate_dir)) - // .flag("-fno-stack-protector") - // .file("src/c/dlmalloc.c") - // .file("src/c/fcntl.c") - // .file("src/c/stack_chk.c") - // .file("src/c/stdio.c") - // .file("src/c/unistd.c") - // .compile("relibc_c"); + let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); + + cc::Build::new() + .flag("-nostdinc") + .flag("-nostdlib") + .flag("-I") + .flag(&format!("{}/include", crate_dir)) + .flag("-fno-stack-protector") + .file("src/c/dlmalloc.c") + .file("src/c/fcntl.c") + .file("src/c/stack_chk.c") + .file("src/c/stdio.c") + .file("src/c/unistd.c") + .compile("relibc_c"); println!("cargo:rustc-link-lib=static=relibc_c"); } diff --git a/src/header/_template/mod.rs b/src/header/_template/mod.rs index e0c83c7cef..ed73313a1d 100644 --- a/src/header/_template/mod.rs +++ b/src/header/_template/mod.rs @@ -1,9 +1,5 @@ //! template implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/template.h.html -#![no_std] - -extern crate platform; - use platform::types::*; /* diff --git a/src/header/dirent/mod.rs b/src/header/dirent/mod.rs index abdb433b06..0083e5f39d 100644 --- a/src/header/dirent/mod.rs +++ b/src/header/dirent/mod.rs @@ -4,6 +4,7 @@ use alloc::boxed::Box; use core::{mem, ptr}; use header::{errno, fcntl, stdio, unistd}; +use platform; use platform::{Pal, Sys}; use platform::types::*; diff --git a/src/header/fcntl/mod.rs b/src/header/fcntl/mod.rs index 4237e905ad..2aadfaa4cc 100644 --- a/src/header/fcntl/mod.rs +++ b/src/header/fcntl/mod.rs @@ -4,7 +4,7 @@ use platform; use platform::{Pal, Sys}; use platform::types::*; -pub use sys::*; +pub use self::sys::*; #[cfg(target_os = "linux")] #[path = "linux.rs"] diff --git a/src/header/inttypes/mod.rs b/src/header/inttypes/mod.rs index a5780290f2..8a433ad2e7 100644 --- a/src/header/inttypes/mod.rs +++ b/src/header/inttypes/mod.rs @@ -1,5 +1,6 @@ use header::{ctype, stdlib}; use header::errno::*; +use header::stdlib::*; use platform; use platform::types::*; @@ -29,7 +30,6 @@ pub unsafe extern "C" fn strtoimax( endptr: *mut *mut c_char, base: c_int, ) -> intmax_t { - use stdlib::*; strto_impl!( intmax_t, false, @@ -47,7 +47,6 @@ pub unsafe extern "C" fn strtoumax( endptr: *mut *mut c_char, base: c_int, ) -> uintmax_t { - use stdlib::*; strto_impl!( uintmax_t, false, diff --git a/src/header/signal/mod.rs b/src/header/signal/mod.rs index c37e81e456..9929bd0709 100644 --- a/src/header/signal/mod.rs +++ b/src/header/signal/mod.rs @@ -1,5 +1,14 @@ //! signal implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/signal.h.html +use core::{mem, ptr}; + +use header::errno; +use platform; +use platform::{PalSignal, Sys}; +use platform::types::*; + +pub use self::sys::*; + #[cfg(target_os = "linux")] #[path = "linux.rs"] pub mod sys; @@ -8,15 +17,6 @@ pub mod sys; #[path = "redox.rs"] pub mod sys; -pub use sys::*; - -use core::{mem, ptr}; - -use header::errno; -use platform; -use platform::{PalSignal, Sys}; -use platform::types::*; - const SIG_ERR: usize = !0; pub const SIG_BLOCK: c_int = 0; diff --git a/src/header/stdio/helpers.rs b/src/header/stdio/helpers.rs index f888162728..7f5bcad833 100644 --- a/src/header/stdio/helpers.rs +++ b/src/header/stdio/helpers.rs @@ -1,15 +1,17 @@ -use super::constants::*; -use super::{BUFSIZ, FILE, UNGET}; use core::mem; use core::sync::atomic::AtomicBool; -use errno; -use fcntl::*; + +use header::errno; +use header::fcntl::*; +use header::string::strchr; use platform; use platform::types::*; +use super::constants::*; +use super::{BUFSIZ, FILE, UNGET}; + /// Parse mode flags as a string and output a mode flags integer pub unsafe fn parse_mode_flags(mode_str: *const c_char) -> i32 { - use string::strchr; let mut flags = if !strchr(mode_str, b'+' as i32).is_null() { O_RDWR } else if (*mode_str) == b'r' as i8 { @@ -38,7 +40,6 @@ pub unsafe fn parse_mode_flags(mode_str: *const c_char) -> i32 { /// Open a file with the file descriptor `fd` in the mode `mode` pub unsafe fn _fdopen(fd: c_int, mode: *const c_char) -> Option<*mut FILE> { - use string::strchr; if *mode != b'r' as i8 && *mode != b'w' as i8 && *mode != b'a' as i8 { platform::errno = errno::EINVAL; return None; diff --git a/src/header/stdio/mod.rs b/src/header/stdio/mod.rs index 77b879f5c2..f274c7caae 100644 --- a/src/header/stdio/mod.rs +++ b/src/header/stdio/mod.rs @@ -17,11 +17,11 @@ use platform::{c_str, errno, Read, Write}; mod printf; mod scanf; +pub use self::default::*; mod default; -pub use default::*; +pub use self::constants::*; mod constants; -pub use constants::*; mod helpers; diff --git a/src/header/stdio/printf.rs b/src/header/stdio/printf.rs index 71c0ca94fa..061fba7ef1 100644 --- a/src/header/stdio/printf.rs +++ b/src/header/stdio/printf.rs @@ -3,7 +3,7 @@ use core::{slice, str}; use platform::types::*; use platform::{self, Write}; -use vl::VaList; +use va_list::VaList; pub unsafe fn printf(w: W, format: *const c_char, mut ap: VaList) -> c_int { let mut w = platform::CountingWriter::new(w); diff --git a/src/header/stdio/scanf.rs b/src/header/stdio/scanf.rs index 2652c141b4..bdb12fb4fa 100644 --- a/src/header/stdio/scanf.rs +++ b/src/header/stdio/scanf.rs @@ -2,7 +2,7 @@ use alloc::String; use alloc::Vec; use platform::types::*; use platform::Read; -use vl::VaList; +use va_list::VaList; #[derive(PartialEq, Eq)] enum IntKind { diff --git a/src/header/stdlib/mod.rs b/src/header/stdlib/mod.rs index c64612d368..fb695bf2f4 100644 --- a/src/header/stdlib/mod.rs +++ b/src/header/stdlib/mod.rs @@ -1,15 +1,16 @@ //! stdlib implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/stdlib.h.html -use core::{iter, mem, ptr, slice, str}; +use core::{intrinsics, iter, mem, ptr, slice, str}; use rand::distributions::Alphanumeric; use rand::prng::XorShiftRng; use rand::rngs::JitterRng; use rand::{Rng, SeedableRng}; -use header::{ctype, time, unistd, wchar}; +use header::{ctype, errno, time, unistd, wchar}; use header::errno::*; use header::fcntl::*; use header::string::*; +use header::time::constants::CLOCK_MONOTONIC; use header::wchar::*; use platform; use platform::{Pal, Sys}; @@ -58,8 +59,6 @@ pub unsafe extern "C" fn a64l(s: *const c_char) -> c_long { #[no_mangle] pub unsafe extern "C" fn abort() { - use core::intrinsics; - intrinsics::abort(); } @@ -173,8 +172,6 @@ pub unsafe extern "C" fn bsearch( #[no_mangle] pub unsafe extern "C" fn calloc(nelem: size_t, elsize: size_t) -> *mut c_void { - use core::intrinsics; - let size = nelem * elsize; let ptr = malloc(size); if !ptr.is_null() { @@ -453,8 +450,6 @@ pub extern "C" fn mktemp(name: *mut c_char) -> *mut c_char { } fn get_nstime() -> u64 { - use core::mem; - use time::constants::CLOCK_MONOTONIC; let mut ts: timespec = unsafe { mem::uninitialized() }; Sys::clock_gettime(CLOCK_MONOTONIC, &mut ts); ts.tv_nsec as u64 @@ -820,110 +815,6 @@ pub fn convert_integer(s: *const c_char, base: c_int) -> Option<(c_ulong, isize, } } -#[macro_export] -macro_rules! strto_impl { - ( - $rettype:ty, $signed:expr, $maxval:expr, $minval:expr, $s:ident, $endptr:ident, $base:ident - ) => {{ - // ensure these are constants - const CHECK_SIGN: bool = $signed; - const MAX_VAL: $rettype = $maxval; - const MIN_VAL: $rettype = $minval; - - let set_endptr = |idx: isize| { - if !$endptr.is_null() { - // This is stupid, but apparently strto* functions want - // const input but mut output, yet the man page says - // "stores the address of the first invalid character in *endptr" - // so obviously it doesn't want us to clone it. - *$endptr = $s.offset(idx) as *mut _; - } - }; - - let invalid_input = || { - platform::errno = EINVAL; - set_endptr(0); - }; - - // only valid bases are 2 through 36 - if $base != 0 && ($base < 2 || $base > 36) { - invalid_input(); - return 0; - } - - let mut idx = 0; - - // skip any whitespace at the beginning of the string - while ctype::isspace(*$s.offset(idx) as c_int) != 0 { - idx += 1; - } - - // check for +/- - let positive = match is_positive(*$s.offset(idx)) { - Some((pos, i)) => { - idx += i; - pos - } - None => { - invalid_input(); - return 0; - } - }; - - // convert the string to a number - let num_str = $s.offset(idx); - let res = match $base { - 0 => detect_base(num_str) - .and_then(|($base, i)| convert_integer(num_str.offset(i), $base)), - 8 => convert_octal(num_str), - 16 => convert_hex(num_str), - _ => convert_integer(num_str, $base), - }; - - // check for error parsing octal/hex prefix - // also check to ensure a number was indeed parsed - let (num, i, overflow) = match res { - Some(res) => res, - None => { - invalid_input(); - return 0; - } - }; - idx += i; - - let overflow = if CHECK_SIGN { - overflow || (num as c_long).is_negative() - } else { - overflow - }; - // account for the sign - let num = num as $rettype; - let num = if overflow { - platform::errno = ERANGE; - if CHECK_SIGN { - if positive { - MAX_VAL - } else { - MIN_VAL - } - } else { - MAX_VAL - } - } else { - if positive { - num - } else { - // not using -num to keep the compiler happy - num.overflowing_neg().0 - } - }; - - set_endptr(idx); - - num - }}; -} - #[no_mangle] pub unsafe extern "C" fn strtoul( s: *const c_char, diff --git a/src/header/sys_file/mod.rs b/src/header/sys_file/mod.rs index 098dddc1b4..f126dd64ba 100644 --- a/src/header/sys_file/mod.rs +++ b/src/header/sys_file/mod.rs @@ -1,6 +1,6 @@ //! sys/file.h implementation -use platform; +use platform::{Pal, Sys}; use platform::types::*; pub const LOCK_SH: usize = 1; @@ -14,5 +14,5 @@ pub const L_XTND: usize = 2; #[no_mangle] pub extern "C" fn flock(fd: c_int, operation: c_int) -> c_int { - platform::flock(fd, operation) + Sys::flock(fd, operation) } diff --git a/src/header/sys_ioctl/mod.rs b/src/header/sys_ioctl/mod.rs index f6c1e44d32..1e392810af 100644 --- a/src/header/sys_ioctl/mod.rs +++ b/src/header/sys_ioctl/mod.rs @@ -16,7 +16,7 @@ pub struct sgttyb { #[cfg(target_os = "linux")] pub mod inner { - use *; + use super::*; #[repr(C)] pub struct winsize { @@ -222,4 +222,4 @@ pub mod inner { } #[cfg(target_os = "linux")] -pub use inner::*; +pub use self::inner::*; diff --git a/src/header/sys_mman/mod.rs b/src/header/sys_mman/mod.rs index e346a2f6e4..96a6f3a8d2 100644 --- a/src/header/sys_mman/mod.rs +++ b/src/header/sys_mman/mod.rs @@ -2,7 +2,7 @@ use platform; use platform::{Pal, Sys}; use platform::types::*; -pub use sys::*; +pub use self::sys::*; #[cfg(target_os = "linux")] #[path = "linux.rs"] diff --git a/src/header/sys_socket/mod.rs b/src/header/sys_socket/mod.rs index 1d5fe32409..714ce9c0b2 100644 --- a/src/header/sys_socket/mod.rs +++ b/src/header/sys_socket/mod.rs @@ -6,8 +6,8 @@ use platform; use platform::{PalSocket, Sys}; use platform::types::*; +use self::constants::*; mod constants; -use constants::*; pub type in_addr_t = [u8; 4]; pub type in_port_t = u16; diff --git a/src/header/sys_utsname/mod.rs b/src/header/sys_utsname/mod.rs index a20924b598..1899d90962 100644 --- a/src/header/sys_utsname/mod.rs +++ b/src/header/sys_utsname/mod.rs @@ -24,4 +24,4 @@ mod inner { } } #[cfg(target_os = "linux")] -pub use inner::*; +pub use self::inner::*; diff --git a/src/header/time/constants.rs b/src/header/time/constants.rs index d677f91b50..45541d4a28 100644 --- a/src/header/time/constants.rs +++ b/src/header/time/constants.rs @@ -1,3 +1,7 @@ +use platform::types::*; + +pub use self::sys::*; + #[cfg(target_os = "linux")] #[path = "linux.rs"] pub mod sys; @@ -6,9 +10,6 @@ pub mod sys; #[path = "redox.rs"] pub mod sys; -use platform::types::*; -pub use sys::*; - // Move epoch from 01.01.1970 to 01.03.0000 (yes, Year 0) - this is the first // day of a 400-year long "era", right after additional day of leap year. // This adjustment is required only for date calculation, so instead of diff --git a/src/header/time/helpers.rs b/src/header/time/helpers.rs index 581c72eca1..70ff5f3afe 100644 --- a/src/header/time/helpers.rs +++ b/src/header/time/helpers.rs @@ -1,6 +1,7 @@ -use constants::*; use platform::types::*; +use super::constants::*; + // compute year, month, day & day of year // for description of this algorithm see // http://howardhinnant.github.io/date_algorithms.html#civil_from_days diff --git a/src/header/time/mod.rs b/src/header/time/mod.rs index 09ba1e1617..1382fb5cbe 100644 --- a/src/header/time/mod.rs +++ b/src/header/time/mod.rs @@ -8,8 +8,8 @@ use platform; use platform::{Pal, Sys}; use platform::types::*; -use constants::*; -use helpers::*; +use self::constants::*; +use self::helpers::*; pub mod constants; mod helpers; diff --git a/src/header/time/strftime.rs b/src/header/time/strftime.rs index aef702f684..bc8a649b49 100644 --- a/src/header/time/strftime.rs +++ b/src/header/time/strftime.rs @@ -1,7 +1,9 @@ use alloc::string::String; -use platform::types::*; + use platform::{self, Write}; -use tm; +use platform::types::*; + +use super::tm; pub unsafe fn strftime( w: &mut W, @@ -115,7 +117,7 @@ pub unsafe fn strftime( b'r' => w!(recurse "%I:%M:%S %p"), b'R' => w!(recurse "%H:%M"), // Nothing is modified in mktime, but the C standard of course requires a mutable pointer ._. - b's' => w!("{}", ::mktime(t as *mut tm)), + b's' => w!("{}", super::mktime(t as *mut tm)), b'S' => w!("{:02}", (*t).tm_sec), b'T' => w!(recurse "%H:%M:%S"), b'u' => w!("{}", ((*t).tm_wday + 7 - 1) % 7 + 1), diff --git a/src/header/unistd/brk.rs b/src/header/unistd/brk.rs index 78ece98354..7cf6ead43a 100644 --- a/src/header/unistd/brk.rs +++ b/src/header/unistd/brk.rs @@ -1,6 +1,6 @@ use core::ptr; -use errno::ENOMEM; +use header::errno::ENOMEM; use platform; use platform::{Pal, Sys}; use platform::types::*; diff --git a/src/header/unistd/getopt.rs b/src/header/unistd/getopt.rs index 29d77b4df6..1a4a66fd2f 100644 --- a/src/header/unistd/getopt.rs +++ b/src/header/unistd/getopt.rs @@ -2,9 +2,8 @@ use core::ptr; +use header::{stdio, string}; use platform::types::*; -use stdio; -use string; #[allow(non_upper_case_globals)] #[no_mangle] diff --git a/src/header/unistd/mod.rs b/src/header/unistd/mod.rs index 7765abd7f6..08eb2deca3 100644 --- a/src/header/unistd/mod.rs +++ b/src/header/unistd/mod.rs @@ -7,9 +7,9 @@ use platform; use platform::{Pal, Sys}; use platform::types::*; -pub use brk::*; -pub use getopt::*; -pub use pathconf::*; +pub use self::brk::*; +pub use self::getopt::*; +pub use self::pathconf::*; mod brk; mod getopt; diff --git a/src/header/wchar/utf8.rs b/src/header/wchar/utf8.rs index f3ef32dd66..1f8e72f03b 100644 --- a/src/header/wchar/utf8.rs +++ b/src/header/wchar/utf8.rs @@ -7,7 +7,7 @@ use header::errno; use platform; use platform::types::*; -use mbstate_t; +use super::mbstate_t; //It's guaranteed that we don't have any nullpointers here pub unsafe fn mbrtowc(pwc: *mut wchar_t, s: *const c_char, n: usize, ps: *mut mbstate_t) -> usize { diff --git a/src/lib.rs b/src/lib.rs index 866cc2db26..28f7d58d0d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,11 +2,15 @@ #![allow(non_camel_case_types)] #![feature(alloc)] #![feature(allocator_api)] +#![feature(const_fn)] #![feature(const_vec_new)] +#![feature(core_intrinsics)] +#![feature(extern_prelude)] #![feature(global_asm)] #![feature(lang_items)] #![feature(linkage)] #![feature(panic_implementation)] +#![feature(str_internals)] #![feature(thread_local)] #[macro_use] @@ -26,10 +30,15 @@ extern crate syscall; #[cfg(target_os = "redox")] extern crate spin; +#[macro_use] +mod macros; pub mod header; pub mod platform; -use platform::{Pal, Sys}; +use platform::{Allocator, Pal, Sys}; + +#[global_allocator] +static ALLOCATOR: Allocator = Allocator; #[cfg(not(test))] #[panic_implementation] diff --git a/src/macros.rs b/src/macros.rs new file mode 100644 index 0000000000..bdccf675b3 --- /dev/null +++ b/src/macros.rs @@ -0,0 +1,103 @@ +#[macro_export] +macro_rules! strto_impl { + ( + $rettype:ty, $signed:expr, $maxval:expr, $minval:expr, $s:ident, $endptr:ident, $base:ident + ) => {{ + // ensure these are constants + const CHECK_SIGN: bool = $signed; + const MAX_VAL: $rettype = $maxval; + const MIN_VAL: $rettype = $minval; + + let set_endptr = |idx: isize| { + if !$endptr.is_null() { + // This is stupid, but apparently strto* functions want + // const input but mut output, yet the man page says + // "stores the address of the first invalid character in *endptr" + // so obviously it doesn't want us to clone it. + *$endptr = $s.offset(idx) as *mut _; + } + }; + + let invalid_input = || { + platform::errno = EINVAL; + set_endptr(0); + }; + + // only valid bases are 2 through 36 + if $base != 0 && ($base < 2 || $base > 36) { + invalid_input(); + return 0; + } + + let mut idx = 0; + + // skip any whitespace at the beginning of the string + while ctype::isspace(*$s.offset(idx) as c_int) != 0 { + idx += 1; + } + + // check for +/- + let positive = match is_positive(*$s.offset(idx)) { + Some((pos, i)) => { + idx += i; + pos + } + None => { + invalid_input(); + return 0; + } + }; + + // convert the string to a number + let num_str = $s.offset(idx); + let res = match $base { + 0 => detect_base(num_str) + .and_then(|($base, i)| convert_integer(num_str.offset(i), $base)), + 8 => convert_octal(num_str), + 16 => convert_hex(num_str), + _ => convert_integer(num_str, $base), + }; + + // check for error parsing octal/hex prefix + // also check to ensure a number was indeed parsed + let (num, i, overflow) = match res { + Some(res) => res, + None => { + invalid_input(); + return 0; + } + }; + idx += i; + + let overflow = if CHECK_SIGN { + overflow || (num as c_long).is_negative() + } else { + overflow + }; + // account for the sign + let num = num as $rettype; + let num = if overflow { + platform::errno = ERANGE; + if CHECK_SIGN { + if positive { + MAX_VAL + } else { + MIN_VAL + } + } else { + MAX_VAL + } + } else { + if positive { + num + } else { + // not using -num to keep the compiler happy + num.overflowing_neg().0 + } + }; + + set_endptr(idx); + + num + }}; +} diff --git a/src/platform/allocator/dlmalloc.rs b/src/platform/allocator/dlmalloc.rs index ad02e7539d..a57748c7e0 100644 --- a/src/platform/allocator/dlmalloc.rs +++ b/src/platform/allocator/dlmalloc.rs @@ -1,6 +1,6 @@ use core::alloc::{GlobalAlloc, Layout}; -use types::*; +use super::types::*; extern "C" { fn dlmalloc(bytes: size_t) -> *mut c_void; diff --git a/src/platform/linux/mod.rs b/src/platform/linux/mod.rs index a11f13da22..232b6a11a6 100644 --- a/src/platform/linux/mod.rs +++ b/src/platform/linux/mod.rs @@ -1,8 +1,8 @@ use core::{mem, ptr}; use core::fmt::Write; -use {errno, FileWriter, Pal}; -use types::*; +use super::{errno, FileWriter, Pal}; +use super::types::*; mod signal; mod socket; @@ -107,7 +107,7 @@ impl Pal for Sys { } fn fstat(fildes: c_int, buf: *mut stat) -> c_int { - let empty_cstr: *const c_char = unsafe { ::cstr_from_bytes_with_nul_unchecked(b"\0") }; + let empty_cstr: *const c_char = unsafe { super::cstr_from_bytes_with_nul_unchecked(b"\0") }; e(unsafe { syscall!(NEWFSTATAT, fildes, empty_cstr, buf, AT_EMPTY_PATH) }) as c_int } diff --git a/src/platform/linux/signal.rs b/src/platform/linux/signal.rs index 1d29bc3d41..0e2e72d80d 100644 --- a/src/platform/linux/signal.rs +++ b/src/platform/linux/signal.rs @@ -1,8 +1,8 @@ use core::mem; use super::{e, Sys}; -use PalSignal; -use types::*; +use super::super::PalSignal; +use super::super::types::*; impl PalSignal for Sys { fn kill(pid: pid_t, sig: c_int) -> c_int { diff --git a/src/platform/linux/socket.rs b/src/platform/linux/socket.rs index f222a6e365..73707d7e42 100644 --- a/src/platform/linux/socket.rs +++ b/src/platform/linux/socket.rs @@ -1,6 +1,6 @@ use super::{e, Sys}; -use PalSocket; -use types::*; +use super::super::PalSocket; +use super::super::types::*; impl PalSocket for Sys { unsafe fn accept(socket: c_int, address: *mut sockaddr, address_len: *mut socklen_t) -> c_int { diff --git a/src/platform/mod.rs b/src/platform/mod.rs index 918c19f59a..4abdab5df7 100644 --- a/src/platform/mod.rs +++ b/src/platform/mod.rs @@ -1,4 +1,7 @@ -pub use allocator::*; +use alloc::vec::Vec; +use core::{fmt, ptr}; + +pub use self::allocator::*; #[cfg(not(feature = "ralloc"))] #[path = "allocator/dlmalloc.rs"] @@ -8,11 +11,11 @@ mod allocator; #[path = "allocator/ralloc.rs"] mod allocator; -pub use pal::{Pal, PalSignal, PalSocket}; +pub use self::pal::{Pal, PalSignal, PalSocket}; mod pal; -pub use sys::Sys; +pub use self::sys::Sys; #[cfg(all(not(feature = "no_std"), target_os = "linux"))] #[path = "linux/mod.rs"] @@ -22,19 +25,13 @@ mod sys; #[path = "redox/mod.rs"] mod sys; +pub use self::rawfile::RawFile; + pub mod rawfile; + +use self::types::*; pub mod types; -pub use rawfile::RawFile; - -use alloc::vec::Vec; -use core::{fmt, ptr}; - -use types::*; - -#[global_allocator] -static ALLOCATOR: Allocator = Allocator; - //TODO #[thread_local] #[allow(non_upper_case_globals)] #[no_mangle] diff --git a/src/platform/pal/mod.rs b/src/platform/pal/mod.rs index 45f13c053a..25b8ea242d 100644 --- a/src/platform/pal/mod.rs +++ b/src/platform/pal/mod.rs @@ -1,6 +1,6 @@ use core::ptr; -use types::*; +use super::types::*; pub use self::signal::PalSignal; mod signal; diff --git a/src/platform/pal/signal.rs b/src/platform/pal/signal.rs index 50176b913c..e8a40a9621 100644 --- a/src/platform/pal/signal.rs +++ b/src/platform/pal/signal.rs @@ -1,5 +1,5 @@ -use Pal; -use types::*; +use super::super::Pal; +use super::super::types::*; pub trait PalSignal: Pal { fn kill(pid: pid_t, sig: c_int) -> c_int { diff --git a/src/platform/pal/socket.rs b/src/platform/pal/socket.rs index a1329d6026..8e8c1f6d90 100644 --- a/src/platform/pal/socket.rs +++ b/src/platform/pal/socket.rs @@ -1,5 +1,5 @@ -use Pal; -use types::*; +use super::super::Pal; +use super::super::types::*; pub trait PalSocket: Pal { unsafe fn accept(socket: c_int, address: *mut sockaddr, address_len: *mut socklen_t) -> c_int { diff --git a/src/platform/rawfile.rs b/src/platform/rawfile.rs index 58d870123c..338ed0b4f3 100644 --- a/src/platform/rawfile.rs +++ b/src/platform/rawfile.rs @@ -1,6 +1,6 @@ use core::ops::Deref; -use {Pal, Sys, types::*}; +use super::{Pal, Sys, types::*}; pub struct RawFile(c_int); diff --git a/src/platform/redox/mod.rs b/src/platform/redox/mod.rs index bbe4920bcb..7c93747043 100644 --- a/src/platform/redox/mod.rs +++ b/src/platform/redox/mod.rs @@ -9,8 +9,8 @@ use syscall::data::TimeSpec as redox_timespec; use syscall::flag::*; use syscall::{self, Result}; -use {c_str, errno, FileReader, FileWriter, Pal, RawFile, Read}; -use types::*; +use super::{c_str, errno, FileReader, FileWriter, Pal, RawFile, Read}; +use super::types::*; mod signal; mod socket; diff --git a/src/platform/redox/signal.rs b/src/platform/redox/signal.rs index 612b04f2ef..76b8b818a4 100644 --- a/src/platform/redox/signal.rs +++ b/src/platform/redox/signal.rs @@ -1,8 +1,8 @@ use syscall; use super::{e, Sys}; -use {Pal, PalSignal}; -use types::*; +use super::super::{Pal, PalSignal}; +use super::super::types::*; #[thread_local] static mut SIG_HANDLER: Option = None; diff --git a/src/platform/redox/socket.rs b/src/platform/redox/socket.rs index bd78eafc90..7de759dab5 100644 --- a/src/platform/redox/socket.rs +++ b/src/platform/redox/socket.rs @@ -3,8 +3,8 @@ use syscall::{self, Result}; use syscall::flag::*; use super::{e, Sys}; -use {errno, Pal, PalSocket}; -use types::*; +use super::super::{errno, Pal, PalSocket}; +use super::super::types::*; macro_rules! bind_or_connect { (bind $path:expr) => { From c63c930e4acc65856034f0e47483216ad3bc8af9 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sun, 26 Aug 2018 12:10:02 -0600 Subject: [PATCH 09/19] Make it compile --- Cargo.lock | 82 ++++++++++++++++----------------- src/crt0/src/lib.rs | 109 ++++---------------------------------------- src/start.rs | 70 ++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+), 142 deletions(-) create mode 100644 src/start.rs diff --git a/Cargo.lock b/Cargo.lock index 3ecbfa7830..5f39557e6a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,17 +8,17 @@ dependencies = [ [[package]] name = "atty" -version = "0.2.10" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "bitflags" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -27,9 +27,9 @@ version = "0.5.2" dependencies = [ "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.75 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.21 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)", "standalone-syn 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)", "tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -37,12 +37,12 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.18" +version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "cfg-if" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -51,8 +51,8 @@ version = "2.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", - "atty 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", - "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -62,7 +62,7 @@ dependencies = [ [[package]] name = "compiler_builtins" version = "0.1.0" -source = "git+https://github.com/rust-lang-nursery/compiler-builtins.git#5d370bb352c915225981d89b80227afa4836cb93" +source = "git+https://github.com/rust-lang-nursery/compiler-builtins.git#3caed3c80207fa43ba2963949c5f104a63c4264e" [[package]] name = "crt0" @@ -71,17 +71,12 @@ dependencies = [ "relibc 0.1.0", ] -[[package]] -name = "dtoa" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "fuchsia-zircon" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -106,7 +101,7 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.42" +version = "0.2.43" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -114,15 +109,15 @@ name = "log" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "log" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -156,11 +151,11 @@ dependencies = [ [[package]] name = "rand" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -199,7 +194,7 @@ dependencies = [ name = "relibc" version = "0.1.0" dependencies = [ - "cc 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.22 (registry+https://github.com/rust-lang/crates.io-index)", "compiler_builtins 0.1.0 (git+https://github.com/rust-lang-nursery/compiler-builtins.git)", "lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "ralloc 1.0.0", @@ -218,6 +213,11 @@ dependencies = [ "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "ryu" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "sc" version = "0.2.2" @@ -225,7 +225,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "serde" -version = "1.0.70" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "serde_derive 1.0.21 (registry+https://github.com/rust-lang/crates.io-index)", @@ -252,12 +252,12 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.24" +version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "dtoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "itoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)", + "ryu 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.75 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -311,7 +311,7 @@ name = "tempdir" version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -320,7 +320,7 @@ name = "termion" version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -338,7 +338,7 @@ name = "toml" version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.75 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -372,7 +372,7 @@ dependencies = [ name = "va_list-helper" version = "0.0.2" dependencies = [ - "cc 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.22 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -406,34 +406,34 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [metadata] "checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" -"checksum atty 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "2fc4a1aa4c24c0718a250f0681885c1af91419d242f29eb8f2ab28502d80dbd1" -"checksum bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d0c54bb8f454c567f21197eefcdbf5679d0bd99f2ddbe52e84c77061952e6789" -"checksum cc 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)" = "2119ea4867bd2b8ed3aecab467709720b2d55b1bcfe09f772fd68066eaf15275" -"checksum cfg-if 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "efe5c877e17a9c717a0bf3613b2709f723202c4e4675cc8f12926ded29bcb17e" +"checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652" +"checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12" +"checksum cc 1.0.22 (registry+https://github.com/rust-lang/crates.io-index)" = "4a6007c146fdd28d4512a794b07ffe9d8e89e6bf86e2e0c4ddff2e1fb54a0007" +"checksum cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0c4e7bb64a8ebb0d856483e1e682ea3422f883c5f5615a90d51a2c82fe87fdd3" "checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e" "checksum compiler_builtins 0.1.0 (git+https://github.com/rust-lang-nursery/compiler-builtins.git)" = "" -"checksum dtoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6d301140eb411af13d3115f9a562c85cc6b541ade9dfa314132244aaee7489dd" "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" "checksum itoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5adb58558dcd1d786b5f0bd15f3226ee23486e24b7b58304b60f64dc68e62606" "checksum lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca488b89a5657b0a2ecd45b95609b3e848cf1755da332a0da46e2b2b1cb371a7" -"checksum libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)" = "b685088df2b950fccadf07a7187c8ef846a959c142338a48f9dc0b94517eb5f1" +"checksum libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)" = "76e3a3ef172f1a0b9a9ff0dd1491ae5e6c948b94479a3021819ba7d860c8645d" "checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" -"checksum log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "61bd98ae7f7b754bc53dca7d44b604f733c6bba044ea6f41bc8d89272d8161d2" +"checksum log 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "cba860f648db8e6f269df990180c2217f333472b4a6e901e97446858487971e2" "checksum proc-macro2 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cd07deb3c6d1d9ff827999c7f9b04cdfd66b1b17ae508e14fe47b620f2282ae0" "checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a" -"checksum rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eba5f8cb59cc50ed56be8880a5c7b496bfd9bd26394e176bc67884094145c2c5" +"checksum rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8356f47b32624fef5b3301c1be97e5944ecdd595409cc5da11d05f211db6cfbd" "checksum rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e464cd887e869cddcae8792a4ee31d23c7edd516700695608f5b98c67ee0131c" "checksum rand_core 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "edecf0f94da5551fc9b492093e30b041a891657db7940ee221f9d2f66e82eef2" "checksum redox_syscall 0.1.40 (git+https://gitlab.redox-os.org/redox-os/syscall.git?branch=relibc)" = "" "checksum redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "c214e91d3ecf43e9a4e41e578973adeb14b474f2bee858742d127af75a0112b1" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" "checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5" +"checksum ryu 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7153dd96dade874ab973e098cb62fcdbb89a03682e46b144fd09550998d4a4a7" "checksum sc 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4ebbb026ba4a707c25caec2db5ef59ad8b41f7ad77cad06257e06229c891f376" -"checksum serde 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)" = "0c3adf19c07af6d186d91dae8927b83b0553d07ca56cbf7f2f32560455c91920" +"checksum serde 1.0.75 (registry+https://github.com/rust-lang/crates.io-index)" = "22d340507cea0b7e6632900a176101fea959c7065d93ba555072da90aaaafc87" "checksum serde_derive 1.0.21 (registry+https://github.com/rust-lang/crates.io-index)" = "652bc323d694dc925829725ec6c890156d8e70ae5202919869cb00fe2eff3788" "checksum serde_derive_internals 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)" = "32f1926285523b2db55df263d2aa4eb69ddcfa7a7eade6430323637866b513ab" -"checksum serde_json 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)" = "c3c6908c7b925cd6c590358a4034de93dbddb20c45e1d021931459fd419bf0e2" +"checksum serde_json 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)" = "44dd2cfde475037451fa99b7e5df77aa3cfd1536575fa8e7a538ab36dcde49ae" "checksum spin 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)" = "37b5646825922b96b5d7d676b5bb3458a54498e96ed7b0ce09dc43a07038fea4" "checksum standalone-quote 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dcedac1d6d98e7e9d1d6e628f5635af9566688ae5f6cea70a3976f495ae8d839" "checksum standalone-syn 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "115808f5187c07c23cb93eee49d542fae54c6e8285d3a24c6ff683fcde9243db" diff --git a/src/crt0/src/lib.rs b/src/crt0/src/lib.rs index fa788eebbb..c54e90b17f 100644 --- a/src/crt0/src/lib.rs +++ b/src/crt0/src/lib.rs @@ -1,23 +1,11 @@ //! crt0 #![no_std] -#![feature(alloc)] #![feature(asm)] +#![feature(lang_items)] #![feature(linkage)] #![feature(naked_functions)] #![feature(panic_implementation)] -#![feature(lang_items)] - -extern crate alloc; -extern crate relibc; - -use relibc::platform; -use relibc::header::stdio; - -use alloc::Vec; -use core::ptr; -use platform::{Pal, Sys}; -use platform::types::*; #[no_mangle] #[naked] @@ -41,96 +29,15 @@ pub unsafe extern "C" fn _start() { ); } -#[repr(C)] -pub struct Stack { - argc: isize, - argv0: *const c_char, -} - -impl Stack { - fn argc(&self) -> isize { - self.argc - } - - fn argv(&self) -> *const *const c_char { - &self.argv0 as *const _ - } - - fn envp(&self) -> *const *const c_char { - unsafe { self.argv().offset(self.argc() + 1) } - } -} - -#[inline(never)] -#[no_mangle] -pub unsafe extern "C" fn _start_rust(sp: &'static Stack) -> ! { - extern "C" { - fn main(argc: isize, argv: *const *const c_char, envp: *const *const c_char) -> c_int; - } - - let argc = sp.argc(); - let argv = sp.argv(); - - let envp = sp.envp(); - let mut len = 0; - while *envp.offset(len) != ptr::null() { - len += 1; - } - platform::inner_environ = Vec::with_capacity(len as usize + 1); - for i in 0..len { - let mut item = *envp.offset(i); - let mut len = 0; - while *item.offset(len) != 0 { - len += 1; - } - - let buf = platform::alloc(len as usize + 1) as *mut c_char; - for i in 0..=len { - *buf.offset(i) = *item.offset(i); - } - platform::inner_environ.push(buf); - } - platform::inner_environ.push(ptr::null_mut()); - platform::environ = platform::inner_environ.as_mut_ptr(); - - // Initialize stdin/stdout/stderr, see https://github.com/rust-lang/rust/issues/51718 - stdio::stdin = stdio::default_stdin.get(); - stdio::stdout = stdio::default_stdout.get(); - stdio::stderr = stdio::default_stderr.get(); - - Sys::exit(main( - argc, - argv, - // not envp, because programs like bash try to modify this *const* - // pointer :| - platform::environ as *const *const c_char - )); -} - #[panic_implementation] #[linkage = "weak"] #[no_mangle] -pub extern "C" fn rust_begin_unwind(pi: &::core::panic::PanicInfo) -> ! { - use core::fmt::Write; +pub extern "C" fn rust_begin_unwind(_pi: &::core::panic::PanicInfo) -> ! { + extern "C" { + fn exit(status: i32) -> !; + } - let mut w = platform::FileWriter(2); - let _ = w.write_fmt(format_args!("RELIBC CRT0 PANIC: {}\n", pi)); - - Sys::exit(1); -} - -#[lang = "oom"] -#[linkage = "weak"] -#[no_mangle] -pub extern "C" fn rust_oom(layout: ::core::alloc::Layout) -> ! { - use core::fmt::Write; - - let mut w = platform::FileWriter(2); - let _ = w.write_fmt(format_args!( - "RELIBC OOM: {} bytes aligned to {} bytes\n", - layout.size(), - layout.align() - )); - - Sys::exit(1); + unsafe { + exit(1) + } } diff --git a/src/start.rs b/src/start.rs new file mode 100644 index 0000000000..235e8783c2 --- /dev/null +++ b/src/start.rs @@ -0,0 +1,70 @@ +use alloc::Vec; +use core::ptr; + +use platform::types::*; + +#[repr(C)] +pub struct Stack { + argc: isize, + argv0: *const c_char, +} + +impl Stack { + fn argc(&self) -> isize { + self.argc + } + + fn argv(&self) -> *const *const c_char { + &self.argv0 as *const _ + } + + fn envp(&self) -> *const *const c_char { + unsafe { self.argv().offset(self.argc() + 1) } + } +} + +#[inline(never)] +#[no_mangle] +pub unsafe extern "C" fn _start_rust(sp: &'static Stack) -> ! { + extern "C" { + fn main(argc: isize, argv: *const *const c_char, envp: *const *const c_char) -> c_int; + } + + let argc = sp.argc(); + let argv = sp.argv(); + + let envp = sp.envp(); + let mut len = 0; + while *envp.offset(len) != ptr::null() { + len += 1; + } + platform::inner_environ = Vec::with_capacity(len as usize + 1); + for i in 0..len { + let mut item = *envp.offset(i); + let mut len = 0; + while *item.offset(len) != 0 { + len += 1; + } + + let buf = platform::alloc(len as usize + 1) as *mut c_char; + for i in 0..=len { + *buf.offset(i) = *item.offset(i); + } + platform::inner_environ.push(buf); + } + platform::inner_environ.push(ptr::null_mut()); + platform::environ = platform::inner_environ.as_mut_ptr(); + + // Initialize stdin/stdout/stderr, see https://github.com/rust-lang/rust/issues/51718 + stdio::stdin = stdio::default_stdin.get(); + stdio::stdout = stdio::default_stdout.get(); + stdio::stderr = stdio::default_stderr.get(); + + Sys::exit(main( + argc, + argv, + // not envp, because programs like bash try to modify this *const* + // pointer :| + platform::environ as *const *const c_char + )); +} From ed00ddfb548dacb1aef80eb7afeacdf3a7ef2e6e Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sun, 26 Aug 2018 12:28:27 -0600 Subject: [PATCH 10/19] Fix remaining issues, move setjmp into relibc crate, move start logic into relibc --- src/crt0/src/lib.rs | 4 ++-- src/header/mod.rs | 1 + src/header/setjmp/Cargo.toml | 4 ---- src/header/setjmp/{src => }/impl/README.md | 0 src/header/setjmp/{src => }/impl/aarch64/longjmp.s | 0 src/header/setjmp/{src => }/impl/aarch64/setjmp.s | 0 src/header/setjmp/{src => }/impl/arm/longjmp.s | 0 src/header/setjmp/{src => }/impl/arm/setjmp.s | 0 src/header/setjmp/{src => }/impl/i386/longjmp.s | 0 src/header/setjmp/{src => }/impl/i386/setjmp.s | 0 src/header/setjmp/{src => }/impl/m68k/longjmp.s | 0 src/header/setjmp/{src => }/impl/m68k/setjmp.s | 0 src/header/setjmp/{src => }/impl/microblaze/longjmp.s | 0 src/header/setjmp/{src => }/impl/microblaze/setjmp.s | 0 src/header/setjmp/{src => }/impl/mips/longjmp.S | 0 src/header/setjmp/{src => }/impl/mips/setjmp.S | 0 src/header/setjmp/{src => }/impl/mips64/longjmp.S | 0 src/header/setjmp/{src => }/impl/mips64/setjmp.S | 0 src/header/setjmp/{src => }/impl/mipsn32/longjmp.S | 0 src/header/setjmp/{src => }/impl/mipsn32/setjmp.S | 0 src/header/setjmp/{src => }/impl/or1k/longjmp.s | 0 src/header/setjmp/{src => }/impl/or1k/setjmp.s | 0 src/header/setjmp/{src => }/impl/powerpc/longjmp.S | 0 src/header/setjmp/{src => }/impl/powerpc/setjmp.S | 0 src/header/setjmp/{src => }/impl/powerpc64/longjmp.s | 0 src/header/setjmp/{src => }/impl/powerpc64/setjmp.s | 0 src/header/setjmp/{src => }/impl/s390x/longjmp.s | 0 src/header/setjmp/{src => }/impl/s390x/setjmp.s | 0 src/header/setjmp/{src => }/impl/sh/longjmp.S | 0 src/header/setjmp/{src => }/impl/sh/setjmp.S | 0 src/header/setjmp/{src => }/impl/x32/longjmp.s | 0 src/header/setjmp/{src => }/impl/x32/setjmp.s | 0 src/header/setjmp/{src => }/impl/x86_64/longjmp.s | 0 src/header/setjmp/{src => }/impl/x86_64/setjmp.s | 0 src/header/setjmp/{src/lib.rs => mod.rs} | 0 src/lib.rs | 1 + src/start.rs | 5 ++++- 37 files changed, 8 insertions(+), 7 deletions(-) delete mode 100644 src/header/setjmp/Cargo.toml rename src/header/setjmp/{src => }/impl/README.md (100%) rename src/header/setjmp/{src => }/impl/aarch64/longjmp.s (100%) rename src/header/setjmp/{src => }/impl/aarch64/setjmp.s (100%) rename src/header/setjmp/{src => }/impl/arm/longjmp.s (100%) rename src/header/setjmp/{src => }/impl/arm/setjmp.s (100%) rename src/header/setjmp/{src => }/impl/i386/longjmp.s (100%) rename src/header/setjmp/{src => }/impl/i386/setjmp.s (100%) rename src/header/setjmp/{src => }/impl/m68k/longjmp.s (100%) rename src/header/setjmp/{src => }/impl/m68k/setjmp.s (100%) rename src/header/setjmp/{src => }/impl/microblaze/longjmp.s (100%) rename src/header/setjmp/{src => }/impl/microblaze/setjmp.s (100%) rename src/header/setjmp/{src => }/impl/mips/longjmp.S (100%) rename src/header/setjmp/{src => }/impl/mips/setjmp.S (100%) rename src/header/setjmp/{src => }/impl/mips64/longjmp.S (100%) rename src/header/setjmp/{src => }/impl/mips64/setjmp.S (100%) rename src/header/setjmp/{src => }/impl/mipsn32/longjmp.S (100%) rename src/header/setjmp/{src => }/impl/mipsn32/setjmp.S (100%) rename src/header/setjmp/{src => }/impl/or1k/longjmp.s (100%) rename src/header/setjmp/{src => }/impl/or1k/setjmp.s (100%) rename src/header/setjmp/{src => }/impl/powerpc/longjmp.S (100%) rename src/header/setjmp/{src => }/impl/powerpc/setjmp.S (100%) rename src/header/setjmp/{src => }/impl/powerpc64/longjmp.s (100%) rename src/header/setjmp/{src => }/impl/powerpc64/setjmp.s (100%) rename src/header/setjmp/{src => }/impl/s390x/longjmp.s (100%) rename src/header/setjmp/{src => }/impl/s390x/setjmp.s (100%) rename src/header/setjmp/{src => }/impl/sh/longjmp.S (100%) rename src/header/setjmp/{src => }/impl/sh/setjmp.S (100%) rename src/header/setjmp/{src => }/impl/x32/longjmp.s (100%) rename src/header/setjmp/{src => }/impl/x32/setjmp.s (100%) rename src/header/setjmp/{src => }/impl/x86_64/longjmp.s (100%) rename src/header/setjmp/{src => }/impl/x86_64/setjmp.s (100%) rename src/header/setjmp/{src/lib.rs => mod.rs} (100%) diff --git a/src/crt0/src/lib.rs b/src/crt0/src/lib.rs index c54e90b17f..d3f1642a9f 100644 --- a/src/crt0/src/lib.rs +++ b/src/crt0/src/lib.rs @@ -13,7 +13,7 @@ pub unsafe extern "C" fn _start() { #[cfg(target_arch = "x86_64")] asm!("mov rdi, rsp and rsp, 0xFFFFFFFFFFFFFFF0 - call _start_rust" + call relibc_start" : : : @@ -21,7 +21,7 @@ pub unsafe extern "C" fn _start() { ); #[cfg(target_arch = "aarch64")] asm!("mov x0, sp - bl _start_rust" + bl relibc_start" : : : diff --git a/src/header/mod.rs b/src/header/mod.rs index 6f65ca7526..4fdee75126 100644 --- a/src/header/mod.rs +++ b/src/header/mod.rs @@ -12,6 +12,7 @@ pub mod locale; pub mod netinet_in; pub mod pwd; pub mod semaphore; +pub mod setjmp; pub mod sgtty; pub mod signal; pub mod stdio; diff --git a/src/header/setjmp/Cargo.toml b/src/header/setjmp/Cargo.toml deleted file mode 100644 index 2826a4e541..0000000000 --- a/src/header/setjmp/Cargo.toml +++ /dev/null @@ -1,4 +0,0 @@ -[package] -name = "setjmp" -version = "0.1.0" -authors = ["Jeremy Soller "] diff --git a/src/header/setjmp/src/impl/README.md b/src/header/setjmp/impl/README.md similarity index 100% rename from src/header/setjmp/src/impl/README.md rename to src/header/setjmp/impl/README.md diff --git a/src/header/setjmp/src/impl/aarch64/longjmp.s b/src/header/setjmp/impl/aarch64/longjmp.s similarity index 100% rename from src/header/setjmp/src/impl/aarch64/longjmp.s rename to src/header/setjmp/impl/aarch64/longjmp.s diff --git a/src/header/setjmp/src/impl/aarch64/setjmp.s b/src/header/setjmp/impl/aarch64/setjmp.s similarity index 100% rename from src/header/setjmp/src/impl/aarch64/setjmp.s rename to src/header/setjmp/impl/aarch64/setjmp.s diff --git a/src/header/setjmp/src/impl/arm/longjmp.s b/src/header/setjmp/impl/arm/longjmp.s similarity index 100% rename from src/header/setjmp/src/impl/arm/longjmp.s rename to src/header/setjmp/impl/arm/longjmp.s diff --git a/src/header/setjmp/src/impl/arm/setjmp.s b/src/header/setjmp/impl/arm/setjmp.s similarity index 100% rename from src/header/setjmp/src/impl/arm/setjmp.s rename to src/header/setjmp/impl/arm/setjmp.s diff --git a/src/header/setjmp/src/impl/i386/longjmp.s b/src/header/setjmp/impl/i386/longjmp.s similarity index 100% rename from src/header/setjmp/src/impl/i386/longjmp.s rename to src/header/setjmp/impl/i386/longjmp.s diff --git a/src/header/setjmp/src/impl/i386/setjmp.s b/src/header/setjmp/impl/i386/setjmp.s similarity index 100% rename from src/header/setjmp/src/impl/i386/setjmp.s rename to src/header/setjmp/impl/i386/setjmp.s diff --git a/src/header/setjmp/src/impl/m68k/longjmp.s b/src/header/setjmp/impl/m68k/longjmp.s similarity index 100% rename from src/header/setjmp/src/impl/m68k/longjmp.s rename to src/header/setjmp/impl/m68k/longjmp.s diff --git a/src/header/setjmp/src/impl/m68k/setjmp.s b/src/header/setjmp/impl/m68k/setjmp.s similarity index 100% rename from src/header/setjmp/src/impl/m68k/setjmp.s rename to src/header/setjmp/impl/m68k/setjmp.s diff --git a/src/header/setjmp/src/impl/microblaze/longjmp.s b/src/header/setjmp/impl/microblaze/longjmp.s similarity index 100% rename from src/header/setjmp/src/impl/microblaze/longjmp.s rename to src/header/setjmp/impl/microblaze/longjmp.s diff --git a/src/header/setjmp/src/impl/microblaze/setjmp.s b/src/header/setjmp/impl/microblaze/setjmp.s similarity index 100% rename from src/header/setjmp/src/impl/microblaze/setjmp.s rename to src/header/setjmp/impl/microblaze/setjmp.s diff --git a/src/header/setjmp/src/impl/mips/longjmp.S b/src/header/setjmp/impl/mips/longjmp.S similarity index 100% rename from src/header/setjmp/src/impl/mips/longjmp.S rename to src/header/setjmp/impl/mips/longjmp.S diff --git a/src/header/setjmp/src/impl/mips/setjmp.S b/src/header/setjmp/impl/mips/setjmp.S similarity index 100% rename from src/header/setjmp/src/impl/mips/setjmp.S rename to src/header/setjmp/impl/mips/setjmp.S diff --git a/src/header/setjmp/src/impl/mips64/longjmp.S b/src/header/setjmp/impl/mips64/longjmp.S similarity index 100% rename from src/header/setjmp/src/impl/mips64/longjmp.S rename to src/header/setjmp/impl/mips64/longjmp.S diff --git a/src/header/setjmp/src/impl/mips64/setjmp.S b/src/header/setjmp/impl/mips64/setjmp.S similarity index 100% rename from src/header/setjmp/src/impl/mips64/setjmp.S rename to src/header/setjmp/impl/mips64/setjmp.S diff --git a/src/header/setjmp/src/impl/mipsn32/longjmp.S b/src/header/setjmp/impl/mipsn32/longjmp.S similarity index 100% rename from src/header/setjmp/src/impl/mipsn32/longjmp.S rename to src/header/setjmp/impl/mipsn32/longjmp.S diff --git a/src/header/setjmp/src/impl/mipsn32/setjmp.S b/src/header/setjmp/impl/mipsn32/setjmp.S similarity index 100% rename from src/header/setjmp/src/impl/mipsn32/setjmp.S rename to src/header/setjmp/impl/mipsn32/setjmp.S diff --git a/src/header/setjmp/src/impl/or1k/longjmp.s b/src/header/setjmp/impl/or1k/longjmp.s similarity index 100% rename from src/header/setjmp/src/impl/or1k/longjmp.s rename to src/header/setjmp/impl/or1k/longjmp.s diff --git a/src/header/setjmp/src/impl/or1k/setjmp.s b/src/header/setjmp/impl/or1k/setjmp.s similarity index 100% rename from src/header/setjmp/src/impl/or1k/setjmp.s rename to src/header/setjmp/impl/or1k/setjmp.s diff --git a/src/header/setjmp/src/impl/powerpc/longjmp.S b/src/header/setjmp/impl/powerpc/longjmp.S similarity index 100% rename from src/header/setjmp/src/impl/powerpc/longjmp.S rename to src/header/setjmp/impl/powerpc/longjmp.S diff --git a/src/header/setjmp/src/impl/powerpc/setjmp.S b/src/header/setjmp/impl/powerpc/setjmp.S similarity index 100% rename from src/header/setjmp/src/impl/powerpc/setjmp.S rename to src/header/setjmp/impl/powerpc/setjmp.S diff --git a/src/header/setjmp/src/impl/powerpc64/longjmp.s b/src/header/setjmp/impl/powerpc64/longjmp.s similarity index 100% rename from src/header/setjmp/src/impl/powerpc64/longjmp.s rename to src/header/setjmp/impl/powerpc64/longjmp.s diff --git a/src/header/setjmp/src/impl/powerpc64/setjmp.s b/src/header/setjmp/impl/powerpc64/setjmp.s similarity index 100% rename from src/header/setjmp/src/impl/powerpc64/setjmp.s rename to src/header/setjmp/impl/powerpc64/setjmp.s diff --git a/src/header/setjmp/src/impl/s390x/longjmp.s b/src/header/setjmp/impl/s390x/longjmp.s similarity index 100% rename from src/header/setjmp/src/impl/s390x/longjmp.s rename to src/header/setjmp/impl/s390x/longjmp.s diff --git a/src/header/setjmp/src/impl/s390x/setjmp.s b/src/header/setjmp/impl/s390x/setjmp.s similarity index 100% rename from src/header/setjmp/src/impl/s390x/setjmp.s rename to src/header/setjmp/impl/s390x/setjmp.s diff --git a/src/header/setjmp/src/impl/sh/longjmp.S b/src/header/setjmp/impl/sh/longjmp.S similarity index 100% rename from src/header/setjmp/src/impl/sh/longjmp.S rename to src/header/setjmp/impl/sh/longjmp.S diff --git a/src/header/setjmp/src/impl/sh/setjmp.S b/src/header/setjmp/impl/sh/setjmp.S similarity index 100% rename from src/header/setjmp/src/impl/sh/setjmp.S rename to src/header/setjmp/impl/sh/setjmp.S diff --git a/src/header/setjmp/src/impl/x32/longjmp.s b/src/header/setjmp/impl/x32/longjmp.s similarity index 100% rename from src/header/setjmp/src/impl/x32/longjmp.s rename to src/header/setjmp/impl/x32/longjmp.s diff --git a/src/header/setjmp/src/impl/x32/setjmp.s b/src/header/setjmp/impl/x32/setjmp.s similarity index 100% rename from src/header/setjmp/src/impl/x32/setjmp.s rename to src/header/setjmp/impl/x32/setjmp.s diff --git a/src/header/setjmp/src/impl/x86_64/longjmp.s b/src/header/setjmp/impl/x86_64/longjmp.s similarity index 100% rename from src/header/setjmp/src/impl/x86_64/longjmp.s rename to src/header/setjmp/impl/x86_64/longjmp.s diff --git a/src/header/setjmp/src/impl/x86_64/setjmp.s b/src/header/setjmp/impl/x86_64/setjmp.s similarity index 100% rename from src/header/setjmp/src/impl/x86_64/setjmp.s rename to src/header/setjmp/impl/x86_64/setjmp.s diff --git a/src/header/setjmp/src/lib.rs b/src/header/setjmp/mod.rs similarity index 100% rename from src/header/setjmp/src/lib.rs rename to src/header/setjmp/mod.rs diff --git a/src/lib.rs b/src/lib.rs index 28f7d58d0d..b624efe17e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,6 +34,7 @@ extern crate spin; mod macros; pub mod header; pub mod platform; +pub mod start; use platform::{Allocator, Pal, Sys}; diff --git a/src/start.rs b/src/start.rs index 235e8783c2..e628c4f0df 100644 --- a/src/start.rs +++ b/src/start.rs @@ -1,6 +1,9 @@ use alloc::Vec; use core::ptr; +use header::stdio; +use platform; +use platform::{Pal, Sys}; use platform::types::*; #[repr(C)] @@ -25,7 +28,7 @@ impl Stack { #[inline(never)] #[no_mangle] -pub unsafe extern "C" fn _start_rust(sp: &'static Stack) -> ! { +pub unsafe extern "C" fn relibc_start(sp: &'static Stack) -> ! { extern "C" { fn main(argc: isize, argv: *const *const c_char, envp: *const *const c_char) -> c_int; } From 124e118f9f5ad9c2383afb1e9f2d6cbf3edc0fae Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sun, 26 Aug 2018 12:35:41 -0600 Subject: [PATCH 11/19] Fix makefile --- Makefile | 17 +++++++++-------- header.sh => include.sh | 4 ++-- 2 files changed, 11 insertions(+), 10 deletions(-) rename header.sh => include.sh (76%) diff --git a/Makefile b/Makefile index c30f02b7db..0f1d15e9ac 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,7 @@ SRC=\ src/*/*/* \ src/*/*/*/* -.PHONY: all clean fmt install libc libm test +.PHONY: all clean fmt include install libc libm test all: | libc libm @@ -45,18 +45,19 @@ install: all cp -rv "openlibm/src"/*.h "$(DESTDIR)/include" cp -v "$(BUILD)/openlibm/libopenlibm.a" "$(DESTDIR)/lib/libm.a" -header: - mkdir -p header - ./header.sh - touch header - -libc: $(BUILD)/release/libc.a $(BUILD)/release/crt0.o +libc: $(BUILD)/include $(BUILD)/release/libc.a $(BUILD)/release/crt0.o libm: $(BUILD)/openlibm/libopenlibm.a test: all make -C tests run +$(BUILD)/include: $(SRC) + rm -rf $@ $@.partial + mkdir -p $@.partial + ./include.sh $@.partial + mv $@.partial $@ + $(BUILD)/debug/libc.a: $(SRC) cargo build $(CARGOFLAGS) touch $@ @@ -80,5 +81,5 @@ $(BUILD)/openlibm: openlibm mv $@.partial $@ touch $@ -$(BUILD)/openlibm/libopenlibm.a: $(BUILD)/openlibm +$(BUILD)/openlibm/libopenlibm.a: $(BUILD)/openlibm $(BUILD)/include make CC=$(CC) CPPFLAGS="-fno-stack-protector -I$(shell pwd)/include -I $(shell pwd)/target/include" -C $< libopenlibm.a diff --git a/header.sh b/include.sh similarity index 76% rename from header.sh rename to include.sh index 2c835809c2..b9b7cc1567 100755 --- a/header.sh +++ b/include.sh @@ -2,7 +2,7 @@ set -ex -header="$(realpath header)" +include="$(realpath "$1")" cbindgen="$(realpath cbindgen)" for config in src/header/*/cbindgen.toml @@ -11,6 +11,6 @@ do name="$(basename "$dir")" pushd "$dir" cargo run --release --manifest-path "$cbindgen/Cargo.toml" -- \ - -c cbindgen.toml -o "$header/$name.h" mod.rs + -c cbindgen.toml -o "$include/$name.h" mod.rs popd done From 6418f893e44bc2c9a26405865a2f2ff80a62e76a Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sun, 26 Aug 2018 12:40:19 -0600 Subject: [PATCH 12/19] Fix headers with directories --- include.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/include.sh b/include.sh index b9b7cc1567..82f7f8a523 100755 --- a/include.sh +++ b/include.sh @@ -9,8 +9,12 @@ for config in src/header/*/cbindgen.toml do dir="$(dirname "$config")" name="$(basename "$dir")" - pushd "$dir" - cargo run --release --manifest-path "$cbindgen/Cargo.toml" -- \ - -c cbindgen.toml -o "$include/$name.h" mod.rs - popd + if [ "${name:0:1}" != "_" ] + then + header="$include/${name/_/\/}.h" + pushd "$dir" + cargo run --release --manifest-path "$cbindgen/Cargo.toml" -- \ + -c cbindgen.toml -o "$header" mod.rs + popd + fi done From 7ab700315dc4954cc62b88083eb33ffe6e8f4d70 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sun, 26 Aug 2018 15:15:29 -0600 Subject: [PATCH 13/19] Fix warnings and add c_str --- Makefile | 14 +- src/c_str.rs | 1238 ++++++++++++++++++++++++++++++++++ src/header/arpa_inet/mod.rs | 3 +- src/header/ctype/mod.rs | 1 - src/header/dirent/mod.rs | 2 +- src/header/fcntl/mod.rs | 1 - src/header/fenv/mod.rs | 1 - src/header/float/mod.rs | 1 - src/header/fnmatch/mod.rs | 1 - src/header/grp/mod.rs | 1 - src/header/inttypes/mod.rs | 2 +- src/header/locale/mod.rs | 1 - src/header/netinet_in/mod.rs | 3 +- src/header/semaphore/mod.rs | 1 - src/header/stdio/mod.rs | 2 +- src/header/stdlib/mod.rs | 4 +- src/header/string/mod.rs | 1 - src/header/strings/mod.rs | 1 - src/header/sys_ioctl/mod.rs | 1 - src/header/sys_mman/mod.rs | 1 - src/header/sys_select/mod.rs | 3 - src/header/sys_socket/mod.rs | 1 - src/header/sys_un/mod.rs | 1 - src/header/sys_wait/mod.rs | 1 - src/header/time/mod.rs | 1 - src/header/unistd/mod.rs | 2 +- src/header/utime/mod.rs | 1 - src/header/wchar/mod.rs | 1 - src/header/wctype/mod.rs | 1 - src/lib.rs | 1 + 30 files changed, 1254 insertions(+), 39 deletions(-) create mode 100644 src/c_str.rs diff --git a/Makefile b/Makefile index 0f1d15e9ac..6d901b6181 100644 --- a/Makefile +++ b/Makefile @@ -45,19 +45,13 @@ install: all cp -rv "openlibm/src"/*.h "$(DESTDIR)/include" cp -v "$(BUILD)/openlibm/libopenlibm.a" "$(DESTDIR)/lib/libm.a" -libc: $(BUILD)/include $(BUILD)/release/libc.a $(BUILD)/release/crt0.o +libc: $(BUILD)/release/libc.a $(BUILD)/release/crt0.o $(BUILD)/include libm: $(BUILD)/openlibm/libopenlibm.a test: all make -C tests run -$(BUILD)/include: $(SRC) - rm -rf $@ $@.partial - mkdir -p $@.partial - ./include.sh $@.partial - mv $@.partial $@ - $(BUILD)/debug/libc.a: $(SRC) cargo build $(CARGOFLAGS) touch $@ @@ -74,6 +68,12 @@ $(BUILD)/release/crt0.o: $(SRC) CARGO_INCREMENTAL=0 cargo rustc --release --manifest-path src/crt0/Cargo.toml $(CARGOFLAGS) -- --emit obj=$@ touch $@ +$(BUILD)/include: $(SRC) + rm -rf $@ $@.partial + mkdir -p $@.partial + ./include.sh $@.partial + mv $@.partial $@ + $(BUILD)/openlibm: openlibm rm -rf $@ $@.partial mkdir -p $(BUILD) diff --git a/src/c_str.rs b/src/c_str.rs new file mode 100644 index 0000000000..1ad8f2ea6c --- /dev/null +++ b/src/c_str.rs @@ -0,0 +1,1238 @@ +// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use alloc::arc::Arc; +use alloc::borrow::{Borrow, Cow, ToOwned}; +use alloc::boxed::Box; +use alloc::rc::Rc; +use alloc::string::String; +use alloc::vec::Vec; +use core::ascii; +use core::cmp::Ordering; +use core::fmt::{self, Write}; +use core::mem; +use core::ops; +use core::ptr; +use core::slice; +use core::str::{self, Utf8Error}; + +use header::string::strlen; +use platform::types::*; + +pub fn memchr(needle: u8, haystack: &[u8]) -> Option { + use header::string; + + let p = unsafe { + string::memchr( + haystack.as_ptr() as *const c_void, + needle as c_int, + haystack.len()) + }; + if p.is_null() { + None + } else { + Some(p as usize - (haystack.as_ptr() as usize)) + } +} + +/// A type representing an owned, C-compatible, nul-terminated string with no nul bytes in the +/// middle. +/// +/// This type serves the purpose of being able to safely generate a +/// C-compatible string from a Rust byte slice or vector. An instance of this +/// type is a static guarantee that the underlying bytes contain no interior 0 +/// bytes ("nul characters") and that the final byte is 0 ("nul terminator"). +/// +/// `CString` is to [`CStr`] as [`String`] is to [`&str`]: the former +/// in each pair are owned strings; the latter are borrowed +/// references. +/// +/// # Creating a `CString` +/// +/// A `CString` is created from either a byte slice or a byte vector, +/// or anything that implements [`Into`]`<`[`Vec`]`<`[`u8`]`>>` (for +/// example, you can build a `CString` straight out of a [`String`] or +/// a [`&str`], since both implement that trait). +/// +/// The [`new`] method will actually check that the provided `&[u8]` +/// does not have 0 bytes in the middle, and return an error if it +/// finds one. +/// +/// # Extracting a raw pointer to the whole C string +/// +/// `CString` implements a [`as_ptr`] method through the [`Deref`] +/// trait. This method will give you a `*const c_char` which you can +/// feed directly to extern functions that expect a nul-terminated +/// string, like C's `strdup()`. +/// +/// # Extracting a slice of the whole C string +/// +/// Alternatively, you can obtain a `&[`[`u8`]`]` slice from a +/// `CString` with the [`as_bytes`] method. Slices produced in this +/// way do *not* contain the trailing nul terminator. This is useful +/// when you will be calling an extern function that takes a `*const +/// u8` argument which is not necessarily nul-terminated, plus another +/// argument with the length of the string — like C's `strndup()`. +/// You can of course get the slice's length with its +/// [`len`][slice.len] method. +/// +/// If you need a `&[`[`u8`]`]` slice *with* the nul terminator, you +/// can use [`as_bytes_with_nul`] instead. +/// +/// Once you have the kind of slice you need (with or without a nul +/// terminator), you can call the slice's own +/// [`as_ptr`][slice.as_ptr] method to get a raw pointer to pass to +/// extern functions. See the documentation for that function for a +/// discussion on ensuring the lifetime of the raw pointer. +/// +/// [`Into`]: ../convert/trait.Into.html +/// [`Vec`]: ../vec/struct.Vec.html +/// [`String`]: ../string/struct.String.html +/// [`&str`]: ../primitive.str.html +/// [`u8`]: ../primitive.u8.html +/// [`new`]: #method.new +/// [`as_bytes`]: #method.as_bytes +/// [`as_bytes_with_nul`]: #method.as_bytes_with_nul +/// [`as_ptr`]: #method.as_ptr +/// [slice.as_ptr]: ../primitive.slice.html#method.as_ptr +/// [slice.len]: ../primitive.slice.html#method.len +/// [`Deref`]: ../ops/trait.Deref.html +/// [`CStr`]: struct.CStr.html +/// +/// # Examples +/// +/// ```ignore (extern-declaration) +/// # fn main() { +/// use std::ffi::CString; +/// use std::os::raw::c_char; +/// +/// extern { +/// fn my_printer(s: *const c_char); +/// } +/// +/// // We are certain that our string doesn't have 0 bytes in the middle, +/// // so we can .unwrap() +/// let c_to_print = CString::new("Hello, world!").unwrap(); +/// unsafe { +/// my_printer(c_to_print.as_ptr()); +/// } +/// # } +/// ``` +/// +/// # Safety +/// +/// `CString` is intended for working with traditional C-style strings +/// (a sequence of non-nul bytes terminated by a single nul byte); the +/// primary use case for these kinds of strings is interoperating with C-like +/// code. Often you will need to transfer ownership to/from that external +/// code. It is strongly recommended that you thoroughly read through the +/// documentation of `CString` before use, as improper ownership management +/// of `CString` instances can lead to invalid memory accesses, memory leaks, +/// and other memory errors. + +#[derive(PartialEq, PartialOrd, Eq, Ord, Hash, Clone)] +pub struct CString { + // Invariant 1: the slice ends with a zero byte and has a length of at least one. + // Invariant 2: the slice contains only one zero byte. + // Improper usage of unsafe function can break Invariant 2, but not Invariant 1. + inner: Box<[u8]>, +} + +/// Representation of a borrowed C string. +/// +/// This type represents a borrowed reference to a nul-terminated +/// array of bytes. It can be constructed safely from a `&[`[`u8`]`]` +/// slice, or unsafely from a raw `*const c_char`. It can then be +/// converted to a Rust [`&str`] by performing UTF-8 validation, or +/// into an owned [`CString`]. +/// +/// `CStr` is to [`CString`] as [`&str`] is to [`String`]: the former +/// in each pair are borrowed references; the latter are owned +/// strings. +/// +/// Note that this structure is **not** `repr(C)` and is not recommended to be +/// placed in the signatures of FFI functions. Instead, safe wrappers of FFI +/// functions may leverage the unsafe [`from_ptr`] constructor to provide a safe +/// interface to other consumers. +/// +/// # Examples +/// +/// Inspecting a foreign C string: +/// +/// ```ignore (extern-declaration) +/// use std::ffi::CStr; +/// use std::os::raw::c_char; +/// +/// extern { fn my_string() -> *const c_char; } +/// +/// unsafe { +/// let slice = CStr::from_ptr(my_string()); +/// println!("string buffer size without nul terminator: {}", slice.to_bytes().len()); +/// } +/// ``` +/// +/// Passing a Rust-originating C string: +/// +/// ```ignore (extern-declaration) +/// use std::ffi::{CString, CStr}; +/// use std::os::raw::c_char; +/// +/// fn work(data: &CStr) { +/// extern { fn work_with(data: *const c_char); } +/// +/// unsafe { work_with(data.as_ptr()) } +/// } +/// +/// let s = CString::new("data data data data").unwrap(); +/// work(&s); +/// ``` +/// +/// Converting a foreign C string into a Rust [`String`]: +/// +/// ```ignore (extern-declaration) +/// use std::ffi::CStr; +/// use std::os::raw::c_char; +/// +/// extern { fn my_string() -> *const c_char; } +/// +/// fn my_string_safe() -> String { +/// unsafe { +/// CStr::from_ptr(my_string()).to_string_lossy().into_owned() +/// } +/// } +/// +/// println!("string: {}", my_string_safe()); +/// ``` +/// +/// [`u8`]: ../primitive.u8.html +/// [`&str`]: ../primitive.str.html +/// [`String`]: ../string/struct.String.html +/// [`CString`]: struct.CString.html +/// [`from_ptr`]: #method.from_ptr +#[derive(Hash)] +pub struct CStr { + // FIXME: this should not be represented with a DST slice but rather with + // just a raw `c_char` along with some form of marker to make + // this an unsized type. Essentially `sizeof(&CStr)` should be the + // same as `sizeof(&c_char)` but `CStr` should be an unsized type. + inner: [c_char] +} + +/// An error indicating that an interior nul byte was found. +/// +/// While Rust strings may contain nul bytes in the middle, C strings +/// can't, as that byte would effectively truncate the string. +/// +/// This error is created by the [`new`][`CString::new`] method on +/// [`CString`]. See its documentation for more. +/// +/// [`CString`]: struct.CString.html +/// [`CString::new`]: struct.CString.html#method.new +/// +/// # Examples +/// +/// ``` +/// use std::ffi::{CString, NulError}; +/// +/// let _: NulError = CString::new(b"f\0oo".to_vec()).unwrap_err(); +/// ``` +#[derive(Clone, PartialEq, Eq, Debug)] +pub struct NulError(usize, Vec); + +/// An error indicating that a nul byte was not in the expected position. +/// +/// The slice used to create a [`CStr`] must have one and only one nul +/// byte at the end of the slice. +/// +/// This error is created by the +/// [`from_bytes_with_nul`][`CStr::from_bytes_with_nul`] method on +/// [`CStr`]. See its documentation for more. +/// +/// [`CStr`]: struct.CStr.html +/// [`CStr::from_bytes_with_nul`]: struct.CStr.html#method.from_bytes_with_nul +/// +/// # Examples +/// +/// ``` +/// use std::ffi::{CStr, FromBytesWithNulError}; +/// +/// let _: FromBytesWithNulError = CStr::from_bytes_with_nul(b"f\0oo").unwrap_err(); +/// ``` +#[derive(Clone, PartialEq, Eq, Debug)] +pub struct FromBytesWithNulError { + kind: FromBytesWithNulErrorKind, +} + +#[derive(Clone, PartialEq, Eq, Debug)] +enum FromBytesWithNulErrorKind { + InteriorNul(usize), + NotNulTerminated, +} + +impl FromBytesWithNulError { + fn interior_nul(pos: usize) -> FromBytesWithNulError { + FromBytesWithNulError { + kind: FromBytesWithNulErrorKind::InteriorNul(pos), + } + } + fn not_nul_terminated() -> FromBytesWithNulError { + FromBytesWithNulError { + kind: FromBytesWithNulErrorKind::NotNulTerminated, + } + } + + fn description(&self) -> &str { + match self.kind { + FromBytesWithNulErrorKind::InteriorNul(..) => + "data provided contains an interior nul byte", + FromBytesWithNulErrorKind::NotNulTerminated => + "data provided is not nul terminated", + } + } +} + +/// An error indicating invalid UTF-8 when converting a [`CString`] into a [`String`]. +/// +/// `CString` is just a wrapper over a buffer of bytes with a nul +/// terminator; [`into_string`][`CString::into_string`] performs UTF-8 +/// validation on those bytes and may return this error. +/// +/// This `struct` is created by the +/// [`into_string`][`CString::into_string`] method on [`CString`]. See +/// its documentation for more. +/// +/// [`String`]: ../string/struct.String.html +/// [`CString`]: struct.CString.html +/// [`CString::into_string`]: struct.CString.html#method.into_string +#[derive(Clone, PartialEq, Eq, Debug)] +pub struct IntoStringError { + inner: CString, + error: Utf8Error, +} + +impl CString { + /// Creates a new C-compatible string from a container of bytes. + /// + /// This function will consume the provided data and use the + /// underlying bytes to construct a new string, ensuring that + /// there is a trailing 0 byte. This trailing 0 byte will be + /// appended by this function; the provided data should *not* + /// contain any 0 bytes in it. + /// + /// # Examples + /// + /// ```ignore (extern-declaration) + /// use std::ffi::CString; + /// use std::os::raw::c_char; + /// + /// extern { fn puts(s: *const c_char); } + /// + /// let to_print = CString::new("Hello!").unwrap(); + /// unsafe { + /// puts(to_print.as_ptr()); + /// } + /// ``` + /// + /// # Errors + /// + /// This function will return an error if the supplied bytes contain an + /// internal 0 byte. The [`NulError`] returned will contain the bytes as well as + /// the position of the nul byte. + /// + /// [`NulError`]: struct.NulError.html + pub fn new>>(t: T) -> Result { + Self::_new(t.into()) + } + + fn _new(bytes: Vec) -> Result { + match memchr(0, &bytes) { + Some(i) => Err(NulError(i, bytes)), + None => Ok(unsafe { CString::from_vec_unchecked(bytes) }), + } + } + + /// Creates a C-compatible string by consuming a byte vector, + /// without checking for interior 0 bytes. + /// + /// This method is equivalent to [`new`] except that no runtime assertion + /// is made that `v` contains no 0 bytes, and it requires an actual + /// byte vector, not anything that can be converted to one with Into. + /// + /// [`new`]: #method.new + /// + /// # Examples + /// + /// ``` + /// use std::ffi::CString; + /// + /// let raw = b"foo".to_vec(); + /// unsafe { + /// let c_string = CString::from_vec_unchecked(raw); + /// } + /// ``` + pub unsafe fn from_vec_unchecked(mut v: Vec) -> CString { + v.reserve_exact(1); + v.push(0); + CString { inner: v.into_boxed_slice() } + } + + /// Retakes ownership of a `CString` that was transferred to C via [`into_raw`]. + /// + /// Additionally, the length of the string will be recalculated from the pointer. + /// + /// # Safety + /// + /// This should only ever be called with a pointer that was earlier + /// obtained by calling [`into_raw`] on a `CString`. Other usage (e.g. trying to take + /// ownership of a string that was allocated by foreign code) is likely to lead + /// to undefined behavior or allocator corruption. + /// + /// > **Note:** If you need to borrow a string that was allocated by + /// > foreign code, use [`CStr`]. If you need to take ownership of + /// > a string that was allocated by foreign code, you will need to + /// > make your own provisions for freeing it appropriately, likely + /// > with the foreign code's API to do that. + /// + /// [`into_raw`]: #method.into_raw + /// [`CStr`]: struct.CStr.html + /// + /// # Examples + /// + /// Create a `CString`, pass ownership to an `extern` function (via raw pointer), then retake + /// ownership with `from_raw`: + /// + /// ```ignore (extern-declaration) + /// use std::ffi::CString; + /// use std::os::raw::c_char; + /// + /// extern { + /// fn some_extern_function(s: *mut c_char); + /// } + /// + /// let c_string = CString::new("Hello!").unwrap(); + /// let raw = c_string.into_raw(); + /// unsafe { + /// some_extern_function(raw); + /// let c_string = CString::from_raw(raw); + /// } + /// ``` + pub unsafe fn from_raw(ptr: *mut c_char) -> CString { + let len = strlen(ptr) + 1; // Including the NUL byte + let slice = slice::from_raw_parts_mut(ptr, len as usize); + CString { inner: Box::from_raw(slice as *mut [c_char] as *mut [u8]) } + } + + /// Consumes the `CString` and transfers ownership of the string to a C caller. + /// + /// The pointer which this function returns must be returned to Rust and reconstituted using + /// [`from_raw`] to be properly deallocated. Specifically, one + /// should *not* use the standard C `free()` function to deallocate + /// this string. + /// + /// Failure to call [`from_raw`] will lead to a memory leak. + /// + /// [`from_raw`]: #method.from_raw + /// + /// # Examples + /// + /// ``` + /// use std::ffi::CString; + /// + /// let c_string = CString::new("foo").unwrap(); + /// + /// let ptr = c_string.into_raw(); + /// + /// unsafe { + /// assert_eq!(b'f', *ptr as u8); + /// assert_eq!(b'o', *ptr.offset(1) as u8); + /// assert_eq!(b'o', *ptr.offset(2) as u8); + /// assert_eq!(b'\0', *ptr.offset(3) as u8); + /// + /// // retake pointer to free memory + /// let _ = CString::from_raw(ptr); + /// } + /// ``` + #[inline] + pub fn into_raw(self) -> *mut c_char { + Box::into_raw(self.into_inner()) as *mut c_char + } + + /// Converts the `CString` into a [`String`] if it contains valid UTF-8 data. + /// + /// On failure, ownership of the original `CString` is returned. + /// + /// [`String`]: ../string/struct.String.html + /// + /// # Examples + /// + /// ``` + /// use std::ffi::CString; + /// + /// let valid_utf8 = vec![b'f', b'o', b'o']; + /// let cstring = CString::new(valid_utf8).unwrap(); + /// assert_eq!(cstring.into_string().unwrap(), "foo"); + /// + /// let invalid_utf8 = vec![b'f', 0xff, b'o', b'o']; + /// let cstring = CString::new(invalid_utf8).unwrap(); + /// let err = cstring.into_string().err().unwrap(); + /// assert_eq!(err.utf8_error().valid_up_to(), 1); + /// ``` + + pub fn into_string(self) -> Result { + String::from_utf8(self.into_bytes()) + .map_err(|e| IntoStringError { + error: e.utf8_error(), + inner: unsafe { CString::from_vec_unchecked(e.into_bytes()) }, + }) + } + + /// Consumes the `CString` and returns the underlying byte buffer. + /// + /// The returned buffer does **not** contain the trailing nul + /// terminator, and it is guaranteed to not have any interior nul + /// bytes. + /// + /// # Examples + /// + /// ``` + /// use std::ffi::CString; + /// + /// let c_string = CString::new("foo").unwrap(); + /// let bytes = c_string.into_bytes(); + /// assert_eq!(bytes, vec![b'f', b'o', b'o']); + /// ``` + pub fn into_bytes(self) -> Vec { + let mut vec = self.into_inner().into_vec(); + let _nul = vec.pop(); + debug_assert_eq!(_nul, Some(0u8)); + vec + } + + /// Equivalent to the [`into_bytes`] function except that the returned vector + /// includes the trailing nul terminator. + /// + /// [`into_bytes`]: #method.into_bytes + /// + /// # Examples + /// + /// ``` + /// use std::ffi::CString; + /// + /// let c_string = CString::new("foo").unwrap(); + /// let bytes = c_string.into_bytes_with_nul(); + /// assert_eq!(bytes, vec![b'f', b'o', b'o', b'\0']); + /// ``` + pub fn into_bytes_with_nul(self) -> Vec { + self.into_inner().into_vec() + } + + /// Returns the contents of this `CString` as a slice of bytes. + /// + /// The returned slice does **not** contain the trailing nul + /// terminator, and it is guaranteed to not have any interior nul + /// bytes. If you need the nul terminator, use + /// [`as_bytes_with_nul`] instead. + /// + /// [`as_bytes_with_nul`]: #method.as_bytes_with_nul + /// + /// # Examples + /// + /// ``` + /// use std::ffi::CString; + /// + /// let c_string = CString::new("foo").unwrap(); + /// let bytes = c_string.as_bytes(); + /// assert_eq!(bytes, &[b'f', b'o', b'o']); + /// ``` + #[inline] + pub fn as_bytes(&self) -> &[u8] { + &self.inner[..self.inner.len() - 1] + } + + /// Equivalent to the [`as_bytes`] function except that the returned slice + /// includes the trailing nul terminator. + /// + /// [`as_bytes`]: #method.as_bytes + /// + /// # Examples + /// + /// ``` + /// use std::ffi::CString; + /// + /// let c_string = CString::new("foo").unwrap(); + /// let bytes = c_string.as_bytes_with_nul(); + /// assert_eq!(bytes, &[b'f', b'o', b'o', b'\0']); + /// ``` + #[inline] + pub fn as_bytes_with_nul(&self) -> &[u8] { + &self.inner + } + + /// Extracts a [`CStr`] slice containing the entire string. + /// + /// [`CStr`]: struct.CStr.html + /// + /// # Examples + /// + /// ``` + /// use std::ffi::{CString, CStr}; + /// + /// let c_string = CString::new(b"foo".to_vec()).unwrap(); + /// let c_str = c_string.as_c_str(); + /// assert_eq!(c_str, CStr::from_bytes_with_nul(b"foo\0").unwrap()); + /// ``` + #[inline] + pub fn as_c_str(&self) -> &CStr { + &*self + } + + /// Converts this `CString` into a boxed [`CStr`]. + /// + /// [`CStr`]: struct.CStr.html + /// + /// # Examples + /// + /// ``` + /// use std::ffi::{CString, CStr}; + /// + /// let c_string = CString::new(b"foo".to_vec()).unwrap(); + /// let boxed = c_string.into_boxed_c_str(); + /// assert_eq!(&*boxed, CStr::from_bytes_with_nul(b"foo\0").unwrap()); + /// ``` + pub fn into_boxed_c_str(self) -> Box { + unsafe { Box::from_raw(Box::into_raw(self.into_inner()) as *mut CStr) } + } + + // Bypass "move out of struct which implements [`Drop`] trait" restriction. + /// + /// [`Drop`]: ../ops/trait.Drop.html + fn into_inner(self) -> Box<[u8]> { + unsafe { + let result = ptr::read(&self.inner); + mem::forget(self); + result + } + } +} + +// Turns this `CString` into an empty string to prevent +// memory unsafe code from working by accident. Inline +// to prevent LLVM from optimizing it away in debug builds. +impl Drop for CString { + #[inline] + fn drop(&mut self) { + unsafe { *self.inner.get_unchecked_mut(0) = 0; } + } +} + +impl ops::Deref for CString { + type Target = CStr; + + #[inline] + fn deref(&self) -> &CStr { + unsafe { CStr::from_bytes_with_nul_unchecked(self.as_bytes_with_nul()) } + } +} + +impl fmt::Debug for CString { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&**self, f) + } +} + +impl From for Vec { + /// Converts a [`CString`] into a [`Vec`]``. + /// + /// The conversion consumes the [`CString`], and removes the terminating NUL byte. + /// + /// [`Vec`]: ../vec/struct.Vec.html + /// [`CString`]: ../ffi/struct.CString.html + #[inline] + fn from(s: CString) -> Vec { + s.into_bytes() + } +} + +impl fmt::Debug for CStr { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "\"")?; + for byte in self.to_bytes().iter().flat_map(|&b| ascii::escape_default(b)) { + f.write_char(byte as char)?; + } + write!(f, "\"") + } +} + +impl<'a> Default for &'a CStr { + fn default() -> &'a CStr { + const SLICE: &'static [c_char] = &[0]; + unsafe { CStr::from_ptr(SLICE.as_ptr()) } + } +} + +impl Default for CString { + /// Creates an empty `CString`. + fn default() -> CString { + let a: &CStr = Default::default(); + a.to_owned() + } +} + +impl Borrow for CString { + #[inline] + fn borrow(&self) -> &CStr { self } +} + +impl<'a> From> for CString { + #[inline] + fn from(s: Cow<'a, CStr>) -> Self { + s.into_owned() + } +} + +impl<'a> From<&'a CStr> for Box { + fn from(s: &'a CStr) -> Box { + let boxed: Box<[u8]> = Box::from(s.to_bytes_with_nul()); + unsafe { Box::from_raw(Box::into_raw(boxed) as *mut CStr) } + } +} + +impl From> for CString { + /// Converts a [`Box`]`` into a [`CString`] without copying or allocating. + /// + /// [`Box`]: ../boxed/struct.Box.html + /// [`CString`]: ../ffi/struct.CString.html + #[inline] + fn from(s: Box) -> CString { + s.into_c_string() + } +} + +impl Clone for Box { + #[inline] + fn clone(&self) -> Self { + (**self).into() + } +} + +impl From for Box { + /// Converts a [`CString`] into a [`Box`]`` without copying or allocating. + /// + /// [`CString`]: ../ffi/struct.CString.html + /// [`Box`]: ../boxed/struct.Box.html + #[inline] + fn from(s: CString) -> Box { + s.into_boxed_c_str() + } +} + +impl<'a> From for Cow<'a, CStr> { + #[inline] + fn from(s: CString) -> Cow<'a, CStr> { + Cow::Owned(s) + } +} + +impl<'a> From<&'a CStr> for Cow<'a, CStr> { + #[inline] + fn from(s: &'a CStr) -> Cow<'a, CStr> { + Cow::Borrowed(s) + } +} + +impl<'a> From<&'a CString> for Cow<'a, CStr> { + #[inline] + fn from(s: &'a CString) -> Cow<'a, CStr> { + Cow::Borrowed(s.as_c_str()) + } +} + +impl From for Arc { + /// Converts a [`CString`] into a [`Arc`]`` without copying or allocating. + /// + /// [`CString`]: ../ffi/struct.CString.html + /// [`Arc`]: ../sync/struct.Arc.html + #[inline] + fn from(s: CString) -> Arc { + let arc: Arc<[u8]> = Arc::from(s.into_inner()); + unsafe { Arc::from_raw(Arc::into_raw(arc) as *const CStr) } + } +} + +impl<'a> From<&'a CStr> for Arc { + #[inline] + fn from(s: &CStr) -> Arc { + let arc: Arc<[u8]> = Arc::from(s.to_bytes_with_nul()); + unsafe { Arc::from_raw(Arc::into_raw(arc) as *const CStr) } + } +} + +impl From for Rc { + /// Converts a [`CString`] into a [`Rc`]`` without copying or allocating. + /// + /// [`CString`]: ../ffi/struct.CString.html + /// [`Rc`]: ../rc/struct.Rc.html + #[inline] + fn from(s: CString) -> Rc { + let rc: Rc<[u8]> = Rc::from(s.into_inner()); + unsafe { Rc::from_raw(Rc::into_raw(rc) as *const CStr) } + } +} + +impl<'a> From<&'a CStr> for Rc { + #[inline] + fn from(s: &CStr) -> Rc { + let rc: Rc<[u8]> = Rc::from(s.to_bytes_with_nul()); + unsafe { Rc::from_raw(Rc::into_raw(rc) as *const CStr) } + } +} + +impl Default for Box { + fn default() -> Box { + let boxed: Box<[u8]> = Box::from([0]); + unsafe { Box::from_raw(Box::into_raw(boxed) as *mut CStr) } + } +} + +impl NulError { + /// Returns the position of the nul byte in the slice that caused + /// [`CString::new`] to fail. + /// + /// [`CString::new`]: struct.CString.html#method.new + /// + /// # Examples + /// + /// ``` + /// use std::ffi::CString; + /// + /// let nul_error = CString::new("foo\0bar").unwrap_err(); + /// assert_eq!(nul_error.nul_position(), 3); + /// + /// let nul_error = CString::new("foo bar\0").unwrap_err(); + /// assert_eq!(nul_error.nul_position(), 7); + /// ``` + pub fn nul_position(&self) -> usize { self.0 } + + /// Consumes this error, returning the underlying vector of bytes which + /// generated the error in the first place. + /// + /// # Examples + /// + /// ``` + /// use std::ffi::CString; + /// + /// let nul_error = CString::new("foo\0bar").unwrap_err(); + /// assert_eq!(nul_error.into_vec(), b"foo\0bar"); + /// ``` + pub fn into_vec(self) -> Vec { self.1 } + + fn description(&self) -> &str { "nul byte found in data" } +} + +impl fmt::Display for NulError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "nul byte found in provided data at position: {}", self.0) + } +} + +impl fmt::Display for FromBytesWithNulError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.write_str(self.description())?; + if let FromBytesWithNulErrorKind::InteriorNul(pos) = self.kind { + write!(f, " at byte pos {}", pos)?; + } + Ok(()) + } +} + +impl IntoStringError { + /// Consumes this error, returning original [`CString`] which generated the + /// error. + /// + /// [`CString`]: struct.CString.html + pub fn into_cstring(self) -> CString { + self.inner + } + + /// Access the underlying UTF-8 error that was the cause of this error. + pub fn utf8_error(&self) -> Utf8Error { + self.error + } + + fn description(&self) -> &str { + "C string contained non-utf8 bytes" + } +} + +impl fmt::Display for IntoStringError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.description().fmt(f) + } +} + +impl CStr { + /// Wraps a raw C string with a safe C string wrapper. + /// + /// This function will wrap the provided `ptr` with a `CStr` wrapper, which + /// allows inspection and interoperation of non-owned C strings. This method + /// is unsafe for a number of reasons: + /// + /// * There is no guarantee to the validity of `ptr`. + /// * The returned lifetime is not guaranteed to be the actual lifetime of + /// `ptr`. + /// * There is no guarantee that the memory pointed to by `ptr` contains a + /// valid nul terminator byte at the end of the string. + /// * It is not guaranteed that the memory pointed by `ptr` won't change + /// before the `CStr` has been destroyed. + /// + /// > **Note**: This operation is intended to be a 0-cost cast but it is + /// > currently implemented with an up-front calculation of the length of + /// > the string. This is not guaranteed to always be the case. + /// + /// # Examples + /// + /// ```ignore (extern-declaration) + /// # fn main() { + /// use std::ffi::CStr; + /// use std::os::raw::c_char; + /// + /// extern { + /// fn my_string() -> *const c_char; + /// } + /// + /// unsafe { + /// let slice = CStr::from_ptr(my_string()); + /// println!("string returned: {}", slice.to_str().unwrap()); + /// } + /// # } + /// ``` + pub unsafe fn from_ptr<'a>(ptr: *const c_char) -> &'a CStr { + let len = strlen(ptr); + let ptr = ptr as *const u8; + CStr::from_bytes_with_nul_unchecked(slice::from_raw_parts(ptr, len as usize + 1)) + } + + /// Creates a C string wrapper from a byte slice. + /// + /// This function will cast the provided `bytes` to a `CStr` + /// wrapper after ensuring that the byte slice is nul-terminated + /// and does not contain any interior nul bytes. + /// + /// # Examples + /// + /// ``` + /// use std::ffi::CStr; + /// + /// let cstr = CStr::from_bytes_with_nul(b"hello\0"); + /// assert!(cstr.is_ok()); + /// ``` + /// + /// Creating a `CStr` without a trailing nul terminator is an error: + /// + /// ``` + /// use std::ffi::CStr; + /// + /// let c_str = CStr::from_bytes_with_nul(b"hello"); + /// assert!(c_str.is_err()); + /// ``` + /// + /// Creating a `CStr` with an interior nul byte is an error: + /// + /// ``` + /// use std::ffi::CStr; + /// + /// let c_str = CStr::from_bytes_with_nul(b"he\0llo\0"); + /// assert!(c_str.is_err()); + /// ``` + pub fn from_bytes_with_nul(bytes: &[u8]) + -> Result<&CStr, FromBytesWithNulError> { + let nul_pos = memchr(0, bytes); + if let Some(nul_pos) = nul_pos { + if nul_pos + 1 != bytes.len() { + return Err(FromBytesWithNulError::interior_nul(nul_pos)); + } + Ok(unsafe { CStr::from_bytes_with_nul_unchecked(bytes) }) + } else { + Err(FromBytesWithNulError::not_nul_terminated()) + } + } + + /// Unsafely creates a C string wrapper from a byte slice. + /// + /// This function will cast the provided `bytes` to a `CStr` wrapper without + /// performing any sanity checks. The provided slice **must** be nul-terminated + /// and not contain any interior nul bytes. + /// + /// # Examples + /// + /// ``` + /// use std::ffi::{CStr, CString}; + /// + /// unsafe { + /// let cstring = CString::new("hello").unwrap(); + /// let cstr = CStr::from_bytes_with_nul_unchecked(cstring.to_bytes_with_nul()); + /// assert_eq!(cstr, &*cstring); + /// } + /// ``` + #[inline] + pub unsafe fn from_bytes_with_nul_unchecked(bytes: &[u8]) -> &CStr { + &*(bytes as *const [u8] as *const CStr) + } + + /// Returns the inner pointer to this C string. + /// + /// The returned pointer will be valid for as long as `self` is, and points + /// to a contiguous region of memory terminated with a 0 byte to represent + /// the end of the string. + /// + /// **WARNING** + /// + /// It is your responsibility to make sure that the underlying memory is not + /// freed too early. For example, the following code will cause undefined + /// behavior when `ptr` is used inside the `unsafe` block: + /// + /// ```no_run + /// # #![allow(unused_must_use)] + /// use std::ffi::{CString}; + /// + /// let ptr = CString::new("Hello").unwrap().as_ptr(); + /// unsafe { + /// // `ptr` is dangling + /// *ptr; + /// } + /// ``` + /// + /// This happens because the pointer returned by `as_ptr` does not carry any + /// lifetime information and the [`CString`] is deallocated immediately after + /// the `CString::new("Hello").unwrap().as_ptr()` expression is evaluated. + /// To fix the problem, bind the `CString` to a local variable: + /// + /// ```no_run + /// # #![allow(unused_must_use)] + /// use std::ffi::{CString}; + /// + /// let hello = CString::new("Hello").unwrap(); + /// let ptr = hello.as_ptr(); + /// unsafe { + /// // `ptr` is valid because `hello` is in scope + /// *ptr; + /// } + /// ``` + /// + /// This way, the lifetime of the `CString` in `hello` encompasses + /// the lifetime of `ptr` and the `unsafe` block. + /// + /// [`CString`]: struct.CString.html + #[inline] + pub fn as_ptr(&self) -> *const c_char { + self.inner.as_ptr() + } + + /// Converts this C string to a byte slice. + /// + /// The returned slice will **not** contain the trailing nul terminator that this C + /// string has. + /// + /// > **Note**: This method is currently implemented as a constant-time + /// > cast, but it is planned to alter its definition in the future to + /// > perform the length calculation whenever this method is called. + /// + /// # Examples + /// + /// ``` + /// use std::ffi::CStr; + /// + /// let c_str = CStr::from_bytes_with_nul(b"foo\0").unwrap(); + /// assert_eq!(c_str.to_bytes(), b"foo"); + /// ``` + #[inline] + pub fn to_bytes(&self) -> &[u8] { + let bytes = self.to_bytes_with_nul(); + &bytes[..bytes.len() - 1] + } + + /// Converts this C string to a byte slice containing the trailing 0 byte. + /// + /// This function is the equivalent of [`to_bytes`] except that it will retain + /// the trailing nul terminator instead of chopping it off. + /// + /// > **Note**: This method is currently implemented as a 0-cost cast, but + /// > it is planned to alter its definition in the future to perform the + /// > length calculation whenever this method is called. + /// + /// [`to_bytes`]: #method.to_bytes + /// + /// # Examples + /// + /// ``` + /// use std::ffi::CStr; + /// + /// let c_str = CStr::from_bytes_with_nul(b"foo\0").unwrap(); + /// assert_eq!(c_str.to_bytes_with_nul(), b"foo\0"); + /// ``` + #[inline] + pub fn to_bytes_with_nul(&self) -> &[u8] { + unsafe { &*(&self.inner as *const [c_char] as *const [u8]) } + } + + /// Yields a [`&str`] slice if the `CStr` contains valid UTF-8. + /// + /// If the contents of the `CStr` are valid UTF-8 data, this + /// function will return the corresponding [`&str`] slice. Otherwise, + /// it will return an error with details of where UTF-8 validation failed. + /// + /// > **Note**: This method is currently implemented to check for validity + /// > after a constant-time cast, but it is planned to alter its definition + /// > in the future to perform the length calculation in addition to the + /// > UTF-8 check whenever this method is called. + /// + /// [`&str`]: ../primitive.str.html + /// + /// # Examples + /// + /// ``` + /// use std::ffi::CStr; + /// + /// let c_str = CStr::from_bytes_with_nul(b"foo\0").unwrap(); + /// assert_eq!(c_str.to_str(), Ok("foo")); + /// ``` + pub fn to_str(&self) -> Result<&str, str::Utf8Error> { + // NB: When CStr is changed to perform the length check in .to_bytes() + // instead of in from_ptr(), it may be worth considering if this should + // be rewritten to do the UTF-8 check inline with the length calculation + // instead of doing it afterwards. + str::from_utf8(self.to_bytes()) + } + + /// Converts a `CStr` into a [`Cow`]`<`[`str`]`>`. + /// + /// If the contents of the `CStr` are valid UTF-8 data, this + /// function will return a [`Cow`]`::`[`Borrowed`]`(`[`&str`]`)` + /// with the the corresponding [`&str`] slice. Otherwise, it will + /// replace any invalid UTF-8 sequences with + /// [`U+FFFD REPLACEMENT CHARACTER`][U+FFFD] and return a + /// [`Cow`]`::`[`Owned`]`(`[`String`]`)` with the result. + /// + /// > **Note**: This method is currently implemented to check for validity + /// > after a constant-time cast, but it is planned to alter its definition + /// > in the future to perform the length calculation in addition to the + /// > UTF-8 check whenever this method is called. + /// + /// [`Cow`]: ../borrow/enum.Cow.html + /// [`Borrowed`]: ../borrow/enum.Cow.html#variant.Borrowed + /// [`Owned`]: ../borrow/enum.Cow.html#variant.Owned + /// [`str`]: ../primitive.str.html + /// [`String`]: ../string/struct.String.html + /// [U+FFFD]: ../char/constant.REPLACEMENT_CHARACTER.html + /// + /// # Examples + /// + /// Calling `to_string_lossy` on a `CStr` containing valid UTF-8: + /// + /// ``` + /// use std::borrow::Cow; + /// use std::ffi::CStr; + /// + /// let c_str = CStr::from_bytes_with_nul(b"Hello World\0").unwrap(); + /// assert_eq!(c_str.to_string_lossy(), Cow::Borrowed("Hello World")); + /// ``` + /// + /// Calling `to_string_lossy` on a `CStr` containing invalid UTF-8: + /// + /// ``` + /// use std::borrow::Cow; + /// use std::ffi::CStr; + /// + /// let c_str = CStr::from_bytes_with_nul(b"Hello \xF0\x90\x80World\0").unwrap(); + /// assert_eq!( + /// c_str.to_string_lossy(), + /// Cow::Owned(String::from("Hello �World")) as Cow + /// ); + /// ``` + pub fn to_string_lossy(&self) -> Cow { + String::from_utf8_lossy(self.to_bytes()) + } + + /// Converts a [`Box`]`` into a [`CString`] without copying or allocating. + /// + /// [`Box`]: ../boxed/struct.Box.html + /// [`CString`]: struct.CString.html + /// + /// # Examples + /// + /// ``` + /// use std::ffi::CString; + /// + /// let c_string = CString::new(b"foo".to_vec()).unwrap(); + /// let boxed = c_string.into_boxed_c_str(); + /// assert_eq!(boxed.into_c_string(), CString::new("foo").unwrap()); + /// ``` + pub fn into_c_string(self: Box) -> CString { + let raw = Box::into_raw(self) as *mut [u8]; + CString { inner: unsafe { Box::from_raw(raw) } } + } +} + +impl PartialEq for CStr { + fn eq(&self, other: &CStr) -> bool { + self.to_bytes().eq(other.to_bytes()) + } +} + +impl Eq for CStr {} + +impl PartialOrd for CStr { + fn partial_cmp(&self, other: &CStr) -> Option { + self.to_bytes().partial_cmp(&other.to_bytes()) + } +} + +impl Ord for CStr { + fn cmp(&self, other: &CStr) -> Ordering { + self.to_bytes().cmp(&other.to_bytes()) + } +} + +impl ToOwned for CStr { + type Owned = CString; + + fn to_owned(&self) -> CString { + CString { inner: self.to_bytes_with_nul().into() } + } +} + +impl<'a> From<&'a CStr> for CString { + fn from(s: &'a CStr) -> CString { + s.to_owned() + } +} + +impl ops::Index for CString { + type Output = CStr; + + #[inline] + fn index(&self, _index: ops::RangeFull) -> &CStr { + self + } +} + +impl AsRef for CStr { + #[inline] + fn as_ref(&self) -> &CStr { + self + } +} + +impl AsRef for CString { + #[inline] + fn as_ref(&self) -> &CStr { + self + } +} diff --git a/src/header/arpa_inet/mod.rs b/src/header/arpa_inet/mod.rs index 8c7018127d..b9dc66b834 100644 --- a/src/header/arpa_inet/mod.rs +++ b/src/header/arpa_inet/mod.rs @@ -1,11 +1,10 @@ //! arpa/inet implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/arpainet.h.html use core::str::FromStr; -use core::{mem, ptr, slice, str}; +use core::{ptr, slice, str}; use header::errno::*; use header::netinet_in::in_addr; -use header::sys_socket; use platform; use platform::c_str; use platform::types::*; diff --git a/src/header/ctype/mod.rs b/src/header/ctype/mod.rs index f1be73a556..8506f84257 100644 --- a/src/header/ctype/mod.rs +++ b/src/header/ctype/mod.rs @@ -1,6 +1,5 @@ //! ctype implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/ctype.h.html -use platform; use platform::types::*; #[no_mangle] diff --git a/src/header/dirent/mod.rs b/src/header/dirent/mod.rs index 0083e5f39d..d1967fea3e 100644 --- a/src/header/dirent/mod.rs +++ b/src/header/dirent/mod.rs @@ -3,7 +3,7 @@ use alloc::boxed::Box; use core::{mem, ptr}; -use header::{errno, fcntl, stdio, unistd}; +use header::{errno, fcntl, unistd}; use platform; use platform::{Pal, Sys}; use platform::types::*; diff --git a/src/header/fcntl/mod.rs b/src/header/fcntl/mod.rs index 2aadfaa4cc..8ce772043b 100644 --- a/src/header/fcntl/mod.rs +++ b/src/header/fcntl/mod.rs @@ -1,6 +1,5 @@ //! fcntl implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/fcntl.h.html -use platform; use platform::{Pal, Sys}; use platform::types::*; diff --git a/src/header/fenv/mod.rs b/src/header/fenv/mod.rs index f7c837a029..6aa92216f0 100644 --- a/src/header/fenv/mod.rs +++ b/src/header/fenv/mod.rs @@ -1,7 +1,6 @@ //! fenv.h implementation for Redox, following //! http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/fenv.h.html -use platform; use platform::types::*; pub const FE_ALL_EXCEPT: c_int = 0; diff --git a/src/header/float/mod.rs b/src/header/float/mod.rs index 6b0c4ea6a9..dec7861c54 100644 --- a/src/header/float/mod.rs +++ b/src/header/float/mod.rs @@ -2,7 +2,6 @@ //! http://pubs.opengroup.org/onlinepubs/7908799/xsh/float.h.html use header::fenv::{fegetround, FE_TONEAREST}; -use platform; use platform::types::*; pub const FLT_RADIX: c_int = 2; diff --git a/src/header/fnmatch/mod.rs b/src/header/fnmatch/mod.rs index 7ad988c63c..ee5ffaf345 100644 --- a/src/header/fnmatch/mod.rs +++ b/src/header/fnmatch/mod.rs @@ -2,7 +2,6 @@ use alloc::vec::Vec; -use platform; use platform::types::*; pub const FNM_NOMATCH: c_int = 1; diff --git a/src/header/grp/mod.rs b/src/header/grp/mod.rs index 9040e4a38c..b0fcd33c48 100644 --- a/src/header/grp/mod.rs +++ b/src/header/grp/mod.rs @@ -1,6 +1,5 @@ //! grp implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/grp.h.html -use platform; use platform::types::*; #[repr(C)] diff --git a/src/header/inttypes/mod.rs b/src/header/inttypes/mod.rs index 8a433ad2e7..380450b987 100644 --- a/src/header/inttypes/mod.rs +++ b/src/header/inttypes/mod.rs @@ -1,4 +1,4 @@ -use header::{ctype, stdlib}; +use header::ctype; use header::errno::*; use header::stdlib::*; use platform; diff --git a/src/header/locale/mod.rs b/src/header/locale/mod.rs index d90be57da3..d3a03c740b 100644 --- a/src/header/locale/mod.rs +++ b/src/header/locale/mod.rs @@ -2,7 +2,6 @@ use core::ptr; -use platform; use platform::types::*; const EMPTY_PTR: *const c_char = "\0" as *const _ as *const c_char; diff --git a/src/header/netinet_in/mod.rs b/src/header/netinet_in/mod.rs index 7872fc99f2..f3819f604f 100644 --- a/src/header/netinet_in/mod.rs +++ b/src/header/netinet_in/mod.rs @@ -1,7 +1,6 @@ #![allow(non_camel_case_types)] -use header::sys_socket::{self, sa_family_t, sockaddr}; -use platform; +use header::sys_socket::sa_family_t; use platform::types::*; pub type in_addr_t = u32; diff --git a/src/header/semaphore/mod.rs b/src/header/semaphore/mod.rs index 9d3d64ad6b..f1331a4381 100644 --- a/src/header/semaphore/mod.rs +++ b/src/header/semaphore/mod.rs @@ -1,4 +1,3 @@ -use platform; use platform::types::*; #[repr(C)] diff --git a/src/header/stdio/mod.rs b/src/header/stdio/mod.rs index f274c7caae..5bbe0aae6a 100644 --- a/src/header/stdio/mod.rs +++ b/src/header/stdio/mod.rs @@ -8,7 +8,7 @@ use core::{ptr, str}; use va_list::VaList as va_list; use header::errno::{self, STR_ERROR}; -use header::{fcntl, string}; +use header::fcntl; use platform; use platform::{Pal, Sys}; use platform::types::*; diff --git a/src/header/stdlib/mod.rs b/src/header/stdlib/mod.rs index fb695bf2f4..fd617c506b 100644 --- a/src/header/stdlib/mod.rs +++ b/src/header/stdlib/mod.rs @@ -1,12 +1,12 @@ //! stdlib implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/stdlib.h.html -use core::{intrinsics, iter, mem, ptr, slice, str}; +use core::{intrinsics, iter, mem, ptr}; use rand::distributions::Alphanumeric; use rand::prng::XorShiftRng; use rand::rngs::JitterRng; use rand::{Rng, SeedableRng}; -use header::{ctype, errno, time, unistd, wchar}; +use header::{ctype, errno, unistd}; use header::errno::*; use header::fcntl::*; use header::string::*; diff --git a/src/header/string/mod.rs b/src/header/string/mod.rs index 6f506f05d3..bd09b9740e 100644 --- a/src/header/string/mod.rs +++ b/src/header/string/mod.rs @@ -1,6 +1,5 @@ //! string implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/string.h.html -use core::cmp; use core::mem; use core::ptr; use core::usize; diff --git a/src/header/strings/mod.rs b/src/header/strings/mod.rs index a20501bc49..a813932530 100644 --- a/src/header/strings/mod.rs +++ b/src/header/strings/mod.rs @@ -3,7 +3,6 @@ use alloc::Vec; use core::ptr; -use platform; use platform::types::*; #[no_mangle] diff --git a/src/header/sys_ioctl/mod.rs b/src/header/sys_ioctl/mod.rs index 1e392810af..78d7714d5c 100644 --- a/src/header/sys_ioctl/mod.rs +++ b/src/header/sys_ioctl/mod.rs @@ -1,6 +1,5 @@ //! ioctl implementation for linux -use platform; use platform::{Pal, Sys}; use platform::types::*; diff --git a/src/header/sys_mman/mod.rs b/src/header/sys_mman/mod.rs index 96a6f3a8d2..56730d401e 100644 --- a/src/header/sys_mman/mod.rs +++ b/src/header/sys_mman/mod.rs @@ -1,4 +1,3 @@ -use platform; use platform::{Pal, Sys}; use platform::types::*; diff --git a/src/header/sys_select/mod.rs b/src/header/sys_select/mod.rs index e1ad11c760..99590e65e6 100644 --- a/src/header/sys_select/mod.rs +++ b/src/header/sys_select/mod.rs @@ -1,8 +1,5 @@ //! sys/select.h implementation -use core::mem; - -use platform; use platform::{Pal, Sys}; use platform::types::*; diff --git a/src/header/sys_socket/mod.rs b/src/header/sys_socket/mod.rs index 714ce9c0b2..30ff349e4d 100644 --- a/src/header/sys_socket/mod.rs +++ b/src/header/sys_socket/mod.rs @@ -6,7 +6,6 @@ use platform; use platform::{PalSocket, Sys}; use platform::types::*; -use self::constants::*; mod constants; pub type in_addr_t = [u8; 4]; diff --git a/src/header/sys_un/mod.rs b/src/header/sys_un/mod.rs index 744e686c1d..2c0a2c9422 100644 --- a/src/header/sys_un/mod.rs +++ b/src/header/sys_un/mod.rs @@ -1,7 +1,6 @@ #![no_std] use header::sys_socket::sa_family_t; -use platform; use platform::types::*; #[repr(C)] diff --git a/src/header/sys_wait/mod.rs b/src/header/sys_wait/mod.rs index 8f83468d62..b9d69f1392 100644 --- a/src/header/sys_wait/mod.rs +++ b/src/header/sys_wait/mod.rs @@ -2,7 +2,6 @@ //! http://pubs.opengroup.org/onlinepubs/7908799/xsh/syswait.h.html use header::sys_resource::rusage; -use platform; use platform::{Pal, Sys}; use platform::types::*; diff --git a/src/header/time/mod.rs b/src/header/time/mod.rs index 1382fb5cbe..d8f7f98ac7 100644 --- a/src/header/time/mod.rs +++ b/src/header/time/mod.rs @@ -2,7 +2,6 @@ use core::mem::transmute; -use header::errno; use header::errno::EIO; use platform; use platform::{Pal, Sys}; diff --git a/src/header/unistd/mod.rs b/src/header/unistd/mod.rs index 08eb2deca3..2e565ed43c 100644 --- a/src/header/unistd/mod.rs +++ b/src/header/unistd/mod.rs @@ -2,7 +2,7 @@ use core::{ptr, slice}; -use header::{errno, stdio, string, sys_time}; +use header::sys_time; use platform; use platform::{Pal, Sys}; use platform::types::*; diff --git a/src/header/utime/mod.rs b/src/header/utime/mod.rs index 01dedc0ece..928243b1aa 100644 --- a/src/header/utime/mod.rs +++ b/src/header/utime/mod.rs @@ -1,6 +1,5 @@ //! utime implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/utime.h.html -use platform; use platform::{Pal, Sys}; use platform::types::*; diff --git a/src/header/wchar/mod.rs b/src/header/wchar/mod.rs index bcdbd58cb2..9df75f1472 100644 --- a/src/header/wchar/mod.rs +++ b/src/header/wchar/mod.rs @@ -3,7 +3,6 @@ use core::ptr; use va_list::VaList as va_list; -use header::errno; use header::stdio::*; use header::time::*; use platform; diff --git a/src/header/wctype/mod.rs b/src/header/wctype/mod.rs index 80d49c3e66..ab8205497a 100644 --- a/src/header/wctype/mod.rs +++ b/src/header/wctype/mod.rs @@ -1,6 +1,5 @@ //! wctype implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/wctype.h.html -use platform; use platform::types::*; // #[no_mangle] diff --git a/src/lib.rs b/src/lib.rs index b624efe17e..bc557b0973 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -32,6 +32,7 @@ extern crate spin; #[macro_use] mod macros; +pub mod c_str; pub mod header; pub mod platform; pub mod start; From bab4e2896a851bedae2acd8327a618a1991b79b0 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Mon, 27 Aug 2018 06:35:30 -0600 Subject: [PATCH 14/19] Format --- fmt.sh | 8 +- src/c_str.rs | 67 +++-- src/crt0/src/lib.rs | 4 +- .../{_todo/oldlib => _oldlib}/dns/answer.rs | 0 .../{_todo/oldlib => _oldlib}/dns/mod.rs | 0 .../{_todo/oldlib => _oldlib}/dns/query.rs | 0 src/header/{_todo/oldlib => _oldlib}/event.rs | 0 src/header/{_todo/oldlib => _oldlib}/file.rs | 0 .../{_todo/oldlib => _oldlib}/folder.rs | 0 .../{_todo/oldlib => _oldlib}/hostname.rs | 0 src/header/{_todo/oldlib => _oldlib}/lib.rs | 0 .../{_todo/oldlib => _oldlib}/macros.rs | 0 .../{_todo/oldlib => _oldlib}/mallocnull.rs | 0 src/header/{_todo/oldlib => _oldlib}/netdb.rs | 0 .../{_todo/oldlib => _oldlib}/process.rs | 0 .../{_todo/oldlib => _oldlib}/rawfile.rs | 0 src/header/{_todo/oldlib => _oldlib}/redox.rs | 0 .../{_todo/oldlib => _oldlib}/socket.rs | 0 .../{_todo/oldlib => _oldlib}/termios.rs | 0 src/header/{_todo/oldlib => _oldlib}/time.rs | 0 src/header/{_todo/oldlib => _oldlib}/types.rs | 0 .../{_todo/oldlib => _oldlib}/unimpl.rs | 0 src/header/{_todo/oldlib => _oldlib}/user.rs | 0 src/header/_pthread/cbindgen.toml | 7 + .../{_todo/pthread/lib.rs => _pthread/mod.rs} | 266 ++++++++---------- src/header/_todo/wctype/lib.rs | 89 ------ src/header/aio/cbindgen.toml | 7 + src/header/{_todo/aio/lib.rs => aio/mod.rs} | 31 +- src/header/dirent/mod.rs | 2 +- src/header/fcntl/mod.rs | 2 +- src/header/fnmatch/mod.rs | 35 ++- src/header/mod.rs | 2 + src/header/netinet_in/mod.rs | 8 +- src/header/pwd/mod.rs | 2 +- src/header/sgtty/mod.rs | 2 +- src/header/signal/mod.rs | 9 +- src/header/stdio/mod.rs | 13 +- src/header/stdio/scanf.rs | 4 +- src/header/stdlib/mod.rs | 40 ++- src/header/string/mod.rs | 11 +- src/header/sys_file/mod.rs | 2 +- src/header/sys_ioctl/mod.rs | 4 +- src/header/sys_mman/mod.rs | 2 +- src/header/sys_resource/mod.rs | 2 +- src/header/sys_select/mod.rs | 2 +- src/header/sys_socket/mod.rs | 2 +- src/header/sys_stat/mod.rs | 4 +- src/header/sys_time/mod.rs | 2 +- src/header/sys_times/mod.rs | 2 +- src/header/sys_utsname/mod.rs | 2 +- src/header/sys_wait/mod.rs | 2 +- src/header/termios/mod.rs | 4 +- src/header/time/mod.rs | 2 +- src/header/time/strftime.rs | 10 +- src/header/unistd/brk.rs | 2 +- src/header/unistd/mod.rs | 7 +- src/header/utime/mod.rs | 2 +- src/platform/linux/mod.rs | 10 +- src/platform/linux/signal.rs | 4 +- src/platform/linux/socket.rs | 4 +- src/platform/mod.rs | 8 +- src/platform/pal/mod.rs | 6 +- src/platform/pal/signal.rs | 2 +- src/platform/pal/socket.rs | 14 +- src/platform/rawfile.rs | 2 +- src/platform/redox/mod.rs | 39 +-- src/platform/redox/signal.rs | 4 +- src/platform/redox/socket.rs | 6 +- src/platform/types.rs | 2 +- src/start.rs | 4 +- 70 files changed, 363 insertions(+), 404 deletions(-) rename src/header/{_todo/oldlib => _oldlib}/dns/answer.rs (100%) rename src/header/{_todo/oldlib => _oldlib}/dns/mod.rs (100%) rename src/header/{_todo/oldlib => _oldlib}/dns/query.rs (100%) rename src/header/{_todo/oldlib => _oldlib}/event.rs (100%) rename src/header/{_todo/oldlib => _oldlib}/file.rs (100%) rename src/header/{_todo/oldlib => _oldlib}/folder.rs (100%) rename src/header/{_todo/oldlib => _oldlib}/hostname.rs (100%) rename src/header/{_todo/oldlib => _oldlib}/lib.rs (100%) rename src/header/{_todo/oldlib => _oldlib}/macros.rs (100%) rename src/header/{_todo/oldlib => _oldlib}/mallocnull.rs (100%) rename src/header/{_todo/oldlib => _oldlib}/netdb.rs (100%) rename src/header/{_todo/oldlib => _oldlib}/process.rs (100%) rename src/header/{_todo/oldlib => _oldlib}/rawfile.rs (100%) rename src/header/{_todo/oldlib => _oldlib}/redox.rs (100%) rename src/header/{_todo/oldlib => _oldlib}/socket.rs (100%) rename src/header/{_todo/oldlib => _oldlib}/termios.rs (100%) rename src/header/{_todo/oldlib => _oldlib}/time.rs (100%) rename src/header/{_todo/oldlib => _oldlib}/types.rs (100%) rename src/header/{_todo/oldlib => _oldlib}/unimpl.rs (100%) rename src/header/{_todo/oldlib => _oldlib}/user.rs (100%) create mode 100644 src/header/_pthread/cbindgen.toml rename src/header/{_todo/pthread/lib.rs => _pthread/mod.rs} (69%) delete mode 100644 src/header/_todo/wctype/lib.rs create mode 100644 src/header/aio/cbindgen.toml rename src/header/{_todo/aio/lib.rs => aio/mod.rs} (51%) diff --git a/fmt.sh b/fmt.sh index cb5a928a33..be8636e2ab 100755 --- a/fmt.sh +++ b/fmt.sh @@ -1,9 +1,3 @@ #!/usr/bin/env bash -ARGS=() -for crate in relibc $(find src -name Cargo.toml | cut -d '/' -f2 | grep -v template) -do - ARGS+=("--package" "$crate") -done - -cargo fmt "${ARGS[@]}" "$@" +cargo fmt --package relibc --package crt0 "$@" diff --git a/src/c_str.rs b/src/c_str.rs index 1ad8f2ea6c..113015ef46 100644 --- a/src/c_str.rs +++ b/src/c_str.rs @@ -33,7 +33,8 @@ pub fn memchr(needle: u8, haystack: &[u8]) -> Option { string::memchr( haystack.as_ptr() as *const c_void, needle as c_int, - haystack.len()) + haystack.len(), + ) }; if p.is_null() { None @@ -222,7 +223,7 @@ pub struct CStr { // just a raw `c_char` along with some form of marker to make // this an unsized type. Essentially `sizeof(&CStr)` should be the // same as `sizeof(&c_char)` but `CStr` should be an unsized type. - inner: [c_char] + inner: [c_char], } /// An error indicating that an interior nul byte was found. @@ -290,10 +291,10 @@ impl FromBytesWithNulError { fn description(&self) -> &str { match self.kind { - FromBytesWithNulErrorKind::InteriorNul(..) => - "data provided contains an interior nul byte", - FromBytesWithNulErrorKind::NotNulTerminated => - "data provided is not nul terminated", + FromBytesWithNulErrorKind::InteriorNul(..) => { + "data provided contains an interior nul byte" + } + FromBytesWithNulErrorKind::NotNulTerminated => "data provided is not nul terminated", } } } @@ -380,7 +381,9 @@ impl CString { pub unsafe fn from_vec_unchecked(mut v: Vec) -> CString { v.reserve_exact(1); v.push(0); - CString { inner: v.into_boxed_slice() } + CString { + inner: v.into_boxed_slice(), + } } /// Retakes ownership of a `CString` that was transferred to C via [`into_raw`]. @@ -426,7 +429,9 @@ impl CString { pub unsafe fn from_raw(ptr: *mut c_char) -> CString { let len = strlen(ptr) + 1; // Including the NUL byte let slice = slice::from_raw_parts_mut(ptr, len as usize); - CString { inner: Box::from_raw(slice as *mut [c_char] as *mut [u8]) } + CString { + inner: Box::from_raw(slice as *mut [c_char] as *mut [u8]), + } } /// Consumes the `CString` and transfers ownership of the string to a C caller. @@ -486,11 +491,10 @@ impl CString { /// ``` pub fn into_string(self) -> Result { - String::from_utf8(self.into_bytes()) - .map_err(|e| IntoStringError { - error: e.utf8_error(), - inner: unsafe { CString::from_vec_unchecked(e.into_bytes()) }, - }) + String::from_utf8(self.into_bytes()).map_err(|e| IntoStringError { + error: e.utf8_error(), + inner: unsafe { CString::from_vec_unchecked(e.into_bytes()) }, + }) } /// Consumes the `CString` and returns the underlying byte buffer. @@ -628,7 +632,9 @@ impl CString { impl Drop for CString { #[inline] fn drop(&mut self) { - unsafe { *self.inner.get_unchecked_mut(0) = 0; } + unsafe { + *self.inner.get_unchecked_mut(0) = 0; + } } } @@ -663,7 +669,11 @@ impl From for Vec { impl fmt::Debug for CStr { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "\"")?; - for byte in self.to_bytes().iter().flat_map(|&b| ascii::escape_default(b)) { + for byte in self + .to_bytes() + .iter() + .flat_map(|&b| ascii::escape_default(b)) + { f.write_char(byte as char)?; } write!(f, "\"") @@ -687,7 +697,9 @@ impl Default for CString { impl Borrow for CString { #[inline] - fn borrow(&self) -> &CStr { self } + fn borrow(&self) -> &CStr { + self + } } impl<'a> From> for CString { @@ -818,7 +830,9 @@ impl NulError { /// let nul_error = CString::new("foo bar\0").unwrap_err(); /// assert_eq!(nul_error.nul_position(), 7); /// ``` - pub fn nul_position(&self) -> usize { self.0 } + pub fn nul_position(&self) -> usize { + self.0 + } /// Consumes this error, returning the underlying vector of bytes which /// generated the error in the first place. @@ -831,9 +845,13 @@ impl NulError { /// let nul_error = CString::new("foo\0bar").unwrap_err(); /// assert_eq!(nul_error.into_vec(), b"foo\0bar"); /// ``` - pub fn into_vec(self) -> Vec { self.1 } + pub fn into_vec(self) -> Vec { + self.1 + } - fn description(&self) -> &str { "nul byte found in data" } + fn description(&self) -> &str { + "nul byte found in data" + } } impl fmt::Display for NulError { @@ -951,8 +969,7 @@ impl CStr { /// let c_str = CStr::from_bytes_with_nul(b"he\0llo\0"); /// assert!(c_str.is_err()); /// ``` - pub fn from_bytes_with_nul(bytes: &[u8]) - -> Result<&CStr, FromBytesWithNulError> { + pub fn from_bytes_with_nul(bytes: &[u8]) -> Result<&CStr, FromBytesWithNulError> { let nul_pos = memchr(0, bytes); if let Some(nul_pos) = nul_pos { if nul_pos + 1 != bytes.len() { @@ -1176,7 +1193,9 @@ impl CStr { /// ``` pub fn into_c_string(self: Box) -> CString { let raw = Box::into_raw(self) as *mut [u8]; - CString { inner: unsafe { Box::from_raw(raw) } } + CString { + inner: unsafe { Box::from_raw(raw) }, + } } } @@ -1204,7 +1223,9 @@ impl ToOwned for CStr { type Owned = CString; fn to_owned(&self) -> CString { - CString { inner: self.to_bytes_with_nul().into() } + CString { + inner: self.to_bytes_with_nul().into(), + } } } diff --git a/src/crt0/src/lib.rs b/src/crt0/src/lib.rs index d3f1642a9f..ca2c2ff2e2 100644 --- a/src/crt0/src/lib.rs +++ b/src/crt0/src/lib.rs @@ -37,7 +37,5 @@ pub extern "C" fn rust_begin_unwind(_pi: &::core::panic::PanicInfo) -> ! { fn exit(status: i32) -> !; } - unsafe { - exit(1) - } + unsafe { exit(1) } } diff --git a/src/header/_todo/oldlib/dns/answer.rs b/src/header/_oldlib/dns/answer.rs similarity index 100% rename from src/header/_todo/oldlib/dns/answer.rs rename to src/header/_oldlib/dns/answer.rs diff --git a/src/header/_todo/oldlib/dns/mod.rs b/src/header/_oldlib/dns/mod.rs similarity index 100% rename from src/header/_todo/oldlib/dns/mod.rs rename to src/header/_oldlib/dns/mod.rs diff --git a/src/header/_todo/oldlib/dns/query.rs b/src/header/_oldlib/dns/query.rs similarity index 100% rename from src/header/_todo/oldlib/dns/query.rs rename to src/header/_oldlib/dns/query.rs diff --git a/src/header/_todo/oldlib/event.rs b/src/header/_oldlib/event.rs similarity index 100% rename from src/header/_todo/oldlib/event.rs rename to src/header/_oldlib/event.rs diff --git a/src/header/_todo/oldlib/file.rs b/src/header/_oldlib/file.rs similarity index 100% rename from src/header/_todo/oldlib/file.rs rename to src/header/_oldlib/file.rs diff --git a/src/header/_todo/oldlib/folder.rs b/src/header/_oldlib/folder.rs similarity index 100% rename from src/header/_todo/oldlib/folder.rs rename to src/header/_oldlib/folder.rs diff --git a/src/header/_todo/oldlib/hostname.rs b/src/header/_oldlib/hostname.rs similarity index 100% rename from src/header/_todo/oldlib/hostname.rs rename to src/header/_oldlib/hostname.rs diff --git a/src/header/_todo/oldlib/lib.rs b/src/header/_oldlib/lib.rs similarity index 100% rename from src/header/_todo/oldlib/lib.rs rename to src/header/_oldlib/lib.rs diff --git a/src/header/_todo/oldlib/macros.rs b/src/header/_oldlib/macros.rs similarity index 100% rename from src/header/_todo/oldlib/macros.rs rename to src/header/_oldlib/macros.rs diff --git a/src/header/_todo/oldlib/mallocnull.rs b/src/header/_oldlib/mallocnull.rs similarity index 100% rename from src/header/_todo/oldlib/mallocnull.rs rename to src/header/_oldlib/mallocnull.rs diff --git a/src/header/_todo/oldlib/netdb.rs b/src/header/_oldlib/netdb.rs similarity index 100% rename from src/header/_todo/oldlib/netdb.rs rename to src/header/_oldlib/netdb.rs diff --git a/src/header/_todo/oldlib/process.rs b/src/header/_oldlib/process.rs similarity index 100% rename from src/header/_todo/oldlib/process.rs rename to src/header/_oldlib/process.rs diff --git a/src/header/_todo/oldlib/rawfile.rs b/src/header/_oldlib/rawfile.rs similarity index 100% rename from src/header/_todo/oldlib/rawfile.rs rename to src/header/_oldlib/rawfile.rs diff --git a/src/header/_todo/oldlib/redox.rs b/src/header/_oldlib/redox.rs similarity index 100% rename from src/header/_todo/oldlib/redox.rs rename to src/header/_oldlib/redox.rs diff --git a/src/header/_todo/oldlib/socket.rs b/src/header/_oldlib/socket.rs similarity index 100% rename from src/header/_todo/oldlib/socket.rs rename to src/header/_oldlib/socket.rs diff --git a/src/header/_todo/oldlib/termios.rs b/src/header/_oldlib/termios.rs similarity index 100% rename from src/header/_todo/oldlib/termios.rs rename to src/header/_oldlib/termios.rs diff --git a/src/header/_todo/oldlib/time.rs b/src/header/_oldlib/time.rs similarity index 100% rename from src/header/_todo/oldlib/time.rs rename to src/header/_oldlib/time.rs diff --git a/src/header/_todo/oldlib/types.rs b/src/header/_oldlib/types.rs similarity index 100% rename from src/header/_todo/oldlib/types.rs rename to src/header/_oldlib/types.rs diff --git a/src/header/_todo/oldlib/unimpl.rs b/src/header/_oldlib/unimpl.rs similarity index 100% rename from src/header/_todo/oldlib/unimpl.rs rename to src/header/_oldlib/unimpl.rs diff --git a/src/header/_todo/oldlib/user.rs b/src/header/_oldlib/user.rs similarity index 100% rename from src/header/_todo/oldlib/user.rs rename to src/header/_oldlib/user.rs diff --git a/src/header/_pthread/cbindgen.toml b/src/header/_pthread/cbindgen.toml new file mode 100644 index 0000000000..a1ea51c3f3 --- /dev/null +++ b/src/header/_pthread/cbindgen.toml @@ -0,0 +1,7 @@ +sys_includes = [] +include_guard = "_PTHREAD_H" +language = "C" +style = "Tag" + +[enum] +prefix_with_name = true diff --git a/src/header/_todo/pthread/lib.rs b/src/header/_pthread/mod.rs similarity index 69% rename from src/header/_todo/pthread/lib.rs rename to src/header/_pthread/mod.rs index 661c9cdf28..b02f301a51 100644 --- a/src/header/_todo/pthread/lib.rs +++ b/src/header/_pthread/mod.rs @@ -1,13 +1,26 @@ +use platform::types::*; + +#[repr(C)] +#[derive(Debug, Copy)] +pub struct sched_param { + pub _address: u8, +} +impl Clone for sched_param { + fn clone(&self) -> Self { + *self + } +} + // #[no_mangle] -pub extern "C" fn pthread_attr_destroy(attr: *mut pthread_attr_t) -> libc::c_int { +pub extern "C" fn pthread_attr_destroy(attr: *mut pthread_attr_t) -> c_int { unimplemented!(); } // #[no_mangle] pub extern "C" fn pthread_attr_getdetachstate( attr: *const pthread_attr_t, - detachstate: *mut libc::c_int, -) -> libc::c_int { + detachstate: *mut c_int, +) -> c_int { unimplemented!(); } @@ -15,15 +28,15 @@ pub extern "C" fn pthread_attr_getdetachstate( pub extern "C" fn pthread_attr_getguardsize( attr: *const pthread_attr_t, guardsize: *mut usize, -) -> libc::c_int { +) -> c_int { unimplemented!(); } // #[no_mangle] pub extern "C" fn pthread_attr_getinheritsched( attr: *const pthread_attr_t, - inheritsched: *mut libc::c_int, -) -> libc::c_int { + inheritsched: *mut c_int, +) -> c_int { unimplemented!(); } @@ -31,31 +44,31 @@ pub extern "C" fn pthread_attr_getinheritsched( pub extern "C" fn pthread_attr_getschedparam( attr: *const pthread_attr_t, param: *mut sched_param, -) -> libc::c_int { +) -> c_int { unimplemented!(); } // #[no_mangle] pub extern "C" fn pthread_attr_getschedpolicy( attr: *const pthread_attr_t, - policy: *mut libc::c_int, -) -> libc::c_int { + policy: *mut c_int, +) -> c_int { unimplemented!(); } // #[no_mangle] pub extern "C" fn pthread_attr_getscope( attr: *const pthread_attr_t, - contentionscope: *mut libc::c_int, -) -> libc::c_int { + contentionscope: *mut c_int, +) -> c_int { unimplemented!(); } // #[no_mangle] pub extern "C" fn pthread_attr_getstackaddr( attr: *const pthread_attr_t, - stackaddr: *mut *mut libc::c_void, -) -> libc::c_int { + stackaddr: *mut *mut c_void, +) -> c_int { unimplemented!(); } @@ -63,33 +76,33 @@ pub extern "C" fn pthread_attr_getstackaddr( pub extern "C" fn pthread_attr_getstacksize( attr: *const pthread_attr_t, stacksize: *mut usize, -) -> libc::c_int { +) -> c_int { unimplemented!(); } // #[no_mangle] -pub extern "C" fn pthread_attr_init(arg1: *mut pthread_attr_t) -> libc::c_int { +pub extern "C" fn pthread_attr_init(arg1: *mut pthread_attr_t) -> c_int { unimplemented!(); } // #[no_mangle] pub extern "C" fn pthread_attr_setdetachstate( attr: *mut pthread_attr_t, - detachstate: libc::c_int, -) -> libc::c_int { + detachstate: c_int, +) -> c_int { unimplemented!(); } // #[no_mangle] -pub extern "C" fn pthread_attr_setguardsize(arg1: *mut pthread_attr_t, arg2: usize) -> libc::c_int { +pub extern "C" fn pthread_attr_setguardsize(arg1: *mut pthread_attr_t, arg2: usize) -> c_int { unimplemented!(); } // #[no_mangle] pub extern "C" fn pthread_attr_setinheritsched( attr: *mut pthread_attr_t, - inheritsched: libc::c_int, -) -> libc::c_int { + inheritsched: c_int, +) -> c_int { unimplemented!(); } @@ -97,61 +110,61 @@ pub extern "C" fn pthread_attr_setinheritsched( pub extern "C" fn pthread_attr_setschedparam( attr: *mut pthread_attr_t, param: *mut sched_param, -) -> libc::c_int { +) -> c_int { unimplemented!(); } // #[no_mangle] pub extern "C" fn pthread_attr_setschedpolicy( attr: *mut pthread_attr_t, - policy: libc::c_int, -) -> libc::c_int { + policy: c_int, +) -> c_int { unimplemented!(); } // #[no_mangle] pub extern "C" fn pthread_attr_setscope( attr: *mut pthread_attr_t, - contentionscope: libc::c_int, -) -> libc::c_int { + contentionscope: c_int, +) -> c_int { unimplemented!(); } // #[no_mangle] pub extern "C" fn pthread_attr_setstackaddr( attr: *mut pthread_attr_t, - stackaddr: *mut libc::c_void, -) -> libc::c_int { + stackaddr: *mut c_void, +) -> c_int { unimplemented!(); } // #[no_mangle] -pub extern "C" fn pthread_attr_setstacksize(attr: *mut pthread_attr_t, stacksize: usize) -> libc::c_int { +pub extern "C" fn pthread_attr_setstacksize(attr: *mut pthread_attr_t, stacksize: usize) -> c_int { unimplemented!(); } // #[no_mangle] -pub extern "C" fn pthread_cancel(thread: pthread_t) -> libc::c_int { +pub extern "C" fn pthread_cancel(thread: pthread_t) -> c_int { unimplemented!(); } // #[no_mangle] -pub extern "C" fn pthread_cleanup_push(routine: *mut libc::c_void, arg: *mut libc::c_void) { +pub extern "C" fn pthread_cleanup_push(routine: *mut c_void, arg: *mut c_void) { unimplemented!(); } // #[no_mangle] -pub extern "C" fn pthread_cleanup_pop(execute: libc::c_int) { +pub extern "C" fn pthread_cleanup_pop(execute: c_int) { unimplemented!(); } // #[no_mangle] -pub extern "C" fn pthread_cond_broadcast(cond: *mut pthread_cond_t) -> libc::c_int { +pub extern "C" fn pthread_cond_broadcast(cond: *mut pthread_cond_t) -> c_int { unimplemented!(); } // #[no_mangle] -pub extern "C" fn pthread_cond_destroy(cond: *mut pthread_cond_t) -> libc::c_int { +pub extern "C" fn pthread_cond_destroy(cond: *mut pthread_cond_t) -> c_int { unimplemented!(); } @@ -159,12 +172,12 @@ pub extern "C" fn pthread_cond_destroy(cond: *mut pthread_cond_t) -> libc::c_int pub extern "C" fn pthread_cond_init( cond: *mut pthread_cond_t, attr: *const pthread_condattr_t, -) -> libc::c_int { +) -> c_int { unimplemented!(); } // #[no_mangle] -pub extern "C" fn pthread_cond_signal(cond: *mut pthread_cond_t) -> libc::c_int { +pub extern "C" fn pthread_cond_signal(cond: *mut pthread_cond_t) -> c_int { unimplemented!(); } @@ -173,7 +186,7 @@ pub extern "C" fn pthread_cond_timedwait( cond: *mut pthread_cond_t, mutex: *mut pthread_mutex_t, abstime: *const timespec, -) -> libc::c_int { +) -> c_int { unimplemented!(); } @@ -181,33 +194,33 @@ pub extern "C" fn pthread_cond_timedwait( pub extern "C" fn pthread_cond_wait( cond: *mut pthread_cond_t, mutex: *mut pthread_mutex_t, -) -> libc::c_int { +) -> c_int { unimplemented!(); } // #[no_mangle] -pub extern "C" fn pthread_condattr_destroy(attr: *mut pthread_condattr_t) -> libc::c_int { +pub extern "C" fn pthread_condattr_destroy(attr: *mut pthread_condattr_t) -> c_int { unimplemented!(); } // #[no_mangle] pub extern "C" fn pthread_condattr_getpshared( attr: *const pthread_condattr_t, - pshared: *mut libc::c_int, -) -> libc::c_int { + pshared: *mut c_int, +) -> c_int { unimplemented!(); } // #[no_mangle] -pub extern "C" fn pthread_condattr_init(attr: *mut pthread_condattr_t) -> libc::c_int { +pub extern "C" fn pthread_condattr_init(attr: *mut pthread_condattr_t) -> c_int { unimplemented!(); } // #[no_mangle] pub extern "C" fn pthread_condattr_setpshared( attr: *mut pthread_condattr_t, - pshared: libc::c_int, -) -> libc::c_int { + pshared: c_int, +) -> c_int { unimplemented!(); } @@ -215,74 +228,74 @@ pub extern "C" fn pthread_condattr_setpshared( pub extern "C" fn pthread_create( thread: *mut pthread_t, attr: *const pthread_attr_t, - start_routine: Option *mut libc::c_void>, - arg: *mut libc::c_void, -) -> libc::c_int { + start_routine: Option *mut c_void>, + arg: *mut c_void, +) -> c_int { unimplemented!(); } // #[no_mangle] -pub extern "C" fn pthread_detach(thread: pthread_t) -> libc::c_int { +pub extern "C" fn pthread_detach(thread: pthread_t) -> c_int { unimplemented!(); } // #[no_mangle] -pub extern "C" fn pthread_equal(t1: pthread_t, t2: pthread_t) -> libc::c_int { +pub extern "C" fn pthread_equal(t1: pthread_t, t2: pthread_t) -> c_int { unimplemented!(); } // #[no_mangle] -pub extern "C" fn pthread_exit(value_ptr: *mut libc::c_void) { +pub extern "C" fn pthread_exit(value_ptr: *mut c_void) { unimplemented!(); } // #[no_mangle] -pub extern "C" fn pthread_getconcurrency() -> libc::c_int { +pub extern "C" fn pthread_getconcurrency() -> c_int { unimplemented!(); } // #[no_mangle] pub extern "C" fn pthread_getschedparam( thread: pthread_t, - policy: *mut libc::c_int, + policy: *mut c_int, param: *mut sched_param, -) -> libc::c_int { +) -> c_int { unimplemented!(); } // #[no_mangle] -pub extern "C" fn pthread_getspecific(key: pthread_key_t) -> *mut libc::c_void { +pub extern "C" fn pthread_getspecific(key: pthread_key_t) -> *mut c_void { unimplemented!(); } // #[no_mangle] -pub extern "C" fn pthread_join(thread: pthread_t, value_ptr: *mut *mut libc::c_void) -> libc::c_int { +pub extern "C" fn pthread_join(thread: pthread_t, value_ptr: *mut *mut c_void) -> c_int { unimplemented!(); } // #[no_mangle] pub extern "C" fn pthread_key_create( key: *mut pthread_key_t, - destructor: Option, -) -> libc::c_int { + destructor: Option, +) -> c_int { unimplemented!(); } // #[no_mangle] -pub extern "C" fn pthread_key_delete(key: pthread_key_t) -> libc::c_int { +pub extern "C" fn pthread_key_delete(key: pthread_key_t) -> c_int { unimplemented!(); } // #[no_mangle] -pub extern "C" fn pthread_mutex_destroy(mutex: *mut pthread_mutex_t) -> libc::c_int { +pub extern "C" fn pthread_mutex_destroy(mutex: *mut pthread_mutex_t) -> c_int { unimplemented!(); } // #[no_mangle] pub extern "C" fn pthread_mutex_getprioceiling( mutex: *const pthread_mutex_t, - prioceiling: *mut libc::c_int, -) -> libc::c_int { + prioceiling: *mut c_int, +) -> c_int { unimplemented!(); } @@ -290,105 +303,105 @@ pub extern "C" fn pthread_mutex_getprioceiling( pub extern "C" fn pthread_mutex_init( mutex: *mut pthread_mutex_t, attr: *const pthread_mutexattr_t, -) -> libc::c_int { +) -> c_int { unimplemented!(); } // #[no_mangle] -pub extern "C" fn pthread_mutex_lock(mutex: *mut pthread_mutex_t) -> libc::c_int { +pub extern "C" fn pthread_mutex_lock(mutex: *mut pthread_mutex_t) -> c_int { unimplemented!(); } // #[no_mangle] pub extern "C" fn pthread_mutex_setprioceiling( mutex: *mut pthread_mutex_t, - prioceiling: libc::c_int, - old_ceiling: *mut libc::c_int, -) -> libc::c_int { + prioceiling: c_int, + old_ceiling: *mut c_int, +) -> c_int { unimplemented!(); } // #[no_mangle] -pub extern "C" fn pthread_mutex_trylock(mutex: *mut pthread_mutex_t) -> libc::c_int { +pub extern "C" fn pthread_mutex_trylock(mutex: *mut pthread_mutex_t) -> c_int { unimplemented!(); } // #[no_mangle] -pub extern "C" fn pthread_mutex_unlock(mutex: *mut pthread_mutex_t) -> libc::c_int { +pub extern "C" fn pthread_mutex_unlock(mutex: *mut pthread_mutex_t) -> c_int { unimplemented!(); } // #[no_mangle] -pub extern "C" fn pthread_mutexattr_destroy(attr: *mut pthread_mutexattr_t) -> libc::c_int { +pub extern "C" fn pthread_mutexattr_destroy(attr: *mut pthread_mutexattr_t) -> c_int { unimplemented!(); } // #[no_mangle] pub extern "C" fn pthread_mutexattr_getprioceiling( attr: *const pthread_mutexattr_t, - prioceiling: *mut libc::c_int, -) -> libc::c_int { + prioceiling: *mut c_int, +) -> c_int { unimplemented!(); } // #[no_mangle] pub extern "C" fn pthread_mutexattr_getprotocol( attr: *const pthread_mutexattr_t, - protocol: *mut libc::c_int, -) -> libc::c_int { + protocol: *mut c_int, +) -> c_int { unimplemented!(); } // #[no_mangle] pub extern "C" fn pthread_mutexattr_getpshared( attr: *const pthread_mutexattr_t, - pshared: *mut libc::c_int, -) -> libc::c_int { + pshared: *mut c_int, +) -> c_int { unimplemented!(); } // #[no_mangle] pub extern "C" fn pthread_mutexattr_gettype( attr: *const pthread_mutexattr_t, - type_: *mut libc::c_int, -) -> libc::c_int { + type_: *mut c_int, +) -> c_int { unimplemented!(); } // #[no_mangle] -pub extern "C" fn pthread_mutexattr_init(attr: *mut pthread_mutexattr_t) -> libc::c_int { +pub extern "C" fn pthread_mutexattr_init(attr: *mut pthread_mutexattr_t) -> c_int { unimplemented!(); } // #[no_mangle] pub extern "C" fn pthread_mutexattr_setprioceiling( attr: *mut pthread_mutexattr_t, - prioceiling: libc::c_int, -) -> libc::c_int { + prioceiling: c_int, +) -> c_int { unimplemented!(); } // #[no_mangle] pub extern "C" fn pthread_mutexattr_setprotocol( attr: *mut pthread_mutexattr_t, - protocol: libc::c_int, -) -> libc::c_int { + protocol: c_int, +) -> c_int { unimplemented!(); } // #[no_mangle] pub extern "C" fn pthread_mutexattr_setpshared( attr: *mut pthread_mutexattr_t, - pshared: libc::c_int, -) -> libc::c_int { + pshared: c_int, +) -> c_int { unimplemented!(); } // #[no_mangle] pub extern "C" fn pthread_mutexattr_settype( attr: *mut pthread_mutexattr_t, - type_: libc::c_int, -) -> libc::c_int { + type_: c_int, +) -> c_int { unimplemented!(); } @@ -396,12 +409,12 @@ pub extern "C" fn pthread_mutexattr_settype( pub extern "C" fn pthread_once( once_control: *mut pthread_once_t, init_routine: Option, -) -> libc::c_int { +) -> c_int { unimplemented!(); } // #[no_mangle] -pub extern "C" fn pthread_rwlock_destroy(rwlock: *mut pthread_rwlock_t) -> libc::c_int { +pub extern "C" fn pthread_rwlock_destroy(rwlock: *mut pthread_rwlock_t) -> c_int { unimplemented!(); } @@ -409,58 +422,58 @@ pub extern "C" fn pthread_rwlock_destroy(rwlock: *mut pthread_rwlock_t) -> libc: pub extern "C" fn pthread_rwlock_init( rwlock: *mut pthread_rwlock_t, attr: *const pthread_rwlockattr_t, -) -> libc::c_int { +) -> c_int { unimplemented!(); } // #[no_mangle] -pub extern "C" fn pthread_rwlock_rdlock(rwlock: *mut pthread_rwlock_t) -> libc::c_int { +pub extern "C" fn pthread_rwlock_rdlock(rwlock: *mut pthread_rwlock_t) -> c_int { unimplemented!(); } // #[no_mangle] -pub extern "C" fn pthread_rwlock_tryrdlock(rwlock: *mut pthread_rwlock_t) -> libc::c_int { +pub extern "C" fn pthread_rwlock_tryrdlock(rwlock: *mut pthread_rwlock_t) -> c_int { unimplemented!(); } // #[no_mangle] -pub extern "C" fn pthread_rwlock_trywrlock(rwlock: *mut pthread_rwlock_t) -> libc::c_int { +pub extern "C" fn pthread_rwlock_trywrlock(rwlock: *mut pthread_rwlock_t) -> c_int { unimplemented!(); } // #[no_mangle] -pub extern "C" fn pthread_rwlock_unlock(rwlock: *mut pthread_rwlock_t) -> libc::c_int { +pub extern "C" fn pthread_rwlock_unlock(rwlock: *mut pthread_rwlock_t) -> c_int { unimplemented!(); } // #[no_mangle] -pub extern "C" fn pthread_rwlock_wrlock(rwlock: *mut pthread_rwlock_t) -> libc::c_int { +pub extern "C" fn pthread_rwlock_wrlock(rwlock: *mut pthread_rwlock_t) -> c_int { unimplemented!(); } // #[no_mangle] -pub extern "C" fn pthread_rwlockattr_destroy(rwlock: *mut pthread_rwlockattr_t) -> libc::c_int { +pub extern "C" fn pthread_rwlockattr_destroy(rwlock: *mut pthread_rwlockattr_t) -> c_int { unimplemented!(); } // #[no_mangle] pub extern "C" fn pthread_rwlockattr_getpshared( rwlock: *const pthread_rwlockattr_t, - pshared: *mut libc::c_int, -) -> libc::c_int { + pshared: *mut c_int, +) -> c_int { unimplemented!(); } // #[no_mangle] -pub extern "C" fn pthread_rwlockattr_init(rwlock: *mut pthread_rwlockattr_t) -> libc::c_int { +pub extern "C" fn pthread_rwlockattr_init(rwlock: *mut pthread_rwlockattr_t) -> c_int { unimplemented!(); } // #[no_mangle] pub extern "C" fn pthread_rwlockattr_setpshared( rwlock: *mut pthread_rwlockattr_t, - pshared: libc::c_int, -) -> libc::c_int { + pshared: c_int, +) -> c_int { unimplemented!(); } @@ -470,34 +483,34 @@ pub extern "C" fn pthread_self() -> pthread_t { } // #[no_mangle] -pub extern "C" fn pthread_setcancelstate(state: libc::c_int, oldstate: *mut libc::c_int) -> libc::c_int { +pub extern "C" fn pthread_setcancelstate(state: c_int, oldstate: *mut c_int) -> c_int { unimplemented!(); } // #[no_mangle] -pub extern "C" fn pthread_setcanceltype(type_: libc::c_int, oldtype: *mut libc::c_int) -> libc::c_int { +pub extern "C" fn pthread_setcanceltype(type_: c_int, oldtype: *mut c_int) -> c_int { unimplemented!(); } // #[no_mangle] -pub extern "C" fn pthread_setconcurrency(new_level: libc::c_int) -> libc::c_int { +pub extern "C" fn pthread_setconcurrency(new_level: c_int) -> c_int { unimplemented!(); } // #[no_mangle] pub extern "C" fn pthread_setschedparam( thread: pthread_t, - policy: libc::c_int, + policy: c_int, param: *mut sched_param, -) -> libc::c_int { +) -> c_int { unimplemented!(); } // #[no_mangle] pub extern "C" fn pthread_setspecific( key: pthread_key_t, - value: *const libc::c_void, -) -> libc::c_int { + value: *const c_void, +) -> c_int { unimplemented!(); } @@ -505,44 +518,3 @@ pub extern "C" fn pthread_setspecific( pub extern "C" fn pthread_testcancel() { unimplemented!(); } - -#[repr(C)] -#[derive(Debug, Copy)] -pub struct sched_param { - pub _address: u8, -} -impl Clone for sched_param { - fn clone(&self) -> Self { - *self - } -} -#[repr(C)] -#[derive(Debug, Copy)] -pub struct sched_param { - pub _address: u8, -} -impl Clone for sched_param { - fn clone(&self) -> Self { - *self - } -} -#[repr(C)] -#[derive(Debug, Copy)] -pub struct sched_param { - pub _address: u8, -} -impl Clone for sched_param { - fn clone(&self) -> Self { - *self - } -} -#[repr(C)] -#[derive(Debug, Copy)] -pub struct sched_param { - pub _address: u8, -} -impl Clone for sched_param { - fn clone(&self) -> Self { - *self - } -} diff --git a/src/header/_todo/wctype/lib.rs b/src/header/_todo/wctype/lib.rs deleted file mode 100644 index c0666b6d09..0000000000 --- a/src/header/_todo/wctype/lib.rs +++ /dev/null @@ -1,89 +0,0 @@ -// #[no_mangle] -pub extern "C" fn iswalnum(wc: wint_t, locale: locale_t) -> libc::c_int { - unimplemented!(); -} - -// #[no_mangle] -pub extern "C" fn iswalpha(wc: wint_t, locale: locale_t) -> libc::c_int { - unimplemented!(); -} - -// #[no_mangle] -pub extern "C" fn iswcntrl(wc: wint_t, locale: locale_t) -> libc::c_int { - unimplemented!(); -} - -// #[no_mangle] -pub extern "C" fn iswdigit(wc: wint_t, locale: locale_t) -> libc::c_int { - unimplemented!(); -} - -// #[no_mangle] -pub extern "C" fn iswgraph(wc: wint_t, locale: locale_t) -> libc::c_int { - unimplemented!(); -} - -// #[no_mangle] -pub extern "C" fn iswlower(wc: wint_t, locale: locale_t) -> libc::c_int { - unimplemented!(); -} - -// #[no_mangle] -pub extern "C" fn iswprint(wc: wint_t, locale: locale_t) -> libc::c_int { - unimplemented!(); -} - -// #[no_mangle] -pub extern "C" fn iswpunct(wc: wint_t, locale: locale_t) -> libc::c_int { - unimplemented!(); -} - -// #[no_mangle] -pub extern "C" fn iswspace(wc: wint_t, locale: locale_t) -> libc::c_int { - unimplemented!(); -} - -// #[no_mangle] -pub extern "C" fn iswupper(wc: wint_t, locale: locale_t) -> libc::c_int { - unimplemented!(); -} - -// #[no_mangle] -pub extern "C" fn iswxdigit(wc: wint_t, locale: locale_t) -> libc::c_int { - unimplemented!(); -} - -// #[no_mangle] -pub extern "C" fn iswblank(wc: wint_t, locale: locale_t) -> libc::c_int { - unimplemented!(); -} - -// #[no_mangle] -pub extern "C" fn wctype(property: *const libc::c_char, locale: locale_t) -> wctype_t { - unimplemented!(); -} - -// #[no_mangle] -pub extern "C" fn iswctype(wc: wint_t, desc: wctype_t, locale: locale_t) -> libc::c_int { - unimplemented!(); -} - -// #[no_mangle] -pub extern "C" fn towlower(wc: wint_t, locale: locale_t) -> wint_t { - unimplemented!(); -} - -// #[no_mangle] -pub extern "C" fn towupper(wc: wint_t, locale: locale_t) -> wint_t { - unimplemented!(); -} - -// #[no_mangle] -pub extern "C" fn wctrans(property: *const libc::c_char, locale: locale_t) -> wctrans_t { - unimplemented!(); -} - -// #[no_mangle] -pub extern "C" fn towctrans(wc: wint_t, desc: wctrans_t, locale: locale_t) -> wint_t { - unimplemented!(); -} diff --git a/src/header/aio/cbindgen.toml b/src/header/aio/cbindgen.toml new file mode 100644 index 0000000000..007f687f94 --- /dev/null +++ b/src/header/aio/cbindgen.toml @@ -0,0 +1,7 @@ +sys_includes = [] +include_guard = "_AIO_H" +language = "C" +style = "Tag" + +[enum] +prefix_with_name = true diff --git a/src/header/_todo/aio/lib.rs b/src/header/aio/mod.rs similarity index 51% rename from src/header/_todo/aio/lib.rs rename to src/header/aio/mod.rs index 40002aa511..d1d9ef49f5 100644 --- a/src/header/_todo/aio/lib.rs +++ b/src/header/aio/mod.rs @@ -1,34 +1,37 @@ +use header::time::sigevent; +use platform::types::*; + pub struct aiocb { - pub aio_fildes: libc::c_int, - pub aio_lio_opcode: libc::c_int, - pub aio_reqprio: libc::c_int, - pub aio_buf: *mut libc::c_void, + pub aio_fildes: c_int, + pub aio_lio_opcode: c_int, + pub aio_reqprio: c_int, + pub aio_buf: *mut c_void, pub aio_nbytes: usize, pub aio_sigevent: sigevent, } // #[no_mangle] -pub extern "C" fn aio_read(aiocbp: *mut aiocb) -> libc::c_int { +pub extern "C" fn aio_read(aiocbp: *mut aiocb) -> c_int { unimplemented!(); } // #[no_mangle] -pub extern "C" fn aio_write(aiocbp: *mut aiocb) -> libc::c_int { +pub extern "C" fn aio_write(aiocbp: *mut aiocb) -> c_int { unimplemented!(); } // #[no_mangle] pub extern "C" fn lio_listio( - mode: libc::c_int, + mode: c_int, list: *const *const aiocb, - nent: libc::c_int, + nent: c_int, sig: *mut sigevent, -) -> libc::c_int { +) -> c_int { unimplemented!(); } // #[no_mangle] -pub extern "C" fn aio_error(aiocbp: *const aiocb) -> libc::c_int { +pub extern "C" fn aio_error(aiocbp: *const aiocb) -> c_int { unimplemented!(); } @@ -38,20 +41,20 @@ pub extern "C" fn aio_return(aiocbp: *mut aiocb) -> usize { } // #[no_mangle] -pub extern "C" fn aio_cancel(fildes: libc::c_int, aiocbp: *mut aiocb) -> libc::c_int { +pub extern "C" fn aio_cancel(fildes: c_int, aiocbp: *mut aiocb) -> c_int { unimplemented!(); } // #[no_mangle] pub extern "C" fn aio_suspend( list: *const *const aiocb, - nent: libc::c_int, + nent: c_int, timeout: *const timespec, -) -> libc::c_int { +) -> c_int { unimplemented!(); } // #[no_mangle] -pub extern "C" fn aio_fsync(operation: libc::c_int, aiocbp: *mut aiocb) -> libc::c_int { +pub extern "C" fn aio_fsync(operation: c_int, aiocbp: *mut aiocb) -> c_int { unimplemented!(); } diff --git a/src/header/dirent/mod.rs b/src/header/dirent/mod.rs index d1967fea3e..09ba4a7f9e 100644 --- a/src/header/dirent/mod.rs +++ b/src/header/dirent/mod.rs @@ -5,8 +5,8 @@ use core::{mem, ptr}; use header::{errno, fcntl, unistd}; use platform; -use platform::{Pal, Sys}; use platform::types::*; +use platform::{Pal, Sys}; const DIR_BUF_SIZE: usize = mem::size_of::() * 3; diff --git a/src/header/fcntl/mod.rs b/src/header/fcntl/mod.rs index 8ce772043b..a22d0eb528 100644 --- a/src/header/fcntl/mod.rs +++ b/src/header/fcntl/mod.rs @@ -1,7 +1,7 @@ //! fcntl implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/fcntl.h.html -use platform::{Pal, Sys}; use platform::types::*; +use platform::{Pal, Sys}; pub use self::sys::*; diff --git a/src/header/fnmatch/mod.rs b/src/header/fnmatch/mod.rs index ee5ffaf345..32819f0a4b 100644 --- a/src/header/fnmatch/mod.rs +++ b/src/header/fnmatch/mod.rs @@ -8,7 +8,7 @@ pub const FNM_NOMATCH: c_int = 1; pub const FNM_NOESCAPE: c_int = 1; pub const FNM_PATHNAME: c_int = 2; -pub const FNM_PERIOD: c_int = 4; +pub const FNM_PERIOD: c_int = 4; pub const FNM_CASEFOLD: c_int = 8; #[derive(Debug)] @@ -39,7 +39,7 @@ unsafe fn next_token(pattern: &mut *const c_char, flags: c_int) -> Option } *pattern = pattern.offset(1); Token::Char(c) - }, + } b'?' => Token::Any, b'*' => Token::Wildcard, b'[' => { @@ -47,7 +47,9 @@ unsafe fn next_token(pattern: &mut *const c_char, flags: c_int) -> Option let invert = if **pattern as u8 == b'!' { *pattern = pattern.offset(1); true - } else { false }; + } else { + false + }; loop { let mut c = **pattern as u8; @@ -64,8 +66,8 @@ unsafe fn next_token(pattern: &mut *const c_char, flags: c_int) -> Option // Trailing backslash. Maybe error? break; } - }, - _ => () + } + _ => (), } if matches.len() >= 2 && matches[matches.len() - 1] == b'-' { let len = matches.len(); @@ -81,13 +83,17 @@ unsafe fn next_token(pattern: &mut *const c_char, flags: c_int) -> Option // Otherwise, there was no closing ]. Maybe error? Token::Match(invert, matches) - }, - c => Token::Char(c) + } + c => Token::Char(c), }) } #[no_mangle] -pub unsafe extern "C" fn fnmatch(mut pattern: *const c_char, mut input: *const c_char, flags: c_int) -> c_int { +pub unsafe extern "C" fn fnmatch( + mut pattern: *const c_char, + mut input: *const c_char, + flags: c_int, +) -> c_int { let pathname = flags & FNM_PATHNAME == FNM_PATHNAME; let casefold = flags & FNM_CASEFOLD == FNM_CASEFOLD; @@ -109,7 +115,7 @@ pub unsafe extern "C" fn fnmatch(mut pattern: *const c_char, mut input: *const c return FNM_NOMATCH; } input = input.offset(1); - }, + } Some(Token::Char(c)) => { let mut a = *input as u8; if casefold && a >= b'a' && a <= b'z' { @@ -126,14 +132,15 @@ pub unsafe extern "C" fn fnmatch(mut pattern: *const c_char, mut input: *const c leading = true; } input = input.offset(1); - }, + } Some(Token::Match(invert, matches)) => { - if (pathname && *input as u8 == b'/') || matches.contains(&(*input as u8)) == invert { + if (pathname && *input as u8 == b'/') || matches.contains(&(*input as u8)) == invert + { // Found it, but it's inverted! Or vise versa. return FNM_NOMATCH; } input = input.offset(1); - }, + } Some(Token::Wildcard) => { loop { let c = *input as u8; @@ -155,8 +162,8 @@ pub unsafe extern "C" fn fnmatch(mut pattern: *const c_char, mut input: *const c } } unreachable!("nothing should be able to break out of the loop"); - }, - None => return FNM_NOMATCH // Pattern ended but there's still some input + } + None => return FNM_NOMATCH, // Pattern ended but there's still some input } } } diff --git a/src/header/mod.rs b/src/header/mod.rs index 4fdee75126..0e1556201f 100644 --- a/src/header/mod.rs +++ b/src/header/mod.rs @@ -1,3 +1,4 @@ +pub mod aio; pub mod arpa_inet; pub mod ctype; pub mod dirent; @@ -10,6 +11,7 @@ pub mod grp; pub mod inttypes; pub mod locale; pub mod netinet_in; +//pub mod pthread; pub mod pwd; pub mod semaphore; pub mod setjmp; diff --git a/src/header/netinet_in/mod.rs b/src/header/netinet_in/mod.rs index f3819f604f..db230c997b 100644 --- a/src/header/netinet_in/mod.rs +++ b/src/header/netinet_in/mod.rs @@ -9,19 +9,19 @@ pub type in_port_t = u16; #[repr(C)] #[derive(Debug, Clone, Copy)] pub struct in_addr { - pub s_addr: in_addr_t + pub s_addr: in_addr_t, } #[repr(C)] pub struct in6_addr { - pub s6_addr: [u8; 16] + pub s6_addr: [u8; 16], } #[repr(C)] pub struct sockaddr_in { pub sin_family: sa_family_t, pub sin_port: in_port_t, - pub sin_addr: in_addr + pub sin_addr: in_addr, } #[repr(C)] @@ -30,7 +30,7 @@ pub struct sockaddr_in6 { pub sin6_port: in_port_t, pub sin6_flowinfo: u32, pub sin6_addr: in6_addr, - pub sin6_scope_id: u32 + pub sin6_scope_id: u32, } #[repr(C)] diff --git a/src/header/pwd/mod.rs b/src/header/pwd/mod.rs index f455e40c62..139acc389a 100644 --- a/src/header/pwd/mod.rs +++ b/src/header/pwd/mod.rs @@ -5,9 +5,9 @@ use core::ptr; use header::{errno, fcntl}; use platform; -use platform::{Pal, Sys}; use platform::types::*; use platform::RawFile; +use platform::{Pal, Sys}; #[repr(C)] pub struct passwd { diff --git a/src/header/sgtty/mod.rs b/src/header/sgtty/mod.rs index c8950c506b..b5f1a40900 100644 --- a/src/header/sgtty/mod.rs +++ b/src/header/sgtty/mod.rs @@ -2,9 +2,9 @@ use core::fmt::Write; +use header::sys_ioctl::*; use platform; use platform::types::*; -use header::sys_ioctl::*; #[no_mangle] pub extern "C" fn gtty(fd: c_int, out: *mut sgttyb) -> c_int { diff --git a/src/header/signal/mod.rs b/src/header/signal/mod.rs index 9929bd0709..c9259651d1 100644 --- a/src/header/signal/mod.rs +++ b/src/header/signal/mod.rs @@ -4,8 +4,8 @@ use core::{mem, ptr}; use header::errno; use platform; -use platform::{PalSignal, Sys}; use platform::types::*; +use platform::{PalSignal, Sys}; pub use self::sys::*; @@ -147,7 +147,10 @@ extern "C" { } #[no_mangle] -pub extern "C" fn signal(sig: c_int, func: Option) -> Option { +pub extern "C" fn signal( + sig: c_int, + func: Option, +) -> Option { let sa = sigaction { sa_handler: func, sa_flags: SA_RESTART as c_ulong, @@ -229,5 +232,5 @@ pub const _signal_strings: [&'static str; 32] = [ "Window changed\0", "I/O possible\0", "Power failure\0", - "Bad system call\0" + "Bad system call\0", ]; diff --git a/src/header/stdio/mod.rs b/src/header/stdio/mod.rs index 5bbe0aae6a..48f3148835 100644 --- a/src/header/stdio/mod.rs +++ b/src/header/stdio/mod.rs @@ -9,10 +9,12 @@ use va_list::VaList as va_list; use header::errno::{self, STR_ERROR}; use header::fcntl; +use header::stdlib::mkstemp; +use header::string::strlen; use platform; -use platform::{Pal, Sys}; use platform::types::*; use platform::{c_str, errno, Read, Write}; +use platform::{Pal, Sys}; mod printf; mod scanf; @@ -220,7 +222,7 @@ impl<'a> Read for LockGuard<'a> { let mut buf = [0]; match self.0.read(&mut buf) { 0 => Ok(None), - _ => Ok(Some(buf[0])) + _ => Ok(Some(buf[0])), } } } @@ -452,9 +454,6 @@ pub extern "C" fn fputc(c: c_int, stream: &mut FILE) -> c_int { /// Insert a string into a stream #[no_mangle] pub extern "C" fn fputs(s: *const c_char, stream: &mut FILE) -> c_int { - extern "C" { - fn strlen(s: *const c_char) -> size_t; - } let len = unsafe { strlen(s) }; (fwrite(s as *const c_void, 1, len, stream) == len) as c_int - 1 } @@ -886,10 +885,6 @@ pub extern "C" fn tempnam(_dir: *const c_char, _pfx: *const c_char) -> *mut c_ch #[no_mangle] pub extern "C" fn tmpfile() -> *mut FILE { - extern "C" { - fn mkstemp(name: *mut c_char) -> c_int; - } - let mut file_name = *b"/tmp/tmpfileXXXXXX"; let file_name = file_name.as_mut_ptr() as *mut c_char; let fd = unsafe { mkstemp(file_name) }; diff --git a/src/header/stdio/scanf.rs b/src/header/stdio/scanf.rs index bdb12fb4fa..d9cd3e15eb 100644 --- a/src/header/stdio/scanf.rs +++ b/src/header/stdio/scanf.rs @@ -44,9 +44,9 @@ unsafe fn inner_scanf( byte = b; count += 1; true - }, + } Ok(None) => false, - Err(()) => return Err(-1) + Err(()) => return Err(-1), } }}; } diff --git a/src/header/stdlib/mod.rs b/src/header/stdlib/mod.rs index fd617c506b..6de7e36f02 100644 --- a/src/header/stdlib/mod.rs +++ b/src/header/stdlib/mod.rs @@ -6,15 +6,15 @@ use rand::prng::XorShiftRng; use rand::rngs::JitterRng; use rand::{Rng, SeedableRng}; -use header::{ctype, errno, unistd}; use header::errno::*; use header::fcntl::*; use header::string::*; use header::time::constants::CLOCK_MONOTONIC; use header::wchar::*; +use header::{ctype, errno, unistd}; use platform; -use platform::{Pal, Sys}; use platform::types::*; +use platform::{Pal, Sys}; mod sort; @@ -507,7 +507,11 @@ pub unsafe extern "C" fn putenv(insert: *mut c_char) -> c_int { platform::inner_environ[i] = insert; } else { let i = platform::inner_environ.len() - 1; - assert_eq!(platform::inner_environ[i], ptr::null_mut(), "environ did not end with null"); + assert_eq!( + platform::inner_environ[i], + ptr::null_mut(), + "environ did not end with null" + ); platform::inner_environ[i] = insert; platform::inner_environ.push(ptr::null_mut()); platform::environ = platform::inner_environ.as_mut_ptr(); @@ -571,7 +575,11 @@ pub extern "C" fn seed48(seed16v: [c_ushort; 3]) -> c_ushort { } #[no_mangle] -pub unsafe extern "C" fn setenv(mut key: *const c_char, mut value: *const c_char, overwrite: c_int) -> c_int { +pub unsafe extern "C" fn setenv( + mut key: *const c_char, + mut value: *const c_char, + overwrite: c_int, +) -> c_int { let mut key_len = 0; while *key.offset(key_len) != 0 { key_len += 1; @@ -602,7 +610,11 @@ pub unsafe extern "C" fn setenv(mut key: *const c_char, mut value: *const c_char } } else { let i = platform::inner_environ.len() - 1; - assert_eq!(platform::inner_environ[i], ptr::null_mut(), "environ did not end with null"); + assert_eq!( + platform::inner_environ[i], + ptr::null_mut(), + "environ did not end with null" + ); platform::inner_environ.push(ptr::null_mut()); platform::environ = platform::inner_environ.as_mut_ptr(); i @@ -664,9 +676,15 @@ pub unsafe extern "C" fn strtod(mut s: *const c_char, endptr: *mut *mut c_char) let mut radix = 10; let negative = match *s as u8 { - b'-' => { s = s.offset(1); true }, - b'+' => { s = s.offset(1); false }, - _ => false + b'-' => { + s = s.offset(1); + true + } + b'+' => { + s = s.offset(1); + false + } + _ => false, }; if *s as u8 == b'0' && *s.offset(1) as u8 == b'x' { @@ -855,7 +873,11 @@ pub unsafe extern "C" fn strtoull( } #[no_mangle] -pub unsafe extern "C" fn strtoll(s: *const c_char, endptr: *mut *mut c_char, base: c_int) -> c_long { +pub unsafe extern "C" fn strtoll( + s: *const c_char, + endptr: *mut *mut c_char, + base: c_int, +) -> c_long { strtol(s, endptr, base) } diff --git a/src/header/string/mod.rs b/src/header/string/mod.rs index bd09b9740e..cb48b8871b 100644 --- a/src/header/string/mod.rs +++ b/src/header/string/mod.rs @@ -4,8 +4,8 @@ use core::mem; use core::ptr; use core::usize; -use header::signal; use header::errno::*; +use header::signal; use platform; use platform::types::*; @@ -179,14 +179,15 @@ pub unsafe fn inner_strspn(s1: *const c_char, s2: *const c_char, cmp: bool) -> s let mut i = 0; while *s2.offset(i) != 0 { byteset[(*s2.offset(i) as usize) / BITSIZE] |= - 1 << (*s2.offset(i) as usize & (BITSIZE-1)); + 1 << (*s2.offset(i) as usize & (BITSIZE - 1)); i += 1; } i = 0; // reset - while *s1.offset(i) != 0 && - (byteset[(*s1.offset(i) as usize) / BITSIZE] & - 1 << (*s1.offset(i) as usize & (BITSIZE-1)) != 0) == cmp { + while *s1.offset(i) != 0 + && (byteset[(*s1.offset(i) as usize) / BITSIZE] + & 1 << (*s1.offset(i) as usize & (BITSIZE - 1)) != 0) == cmp + { i += 1; } i as size_t diff --git a/src/header/sys_file/mod.rs b/src/header/sys_file/mod.rs index f126dd64ba..80a99855c4 100644 --- a/src/header/sys_file/mod.rs +++ b/src/header/sys_file/mod.rs @@ -1,7 +1,7 @@ //! sys/file.h implementation -use platform::{Pal, Sys}; use platform::types::*; +use platform::{Pal, Sys}; pub const LOCK_SH: usize = 1; pub const LOCK_EX: usize = 2; diff --git a/src/header/sys_ioctl/mod.rs b/src/header/sys_ioctl/mod.rs index 78d7714d5c..adbdd7f3e2 100644 --- a/src/header/sys_ioctl/mod.rs +++ b/src/header/sys_ioctl/mod.rs @@ -1,6 +1,5 @@ //! ioctl implementation for linux -use platform::{Pal, Sys}; use platform::types::*; // This is used from sgtty @@ -15,7 +14,8 @@ pub struct sgttyb { #[cfg(target_os = "linux")] pub mod inner { - use super::*; + use platform::types::*; + use platform::{Pal, Sys}; #[repr(C)] pub struct winsize { diff --git a/src/header/sys_mman/mod.rs b/src/header/sys_mman/mod.rs index 56730d401e..013050a053 100644 --- a/src/header/sys_mman/mod.rs +++ b/src/header/sys_mman/mod.rs @@ -1,5 +1,5 @@ -use platform::{Pal, Sys}; use platform::types::*; +use platform::{Pal, Sys}; pub use self::sys::*; diff --git a/src/header/sys_resource/mod.rs b/src/header/sys_resource/mod.rs index 1b8dae9258..6afcc6fe9b 100644 --- a/src/header/sys_resource/mod.rs +++ b/src/header/sys_resource/mod.rs @@ -3,8 +3,8 @@ use header::sys_time::timeval; use platform; -use platform::{Pal, Sys}; use platform::types::*; +use platform::{Pal, Sys}; // Exported in bits file const RUSAGE_SELF: c_int = 0; diff --git a/src/header/sys_select/mod.rs b/src/header/sys_select/mod.rs index 99590e65e6..dcb40b6af6 100644 --- a/src/header/sys_select/mod.rs +++ b/src/header/sys_select/mod.rs @@ -1,7 +1,7 @@ //! sys/select.h implementation -use platform::{Pal, Sys}; use platform::types::*; +use platform::{Pal, Sys}; // fd_set is defined in C because cbindgen is incompatible with mem::size_of booo diff --git a/src/header/sys_socket/mod.rs b/src/header/sys_socket/mod.rs index 30ff349e4d..5a305274ef 100644 --- a/src/header/sys_socket/mod.rs +++ b/src/header/sys_socket/mod.rs @@ -3,8 +3,8 @@ use core::ptr; use platform; -use platform::{PalSocket, Sys}; use platform::types::*; +use platform::{PalSocket, Sys}; mod constants; diff --git a/src/header/sys_stat/mod.rs b/src/header/sys_stat/mod.rs index 3e393d570f..8490a3126d 100644 --- a/src/header/sys_stat/mod.rs +++ b/src/header/sys_stat/mod.rs @@ -1,9 +1,9 @@ //! stat implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/sysstat.h.html -use header::fcntl::{O_PATH, O_NOFOLLOW}; +use header::fcntl::{O_NOFOLLOW, O_PATH}; use platform; -use platform::{Pal, Sys}; use platform::types::*; +use platform::{Pal, Sys}; pub const S_IFMT: c_int = 0o0170000; diff --git a/src/header/sys_time/mod.rs b/src/header/sys_time/mod.rs index 163f9c01fb..13c67d9d45 100644 --- a/src/header/sys_time/mod.rs +++ b/src/header/sys_time/mod.rs @@ -1,8 +1,8 @@ //! sys/time implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/systime.h.html use platform; -use platform::{Pal, Sys}; use platform::types::*; +use platform::{Pal, Sys}; pub const ITIMER_REAL: c_int = 0; pub const ITIMER_VIRTUAL: c_int = 1; diff --git a/src/header/sys_times/mod.rs b/src/header/sys_times/mod.rs index 57d149da53..72c0305a2f 100644 --- a/src/header/sys_times/mod.rs +++ b/src/header/sys_times/mod.rs @@ -1,8 +1,8 @@ //! sys/times.h implementation use platform; -use platform::{Pal, Sys}; use platform::types::*; +use platform::{Pal, Sys}; #[repr(C)] pub struct tms { diff --git a/src/header/sys_utsname/mod.rs b/src/header/sys_utsname/mod.rs index 1899d90962..fcd6c80728 100644 --- a/src/header/sys_utsname/mod.rs +++ b/src/header/sys_utsname/mod.rs @@ -3,8 +3,8 @@ #[cfg(target_os = "linux")] mod inner { use platform; - use platform::{Pal, Sys}; use platform::types::*; + use platform::{Pal, Sys}; const UTSLENGTH: usize = 65; diff --git a/src/header/sys_wait/mod.rs b/src/header/sys_wait/mod.rs index b9d69f1392..346fe67723 100644 --- a/src/header/sys_wait/mod.rs +++ b/src/header/sys_wait/mod.rs @@ -2,8 +2,8 @@ //! http://pubs.opengroup.org/onlinepubs/7908799/xsh/syswait.h.html use header::sys_resource::rusage; -use platform::{Pal, Sys}; use platform::types::*; +use platform::{Pal, Sys}; pub const WNOHANG: c_int = 1; pub const WUNTRACED: c_int = 2; diff --git a/src/header/termios/mod.rs b/src/header/termios/mod.rs index fe8988f340..c9159ffdba 100644 --- a/src/header/termios/mod.rs +++ b/src/header/termios/mod.rs @@ -1,8 +1,8 @@ //! termios implementation, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/termios.h.html use platform; -use platform::{Pal, Sys}; use platform::types::*; +use platform::{Pal, Sys}; pub type cc_t = u8; pub type speed_t = u32; @@ -19,7 +19,7 @@ pub struct termios { c_line: cc_t, c_cc: [cc_t; NCCS], __c_ispeed: speed_t, - __c_ospeed: speed_t + __c_ospeed: speed_t, } #[no_mangle] diff --git a/src/header/time/mod.rs b/src/header/time/mod.rs index d8f7f98ac7..1819601a09 100644 --- a/src/header/time/mod.rs +++ b/src/header/time/mod.rs @@ -4,8 +4,8 @@ use core::mem::transmute; use header::errno::EIO; use platform; -use platform::{Pal, Sys}; use platform::types::*; +use platform::{Pal, Sys}; use self::constants::*; use self::helpers::*; diff --git a/src/header/time/strftime.rs b/src/header/time/strftime.rs index bc8a649b49..7456ce43b6 100644 --- a/src/header/time/strftime.rs +++ b/src/header/time/strftime.rs @@ -1,15 +1,11 @@ use alloc::string::String; -use platform::{self, Write}; use platform::types::*; +use platform::{self, Write}; use super::tm; -pub unsafe fn strftime( - w: &mut W, - format: *const c_char, - t: *const tm, -) -> size_t { +pub unsafe fn strftime(w: &mut W, format: *const c_char, t: *const tm) -> size_t { pub unsafe fn inner_strftime( mut w: &mut W, mut format: *const c_char, @@ -73,7 +69,7 @@ pub unsafe fn strftime( while *format != 0 { if *format as u8 != b'%' { - w!(byte *format as u8); + w!(byte * format as u8); format = format.offset(1); continue; } diff --git a/src/header/unistd/brk.rs b/src/header/unistd/brk.rs index 7cf6ead43a..07466da39b 100644 --- a/src/header/unistd/brk.rs +++ b/src/header/unistd/brk.rs @@ -2,8 +2,8 @@ use core::ptr; use header::errno::ENOMEM; use platform; -use platform::{Pal, Sys}; use platform::types::*; +use platform::{Pal, Sys}; static mut BRK: *mut c_void = ptr::null_mut(); diff --git a/src/header/unistd/mod.rs b/src/header/unistd/mod.rs index 2e565ed43c..817504658a 100644 --- a/src/header/unistd/mod.rs +++ b/src/header/unistd/mod.rs @@ -4,8 +4,8 @@ use core::{ptr, slice}; use header::sys_time; use platform; -use platform::{Pal, Sys}; use platform::types::*; +use platform::{Pal, Sys}; pub use self::brk::*; pub use self::getopt::*; @@ -195,7 +195,10 @@ pub extern "C" fn getcwd(mut buf: *mut c_char, mut size: size_t) -> *mut c_char } if alloc { - let mut len = stack_buf.iter().position(|b| *b == 0).expect("no nul-byte in getcwd string") + 1; + let mut len = stack_buf + .iter() + .position(|b| *b == 0) + .expect("no nul-byte in getcwd string") + 1; let mut heap_buf = unsafe { platform::alloc(len) as *mut c_char }; for i in 0..len { unsafe { diff --git a/src/header/utime/mod.rs b/src/header/utime/mod.rs index 928243b1aa..dd891aa6ee 100644 --- a/src/header/utime/mod.rs +++ b/src/header/utime/mod.rs @@ -1,7 +1,7 @@ //! utime implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/utime.h.html -use platform::{Pal, Sys}; use platform::types::*; +use platform::{Pal, Sys}; #[repr(C)] #[derive(Clone)] diff --git a/src/platform/linux/mod.rs b/src/platform/linux/mod.rs index 232b6a11a6..5ef98c4626 100644 --- a/src/platform/linux/mod.rs +++ b/src/platform/linux/mod.rs @@ -1,8 +1,8 @@ -use core::{mem, ptr}; use core::fmt::Write; +use core::{mem, ptr}; -use super::{errno, FileWriter, Pal}; use super::types::*; +use super::{errno, FileWriter, Pal}; mod signal; mod socket; @@ -79,7 +79,11 @@ impl Pal for Sys { e(unsafe { syscall!(DUP3, fildes, fildes2, 0) }) as c_int } - unsafe fn execve(path: *const c_char, argv: *const *mut c_char, envp: *const *mut c_char) -> c_int { + unsafe fn execve( + path: *const c_char, + argv: *const *mut c_char, + envp: *const *mut c_char, + ) -> c_int { e(syscall!(EXECVE, path, argv, envp)) as c_int } diff --git a/src/platform/linux/signal.rs b/src/platform/linux/signal.rs index 0e2e72d80d..9ad5cff3b4 100644 --- a/src/platform/linux/signal.rs +++ b/src/platform/linux/signal.rs @@ -1,8 +1,8 @@ use core::mem; -use super::{e, Sys}; -use super::super::PalSignal; use super::super::types::*; +use super::super::PalSignal; +use super::{e, Sys}; impl PalSignal for Sys { fn kill(pid: pid_t, sig: c_int) -> c_int { diff --git a/src/platform/linux/socket.rs b/src/platform/linux/socket.rs index 73707d7e42..7b030b609c 100644 --- a/src/platform/linux/socket.rs +++ b/src/platform/linux/socket.rs @@ -1,6 +1,6 @@ -use super::{e, Sys}; -use super::super::PalSocket; use super::super::types::*; +use super::super::PalSocket; +use super::{e, Sys}; impl PalSocket for Sys { unsafe fn accept(socket: c_int, address: *mut sockaddr, address_len: *mut socklen_t) -> c_int { diff --git a/src/platform/mod.rs b/src/platform/mod.rs index 4abdab5df7..53acee0e0f 100644 --- a/src/platform/mod.rs +++ b/src/platform/mod.rs @@ -160,7 +160,7 @@ impl Read for FileReader { match self.read(&mut buf) { 0 => Ok(None), n if n < 0 => Err(()), - _ => Ok(Some(buf[0])) + _ => Ok(Some(buf[0])), } } } @@ -258,13 +258,13 @@ impl Read for UnsafeStringReader { pub struct CountingWriter { pub inner: T, - pub written: usize + pub written: usize, } impl CountingWriter { - pub /* const */ fn new(writer: T) -> Self { + pub fn new(writer: T) -> Self { Self { inner: writer, - written: 0 + written: 0, } } } diff --git a/src/platform/pal/mod.rs b/src/platform/pal/mod.rs index 25b8ea242d..4d15c3b26b 100644 --- a/src/platform/pal/mod.rs +++ b/src/platform/pal/mod.rs @@ -45,7 +45,11 @@ pub trait Pal { Self::no_pal("dup2") } - unsafe fn execve(path: *const c_char, argv: *const *mut c_char, envp: *const *mut c_char) -> c_int { + unsafe fn execve( + path: *const c_char, + argv: *const *mut c_char, + envp: *const *mut c_char, + ) -> c_int { Self::no_pal("execve") } diff --git a/src/platform/pal/signal.rs b/src/platform/pal/signal.rs index e8a40a9621..f8d69fd2c3 100644 --- a/src/platform/pal/signal.rs +++ b/src/platform/pal/signal.rs @@ -1,5 +1,5 @@ -use super::super::Pal; use super::super::types::*; +use super::super::Pal; pub trait PalSignal: Pal { fn kill(pid: pid_t, sig: c_int) -> c_int { diff --git a/src/platform/pal/socket.rs b/src/platform/pal/socket.rs index 8e8c1f6d90..aac4205687 100644 --- a/src/platform/pal/socket.rs +++ b/src/platform/pal/socket.rs @@ -1,5 +1,5 @@ -use super::super::Pal; use super::super::types::*; +use super::super::Pal; pub trait PalSocket: Pal { unsafe fn accept(socket: c_int, address: *mut sockaddr, address_len: *mut socklen_t) -> c_int { @@ -14,11 +14,19 @@ pub trait PalSocket: Pal { Self::no_pal("connect") } - unsafe fn getpeername(socket: c_int, address: *mut sockaddr, address_len: *mut socklen_t) -> c_int { + unsafe fn getpeername( + socket: c_int, + address: *mut sockaddr, + address_len: *mut socklen_t, + ) -> c_int { Self::no_pal("getpeername") } - unsafe fn getsockname(socket: c_int, address: *mut sockaddr, address_len: *mut socklen_t) -> c_int { + unsafe fn getsockname( + socket: c_int, + address: *mut sockaddr, + address_len: *mut socklen_t, + ) -> c_int { Self::no_pal("getsockname") } diff --git a/src/platform/rawfile.rs b/src/platform/rawfile.rs index 338ed0b4f3..4686ce8d04 100644 --- a/src/platform/rawfile.rs +++ b/src/platform/rawfile.rs @@ -1,6 +1,6 @@ use core::ops::Deref; -use super::{Pal, Sys, types::*}; +use super::{types::*, Pal, Sys}; pub struct RawFile(c_int); diff --git a/src/platform/redox/mod.rs b/src/platform/redox/mod.rs index 7c93747043..02bb24e1e4 100644 --- a/src/platform/redox/mod.rs +++ b/src/platform/redox/mod.rs @@ -1,16 +1,16 @@ //! sys/socket implementation, following http://pubs.opengroup.org/onlinepubs/009696699/basedefs/sys/socket.h.html use alloc::btree_map::BTreeMap; -use core::{mem, ptr, slice}; use core::fmt::Write; -use spin::{Once, Mutex, MutexGuard}; +use core::{mem, ptr, slice}; +use spin::{Mutex, MutexGuard, Once}; use syscall::data::Stat as redox_stat; use syscall::data::TimeSpec as redox_timespec; use syscall::flag::*; use syscall::{self, Result}; -use super::{c_str, errno, FileReader, FileWriter, Pal, RawFile, Read}; use super::types::*; +use super::{c_str, errno, FileReader, FileWriter, Pal, RawFile, Read}; mod signal; mod socket; @@ -22,7 +22,9 @@ const MAP_ANON: c_int = 1; static ANONYMOUS_MAPS: Once>> = Once::new(); fn anonymous_maps() -> MutexGuard<'static, BTreeMap> { - ANONYMOUS_MAPS.call_once(|| Mutex::new(BTreeMap::new())).lock() + ANONYMOUS_MAPS + .call_once(|| Mutex::new(BTreeMap::new())) + .lock() } fn e(sys: Result) -> usize { @@ -51,7 +53,7 @@ impl Pal for Sys { fn access(path: *const c_char, mode: c_int) -> c_int { let fd = match RawFile::open(path, 0, 0) { Ok(fd) => fd, - Err(_) => return -1 + Err(_) => return -1, }; if mode == F_OK { return 0; @@ -82,8 +84,9 @@ impl Pal for Sys { stat.st_mode & 0o7 }; if (mode & R_OK == R_OK && perms & 0o4 != 0o4) - || (mode & W_OK == W_OK && perms & 0o2 != 0o2) - || (mode & X_OK == X_OK && perms & 0o1 != 0o1) { + || (mode & W_OK == W_OK && perms & 0o2 != 0o2) + || (mode & X_OK == X_OK && perms & 0o1 != 0o1) + { unsafe { errno = EINVAL; } @@ -166,7 +169,7 @@ impl Pal for Sys { let fd = match RawFile::open(path, O_RDONLY as c_int, 0) { Ok(fd) => fd, - Err(_) => return -1 + Err(_) => return -1, }; let mut len = 0; @@ -383,12 +386,12 @@ impl Pal for Sys { Ok(Some(b)) => { *name = b as c_char; name = name.offset(1); - }, + } Ok(None) => { *name = 0; break; - }, - Err(()) => return -1 + } + Err(()) => return -1, } } 0 @@ -694,10 +697,9 @@ impl Pal for Sys { return -1; } - let read = e(syscall::read(dup, unsafe { slice::from_raw_parts_mut( - out as *mut u8, - mem::size_of::() - ) })); + let read = e(syscall::read(dup, unsafe { + slice::from_raw_parts_mut(out as *mut u8, mem::size_of::()) + })); let _ = syscall::close(dup); if read == !0 { @@ -712,10 +714,9 @@ impl Pal for Sys { return -1; } - let write = e(syscall::write(dup, unsafe { slice::from_raw_parts( - value as *const u8, - mem::size_of::() - ) })); + let write = e(syscall::write(dup, unsafe { + slice::from_raw_parts(value as *const u8, mem::size_of::()) + })); let _ = syscall::close(dup); if write == !0 { diff --git a/src/platform/redox/signal.rs b/src/platform/redox/signal.rs index 76b8b818a4..abbf8bd0d3 100644 --- a/src/platform/redox/signal.rs +++ b/src/platform/redox/signal.rs @@ -1,8 +1,8 @@ use syscall; -use super::{e, Sys}; -use super::super::{Pal, PalSignal}; use super::super::types::*; +use super::super::{Pal, PalSignal}; +use super::{e, Sys}; #[thread_local] static mut SIG_HANDLER: Option = None; diff --git a/src/platform/redox/socket.rs b/src/platform/redox/socket.rs index 7de759dab5..501c4b899b 100644 --- a/src/platform/redox/socket.rs +++ b/src/platform/redox/socket.rs @@ -1,10 +1,10 @@ use core::{mem, ptr, slice}; -use syscall::{self, Result}; use syscall::flag::*; +use syscall::{self, Result}; -use super::{e, Sys}; -use super::super::{errno, Pal, PalSocket}; use super::super::types::*; +use super::super::{errno, Pal, PalSocket}; +use super::{e, Sys}; macro_rules! bind_or_connect { (bind $path:expr) => { diff --git a/src/platform/types.rs b/src/platform/types.rs index bff380a3b8..bcccee75fc 100644 --- a/src/platform/types.rs +++ b/src/platform/types.rs @@ -257,5 +257,5 @@ pub struct termios { c_line: cc_t, c_cc: [cc_t; NCCS], __c_ispeed: speed_t, - __c_ospeed: speed_t + __c_ospeed: speed_t, } diff --git a/src/start.rs b/src/start.rs index e628c4f0df..02e739f828 100644 --- a/src/start.rs +++ b/src/start.rs @@ -3,8 +3,8 @@ use core::ptr; use header::stdio; use platform; -use platform::{Pal, Sys}; use platform::types::*; +use platform::{Pal, Sys}; #[repr(C)] pub struct Stack { @@ -68,6 +68,6 @@ pub unsafe extern "C" fn relibc_start(sp: &'static Stack) -> ! { argv, // not envp, because programs like bash try to modify this *const* // pointer :| - platform::environ as *const *const c_char + platform::environ as *const *const c_char, )); } From 8f5470fd2734044e7bea769623dadd38b8cbe1ff Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Mon, 27 Aug 2018 07:12:24 -0600 Subject: [PATCH 15/19] Reduce warnings --- src/c_str.rs | 4 ---- src/header/arpa_inet/mod.rs | 16 ++++++++-------- src/header/fnmatch/mod.rs | 1 - src/header/setjmp/mod.rs | 3 --- src/header/signal/mod.rs | 2 +- src/header/stdio/mod.rs | 2 +- src/header/stdlib/mod.rs | 2 -- src/header/strings/mod.rs | 4 ++-- src/header/sys_resource/mod.rs | 8 ++++---- src/header/sys_socket/mod.rs | 2 +- src/header/sys_un/mod.rs | 2 -- src/header/sys_wait/mod.rs | 1 + src/header/time/constants.rs | 1 - src/header/time/strftime.rs | 2 +- src/header/unistd/mod.rs | 4 ++-- src/header/wchar/mod.rs | 14 +++++--------- src/header/wchar/utf8.rs | 4 ++-- src/lib.rs | 2 ++ src/platform/linux/mod.rs | 1 - src/platform/pal/mod.rs | 2 +- 20 files changed, 31 insertions(+), 46 deletions(-) diff --git a/src/c_str.rs b/src/c_str.rs index 113015ef46..cb37b89593 100644 --- a/src/c_str.rs +++ b/src/c_str.rs @@ -848,10 +848,6 @@ impl NulError { pub fn into_vec(self) -> Vec { self.1 } - - fn description(&self) -> &str { - "nul byte found in data" - } } impl fmt::Display for NulError { diff --git a/src/header/arpa_inet/mod.rs b/src/header/arpa_inet/mod.rs index b9dc66b834..cca48be4b9 100644 --- a/src/header/arpa_inet/mod.rs +++ b/src/header/arpa_inet/mod.rs @@ -29,8 +29,6 @@ pub extern "C" fn ntohs(netshort: u16) -> u16 { u16::from_be(netshort) } -static mut NTOA_ADDR: [c_char; 16] = [0; 16]; - #[no_mangle] pub unsafe extern "C" fn inet_aton(cp: *const c_char, inp: *mut in_addr) -> c_int { // TODO: octal/hex @@ -39,6 +37,8 @@ pub unsafe extern "C" fn inet_aton(cp: *const c_char, inp: *mut in_addr) -> c_in #[no_mangle] pub unsafe extern "C" fn inet_ntoa(addr: in_addr) -> *const c_char { + static mut NTOA_ADDR: [c_char; 16] = [0; 16]; + inet_ntop( AF_INET, &addr as *const in_addr as *const c_void, @@ -53,7 +53,7 @@ pub unsafe extern "C" fn inet_pton(domain: c_int, src: *const c_char, dest: *mut platform::errno = EAFNOSUPPORT; -1 } else { - let mut s_addr = slice::from_raw_parts_mut( + let s_addr = slice::from_raw_parts_mut( &mut (*(dest as *mut in_addr)).s_addr as *mut _ as *mut u8, 4, ); @@ -97,27 +97,27 @@ pub unsafe extern "C" fn inet_ntop( } } -#[no_mangle] +//#[no_mangle] pub extern "C" fn inet_addr(cp: *const c_char) -> in_addr_t { unimplemented!(); } -#[no_mangle] +//#[no_mangle] pub extern "C" fn inet_lnaof(_in: in_addr) -> in_addr_t { unimplemented!(); } -#[no_mangle] +//#[no_mangle] pub extern "C" fn inet_makeaddr(net: in_addr_t, lna: in_addr_t) -> in_addr { unimplemented!(); } -#[no_mangle] +//#[no_mangle] pub extern "C" fn inet_netof(_in: in_addr) -> in_addr_t { unimplemented!(); } -#[no_mangle] +//#[no_mangle] pub extern "C" fn inet_network(cp: *const c_char) -> in_addr_t { unimplemented!(); } diff --git a/src/header/fnmatch/mod.rs b/src/header/fnmatch/mod.rs index 32819f0a4b..899dbf7b7c 100644 --- a/src/header/fnmatch/mod.rs +++ b/src/header/fnmatch/mod.rs @@ -161,7 +161,6 @@ pub unsafe extern "C" fn fnmatch( return FNM_NOMATCH; } } - unreachable!("nothing should be able to break out of the loop"); } None => return FNM_NOMATCH, // Pattern ended but there's still some input } diff --git a/src/header/setjmp/mod.rs b/src/header/setjmp/mod.rs index 0f6392dc9f..6371c9a58b 100644 --- a/src/header/setjmp/mod.rs +++ b/src/header/setjmp/mod.rs @@ -1,8 +1,5 @@ //! setjmp implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/setjmp.h.html -#![no_std] -#![feature(global_asm)] - macro_rules! platform_specific { ($($arch:expr,$ext:expr;)+) => { $( diff --git a/src/header/signal/mod.rs b/src/header/signal/mod.rs index c9259651d1..2aa9862a10 100644 --- a/src/header/signal/mod.rs +++ b/src/header/signal/mod.rs @@ -74,7 +74,7 @@ pub unsafe extern "C" fn sigaction( } #[no_mangle] -pub extern "C" fn sigaddset(set: *mut sigset_t, mut signo: c_int) -> c_int { +pub extern "C" fn sigaddset(set: *mut sigset_t, signo: c_int) -> c_int { if signo <= 0 || signo as usize > NSIG { unsafe { platform::errno = errno::EINVAL; diff --git a/src/header/stdio/mod.rs b/src/header/stdio/mod.rs index 48f3148835..ca4bdc5156 100644 --- a/src/header/stdio/mod.rs +++ b/src/header/stdio/mod.rs @@ -887,7 +887,7 @@ pub extern "C" fn tempnam(_dir: *const c_char, _pfx: *const c_char) -> *mut c_ch pub extern "C" fn tmpfile() -> *mut FILE { let mut file_name = *b"/tmp/tmpfileXXXXXX"; let file_name = file_name.as_mut_ptr() as *mut c_char; - let fd = unsafe { mkstemp(file_name) }; + let fd = mkstemp(file_name); if fd < 0 { return ptr::null_mut(); diff --git a/src/header/stdlib/mod.rs b/src/header/stdlib/mod.rs index 6de7e36f02..a11a06b4e1 100644 --- a/src/header/stdlib/mod.rs +++ b/src/header/stdlib/mod.rs @@ -432,13 +432,11 @@ where #[no_mangle] pub extern "C" fn mktemp(name: *mut c_char) -> *mut c_char { if inner_mktemp(name, 0, || unsafe { - let mut st: stat = mem::uninitialized(); let ret = if Sys::access(name, 0) != 0 && platform::errno == ENOENT { Some(()) } else { None }; - mem::forget(st); ret }).is_none() { diff --git a/src/header/strings/mod.rs b/src/header/strings/mod.rs index a813932530..77eb9ea0b1 100644 --- a/src/header/strings/mod.rs +++ b/src/header/strings/mod.rs @@ -7,8 +7,8 @@ use platform::types::*; #[no_mangle] pub unsafe extern "C" fn bcmp( - mut first: *const c_void, - mut second: *const c_void, + first: *const c_void, + second: *const c_void, n: size_t, ) -> c_int { let first = first as *const c_char; diff --git a/src/header/sys_resource/mod.rs b/src/header/sys_resource/mod.rs index 6afcc6fe9b..f4b7bc29a2 100644 --- a/src/header/sys_resource/mod.rs +++ b/src/header/sys_resource/mod.rs @@ -7,10 +7,10 @@ use platform::types::*; use platform::{Pal, Sys}; // Exported in bits file -const RUSAGE_SELF: c_int = 0; -const RUSAGE_CHILDREN: c_int = -1; -const RUSAGE_BOTH: c_int = -2; -const RUSAGE_THREAD: c_int = 1; +// const RUSAGE_SELF: c_int = 0; +// const RUSAGE_CHILDREN: c_int = -1; +// const RUSAGE_BOTH: c_int = -2; +// const RUSAGE_THREAD: c_int = 1; type rlim_t = u64; diff --git a/src/header/sys_socket/mod.rs b/src/header/sys_socket/mod.rs index 5a305274ef..877b9cae2c 100644 --- a/src/header/sys_socket/mod.rs +++ b/src/header/sys_socket/mod.rs @@ -6,7 +6,7 @@ use platform; use platform::types::*; use platform::{PalSocket, Sys}; -mod constants; +pub mod constants; pub type in_addr_t = [u8; 4]; pub type in_port_t = u16; diff --git a/src/header/sys_un/mod.rs b/src/header/sys_un/mod.rs index 2c0a2c9422..41f55107be 100644 --- a/src/header/sys_un/mod.rs +++ b/src/header/sys_un/mod.rs @@ -1,5 +1,3 @@ -#![no_std] - use header::sys_socket::sa_family_t; use platform::types::*; diff --git a/src/header/sys_wait/mod.rs b/src/header/sys_wait/mod.rs index 346fe67723..4259c48d1b 100644 --- a/src/header/sys_wait/mod.rs +++ b/src/header/sys_wait/mod.rs @@ -15,6 +15,7 @@ pub const WNOWAIT: c_int = 0x1000000; pub const __WNOTHREAD: c_int = 0x20000000; pub const __WALL: c_int = 0x40000000; +#[allow(overflowing_literals)] pub const __WCLONE: c_int = 0x80000000; #[no_mangle] diff --git a/src/header/time/constants.rs b/src/header/time/constants.rs index 45541d4a28..15810f64c6 100644 --- a/src/header/time/constants.rs +++ b/src/header/time/constants.rs @@ -47,7 +47,6 @@ pub(crate) const MON_NAMES: [&str; 12] = [ pub(crate) const CLOCK_REALTIME: clockid_t = 0; pub const CLOCK_MONOTONIC: clockid_t = 1; pub(crate) const CLOCK_PROCESS_CPUTIME_ID: clockid_t = 2; -pub(crate) const CLOCK_THREAD_CPUTIME_ID: clockid_t = 3; // Can't be time_t because cbindgen UGH pub(crate) const CLOCKS_PER_SEC: c_long = 1_000_000; diff --git a/src/header/time/strftime.rs b/src/header/time/strftime.rs index 7456ce43b6..d2f6f91100 100644 --- a/src/header/time/strftime.rs +++ b/src/header/time/strftime.rs @@ -7,7 +7,7 @@ use super::tm; pub unsafe fn strftime(w: &mut W, format: *const c_char, t: *const tm) -> size_t { pub unsafe fn inner_strftime( - mut w: &mut W, + w: &mut W, mut format: *const c_char, t: *const tm, ) -> bool { diff --git a/src/header/unistd/mod.rs b/src/header/unistd/mod.rs index 817504658a..0f426a730a 100644 --- a/src/header/unistd/mod.rs +++ b/src/header/unistd/mod.rs @@ -195,11 +195,11 @@ pub extern "C" fn getcwd(mut buf: *mut c_char, mut size: size_t) -> *mut c_char } if alloc { - let mut len = stack_buf + let len = stack_buf .iter() .position(|b| *b == 0) .expect("no nul-byte in getcwd string") + 1; - let mut heap_buf = unsafe { platform::alloc(len) as *mut c_char }; + let heap_buf = unsafe { platform::alloc(len) as *mut c_char }; for i in 0..len { unsafe { *heap_buf.offset(i as isize) = stack_buf[i]; diff --git a/src/header/wchar/mod.rs b/src/header/wchar/mod.rs index 9df75f1472..b60232e7d5 100644 --- a/src/header/wchar/mod.rs +++ b/src/header/wchar/mod.rs @@ -4,6 +4,7 @@ use core::ptr; use va_list::VaList as va_list; use header::stdio::*; +use header::stdlib::MB_CUR_MAX; use header::time::*; use platform; use platform::types::*; @@ -12,11 +13,6 @@ mod utf8; const WEOF: wint_t = 0xFFFFFFFFu32; -//Maximum number of bytes in a multibyte character for the current locale -const MB_CUR_MAX: c_int = 4; -//Maximum number of bytes in a multibyte characters for any locale -const MB_LEN_MAX: c_int = 4; - #[repr(C)] #[derive(Clone, Copy)] pub struct mbstate_t; @@ -204,13 +200,13 @@ pub extern "C" fn swprintf( s: *mut wchar_t, n: size_t, format: *const wchar_t, - mut ap: va_list, + ap: va_list, ) -> c_int { unimplemented!(); } // #[no_mangle] -pub extern "C" fn swscanf(s: *const wchar_t, format: *const wchar_t, mut ap: va_list) -> c_int { +pub extern "C" fn swscanf(s: *const wchar_t, format: *const wchar_t, ap: va_list) -> c_int { unimplemented!(); } @@ -429,11 +425,11 @@ pub extern "C" fn wmemset(ws1: *mut wchar_t, ws2: wchar_t, n: size_t) -> *mut wc } // #[no_mangle] -pub extern "C" fn wprintf(format: *const wchar_t, mut ap: va_list) -> c_int { +pub extern "C" fn wprintf(format: *const wchar_t, ap: va_list) -> c_int { unimplemented!(); } // #[no_mangle] -pub extern "C" fn wscanf(format: *const wchar_t, mut ap: va_list) -> c_int { +pub extern "C" fn wscanf(format: *const wchar_t, ap: va_list) -> c_int { unimplemented!(); } diff --git a/src/header/wchar/utf8.rs b/src/header/wchar/utf8.rs index 1f8e72f03b..fded8d1d86 100644 --- a/src/header/wchar/utf8.rs +++ b/src/header/wchar/utf8.rs @@ -11,7 +11,7 @@ use super::mbstate_t; //It's guaranteed that we don't have any nullpointers here pub unsafe fn mbrtowc(pwc: *mut wchar_t, s: *const c_char, n: usize, ps: *mut mbstate_t) -> usize { - let mut size = str::utf8_char_width(*s as u8); + let size = str::utf8_char_width(*s as u8); if size > n { platform::errno = errno::EILSEQ; return -2isize as usize; @@ -50,7 +50,7 @@ pub unsafe fn wcrtomb(s: *mut c_char, wc: wchar_t, ps: *mut mbstate_t) -> usize let c = dc.unwrap(); let size = c.len_utf8(); - let mut slice = slice::from_raw_parts_mut(s as *mut u8, size); + let slice = slice::from_raw_parts_mut(s as *mut u8, size); c.encode_utf8(slice); diff --git a/src/lib.rs b/src/lib.rs index bc557b0973..90f2507fcd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,7 @@ #![no_std] #![allow(non_camel_case_types)] +#![allow(non_upper_case_globals)] +#![allow(unused_variables)] #![feature(alloc)] #![feature(allocator_api)] #![feature(const_fn)] diff --git a/src/platform/linux/mod.rs b/src/platform/linux/mod.rs index 5ef98c4626..80061b698e 100644 --- a/src/platform/linux/mod.rs +++ b/src/platform/linux/mod.rs @@ -19,7 +19,6 @@ const TIOCGWINSZ: c_ulong = 0x5413; const AT_FDCWD: c_int = -100; const AT_EMPTY_PATH: c_int = 0x1000; const AT_REMOVEDIR: c_int = 0x200; -const AT_SYMLINK_NOFOLLOW: c_int = 0x100; fn e(sys: usize) -> usize { if (sys as isize) < 0 && (sys as isize) >= -256 { diff --git a/src/platform/pal/mod.rs b/src/platform/pal/mod.rs index 4d15c3b26b..b1da6f24d6 100644 --- a/src/platform/pal/mod.rs +++ b/src/platform/pal/mod.rs @@ -124,7 +124,7 @@ pub trait Pal { Self::no_pal("getrusage") } - unsafe fn gethostname(mut name: *mut c_char, len: size_t) -> c_int { + unsafe fn gethostname(name: *mut c_char, len: size_t) -> c_int { Self::no_pal("gethostname") } From 16373257b083d7be4383dac820d3f7df166d26fe Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Mon, 27 Aug 2018 07:12:37 -0600 Subject: [PATCH 16/19] format --- src/header/strings/mod.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/header/strings/mod.rs b/src/header/strings/mod.rs index 77eb9ea0b1..d755295d76 100644 --- a/src/header/strings/mod.rs +++ b/src/header/strings/mod.rs @@ -6,11 +6,7 @@ use core::ptr; use platform::types::*; #[no_mangle] -pub unsafe extern "C" fn bcmp( - first: *const c_void, - second: *const c_void, - n: size_t, -) -> c_int { +pub unsafe extern "C" fn bcmp(first: *const c_void, second: *const c_void, n: size_t) -> c_int { let first = first as *const c_char; let second = second as *const c_char; From c911facca6147bde9dba1b452eff89d00279eba4 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Mon, 27 Aug 2018 08:33:12 -0600 Subject: [PATCH 17/19] Make pal functions take cstr --- build.rs | 1 + src/header/dirent/mod.rs | 2 ++ src/header/fcntl/mod.rs | 2 ++ src/header/pwd/mod.rs | 3 ++- src/header/stdio/mod.rs | 9 ++++++- src/header/stdlib/mod.rs | 5 +++- src/header/sys_stat/mod.rs | 13 +++++----- src/header/sys_time/mod.rs | 2 ++ src/header/unistd/mod.rs | 9 +++++++ src/header/utime/mod.rs | 2 ++ src/platform/linux/mod.rs | 53 +++++++++++++++++++------------------- src/platform/pal/mod.rs | 27 +++++++++---------- src/platform/rawfile.rs | 3 ++- src/platform/redox/mod.rs | 30 ++++++++++----------- 14 files changed, 96 insertions(+), 65 deletions(-) diff --git a/build.rs b/build.rs index 8f61a6d4b2..4ee52afdf9 100644 --- a/build.rs +++ b/build.rs @@ -11,6 +11,7 @@ fn main() { .flag("-I") .flag(&format!("{}/include", crate_dir)) .flag("-fno-stack-protector") + .flag("-Wno-expansion-to-defined") .file("src/c/dlmalloc.c") .file("src/c/fcntl.c") .file("src/c/stack_chk.c") diff --git a/src/header/dirent/mod.rs b/src/header/dirent/mod.rs index 09ba4a7f9e..478e902461 100644 --- a/src/header/dirent/mod.rs +++ b/src/header/dirent/mod.rs @@ -3,6 +3,7 @@ use alloc::boxed::Box; use core::{mem, ptr}; +use c_str::CStr; use header::{errno, fcntl, unistd}; use platform; use platform::types::*; @@ -35,6 +36,7 @@ pub struct dirent { #[no_mangle] pub extern "C" fn opendir(path: *const c_char) -> *mut DIR { + let path = unsafe { CStr::from_ptr(path) }; let fd = Sys::open( path, fcntl::O_RDONLY | fcntl::O_DIRECTORY | fcntl::O_CLOEXEC, diff --git a/src/header/fcntl/mod.rs b/src/header/fcntl/mod.rs index a22d0eb528..07a88647c5 100644 --- a/src/header/fcntl/mod.rs +++ b/src/header/fcntl/mod.rs @@ -1,5 +1,6 @@ //! fcntl implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/fcntl.h.html +use c_str::CStr; use platform::types::*; use platform::{Pal, Sys}; @@ -40,5 +41,6 @@ pub extern "C" fn sys_fcntl(fildes: c_int, cmd: c_int, arg: c_int) -> c_int { #[no_mangle] pub extern "C" fn sys_open(path: *const c_char, oflag: c_int, mode: mode_t) -> c_int { + let path = unsafe { CStr::from_ptr(path) }; Sys::open(path, oflag, mode) } diff --git a/src/header/pwd/mod.rs b/src/header/pwd/mod.rs index 139acc389a..d719cecbae 100644 --- a/src/header/pwd/mod.rs +++ b/src/header/pwd/mod.rs @@ -3,6 +3,7 @@ use alloc::vec::Vec; use core::ptr; +use c_str::CStr; use header::{errno, fcntl}; use platform; use platform::types::*; @@ -47,7 +48,7 @@ where F: FnMut(&[&[u8]]) -> bool, { let file = match RawFile::open( - "/etc/passwd\0".as_ptr() as *const c_char, + CStr::from_bytes_with_nul(b"/etc/passwd\0").unwrap(), fcntl::O_RDONLY, 0, ) { diff --git a/src/header/stdio/mod.rs b/src/header/stdio/mod.rs index ca4bdc5156..e4e0e8d9ef 100644 --- a/src/header/stdio/mod.rs +++ b/src/header/stdio/mod.rs @@ -7,6 +7,7 @@ use core::sync::atomic::{AtomicBool, Ordering}; use core::{ptr, str}; use va_list::VaList as va_list; +use c_str::CStr; use header::errno::{self, STR_ERROR}; use header::fcntl; use header::stdlib::mkstemp; @@ -814,6 +815,7 @@ pub extern "C" fn putw(w: c_int, stream: &mut FILE) -> c_int { /// Delete file or directory `path` #[no_mangle] pub extern "C" fn remove(path: *const c_char) -> c_int { + let path = unsafe { CStr::from_ptr(path) }; let r = Sys::unlink(path); if r == -errno::EISDIR { Sys::rmdir(path) @@ -824,6 +826,8 @@ pub extern "C" fn remove(path: *const c_char) -> c_int { #[no_mangle] pub extern "C" fn rename(oldpath: *const c_char, newpath: *const c_char) -> c_int { + let oldpath = unsafe { CStr::from_ptr(oldpath) }; + let newpath = unsafe { CStr::from_ptr(newpath) }; Sys::rename(oldpath, newpath) } @@ -894,7 +898,10 @@ pub extern "C" fn tmpfile() -> *mut FILE { } let fp = fdopen(fd, b"w+".as_ptr() as *const i8); - Sys::unlink(file_name); + { + let file_name = unsafe { CStr::from_ptr(file_name) }; + Sys::unlink(file_name); + } if fp == ptr::null_mut() { Sys::close(fd); diff --git a/src/header/stdlib/mod.rs b/src/header/stdlib/mod.rs index a11a06b4e1..9116eb7a4a 100644 --- a/src/header/stdlib/mod.rs +++ b/src/header/stdlib/mod.rs @@ -6,6 +6,7 @@ use rand::prng::XorShiftRng; use rand::rngs::JitterRng; use rand::{Rng, SeedableRng}; +use c_str::CStr; use header::errno::*; use header::fcntl::*; use header::string::*; @@ -390,7 +391,7 @@ fn inner_mktemp(name: *mut c_char, suffix_len: c_int, mut attempt: F) -> O where F: FnMut() -> Option, { - let len = unsafe { strlen(name) } as c_int; + let len = unsafe { strlen(name) as c_int }; if len < 6 || suffix_len > len - 6 { unsafe { platform::errno = errno::EINVAL }; @@ -432,6 +433,7 @@ where #[no_mangle] pub extern "C" fn mktemp(name: *mut c_char) -> *mut c_char { if inner_mktemp(name, 0, || unsafe { + let name = unsafe { CStr::from_ptr(name) }; let ret = if Sys::access(name, 0) != 0 && platform::errno == ENOENT { Some(()) } else { @@ -459,6 +461,7 @@ pub extern "C" fn mkostemps(name: *mut c_char, suffix_len: c_int, mut flags: c_i flags |= O_RDWR | O_CREAT | O_EXCL; inner_mktemp(name, suffix_len, || { + let name = unsafe { CStr::from_ptr(name) }; let fd = Sys::open(name, flags, 0600); if fd >= 0 { diff --git a/src/header/sys_stat/mod.rs b/src/header/sys_stat/mod.rs index 8490a3126d..1bd6c005d1 100644 --- a/src/header/sys_stat/mod.rs +++ b/src/header/sys_stat/mod.rs @@ -1,5 +1,6 @@ //! stat implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/sysstat.h.html +use c_str::CStr; use header::fcntl::{O_NOFOLLOW, O_PATH}; use platform; use platform::types::*; @@ -58,6 +59,7 @@ pub struct stat { #[no_mangle] pub extern "C" fn chmod(path: *const c_char, mode: mode_t) -> c_int { + let path = unsafe { CStr::from_ptr(path) }; Sys::chmod(path, mode) } @@ -83,6 +85,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 { + let path = unsafe { CStr::from_ptr(path) }; let fd = Sys::open(path, O_PATH | O_NOFOLLOW, 0); if fd < 0 { return -1; @@ -97,11 +100,13 @@ pub extern "C" fn lstat(path: *const c_char, buf: *mut platform::types::stat) -> #[no_mangle] pub extern "C" fn mkdir(path: *const c_char, mode: mode_t) -> c_int { + let path = unsafe { CStr::from_ptr(path) }; Sys::mkdir(path, mode) } #[no_mangle] pub extern "C" fn mkfifo(path: *const c_char, mode: mode_t) -> c_int { + let path = unsafe { CStr::from_ptr(path) }; Sys::mkfifo(path, mode) } @@ -112,6 +117,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 { + let file = unsafe { CStr::from_ptr(file) }; let fd = Sys::open(file, O_PATH, 0); if fd < 0 { return -1; @@ -128,10 +134,3 @@ pub extern "C" fn stat(file: *const c_char, buf: *mut platform::types::stat) -> pub extern "C" fn umask(mask: mode_t) -> mode_t { Sys::umask(mask) } - -/* -#[no_mangle] -pub extern "C" fn func(args) -> c_int { - unimplemented!(); -} -*/ diff --git a/src/header/sys_time/mod.rs b/src/header/sys_time/mod.rs index 13c67d9d45..dc50a4ce80 100644 --- a/src/header/sys_time/mod.rs +++ b/src/header/sys_time/mod.rs @@ -1,5 +1,6 @@ //! 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}; @@ -71,6 +72,7 @@ pub extern "C" fn select( #[no_mangle] pub unsafe extern "C" fn utimes(path: *const c_char, times: *const timeval) -> c_int { + let path = CStr::from_ptr(path); let times_spec = [ timespec { tv_sec: (*times.offset(0)).tv_sec, diff --git a/src/header/unistd/mod.rs b/src/header/unistd/mod.rs index 0f426a730a..5a7e8b1cd3 100644 --- a/src/header/unistd/mod.rs +++ b/src/header/unistd/mod.rs @@ -2,6 +2,7 @@ use core::{ptr, slice}; +use c_str::CStr; use header::sys_time; use platform; use platform::types::*; @@ -42,6 +43,7 @@ pub extern "C" fn _exit(status: c_int) { #[no_mangle] pub extern "C" fn access(path: *const c_char, mode: c_int) -> c_int { + let path = unsafe { CStr::from_ptr(path) }; Sys::access(path, mode) } @@ -69,6 +71,7 @@ pub extern "C" fn alarm(seconds: c_uint) -> c_uint { #[no_mangle] pub extern "C" fn chdir(path: *const c_char) -> c_int { + let path = unsafe { CStr::from_ptr(path) }; Sys::chdir(path) } @@ -79,6 +82,7 @@ pub extern "C" fn chroot(path: *const c_char) -> c_int { #[no_mangle] pub extern "C" fn chown(path: *const c_char, owner: uid_t, group: gid_t) -> c_int { + let path = unsafe { CStr::from_ptr(path) }; Sys::chown(path, owner, group) } @@ -142,6 +146,7 @@ pub unsafe extern "C" fn execve( argv: *const *mut c_char, envp: *const *mut c_char, ) -> c_int { + let path = unsafe { CStr::from_ptr(path) }; Sys::execve(path, argv, envp) } @@ -313,6 +318,8 @@ pub extern "C" fn lchown(path: *const c_char, owner: uid_t, group: gid_t) -> c_i #[no_mangle] pub extern "C" fn link(path1: *const c_char, path2: *const c_char) -> c_int { + let path1 = unsafe { CStr::from_ptr(path1) }; + let path2 = unsafe { CStr::from_ptr(path2) }; Sys::link(path1, path2) } @@ -379,6 +386,7 @@ pub extern "C" fn readlink(path: *const c_char, buf: *mut c_char, bufsize: size_ #[no_mangle] pub extern "C" fn rmdir(path: *const c_char) -> c_int { + let path = unsafe { CStr::from_ptr(path) }; Sys::rmdir(path) } @@ -500,6 +508,7 @@ pub extern "C" fn ualarm(value: useconds_t, interval: useconds_t) -> useconds_t #[no_mangle] pub extern "C" fn unlink(path: *const c_char) -> c_int { + let path = unsafe { CStr::from_ptr(path) }; Sys::unlink(path) } diff --git a/src/header/utime/mod.rs b/src/header/utime/mod.rs index dd891aa6ee..8007744a32 100644 --- a/src/header/utime/mod.rs +++ b/src/header/utime/mod.rs @@ -1,5 +1,6 @@ //! utime implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/utime.h.html +use c_str::CStr; use platform::types::*; use platform::{Pal, Sys}; @@ -12,6 +13,7 @@ pub struct utimbuf { #[no_mangle] pub unsafe extern "C" fn utime(filename: *const c_char, times: *const utimbuf) -> c_int { + let filename = CStr::from_ptr(filename); let times_spec = [ timespec { tv_sec: (*times).actime, diff --git a/src/platform/linux/mod.rs b/src/platform/linux/mod.rs index 80061b698e..1f9884aaa0 100644 --- a/src/platform/linux/mod.rs +++ b/src/platform/linux/mod.rs @@ -1,6 +1,7 @@ use core::fmt::Write; use core::{mem, ptr}; +use c_str::CStr; use super::types::*; use super::{errno, FileWriter, Pal}; @@ -42,24 +43,24 @@ impl Pal for Sys { -1 } - fn access(path: *const c_char, mode: c_int) -> c_int { - e(unsafe { syscall!(ACCESS, path, mode) }) as c_int + fn access(path: &CStr, mode: c_int) -> c_int { + e(unsafe { syscall!(ACCESS, path.as_ptr(), mode) }) as c_int } fn brk(addr: *mut c_void) -> *mut c_void { unsafe { syscall!(BRK, addr) as *mut c_void } } - fn chdir(path: *const c_char) -> c_int { - e(unsafe { syscall!(CHDIR, path) }) as c_int + fn chdir(path: &CStr) -> c_int { + e(unsafe { syscall!(CHDIR, path.as_ptr()) }) as c_int } - fn chmod(path: *const c_char, mode: mode_t) -> c_int { - e(unsafe { syscall!(FCHMODAT, AT_FDCWD, path, mode, 0) }) as c_int + fn chmod(path: &CStr, mode: mode_t) -> c_int { + e(unsafe { syscall!(FCHMODAT, AT_FDCWD, path.as_ptr(), mode, 0) }) as c_int } - fn chown(path: *const c_char, owner: uid_t, group: gid_t) -> c_int { - e(unsafe { syscall!(FCHOWNAT, AT_FDCWD, path, owner as u32, group as u32) }) as c_int + fn chown(path: &CStr, owner: uid_t, group: gid_t) -> c_int { + e(unsafe { syscall!(FCHOWNAT, AT_FDCWD, path.as_ptr(), owner as u32, group as u32) }) as c_int } fn clock_gettime(clk_id: clockid_t, tp: *mut timespec) -> c_int { @@ -79,11 +80,11 @@ impl Pal for Sys { } unsafe fn execve( - path: *const c_char, + path: &CStr, argv: *const *mut c_char, envp: *const *mut c_char, ) -> c_int { - e(syscall!(EXECVE, path, argv, envp)) as c_int + e(syscall!(EXECVE, path.as_ptr(), argv, envp)) as c_int } fn exit(status: c_int) -> ! { @@ -134,8 +135,8 @@ impl Pal for Sys { e(unsafe { syscall!(UTIMENSAT, fd, ptr::null::(), times, 0) }) as c_int } - fn utimens(path: *const c_char, times: *const timespec) -> c_int { - e(unsafe { syscall!(UTIMENSAT, AT_FDCWD, path, times, 0) }) as c_int + fn utimens(path: &CStr, times: *const timespec) -> c_int { + e(unsafe { syscall!(UTIMENSAT, AT_FDCWD, path.as_ptr(), times, 0) }) as c_int } fn getcwd(buf: *mut c_char, size: size_t) -> *mut c_char { @@ -228,20 +229,20 @@ impl Pal for Sys { (Self::ioctl(fd, TIOCGWINSZ, &mut winsize as *mut _ as *mut c_void) == 0) as c_int } - fn link(path1: *const c_char, path2: *const c_char) -> c_int { - e(unsafe { syscall!(LINKAT, AT_FDCWD, path1, AT_FDCWD, path2, 0) }) as c_int + fn link(path1: &CStr, path2: &CStr) -> c_int { + e(unsafe { syscall!(LINKAT, AT_FDCWD, path1.as_ptr(), AT_FDCWD, path2.as_ptr(), 0) }) as c_int } fn lseek(fildes: c_int, offset: off_t, whence: c_int) -> off_t { e(unsafe { syscall!(LSEEK, fildes, offset, whence) }) as off_t } - fn mkdir(path: *const c_char, mode: mode_t) -> c_int { - e(unsafe { syscall!(MKDIRAT, AT_FDCWD, path, mode) }) as c_int + fn mkdir(path: &CStr, mode: mode_t) -> c_int { + e(unsafe { syscall!(MKDIRAT, AT_FDCWD, path.as_ptr(), mode) }) as c_int } - fn mkfifo(path: *const c_char, mode: mode_t) -> c_int { - e(unsafe { syscall!(MKNODAT, AT_FDCWD, path, mode, 0) }) as c_int + fn mkfifo(path: &CStr, mode: mode_t) -> c_int { + e(unsafe { syscall!(MKNODAT, AT_FDCWD, path.as_ptr(), mode, 0) }) as c_int } unsafe fn mmap( @@ -263,8 +264,8 @@ impl Pal for Sys { e(unsafe { syscall!(NANOSLEEP, rqtp, rmtp) }) as c_int } - fn open(path: *const c_char, oflag: c_int, mode: mode_t) -> c_int { - e(unsafe { syscall!(OPENAT, AT_FDCWD, path, oflag, mode) }) as c_int + fn open(path: &CStr, oflag: c_int, mode: mode_t) -> c_int { + e(unsafe { syscall!(OPENAT, AT_FDCWD, path.as_ptr(), oflag, mode) }) as c_int } fn pipe(fildes: &mut [c_int]) -> c_int { @@ -275,12 +276,12 @@ impl Pal for Sys { e(unsafe { syscall!(READ, fildes, buf.as_mut_ptr(), buf.len()) }) as ssize_t } - fn rename(old: *const c_char, new: *const c_char) -> c_int { - e(unsafe { syscall!(RENAMEAT, AT_FDCWD, old, AT_FDCWD, new) }) as c_int + fn rename(old: &CStr, new: &CStr) -> c_int { + e(unsafe { syscall!(RENAMEAT, AT_FDCWD, old.as_ptr(), AT_FDCWD, new.as_ptr()) }) as c_int } - fn rmdir(path: *const c_char) -> c_int { - e(unsafe { syscall!(UNLINKAT, AT_FDCWD, path, AT_REMOVEDIR) }) as c_int + fn rmdir(path: &CStr) -> c_int { + e(unsafe { syscall!(UNLINKAT, AT_FDCWD, path.as_ptr(), AT_REMOVEDIR) }) as c_int } fn select( @@ -336,8 +337,8 @@ impl Pal for Sys { e(unsafe { syscall!(UNAME, utsname, 0) }) as c_int } - fn unlink(path: *const c_char) -> c_int { - e(unsafe { syscall!(UNLINKAT, AT_FDCWD, path, 0) }) as c_int + fn unlink(path: &CStr) -> c_int { + e(unsafe { syscall!(UNLINKAT, AT_FDCWD, path.as_ptr(), 0) }) as c_int } fn waitpid(pid: pid_t, stat_loc: *mut c_int, options: c_int) -> pid_t { diff --git a/src/platform/pal/mod.rs b/src/platform/pal/mod.rs index b1da6f24d6..3a1dec48a9 100644 --- a/src/platform/pal/mod.rs +++ b/src/platform/pal/mod.rs @@ -1,5 +1,6 @@ use core::ptr; +use c_str::CStr; use super::types::*; pub use self::signal::PalSignal; @@ -11,21 +12,21 @@ mod socket; pub trait Pal { fn no_pal(name: &str) -> c_int; - fn access(path: *const c_char, mode: c_int) -> c_int { + fn access(path: &CStr, mode: c_int) -> c_int { Self::no_pal("access") } fn brk(addr: *mut c_void) -> *mut c_void; - fn chdir(path: *const c_char) -> c_int { + fn chdir(path: &CStr) -> c_int { Self::no_pal("chdir") } - fn chmod(path: *const c_char, mode: mode_t) -> c_int { + fn chmod(path: &CStr, mode: mode_t) -> c_int { Self::no_pal("chmod") } - fn chown(path: *const c_char, owner: uid_t, group: gid_t) -> c_int { + fn chown(path: &CStr, owner: uid_t, group: gid_t) -> c_int { Self::no_pal("chown") } @@ -46,7 +47,7 @@ pub trait Pal { } unsafe fn execve( - path: *const c_char, + path: &CStr, argv: *const *mut c_char, envp: *const *mut c_char, ) -> c_int { @@ -95,7 +96,7 @@ pub trait Pal { Self::no_pal("futimens") } - fn utimens(path: *const c_char, times: *const timespec) -> c_int { + fn utimens(path: &CStr, times: *const timespec) -> c_int { Self::no_pal("utimens") } @@ -160,7 +161,7 @@ pub trait Pal { Self::no_pal("isatty") } - fn link(path1: *const c_char, path2: *const c_char) -> c_int { + fn link(path1: &CStr, path2: &CStr) -> c_int { Self::no_pal("link") } @@ -168,11 +169,11 @@ pub trait Pal { Self::no_pal("lseek") as off_t } - fn mkdir(path: *const c_char, mode: mode_t) -> c_int { + fn mkdir(path: &CStr, mode: mode_t) -> c_int { Self::no_pal("mkdir") } - fn mkfifo(path: *const c_char, mode: mode_t) -> c_int { + fn mkfifo(path: &CStr, mode: mode_t) -> c_int { Self::no_pal("mkfifo") } @@ -195,7 +196,7 @@ pub trait Pal { Self::no_pal("nanosleep") } - fn open(path: *const c_char, oflag: c_int, mode: mode_t) -> c_int { + fn open(path: &CStr, oflag: c_int, mode: mode_t) -> c_int { Self::no_pal("open") } @@ -207,11 +208,11 @@ pub trait Pal { Self::no_pal("read") as ssize_t } - fn rename(old: *const c_char, new: *const c_char) -> c_int { + fn rename(old: &CStr, new: &CStr) -> c_int { Self::no_pal("rename") } - fn rmdir(path: *const c_char) -> c_int { + fn rmdir(path: &CStr) -> c_int { Self::no_pal("rmdir") } @@ -262,7 +263,7 @@ pub trait Pal { Self::no_pal("uname") } - fn unlink(path: *const c_char) -> c_int { + fn unlink(path: &CStr) -> c_int { Self::no_pal("unlink") } diff --git a/src/platform/rawfile.rs b/src/platform/rawfile.rs index 4686ce8d04..e111338aa5 100644 --- a/src/platform/rawfile.rs +++ b/src/platform/rawfile.rs @@ -1,11 +1,12 @@ use core::ops::Deref; +use c_str::CStr; use super::{types::*, Pal, Sys}; pub struct RawFile(c_int); impl RawFile { - pub fn open(path: *const c_char, oflag: c_int, mode: mode_t) -> Result { + pub fn open(path: &CStr, oflag: c_int, mode: mode_t) -> Result { match Sys::open(path, oflag, mode) { -1 => Err(()), n => Ok(RawFile(n)), diff --git a/src/platform/redox/mod.rs b/src/platform/redox/mod.rs index 02bb24e1e4..8fabf0617a 100644 --- a/src/platform/redox/mod.rs +++ b/src/platform/redox/mod.rs @@ -50,7 +50,7 @@ impl Pal for Sys { -1 } - fn access(path: *const c_char, mode: c_int) -> c_int { + fn access(path: &CStr, mode: c_int) -> c_int { let fd = match RawFile::open(path, 0, 0) { Ok(fd) => fd, Err(_) => return -1, @@ -100,12 +100,12 @@ impl Pal for Sys { unsafe { syscall::brk(addr as usize).unwrap_or(0) as *mut c_void } } - fn chdir(path: *const c_char) -> c_int { + fn chdir(path: &CStr) -> c_int { let path = unsafe { c_str(path) }; e(syscall::chdir(path)) as c_int } - fn chmod(path: *const c_char, mode: mode_t) -> c_int { + fn chmod(path: &CStr, mode: mode_t) -> c_int { let path = unsafe { c_str(path) }; match syscall::open(path, O_WRONLY) { Err(err) => e(Err(err)) as c_int, @@ -117,7 +117,7 @@ impl Pal for Sys { } } - fn chown(path: *const c_char, owner: uid_t, group: gid_t) -> c_int { + fn chown(path: &CStr, owner: uid_t, group: gid_t) -> c_int { let path = unsafe { c_str(path) }; match syscall::open(path, O_WRONLY) { Err(err) => e(Err(err)) as c_int, @@ -161,7 +161,7 @@ impl Pal for Sys { } unsafe fn execve( - path: *const c_char, + path: &CStr, mut argv: *const *mut c_char, mut envp: *const *mut c_char, ) -> c_int { @@ -290,7 +290,7 @@ impl Pal for Sys { e(syscall::futimens(fd as usize, ×)) as c_int } - fn utimens(path: *const c_char, times: *const timespec) -> c_int { + fn utimens(path: &CStr, times: *const timespec) -> c_int { let path = unsafe { c_str(path) }; match syscall::open(path, O_STAT) { Err(err) => e(Err(err)) as c_int, @@ -443,7 +443,7 @@ impl Pal for Sys { .unwrap_or(0) } - fn link(path1: *const c_char, path2: *const c_char) -> c_int { + fn link(path1: &CStr, path2: &CStr) -> c_int { let path1 = unsafe { c_str(path1) }; let path2 = unsafe { c_str(path2) }; e(unsafe { syscall::link(path1.as_ptr(), path2.as_ptr()) }) as c_int @@ -457,7 +457,7 @@ impl Pal for Sys { )) as off_t } - fn mkdir(path: *const c_char, mode: mode_t) -> c_int { + fn mkdir(path: &CStr, mode: mode_t) -> c_int { let flags = O_CREAT | O_EXCL | O_CLOEXEC | O_DIRECTORY | mode as usize & 0o777; let path = unsafe { c_str(path) }; match syscall::open(path, flags) { @@ -469,7 +469,7 @@ impl Pal for Sys { } } - fn mkfifo(path: *const c_char, mode: mode_t) -> c_int { + fn mkfifo(path: &CStr, mode: mode_t) -> c_int { let flags = O_CREAT | MODE_FIFO as usize | mode as usize & 0o777; let path = unsafe { c_str(path) }; match syscall::open(path, flags) { @@ -540,7 +540,7 @@ impl Pal for Sys { } } - fn open(path: *const c_char, oflag: c_int, mode: mode_t) -> c_int { + fn open(path: &CStr, oflag: c_int, mode: mode_t) -> c_int { let path = unsafe { c_str(path) }; e(syscall::open(path, (oflag as usize) | (mode as usize))) as c_int } @@ -557,7 +557,7 @@ impl Pal for Sys { e(syscall::read(fd as usize, buf)) as ssize_t } - fn rename(oldpath: *const c_char, newpath: *const c_char) -> c_int { + fn rename(oldpath: &CStr, newpath: &CStr) -> c_int { let (oldpath, newpath) = unsafe { (c_str(oldpath), c_str(newpath)) }; match syscall::open(oldpath, O_WRONLY) { Ok(fd) => { @@ -569,7 +569,7 @@ impl Pal for Sys { } } - fn rmdir(path: *const c_char) -> c_int { + fn rmdir(path: &CStr) -> c_int { let path = unsafe { c_str(path) }; e(syscall::rmdir(path)) as c_int } @@ -590,7 +590,7 @@ impl Pal for Sys { unsafe { (*set).fds_bits[fd / (8 * mem::size_of::())] & mask == mask } } - let event_file = match RawFile::open("event:\0".as_ptr() as *const c_char, 0, 0) { + let event_file = match RawFile::open("event:\0".as_ptr() as &CStr, 0, 0) { Ok(file) => file, Err(_) => return -1, }; @@ -632,7 +632,7 @@ impl Pal for Sys { None } else { let timeout_file = match RawFile::open( - format!("time:{}\0", syscall::CLOCK_MONOTONIC).as_ptr() as *const c_char, + format!("time:{}\0", syscall::CLOCK_MONOTONIC).as_ptr() as &CStr, 0, 0, ) { @@ -725,7 +725,7 @@ impl Pal for Sys { 0 } - fn unlink(path: *const c_char) -> c_int { + fn unlink(path: &CStr) -> c_int { let path = unsafe { c_str(path) }; e(syscall::unlink(path)) as c_int } From b52c8221503c3cf74e439942903854f4b55a2bdc Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Mon, 27 Aug 2018 08:44:42 -0600 Subject: [PATCH 18/19] Update Redox module to use CStr --- src/header/pwd/mod.rs | 2 +- src/platform/linux/mod.rs | 29 ++++++++++++++++------ src/platform/pal/mod.rs | 8 ++---- src/platform/rawfile.rs | 2 +- src/platform/redox/mod.rs | 52 +++++++++++++++++++-------------------- 5 files changed, 50 insertions(+), 43 deletions(-) diff --git a/src/header/pwd/mod.rs b/src/header/pwd/mod.rs index d719cecbae..97b912af91 100644 --- a/src/header/pwd/mod.rs +++ b/src/header/pwd/mod.rs @@ -48,7 +48,7 @@ where F: FnMut(&[&[u8]]) -> bool, { let file = match RawFile::open( - CStr::from_bytes_with_nul(b"/etc/passwd\0").unwrap(), + unsafe { CStr::from_bytes_with_nul_unchecked(b"/etc/passwd\0") }, fcntl::O_RDONLY, 0, ) { diff --git a/src/platform/linux/mod.rs b/src/platform/linux/mod.rs index 1f9884aaa0..7bd671f821 100644 --- a/src/platform/linux/mod.rs +++ b/src/platform/linux/mod.rs @@ -1,9 +1,9 @@ use core::fmt::Write; use core::{mem, ptr}; -use c_str::CStr; use super::types::*; use super::{errno, FileWriter, Pal}; +use c_str::CStr; mod signal; mod socket; @@ -60,7 +60,15 @@ impl Pal for Sys { } fn chown(path: &CStr, owner: uid_t, group: gid_t) -> c_int { - e(unsafe { syscall!(FCHOWNAT, AT_FDCWD, path.as_ptr(), owner as u32, group as u32) }) as c_int + e(unsafe { + syscall!( + FCHOWNAT, + AT_FDCWD, + path.as_ptr(), + owner as u32, + group as u32 + ) + }) as c_int } fn clock_gettime(clk_id: clockid_t, tp: *mut timespec) -> c_int { @@ -79,11 +87,7 @@ impl Pal for Sys { e(unsafe { syscall!(DUP3, fildes, fildes2, 0) }) as c_int } - unsafe fn execve( - path: &CStr, - argv: *const *mut c_char, - envp: *const *mut c_char, - ) -> c_int { + unsafe fn execve(path: &CStr, argv: *const *mut c_char, envp: *const *mut c_char) -> c_int { e(syscall!(EXECVE, path.as_ptr(), argv, envp)) as c_int } @@ -230,7 +234,16 @@ impl Pal for Sys { } fn link(path1: &CStr, path2: &CStr) -> c_int { - e(unsafe { syscall!(LINKAT, AT_FDCWD, path1.as_ptr(), AT_FDCWD, path2.as_ptr(), 0) }) as c_int + e(unsafe { + syscall!( + LINKAT, + AT_FDCWD, + path1.as_ptr(), + AT_FDCWD, + path2.as_ptr(), + 0 + ) + }) as c_int } fn lseek(fildes: c_int, offset: off_t, whence: c_int) -> off_t { diff --git a/src/platform/pal/mod.rs b/src/platform/pal/mod.rs index 3a1dec48a9..08981a5676 100644 --- a/src/platform/pal/mod.rs +++ b/src/platform/pal/mod.rs @@ -1,7 +1,7 @@ use core::ptr; -use c_str::CStr; use super::types::*; +use c_str::CStr; pub use self::signal::PalSignal; mod signal; @@ -46,11 +46,7 @@ pub trait Pal { Self::no_pal("dup2") } - unsafe fn execve( - path: &CStr, - argv: *const *mut c_char, - envp: *const *mut c_char, - ) -> c_int { + unsafe fn execve(path: &CStr, argv: *const *mut c_char, envp: *const *mut c_char) -> c_int { Self::no_pal("execve") } diff --git a/src/platform/rawfile.rs b/src/platform/rawfile.rs index e111338aa5..1984217594 100644 --- a/src/platform/rawfile.rs +++ b/src/platform/rawfile.rs @@ -1,7 +1,7 @@ use core::ops::Deref; -use c_str::CStr; use super::{types::*, Pal, Sys}; +use c_str::CStr; pub struct RawFile(c_int); diff --git a/src/platform/redox/mod.rs b/src/platform/redox/mod.rs index 8fabf0617a..d156392318 100644 --- a/src/platform/redox/mod.rs +++ b/src/platform/redox/mod.rs @@ -10,7 +10,8 @@ use syscall::flag::*; use syscall::{self, Result}; use super::types::*; -use super::{c_str, errno, FileReader, FileWriter, Pal, RawFile, Read}; +use super::{errno, FileReader, FileWriter, Pal, RawFile, Read}; +use c_str::{CStr, CString}; mod signal; mod socket; @@ -101,13 +102,11 @@ impl Pal for Sys { } fn chdir(path: &CStr) -> c_int { - let path = unsafe { c_str(path) }; - e(syscall::chdir(path)) as c_int + e(syscall::chdir(path.to_bytes())) as c_int } fn chmod(path: &CStr, mode: mode_t) -> c_int { - let path = unsafe { c_str(path) }; - match syscall::open(path, O_WRONLY) { + match syscall::open(path.to_bytes(), O_WRONLY) { Err(err) => e(Err(err)) as c_int, Ok(fd) => { let res = syscall::fchmod(fd as usize, mode as u16); @@ -118,8 +117,7 @@ impl Pal for Sys { } fn chown(path: &CStr, owner: uid_t, group: gid_t) -> c_int { - let path = unsafe { c_str(path) }; - match syscall::open(path, O_WRONLY) { + match syscall::open(path.to_bytes(), O_WRONLY) { Err(err) => e(Err(err)) as c_int, Ok(fd) => { let res = syscall::fchown(fd as usize, owner as u32, group as u32); @@ -291,8 +289,7 @@ impl Pal for Sys { } fn utimens(path: &CStr, times: *const timespec) -> c_int { - let path = unsafe { c_str(path) }; - match syscall::open(path, O_STAT) { + match syscall::open(path.to_bytes(), O_STAT) { Err(err) => e(Err(err)) as c_int, Ok(fd) => { let res = Self::futimens(fd as c_int, times); @@ -444,9 +441,8 @@ impl Pal for Sys { } fn link(path1: &CStr, path2: &CStr) -> c_int { - let path1 = unsafe { c_str(path1) }; - let path2 = unsafe { c_str(path2) }; - e(unsafe { syscall::link(path1.as_ptr(), path2.as_ptr()) }) as c_int + e(unsafe { syscall::link(path1.as_ptr() as *const u8, path2.as_ptr() as *const u8) }) + as c_int } fn lseek(fd: c_int, offset: off_t, whence: c_int) -> off_t { @@ -459,8 +455,7 @@ impl Pal for Sys { fn mkdir(path: &CStr, mode: mode_t) -> c_int { let flags = O_CREAT | O_EXCL | O_CLOEXEC | O_DIRECTORY | mode as usize & 0o777; - let path = unsafe { c_str(path) }; - match syscall::open(path, flags) { + match syscall::open(path.to_bytes(), flags) { Ok(fd) => { let _ = syscall::close(fd); 0 @@ -471,8 +466,7 @@ impl Pal for Sys { fn mkfifo(path: &CStr, mode: mode_t) -> c_int { let flags = O_CREAT | MODE_FIFO as usize | mode as usize & 0o777; - let path = unsafe { c_str(path) }; - match syscall::open(path, flags) { + match syscall::open(path.to_bytes(), flags) { Ok(fd) => { let _ = syscall::close(fd); 0 @@ -541,8 +535,10 @@ impl Pal for Sys { } fn open(path: &CStr, oflag: c_int, mode: mode_t) -> c_int { - let path = unsafe { c_str(path) }; - e(syscall::open(path, (oflag as usize) | (mode as usize))) as c_int + e(syscall::open( + path.to_bytes(), + (oflag as usize) | (mode as usize), + )) as c_int } fn pipe(fds: &mut [c_int]) -> c_int { @@ -558,10 +554,9 @@ impl Pal for Sys { } fn rename(oldpath: &CStr, newpath: &CStr) -> c_int { - let (oldpath, newpath) = unsafe { (c_str(oldpath), c_str(newpath)) }; - match syscall::open(oldpath, O_WRONLY) { + match syscall::open(oldpath.to_bytes(), O_WRONLY) { Ok(fd) => { - let retval = syscall::frename(fd, newpath); + let retval = syscall::frename(fd, newpath.to_bytes()); let _ = syscall::close(fd); e(retval) as c_int } @@ -570,8 +565,7 @@ impl Pal for Sys { } fn rmdir(path: &CStr) -> c_int { - let path = unsafe { c_str(path) }; - e(syscall::rmdir(path)) as c_int + e(syscall::rmdir(path.to_bytes())) as c_int } fn select( @@ -590,7 +584,8 @@ impl Pal for Sys { unsafe { (*set).fds_bits[fd / (8 * mem::size_of::())] & mask == mask } } - let event_file = match RawFile::open("event:\0".as_ptr() as &CStr, 0, 0) { + let event_path = unsafe { CStr::from_bytes_with_nul_unchecked(b"event:\0") }; + let event_file = match RawFile::open(event_path, 0, 0) { Ok(file) => file, Err(_) => return -1, }; @@ -632,7 +627,11 @@ impl Pal for Sys { None } else { let timeout_file = match RawFile::open( - format!("time:{}\0", syscall::CLOCK_MONOTONIC).as_ptr() as &CStr, + &unsafe { + CString::from_vec_unchecked( + format!("time:{}", syscall::CLOCK_MONOTONIC).into_bytes(), + ) + }, 0, 0, ) { @@ -726,8 +725,7 @@ impl Pal for Sys { } fn unlink(path: &CStr) -> c_int { - let path = unsafe { c_str(path) }; - e(syscall::unlink(path)) as c_int + e(syscall::unlink(path.to_bytes())) as c_int } fn waitpid(mut pid: pid_t, stat_loc: *mut c_int, options: c_int) -> pid_t { From 0258fb3f5e32081714558b515c181c81e77ae435 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Mon, 27 Aug 2018 08:47:16 -0600 Subject: [PATCH 19/19] Fix header path --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 6d901b6181..ee536cc621 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,7 @@ install: all mkdir -pv "$(DESTDIR)/lib" mkdir -pv "$(DESTDIR)/include" cp -rv "include"/* "$(DESTDIR)/include" - cp -rv "target/include"/* "$(DESTDIR)/include" + cp -rv "$(BUILD)/include"/* "$(DESTDIR)/include" cp -v "$(BUILD)/release/libc.a" "$(DESTDIR)/lib" cp -v "$(BUILD)/release/crt0.o" "$(DESTDIR)/lib" cp -rv "openlibm/include"/* "$(DESTDIR)/include" @@ -82,4 +82,4 @@ $(BUILD)/openlibm: openlibm touch $@ $(BUILD)/openlibm/libopenlibm.a: $(BUILD)/openlibm $(BUILD)/include - make CC=$(CC) CPPFLAGS="-fno-stack-protector -I$(shell pwd)/include -I $(shell pwd)/target/include" -C $< libopenlibm.a + make CC=$(CC) CPPFLAGS="-fno-stack-protector -I$(shell pwd)/include -I $(shell pwd)/$(BUILD)/include" -C $< libopenlibm.a