-
Notifications
You must be signed in to change notification settings - Fork 298
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
Add support for stack argument #773
Changes from 13 commits
9c167c7
454bf0d
f00ddb6
08d038c
d8f7675
24cc238
e807cb7
a2201e6
7060235
b3b8d44
5ed278a
b249789
31fb700
5812252
59e8098
f9861aa
da29228
c627cde
0347dae
21f63e0
b8c43a0
dd4ee87
5fc269e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
edition = "2021" | ||
unstable_features = true | ||
reorder_imports = true | ||
imports_granularity = "Crate" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#![no_std] | ||
#![no_main] | ||
|
||
use aya_bpf::{ | ||
macros::{map, uprobe}, | ||
maps::HashMap, | ||
programs::ProbeContext, | ||
}; | ||
|
||
#[map] | ||
static ARGS: HashMap<u32, u64> = HashMap::with_max_entries(24, 0); | ||
|
||
#[uprobe] | ||
pub fn test_stack_argument(ctx: ProbeContext) -> i32 { | ||
match try_stack_argument(ctx) { | ||
Ok(ret) => ret, | ||
Err(_) => 0, | ||
} | ||
} | ||
|
||
//read argument, and send event | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what event? I don't understand this comment. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. comment modified. |
||
fn try_stack_argument(ctx: ProbeContext) -> Result<i32, i64> { | ||
let _ = ARGS.insert(&0, &ctx.arg(0).ok_or(255)?, 0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we avoid these There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There would be warning if no
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, the proper thing to do is handle these errors rather than silently ignore them. You probably want to return from the program on any error. |
||
let _ = ARGS.insert(&1, &ctx.arg(1).ok_or(255)?, 0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's the story with these .ok_or(255)? I don't understand why this function returns a Result where the only possible "error" is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no means for 255, just to make sure the test in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand, but I do not think this is an appropriate thing to do. If these methods fail, we should just return from this program. |
||
let _ = ARGS.insert(&2, &ctx.arg(2).ok_or(255)?, 0); | ||
let _ = ARGS.insert(&3, &ctx.arg(3).ok_or(255)?, 0); | ||
let _ = ARGS.insert(&4, &ctx.arg(4).ok_or(255)?, 0); | ||
let _ = ARGS.insert(&5, &ctx.arg(5).ok_or(255)?, 0); | ||
let _ = ARGS.insert(&6, &ctx.stack_arg(0).ok_or(255)?, 0); | ||
let _ = ARGS.insert(&7, &ctx.stack_arg(1).ok_or(255)?, 0); | ||
|
||
Ok(0) | ||
} | ||
|
||
#[cfg(not(test))] | ||
#[panic_handler] | ||
fn panic(_info: &core::panic::PanicInfo) -> ! { | ||
loop {} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ assert_matches = { workspace = true } | |
aya = { workspace = true } | ||
aya-log = { workspace = true } | ||
aya-obj = { workspace = true } | ||
bytes = { workspace = true } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is this? |
||
libc = { workspace = true } | ||
log = { workspace = true } | ||
netns-rs = { workspace = true } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,5 @@ mod log; | |
mod rbpf; | ||
mod relocations; | ||
mod smoke; | ||
mod stack_argument; | ||
mod xdp; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use aya::{ | ||
include_bytes_aligned, | ||
maps::{AsyncPerfEventArray, HashMap}, | ||
programs::UProbe, | ||
util::online_cpus, | ||
Bpf, | ||
}; | ||
use aya_log::BpfLogger; | ||
use bytes::BytesMut; | ||
use log::warn; | ||
|
||
use crate::STACK_ARGUMENT; | ||
|
||
#[no_mangle] | ||
#[inline(never)] | ||
pub extern "C" fn trigger_stack_argument( | ||
a_0: u64, | ||
a_1: u64, | ||
a_2: u64, | ||
a_3: u64, | ||
a_4: u64, | ||
a_5: u64, | ||
//in x86_64, from arg6, stack_argument would be used | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please write a proper sentence and add a space after the can you add a citation? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. citation added. |
||
a_6: u64, | ||
a_7: i64, | ||
) { | ||
} | ||
|
||
#[tokio::test] | ||
async fn stack_argument() { | ||
event_logger::init(); | ||
let mut bpf = Bpf::load(crate::STACK_ARGUMENT).unwrap(); | ||
|
||
let prog: &mut UProbe = bpf | ||
.program_mut("test_stack_argument") | ||
.unwrap() | ||
.try_into() | ||
.unwrap(); | ||
prog.load().unwrap(); | ||
prog.attach(Some("trigger_stack_argument"), 0, "/proc/self/exe", None) | ||
.unwrap(); | ||
let mut args_map: HashMap<_, u32, u64> = | ||
HashMap::try_from(bpf.take_map("ARGS").unwrap()).unwrap(); | ||
trigger_stack_argument(0, 1, 2, 3, 4, 5, 6, 7); | ||
|
||
tokio::time::sleep(std::time::Duration::from_millis(100)).await; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why are we sleeping here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The sleeping could be removed, and it works okay in my local environment. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed. |
||
assert_eq!(args_map.keys().count(), 8); | ||
for iter in args_map.iter() { | ||
let iter_v = iter.unwrap(); | ||
assert_eq!(iter_v.0 as u64, iter_v.1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please destructure instead of these point accesses. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure about this. Any problems with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed.