Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Upcoming Release

## Added
- Support for loongarch64 is added

# v0.5.0

## Added
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Supported host architectures:
- Little-endian x86_64
- Little-endian aarch64
- Little-endian riscv64
- Little-endian loongarch64

## Short seccomp tutorial

Expand Down
5 changes: 5 additions & 0 deletions src/backend/bpf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ pub const AUDIT_ARCH_AARCH64: u32 = 183 | 0x8000_0000 | 0x4000_0000;
// `#define AUDIT_ARCH_RISCV64 (EM_RISCV|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)`
pub const AUDIT_ARCH_RISCV64: u32 = 243 | 0x8000_0000 | 0x4000_0000;

// Architecture identifier for loongarch64 LE.
// Defined as:
// `#define AUDIT_ARCH_LOONGARCH64 (EM_LOONGARCH|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)`
pub const AUDIT_ARCH_LOONGARCH64: u32 = 258 | 0x8000_0000 | 0x4000_0000;

/// BPF instruction structure definition.
// See /usr/include/linux/filter.h .
// We cannot use the `libc::sock_filter` definition since it doesn't implement `Debug` and
Expand Down
15 changes: 14 additions & 1 deletion src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use libc::{
SECCOMP_RET_KILL_THREAD, SECCOMP_RET_LOG, SECCOMP_RET_TRACE, SECCOMP_RET_TRAP,
};

use bpf::{ARG_NUMBER_MAX, AUDIT_ARCH_AARCH64, AUDIT_ARCH_RISCV64, AUDIT_ARCH_X86_64, BPF_MAX_LEN};
use bpf::{ARG_NUMBER_MAX, AUDIT_ARCH_AARCH64, AUDIT_ARCH_LOONGARCH64, AUDIT_ARCH_RISCV64, AUDIT_ARCH_X86_64, BPF_MAX_LEN};

pub use bpf::{sock_filter, BpfProgram, BpfProgramRef};

Expand Down Expand Up @@ -85,6 +85,8 @@ pub enum TargetArch {
aarch64,
/// riscv64 arch
riscv64,
/// loongarch64 arch
loongarch64,
}

impl TargetArch {
Expand All @@ -94,6 +96,7 @@ impl TargetArch {
TargetArch::x86_64 => AUDIT_ARCH_X86_64,
TargetArch::aarch64 => AUDIT_ARCH_AARCH64,
TargetArch::riscv64 => AUDIT_ARCH_RISCV64,
TargetArch::loongarch64 => AUDIT_ARCH_LOONGARCH64,
}
}
}
Expand All @@ -105,6 +108,7 @@ impl TryFrom<&str> for TargetArch {
"x86_64" => Ok(TargetArch::x86_64),
"aarch64" => Ok(TargetArch::aarch64),
"riscv64" => Ok(TargetArch::riscv64),
"loongarch64" => Ok(TargetArch::loongarch64),
_ => Err(Error::InvalidTargetArch(input.to_string())),
}
}
Expand Down Expand Up @@ -218,5 +222,14 @@ mod tests {
TargetArch::try_from("RiScV64").unwrap(),
TargetArch::riscv64
);

assert_eq!(
TargetArch::try_from("loongarch64").unwrap(),
TargetArch::loongarch64
);
assert_eq!(
TargetArch::try_from("LoOnGaRch64").unwrap(),
TargetArch::loongarch64
);
}
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
//! - Little-endian x86_64
//! - Little-endian aarch64
//! - Little-endian riscv64
//! - Little-endian loongarch64
//!
//! # Terminology
//!
Expand Down
Loading