123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335 |
- use dsc::syscall;
- use super::{pal::Pal, types::{c_void, c_int}};
- pub struct Sys;
- impl Sys {
- pub unsafe fn ioctl() {
- unimplemented!();
- }
- }
- pub fn e(sys: usize) -> usize {
- if (sys as isize) < 0 && (sys as isize) >= -256 {
- unsafe {
- errno = -(sys as isize) as c_int;
- }
- !0
- } else {
- sys
- }
- }
- impl Pal for Sys {
- fn access(path: &CStr, mode: c_int) -> c_int {
- unimplemented!()
- }
- fn brk(addr: *mut c_void) -> *mut c_void {
- unsafe { syscall!(SYS_BRK, addr) as *mut c_void }
- }
- fn chdir(path: &CStr) -> c_int {
- e(unsafe { syscall!(SYS_CHDIR, path.as_ptr()) }) as c_int
- }
- fn chmod(path: &CStr, mode: mode_t) -> c_int {
- return 0;
- }
- fn chown(path: &CStr, owner: uid_t, group: gid_t) -> c_int {
- return 0;
- }
- fn clock_gettime(clk_id: clockid_t, tp: *mut timespec) -> c_int {
- return -ENOSYS;
- }
- fn close(fildes: c_int) -> c_int {
- e(unsafe { syscall!(SYS_CLOSE, fildes) }) as c_int
- }
- fn dup(fildes: c_int) -> c_int {
- e(unsafe { syscall!(SYS_DUP, fildes) }) as c_int
- }
- fn dup2(fildes: c_int, fildes2: c_int) -> c_int {
- e(unsafe { syscall!(SYS_DUP2, fildes, fildes2) }) as c_int
- }
- unsafe fn execve(path: &CStr, argv: *const *mut c_char, envp: *const *mut c_char) -> c_int {
- e(syscall!(SYS_EXECVE, path.as_ptr(), argv, envp)) as c_int
- }
- fn exit(status: c_int) -> ! {
- unsafe {
- syscall!(SYS_EXIT, status);
- }
- loop {}
- }
- fn fchdir(fildes: c_int) -> c_int {
- unimplemented!()
- }
- fn fchmod(fildes: c_int, mode: mode_t) -> c_int {
- return 0;
- }
- fn fchown(fildes: c_int, owner: uid_t, group: gid_t) -> c_int {
- return 0;
- }
- fn flock(fd: c_int, operation: c_int) -> c_int {
- return 0;
- }
- fn fstat(fildes: c_int, buf: *mut stat) -> c_int {
- e(unsafe { syscall!(SYS_FSTAT, fildes, buf) }) as c_int
- }
- fn fstatvfs(fildes: c_int, buf: *mut statvfs) -> c_int {
- unimplemented!()
- }
- fn fcntl(fildes: c_int, cmd: c_int, arg: c_int) -> c_int {
- let rc = e(unsafe { syscall!(SYS_FCNTL, fildes, cmd, arg) }) as c_int;
- return rc;
- }
- fn fork() -> pid_t {
- e(unsafe { syscall!(SYS_FORK) }) as pid_t
- }
- fn fpath(fildes: c_int, out: &mut [u8]) -> ssize_t {
- unimplemented!()
- }
- fn fsync(fildes: c_int) -> c_int {
- return 0;
- }
- fn ftruncate(fildes: c_int, length: off_t) -> c_int {
- e(unsafe { syscall!(SYS_FTRUNCATE, fildes, length) }) as c_int
- }
- fn futex(addr: *mut c_int, op: c_int, val: c_int, val2: usize) -> c_int {
- unimplemented!()
- }
- fn futimens(fd: c_int, times: *const timespec) -> c_int {
- unimplemented!()
- }
- fn utimens(path: &CStr, times: *const timespec) -> c_int {
- unimplemented!()
- }
- fn getcwd(buf: *mut c_char, size: size_t) -> *mut c_char {
- if size > 2 {
- unsafe {
- *buf = b'/' as c_char;
- *buf.add(1) = b'\0' as c_char;
- }
- }
- return buf;
- }
- fn getdents(fd: c_int, dirents: *mut dirent, bytes: usize) -> c_int {
- unsafe { syscall!(SYS_GET_DENTS, fd, dirents, bytes) as c_int }
- }
- fn getegid() -> gid_t {
- return 0;
- }
- fn geteuid() -> uid_t {
- return 0;
- }
- fn getgid() -> gid_t {
- return 0;
- }
- fn getpagesize() -> usize {
- return 4096;
- }
- fn getpgid(pid: pid_t) -> pid_t {
- return 0;
- }
- fn getpid() -> pid_t {
- e(unsafe { syscall!(SYS_GETPID) }) as pid_t
- }
- fn getppid() -> pid_t {
- return 0;
- }
- fn getrandom(buf: &mut [u8], flags: c_uint) -> ssize_t {
- unimplemented!()
- }
- unsafe fn getrlimit(resource: c_int, rlim: *mut rlimit) -> c_int {
- unimplemented!()
- }
- fn getsid(pid: pid_t) -> pid_t {
- return 0;
- }
- fn gettid() -> pid_t {
- return Self::getpid();
- }
- fn gettimeofday(tp: *mut timeval, tzp: *mut timezone) -> c_int {
- e(unsafe { syscall!(SYS_GETTIMEOFDAY, tp, tzp) }) as c_int
- }
- fn getuid() -> uid_t {
- return 0;
- }
- fn lchown(path: &CStr, owner: uid_t, group: gid_t) -> c_int {
- return 0;
- }
- fn link(path1: &CStr, path2: &CStr) -> c_int {
- unimplemented!()
- }
- fn lseek(fildes: c_int, offset: off_t, whence: c_int) -> off_t {
- e(unsafe { syscall!(SYS_LSEEK, fildes, offset, whence) }) as off_t
- }
- fn mkdir(path: &CStr, mode: mode_t) -> c_int {
- e(unsafe { syscall!(SYS_MKDIR, path.as_ptr(), mode) }) as c_int
- }
- fn mkfifo(path: &CStr, mode: mode_t) -> c_int {
- unimplemented!()
- }
- unsafe fn mlock(addr: *const c_void, len: usize) -> c_int {
- unimplemented!()
- }
- fn mlockall(flags: c_int) -> c_int {
- unimplemented!()
- }
- 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!(SYS_MMAP, addr, len, prot, flags, fildes, off)) as *mut c_void
- }
- unsafe fn mprotect(addr: *mut c_void, len: usize, prot: c_int) -> c_int {
- e(syscall!(SYS_MPROTECT, addr, len, prot)) as c_int
- }
- unsafe fn msync(addr: *mut c_void, len: usize, flags: c_int) -> c_int {
- unimplemented!()
- }
- unsafe fn munlock(addr: *const c_void, len: usize) -> c_int {
- unimplemented!()
- }
- fn munlockall() -> c_int {
- unimplemented!()
- }
- unsafe fn munmap(addr: *mut c_void, len: usize) -> c_int {
- e(syscall!(SYS_MUNMAP, addr, len)) as c_int
- }
- fn nanosleep(rqtp: *const timespec, rmtp: *mut timespec) -> c_int {
- e(unsafe { syscall!(SYS_NANOSLEEP, rqtp, rmtp) }) as c_int
- }
- fn open(path: &CStr, oflag: c_int, mode: mode_t) -> c_int {
- e(unsafe { syscall!(SYS_OPEN, path.as_ptr(), oflag, mode) }) as c_int
- }
- fn pipe2(fildes: &mut [c_int], flags: c_int) -> c_int {
- if flags == 0 {
- e(unsafe { syscall!(SYS_PIPE, fildes.as_mut_ptr()) }) as c_int
- } else {
- unimplemented!()
- }
- }
- #[cfg(target_arch = "x86_64")]
- unsafe fn pte_clone(stack: *mut usize) -> pid_t {
- unimplemented!()
- }
- fn read(fildes: c_int, buf: &mut [u8]) -> ssize_t {
- e(unsafe { syscall!(SYS_READ, fildes, buf.as_mut_ptr(), buf.len()) }) as ssize_t
- }
- fn readlink(pathname: &CStr, out: &mut [u8]) -> ssize_t {
- unimplemented!()
- }
- fn rename(old: &CStr, new: &CStr) -> c_int {
- unimplemented!()
- }
- fn rmdir(path: &CStr) -> c_int {
- e(unsafe { syscall!(SYS_UNLINK_AT, 0, path.as_ptr(), AT_REMOVEDIR) }) as c_int
- }
- fn sched_yield() -> c_int {
- unimplemented!()
- }
- fn setpgid(pid: pid_t, pgid: pid_t) -> c_int {
- unimplemented!()
- }
- fn setregid(rgid: gid_t, egid: gid_t) -> c_int {
- unimplemented!()
- }
- fn setreuid(ruid: uid_t, euid: uid_t) -> c_int {
- unimplemented!()
- }
- fn symlink(path1: &CStr, path2: &CStr) -> c_int {
- unimplemented!()
- }
- fn umask(mask: mode_t) -> mode_t {
- unimplemented!()
- }
- fn uname(utsname: *mut utsname) -> c_int {
- unimplemented!()
- }
- fn unlink(path: &CStr) -> c_int {
- e(unsafe { syscall!(SYS_UNLINK_AT, AT_FDCWD, path.as_ptr(), 0) }) as c_int
- }
- fn waitpid(pid: pid_t, stat_loc: *mut c_int, options: c_int) -> pid_t {
- e(unsafe { syscall!(SYS_WAIT4, pid, stat_loc, options, 0) }) as pid_t
- }
- fn write(fildes: c_int, buf: &[u8]) -> ssize_t {
- e(unsafe { syscall!(SYS_WRITE, fildes, buf.as_ptr(), buf.len()) }) as ssize_t
- }
- fn verify() -> bool {
- return true;
- }
- }
|