bytecodealliance/rustix

page_size() returns zero under Alpine Linux

yorickpeterse opened this issue · 6 comments

The method rustix::param::page_size() returns 0 when using Alpine Linux. Consider this program:

const _SC_PAGESIZE: std::ffi::c_int = 30;

extern "C" {
    fn sysconf(name: std::ffi::c_int) -> std::ffi::c_long;
}

fn page_size() -> usize {
    unsafe { sysconf(_SC_PAGESIZE) as usize }
}

fn main() {
    println!("rustix: {}", rustix::param::page_size());
    println!("libc:   {}", page_size());
}

And this Cargo.toml:

[package]
name = "playground"
version = "0.1.0"
authors = ["Yorick Peterse"]
edition = "2021"

[dependencies]
rustix = { version = "^0.38", features = ["fs", "mm", "param", "process", "net", "std", "time"], default-features = false }
libc = "*"

When running this with cargo run, the output is as follows:

rustix: 0
libc:   4096

This was tested inside an Alpine 3.18.4 container, running on a Fedora 39 host with Linux kernel version 6.5.11.

Thanks for the report! I can confirm this is a rustix bug.

This can be worked around by removing the default-features = false or by adding "use-libc-auxv" to the features array.

@sunfishcode Thanks for the tip. Just to confirm: that means rustix will go through libc instead of using the Linux kernel interface directly right?

I've now submitted #934 with a fix.

@yorickpeterse Yes, the default features or "use-libc-auxv" tells rustix to call the libc sysconf function to retrieve the page size.

@sunfishcode Thanks for the clarification, and the quick fix! 🎉

This is now released in rustix 0.38.24.