From e4d17e3ea3cbade54e0d9abdb185d61f9cdc1cb1 Mon Sep 17 00:00:00 2001 From: edef Date: Wed, 27 Jul 2022 15:15:35 +0000 Subject: ripple/minitrace: introduce syscall_bitflags! Squeeze the bitflags / SyscallArg impl boilerplate into one macro. Change-Id: I5b5213b6f3ee11bc61b6f8439ceb2510ef6dffec --- ripple/minitrace/src/main.rs | 46 +++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-) (limited to 'ripple') 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 { + SyscallArg::try_from_reg(reg).and_then(Self::from_bits) + } + } + + syscall_bitflags! { + $($t)* + } + }; + + () => {} +} + trait SyscallArg: Sized { fn try_from_reg(reg: u64) -> Option; } @@ -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 { - SyscallArg::try_from_reg(reg).and_then(Self::from_bits) - } -} - -impl SyscallArg for GrndFlags { - fn try_from_reg(reg: u64) -> Option { - SyscallArg::try_from_reg(reg).and_then(Self::from_bits) - } -} -- cgit 1.4.1