From f4832f2d2c2a0a4b2106458be318bb2fdf391802 Mon Sep 17 00:00:00 2001 From: Barnadrot Date: Sun, 10 May 2026 12:33:05 -0400 Subject: [PATCH 1/2] fix(syscall): MAP_NORESERVE on aarch64 Linux via raw syscall MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The existing raw-syscall path with MAP_NORESERVE was gated on target_arch="x86_64" only. aarch64 Linux fell through to the libc::mmap fallback that omits MAP_NORESERVE — fine for macOS (which has no equivalent flag) but broken on Linux: with vm.overcommit_memory=0 (default on Asahi Fedora and many other distros), the kernel rejects the multi-tens-of-GB arena reservation and ensure_region aborts the process before any work runs. Reproduced on Apple Silicon M2 / Asahi Linux Fedora 42 (16 KiB pages, 16 GiB RAM, kernel 6.14.2). Patched build runs cleanly and is +3.4% faster than standard-alloc on the leanMultisig 1550-sig XMSS aggregation workload. Adds a parallel imp module gated on (target_os=linux, target_arch=aarch64) that mirrors the x86_64 raw-syscall path with the correct aarch64 syscall numbers (SYS_mmap=222, SYS_madvise=233) and ABI (svc 0, x8=nr, x0..x5=args). The macOS path is unchanged. --- src/syscall.rs | 87 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 86 insertions(+), 1 deletion(-) diff --git a/src/syscall.rs b/src/syscall.rs index f676b2a..cae6ae5 100644 --- a/src/syscall.rs +++ b/src/syscall.rs @@ -92,7 +92,92 @@ mod imp { } } -#[cfg(not(all(target_os = "linux", target_arch = "x86_64")))] +#[cfg(all(target_os = "linux", target_arch = "aarch64"))] +mod imp { + use std::ptr; + + const SYS_MMAP: usize = 222; + const SYS_MADVISE: usize = 233; + + const PROT_READ: usize = 1; + const PROT_WRITE: usize = 2; + const MAP_PRIVATE: usize = 0x02; + const MAP_ANONYMOUS: usize = 0x20; + const MAP_NORESERVE: usize = 0x4000; + + pub const MADV_NOHUGEPAGE: usize = 15; + + #[inline] + unsafe fn syscall6( + nr: usize, + a1: usize, + a2: usize, + a3: usize, + a4: usize, + a5: usize, + a6: usize, + ) -> isize { + let ret: isize; + unsafe { + std::arch::asm!( + "svc 0", + in("x8") nr, + inlateout("x0") a1 as isize => ret, + in("x1") a2, + in("x2") a3, + in("x3") a4, + in("x4") a5, + in("x5") a6, + options(nostack), + ); + } + ret + } + + #[inline] + unsafe fn syscall3(nr: usize, a1: usize, a2: usize, a3: usize) -> isize { + let ret: isize; + unsafe { + std::arch::asm!( + "svc 0", + in("x8") nr, + inlateout("x0") a1 as isize => ret, + in("x1") a2, + in("x2") a3, + options(nostack), + ); + } + ret + } + + #[inline] + pub unsafe fn mmap_anonymous(size: usize) -> *mut u8 { + let flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE; + let ret = unsafe { + syscall6( + SYS_MMAP, + 0, + size, + PROT_READ | PROT_WRITE, + flags, + usize::MAX, + 0, + ) + }; + if ret < 0 { + ptr::null_mut() + } else { + ret as *mut u8 + } + } + + #[inline] + pub unsafe fn madvise(ptr: *mut u8, size: usize, advice: usize) { + unsafe { syscall3(SYS_MADVISE, ptr as usize, size, advice) }; + } +} + +#[cfg(not(all(target_os = "linux", any(target_arch = "x86_64", target_arch = "aarch64"))))] mod imp { use std::ptr; From a9feef4d3e2a90c741ebe96cd519e20f1201de28 Mon Sep 17 00:00:00 2001 From: Barnadrot Date: Sun, 10 May 2026 12:39:43 -0400 Subject: [PATCH 2/2] chore: rustfmt for the new aarch64 cfg gate --- src/syscall.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/syscall.rs b/src/syscall.rs index cae6ae5..54f67d4 100644 --- a/src/syscall.rs +++ b/src/syscall.rs @@ -177,7 +177,10 @@ mod imp { } } -#[cfg(not(all(target_os = "linux", any(target_arch = "x86_64", target_arch = "aarch64"))))] +#[cfg(not(all( + target_os = "linux", + any(target_arch = "x86_64", target_arch = "aarch64") +)))] mod imp { use std::ptr;