This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
[Local GC] Fix (another) ScanContext layout issue when building without FEATURE_REDHAWK #14777
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.
Fundamentally this is the same issue as #14747 -
FEATURE_REDHAWK
is currently defined for a standalone GC and thus_unused2
is not included in theScanContext
. This presents much differently than the previous issue, though - an out-of-bounds write to aScanContext
on the GC's stack this time clobbers the stack slot that MSVC has previously used to saverdi
, which results ingc_heap::relocate_phase
trashingrdi
when it shouldn't. The function that callsrelocate_phase
has allocated the constant 0 forrdi
, so all uses of the constant 0 (namely, booleanfalse
) become not-false in the function that callsrelocate_phase
and false literals magically become true.The end result is that the GC crashes because it attempted to write a (literal) 0 to a global variable, but 0 (rdi) was actually the random value that
gc_heap::relocate_phase
trashed it with. This non-zero global variable (the mark stack TOS) eventually causes us to read garbage memory.This PR fixes the issue by actually fixing the underlying layout problem:
After this fix, checked and release standalone GCs pass all functional tests. (This doesn't repro on Debug builds).
I think this one took some time off of my life... @sergiy-k PTAL?