Skip to content

Collapse VM contracts to STANDARD_VM_CONTRACT where equivalent - #132637

Draft
AaronRobinsonMSFT wants to merge 7 commits into
dotnet:mainfrom
AaronRobinsonMSFT:cleanup_contracts
Draft

Collapse VM contracts to STANDARD_VM_CONTRACT where equivalent#132637
AaronRobinsonMSFT wants to merge 7 commits into
dotnet:mainfrom
AaronRobinsonMSFT:cleanup_contracts

Conversation

@AaronRobinsonMSFT

Copy link
Copy Markdown
Member

Collapse expanded CONTRACTL blocks to STANDARD_VM_CONTRACT / STANDARD_VM_CHECK in the VM where semantically equivalent.

Helpers reachable from both cooperative and preemptive callers (metadata capture, static-field-address) are kept mode-agnostic to avoid adding an incorrect MODE_PREEMPTIVE check.

Validated with a Checked x64 build and the full System.Reflection test suite (1794 passed, 0 failed).

Note

This PR description was generated with assistance from GitHub Copilot.

AaronRobinsonMSFT and others added 3 commits August 20, 2026 11:40
Keep metadata-capture and static-field-address helpers mode-agnostic
since they are reachable from both cooperative and preemptive callers.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 52084f96-2cf7-43bf-8c38-3b9ac3baab4f
@AaronRobinsonMSFT AaronRobinsonMSFT added this to the 12.0.0 milestone Aug 21, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke
See info in area-owners.md if you want to be subscribed.

Comment thread src/coreclr/vm/genmeth.cpp Outdated
Comment thread src/coreclr/vm/threadsuspend.cpp Outdated
Co-authored-by: Aaron R Robinson <arobins@microsoft.com>
Comment thread src/coreclr/vm/gchelpers.cpp Outdated
@jkotas

jkotas commented Aug 21, 2026

Copy link
Copy Markdown
Member

Looks like we have a problem with sprintf in CONTRACT_ASSERT macro:

000000d1`1e1f8dc0 00007fff`4e072c97 ntdll!KiUserExceptionDispatcher+0x3a
000000d1`1e1f9b30 00007fff`4e073370 coreclr!common_strnlen_c<0,unsigned char>+0x57
000000d1`1e1f9b70 00007fff`4e072b26 coreclr!common_strnlen_simd<0,1,unsigned char>+0xc0
000000d1`1e1f9d00 00007fff`4e073f4d coreclr!common_strnlen<0,unsigned char>+0x26
000000d1`1e1f9d30 00007fff`4e069458 coreclr!strnlen+0x1d
000000d1`1e1f9d60 00007fff`4e068f62 coreclr!__crt_stdio_output::output_processor<char,__crt_stdio_output::string_output_adapter<char>,__crt_stdio_output::format_validation_base<char,__crt_stdio_output::string_output_adapter<char> > >::type_case_s_compute_narrow_string_length+0x28
000000d1`1e1f9d90 00007fff`4e062f52 coreclr!__crt_stdio_output::output_processor<char,__crt_stdio_output::string_output_adapter<char>,__crt_stdio_output::format_validation_base<char,__crt_stdio_output::string_output_adapter<char> > >::type_case_s+0x102
000000d1`1e1f9dd0 00007fff`4e05e5cf coreclr!__crt_stdio_output::output_processor<char,__crt_stdio_output::string_output_adapter<char>,__crt_stdio_output::format_validation_base<char,__crt_stdio_output::string_output_adapter<char> > >::state_case_type+0x82
000000d1`1e1f9e40 00007fff`4e050806 coreclr!__crt_stdio_output::output_processor<char,__crt_stdio_output::string_output_adapter<char>,__crt_stdio_output::format_validation_base<char,__crt_stdio_output::string_output_adapter<char> > >::process+0x34f
000000d1`1e1f9eb0 00007fff`4e051a41 coreclr!common_vsprintf<__crt_stdio_output::format_validation_base,char>+0x2a6
000000d1`1e1fa3e0 00007fff`4e06c4ba coreclr!common_vsprintf_s<char>+0x201
000000d1`1e1fa480 00007fff`4d77fb84 coreclr!__stdio_common_vsprintf_s+0x6a
(Inline Function) --------`-------- coreclr!_vsprintf_s_l+0x24
000000d1`1e1fa510 00007fff`4d762750 coreclr!sprintf_s+0x44
000000d1`1e1fa570 00007fff`4dd16679 coreclr!CONTRACT_ASSERT+0x210

@AaronRobinsonMSFT

Copy link
Copy Markdown
Member Author

Looks like we have a problem with sprintf in CONTRACT_ASSERT macro:

Yes, that has been this way for a while. There are certain code paths that if they assert during a contract will cause a failure. The issue is a stale link in the contract stack frame. I am going to start on that soon.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 52084f96-2cf7-43bf-8c38-3b9ac3baab4f
Comment thread src/coreclr/vm/methodtable.cpp Outdated
Comment thread src/coreclr/vm/methodtable.cpp Outdated
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread src/coreclr/debug/ee/debugger.cpp Outdated
@@ -1970,12 +1960,7 @@ HRESULT Debugger::StartupPhase2(Thread * pThread)

void Debugger::InitializeLazyDataIfNecessary()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Dead code - delete? It does not seem to be called anywhere.

Comment thread src/coreclr/debug/ee/debugger.cpp Outdated
GC_TRIGGERS;
}
CONTRACTL_END;
STANDARD_VM_CONTRACT;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I am not sure about this and other changed under debugger, and in eedbginterfaceimpl.cpp. Debugger often wants to do stuff in no-GC trigger mode. Have you been able to validate this with debugger tests on checked build of the runtime?

@AaronRobinsonMSFT

Copy link
Copy Markdown
Member Author

@jkotas @jkoritzinsky I pushed up a bunch of random changes I made on the branch. I need to audit them still. Please ignore this PR for now.

@AaronRobinsonMSFT AaronRobinsonMSFT added the NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) label Aug 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-VM-coreclr NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons)

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants