Proof of concept mechanical port of ircnet/ircd to Rust as part of a bit about C being insecure for network services
0

Configure Feed

Select the types of activity you want to include in your feed.

ircd.rs / docs / claude-memory / p7-l1-shared-global-race.md
1.6 kB 28 lines
1--- 2name: p7-l1-shared-global-race 3description: "P7 L1 differential tests that touch shared C globals (me/cref_me, local[], highest_fd, timeofday) must serialize on a mutex — cargo runs" 4metadata: 5 node_type: memory 6 type: feedback 7 originSessionId: 7cceaba5-1974-4889-94b9-afa6039d571f 8--- 9 10P7 (I/O core) ports touch process-wide C globals (`me`/`cref_me`, and coming up 11`local[]`, `highest_fd`, `timeofday`, `FdAry`). An L1 differential test that zeroes 12then reads such a global races against cargo's other parallel `#[test]` threads in 13the same binary — one test zeroes `me` while another reads it → flaky wrong values 14(seen in P7a `bsd_diff.rs`: `cref_me.sendB` read 0 instead of the written value; 15the failing case passed when run alone via a filter, which is the tell). 16 17**Why:** unlike heap clients passed by pointer (per-test, no sharing), a `static mut` 18global is one instance shared by all tests in the binary. This is the L1 analogue of 19the L2 `PORT_LOCK`. 20 21**How to apply:** in any L1 test file that mutates+reads a shared C global, add a 22file-level `static LOCK: std::sync::Mutex<()> = Mutex::new(())` and have the per-test 23`setup()` return the held guard (`LOCK.lock().unwrap_or_else(|e| e.into_inner())`); 24bind it `let _guard = setup();` so it's held for the whole body. See 25`ircd-testkit/tests/bsd_diff.rs`. Diagnose a suspected race by re-running the single 26failing test with a name filter — if it passes alone but fails in the suite, it's this. 27 28Related: [[l1-cref-static-symbol-limit]], [[piauth-state]] (P7 is the linear next phase).