2
0

mod.rs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. use dsc::syscall;
  2. use super::{pal::Pal, types::{c_void, c_int}};
  3. pub struct Sys;
  4. impl Sys {
  5. pub unsafe fn ioctl() {
  6. unimplemented!();
  7. }
  8. }
  9. pub fn e(sys: usize) -> usize {
  10. if (sys as isize) < 0 && (sys as isize) >= -256 {
  11. unsafe {
  12. errno = -(sys as isize) as c_int;
  13. }
  14. !0
  15. } else {
  16. sys
  17. }
  18. }
  19. impl Pal for Sys {
  20. fn access(path: &CStr, mode: c_int) -> c_int {
  21. unimplemented!()
  22. }
  23. fn brk(addr: *mut c_void) -> *mut c_void {
  24. unsafe { syscall!(SYS_BRK, addr) as *mut c_void }
  25. }
  26. fn chdir(path: &CStr) -> c_int {
  27. e(unsafe { syscall!(SYS_CHDIR, path.as_ptr()) }) as c_int
  28. }
  29. fn chmod(path: &CStr, mode: mode_t) -> c_int {
  30. return 0;
  31. }
  32. fn chown(path: &CStr, owner: uid_t, group: gid_t) -> c_int {
  33. return 0;
  34. }
  35. fn clock_gettime(clk_id: clockid_t, tp: *mut timespec) -> c_int {
  36. return -ENOSYS;
  37. }
  38. fn close(fildes: c_int) -> c_int {
  39. e(unsafe { syscall!(SYS_CLOSE, fildes) }) as c_int
  40. }
  41. fn dup(fildes: c_int) -> c_int {
  42. e(unsafe { syscall!(SYS_DUP, fildes) }) as c_int
  43. }
  44. fn dup2(fildes: c_int, fildes2: c_int) -> c_int {
  45. e(unsafe { syscall!(SYS_DUP2, fildes, fildes2) }) as c_int
  46. }
  47. unsafe fn execve(path: &CStr, argv: *const *mut c_char, envp: *const *mut c_char) -> c_int {
  48. e(syscall!(SYS_EXECVE, path.as_ptr(), argv, envp)) as c_int
  49. }
  50. fn exit(status: c_int) -> ! {
  51. unsafe {
  52. syscall!(SYS_EXIT, status);
  53. }
  54. loop {}
  55. }
  56. fn fchdir(fildes: c_int) -> c_int {
  57. unimplemented!()
  58. }
  59. fn fchmod(fildes: c_int, mode: mode_t) -> c_int {
  60. return 0;
  61. }
  62. fn fchown(fildes: c_int, owner: uid_t, group: gid_t) -> c_int {
  63. return 0;
  64. }
  65. fn flock(fd: c_int, operation: c_int) -> c_int {
  66. return 0;
  67. }
  68. fn fstat(fildes: c_int, buf: *mut stat) -> c_int {
  69. e(unsafe { syscall!(SYS_FSTAT, fildes, buf) }) as c_int
  70. }
  71. fn fstatvfs(fildes: c_int, buf: *mut statvfs) -> c_int {
  72. unimplemented!()
  73. }
  74. fn fcntl(fildes: c_int, cmd: c_int, arg: c_int) -> c_int {
  75. let rc = e(unsafe { syscall!(SYS_FCNTL, fildes, cmd, arg) }) as c_int;
  76. return rc;
  77. }
  78. fn fork() -> pid_t {
  79. e(unsafe { syscall!(SYS_FORK) }) as pid_t
  80. }
  81. fn fpath(fildes: c_int, out: &mut [u8]) -> ssize_t {
  82. unimplemented!()
  83. }
  84. fn fsync(fildes: c_int) -> c_int {
  85. return 0;
  86. }
  87. fn ftruncate(fildes: c_int, length: off_t) -> c_int {
  88. e(unsafe { syscall!(SYS_FTRUNCATE, fildes, length) }) as c_int
  89. }
  90. fn futex(addr: *mut c_int, op: c_int, val: c_int, val2: usize) -> c_int {
  91. unimplemented!()
  92. }
  93. fn futimens(fd: c_int, times: *const timespec) -> c_int {
  94. unimplemented!()
  95. }
  96. fn utimens(path: &CStr, times: *const timespec) -> c_int {
  97. unimplemented!()
  98. }
  99. fn getcwd(buf: *mut c_char, size: size_t) -> *mut c_char {
  100. if size > 2 {
  101. unsafe {
  102. *buf = b'/' as c_char;
  103. *buf.add(1) = b'\0' as c_char;
  104. }
  105. }
  106. return buf;
  107. }
  108. fn getdents(fd: c_int, dirents: *mut dirent, bytes: usize) -> c_int {
  109. unsafe { syscall!(SYS_GET_DENTS, fd, dirents, bytes) as c_int }
  110. }
  111. fn getegid() -> gid_t {
  112. return 0;
  113. }
  114. fn geteuid() -> uid_t {
  115. return 0;
  116. }
  117. fn getgid() -> gid_t {
  118. return 0;
  119. }
  120. fn getpagesize() -> usize {
  121. return 4096;
  122. }
  123. fn getpgid(pid: pid_t) -> pid_t {
  124. return 0;
  125. }
  126. fn getpid() -> pid_t {
  127. e(unsafe { syscall!(SYS_GETPID) }) as pid_t
  128. }
  129. fn getppid() -> pid_t {
  130. return 0;
  131. }
  132. fn getrandom(buf: &mut [u8], flags: c_uint) -> ssize_t {
  133. unimplemented!()
  134. }
  135. unsafe fn getrlimit(resource: c_int, rlim: *mut rlimit) -> c_int {
  136. unimplemented!()
  137. }
  138. fn getsid(pid: pid_t) -> pid_t {
  139. return 0;
  140. }
  141. fn gettid() -> pid_t {
  142. return Self::getpid();
  143. }
  144. fn gettimeofday(tp: *mut timeval, tzp: *mut timezone) -> c_int {
  145. e(unsafe { syscall!(SYS_GETTIMEOFDAY, tp, tzp) }) as c_int
  146. }
  147. fn getuid() -> uid_t {
  148. return 0;
  149. }
  150. fn lchown(path: &CStr, owner: uid_t, group: gid_t) -> c_int {
  151. return 0;
  152. }
  153. fn link(path1: &CStr, path2: &CStr) -> c_int {
  154. unimplemented!()
  155. }
  156. fn lseek(fildes: c_int, offset: off_t, whence: c_int) -> off_t {
  157. e(unsafe { syscall!(SYS_LSEEK, fildes, offset, whence) }) as off_t
  158. }
  159. fn mkdir(path: &CStr, mode: mode_t) -> c_int {
  160. e(unsafe { syscall!(SYS_MKDIR, path.as_ptr(), mode) }) as c_int
  161. }
  162. fn mkfifo(path: &CStr, mode: mode_t) -> c_int {
  163. unimplemented!()
  164. }
  165. unsafe fn mlock(addr: *const c_void, len: usize) -> c_int {
  166. unimplemented!()
  167. }
  168. fn mlockall(flags: c_int) -> c_int {
  169. unimplemented!()
  170. }
  171. unsafe fn mmap(
  172. addr: *mut c_void,
  173. len: usize,
  174. prot: c_int,
  175. flags: c_int,
  176. fildes: c_int,
  177. off: off_t,
  178. ) -> *mut c_void {
  179. e(syscall!(SYS_MMAP, addr, len, prot, flags, fildes, off)) as *mut c_void
  180. }
  181. unsafe fn mprotect(addr: *mut c_void, len: usize, prot: c_int) -> c_int {
  182. e(syscall!(SYS_MPROTECT, addr, len, prot)) as c_int
  183. }
  184. unsafe fn msync(addr: *mut c_void, len: usize, flags: c_int) -> c_int {
  185. unimplemented!()
  186. }
  187. unsafe fn munlock(addr: *const c_void, len: usize) -> c_int {
  188. unimplemented!()
  189. }
  190. fn munlockall() -> c_int {
  191. unimplemented!()
  192. }
  193. unsafe fn munmap(addr: *mut c_void, len: usize) -> c_int {
  194. e(syscall!(SYS_MUNMAP, addr, len)) as c_int
  195. }
  196. fn nanosleep(rqtp: *const timespec, rmtp: *mut timespec) -> c_int {
  197. e(unsafe { syscall!(SYS_NANOSLEEP, rqtp, rmtp) }) as c_int
  198. }
  199. fn open(path: &CStr, oflag: c_int, mode: mode_t) -> c_int {
  200. e(unsafe { syscall!(SYS_OPEN, path.as_ptr(), oflag, mode) }) as c_int
  201. }
  202. fn pipe2(fildes: &mut [c_int], flags: c_int) -> c_int {
  203. if flags == 0 {
  204. e(unsafe { syscall!(SYS_PIPE, fildes.as_mut_ptr()) }) as c_int
  205. } else {
  206. unimplemented!()
  207. }
  208. }
  209. #[cfg(target_arch = "x86_64")]
  210. unsafe fn pte_clone(stack: *mut usize) -> pid_t {
  211. unimplemented!()
  212. }
  213. fn read(fildes: c_int, buf: &mut [u8]) -> ssize_t {
  214. e(unsafe { syscall!(SYS_READ, fildes, buf.as_mut_ptr(), buf.len()) }) as ssize_t
  215. }
  216. fn readlink(pathname: &CStr, out: &mut [u8]) -> ssize_t {
  217. unimplemented!()
  218. }
  219. fn rename(old: &CStr, new: &CStr) -> c_int {
  220. unimplemented!()
  221. }
  222. fn rmdir(path: &CStr) -> c_int {
  223. e(unsafe { syscall!(SYS_UNLINK_AT, 0, path.as_ptr(), AT_REMOVEDIR) }) as c_int
  224. }
  225. fn sched_yield() -> c_int {
  226. unimplemented!()
  227. }
  228. fn setpgid(pid: pid_t, pgid: pid_t) -> c_int {
  229. unimplemented!()
  230. }
  231. fn setregid(rgid: gid_t, egid: gid_t) -> c_int {
  232. unimplemented!()
  233. }
  234. fn setreuid(ruid: uid_t, euid: uid_t) -> c_int {
  235. unimplemented!()
  236. }
  237. fn symlink(path1: &CStr, path2: &CStr) -> c_int {
  238. unimplemented!()
  239. }
  240. fn umask(mask: mode_t) -> mode_t {
  241. unimplemented!()
  242. }
  243. fn uname(utsname: *mut utsname) -> c_int {
  244. unimplemented!()
  245. }
  246. fn unlink(path: &CStr) -> c_int {
  247. e(unsafe { syscall!(SYS_UNLINK_AT, AT_FDCWD, path.as_ptr(), 0) }) as c_int
  248. }
  249. fn waitpid(pid: pid_t, stat_loc: *mut c_int, options: c_int) -> pid_t {
  250. e(unsafe { syscall!(SYS_WAIT4, pid, stat_loc, options, 0) }) as pid_t
  251. }
  252. fn write(fildes: c_int, buf: &[u8]) -> ssize_t {
  253. e(unsafe { syscall!(SYS_WRITE, fildes, buf.as_ptr(), buf.len()) }) as ssize_t
  254. }
  255. fn verify() -> bool {
  256. return true;
  257. }
  258. }