Repository navigation
Conversation
`memory_at_names_what_an_access_hit` releases a four-page reservation and then reads one of
the pages back to see `nothing mapped there`. Another test in the same binary mapping in the
microseconds between the `VirtualFree` and the read takes that address, and the read says
`read-write` instead - which is exactly what CI did on two unrelated pull requests:
---- crash::tests::memory_at_names_what_an_access_hit
assertion `left == right` failed
left: "read-write"
right: "nothing mapped there"
The read is now over a fresh reservation released immediately before it, retried: the first
attempt whose address nobody took is the answer, and 64 taken in a row is a real failure
rather than a busy neighbour. Each attempt is a `VirtualAlloc` and a `VirtualFree` of 4 KiB.
Why not a lock: the window is between the release and the read, and the neighbour is any of
six files in this crate that map pages in their tests (`console_insn`, `descriptor_sites`,
`game_actions`, `thunks`, `tls`, `write_sites`), so a lock held by this module alone would not
remove it; a crate-wide one would touch all seven. The retry costs nothing and holds whatever
the neighbour does.
What I could not do: reproduce the failure on demand. `cargo test -p leonida-loader --lib
crash::tests` passed 19/19 six times in a row here, so the negative control is the CI log
above and not a local red. With the change: 19/19 four more times, clippy 0.
Written with an AI assistant.
|
Ran the Windows leonida-loader library suite 25 times at parent 913b88b and 25 times at PR head a607df1. I rebuilt at each revision with cargo test --locked -p leonida-loader --lib --no-run, then launched the resulting test executable in a fresh process each time with --test-threads 16. All 85 tests passed in each of the 50 runs (2,125 test executions per revision). I could not reproduce the original intermittent failure on this machine, so this confirms repeated parallel passes on the PR but does not establish a reduction in flake rate. Codex-assisted. |
VERIFY-3017 — Linux, Fedora 45, Rust 1.98.1, cross-compiled for x86_64-pc-windows-gnu, Wine 11.21, no GPU device, no game filesVerdict: PASS. The old line reads an address back after handing it to the free pool, and anything else can already be in it; the pull request keeps the property the line was checking (a released page reads back free) and stops failing on a neighbour taking it. I reproduced the race it is defending against. Head 1. What it changesOne test, unsafe { VirtualFree(base as *mut _, 0, MEM_RELEASE) };
- assert_eq!(memory_at(base + 8), "nothing mapped there");The release hands those pages back to the process, and a test running beside this one can take them between the + let gone = (0..64).any(|_| {
+ // SAFETY: reserves, commits and releases four pages of ours; nothing reads them.
+ let fresh = unsafe {
+ let fresh = VirtualAlloc(std::ptr::null(), 0x4000, MEM_RESERVE, PAGE_NOACCESS);
+ assert!(!fresh.is_null());
+ assert!(!VirtualAlloc(fresh, 0x1000, MEM_COMMIT, PAGE_READWRITE).is_null());
+ VirtualFree(fresh, 0, MEM_RELEASE);
+ fresh as usize
+ };
+ memory_at(fresh + 8) == "nothing mapped there"
+ });
+ assert!(gone, "a released page was still read back as mapped 64 times in a row");and it keeps the base's remaining lines, 2. The new test checks the property that mattersThis is test-only, so the red side (merge base plus the test hunks) compiles and passes the same way the green side does, and the harness cannot show red-then-green. Two things were worth checking instead. First, that the race is real. I wrote a small standalone program (cross-compiled with the same toolchain and run under Wine) where one thread reserves the same range as
So the base line is not deterministic: in about one round out of thirty the range already holds somebody else's Second, that the replacement is not vacuous. I mutated the loop body so no attempt can ever match ( Restoring the line, it passes again. So the assertion still has teeth, and it still says something the base said — a released page really does read back free — rather than giving that up. Compared with the sibling pull request #2939, which fixes the same test by querying addresses Windows never maps, this one is the more conservative fix: it retains the property under test. The cost is the 3. What the tests do here
Run by hand on the head, the crate's unit suite is 84 passed / 0 failed three times in a row, and 4. Any failure I saw, and why it is not this pull request
The test shells out to 5. What I did not check
The program was scratch work under |
tests: a released page is read back without racing the tests beside it
memory_at_names_what_an_access_hitreleases a four-page reservation and then reads one ofthe pages back to see
nothing mapped there. Another test in the same binary mapping in themicroseconds between the
VirtualFreeand the read takes that address, and the read saysread-writeinstead - which is exactly what CI did on two unrelated pull requests:The read is now over a fresh reservation released immediately before it, retried: the first
attempt whose address nobody took is the answer, and 64 taken in a row is a real failure
rather than a busy neighbour. Each attempt is a
VirtualAllocand aVirtualFreeof 4 KiB.Why not a lock: the window is between the release and the read, and the neighbour is any of
six files in this crate that map pages in their tests (
console_insn,descriptor_sites,game_actions,thunks,tls,write_sites), so a lock held by this module alone would notremove it; a crate-wide one would touch all seven. The retry costs nothing and holds whatever
the neighbour does.
What I could not do: reproduce the failure on demand.
cargo test -p leonida-loader --lib crash::testspassed 19/19 six times in a row here, so the negative control is the CI logabove and not a local red. With the change: 19/19 four more times, clippy 0.
Written with an AI assistant.