Skip to content

Harpoon port #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 20 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
3e99962
rex: modify task_struct's get_comm
MinhPhan8803 Mar 14, 2025
cc95b6a
rex: add perf_array_map helper symbols
MinhPhan8803 Mar 19, 2025
7815e04
rex-macros: add macro for uprobe
MinhPhan8803 Mar 19, 2025
e3d3321
rex: add PerfEventArray and StreamableProgram trait
MinhPhan8803 Mar 19, 2025
08922c6
samples: initial code for harpoon port
MinhPhan8803 Mar 19, 2025
db4b053
Merge branch 'main' into harpoon_port
MinhPhan8803 Mar 19, 2025
9fa66c7
rex: fix event output symbols in stub
MinhPhan8803 Mar 19, 2025
e91f541
rex: implement StreamableProgram for tracepoint
MinhPhan8803 Mar 22, 2025
a659c1e
Merge branch 'main' into harpoon_port
MinhPhan8803 Mar 22, 2025
3fe9cb1
rex/src/utils.rs: update PerfEventMaskedCPU method names
MinhPhan8803 Mar 22, 2025
abdc31d
rex: fix type issues in StreamableProgram implementation
MinhPhan8803 Mar 22, 2025
046d284
Merge branch 'main' into harpoon_port
MinhPhan8803 Mar 22, 2025
182bf51
rex: cast c_char to u8 in TaskStruct::get_comm()
MinhPhan8803 Mar 23, 2025
70e86aa
Merge branch 'main' into harpoon_port
MinhPhan8803 Mar 30, 2025
30f8795
rex: cleanup: hide BPF_F_CURRENT_CPU, remove ProgramContextPair, add …
MinhPhan8803 Mar 30, 2025
6d23109
rex: add RawSyscallsEnter tracepoint variant, complete harpoon kernel…
MinhPhan8803 Apr 4, 2025
d9321a4
Merge branch 'main' into harpoon_port
MinhPhan8803 Apr 13, 2025
b6bcc6c
rex: change stub to ffi
MinhPhan8803 Apr 14, 2025
bf10a1a
Merge branch 'main' into harpoon_port
MinhPhan8803 Apr 24, 2025
6590fae
rex: clean up tracepoint and map impls
MinhPhan8803 Apr 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 7 additions & 18 deletions rex/src/task_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::bindings::uapi::linux::errno::EINVAL;
use crate::per_cpu::{current_task, this_cpu_read};
use crate::pt_regs::PtRegs;
use crate::stub;
use core::ffi::{self, CStr};

// Bindgen has problem generating these constants
const TOP_OF_KERNEL_STACK_PADDING: u64 = 0;
Expand Down Expand Up @@ -44,27 +45,15 @@ impl TaskStruct {
self.kptr.tgid
}

// Design decision: the original BPF interface does not have type safety,
// since buf is just a buffer. But in Rust we can use const generics to
// restrict it to only [u8; N] given that comm is a cstring. This also
// automatically achieves size check, since N is a constexpr.
pub fn get_comm<const N: usize>(&self, buf: &mut [i8; N]) -> i32 {
if N == 0 {
return -(EINVAL as i32);
}

let size = core::cmp::min::<usize>(N, self.kptr.comm.len()) - 1;
if size == 0 {
return -(EINVAL as i32);
}

buf[..size].copy_from_slice(&self.kptr.comm[..size]);
buf[size] = 0;
0
// Design decision: the equivalent BPF helper writes the program name to
// a user-provided buffer, here we can take advantage of Rust's ownership by
// just providing a reference to the CString instead
pub fn get_comm(&self) -> Result<&CStr, ffi::FromBytesUntilNulError> {
CStr::from_bytes_until_nul(&self.kptr.comm)
}

pub fn get_pt_regs(&self) -> &'static PtRegs {
// X86 sepcific
// X86 specific
// stack_top is actually bottom of the kernel stack, it refers to the
// highest address of the stack pages
let stack_top =
Expand Down