mirror of
https://github.com/joleuger/vuinputd.git
synced 2026-07-18 00:45:07 +00:00
Started to write code to detect if the calling process is 32bit or not.
This commit is contained in:
parent
4efc3b206e
commit
2192432915
2 changed files with 45 additions and 3 deletions
|
|
@ -97,7 +97,9 @@ static VUINPUT_COUNTER: OnceLock<AtomicU64> = OnceLock::new();
|
|||
static VUINPUT_STATE: OnceLock<RwLock<HashMap<VuFileHandle, Arc<Mutex<VuInputState>>>>> = OnceLock::new();
|
||||
static JOB_DISPATCHER: OnceLock<Mutex<Dispatcher>>= OnceLock::new();
|
||||
static SELF_NAMESPACES: OnceLock<Namespaces>= OnceLock::new();
|
||||
static DEDUP_LAST_ERROR: OnceLock<Mutex<Option<(u64,VuError)>>> = OnceLock::new();
|
||||
|
||||
// For log limiting. Idea: Move to log_limit crate
|
||||
static DEDUP_LAST_ERROR: OnceLock<Mutex<Option<(u64,VuError)>>> = 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,
|
||||
|
|
|
|||
|
|
@ -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<bool> {
|
||||
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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue