Skip to content

Commit 6d23109

Browse files
committed
rex: add RawSyscallsEnter tracepoint variant, complete harpoon kernel app
Signed-off-by: MinhPhan8803 <[email protected]>
1 parent 30f8795 commit 6d23109

File tree

5 files changed

+33
-3
lines changed

5 files changed

+33
-3
lines changed

rex-macros/src/tracepoint.rs

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ impl TracePoint {
5656
"Void" => quote!(tp_type::Void),
5757
"SyscallsEnterOpen" => quote!(tp_type::SyscallsExitOpen),
5858
"SyscallsExitOpen" => quote!(tp_type::SyscallsExitOpen),
59+
"RawSyscallsEnter" => quote! {tp_type::RawSyscallsEnter},
5960
_ => panic!("Please provide valid tp_type"),
6061
};
6162

rex/src/tracepoint/binding.rs

+8
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,11 @@ pub struct SyscallsExitOpenArgs {
1515
pub syscall_nr: i64,
1616
pub ret: i64,
1717
}
18+
19+
#[repr(C)]
20+
#[derive(Debug, Copy, Clone)]
21+
pub struct RawSyscallsEnterArgs {
22+
pub unused: u64,
23+
pub id: i64,
24+
pub args: [u64; 6],
25+
}

rex/src/tracepoint/tp_impl.rs

+8
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ pub enum tp_type {
1414
Void,
1515
SyscallsEnterOpen,
1616
SyscallsExitOpen,
17+
RawSyscallsEnter,
1718
}
1819
pub enum tp_ctx {
1920
Void,
2021
SyscallsEnterOpen(&'static SyscallsEnterOpenArgs),
2122
SyscallsExitOpen(&'static SyscallsExitOpenArgs),
23+
RawSyscallsEnter(&'static RawSyscallsEnterArgs),
2224
}
2325

2426
impl tp_ctx {
@@ -31,6 +33,9 @@ impl tp_ctx {
3133
tp_ctx::SyscallsExitOpen(args) => {
3234
*args as *const SyscallsExitOpenArgs as *const ()
3335
}
36+
tp_ctx::RawSyscallsEnter(args) => {
37+
*args as *const RawSyscallsEnterArgs as *const ()
38+
}
3439
}
3540
}
3641
}
@@ -77,6 +82,9 @@ impl tracepoint {
7782
tp_type::SyscallsExitOpen => tp_ctx::SyscallsExitOpen(unsafe {
7883
&*(ctx as *mut SyscallsExitOpenArgs)
7984
}),
85+
tp_type::RawSyscallsEnter => tp_ctx::RawSyscallsEnter(unsafe {
86+
&*(ctx as *mut RawSyscallsEnterArgs)
87+
}),
8088
}
8189
}
8290

rex/src/utils.rs

+1
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ pub trait StreamableProgram {
279279
/// newtype for a cpu for perf event output to ensure
280280
/// type safety since the cpu must be masked
281281
/// with BPF_F_INDEX_MASK
282+
#[derive(Debug, Copy, Clone)]
282283
pub struct PerfEventMaskedCPU {
283284
pub(crate) masked_cpu: u64,
284285
}

samples/harpoon/src/main.rs

+15-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use rex::tracepoint::*;
1010
use rex::kprobe::kprobe;
1111
use rex::map::{RexArrayMap, RexHashMap, RexPerfEventArray};
1212
use rex::pt_regs::PtRegs;
13+
use rex::utils::PerfEventMaskedCPU;
1314
use core::ffi::CStr;
1415

1516
#[repr(C)]
@@ -21,7 +22,7 @@ struct Config {
2122
#[repr(C)]
2223
#[derive(Clone, Copy, core::Default)]
2324
struct SyscallData {
24-
id: u32,
25+
id: i64,
2526
}
2627

2728
#[repr(C)]
@@ -55,8 +56,8 @@ fn exit_function(obj: &kprobe, ctx: &mut PtRegs) -> Result {
5556
bpf_printk!(obj, c"Exit function.\n");
5657
}
5758

58-
#[rex_tracepoint(name = "syscalls/sys_enter_dup", tp_type = "Void")]
59-
fn rex_prog1(obj: &tracepoint, _: tp_ctx) -> Result {
59+
#[rex_tracepoint(name = "raw_syscalls/sys_enter", tp_type = "RawSyscallsEnter")]
60+
fn rex_prog1(obj: &tracepoint, ctx: tp_ctx) -> Result {
6061
let mut data = SyscallData::new();
6162
let key_config = 0;
6263
let key_trace = 0;
@@ -95,5 +96,16 @@ fn rex_prog1(obj: &tracepoint, _: tp_ctx) -> Result {
9596
return Err(1);
9697
}
9798

99+
let id = match ctx {
100+
RawSyscallsEnter(args) => args.id,
101+
_ => 0,
102+
};
103+
104+
data.id = id;
105+
106+
EVENTS.output(obj, ctx, data, PerfEventMaskedCPU::current_cpu());
107+
108+
bpf_printk!(obj, c"Sending syscall id %llu.\n", id as u64);
109+
98110
Ok(0)
99111
}

0 commit comments

Comments
 (0)