Skip to content

Commit

Permalink
add riscv support.
Browse files Browse the repository at this point in the history
  • Loading branch information
pdliyan committed Sep 28, 2023
1 parent 59e8098 commit f9861aa
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 23 deletions.
34 changes: 29 additions & 5 deletions bpf/aya-bpf/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ impl<T> FromPtRegs for *const T {

fn from_stack_argument(ctx: &pt_regs, n: usize) -> Option<Self> {
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)
.map(|v| &v as *const _)
.ok()
Expand All @@ -173,7 +175,7 @@ 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;
let addr: c_ulonglong = (ctx.sp + 8 * (n + 1) as u64) as c_ulonglong;
bpf_probe_read(addr as *const T)
.map(|v| &v as *const _)
.ok()
Expand Down Expand Up @@ -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> {
unsafe { bpf_probe_read(&ctx.ra).map(|v| v as *const _).ok() }
}
Expand Down Expand Up @@ -246,7 +257,9 @@ impl<T> FromPtRegs for *mut T {

fn from_stack_argument(ctx: &pt_regs, n: usize) -> Option<Self> {
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)
.map(|mut v| &mut v as *mut _)
.ok()
Expand All @@ -270,7 +283,7 @@ 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;
let addr: c_ulonglong = (ctx.sp + 8 * (n + 1) as u64) as c_ulonglong;
bpf_probe_read(addr as *mut T)
.map(|mut v| &mut v as *mut _)
.ok()
Expand Down Expand Up @@ -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> {
unsafe { bpf_probe_read(&ctx.ra).map(|v| v as *mut _).ok() }
}
Expand Down Expand Up @@ -346,7 +368,9 @@ macro_rules! impl_from_pt_regs {

fn from_stack_argument(ctx: &pt_regs, n: usize) -> Option<Self> {
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)
.map(|v| v as $type)
.ok()
Expand Down
10 changes: 5 additions & 5 deletions test/integration-ebpf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ path = "src/name_test.rs"
name = "pass"
path = "src/pass.rs"

[[bin]]
name = "stack_argument"
path = "src/stack_argument.rs"

[[bin]]
name = "test"
path = "src/test.rs"
Expand All @@ -50,8 +54,4 @@ path = "src/redirect.rs"

[[bin]]
name = "xdp_sec"
path = "src/xdp_sec.rs"

[[bin]]
name = "stack_argument"
path = "src/stack_argument.rs"
path = "src/xdp_sec.rs"
14 changes: 1 addition & 13 deletions test/integration-test/src/tests/stack_argument.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
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;
use aya::{maps::HashMap, programs::UProbe, Bpf};

#[no_mangle]
#[inline(never)]
Expand All @@ -33,7 +22,6 @@ pub extern "C" fn trigger_stack_argument(

#[tokio::test]
async fn stack_argument() {
event_logger::init();
let mut bpf = Bpf::load(crate::STACK_ARGUMENT).unwrap();

let prog: &mut UProbe = bpf
Expand Down

0 comments on commit f9861aa

Please sign in to comment.