Skip to content

Insufficient alignment in Hermit ReadDir implementation #147962

@m-mueller678

Description

@m-mueller678

I tried using a custom global allocator on hermit. ReadDir fails as a result:

thread 'main' (1) panicked at /home/marcus/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/fs/hermit.rs:198:32:
misaligned pointer dereference: address must be a multiple of 0x8 but is 0x4000c1fffcf5

Aligning all allocations to at least 8 bytes fixes the issue, so I looked into the file. It seems like the buffer used for ReadDir is not suitably aligned:

// all DirEntry's will have a reference to this struct
struct InnerReadDir {
    root: PathBuf,
    dir: Vec<u8>,
}

dir is later expected to be aligned to 8 bytes:

let dir = unsafe { &*(self.inner.dir.as_ptr().add(offset) as *const dirent64) };

rustc --version --verbose:

rustc 1.92.0-nightly (3d8c1c1fc 2025-10-06)
binary: rustc
commit-hash: 3d8c1c1fc077d04658de63261d8ce2903546db13
commit-date: 2025-10-06
host: x86_64-unknown-linux-gnu
release: 1.92.0-nightly
LLVM version: 21.1.2

@stlankes @mkroening

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.O-hermitOperating System: HermitT-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions