summary refs log tree commit diff
diff options
context:
space:
mode:
authoredef <edef@unfathomable.blue>2022-07-27 15:15:35 +0000
committeredef <edef@unfathomable.blue>2022-07-27 15:15:35 +0000
commite4d17e3ea3cbade54e0d9abdb185d61f9cdc1cb1 (patch)
tree45783ab98dc8b0e7d8cd6cd1fe1e2408f955804c
parent1186ca99272815713af1bbdfad63377fd9ccc604 (diff)
downloadunf-legacy-e4d17e3ea3cbade54e0d9abdb185d61f9cdc1cb1.tar.zst
ripple/minitrace: introduce syscall_bitflags!
Squeeze the bitflags / SyscallArg impl boilerplate into one macro.

Change-Id: I5b5213b6f3ee11bc61b6f8439ceb2510ef6dffec
-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)
-	}
-}