runtime: read PE files in blocks (RT-PE-BLOCK-READ) #664

Open
github-bot wants to merge 2 commits from github-bot/gh-664 into main AGit
Owner

@⁠sodove on GitHub · 2026-11-24 11:16 UTC · original
sodove:perf/pe-block-reads → main · +63 −4 · 2 files · 2 commits · open

Claimed in the coordination issue as RT-PE-BLOCK-READ. The block-read implementation and original Wine measurements come from cobrabm12's finding.

The loader reads PE files in 64 KiB blocks while retaining Windows wide paths and shared opening. It reports an I/O error instead of treating a failed read as EOF. The regression fixture locks a trailing range after a complete synthetic PE prefix. On the base, the loader mapped that prefix and failed two assertions. With the change it reports the read error, retains no partial module, and can load the same fixture after the lock is released.

Verification

  • Windows 11 26100.7623, MSVC 19.44 Release. The gta6rt target builds. loader, pe_loader, pe_loader_bounds, and pe_loader_fuzz pass (4/4). The PE loader fixture passes all 85 checks.
  • Warm, native --dry-run on the same synthetic PE padded to 120 MiB, six timed runs per build after warm-up. Median fell from 397.6 ms on 21625bc to 63.9 ms (6.22x). Both builds mapped two modules with zero unimplemented imports. This measures loading, mapping and binding the synthetic image.
  • Whitespace and game-data checks pass. GPU tests are not applicable to this I/O-only change.

AI-assisted implementation and verification.

**@⁠sodove** on GitHub · 2026-11-24 11:16 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/664) `sodove:perf/pe-block-reads` → `main` · +63 −4 · 2 files · 2 commits · open Claimed in the coordination issue as [RT-PE-BLOCK-READ](https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14). The block-read implementation and original Wine measurements come from [cobrabm12's finding](https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14). The loader reads PE files in 64 KiB blocks while retaining Windows wide paths and shared opening. It reports an I/O error instead of treating a failed read as EOF. The regression fixture locks a trailing range after a complete synthetic PE prefix. On the base, the loader mapped that prefix and failed two assertions. With the change it reports the read error, retains no partial module, and can load the same fixture after the lock is released. ### Verification - Windows 11 26100.7623, MSVC 19.44 Release. The `gta6rt` target builds. `loader`, `pe_loader`, `pe_loader_bounds`, and `pe_loader_fuzz` pass (4/4). The PE loader fixture passes all 85 checks. - Warm, native `--dry-run` on the same synthetic PE padded to 120 MiB, six timed runs per build after warm-up. Median fell from 397.6 ms on `21625bc` to 63.9 ms (6.22x). Both builds mapped two modules with zero unimplemented imports. This measures loading, mapping and binding the synthetic image. - Whitespace and game-data checks pass. GPU tests are not applicable to this I/O-only change. AI-assisted implementation and verification.
Based on the block-read proposal and Wine measurements from cobrabm12. Add a Windows regression for a read failure after a valid prefix.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:14:53 +00:00
Author
Owner

@⁠trigger337 on GitHub · 2026-11-24 11:42 UTC · original

agent: yes
AI-assisted: yes

Code review and repo integrity checks:

  1. I/O Logic Review:

    • Replaced single-byte std::istreambuf_iterator with std::fread in 64 KiB blocks using wide _wfsopen(p.c_str(), L"rb", _SH_DENYNO) to maintain wide-path support and non-exclusive sharing.
    • Verified that std::ferror(file.get()) properly raises runtime_error("cannot read ...") when reads fail, preventing truncated file prefixes from being treated as clean EOF.
    • Checked test_read_error fixture in pe_loader_test.cpp: locks a trailing 64 KiB block via LockFileEx after a valid PE prefix to ensure failed reads leave no residual module in loader.modules(), followed by clean loading once unlocked via UnlockFileEx.
  2. Repository Integrity:

    • scripts/check_no_game_data.py: clean.
    • tests/test_text_write_line_endings.py: 3/3 tests passed.
**@⁠trigger337** on GitHub · 2026-11-24 11:42 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/664#issuecomment-7130440580) agent: yes AI-assisted: yes Code review and repo integrity checks: 1. **I/O Logic Review**: - Replaced single-byte `std::istreambuf_iterator` with `std::fread` in 64 KiB blocks using wide `_wfsopen(p.c_str(), L"rb", _SH_DENYNO)` to maintain wide-path support and non-exclusive sharing. - Verified that `std::ferror(file.get())` properly raises `runtime_error("cannot read ...")` when reads fail, preventing truncated file prefixes from being treated as clean EOF. - Checked `test_read_error` fixture in `pe_loader_test.cpp`: locks a trailing 64 KiB block via `LockFileEx` after a valid PE prefix to ensure failed reads leave no residual module in `loader.modules()`, followed by clean loading once unlocked via `UnlockFileEx`. 2. **Repository Integrity**: - `scripts/check_no_game_data.py`: clean. - `tests/test_text_write_line_endings.py`: 3/3 tests passed.
Author
Owner

@⁠aslan2142 on GitHub · 2026-11-25 19:43 UTC · original

I ran the runtime suite under Wine (llvmpipe and an AMD iGPU), merged onto current main. pe_loader fails on two checks:

  • "a failed PE read after a valid prefix reports an I/O error";
  • "a partial PE read leaves no module behind".

With main's pe_loader.cpp, the same two checks fail. So under Wine the locked-tail fixture doesn't produce a read error, and CI's Wine run would go red. Can the fixture force the error some way that works under Wine, or skip when the lock isn't enforced?

AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠aslan2142** on GitHub · 2026-11-25 19:43 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/664#issuecomment-7172692976) I ran the runtime suite under Wine (llvmpipe and an AMD iGPU), merged onto current `main`. `pe_loader` fails on two checks: - "a failed PE read after a valid prefix reports an I/O error"; - "a partial PE read leaves no module behind". With `main`'s `pe_loader.cpp`, the same two checks fail. So under Wine the locked-tail fixture doesn't produce a read error, and CI's Wine run would go red. Can the fixture force the error some way that works under Wine, or skip when the lock isn't enforced? AI-assisted (Claude Code, Claude Opus 5.5).
Author
Owner

@⁠sodove on GitHub · 2026-11-26 05:11 UTC · original

Fixed in d8cfc01d5. The fixture now probes the locked byte through the same CRT sharing mode as the loader. If the read succeeds, it skips the two assertions that require a read error and still verifies the complete PE loads after unlocking. Windows/MSVC ran all 86 checks, including both I/O assertions. I also tested the fallback with a shared lock that permits reads: it reproduced the two failures on the old fixture and passed on the new one. Wine itself was not available on this machine. AI-assisted.

**@⁠sodove** on GitHub · 2026-11-26 05:11 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/664#issuecomment-7183266487) Fixed in d8cfc01d5. The fixture now probes the locked byte through the same CRT sharing mode as the loader. If the read succeeds, it skips the two assertions that require a read error and still verifies the complete PE loads after unlocking. Windows/MSVC ran all 86 checks, including both I/O assertions. I also tested the fallback with a shared lock that permits reads: it reproduced the two failures on the old fixture and passed on the new one. Wine itself was not available on this machine. AI-assisted.
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/664/head:github-bot/gh-664'
git switch 'github-bot/gh-664'

Merge

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