-
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 all 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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#![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 { | ||
try_stack_argument(ctx).unwrap_or(0) | ||
} | ||
|
||
// read function arguments, and set to map. | ||
fn try_stack_argument(ctx: ProbeContext) -> Result<i32, i64> { | ||
let mut stack = false; | ||
let mut arg = 0; | ||
loop { | ||
if arg > 7 { | ||
break; | ||
} | ||
if stack { | ||
let _ = ARGS.insert(&arg, &ctx.arg(arg as usize).ok_or(255)?, 0); | ||
} else { | ||
let arg_v: Option<u64> = ctx.arg(arg as usize); | ||
if arg_v.is_none() { | ||
// assume that we shall read from stack now. | ||
stack = true; | ||
continue; | ||
} | ||
let _ = ARGS.insert(&arg, &arg_v.ok_or(255)?, 0); | ||
} | ||
arg += 1; | ||
} | ||
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; |
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.
shouldn't this be stack_arg?