Skip to content

Fix inverted IsNull check in RangeSectionMap::EnumMemoryRangeSectionMapLevel#124862

Open
max-charlamb wants to merge 1 commit intomainfrom
fix/rangesectionmap-enum-isnull-inversion
Open

Fix inverted IsNull check in RangeSectionMap::EnumMemoryRangeSectionMapLevel#124862
max-charlamb wants to merge 1 commit intomainfrom
fix/rangesectionmap-enum-isnull-inversion

Conversation

@max-charlamb
Copy link
Member

@max-charlamb max-charlamb commented Feb 25, 2026

Summary

One-line fix: invert the IsNull() condition in the template overload of EnumMemoryRangeSectionMapLevel to match the non-template L1 overload.

Problem

The template overload of EnumMemoryRangeSectionMapLevel (handling levels L2–L5 on 64-bit) has an inverted condition at line 1553 of codeman.h:

// BUG: recurses into NULL entries, skips populated ones
if (level[i].IsNull())
{
    EnumMemoryRangeSectionMapLevel(flags, *level[i].VolatileLoad(pLockState), pLockState);
}

The non-template L1 overload at line 1538 correctly uses !IsNull():

// CORRECT: only recurse into populated entries
if (!level[i].IsNull())
{
    EnumMemoryRangeSectionMapLevel(flags, level[i], pLockState);
}

This bug means EnumMemoryRegions for the RangeSectionMap never enumerates anything below the top level on 64-bit (where levels L2–L5 use the template), and attempts to dereference null pointers for empty slots. This could cause incomplete DAC memory enumeration during dump generation.

…apLevel

The template overload of EnumMemoryRangeSectionMapLevel (handling levels
L2-L5 on 64-bit) had an inverted condition: it called IsNull() without
negation, causing it to skip all populated entries and attempt to
dereference null pointers. The non-template L1 overload at line 1538
correctly uses !IsNull().

This bug meant EnumMemoryRegions for the RangeSectionMap never actually
enumerated anything below the top level on 64-bit, potentially causing
incomplete dumps where RangeSection data is missing.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings February 25, 2026 16:18
@github-actions github-actions bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Feb 25, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a logic bug in CoreCLR’s DAC memory enumeration for RangeSectionMap by making the template recursion (used for deeper map levels on 64-bit) skip null entries and only recurse into populated ones, matching the L1 non-template overload.

Changes:

  • Invert the IsNull() condition in RangeSectionMap::EnumMemoryRangeSectionMapLevel (template overload) to avoid recursing into null slots and skipping valid ones.

@jkotas jkotas added area-Diagnostics-coreclr and removed area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI labels Feb 25, 2026
@jkotas
Copy link
Member

jkotas commented Feb 25, 2026

Is this enough to make your test pass or is there more?

@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag
See info in area-owners.md if you want to be subscribed.

@max-charlamb
Copy link
Member Author

Is this enough to make your test pass or is there more?

I don't know for sure. The failing SOS test does not produce a dump. I am working on adding a dump, but it requires a non-deterministic run on CI.

With copilot, I found several bugs in the unwinder which could have impacted the stackwalk:
#124845
#124848

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants