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

Open
github-bot wants to merge 1 commit from github-bot/gh-2420 into main AGit
Owner

@⁠Andretuta on GitHub · 2026-11-27 03:17 UTC · original
ubiquitarianism:fix/address-guard-wraparound-parity → main · +181 −13 · 3 files · 1 commits · open

Claimed in the coordination issue as: TOOLS-ADDRESS-GUARD-WRAPAROUND (#1608)

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)
**@⁠Andretuta** on GitHub · 2026-11-27 03:17 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2420) `ubiquitarianism:fix/address-guard-wraparound-parity` → `main` · +181 −13 · 3 files · 1 commits · open Claimed in the coordination issue as: TOOLS-ADDRESS-GUARD-WRAPAROUND (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### 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)*
Support 48-bit spans crossing 0 (both signed negative and unsigned 48-bit two's complement)
using chunk-level bit-range marking matching runtime/src/address_guard.h, add optional
last_module parameter to header(), and add unit + semantic regression tests verified with
address_guard_test and RTX 3060 run_address_guard_gpu_test.py.

AI-assisted: Antigravity gemini-4-neon.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 03:19:53 +00:00
Author
Owner

@⁠tiguan26 on GitHub · 2026-11-27 05:48 UTC · original · approved these changes

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.

**@⁠tiguan26** on GitHub · 2026-11-27 05:48 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2420#pullrequestreview-6084004189) · **approved these changes** 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.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2420/head:github-bot/gh-2420'
git switch 'github-bot/gh-2420'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2420'
git switch 'github-bot/gh-2420'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2420'
git switch 'github-bot/gh-2420'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2420'
git switch 'main'
git merge --squash 'github-bot/gh-2420'
git switch 'main'
git merge --ff-only 'github-bot/gh-2420'
git switch 'main'
git merge 'github-bot/gh-2420'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.