summary refs log tree commit diff
path: root/ripple/minitrace/src
diff options
context:
space:
mode:
authoredef <edef@unfathomable.blue>2022-07-29 12:48:46 +0000
committeredef <edef@unfathomable.blue>2022-07-29 12:48:46 +0000
commite2fd0668e5a54154fe6c5a8b57eb84356b6b31be (patch)
tree1999ba63c9ae9fbfca6609b6b56db50cc3f4d499 /ripple/minitrace/src
parent944c1fc7ed2ac0dc396bafea5ae92aca04dd139a (diff)
downloadunf-legacy-e2fd0668e5a54154fe6c5a8b57eb84356b6b31be.tar.zst
ripple/minitrace: verify syscall bitflags against libc
Change-Id: Ie9eae95ff5f6e438ef84007153a599d092953382
Diffstat (limited to 'ripple/minitrace/src')
-rw-r--r--ripple/minitrace/src/main.rs51
1 files changed, 36 insertions, 15 deletions
diff --git a/ripple/minitrace/src/main.rs b/ripple/minitrace/src/main.rs
index 46773ee..cca16ec 100644
--- a/ripple/minitrace/src/main.rs
+++ b/ripple/minitrace/src/main.rs
@@ -130,11 +130,18 @@ macro_rules! syscall_bitflags {
 		$(
 			struct $BitFlags:ident: $T:ty {
 				$(
-					const $FLAG:ident = $value:expr;
+					const $FLAG:ident = $value:expr => $LIBC_FLAG:ident;
 				)*
 			}
 		)*
 	) => {
+		#[test]
+		fn verify_syscall_bitflags() {
+			$(
+				$BitFlags::verify();
+			)*
+		}
+
 		$(
 			bitflags! {
 				struct $BitFlags: $T {
@@ -144,6 +151,20 @@ macro_rules! syscall_bitflags {
 				}
 			}
 
+			impl $BitFlags {
+				#[cfg(test)]
+				fn verify() {
+					$(
+						let left = Self::$FLAG.bits();
+						let right = libc::$LIBC_FLAG;
+						assert!(
+							left == right,
+							"{}::{} ({left:#x}) != libc::{} ({right:#x})", stringify!($BitFlags), stringify!($FLAG), stringify!($LIBC_FLAG),
+						);
+					)*
+				}
+			}
+
 			impl SyscallArg for $BitFlags {
 				fn try_from_reg(reg: u64) -> Option<Self> {
 					SyscallArg::try_from_reg(reg).and_then(Self::from_bits)
@@ -457,28 +478,28 @@ fn check_syscall(process: &Process, entry: SyscallEntry) -> bool {
 
 syscall_bitflags! {
 	struct OpenFlags: i32 {
-		const WRONLY  = 0o00000001;
-		const CREAT   = 0o00000100;
-		const NOCTTY  = 0o00000400;
-		const TRUNC   = 0o00001000;
-		const CLOEXEC = 0o02000000;
+		const WRONLY  = 0o00000001 => O_WRONLY;
+		const CREAT   = 0o00000100 => O_CREAT;
+		const NOCTTY  = 0o00000400 => O_NOCTTY;
+		const TRUNC   = 0o00001000 => O_TRUNC;
+		const CLOEXEC = 0o02000000 => O_CLOEXEC;
 	}
 
 	struct GrndFlags: u32 {
-		const NONBLOCK = 1 << 0;
-		const RANDOM = 1 << 1;
+		const NONBLOCK = 1 << 0 => GRND_NONBLOCK;
+		const RANDOM   = 1 << 1 => GRND_RANDOM;
 	}
 
 	struct MapFlags: i32 {
-		const PRIVATE   = 1 << 1;
-		const FIXED     = 1 << 4;
-		const ANONYMOUS = 1 << 5;
-		const DENYWRITE = 1 << 11;
+		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;
-		const WRITE = 1 << 1;
-		const EXEC  = 1 << 2;
+		const READ  = 1 << 0 => PROT_READ;
+		const WRITE = 1 << 1 => PROT_WRITE;
+		const EXEC  = 1 << 2 => PROT_EXEC;
 	}
 }