Skip to content

set null check offset to 0 - #123290

Closed
AndyAyersMS wants to merge 4 commits into
dotnet:mainfrom
AndyAyersMS:ZeroUncheckedOffset
Closed

AndyAyersMS wants to merge 4 commits into
dotnet:mainfrom
AndyAyersMS:ZeroUncheckedOffset

Conversation

@AndyAyersMS

Copy link
Copy Markdown
Member

No description provided.

@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 Jan 16, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @dotnet/jit-contrib
See info in area-owners.md if you want to be subscribed.

@AndyAyersMS

Copy link
Copy Markdown
Member Author

Diffs

Not surprisingly, large code size and TP impact. Though as Egor has pointed out above also some cases where code size got smaller.

@SingleAccretion

Copy link
Copy Markdown
Contributor

I think for correctness testing, we need to set the VM-side control of this value to zero as well, so that various [almost null] indirections actually get converted to AVs.

That said, it is a know quantity that we have many places in the Jit that assume this value is "somewhat larger" than 0. Almost all places that create indirections of the form [base + known_offset] have this problem (promoted struct copy decomposition, delegate invoke lower, memcpy expansions, array ops expansion, etc).

@AndyAyersMS

Copy link
Copy Markdown
Member Author

Let's see if setting the VM side to zero causes any new issues.

@AndyAyersMS

Copy link
Copy Markdown
Member Author

Looks like it doesn't...

@SingleAccretion

Copy link
Copy Markdown
Contributor

Looks like it doesn't...

It looks like the AV logic has this value duplicated in a different spot:

// If the address accessed is above 64k (Windows) or page size (Unix), then its an AccessViolationException.
if (pExceptionRecord->ExceptionInformation[1] >= NULL_AREA_SIZE)
{
return (DWORD) kAccessViolationException;
->
#ifndef TARGET_UNIX
// Windows uses 64kB as the null-reference area
#define NULL_AREA_SIZE (64 * 1024)
#else // !TARGET_UNIX
#define NULL_AREA_SIZE GetOsPageSize()
#endif // !TARGET_UNIX
.

@jkotas

jkotas commented Jan 18, 2026

Copy link
Copy Markdown
Member

It looks like the AV logic has this value duplicated in a different spot

This may be covering up for missing null checks. This test PR is not proving that the explicit null checks are complete. It is only proving that setting maxUncheckedOffsetForNullObject to 0 does not introduce major functional regressions.

@AndyAyersMS

Copy link
Copy Markdown
Member Author

Latest run with NULL_AREA_SIZE=1 has 284 test failures; random sampling shows access violations that presumably should have been null references, eg

  Starting:    System.Collections.Immutable.Tests (parallel test collections = on [2 threads], stop on fail = off)
Fatal error.
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at System.Collections.Immutable.ImmutableArray`1[[System.Int32, System.Private.CoreLib, Version=11.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].get_Length()

@SingleAccretion presumably this is what you expected to see?

@AndyAyersMS

Copy link
Copy Markdown
Member Author

/azp run coreclr-interpreter

@azure-pipelines

Copy link
Copy Markdown
No pipelines are associated with this pull request.

@AndyAyersMS

Copy link
Copy Markdown
Member Author

/azp run runtime-interpreter

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@SingleAccretion

Copy link
Copy Markdown
Contributor

presumably this is what you expected to see?

Yup.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Draft Pull Request was automatically closed for 30 days of inactivity. Please let us know if you'd like to reopen it.

@github-actions github-actions Bot locked and limited conversation to collaborators Mar 23, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants