Skip to content

Commit 7eecd9e

Browse files
committed
intercept SYS_statx on Linux
1 parent a6ce21b commit 7eecd9e

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
use std::ffi::c_long;
2+
3+
use fspy_shared::ipc::AccessMode;
4+
5+
use crate::{
6+
client::{convert::PathAt, handle_open},
7+
macros::intercept,
8+
};
9+
10+
intercept!(syscall(64): unsafe extern "C" fn(c_long, args: ...) -> c_long);
11+
unsafe extern "C" fn syscall(syscall_no: c_long, mut args: ...) -> c_long {
12+
// https://github.com/bminor/glibc/blob/efc8642051e6c4fe5165e8986c1338ba2c180de6/sysdeps/unix/sysv/linux/syscall.c#L23
13+
let a0 = unsafe { args.arg::<c_long>() };
14+
let a1 = unsafe { args.arg::<c_long>() };
15+
let a2 = unsafe { args.arg::<c_long>() };
16+
let a3 = unsafe { args.arg::<c_long>() };
17+
let a4 = unsafe { args.arg::<c_long>() };
18+
let a5 = unsafe { args.arg::<c_long>() };
19+
20+
match syscall_no {
21+
libc::SYS_statx => {
22+
if let Ok(dirfd) = i32::try_from(a0) {
23+
let pathname = a1 as *const u8;
24+
unsafe {
25+
handle_open(PathAt(dirfd, pathname), AccessMode::Read);
26+
}
27+
}
28+
}
29+
_ => {}
30+
}
31+
unsafe { syscall::original()(syscall_no, a0, a1, a2, a3, a4, a5) }
32+
}

crates/fspy_preload_unix/src/interceptions/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ mod dirent;
33
mod open;
44
mod spawn;
55
mod stat;
6+
7+
#[cfg(target_os = "linux")]
8+
mod linux_syscall;

0 commit comments

Comments
 (0)