Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for LoongArch64 #123

Merged
merged 1 commit into from
Nov 16, 2023
Merged
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
74 changes: 62 additions & 12 deletions src/sandbox/seccomp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,44 @@ pub fn activate_stage1() -> Result<()> {
ctx.allow_syscall(Syscall::futex)?;
ctx.allow_syscall(Syscall::read)?;
ctx.allow_syscall(Syscall::write)?;
#[cfg(not(any(target_arch = "aarch64", target_arch = "riscv64")))]
#[cfg(not(any(
target_arch = "aarch64",
target_arch = "riscv64",
target_arch = "loongarch64"
)))]
ctx.allow_syscall(Syscall::open)?;
ctx.allow_syscall(Syscall::close)?;
#[cfg(not(any(target_arch = "aarch64", target_arch = "riscv64")))]
#[cfg(not(any(
target_arch = "aarch64",
target_arch = "riscv64",
target_arch = "loongarch64"
)))]
ctx.allow_syscall(Syscall::stat)?;
#[cfg(target_arch = "arm")]
ctx.allow_syscall(Syscall::stat64)?;
ctx.allow_syscall(Syscall::fstat)?;
#[cfg(target_arch = "arm")]
ctx.allow_syscall(Syscall::fstat64)?;
#[cfg(not(any(target_arch = "aarch64", target_arch = "riscv64")))]
#[cfg(not(any(
target_arch = "aarch64",
target_arch = "riscv64",
target_arch = "loongarch64"
)))]
ctx.allow_syscall(Syscall::lstat)?;
#[cfg(target_arch = "arm")]
ctx.allow_syscall(Syscall::lstat64)?;
ctx.allow_syscall(Syscall::statx)?;
#[cfg(not(any(target_arch = "aarch64", target_arch = "riscv64")))]
#[cfg(not(any(
target_arch = "aarch64",
target_arch = "riscv64",
target_arch = "loongarch64"
)))]
ctx.allow_syscall(Syscall::poll)?;
#[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))]
#[cfg(any(
target_arch = "aarch64",
target_arch = "riscv64",
target_arch = "loongarch64"
))]
ctx.allow_syscall(Syscall::ppoll)?;
ctx.allow_syscall(Syscall::lseek)?; // needed for stage2
#[cfg(target_arch = "arm")]
Expand Down Expand Up @@ -58,7 +78,11 @@ pub fn activate_stage1() -> Result<()> {
ctx.allow_syscall(Syscall::fcntl)?;
#[cfg(target_arch = "arm")]
ctx.allow_syscall(Syscall::fcntl64)?;
#[cfg(not(any(target_arch = "aarch64", target_arch = "riscv64")))]
#[cfg(not(any(
target_arch = "aarch64",
target_arch = "riscv64",
target_arch = "loongarch64"
)))]
ctx.allow_syscall(Syscall::getdents)?;
ctx.allow_syscall(Syscall::chdir)?; // needed for stage2
ctx.allow_syscall(Syscall::getuid)?; // needed for stage2
Expand Down Expand Up @@ -102,11 +126,20 @@ pub fn activate_stage1() -> Result<()> {
ctx.allow_syscall(Syscall::exit_group)?;
ctx.allow_syscall(Syscall::set_robust_list)?;
ctx.allow_syscall(Syscall::openat)?;
#[cfg(any(target_arch = "x86_64", target_arch = "aarch64", target_arch = "riscv64"))]
#[cfg(any(
target_arch = "x86_64",
target_arch = "aarch64",
target_arch = "riscv64",
target_arch = "loongarch64"
))]
ctx.allow_syscall(Syscall::newfstatat)?;
ctx.allow_syscall(Syscall::seccomp)?; // needed for stage2
ctx.allow_syscall(Syscall::getrandom)?;
#[cfg(not(any(target_arch = "aarch64", target_arch = "riscv64")))]
#[cfg(not(any(
target_arch = "aarch64",
target_arch = "riscv64",
target_arch = "loongarch64"
)))]
ctx.allow_syscall(Syscall::pipe)?; // used in libpcap
ctx.allow_syscall(Syscall::wait4)?;
ctx.allow_syscall(Syscall::clock_gettime)?;
Expand All @@ -117,7 +150,11 @@ pub fn activate_stage1() -> Result<()> {
ctx.allow_syscall(Syscall::brk)?;
ctx.allow_syscall(Syscall::madvise)?;
ctx.allow_syscall(Syscall::membarrier)?;
#[cfg(not(any(target_arch = "aarch64", target_arch = "riscv64")))]
#[cfg(not(any(
target_arch = "aarch64",
target_arch = "riscv64",
target_arch = "loongarch64"
)))]
ctx.allow_syscall(Syscall::access)?; // needed for debian /etc/ld.so.nohwcap
ctx.allow_syscall(Syscall::faccessat)?; // needed for debian /etc/ld.so.nohwcap
ctx.allow_syscall(Syscall::eventfd2)?;
Expand Down Expand Up @@ -145,9 +182,17 @@ pub fn activate_stage2() -> Result<()> {
// ctx.allow_syscall(Syscall::stat)?;
// ctx.allow_syscall(Syscall::fstat)?;
// ctx.allow_syscall(Syscall::lstat)?;
#[cfg(not(any(target_arch = "aarch64", target_arch = "riscv64")))]
#[cfg(not(any(
target_arch = "aarch64",
target_arch = "riscv64",
target_arch = "loongarch64"
)))]
ctx.allow_syscall(Syscall::poll)?;
#[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))]
#[cfg(any(
target_arch = "aarch64",
target_arch = "riscv64",
target_arch = "loongarch64"
))]
ctx.allow_syscall(Syscall::ppoll)?;
#[cfg(not(target_arch = "arm"))]
ctx.allow_syscall(Syscall::mmap)?;
Expand Down Expand Up @@ -200,7 +245,12 @@ pub fn activate_stage2() -> Result<()> {

// /proc/sys/vm/overcommit_memory
ctx.set_action_for_syscall(Action::Errno(1), Syscall::openat)?;
#[cfg(not(any(target_arch = "x86_64", target_arch = "aarch64", target_arch = "riscv64")))]
#[cfg(not(any(
target_arch = "x86_64",
target_arch = "aarch64",
target_arch = "riscv64",
target_arch = "loongarch64"
)))]
ctx.set_action_for_syscall(Action::Errno(1), Syscall::open)?;

ctx.load()?;
Expand Down