summary refs log tree commit diff
path: root/ripple/minitrace/src/syscall_abi/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'ripple/minitrace/src/syscall_abi/mod.rs')
-rw-r--r--ripple/minitrace/src/syscall_abi/mod.rs127
1 files changed, 127 insertions, 0 deletions
diff --git a/ripple/minitrace/src/syscall_abi/mod.rs b/ripple/minitrace/src/syscall_abi/mod.rs
new file mode 100644
index 0000000..e0b35a9
--- /dev/null
+++ b/ripple/minitrace/src/syscall_abi/mod.rs
@@ -0,0 +1,127 @@
+// SPDX-FileCopyrightText: edef <edef@unfathomable.blue>
+// SPDX-FileCopyrightText: V <v@unfathomable.blue>
+// SPDX-License-Identifier: OSL-3.0
+
+use {
+	crate::{define_syscalls, syscall_bitflags, syscall_enums, Process},
+	std::ffi::CString,
+};
+
+pub(crate) use arg::{ProcessSyscallArg, SyscallArg};
+pub(crate) use fd::{DirFd, FileDesc};
+
+mod arg;
+mod fd;
+pub mod macros;
+
+type SigAction = ();
+type SysInfo = ();
+type Tms = ();
+type Stat = ();
+type RobustListHead = ();
+type RLimit64 = ();
+
+define_syscalls! {
+	enum SyscallEntry {
+		fn read(fd: FileDesc, buf: *mut u8, count: usize) -> i64 = 0;
+		fn write(fd: FileDesc, buf: *const u8, count: usize) -> i64 = 1;
+		fn close(fd: FileDesc) -> i64 = 3;
+		fn mmap(addr: u64, len: u64, prot: ProtFlags, flags: MapFlags, fd: Option<FileDesc>, off: u64) -> i64 = 9;
+		fn mprotect(addr: u64, len: usize, prot: ProtFlags) -> i64 = 10;
+		fn brk(brk: u64) -> i64 = 12;
+		fn rt_sigaction(sig: Signal, act: *const SigAction, oact: *mut SigAction, sigsetsize: usize) -> i64 = 13;
+		fn ioctl(fd: FileDesc, cmd: Ioctl, arg: u64) -> i64 = 16;
+		fn pread64(fd: FileDesc, buf: *mut u8, count: usize, pos: u64) -> i64 = 17;
+		fn access(filename: CString, mode: AccessMode) -> i64 = 21;
+		fn getcwd(buf: *mut u8, size: u64) -> i64 = 79;
+		fn readlink(path: CString, buf: *mut u8, bufsiz: i32) -> i64 = 89;
+		fn sysinfo(info: *mut SysInfo) -> i64 = 99;
+		fn times(tbuf: *mut Tms) -> i64 = 100;
+		fn arch_prctl(option: ArchOption, arg2: u64) -> i64 = 158;
+		fn set_tid_address(tidptr: *mut i32) -> i64 = 218;
+		fn exit_group(error_code: i32) -> i64 = 231;
+		fn openat(dfd: DirFd, filename: CString, flags: OpenFlags, mode: FileMode) -> i64 = 257;
+		fn newfstatat(dfd: DirFd, filename: CString, statbuf: *mut Stat, flags: AtFlags) -> i64 = 262;
+		fn set_robust_list(head: *mut RobustListHead, len: usize) -> i64 = 273;
+		fn prlimit64(pid: i32, resource: ResourceLimit, new_rlim: *const RLimit64, old_rlim: *mut RLimit64) -> i64 = 302;
+		fn getrandom(ubuf: *mut u8, len: usize, flags: GrndFlags) -> i64 = 318;
+	}
+}
+
+syscall_bitflags! {
+	struct OpenFlags: i32 {
+		const WRONLY  = 1 <<  0 => O_WRONLY;
+		const CREAT   = 1 <<  6 => O_CREAT;
+		const NOCTTY  = 1 <<  8 => O_NOCTTY;
+		const TRUNC   = 1 <<  9 => O_TRUNC;
+		const CLOEXEC = 1 << 19 => O_CLOEXEC;
+	}
+
+	struct GrndFlags: u32 {
+		const NONBLOCK = 1 << 0 => GRND_NONBLOCK;
+		const RANDOM   = 1 << 1 => GRND_RANDOM;
+	}
+
+	struct MapFlags: i32 {
+		const PRIVATE   = 1 <<  1 => MAP_PRIVATE;
+		const FIXED     = 1 <<  4 => MAP_FIXED;
+		const ANONYMOUS = 1 <<  5 => MAP_ANONYMOUS;
+		const DENYWRITE = 1 << 11 => MAP_DENYWRITE;
+	}
+
+	struct ProtFlags: i32 {
+		const READ  = 1 << 0 => PROT_READ;
+		const WRITE = 1 << 1 => PROT_WRITE;
+		const EXEC  = 1 << 2 => PROT_EXEC;
+	}
+
+	struct AtFlags: i32 {
+		const EMPTY_PATH = 1 << 12 => AT_EMPTY_PATH;
+	}
+
+	struct AccessMode: i32 {
+		const F = 0 => F_OK;
+		const X = 1 << 0 => X_OK;
+		const W = 1 << 1 => W_OK;
+		const R = 1 << 2 => R_OK;
+	}
+
+	struct FileMode: u32 {
+		const IRUSR = 0o400 => S_IRUSR;
+		const IWUSR = 0o200 => S_IWUSR;
+		const IXUSR = 0o100 => S_IXUSR;
+
+		const IRGRP = 0o040 => S_IRGRP;
+		const IWGRP = 0o020 => S_IWGRP;
+		const IXGRP = 0o010 => S_IXGRP;
+
+		const IROTH = 0o004 => S_IROTH;
+		const IWOTH = 0o002 => S_IWOTH;
+		const IXOTH = 0o001 => S_IXOTH;
+	}
+}
+
+syscall_enums! {
+	enum ResourceLimit: u32 {
+		STACK = 0x3 => RLIMIT_STACK,
+		RSS   = 0x5 => RLIMIT_RSS,
+		AS    = 0x9 => RLIMIT_AS,
+	}
+
+	enum ArchOption: i32 {
+		SET_FS = 0x1002,
+	}
+
+	enum Ioctl: u64 {
+		TCGETS     = 0x5401 => TCGETS,
+		TIOCGWINSZ = 0x5413 => TIOCGWINSZ,
+	}
+
+	enum Signal: i32 {
+		ILL  =  4 => SIGILL,
+		ABRT =  6 => SIGABRT,
+		BUS  =  7 => SIGBUS,
+		FPE  =  8 => SIGFPE,
+		SEGV = 11 => SIGSEGV,
+	}
+}