Repository navigation
engine: fault guest reads on the requested access size instead of always 8 bytes - #2
Open
bluetoe-99 wants to merge 2 commits into
Open
bluetoe-99 wants to merge 2 commits into
bluetoe-99 wants to merge 2 commits into
Conversation
bluetoe-99
force-pushed
the
feature/tier1-ldr-prepost-index
branch
from
October 29, 2026 15:50
4e49723 to
4900c88
Compare
bluetoe-99
force-pushed
the
feature/engine-sized-guest-read
branch
from
October 29, 2026 15:50
3a5a81a to
646707a
Compare
bluetoe-99
force-pushed
the
feature/tier1-ldr-prepost-index
branch
from
October 29, 2026 19:21
4900c88 to
877a93a
Compare
bluetoe-99
force-pushed
the
feature/engine-sized-guest-read
branch
from
October 29, 2026 19:21
646707a to
c057245
Compare
bluetoe-99
force-pushed
the
feature/tier1-ldr-prepost-index
branch
from
October 29, 2026 19:46
877a93a to
38a2bc3
Compare
bluetoe-99
force-pushed
the
feature/engine-sized-guest-read
branch
from
October 29, 2026 19:46
c057245 to
f6f6822
Compare
The tier1 LDR lowering now passes the instruction's access width (bits 31-30 as a power of two: 1/2/4/8) as the third helper argument. guest_read faults only when the actual access is unreadable, matching the reference engine's per-access fault granularity. Reads that previously faulted spuriously near region ends (e.g. an LDRB at the last byte) now execute correctly. Signed-off-by: bluetoe-99 <102478736+bluetoe-99@users.noreply.github.com>
Four differential unit tests: a 64-bit read ending flush with the region end still succeeds, a byte read at the last byte succeeds where a full-width read would fault, and halfword and 64-bit reads crossing the end still fault with BAL_ERROR_MEMORY_FAULT. Signed-off-by: bluetoe-99 <102478736+bluetoe-99@users.noreply.github.com>
bluetoe-99
force-pushed
the
feature/engine-sized-guest-read
branch
from
October 29, 2026 20:22
f6f6822 to
45d9d99
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
guest_readalways reads 8 bytes and faults unlessmax_readable_bytes >= 8, so a byte load at the last readable byte of a region faults even though the architecture only asked for 1 byte. The reference engine faults at the access's own granularity, not at 8 bytes. This is the remaining baseline fuzzer error class reported in the upstream LDR pre/post PR (397FFC00and theFF C00family at every width).This PR is stacked on
feature/tier1-ldr-prepost-index: the JIT stub changed here sits inside that branch'stranslate_ldrhunks. This PR's diff is the lane only (+94/-11); it will be retargeted upstream once that PR merges.Change
The Tier 1 LDR lowering passes the instruction's access width as a third helper argument:
1 << bits[31:30](0 byte, 1 halfword, 2 word, 3 doubleword). That formula covers the whole immediate and register-offset LDR group, including LDRB/LDRH/LDRSB/LDRSH/LDRSW, since they all route through the singletranslate_ldrstub. The engine faults only when the requested size exceedsmax_readable_bytesand copies exactly that many bytes into a zero-initializeduint64_t.include/backend/bal_cpu.h: one typedef (read_sizeparameter). The JIT stub is the only other consumer of the function pointer.src/bal_engine.c: range guard (1..8), size-based fault check, sizedmemcpy.src/backend/x86/bal_x86_tier1_compiler.c:BAL_X86_ABI_ARG3(R8on Windows,RDXon SysV) plus oneMOV_REGISTER_IMMEDIATEbefore the call. The third argument is caller-saved and already clobbered by the existing call, so no allocator impact.Fault behavior is strictly monotone:
max_readable < sizewithsize <= 8is a subset of the oldmax_readable < 8, so this change can only remove faults, never add one.Fuzz evidence (full 60,389-seed corpus, identical order and worker state on both sides)
To compare against main without its 6-error early stop, a diagnostic copy of
de07fcaawas built with the cap raised (scratch build, not committed).de07fcaa(cap raised)39x/79x FF C00families, and 6 became oracle skips because of the harness order in the LDR pre/post PR.The extra failed seeds this branch does show (78 beyond the known 26 sign-extension ones) were never executed by any previous run because main stops at 6 errors. They are pre-existing flag/ADC-family mismatches, shown by the same-context full-corpus comparison above.
Unit tests
20 tests in
test_bal_tier1_ldr(16 from the LDR pre/post PR plus 4 new): a 64-bit read ending flush with the region end still succeeds, a byte read at the last byte succeeds where a full-width read would fault, and halfword and 64-bit reads crossing the end still fault withBAL_ERROR_MEMORY_FAULT. Full suite: ctest 15/15 green, Clang 18 Debug, generated decoder tables byte-identical to main.