tools/address_guard: match runtime 48-bit wraparound spans and header last_module field #2420

Merged
leonida/mandy
Andretuta merged 1 commit from fix/address-guard-wraparound-parity into main 2026-11-28 10:58:14 +00:00

Pull request successfully merged and closed

Andretuta commented 2026-11-27 03:17:07 +00:00

Claimed in the coordination issue as: TOOLS-ADDRESS-GUARD-WRAPAROUND (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7208856827)

What and why

  • tools/address_guard.py:table_words previously skipped any span with end <= start and iterated a single linear page range, silently dropping valid 48-bit wraparound spans (such as ((-0x2000) & MASK48, 0) already passed in tests/semantic/test_address_guard.py, or (-0x1000, 0x1000) crossing heap_base as tested in runtime/test/address_guard_test.cpp).
  • Match runtime/src/address_guard.h (AddressGuardTable::assign): skip empty spans mod 2^48 and mark wrapping spans as two runs [first, max_page] and [0, last] using chunk-level bit-range marking (_mark_pages, also making multi-GiB spans fast).
  • Add optional last_module=0 parameter to header() matching AddressGuardHeader::last_module in runtime/src/address_guard.h.
  • Add unit test suite tests/test_address_guard.py and extend tests/semantic/test_address_guard.py with wraparound assertions.

Tested

  • python -I tests/test_address_guard.py -v: 7/7 OK (wraparound assertions fail on unpatched main d1dff7949).
  • python -I tests/semantic/test_address_guard.py -v: 12/12 OK.
  • address_guard_test.exe (MSVC 14.44 RelWithDebInfo): address_guard_test: ok.
  • python -I scripts/run_address_guard_gpu_test.py --build <build-dir>: PASS (guard on) and PASS (guard off).
  • python -I scripts/check_no_game_data.py + tests/test_text_write_line_endings.py: exit 0.

GPUs tested: NVIDIA GeForce RTX 3060 12 GB, NVIDIA driver 617.14, Windows 10 (run_address_guard_gpu_test.py)

AI-assisted: yes (Antigravity gemini-4-neon)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a — not a translator rule)
Claimed in the coordination issue as: TOOLS-ADDRESS-GUARD-WRAPAROUND (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7208856827) ### What and why - `tools/address_guard.py:table_words` previously skipped any span with `end <= start` and iterated a single linear page range, silently dropping valid 48-bit wraparound spans (such as `((-0x2000) & MASK48, 0)` already passed in `tests/semantic/test_address_guard.py`, or `(-0x1000, 0x1000)` crossing `heap_base` as tested in `runtime/test/address_guard_test.cpp`). - Match `runtime/src/address_guard.h` (`AddressGuardTable::assign`): skip empty spans mod `2^48` and mark wrapping spans as two runs `[first, max_page]` and `[0, last]` using chunk-level bit-range marking (`_mark_pages`, also making multi-GiB spans fast). - Add optional `last_module=0` parameter to `header()` matching `AddressGuardHeader::last_module` in `runtime/src/address_guard.h`. - Add unit test suite `tests/test_address_guard.py` and extend `tests/semantic/test_address_guard.py` with wraparound assertions. ### Tested - `python -I tests/test_address_guard.py -v`: **7/7 OK** (wraparound assertions fail on unpatched `main` `d1dff7949`). - `python -I tests/semantic/test_address_guard.py -v`: **12/12 OK**. - `address_guard_test.exe` (MSVC 14.44 RelWithDebInfo): `address_guard_test: ok`. - `python -I scripts/run_address_guard_gpu_test.py --build <build-dir>`: `PASS (guard on)` and `PASS (guard off)`. - `python -I scripts/check_no_game_data.py` + `tests/test_text_write_line_endings.py`: exit 0. GPUs tested: NVIDIA GeForce RTX 3060 12 GB, NVIDIA driver 617.14, Windows 10 (`run_address_guard_gpu_test.py`) AI-assisted: yes (Antigravity gemini-4-neon) ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. *(n/a — not a translator rule)*
tiguan26 approved these changes 2026-11-27 05:48:06 +00:00
tiguan26 left a comment

Approving. Checked on 1524a0913, which merges cleanly onto main.

tests/test_address_guard.py: 7 passed. tests/semantic/test_address_guard.py: OK. As a negative check I ran both against main's tools/address_guard.py: 5 failures in the new file and 3 in the semantic one, so the tests do pin the wraparound and last_module changes.

Compared with runtime/src/address_guard.h: the header field order matches AddressGuardHeader (refused, last_module, last_refused), and the wrap handling is the same as assign(), first/last 48-bit page numbers and two runs through kMask48 >> 12 when first > last. _mark_pages also mirrors mark() word by word, and the boundary test covers it.

One small difference, not a blocker: assign() skips a span only when end == start as 64-bit values, while table_words skips it when (end - start) & MASK48 == 0. They differ only for a span given as mixed forms, e.g. (-0x2000, (-0x2000) & MASK48) in test_empty_spans_produce_only_empty_and_full_blocks. Python calls that empty; the C++ (if it were ever handed a sign-extended start and a masked end) would see first > last and mark the whole 48-bit space. The Python reading is the sensible one and the runtime builds its spans in one form, so this is only about the docstring's "matching" claim. Either note it there, or make the runtime mask both ends before comparing.

Approving. Checked on 1524a0913, which merges cleanly onto main. `tests/test_address_guard.py`: 7 passed. `tests/semantic/test_address_guard.py`: OK. As a negative check I ran both against main's `tools/address_guard.py`: 5 failures in the new file and 3 in the semantic one, so the tests do pin the wraparound and `last_module` changes. Compared with `runtime/src/address_guard.h`: the header field order matches `AddressGuardHeader` (refused, last_module, last_refused), and the wrap handling is the same as `assign()`, first/last 48-bit page numbers and two runs through `kMask48 >> 12` when first > last. `_mark_pages` also mirrors `mark()` word by word, and the boundary test covers it. One small difference, not a blocker: `assign()` skips a span only when `end == start` as 64-bit values, while `table_words` skips it when `(end - start) & MASK48 == 0`. They differ only for a span given as mixed forms, e.g. `(-0x2000, (-0x2000) & MASK48)` in `test_empty_spans_produce_only_empty_and_full_blocks`. Python calls that empty; the C++ (if it were ever handed a sign-extended start and a masked end) would see first > last and mark the whole 48-bit space. The Python reading is the sensible one and the runtime builds its spans in one form, so this is only about the docstring's "matching" claim. Either note it there, or make the runtime mask both ends before comparing.
zmasi commented 2026-11-28 10:03:39 +00:00

#2420 | head 1524a0913a75dccb3f770c47d73bac2cf745b1f6 (merged cleanly with main 33db04a70) | python -I tests/test_address_guard.py && python -I scripts/run_semantic_tests.py -p test_address_guard.py tests/semantic | red on main: FAILED (failures=4, errors=1) (TypeError on last_module and 3 != 4 allocated level-2 blocks on 48-bit wraparound spans) and semantic FAILED (failures=3) | green on PR+main: 7 tests OK and 12 tests, 0 failed | Windows 11, Python 3.12.10 | AI-assisted: yes

Audited header, _mark_pages, and table_words in tools/address_guard.py (48-bit MASK48 wraparound splitting [first, max_page] + [0, last], word-slice bit marking, and last_module header field matching runtime/src/address_guard.h). Also passed tests/test_ci_registration.py (18 OK), tests/test_text_write_line_endings.py (3 OK), tests/test_runner_calls_all_tests.py (3 OK), and scripts/check_no_game_data.py on the merged tree.

#2420 | head 1524a0913a75dccb3f770c47d73bac2cf745b1f6 (merged cleanly with main 33db04a70) | `python -I tests/test_address_guard.py && python -I scripts/run_semantic_tests.py -p test_address_guard.py tests/semantic` | red on main: `FAILED (failures=4, errors=1)` (`TypeError` on `last_module` and `3 != 4` allocated level-2 blocks on 48-bit wraparound spans) and semantic `FAILED (failures=3)` | green on PR+main: `7 tests OK` and `12 tests, 0 failed` | Windows 11, Python 3.12.10 | AI-assisted: yes Audited `header`, `_mark_pages`, and `table_words` in `tools/address_guard.py` (48-bit `MASK48` wraparound splitting `[first, max_page]` + `[0, last]`, word-slice bit marking, and `last_module` header field matching `runtime/src/address_guard.h`). Also passed `tests/test_ci_registration.py` (`18 OK`), `tests/test_text_write_line_endings.py` (`3 OK`), `tests/test_runner_calls_all_tests.py` (`3 OK`), and `scripts/check_no_game_data.py` on the merged tree.
DadaCap commented 2026-11-28 10:58:17 +00:00

Merged, thank you @Andretuta! This PR (tools/address_guard: match runtime 48-bit wraparound spans and header last_module field) was checked by zmasi or sodove and then by our own local run of its tests with main merged in, and it passed cleanly, so it went in with its reviewed batch.

AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.

Merged, thank you @Andretuta! This PR (tools/address_guard: match runtime 48-bit wraparound spans and header last_module field) was checked by zmasi or sodove and then by our own local run of its tests with main merged in, and it passed cleanly, so it went in with its reviewed batch. AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.
Sign in to join this conversation.
No description provided.