diff --git a/vuinputd/src/main.rs b/vuinputd/src/main.rs index eb10c35..853d477 100644 --- a/vuinputd/src/main.rs +++ b/vuinputd/src/main.rs @@ -97,7 +97,9 @@ static VUINPUT_COUNTER: OnceLock = OnceLock::new(); static VUINPUT_STATE: OnceLock>>>> = OnceLock::new(); static JOB_DISPATCHER: OnceLock>= OnceLock::new(); static SELF_NAMESPACES: OnceLock= OnceLock::new(); -static DEDUP_LAST_ERROR: OnceLock>> = OnceLock::new(); + +// For log limiting. Idea: Move to log_limit crate +static DEDUP_LAST_ERROR: OnceLock>> = OnceLock::new(); const SYS_INPUT_DIR: &str = "/sys/devices/virtual/input/"; @@ -221,6 +223,9 @@ unsafe extern "C" fn vuinput_open( } } } + + +// TODO: compat-mode+ ensure sizeof(struct input_event) unsafe extern "C" fn vuinput_write( _req: fuse_lowlevel::fuse_req_t, _buf: *const c_char, diff --git a/vuinputd/src/namespace.rs b/vuinputd/src/namespace.rs index 989348c..4bee9eb 100644 --- a/vuinputd/src/namespace.rs +++ b/vuinputd/src/namespace.rs @@ -8,8 +8,7 @@ use nix::{ unistd::{fork, ForkResult}, }; use std::{ - fs::{self, File}, - os::fd::AsFd, path::{self, Path}, process, thread, time::Duration, + fs::{self, File}, io::Read, os::fd::AsFd, path::{self, Path}, process, thread, time::Duration }; use std::io::{self, BufRead}; @@ -46,6 +45,44 @@ struct NamespaceInodes { } +// this is static for the architecture +fn compat_uses_64bit_time() -> bool { + let uname = nix::sys::utsname::uname().unwrap(); + let arch = uname.machine().to_str().unwrap(); + + match arch { + "x86_64" => false, + "ppc64" => false, // some setups still 32-bit time_t + _ => true, // arm64, riscv64, s390x all use 64-bit + } +} + +/// Returns true if the process with `pid` is a 32-bit (compat) process. None, if unsure. +pub fn is_compat_process(pid: i32) -> Option { + const EI_CLASS: usize = 4; + const ELFCLASS32: u8 = 1; + const ELFCLASS64: u8 = 2; + + let exe_path = format!("/proc/{}/exe", pid); + let mut buf = [0u8; 5]; + + match File::open(&exe_path).and_then(|mut f| f.read_exact(&mut buf)) { + Ok(()) => { + // ELF magic check + if &buf[0..4] != b"\x7FELF" { + return None; + } + match buf[EI_CLASS] { + ELFCLASS32 => Some(true), + ELFCLASS64 => Some(false), + _ => None, + } + } + Err(_) => None, + } +} + +// TODO: Rename to capture all relevant process information #[derive(Debug, Default, Clone, Eq, PartialEq, Hash)] pub struct Namespaces { pub nspath: String,