feat(ebpf): Implement FromPtRegs for mips

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
pull/482/head
Dave Tucker 3 weeks ago
parent 3ff609114e
commit 1ccac3c135

@ -13,7 +13,7 @@ fn main() {
} }
println!("cargo:rustc-cfg=bpf_target_arch=\"{arch}\""); println!("cargo:rustc-cfg=bpf_target_arch=\"{arch}\"");
} }
println!("cargo::rustc-check-cfg=cfg(bpf_target_arch, values(\"x86_64\",\"arm\",\"aarch64\",\"riscv64\",\"powerpc64\",\"s390x\"))"); println!("cargo::rustc-check-cfg=cfg(bpf_target_arch, values(\"x86_64\",\"arm\",\"aarch64\",\"riscv64\",\"powerpc64\",\"s390x\",\"mips\"))");
println!("cargo::rustc-check-cfg=cfg(unstable)"); println!("cargo::rustc-check-cfg=cfg(unstable)");
} }

@ -1,7 +1,8 @@
#[cfg(any( #[cfg(any(
bpf_target_arch = "x86_64", bpf_target_arch = "x86_64",
bpf_target_arch = "arm", bpf_target_arch = "arm",
bpf_target_arch = "powerpc64" bpf_target_arch = "powerpc64",
bpf_target_arch = "mips",
))] ))]
use crate::bindings::pt_regs; use crate::bindings::pt_regs;
// aarch64 uses user_pt_regs instead of pt_regs // aarch64 uses user_pt_regs instead of pt_regs
@ -203,6 +204,22 @@ impl<T> FromPtRegs for *const T {
} }
} }
#[cfg(bpf_target_arch = "mips")]
impl<T> FromPtRegs for *const T {
fn from_argument(ctx: &pt_regs, n: usize) -> Option<Self> {
// Assume N64 ABI like libbpf does.
if n <= 7 {
unsafe { bpf_probe_read(&ctx.regs[n + 4]).map(|v| v as *const _).ok() }
} else {
None
}
}
fn from_retval(ctx: &pt_regs) -> Option<Self> {
unsafe { bpf_probe_read(&ctx.regs[31]).map(|v| v as *const _).ok() }
}
}
#[cfg(bpf_target_arch = "x86_64")] #[cfg(bpf_target_arch = "x86_64")]
impl<T> FromPtRegs for *mut T { impl<T> FromPtRegs for *mut T {
fn from_argument(ctx: &pt_regs, n: usize) -> Option<Self> { fn from_argument(ctx: &pt_regs, n: usize) -> Option<Self> {
@ -303,6 +320,22 @@ impl<T> FromPtRegs for *mut T {
} }
} }
#[cfg(bpf_target_arch = "mips")]
impl<T> FromPtRegs for *mut T {
fn from_argument(ctx: &pt_regs, n: usize) -> Option<Self> {
// Assume N64 ABI like libbpf does.
if n <= 7 {
unsafe { bpf_probe_read(&ctx.regs[n + 4]).map(|v| v as *mut _).ok() }
} else {
None
}
}
fn from_retval(ctx: &pt_regs) -> Option<Self> {
unsafe { bpf_probe_read(&ctx.regs[31]).map(|v| v as *mut _).ok() }
}
}
/// Helper macro to implement [`FromPtRegs`] for a primitive type. /// Helper macro to implement [`FromPtRegs`] for a primitive type.
macro_rules! impl_from_pt_regs { macro_rules! impl_from_pt_regs {
($type:ident) => { ($type:ident) => {
@ -405,6 +438,21 @@ macro_rules! impl_from_pt_regs {
Some(ctx.gprs[2] as *const $type as _) Some(ctx.gprs[2] as *const $type as _)
} }
} }
#[cfg(bpf_target_arch = "mips")]
impl FromPtRegs for $type {
fn from_argument(ctx: &pt_regs, n: usize) -> Option<Self> {
if n <= 7 {
Some(ctx.regs[n + 4] as *const $type as _)
} else {
None
}
}
fn from_retval(ctx: &pt_regs) -> Option<Self> {
Some(ctx.regs[31] as *const $type as _)
}
}
}; };
} }

@ -3,7 +3,8 @@ use core::ffi::c_void;
#[cfg(any( #[cfg(any(
bpf_target_arch = "x86_64", bpf_target_arch = "x86_64",
bpf_target_arch = "arm", bpf_target_arch = "arm",
bpf_target_arch = "powerpc64" bpf_target_arch = "powerpc64",
bpf_target_arch = "mips"
))] ))]
use crate::bindings::pt_regs; use crate::bindings::pt_regs;
// aarch64 uses user_pt_regs instead of pt_regs // aarch64 uses user_pt_regs instead of pt_regs

@ -3,7 +3,8 @@ use core::ffi::c_void;
#[cfg(any( #[cfg(any(
bpf_target_arch = "x86_64", bpf_target_arch = "x86_64",
bpf_target_arch = "arm", bpf_target_arch = "arm",
bpf_target_arch = "powerpc64" bpf_target_arch = "powerpc64",
bpf_target_arch = "mips"
))] ))]
use crate::bindings::pt_regs; use crate::bindings::pt_regs;
// aarch64 uses user_pt_regs instead of pt_regs // aarch64 uses user_pt_regs instead of pt_regs

Loading…
Cancel
Save