From 0682ee981a40ee3c549e5a8d62ffd8c6c542ed69 Mon Sep 17 00:00:00 2001 From: edef Date: Sat, 30 Jul 2022 19:56:58 +0000 Subject: ripple/minitrace/syscall_abi: represent prlimit64 pid with a unit struct We don't accept nonzero values here, so we should simply reject those early. Change-Id: I329ae76b1f44f6d3305e710ed8f5f90ee0df988f --- ripple/minitrace/src/syscall_abi/mod.rs | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'ripple/minitrace/src/syscall_abi') diff --git a/ripple/minitrace/src/syscall_abi/mod.rs b/ripple/minitrace/src/syscall_abi/mod.rs index c274d0b..e050711 100644 --- a/ripple/minitrace/src/syscall_abi/mod.rs +++ b/ripple/minitrace/src/syscall_abi/mod.rs @@ -4,7 +4,10 @@ use { crate::{define_syscalls, syscall_bitflags, syscall_enums, Process}, - std::ffi::CString, + std::{ + ffi::CString, + fmt::{self, Debug, Write}, + }, }; pub(crate) use arg::{ProcessSyscallArg, SyscallArg}; @@ -43,7 +46,7 @@ define_syscalls! { 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: RobustListHeadSize) -> i64 = 273; - fn prlimit64(pid: i32, resource: ResourceLimit, new_rlim: *const RLimit64, old_rlim: *mut RLimit64) -> i64 = 302; + fn prlimit64(pid: Zero, resource: ResourceLimit, new_rlim: *const RLimit64, old_rlim: *mut RLimit64) -> i64 = 302; fn getrandom(ubuf: *mut u8, len: usize, flags: GrndFlags) -> i64 = 318; } } @@ -126,6 +129,25 @@ syscall_enums! { } } +#[derive(Copy, Clone)] +pub(crate) struct Zero; + +impl Debug for Zero { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.write_char('0') + } +} + +impl SyscallArg for Zero { + fn try_from_reg(reg: u64) -> Option { + if reg == 0 { + Some(Zero) + } else { + None + } + } +} + #[derive(Debug, Copy, Clone)] pub(crate) struct SigSetSize; -- cgit 1.4.1