add riscv support.

pull/773/head
pdliyan 2 years ago
parent 59e8098d94
commit f9861aa8cd

@ -149,7 +149,9 @@ impl<T> FromPtRegs for *const T {
fn from_stack_argument(ctx: &pt_regs, n: usize) -> Option<Self> { fn from_stack_argument(ctx: &pt_regs, n: usize) -> Option<Self> {
unsafe { unsafe {
let addr: c_ulonglong = ctx.uregs[13] + 8 * (n + 1) as c_ulonglong; let addr: c_ulonglong = (ctx.uregs[13] + 8 * (n + 1) as c_ulonglong)
.try_into()
.unwrap();
bpf_probe_read(addr as *const T) bpf_probe_read(addr as *const T)
.map(|v| &v as *const _) .map(|v| &v as *const _)
.ok() .ok()
@ -173,7 +175,7 @@ impl<T> FromPtRegs for *const T {
fn from_stack_argument(ctx: &pt_regs, n: usize) -> Option<Self> { fn from_stack_argument(ctx: &pt_regs, n: usize) -> Option<Self> {
unsafe { unsafe {
let addr: c_ulonglong = ctx.sp + 8 * (n + 1) as c_ulonglong; let addr: c_ulonglong = (ctx.sp + 8 * (n + 1) as u64) as c_ulonglong;
bpf_probe_read(addr as *const T) bpf_probe_read(addr as *const T)
.map(|v| &v as *const _) .map(|v| &v as *const _)
.ok() .ok()
@ -201,6 +203,15 @@ impl<T> FromPtRegs for *const T {
} }
} }
fn from_stack_argument(ctx: &pt_regs, n: usize) -> Option<Self> {
unsafe {
let addr: c_ulonglong = ctx.sp + 8 * (n + 1) as c_ulonglong;
bpf_probe_read(addr as *const T)
.map(|v| &v as *const _)
.ok()
}
}
fn from_retval(ctx: &pt_regs) -> Option<Self> { fn from_retval(ctx: &pt_regs) -> Option<Self> {
unsafe { bpf_probe_read(&ctx.ra).map(|v| v as *const _).ok() } unsafe { bpf_probe_read(&ctx.ra).map(|v| v as *const _).ok() }
} }
@ -246,7 +257,9 @@ impl<T> FromPtRegs for *mut T {
fn from_stack_argument(ctx: &pt_regs, n: usize) -> Option<Self> { fn from_stack_argument(ctx: &pt_regs, n: usize) -> Option<Self> {
unsafe { unsafe {
let addr: c_ulonglong = ctx.uregs[13] + 8 * (n + 1) as c_ulonglong; let addr: c_ulonglong = (ctx.uregs[13] + 8 * (n + 1) as c_ulonglong)
.try_into()
.unwrap();
bpf_probe_read(addr as *mut T) bpf_probe_read(addr as *mut T)
.map(|mut v| &mut v as *mut _) .map(|mut v| &mut v as *mut _)
.ok() .ok()
@ -270,7 +283,7 @@ impl<T> FromPtRegs for *mut T {
fn from_stack_argument(ctx: &pt_regs, n: usize) -> Option<Self> { fn from_stack_argument(ctx: &pt_regs, n: usize) -> Option<Self> {
unsafe { unsafe {
let addr: c_ulonglong = ctx.sp + 8 * (n + 1) as c_ulonglong; let addr: c_ulonglong = (ctx.sp + 8 * (n + 1) as u64) as c_ulonglong;
bpf_probe_read(addr as *mut T) bpf_probe_read(addr as *mut T)
.map(|mut v| &mut v as *mut _) .map(|mut v| &mut v as *mut _)
.ok() .ok()
@ -298,6 +311,15 @@ impl<T> FromPtRegs for *mut T {
} }
} }
fn from_stack_argument(ctx: &pt_regs, n: usize) -> Option<Self> {
unsafe {
let addr: c_ulonglong = ctx.sp + 8 * (n + 1) as c_ulonglong;
bpf_probe_read(addr as *mut T)
.map(|mut v| &mut v as *mut _)
.ok()
}
}
fn from_retval(ctx: &pt_regs) -> Option<Self> { fn from_retval(ctx: &pt_regs) -> Option<Self> {
unsafe { bpf_probe_read(&ctx.ra).map(|v| v as *mut _).ok() } unsafe { bpf_probe_read(&ctx.ra).map(|v| v as *mut _).ok() }
} }
@ -346,7 +368,9 @@ macro_rules! impl_from_pt_regs {
fn from_stack_argument(ctx: &pt_regs, n: usize) -> Option<Self> { fn from_stack_argument(ctx: &pt_regs, n: usize) -> Option<Self> {
unsafe { unsafe {
let addr: c_ulonglong = ctx.uregs[13] + 8 * (n + 1) as c_ulonglong; let addr: c_ulonglong = (ctx.uregs[13] + 8 * (n + 1) as c_ulonglong)
.try_into()
.unwrap();
bpf_probe_read(addr as *const $type) bpf_probe_read(addr as *const $type)
.map(|v| v as $type) .map(|v| v as $type)
.ok() .ok()

@ -28,6 +28,10 @@ path = "src/name_test.rs"
name = "pass" name = "pass"
path = "src/pass.rs" path = "src/pass.rs"
[[bin]]
name = "stack_argument"
path = "src/stack_argument.rs"
[[bin]] [[bin]]
name = "test" name = "test"
path = "src/test.rs" path = "src/test.rs"
@ -51,7 +55,3 @@ path = "src/redirect.rs"
[[bin]] [[bin]]
name = "xdp_sec" name = "xdp_sec"
path = "src/xdp_sec.rs" path = "src/xdp_sec.rs"
[[bin]]
name = "stack_argument"
path = "src/stack_argument.rs"

@ -1,15 +1,4 @@
use aya::{ use aya::{maps::HashMap, programs::UProbe, Bpf};
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] #[no_mangle]
#[inline(never)] #[inline(never)]
@ -33,7 +22,6 @@ pub extern "C" fn trigger_stack_argument(
#[tokio::test] #[tokio::test]
async fn stack_argument() { async fn stack_argument() {
event_logger::init();
let mut bpf = Bpf::load(crate::STACK_ARGUMENT).unwrap(); let mut bpf = Bpf::load(crate::STACK_ARGUMENT).unwrap();
let prog: &mut UProbe = bpf let prog: &mut UProbe = bpf

Loading…
Cancel
Save