Skip to content

Run Miri on test suite to detect undefined behavior in unsafe code #11

Description

@ddsha441981

Summary

PulseMap contains several unsafe blocks:

  • SlabPool (src/engine/slab.rs): Manual heap allocation via std::alloc::Layout, raw pointer reads/writes
  • MetaWord (src/engine/meta.rs): AtomicU64 with Relaxed ordering
  • PulseMapRaw (src/raw.rs): unsafe impl Send (intentionally no Sync)
  • AccessBuffer (src/engine/access_buffer.rs): unsafe impl Send + Sync
  • simd.rs: unsafe SSE2 intrinsics

Miri is Rust's official interpreter for detecting undefined behavior (UB) at runtime. Running the existing test suite under Miri can catch memory errors that normal tests miss: use-after-free, out-of-bounds access, invalid pointer alignment, and violations of Rust's aliasing model (Stacked Borrows).

What To Do

1. Try running the existing tests under Miri

rustup +nightly component add miri
cargo +nightly miri test -p pulse_map --no-default-features  # core engine only
cargo +nightly miri test -p pulse_map                        # with std features

2. Document and fix any Miri violations

  • If Miri reports UB, create a separate issue for each distinct violation with the full Miri backtrace
  • Common findings in projects like this:
    • Stacked Borrows violations from casting &self to *mut (we already fixed the big one in v0.6.2)
    • Alignment issues in repr(C, packed) structs (our Slot is packed)
    • Provenance issues in the SlabPool raw pointer usage

3. Add Miri to CI

Add a new job in .github/workflows/build.yml:

- name: Run Miri
  run: |
    rustup +nightly component add miri
    cargo +nightly miri test -p pulse_map --no-default-features

Known Limitations

  • Miri does not support inline assembly or SIMD intrinsics. Tests using the simd feature will need to be skipped (--no-default-features avoids this)
  • Miri is slow (~100x slower than normal execution). This is expected.

Acceptance Criteria

  • All existing tests pass under cargo +nightly miri test --no-default-features
  • Any Miri violations are documented as separate issues with full backtraces
  • Miri CI job added to .github/workflows/build.yml
  • No changes to core engine logic unless fixing a genuine Miri-detected UB

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions