diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5a016be8..f6b2a8cb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -81,6 +81,7 @@ jobs: arch: - aarch64-unknown-linux-gnu - armv7-unknown-linux-gnueabi + - loongarch64-unknown-linux-gnu - powerpc64le-unknown-linux-gnu - riscv64gc-unknown-linux-gnu - s390x-unknown-linux-gnu @@ -149,6 +150,7 @@ jobs: bpf_target_arch: - aarch64 - arm + - loongarch64 - mips - powerpc64 - riscv64 diff --git a/ebpf/aya-ebpf/src/args.rs b/ebpf/aya-ebpf/src/args.rs index a996cee7..c67be51c 100644 --- a/ebpf/aya-ebpf/src/args.rs +++ b/ebpf/aya-ebpf/src/args.rs @@ -162,6 +162,21 @@ impl FromPtRegs for *const T { } } +#[cfg(bpf_target_arch = "loongarch64")] +impl FromPtRegs for *const T { + fn from_argument(ctx: &pt_regs, n: usize) -> Option { + if n <= 7 { + unsafe { bpf_probe_read(&ctx.regs[4 + n]).map(|v| v as *const _).ok() } + } else { + None + } + } + + fn from_retval(ctx: &pt_regs) -> Option { + unsafe { bpf_probe_read(&ctx.regs[4]).map(|v| v as *const _).ok() } + } +} + #[cfg(bpf_target_arch = "riscv64")] impl FromPtRegs for *const T { fn from_argument(ctx: &pt_regs, n: usize) -> Option { @@ -278,6 +293,21 @@ impl FromPtRegs for *mut T { } } +#[cfg(bpf_target_arch = "loongarch64")] +impl FromPtRegs for *mut T { + fn from_argument(ctx: &pt_regs, n: usize) -> Option { + if n <= 7 { + unsafe { bpf_probe_read(&ctx.regs[4 + n]).map(|v| v as *mut _).ok() } + } else { + None + } + } + + fn from_retval(ctx: &pt_regs) -> Option { + unsafe { bpf_probe_read(&ctx.regs[4]).map(|v| v as *mut _).ok() } + } +} + #[cfg(bpf_target_arch = "riscv64")] impl FromPtRegs for *mut T { fn from_argument(ctx: &pt_regs, n: usize) -> Option { @@ -397,6 +427,21 @@ macro_rules! impl_from_pt_regs { } } + #[cfg(bpf_target_arch = "loongarch64")] + impl FromPtRegs for $type { + fn from_argument(ctx: &pt_regs, n: usize) -> Option { + if n <= 7 { + Some(ctx.regs[4 + n] as *const $type as _) + } else { + None + } + } + + fn from_retval(ctx: &pt_regs) -> Option { + Some(ctx.regs[4] as *const $type as _) + } + } + #[cfg(bpf_target_arch = "riscv64")] impl FromPtRegs for $type { fn from_argument(ctx: &pt_regs, n: usize) -> Option { diff --git a/ebpf/aya-ebpf/src/programs/probe.rs b/ebpf/aya-ebpf/src/programs/probe.rs index 2819c80c..461164fd 100644 --- a/ebpf/aya-ebpf/src/programs/probe.rs +++ b/ebpf/aya-ebpf/src/programs/probe.rs @@ -7,10 +7,12 @@ use core::ffi::c_void; bpf_target_arch = "mips" ))] use crate::bindings::pt_regs; -// aarch64 uses user_pt_regs instead of pt_regs -#[cfg(any(bpf_target_arch = "aarch64", bpf_target_arch = "s390x"))] +#[cfg(any( + bpf_target_arch = "aarch64", + bpf_target_arch = "loongarch64", + bpf_target_arch = "s390x", +))] use crate::bindings::user_pt_regs as pt_regs; -// riscv64 uses user_regs_struct instead of pt_regs #[cfg(bpf_target_arch = "riscv64")] use crate::bindings::user_regs_struct as pt_regs; use crate::{EbpfContext, args::FromPtRegs}; diff --git a/ebpf/aya-ebpf/src/programs/retprobe.rs b/ebpf/aya-ebpf/src/programs/retprobe.rs index 5aef5f5c..e3d83ad6 100644 --- a/ebpf/aya-ebpf/src/programs/retprobe.rs +++ b/ebpf/aya-ebpf/src/programs/retprobe.rs @@ -7,10 +7,12 @@ use core::ffi::c_void; bpf_target_arch = "mips" ))] use crate::bindings::pt_regs; -// aarch64 uses user_pt_regs instead of pt_regs -#[cfg(any(bpf_target_arch = "aarch64", bpf_target_arch = "s390x"))] +#[cfg(any( + bpf_target_arch = "aarch64", + bpf_target_arch = "loongarch64", + bpf_target_arch = "s390x", +))] use crate::bindings::user_pt_regs as pt_regs; -// riscv64 uses user_regs_struct instead of pt_regs #[cfg(bpf_target_arch = "riscv64")] use crate::bindings::user_regs_struct as pt_regs; use crate::{EbpfContext, args::FromPtRegs};