summary refs log tree commit diff
path: root/ripple/minitrace/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'ripple/minitrace/src/main.rs')
-rw-r--r--ripple/minitrace/src/main.rs46
1 files changed, 33 insertions, 13 deletions
diff --git a/ripple/minitrace/src/main.rs b/ripple/minitrace/src/main.rs
index 98bf4d5..4e2368a 100644
--- a/ripple/minitrace/src/main.rs
+++ b/ripple/minitrace/src/main.rs
@@ -122,6 +122,38 @@ macro_rules! define_syscalls {
 	}
 }
 
+macro_rules! syscall_bitflags {
+	(
+		struct $BitFlags:ident: $T:ty {
+			$(
+				const $Flag:ident = $value:expr;
+			)*
+		}
+
+		$($t:tt)*
+	) => {
+		bitflags! {
+			struct $BitFlags: $T {
+				$(
+					const $Flag = $value;
+				)*
+			}
+		}
+
+		impl SyscallArg for $BitFlags {
+			fn try_from_reg(reg: u64) -> Option<Self> {
+				SyscallArg::try_from_reg(reg).and_then(Self::from_bits)
+			}
+		}
+
+		syscall_bitflags! {
+			$($t)*
+		}
+	};
+
+	() => {}
+}
+
 trait SyscallArg: Sized {
 	fn try_from_reg(reg: u64) -> Option<Self>;
 }
@@ -421,7 +453,7 @@ fn check_syscall(process: &Process, entry: SyscallEntry) -> bool {
 	true
 }
 
-bitflags! {
+syscall_bitflags! {
 	struct OpenFlags: i32 {
 		const WRONLY  = 0o00000001;
 		const CREAT   = 0o00000100;
@@ -435,15 +467,3 @@ bitflags! {
 		const GRND_RANDOM = 1 << 1;
 	}
 }
-
-impl SyscallArg for OpenFlags {
-	fn try_from_reg(reg: u64) -> Option<Self> {
-		SyscallArg::try_from_reg(reg).and_then(Self::from_bits)
-	}
-}
-
-impl SyscallArg for GrndFlags {
-	fn try_from_reg(reg: u64) -> Option<Self> {
-		SyscallArg::try_from_reg(reg).and_then(Self::from_bits)
-	}
-}