Merge pull request #482 from ishanjain28/add_mips_support

Added MIPS bindings
reviewable/pr690/r3
Dave Tucker 3 weeks ago committed by GitHub
commit 2f757b2091
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -15,3 +15,6 @@ linker = "powerpc64le-linux-gnu-gcc"
[target.s390x-unknown-linux-gnu]
linker = "s390x-linux-gnu-gcc"
[target.mips-unknown-linux-gnu]
linker = "mips-linux-gnu-gcc"

@ -83,6 +83,7 @@ jobs:
- riscv64gc-unknown-linux-gnu
- powerpc64le-unknown-linux-gnu
- s390x-unknown-linux-gnu
- mips-unknown-linux-gnu
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
@ -141,6 +142,7 @@ jobs:
- riscv64
- powerpc64
- s390x
- mips
target:
- bpfel-unknown-none
- bpfeb-unknown-none

@ -44,7 +44,7 @@ default-members = [
# ebpf crates are omitted; they must be built with:
# --target bpfe{b,l}-unknown-none
# CARGO_CFG_BPF_TARGET_ARCH={x86_64,aarch64,arm,riscv64,powerpc64,s390x}
# CARGO_CFG_BPF_TARGET_ARCH={x86_64,aarch64,arm,riscv64,powerpc64,s390x,mips}
]
[workspace.package]

@ -13,6 +13,8 @@ mod btf_internal_bindings;
mod linux_bindings_aarch64;
#[cfg(target_arch = "arm")]
mod linux_bindings_armv7;
#[cfg(target_arch = "mips")]
mod linux_bindings_mips;
#[cfg(target_arch = "powerpc64")]
mod linux_bindings_powerpc64;
#[cfg(target_arch = "riscv64")]
@ -29,6 +31,8 @@ pub use btf_internal_bindings::{bpf_core_relo, bpf_core_relo_kind, btf_ext_heade
pub use linux_bindings_aarch64::*;
#[cfg(target_arch = "arm")]
pub use linux_bindings_armv7::*;
#[cfg(target_arch = "mips")]
pub use linux_bindings_mips::*;
#[cfg(target_arch = "powerpc64")]
pub use linux_bindings_powerpc64::*;
#[cfg(target_arch = "riscv64")]

@ -12,5 +12,5 @@ fn main() {
}
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\"))");
}

@ -20,11 +20,16 @@ mod powerpc64;
#[cfg(bpf_target_arch = "s390x")]
mod s390x;
#[cfg(bpf_target_arch = "mips")]
mod mips;
mod gen {
#[cfg(bpf_target_arch = "aarch64")]
pub use super::aarch64::*;
#[cfg(bpf_target_arch = "arm")]
pub use super::armv7::*;
#[cfg(bpf_target_arch = "mips")]
pub use super::mips::*;
#[cfg(bpf_target_arch = "powerpc64")]
pub use super::powerpc64::*;
#[cfg(bpf_target_arch = "riscv64")]

@ -0,0 +1,3 @@
#![allow(clippy::all, dead_code)]
pub mod bindings;
pub mod helpers;

@ -12,6 +12,6 @@ fn main() {
}
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(target_arch, values(\"asmjs\",\"nvptx\",\"xtensa\"))");
}

@ -33,6 +33,9 @@ mod ad {
#[cfg(bpf_target_arch = "s390x")]
pub type c_char = super::c_uchar;
#[cfg(bpf_target_arch = "mips")]
pub type c_char = super::c_uchar;
#[cfg(bpf_target_arch = "x86_64")]
pub type c_char = super::c_schar;
}

@ -13,7 +13,7 @@ fn main() {
}
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)");
}

@ -1,7 +1,8 @@
#[cfg(any(
bpf_target_arch = "x86_64",
bpf_target_arch = "arm",
bpf_target_arch = "powerpc64"
bpf_target_arch = "powerpc64",
bpf_target_arch = "mips",
))]
use crate::bindings::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")]
impl<T> FromPtRegs for *mut T {
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.
macro_rules! impl_from_pt_regs {
($type:ident) => {
@ -405,6 +438,21 @@ macro_rules! impl_from_pt_regs {
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(
bpf_target_arch = "x86_64",
bpf_target_arch = "arm",
bpf_target_arch = "powerpc64"
bpf_target_arch = "powerpc64",
bpf_target_arch = "mips"
))]
use crate::bindings::pt_regs;
// aarch64 uses user_pt_regs instead of pt_regs

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

Loading…
Cancel
Save