Skip to content

Commit 84c1f62

Browse files
Sprinkle SuppressGCTransition across Unix shim P/Invokes (dotnet#39206)
* Sprinkle SuppressGCTransition across Unix shim P/Invokes Did a quick audit and added it to all the trivial functions that just return a constant or return some static or map one value to another or such things. * Address PR feedback * Update src/libraries/Native/Unix/System.Native/pal_io.c Co-authored-by: Aaron Robinson <arobins@microsoft.com> Co-authored-by: Aaron Robinson <arobins@microsoft.com>
1 parent df8d056 commit 84c1f62

15 files changed

Lines changed: 33 additions & 14 deletions

src/libraries/Common/src/Interop/Unix/Interop.Errors.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,11 @@ internal static unsafe string StrError(int platformErrno)
193193
private static extern unsafe byte* StrErrorR(int platformErrno, byte* buffer, int bufferSize);
194194
#else
195195
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_ConvertErrorPlatformToPal")]
196+
[SuppressGCTransition]
196197
internal static extern Error ConvertErrorPlatformToPal(int platformErrno);
197198

198199
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_ConvertErrorPalToPlatform")]
200+
[SuppressGCTransition]
199201
internal static extern int ConvertErrorPalToPlatform(Error error);
200202

201203
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_StrErrorR")]

src/libraries/Common/src/Interop/Unix/System.Native/Interop.Fcntl.Pipe.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ internal static partial class Fcntl
2020
internal static extern int SetPipeSz(SafePipeHandle fd, int size);
2121

2222
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_FcntlCanGetSetPipeSz")]
23+
[SuppressGCTransition]
2324
private static extern int FcntlCanGetSetPipeSz();
2425
}
2526
}

src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetDomainSocketSizes.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ internal static partial class Interop
99
internal static partial class Sys
1010
{
1111
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetDomainSocketSizes")]
12+
[SuppressGCTransition]
1213
internal static extern void GetDomainSocketSizes(out int pathOffset, out int pathSize, out int addressSize);
1314
}
1415
}

src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetMaximumAddressSize.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ internal static partial class Interop
99
internal static partial class Sys
1010
{
1111
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetMaximumAddressSize")]
12+
[SuppressGCTransition]
1213
internal static extern int GetMaximumAddressSize();
1314
}
1415
}

src/libraries/Common/src/Interop/Unix/System.Native/Interop.IPPacketInformation.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ internal struct IPPacketInformation
1717
}
1818

1919
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetControlMessageBufferSize")]
20-
internal static extern int GetControlMessageBufferSize(bool isIPv4, bool isIPv6);
20+
[SuppressGCTransition]
21+
internal static extern int GetControlMessageBufferSize(int isIPv4, int isIPv6);
2122

2223
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_TryGetIPPacketInformation")]
2324
internal static extern unsafe bool TryGetIPPacketInformation(MessageHeader* messageHeader, bool isIPv4, IPPacketInformation* packetInfo);

src/libraries/Common/src/Interop/Unix/System.Native/Interop.LChflags.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ internal enum UserFlags : uint
2020
internal static readonly bool CanSetHiddenFlag = (LChflagsCanSetHiddenFlag() != 0);
2121

2222
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_LChflagsCanSetHiddenFlag")]
23+
[SuppressGCTransition]
2324
private static extern int LChflagsCanSetHiddenFlag();
2425
}
2526
}

src/libraries/Common/src/Interop/Unix/System.Native/Interop.MapTcpState.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ internal static partial class Interop
99
internal static partial class Sys
1010
{
1111
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_MapTcpState")]
12+
[SuppressGCTransition]
1213
internal static extern TcpState MapTcpState(int nativeState);
1314
}
1415
}

src/libraries/Common/src/Interop/Unix/System.Native/Interop.PlatformSocketSupport.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ internal static partial class Interop
88
internal static partial class Sys
99
{
1010
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_PlatformSupportsDualModeIPv4PacketInfo")]
11-
internal static extern bool PlatformSupportsDualModeIPv4PacketInfo();
11+
[SuppressGCTransition]
12+
internal static extern int PlatformSupportsDualModeIPv4PacketInfo();
1213
}
1314
}

src/libraries/Common/src/Interop/Unix/System.Native/Interop.ReadDir.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ internal ReadOnlySpan<char> GetName(Span<char> buffer)
5757
internal static extern IntPtr OpenDir(string path);
5858

5959
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetReadDirRBufferSize", SetLastError = false)]
60+
[SuppressGCTransition]
6061
internal static extern int GetReadDirRBufferSize();
6162

6263
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_ReadDirR", SetLastError = false)]

src/libraries/Common/src/Interop/Unix/System.Native/Interop.RegisterForCtrlC.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ internal enum CtrlCode
1616
internal delegate void CtrlCallback(CtrlCode ctrlCode);
1717

1818
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_RegisterForCtrl")]
19+
[SuppressGCTransition]
1920
internal static extern void RegisterForCtrl(CtrlCallback handler);
2021

2122
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_UnregisterForCtrl")]
23+
[SuppressGCTransition]
2224
internal static extern void UnregisterForCtrl();
2325
}
2426
}

0 commit comments

Comments
 (0)