syscall_intercept/lib.rs
1#[link(name = "syscall_intercept")]
2extern "C" {
3 static mut intercept_hook_point: Option<HookFn>;
4
5 pub fn syscall_no_intercept(num: isize, ...) -> isize;
6}
7
8/// Set syscall intercept hook function.
9///
10/// # Safety
11///
12/// This function will change all syscall behavior!
13pub unsafe fn set_hook_fn(f: HookFn) {
14 intercept_hook_point = Some(f);
15}
16
17/// Clear syscall intercept hook function.
18///
19/// # Safety
20///
21/// This function will change all syscall behavior!
22pub unsafe fn unset_hook_fn() {
23 intercept_hook_point = None;
24}
25
26/// The type of hook function.
27pub type HookFn = extern "C" fn(
28 num: isize,
29 a0: isize,
30 a1: isize,
31 a2: isize,
32 a3: isize,
33 a4: isize,
34 a5: isize,
35 result: &mut isize,
36) -> InterceptResult;
37
38/// The return value of hook function.
39#[repr(i32)]
40pub enum InterceptResult {
41 /// The user takes over the system call. The return value should be set via `result`.
42 Hook = 0,
43 /// The specific system call was ignored by the user and the original syscall should be executed.
44 Forward = 1,
45}