Skip to content

Partially revert #125574: restore fixed buffers in networking P/Invoke structs to fix Crst level violation - #125664

Closed
jkotas with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-crst-level-violation
Closed

Partially revert #125574: restore fixed buffers in networking P/Invoke structs to fix Crst level violation#125664
jkotas with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-crst-level-violation

Conversation

CopilotAI commented Mar 17, 2026

Copy link
Copy Markdown
Contributor

PR #125574 replaced unsafe fixed byte fields in several P/Invoke structs with generic InlineArray<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

…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 <6668460+jkotas@users.noreply.github.com>
CopilotAI changed the title [WIP] Fix crst level violation for lock CrstLoaderAllocatorReferencesPartially revert #125574: restore fixed buffers in networking P/Invoke structs to fix Crst level violationMar 17, 2026
CopilotAI requested a review from jkotasMarch 17, 2026 17:49
@jkotas
jkotas marked this pull request as ready for review March 17, 2026 17:51
@jkotas
jkotas requested review from EgorBo and CopilotMarch 17, 2026 17:51

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 to unsafe 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.CompilerServices usings 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
FileDescription
src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/UnixNetworkInterface.csUpdates link-layer MAC extraction to copy from fixed buffer.
src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkInterfacePal.Android.csUpdates interface name marshalling to pass fixed buffer pointer directly.
src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/LinuxNetworkInterface.csUpdates name marshalling and address/span construction for fixed buffers.
src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPAddressUtil.csUpdates IPAddress construction to use pointer-based spans.
src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/BsdIpInterfaceProperties.csUpdates gateway IPAddress construction to use pointer-based spans.
src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/BsdIPGlobalProperties.csUpdates TCP/UDP endpoint IPAddress construction to use pointer-based spans.
src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/AndroidNetworkInterface.csUpdates physical/MAC and IP address construction to use pointer-based spans.
src/libraries/Common/src/Interop/Unix/System.Native/Interop.EnumerateInterfaceAddresses.csRestores fixed buffers for link-layer/IP/interface info structs.
src/libraries/Common/src/Interop/BSD/System.Native/Interop.TcpConnectionInfo.csRestores fixed buffer for BSD IPEndPointInfo.AddressBytes.

Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@EgorBo@jkotas