// SPDX-FileCopyrightText: edef // SPDX-License-Identifier: OSL-3.0 use {crate::Process, std::ffi::CString}; pub(crate) trait ProcessSyscallArg: Sized { fn try_from_process_reg(process: &Process, reg: u64) -> Option; } impl ProcessSyscallArg for CString { fn try_from_process_reg(process: &Process, reg: u64) -> Option { process.read_mem_cstr(reg).ok() } } impl ProcessSyscallArg for T { fn try_from_process_reg(_process: &Process, reg: u64) -> Option { SyscallArg::try_from_reg(reg) } } pub(crate) trait SyscallArg: Sized { fn try_from_reg(reg: u64) -> Option; } impl SyscallArg for u16 { fn try_from_reg(reg: u64) -> Option { reg.try_into().ok() } } impl SyscallArg for u32 { fn try_from_reg(reg: u64) -> Option { reg.try_into().ok() } } impl SyscallArg for u64 { fn try_from_reg(reg: u64) -> Option { Some(reg) } } impl SyscallArg for i32 { fn try_from_reg(reg: u64) -> Option { Some(u32::try_from(reg).ok()? as i32) } } impl SyscallArg for *mut i32 { fn try_from_reg(reg: u64) -> Option { Some(usize::try_from_reg(reg)? as *mut i32) } } impl SyscallArg for usize { fn try_from_reg(reg: u64) -> Option { reg.try_into().ok() } } impl SyscallArg for *const u8 { fn try_from_reg(reg: u64) -> Option { Some(usize::try_from_reg(reg)? as *const u8) } } impl SyscallArg for *mut u8 { fn try_from_reg(reg: u64) -> Option { Some(usize::try_from_reg(reg)? as *mut u8) } } impl SyscallArg for *mut () { fn try_from_reg(reg: u64) -> Option { Some(usize::try_from_reg(reg)? as *mut ()) } } impl SyscallArg for *const () { fn try_from_reg(reg: u64) -> Option { Some(usize::try_from_reg(reg)? as *const ()) } }