fix(bench): eliminate SIGBUS handler static mut UB with Once + raw atomics (closes #33)

Replace `static mut OLD_SIGBUS_HANDLER` with AtomicU8 + AtomicPtr to
remove data race UB when concurrent benchmarks call open() from multiple
threads.

Key changes:
- Use `Once::call_once` to guarantee single handler installation
- Publish old handler to atomics BEFORE installing new handler (closes
  the handler-active-but-state-unpublished race window)
- Read atomics with Acquire in signal handler (async-signal-safe)
- Align si_addr to page boundary before mmap(MAP_FIXED)
- Add concurrent test: 8 threads open all 5 variants simultaneously
This commit is contained in:
dailz
2026-06-05 13:22:02 +08:00
parent 534a089b58
commit dad5f5a635
19 changed files with 3562 additions and 0 deletions

18
crates/bench/Cargo.toml Normal file
View File

@@ -0,0 +1,18 @@
[package]
name = "log-viewer-bench"
version = "0.1.0"
edition = "2024"
[[bin]]
name = "log-viewer-bench"
path = "src/main.rs"
[dependencies]
memmap2 = "0.9"
nix = { version = "0.30", features = ["signal", "resource", "mman", "fs"] }
libc = "0.2"
memchr = "2"
serde_json = "1"
clap = { version = "4", features = ["derive"] }
crossbeam-channel = "0.5"
tempfile = "3"