Skip to content

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

Closed
Copilot wants to merge 2 commits intomainfrom
copilot/fix-crst-level-violation
Closed

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

Conversation

Copy link
Contributor

Copilot AI commented Mar 17, 2026

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 <[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
Copilot AI requested a review from jkotas March 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 Copilot March 17, 2026 17:51
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

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
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.

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.

4 participants