Partially revert #125574: restore fixed buffers in networking P/Invoke structs to fix Crst level violation#125664
Closed
Partially revert #125574: restore fixed buffers in networking P/Invoke structs to fix Crst level violation#125664
Conversation
…e structs Reverts the InlineArray<T> replacements in networking-related P/Invoke structs that were introduced by #125574. The generic InlineArray<byte> types (e.g., InlineArray16<byte>, InlineArray8<byte>) caused a Crst level violation: CrstLoaderAllocatorReferences (level 17) cannot be acquired while holding CrstILStubGen (level 14), which happens during IL stub generation for P/Invoke methods that use these structs. Reverted files: - Interop.EnumerateInterfaceAddresses.cs: restored fixed byte buffers - Interop.TcpConnectionInfo.cs: restored fixed byte buffers - All callers in System.Net.NetworkInformation updated to use pointer-based span construction Co-authored-by: jkotas <[email protected]>
Copilot
AI
changed the title
[WIP] Fix crst level violation for lock CrstLoaderAllocatorReferences
Partially revert #125574: restore fixed buffers in networking P/Invoke structs to fix Crst level violation
Mar 17, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR partially reverts #125574 in System.Net.NetworkInformation by restoring unsafe fixed byte[...] buffers in several Unix/BSD P/Invoke structs, avoiding generic InlineArray<T> type loading during IL stub generation that can trigger a CoreCLR Crst level violation on BSD/macOS.
Changes:
- Revert select networking interop structs from
InlineArray<T>back tounsafe fixed byte[...]buffers. - Update managed callers to construct spans from pointers (
new ReadOnlySpan<byte>(ptr, length)) and adjust UTF-8 name marshalling call sites. - Remove now-unneeded
System.Runtime.CompilerServicesusings from affected interop files.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/UnixNetworkInterface.cs | Updates link-layer MAC extraction to copy from fixed buffer. |
| src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkInterfacePal.Android.cs | Updates interface name marshalling to pass fixed buffer pointer directly. |
| src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/LinuxNetworkInterface.cs | Updates name marshalling and address/span construction for fixed buffers. |
| src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPAddressUtil.cs | Updates IPAddress construction to use pointer-based spans. |
| src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/BsdIpInterfaceProperties.cs | Updates gateway IPAddress construction to use pointer-based spans. |
| src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/BsdIPGlobalProperties.cs | Updates TCP/UDP endpoint IPAddress construction to use pointer-based spans. |
| src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/AndroidNetworkInterface.cs | Updates physical/MAC and IP address construction to use pointer-based spans. |
| src/libraries/Common/src/Interop/Unix/System.Native/Interop.EnumerateInterfaceAddresses.cs | Restores fixed buffers for link-layer/IP/interface info structs. |
| src/libraries/Common/src/Interop/BSD/System.Native/Interop.TcpConnectionInfo.cs | Restores fixed buffer for BSD IPEndPointInfo.AddressBytes. |
...ries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/UnixNetworkInterface.cs
Show resolved
Hide resolved
EgorBo
approved these changes
Mar 17, 2026
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.
PR #125574 replaced
unsafe fixed bytefields in several P/Invoke structs with genericInlineArray<T>types (e.g.,InlineArray16<byte>,InlineArray8<byte>). This exposed a pre-existing bug in the type loader.Partially revert #125574 to unblock the CI
Contributes to #125638