enable bpf_target_arch = loongarch64

Signed-off-by: Godones <chenlinfeng25@outlook.com>
Signed-off-by: Tamir Duberstein <tamird@gmail.com>
reviewable/pr1374/r4
Godones 3 days ago committed by Tamir Duberstein
parent 9e577f60b5
commit 4b4b9f83bd
No known key found for this signature in database

@ -81,6 +81,7 @@ jobs:
arch: arch:
- aarch64-unknown-linux-gnu - aarch64-unknown-linux-gnu
- armv7-unknown-linux-gnueabi - armv7-unknown-linux-gnueabi
- loongarch64-unknown-linux-gnu
- powerpc64le-unknown-linux-gnu - powerpc64le-unknown-linux-gnu
- riscv64gc-unknown-linux-gnu - riscv64gc-unknown-linux-gnu
- s390x-unknown-linux-gnu - s390x-unknown-linux-gnu
@ -149,6 +150,7 @@ jobs:
bpf_target_arch: bpf_target_arch:
- aarch64 - aarch64
- arm - arm
- loongarch64
- mips - mips
- powerpc64 - powerpc64
- riscv64 - riscv64

@ -162,6 +162,21 @@ impl<T> FromPtRegs for *const T {
} }
} }
#[cfg(bpf_target_arch = "loongarch64")]
impl<T> FromPtRegs for *const T {
fn from_argument(ctx: &pt_regs, n: usize) -> Option<Self> {
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<Self> {
unsafe { bpf_probe_read(&ctx.regs[4]).map(|v| v as *const _).ok() }
}
}
#[cfg(bpf_target_arch = "riscv64")] #[cfg(bpf_target_arch = "riscv64")]
impl<T> FromPtRegs for *const T { impl<T> FromPtRegs for *const T {
fn from_argument(ctx: &pt_regs, n: usize) -> Option<Self> { fn from_argument(ctx: &pt_regs, n: usize) -> Option<Self> {
@ -278,6 +293,21 @@ impl<T> FromPtRegs for *mut T {
} }
} }
#[cfg(bpf_target_arch = "loongarch64")]
impl<T> FromPtRegs for *mut T {
fn from_argument(ctx: &pt_regs, n: usize) -> Option<Self> {
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<Self> {
unsafe { bpf_probe_read(&ctx.regs[4]).map(|v| v as *mut _).ok() }
}
}
#[cfg(bpf_target_arch = "riscv64")] #[cfg(bpf_target_arch = "riscv64")]
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> {
@ -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<Self> {
if n <= 7 {
Some(ctx.regs[4 + n] as *const $type as _)
} else {
None
}
}
fn from_retval(ctx: &pt_regs) -> Option<Self> {
Some(ctx.regs[4] as *const $type as _)
}
}
#[cfg(bpf_target_arch = "riscv64")] #[cfg(bpf_target_arch = "riscv64")]
impl FromPtRegs for $type { impl FromPtRegs for $type {
fn from_argument(ctx: &pt_regs, n: usize) -> Option<Self> { fn from_argument(ctx: &pt_regs, n: usize) -> Option<Self> {

@ -7,10 +7,12 @@ use core::ffi::c_void;
bpf_target_arch = "mips" bpf_target_arch = "mips"
))] ))]
use crate::bindings::pt_regs; use crate::bindings::pt_regs;
// aarch64 uses user_pt_regs instead of pt_regs #[cfg(any(
#[cfg(any(bpf_target_arch = "aarch64", bpf_target_arch = "s390x"))] bpf_target_arch = "aarch64",
bpf_target_arch = "loongarch64",
bpf_target_arch = "s390x",
))]
use crate::bindings::user_pt_regs as pt_regs; use crate::bindings::user_pt_regs as pt_regs;
// riscv64 uses user_regs_struct instead of pt_regs
#[cfg(bpf_target_arch = "riscv64")] #[cfg(bpf_target_arch = "riscv64")]
use crate::bindings::user_regs_struct as pt_regs; use crate::bindings::user_regs_struct as pt_regs;
use crate::{EbpfContext, args::FromPtRegs}; use crate::{EbpfContext, args::FromPtRegs};

@ -7,10 +7,12 @@ use core::ffi::c_void;
bpf_target_arch = "mips" bpf_target_arch = "mips"
))] ))]
use crate::bindings::pt_regs; use crate::bindings::pt_regs;
// aarch64 uses user_pt_regs instead of pt_regs #[cfg(any(
#[cfg(any(bpf_target_arch = "aarch64", bpf_target_arch = "s390x"))] bpf_target_arch = "aarch64",
bpf_target_arch = "loongarch64",
bpf_target_arch = "s390x",
))]
use crate::bindings::user_pt_regs as pt_regs; use crate::bindings::user_pt_regs as pt_regs;
// riscv64 uses user_regs_struct instead of pt_regs
#[cfg(bpf_target_arch = "riscv64")] #[cfg(bpf_target_arch = "riscv64")]
use crate::bindings::user_regs_struct as pt_regs; use crate::bindings::user_regs_struct as pt_regs;
use crate::{EbpfContext, args::FromPtRegs}; use crate::{EbpfContext, args::FromPtRegs};

Loading…
Cancel
Save