mod.rs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. use super::types::*;
  2. use crate::{
  3. c_str::CStr,
  4. header::{
  5. dirent::dirent,
  6. sys_resource::rlimit,
  7. sys_stat::stat,
  8. sys_statvfs::statvfs,
  9. sys_time::{timeval, timezone},
  10. sys_utsname::utsname,
  11. time::timespec,
  12. },
  13. };
  14. pub use self::epoll::PalEpoll;
  15. mod epoll;
  16. pub use self::ptrace::PalPtrace;
  17. mod ptrace;
  18. pub use self::signal::PalSignal;
  19. mod signal;
  20. pub use self::socket::PalSocket;
  21. mod socket;
  22. pub trait Pal {
  23. fn access(path: &CStr, mode: c_int) -> c_int;
  24. fn brk(addr: *mut c_void) -> *mut c_void;
  25. fn chdir(path: &CStr) -> c_int;
  26. fn chmod(path: &CStr, mode: mode_t) -> c_int;
  27. fn chown(path: &CStr, owner: uid_t, group: gid_t) -> c_int;
  28. fn clock_gettime(clk_id: clockid_t, tp: *mut timespec) -> c_int;
  29. fn close(fildes: c_int) -> c_int;
  30. fn dup(fildes: c_int) -> c_int;
  31. fn dup2(fildes: c_int, fildes2: c_int) -> c_int;
  32. unsafe fn execve(path: &CStr, argv: *const *mut c_char, envp: *const *mut c_char) -> c_int;
  33. fn exit(status: c_int) -> !;
  34. fn fchdir(fildes: c_int) -> c_int;
  35. fn fchmod(fildes: c_int, mode: mode_t) -> c_int;
  36. fn fchown(fildes: c_int, owner: uid_t, group: gid_t) -> c_int;
  37. fn flock(fd: c_int, operation: c_int) -> c_int;
  38. fn fstat(fildes: c_int, buf: *mut stat) -> c_int;
  39. fn fstatvfs(fildes: c_int, buf: *mut statvfs) -> c_int;
  40. fn fcntl(fildes: c_int, cmd: c_int, arg: c_int) -> c_int;
  41. fn fork() -> pid_t;
  42. fn fpath(fildes: c_int, out: &mut [u8]) -> ssize_t;
  43. fn fsync(fildes: c_int) -> c_int;
  44. fn ftruncate(fildes: c_int, length: off_t) -> c_int;
  45. fn futex(addr: *mut c_int, op: c_int, val: c_int) -> c_int;
  46. fn futimens(fd: c_int, times: *const timespec) -> c_int;
  47. fn utimens(path: &CStr, times: *const timespec) -> c_int;
  48. fn getcwd(buf: *mut c_char, size: size_t) -> *mut c_char;
  49. fn getdents(fd: c_int, dirents: *mut dirent, bytes: usize) -> c_int;
  50. fn getegid() -> gid_t;
  51. fn geteuid() -> uid_t;
  52. fn getgid() -> gid_t;
  53. /* Note that this is distinct from the legacy POSIX function
  54. * getpagesize(), which returns a c_int. On some Linux platforms,
  55. * page size may be determined through a syscall ("getpagesize"). */
  56. fn getpagesize() -> usize;
  57. fn getpgid(pid: pid_t) -> pid_t;
  58. fn getpid() -> pid_t;
  59. fn getppid() -> pid_t;
  60. fn getrandom(buf: &mut [u8], flags: c_uint) -> ssize_t;
  61. unsafe fn getrlimit(resource: c_int, rlim: *mut rlimit) -> c_int;
  62. fn gettid() -> pid_t;
  63. fn gettimeofday(tp: *mut timeval, tzp: *mut timezone) -> c_int;
  64. fn getuid() -> uid_t;
  65. fn lchown(path: &CStr, owner: uid_t, group: gid_t) -> c_int;
  66. fn link(path1: &CStr, path2: &CStr) -> c_int;
  67. fn lseek(fildes: c_int, offset: off_t, whence: c_int) -> off_t;
  68. fn mkdir(path: &CStr, mode: mode_t) -> c_int;
  69. fn mkfifo(path: &CStr, mode: mode_t) -> c_int;
  70. unsafe fn mlock(addr: *const c_void, len: usize) -> c_int;
  71. fn mlockall(flags: c_int) -> c_int;
  72. unsafe fn mmap(
  73. addr: *mut c_void,
  74. len: usize,
  75. prot: c_int,
  76. flags: c_int,
  77. fildes: c_int,
  78. off: off_t,
  79. ) -> *mut c_void;
  80. unsafe fn mprotect(addr: *mut c_void, len: usize, prot: c_int) -> c_int;
  81. unsafe fn msync(addr: *mut c_void, len: usize, flags: c_int) -> c_int;
  82. unsafe fn munlock(addr: *const c_void, len: usize) -> c_int;
  83. fn munlockall() -> c_int;
  84. unsafe fn munmap(addr: *mut c_void, len: usize) -> c_int;
  85. fn nanosleep(rqtp: *const timespec, rmtp: *mut timespec) -> c_int;
  86. fn open(path: &CStr, oflag: c_int, mode: mode_t) -> c_int;
  87. fn pipe2(fildes: &mut [c_int], flags: c_int) -> c_int;
  88. unsafe fn pte_clone(stack: *mut usize) -> pid_t;
  89. fn read(fildes: c_int, buf: &mut [u8]) -> ssize_t;
  90. fn readlink(pathname: &CStr, out: &mut [u8]) -> ssize_t;
  91. fn rename(old: &CStr, new: &CStr) -> c_int;
  92. fn rmdir(path: &CStr) -> c_int;
  93. fn sched_yield() -> c_int;
  94. fn setpgid(pid: pid_t, pgid: pid_t) -> c_int;
  95. fn setregid(rgid: gid_t, egid: gid_t) -> c_int;
  96. fn setreuid(ruid: uid_t, euid: uid_t) -> c_int;
  97. fn symlink(path1: &CStr, path2: &CStr) -> c_int;
  98. fn umask(mask: mode_t) -> mode_t;
  99. fn uname(utsname: *mut utsname) -> c_int;
  100. fn unlink(path: &CStr) -> c_int;
  101. fn waitpid(pid: pid_t, stat_loc: *mut c_int, options: c_int) -> pid_t;
  102. fn write(fildes: c_int, buf: &[u8]) -> ssize_t;
  103. fn verify() -> bool;
  104. }