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

Merged
leonida/mandy
sodove merged 2 commits from perf/pe-block-reads into main 2026-11-28 17:59:08 +00:00

Pull request successfully merged and closed

sodove commented 2026-11-24 11:16:55 +00:00

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.

Claimed in the coordination issue as [RT-PE-BLOCK-READ](https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7128772845). The block-read implementation and original Wine measurements come from [cobrabm12's finding](https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7127781668). 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.
trigger337 commented 2026-11-24 11:42:22 +00:00

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.
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.
aslan2142 commented 2026-11-25 19:43:57 +00:00

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).

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).
sodove commented 2026-11-26 05:11:48 +00:00

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.

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.
MoonEyes commented 2026-11-28 17:59:03 +00:00

Red/green: On main pe_loader_test fails 2 checks (a failed PE read after a valid prefix reports no I/O error and a partial read leaves a module behind), and with the PR ctest -R "^pe_loader$" passes.
Independent tester (OreoFR, RTX 4070, Windows 11): PR head merged with the other PRs of its batch on main c1ecf04ed, full ctest run (485 tests, tests that launch the game excluded): no new failure compared with main.

Red/green: On main pe_loader_test fails 2 checks (a failed PE read after a valid prefix reports no I/O error and a partial read leaves a module behind), and with the PR ctest -R "^pe_loader$" passes. Independent tester (OreoFR, RTX 4070, Windows 11): PR head merged with the other PRs of its batch on main c1ecf04ed, full ctest run (485 tests, tests that launch the game excluded): no new failure compared with main.
OreoFR commented 2026-11-28 21:43:07 +00:00

Verified by OreoFR

  • Base: main c1ecf04ed + PR head d8cfc01d5; green run in a merge package of 9 PRs, no new ctest failure vs main
  • Test: ctest -R ^pe_loader$
  • Red on main: 2 failures (PE read failing after a valid prefix with no I/O error; module left after a partial read)
  • Green with the PR: OK
  • Verdict: READY
  • Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11

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

**Verified by OreoFR** - Base: main `c1ecf04ed` + PR head `d8cfc01d5`; green run in a merge package of 9 PRs, no new ctest failure vs main - Test: `ctest -R ^pe_loader$` - Red on main: 2 failures (PE read failing after a valid prefix with no I/O error; module left after a partial read) - Green with the PR: OK - Verdict: READY - Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11 AI-assisted (Claude Code, Claude Opus 5.5).
Sign in to join this conversation.
No description provided.