From 90a7b23aeecda92c90a32f4b78cdec2bc13bdb8a Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Fri, 6 Sep 2024 17:12:53 +0200 Subject: [PATCH 01/19] rebase --- .../Unix/System.Native/Interop.GetHostName.cs | 4 + .../Unix/System.Native/Interop.HostEntry.cs | 1 + .../Directory.Build.props | 3 +- .../src/System.Net.NameResolution.csproj | 46 +- .../src/System/Net/Dns.cs | 47 ++ .../src/System/Net/NameResolutionPal.Unix.cs | 10 + .../Net/NameResolutionTelemetry.Wasi.cs | 44 ++ .../FunctionalTests/GetHostAddressesTest.cs | 6 +- .../FunctionalTests/GetHostByAddressTest.cs | 1 + .../FunctionalTests/GetHostByNameTest.cs | 3 +- .../tests/FunctionalTests/GetHostEntryTest.cs | 20 + .../tests/FunctionalTests/LoggingTest.cs | 1 + .../tests/FunctionalTests/MetricsTest.cs | 1 + .../tests/FunctionalTests/ResolveTest.cs | 1 + ...Net.NameResolution.Functional.Tests.csproj | 7 +- .../tests/FunctionalTests/TelemetryTest.cs | 1 + .../tests/PalTests/NameResolutionPalTests.cs | 7 + ...System.Net.NameResolution.Pal.Tests.csproj | 11 +- .../System.Net.Primitives.Pal.Tests.csproj | 2 +- .../System/Environment.MachineName.cs | 2 +- src/libraries/tests.proj | 1 + src/native/libs/System.Native/CMakeLists.txt | 3 +- .../libs/System.Native/pal_networking.c | 155 +++++- .../libs/System.Native/pal_networking.h | 1 + .../libs/System.Native/pal_networking_wasi.c | 443 ------------------ src/native/libs/configure.cmake | 5 +- 26 files changed, 348 insertions(+), 478 deletions(-) create mode 100644 src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionTelemetry.Wasi.cs delete mode 100644 src/native/libs/System.Native/pal_networking_wasi.c diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetHostName.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetHostName.cs index 5cc0c19772753..3f109bf1a5c96 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetHostName.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetHostName.cs @@ -14,6 +14,7 @@ internal static partial class Sys internal static unsafe string GetHostName() { +#if !TARGET_WASI const int HOST_NAME_MAX = 255; const int ArrLength = HOST_NAME_MAX + 1; @@ -34,6 +35,9 @@ internal static unsafe string GetHostName() name[ArrLength - 1] = 0; return Marshal.PtrToStringUTF8((IntPtr)name)!; +#else + return "localhost"; +#endif } } } diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.HostEntry.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.HostEntry.cs index b8bc38524a59c..8d00d95ebf214 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.HostEntry.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.HostEntry.cs @@ -21,6 +21,7 @@ internal enum GetAddrInfoErrorFlags : int EAI_BADARG = 6, // One or more input arguments were invalid. EAI_NOMORE = 7, // No more entries are present in the list. EAI_MEMORY = 8, // Out of memory. + EAI_SYSTEM = 9, // Other system error; errno is set to indicate the error. } [StructLayout(LayoutKind.Sequential)] diff --git a/src/libraries/System.Net.NameResolution/Directory.Build.props b/src/libraries/System.Net.NameResolution/Directory.Build.props index bc799605d32ed..ce244cbea5619 100644 --- a/src/libraries/System.Net.NameResolution/Directory.Build.props +++ b/src/libraries/System.Net.NameResolution/Directory.Build.props @@ -3,7 +3,6 @@ Microsoft true - - browser;wasi + browser \ No newline at end of file diff --git a/src/libraries/System.Net.NameResolution/src/System.Net.NameResolution.csproj b/src/libraries/System.Net.NameResolution/src/System.Net.NameResolution.csproj index c5c8b4ffc9a58..2be977f33fe7b 100644 --- a/src/libraries/System.Net.NameResolution/src/System.Net.NameResolution.csproj +++ b/src/libraries/System.Net.NameResolution/src/System.Net.NameResolution.csproj @@ -9,16 +9,17 @@ $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) - SR.SystemNetNameResolution_PlatformNotSupported - ExcludeApiList.PNSE.Browser.txt + SR.SystemNetNameResolution_PlatformNotSupported + ExcludeApiList.PNSE.Browser.txt + $(DefineConstants);TARGET_WASI - - - + + + @@ -96,7 +97,40 @@ Link="Common\Interop\Unix\System.Native\Interop.SocketAddress.cs" /> - + + + + + + + + + + + + + + + + + + + + + diff --git a/src/libraries/System.Net.NameResolution/src/System/Net/Dns.cs b/src/libraries/System.Net.NameResolution/src/System/Net/Dns.cs index c8a526ccc4b3c..e1c9866929ab1 100644 --- a/src/libraries/System.Net.NameResolution/src/System/Net/Dns.cs +++ b/src/libraries/System.Net.NameResolution/src/System/Net/Dns.cs @@ -7,6 +7,7 @@ using System.Net.Sockets; using System.Threading; using System.Threading.Tasks; +using System.Runtime.Versioning; namespace System.Net { @@ -37,6 +38,9 @@ public static string GetHostName() public static IPHostEntry GetHostEntry(IPAddress address) { +#if TARGET_WASI + if (OperatingSystem.IsWasi()) throw new PlatformNotSupportedException(); // TODO remove with https://github.com/dotnet/runtime/pull/107185 +#endif // TARGET_WASI ArgumentNullException.ThrowIfNull(address); if (address.Equals(IPAddress.Any) || address.Equals(IPAddress.IPv6Any)) @@ -68,6 +72,7 @@ public static IPHostEntry GetHostEntry(string hostNameOrAddress, AddressFamily f // See if it's an IP Address. IPHostEntry ipHostEntry; +#if !TARGET_WASI if (IPAddress.TryParse(hostNameOrAddress, out IPAddress? address)) { if (address.Equals(IPAddress.Any) || address.Equals(IPAddress.IPv6Any)) @@ -79,6 +84,7 @@ public static IPHostEntry GetHostEntry(string hostNameOrAddress, AddressFamily f ipHostEntry = GetHostEntryCore(address, family); } else +#endif // TARGET_WASI { ipHostEntry = GetHostEntryCore(hostNameOrAddress, family); } @@ -147,6 +153,9 @@ public static Task GetHostEntryAsync(string hostNameOrAddress, Addr public static Task GetHostEntryAsync(IPAddress address) { +#if TARGET_WASI + throw new PlatformNotSupportedException(); // TODO remove with https://github.com/dotnet/runtime/pull/107185 +#else ArgumentNullException.ThrowIfNull(address); if (address.Equals(IPAddress.Any) || address.Equals(IPAddress.IPv6Any)) @@ -160,6 +169,7 @@ public static Task GetHostEntryAsync(IPAddress address) if (NetEventSource.Log.IsEnabled()) NetEventSource.Info((IPAddress)s, $"{ipHostEntry} with {ipHostEntry.AddressList.Length} entries"); return ipHostEntry; }, address, CancellationToken.None); +#endif // TARGET_WASI } public static IAsyncResult BeginGetHostEntry(IPAddress address, AsyncCallback? requestCallback, object? stateObject) => @@ -170,6 +180,9 @@ public static IAsyncResult BeginGetHostEntry(string hostNameOrAddress, AsyncCall public static IPHostEntry EndGetHostEntry(IAsyncResult asyncResult) { +#if TARGET_WASI + if (OperatingSystem.IsWasi()) throw new PlatformNotSupportedException(); // TODO remove with https://github.com/dotnet/runtime/pull/107185 +#endif // TARGET_WASI ArgumentNullException.ThrowIfNull(asyncResult); return TaskToAsyncResult.End(asyncResult); @@ -192,6 +205,7 @@ public static IPAddress[] GetHostAddresses(string hostNameOrAddress, AddressFami // See if it's an IP Address. IPAddress[] addresses; +#if TARGET_WASI if (IPAddress.TryParse(hostNameOrAddress, out IPAddress? address)) { if (address.Equals(IPAddress.Any) || address.Equals(IPAddress.IPv6Any)) @@ -203,6 +217,7 @@ public static IPAddress[] GetHostAddresses(string hostNameOrAddress, AddressFami addresses = (family == AddressFamily.Unspecified || address.AddressFamily == family) ? new IPAddress[] { address } : Array.Empty(); } else +#endif // TARGET_WASI { addresses = GetHostAddressesCore(hostNameOrAddress, family); } @@ -244,6 +259,9 @@ public static IAsyncResult BeginGetHostAddresses(string hostNameOrAddress, Async public static IPAddress[] EndGetHostAddresses(IAsyncResult asyncResult) { +#if TARGET_WASI + if (OperatingSystem.IsWasi()) throw new PlatformNotSupportedException(); // TODO remove with https://github.com/dotnet/runtime/pull/107185 +#endif // TARGET_WASI ArgumentNullException.ThrowIfNull(asyncResult); return TaskToAsyncResult.End(asyncResult); @@ -269,6 +287,9 @@ public static IAsyncResult BeginGetHostByName(string hostName, AsyncCallback? re [Obsolete("EndGetHostByName has been deprecated. Use EndGetHostEntry instead.")] public static IPHostEntry EndGetHostByName(IAsyncResult asyncResult) { +#if TARGET_WASI + if (OperatingSystem.IsWasi()) throw new PlatformNotSupportedException(); // TODO remove with https://github.com/dotnet/runtime/pull/107185 +#endif // TARGET_WASI ArgumentNullException.ThrowIfNull(asyncResult); return TaskToAsyncResult.End(asyncResult); @@ -277,6 +298,9 @@ public static IPHostEntry EndGetHostByName(IAsyncResult asyncResult) [Obsolete("GetHostByAddress has been deprecated. Use GetHostEntry instead.")] public static IPHostEntry GetHostByAddress(string address) { +#if TARGET_WASI + if (OperatingSystem.IsWasi()) throw new PlatformNotSupportedException(); // TODO remove with https://github.com/dotnet/runtime/pull/107185 +#endif // TARGET_WASI ArgumentNullException.ThrowIfNull(address); IPHostEntry ipHostEntry = GetHostEntryCore(IPAddress.Parse(address), AddressFamily.Unspecified); @@ -288,6 +312,9 @@ public static IPHostEntry GetHostByAddress(string address) [Obsolete("GetHostByAddress has been deprecated. Use GetHostEntry instead.")] public static IPHostEntry GetHostByAddress(IPAddress address) { +#if TARGET_WASI + if (OperatingSystem.IsWasi()) throw new PlatformNotSupportedException(); // TODO remove with https://github.com/dotnet/runtime/pull/107185 +#endif // TARGET_WASI ArgumentNullException.ThrowIfNull(address); IPHostEntry ipHostEntry = GetHostEntryCore(address, AddressFamily.Unspecified); @@ -303,6 +330,7 @@ public static IPHostEntry Resolve(string hostName) // See if it's an IP Address. IPHostEntry ipHostEntry; +#if !TARGET_WASI if (IPAddress.TryParse(hostName, out IPAddress? address) && (address.AddressFamily != AddressFamily.InterNetworkV6 || SocketProtocolSupportPal.OSSupportsIPv6)) { @@ -317,6 +345,7 @@ public static IPHostEntry Resolve(string hostName) } } else +#endif // TARGET_WASI { ipHostEntry = GetHostEntryCore(hostName, AddressFamily.Unspecified); } @@ -332,6 +361,9 @@ public static IAsyncResult BeginResolve(string hostName, AsyncCallback? requestC [Obsolete("EndResolve has been deprecated. Use EndGetHostEntry instead.")] public static IPHostEntry EndResolve(IAsyncResult asyncResult) { +#if TARGET_WASI + if (OperatingSystem.IsWasi()) throw new PlatformNotSupportedException(); // TODO remove with https://github.com/dotnet/runtime/pull/107185 +#endif // TARGET_WASI IPHostEntry ipHostEntry; try @@ -405,13 +437,16 @@ private static object GetHostEntryOrAddressesCore(string hostName, bool justAddr return result; } + [UnsupportedOSPlatform("wasi")] private static IPHostEntry GetHostEntryCore(IPAddress address, AddressFamily addressFamily, NameResolutionActivity? activityOrDefault = default) => (IPHostEntry)GetHostEntryOrAddressesCore(address, justAddresses: false, addressFamily, activityOrDefault); + [UnsupportedOSPlatform("wasi")] private static IPAddress[] GetHostAddressesCore(IPAddress address, AddressFamily addressFamily, NameResolutionActivity? activityOrDefault = default) => (IPAddress[])GetHostEntryOrAddressesCore(address, justAddresses: true, addressFamily, activityOrDefault); // Does internal IPAddress reverse and then forward lookups (for Legacy and current public methods). + [UnsupportedOSPlatform("wasi")] private static object GetHostEntryOrAddressesCore(IPAddress address, bool justAddresses, AddressFamily addressFamily, NameResolutionActivity? activityOrDefault = default) { // Try to get the data for the host from its address. @@ -499,6 +534,7 @@ private static Task GetHostEntryOrAddressesCoreAsync(string hostName, bool justR object asyncState; +#if !TARGET_WASI // See if it's an IP Address. if (IPAddress.TryParse(hostName, out IPAddress? ipAddress)) { @@ -518,6 +554,7 @@ private static Task GetHostEntryOrAddressesCoreAsync(string hostName, bool justR asyncState = family == AddressFamily.Unspecified ? (object)ipAddress : new KeyValuePair(ipAddress, family); } else +#endif // TARGET_WASI { if (NameResolutionPal.SupportsGetAddrInfoAsync) { @@ -558,8 +595,13 @@ private static Task GetHostEntryOrAddressesCoreAsync(string hostName, bool justR { string h => GetHostAddressesCore(h, AddressFamily.Unspecified, activity), KeyValuePair t => GetHostAddressesCore(t.Key, t.Value, activity), +#if !TARGET_WASI IPAddress a => GetHostAddressesCore(a, AddressFamily.Unspecified, activity), KeyValuePair t => GetHostAddressesCore(t.Key, t.Value, activity), +#else + IPAddress => throw new PlatformNotSupportedException(), + KeyValuePair => throw new PlatformNotSupportedException(), +#endif // TARGET_WASI _ => null }, asyncState, cancellationToken); } @@ -569,8 +611,13 @@ private static Task GetHostEntryOrAddressesCoreAsync(string hostName, bool justR { string h => GetHostEntryCore(h, AddressFamily.Unspecified, activity), KeyValuePair t => GetHostEntryCore(t.Key, t.Value, activity), +#if !TARGET_WASI IPAddress a => GetHostEntryCore(a, AddressFamily.Unspecified, activity), KeyValuePair t => GetHostEntryCore(t.Key, t.Value, activity), +#else + IPAddress => throw new PlatformNotSupportedException(), + KeyValuePair => throw new PlatformNotSupportedException(), +#endif // TARGET_WASI _ => null }, asyncState, cancellationToken); } diff --git a/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionPal.Unix.cs b/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionPal.Unix.cs index 54ec640a3b071..29674b806a1fe 100644 --- a/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionPal.Unix.cs +++ b/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionPal.Unix.cs @@ -39,6 +39,12 @@ private static SocketError GetSocketErrorForNativeError(int error) return SocketError.HostNotFound; case (int)Interop.Sys.GetAddrInfoErrorFlags.EAI_MEMORY: throw new OutOfMemoryException(); + case (int)Interop.Sys.GetAddrInfoErrorFlags.EAI_SYSTEM: +#if !TARGET_WASI + return SocketError.SocketError; +#else + throw new Exception("ErrNo: " + Interop.Sys.GetErrNo()); +#endif default: Debug.Fail($"Unexpected error: {error}"); return SocketError.SocketError; @@ -146,6 +152,7 @@ public static unsafe SocketError TryGetAddrInfo(string name, bool justAddresses, public static unsafe string? TryGetNameInfo(IPAddress addr, out SocketError socketError, out int nativeErrorCode) { +#if !TARGET_WASI byte* buffer = stackalloc byte[Interop.Sys.NI_MAXHOST + 1 /*for null*/]; byte isIPv6; @@ -178,6 +185,9 @@ public static unsafe SocketError TryGetAddrInfo(string name, bool justAddresses, socketError = GetSocketErrorForNativeError(error); nativeErrorCode = error; return socketError == SocketError.Success ? Marshal.PtrToStringUTF8((IntPtr)buffer) : null; +#else + throw new PlatformNotSupportedException(); +#endif } public static string GetHostName() => Interop.Sys.GetHostName(); diff --git a/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionTelemetry.Wasi.cs b/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionTelemetry.Wasi.cs new file mode 100644 index 0000000000000..d4842f1656946 --- /dev/null +++ b/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionTelemetry.Wasi.cs @@ -0,0 +1,44 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Collections.Generic; +using System.Diagnostics; +using System.Diagnostics.Tracing; +using System.Net.Sockets; +using System.Threading; +using System.Runtime.Versioning; + +namespace System.Net +{ +#pragma warning disable IDE0060 +#pragma warning disable CA1822 + internal sealed class NameResolutionTelemetry : EventSource + { + public static readonly NameResolutionTelemetry Log = new NameResolutionTelemetry(); + + [NonEvent] + public static bool AnyDiagnosticsEnabled() + { + return false; + } + + [NonEvent] + public NameResolutionActivity BeforeResolution(object hostNameOrAddress, long startingTimestamp = 0) + { + return default; + } + + [NonEvent] + public void AfterResolution(object hostNameOrAddress, in NameResolutionActivity activity, object? answer, Exception? exception = null) + { + } + } + + internal readonly struct NameResolutionActivity + { + public static bool IsTracingEnabled() + { + return false; + } + } +} diff --git a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostAddressesTest.cs b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostAddressesTest.cs index 71820b8cc72f7..d1073db5d3986 100644 --- a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostAddressesTest.cs +++ b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostAddressesTest.cs @@ -69,14 +69,14 @@ public async Task Dns_GetHostAddressesAsync_NullHost_Fail() await Assert.ThrowsAsync(() => Dns.GetHostAddressesAsync(null)); } - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] public void DnsBeginGetHostAddresses_BadName_Throws() { IAsyncResult asyncObject = Dns.BeginGetHostAddresses("BadName", null, null); Assert.ThrowsAny(() => Dns.EndGetHostAddresses(asyncObject)); } - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] public void DnsBeginGetHostAddresses_BadIpString_ReturnsAddress() { IAsyncResult asyncObject = Dns.BeginGetHostAddresses("0.0.1.1", null, null); @@ -86,7 +86,7 @@ public void DnsBeginGetHostAddresses_BadIpString_ReturnsAddress() Assert.Equal(IPAddress.Parse("0.0.1.1"), results[0]); } - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] public void DnsBeginGetHostAddresses_MachineName_MatchesGetHostAddresses() { IAsyncResult asyncObject = Dns.BeginGetHostAddresses(TestSettings.LocalHost, null, null); diff --git a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostByAddressTest.cs b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostByAddressTest.cs index a9072c6506faa..6a6b237b0d938 100644 --- a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostByAddressTest.cs +++ b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostByAddressTest.cs @@ -8,6 +8,7 @@ namespace System.Net.NameResolution.Tests { + [SkipOnPlatform(TestPlatforms.Wasi, "WASI has no getnameinfo")] public class GetHostByAddressTest { [Fact] diff --git a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostByNameTest.cs b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostByNameTest.cs index 56f52afb1b7da..479a5cd39ac35 100644 --- a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostByNameTest.cs +++ b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostByNameTest.cs @@ -19,7 +19,7 @@ public void DnsObsoleteBeginGetHostByName_BadName_Throws() Assert.ThrowsAny(() => Dns.EndGetHostByName(asyncObject)); } - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] public void DnsObsoleteBeginGetHostByName_IPv4String_ReturnsOnlyGivenIP() { IAsyncResult asyncObject = Dns.BeginGetHostByName(IPAddress.Loopback.ToString(), null, null); @@ -106,6 +106,7 @@ public void DnsObsoleteGetHostByName_IPv6String_ReturnsOnlyGivenIP() [ActiveIssue("https://github.com/dotnet/runtime/issues/1488", TestPlatforms.OSX)] [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotArm64Process))] // [ActiveIssue("https://github.com/dotnet/runtime/issues/27622")] [ActiveIssue("https://github.com/dotnet/runtime/issues/51377", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)] + [ActiveIssue("https://github.com/dotnet/runtime/issues/107339", TestPlatforms.Wasi)] public void DnsObsoleteGetHostByName_EmptyString_ReturnsHostName() { IPHostEntry entry = Dns.GetHostByName(""); diff --git a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostEntryTest.cs b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostEntryTest.cs index a4a7174897a39..5ca558b9316bd 100644 --- a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostEntryTest.cs +++ b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostEntryTest.cs @@ -148,10 +148,16 @@ public async Task Dns_GetHostEntry_NullStringHost_Fail() { Assert.Throws(() => Dns.GetHostEntry((string)null)); await Assert.ThrowsAsync(() => Dns.GetHostEntryAsync((string)null)); + } + + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + public async Task Dns_GetHostEntry_NullStringHost_Fail_Obsolete() + { await Assert.ThrowsAsync(() => Task.Factory.FromAsync(Dns.BeginGetHostEntry, Dns.EndGetHostEntry, (string)null, null)); } [Fact] + [SkipOnPlatform(TestPlatforms.Wasi, "WASI has no getnameinfo")] public async Task Dns_GetHostEntryAsync_NullIPAddressHost_Fail() { Assert.Throws(() => Dns.GetHostEntry((IPAddress)null)); @@ -168,6 +174,7 @@ public static IEnumerable GetInvalidAddresses() [Theory] [MemberData(nameof(GetInvalidAddresses))] + [SkipOnPlatform(TestPlatforms.Wasi, "WASI has no getnameinfo")] public async Task Dns_GetHostEntry_AnyIPAddress_Fail(IPAddress address) { Assert.Throws(() => Dns.GetHostEntry(address)); @@ -195,6 +202,7 @@ public async Task DnsGetHostEntry_MachineName_AllVariationsMatch() } [Fact] + [SkipOnPlatform(TestPlatforms.Wasi, "WASI has no getnameinfo")] public async Task DnsGetHostEntry_Loopback_AllVariationsMatch() { IPHostEntry syncResult = Dns.GetHostEntry(IPAddress.Loopback); @@ -216,6 +224,7 @@ public async Task DnsGetHostEntry_Loopback_AllVariationsMatch() [InlineData("Really.Long.Name.Over.One.Hundred.And.Twenty.Six.Chars.Eeeeeeeventualllllllly.I.Will.Get.To.The.Eeeee" + "eeeeend.Almost.There.Are.We.Really.Long.Name.Over.One.Hundred.And.Twenty.Six.Chars.Eeeeeeeventualll" + "llllly.I.Will.Get.To.The.Eeeeeeeeeend.Almost.There.Are")] // very long name but not too long + [ActiveIssue("https://github.com/dotnet/runtime/issues/107339", TestPlatforms.Wasi)] public async Task DnsGetHostEntry_BadName_ThrowsSocketException(string hostNameOrAddress) { Assert.ThrowsAny(() => Dns.GetHostEntry(hostNameOrAddress)); @@ -231,6 +240,14 @@ public async Task DnsGetHostEntry_BadName_ThrowsArgumentOutOfRangeException(stri { Assert.ThrowsAny(() => Dns.GetHostEntry(hostNameOrAddress)); await Assert.ThrowsAnyAsync(() => Dns.GetHostEntryAsync(hostNameOrAddress)); + } + + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + [InlineData("Really.Long.Name.Over.One.Hundred.And.Twenty.Six.Chars.Eeeeeeeventualllllllly.I.Will.Get.To.The.Eeeee" + + "eeeeend.Almost.There.Are.We.Really.Long.Name.Over.One.Hundred.And.Twenty.Six.Chars.Eeeeeeeventualll" + + "llllly.I.Will.Get.To.The.Eeeeeeeeeend.Almost.There.Aret")] + public async Task DnsGetHostEntry_BadName_ThrowsArgumentOutOfRangeException_Obsolete(string hostNameOrAddress) + { await Assert.ThrowsAnyAsync(() => Task.Factory.FromAsync(Dns.BeginGetHostEntry, Dns.EndGetHostEntry, hostNameOrAddress, null)); } @@ -238,6 +255,7 @@ public async Task DnsGetHostEntry_BadName_ThrowsArgumentOutOfRangeException(stri [InlineData(0)] [InlineData(1)] [InlineData(2)] + [ActiveIssue("https://github.com/dotnet/runtime/issues/107339", TestPlatforms.Wasi)] public async Task DnsGetHostEntry_LocalHost_ReturnsFqdnAndLoopbackIPs(int mode) { IPHostEntry entry = mode switch @@ -256,7 +274,9 @@ public async Task DnsGetHostEntry_LocalHost_ReturnsFqdnAndLoopbackIPs(int mode) [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] [InlineData(0)] [InlineData(1)] +#if !TARGET_WASI [InlineData(2)] +#endif public async Task DnsGetHostEntry_LoopbackIP_MatchesGetHostEntryLoopbackString(int mode) { IPAddress address = IPAddress.Loopback; diff --git a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/LoggingTest.cs b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/LoggingTest.cs index 920a5af60cf00..9c443cc991135 100644 --- a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/LoggingTest.cs +++ b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/LoggingTest.cs @@ -15,6 +15,7 @@ namespace System.Net.NameResolution.Tests using Configuration = System.Net.Test.Common.Configuration; [Collection(nameof(DisableParallelization))] + [SkipOnPlatform(TestPlatforms.Wasi, "WASI has event source yet")] public class LoggingTest { [Fact] diff --git a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/MetricsTest.cs b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/MetricsTest.cs index 0cafd974a4a20..cf9819cd9940f 100644 --- a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/MetricsTest.cs +++ b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/MetricsTest.cs @@ -12,6 +12,7 @@ namespace System.Net.NameResolution.Tests { + [SkipOnPlatform(TestPlatforms.Wasi, "WASI has event source yet")] public class MetricsTest { private const string DnsLookupDuration = "dns.lookup.duration"; diff --git a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/ResolveTest.cs b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/ResolveTest.cs index 071e9927ee9ff..814ec5cc6c267 100644 --- a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/ResolveTest.cs +++ b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/ResolveTest.cs @@ -46,6 +46,7 @@ public void DnsObsoleteResolve_BadName_Throws() } [Fact] + [SkipOnPlatform(TestPlatforms.Wasi, "WASI has no getnameinfo")] public void DnsObsoleteResolve_BadIP_ReturnsIPasNameAndIP() { IPHostEntry entry = Dns.Resolve("0.0.1.1"); diff --git a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/System.Net.NameResolution.Functional.Tests.csproj b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/System.Net.NameResolution.Functional.Tests.csproj index 182e5d9eba19b..993acdec9d57f 100644 --- a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/System.Net.NameResolution.Functional.Tests.csproj +++ b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/System.Net.NameResolution.Functional.Tests.csproj @@ -1,9 +1,14 @@ - $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-unix;$(NetCoreAppCurrent)-browser + $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-unix;$(NetCoreAppCurrent)-browser;$(NetCoreAppCurrent)-wasi true true true + true + + + $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) + $(DefineConstants);TARGET_WASI diff --git a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/TelemetryTest.cs b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/TelemetryTest.cs index b88ad1188aedc..50e38a22c206f 100644 --- a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/TelemetryTest.cs +++ b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/TelemetryTest.cs @@ -12,6 +12,7 @@ namespace System.Net.NameResolution.Tests { + [SkipOnPlatform(TestPlatforms.Wasi, "WASI has event source yet")] public class TelemetryTest { [Fact] diff --git a/src/libraries/System.Net.NameResolution/tests/PalTests/NameResolutionPalTests.cs b/src/libraries/System.Net.NameResolution/tests/PalTests/NameResolutionPalTests.cs index 030f03c01eddf..e4049b1291990 100644 --- a/src/libraries/System.Net.NameResolution/tests/PalTests/NameResolutionPalTests.cs +++ b/src/libraries/System.Net.NameResolution/tests/PalTests/NameResolutionPalTests.cs @@ -61,6 +61,7 @@ private void LogUnixInfo() [Theory] [InlineData(false)] [InlineData(true)] + [ActiveIssue("https://github.com/dotnet/runtime/issues/107339", TestPlatforms.Wasi)] public void TryGetAddrInfo_LocalHost(bool justAddresses) { SocketError error = NameResolutionPal.TryGetAddrInfo("localhost", justAddresses, AddressFamily.Unspecified, out string hostName, out string[] aliases, out IPAddress[] addresses, out int nativeErrorCode); @@ -77,6 +78,7 @@ public void TryGetAddrInfo_LocalHost(bool justAddresses) [Theory] [InlineData(false)] [InlineData(true)] + [ActiveIssue("https://github.com/dotnet/runtime/issues/107339", TestPlatforms.Wasi)] public void TryGetAddrInfo_EmptyHost(bool justAddresses) { SocketError error = NameResolutionPal.TryGetAddrInfo("", justAddresses, AddressFamily.Unspecified, out string hostName, out string[] aliases, out IPAddress[] addresses, out int nativeErrorCode); @@ -151,6 +153,7 @@ public void TryGetAddrInfo_UnknownHost(bool justAddresses) } [Fact] + [SkipOnPlatform(TestPlatforms.Wasi, "WASI has no getnameinfo")] public void TryGetNameInfo_LocalHost_IPv4() { SocketError error; @@ -161,6 +164,7 @@ public void TryGetNameInfo_LocalHost_IPv4() } [ConditionalFact(nameof(Ipv6LocalHostNameLookupNotBrokenByNrpRule))] + [SkipOnPlatform(TestPlatforms.Wasi, "WASI has no getnameinfo")] public void TryGetNameInfo_LocalHost_IPv6() { SocketError error; @@ -176,6 +180,7 @@ public void TryGetNameInfo_LocalHost_IPv6() } [Fact] + [SkipOnPlatform(TestPlatforms.Wasi, "WASI has no getnameinfo")] public void TryGetAddrInfo_LocalHost_TryGetNameInfo() { SocketError error = NameResolutionPal.TryGetAddrInfo("localhost", justAddresses: false, AddressFamily.Unspecified, out string hostName, out string[] aliases, out IPAddress[] addresses, out int nativeErrorCode); @@ -247,6 +252,7 @@ public void TryGetAddrInfo_HostName_TryGetNameInfo() [Theory] [InlineData(false)] [InlineData(true)] + [SkipOnPlatform(TestPlatforms.Wasi, "WASI has no getnameinfo")] public void TryGetNameInfo_LocalHost_IPv4_TryGetAddrInfo(bool justAddresses) { string name = NameResolutionPal.TryGetNameInfo(new IPAddress(new byte[] { 127, 0, 0, 1 }), out SocketError error, out _); @@ -262,6 +268,7 @@ public void TryGetNameInfo_LocalHost_IPv4_TryGetAddrInfo(bool justAddresses) [ConditionalTheory(nameof(Ipv6LocalHostNameLookupNotBrokenByNrpRule))] [InlineData(false)] [InlineData(true)] + [SkipOnPlatform(TestPlatforms.Wasi, "WASI has no getnameinfo")] public void TryGetNameInfo_LocalHost_IPv6_TryGetAddrInfo(bool justAddresses) { SocketError error; diff --git a/src/libraries/System.Net.NameResolution/tests/PalTests/System.Net.NameResolution.Pal.Tests.csproj b/src/libraries/System.Net.NameResolution/tests/PalTests/System.Net.NameResolution.Pal.Tests.csproj index 6e08a5f973e09..c9bce86798b0d 100644 --- a/src/libraries/System.Net.NameResolution/tests/PalTests/System.Net.NameResolution.Pal.Tests.csproj +++ b/src/libraries/System.Net.NameResolution/tests/PalTests/System.Net.NameResolution.Pal.Tests.csproj @@ -2,8 +2,13 @@ true ../../src/Resources/Strings.resx - $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-unix;$(NetCoreAppCurrent)-browser + $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-unix;$(NetCoreAppCurrent)-browser;$(NetCoreAppCurrent)-wasi true + true + + + $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) + $(DefineConstants);TARGET_WASI @@ -71,7 +76,9 @@ - + + - + + diff --git a/src/native/libs/System.Native/CMakeLists.txt b/src/native/libs/System.Native/CMakeLists.txt index 4cac1051f6739..7e00e0ed0a271 100644 --- a/src/native/libs/System.Native/CMakeLists.txt +++ b/src/native/libs/System.Native/CMakeLists.txt @@ -24,6 +24,7 @@ set(NATIVE_SOURCES pal_io.c pal_maphardwaretype.c pal_memory.c + pal_networking.c pal_networkstatistics.c pal_random.c pal_runtimeinformation.c @@ -42,7 +43,6 @@ if (NOT CLR_CMAKE_TARGET_WASI) list (APPEND NATIVE_SOURCES pal_dynamicload.c pal_mount.c - pal_networking.c pal_process.c pal_signal.c pal_threading.c @@ -52,7 +52,6 @@ else() list (APPEND NATIVE_SOURCES pal_dynamicload_wasi.c pal_mount_wasi.c - pal_networking_wasi.c pal_process_wasi.c pal_signal_wasi.c pal_threading_wasi.c diff --git a/src/native/libs/System.Native/pal_networking.c b/src/native/libs/System.Native/pal_networking.c index dc727fe546504..1a386cef542bb 100644 --- a/src/native/libs/System.Native/pal_networking.c +++ b/src/native/libs/System.Native/pal_networking.c @@ -34,7 +34,9 @@ #include #include #include +#if HAVE_NET_IF_H #include +#endif #include #include #include @@ -50,7 +52,9 @@ #include #endif #include +#ifdef HAVE_PWD_H #include +#endif #if HAVE_SENDFILE_4 #include #elif HAVE_SENDFILE_6 @@ -139,6 +143,7 @@ struct in_pktinfo #define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP #endif +#if !defined(TARGET_WASI) enum { #if defined(__APPLE__) && __APPLE__ @@ -147,6 +152,7 @@ enum LINGER_OPTION_NAME = SO_LINGER, #endif }; +#endif // TARGET_WASI enum { @@ -271,11 +277,13 @@ static void ConvertByteArrayToSockAddrIn6(struct sockaddr_in6* addr, const uint8 addr->sin6_family = AF_INET6; } +#if !defined(TARGET_WASI) static void ConvertByteArrayToInAddr(struct in_addr* addr, const uint8_t* buffer, int32_t bufferLength) { assert(bufferLength == NUM_BYTES_IN_IPV4_ADDRESS); memcpy_s(&addr->s_addr, NUM_BYTES_IN_IPV4_ADDRESS, buffer, (uint32_t)bufferLength); // Send back in network byte order. } +#endif // !TARGET_WASI static void ConvertInAddrToByteArray(uint8_t* buffer, int32_t bufferLength, const struct in_addr* addr) { @@ -283,12 +291,14 @@ static void ConvertInAddrToByteArray(uint8_t* buffer, int32_t bufferLength, cons memcpy_s(buffer, (uint32_t)bufferLength, &addr->s_addr, NUM_BYTES_IN_IPV4_ADDRESS); // Send back in network byte order. } +#if !defined(TARGET_WASI) static void ConvertByteArrayToSockAddrIn(struct sockaddr_in* addr, const uint8_t* buffer, int32_t bufferLength) { ConvertByteArrayToInAddr(&addr->sin_addr, buffer, bufferLength); addr->sin_family = AF_INET; } +#endif // !TARGET_WASI static int32_t ConvertGetAddrInfoAndGetNameInfoErrorsToPal(int32_t error) { @@ -313,10 +323,12 @@ static int32_t ConvertGetAddrInfoAndGetNameInfoErrorsToPal(int32_t error) case EAI_NODATA: #endif return GetAddrInfoErrorFlags_EAI_NONAME; + case EAI_SYSTEM: + return GetAddrInfoErrorFlags_EAI_SYSTEM; + default: + assert_err(0, "Unknown AddrInfo error flag", error); + return -1; } - - assert_err(0, "Unknown AddrInfo error flag", error); - return -1; } static int32_t CopySockAddrToIPAddress(sockaddr* addr, sa_family_t family, IPAddress* ipAddress) @@ -546,6 +558,7 @@ typedef int32_t NativeFlagsType; typedef uint32_t NativeFlagsType; #endif +#if !defined(TARGET_WASI) static inline NativeFlagsType ConvertGetNameInfoFlagsToNative(int32_t flags) { NativeFlagsType outFlags = 0; @@ -560,6 +573,7 @@ static inline NativeFlagsType ConvertGetNameInfoFlagsToNative(int32_t flags) return outFlags; } +#endif // !TARGET_WASI int32_t SystemNative_GetNameInfo(const uint8_t* address, int32_t addressLength, @@ -570,6 +584,7 @@ int32_t SystemNative_GetNameInfo(const uint8_t* address, int32_t serviceLength, int32_t flags) { +#if !defined(TARGET_WASI) assert(address != NULL); assert(addressLength > 0); assert((host != NULL) || (service != NULL)); @@ -606,6 +621,17 @@ int32_t SystemNative_GetNameInfo(const uint8_t* address, } return ConvertGetAddrInfoAndGetNameInfoErrorsToPal(result); +#else // TARGET_WASI + (void)address; + (void)addressLength, + (void)isIPv6, + (void)host, + (void)hostLength, + (void)service, + (void)serviceLength, + (void)flags; + return ConvertGetAddrInfoAndGetNameInfoErrorsToPal(EAI_FAIL); +#endif // !TARGET_WASI } int32_t SystemNative_GetDomainName(uint8_t* name, int32_t nameLength) @@ -652,11 +678,17 @@ int32_t SystemNative_GetDomainName(uint8_t* name, int32_t nameLength) int32_t SystemNative_GetHostName(uint8_t* name, int32_t nameLength) { +#if !defined(TARGET_WASI) assert(name != NULL); assert(nameLength > 0); size_t unsignedSize = (uint32_t)nameLength; return gethostname((char*)name, unsignedSize); +#else // TARGET_WASI + (void)name; + (void)nameLength; + return Error_ENOTSUP; +#endif // !TARGET_WASI } static bool IsInBounds(const void* void_baseAddr, size_t len, const void* void_valueAddr, size_t valueSize) @@ -907,6 +939,7 @@ SystemNative_SetIPv6Address(uint8_t* socketAddress, int32_t socketAddressLen, ui return Error_SUCCESS; } +#if !defined(TARGET_WASI) static int8_t IsStreamSocket(int socket) { int type; @@ -933,15 +966,23 @@ static void ConvertMessageHeaderToMsghdr(struct msghdr* header, const MessageHea header->msg_controllen = (uint32_t)messageHeader->ControlBufferLen; header->msg_flags = 0; } +#endif // !TARGET_WASI int32_t SystemNative_GetControlMessageBufferSize(int32_t isIPv4, int32_t isIPv6) { // Note: it is possible that the address family of the socket is neither // AF_INET nor AF_INET6. In this case both inputs will be 0 and // the control message buffer size should be zero. +#if !defined(TARGET_WASI) return (isIPv4 != 0 ? CMSG_SPACE(sizeof(struct in_pktinfo)) : 0) + (isIPv6 != 0 ? CMSG_SPACE(sizeof(struct in6_pktinfo)) : 0); +#else // TARGET_WASI + (void)isIPv4; + (void)isIPv6; + return 0; +#endif // TARGET_WASI } +#if !defined(TARGET_WASI) static int32_t GetIPv4PacketInformation(struct cmsghdr* controlMessage, IPPacketInformation* packetInfo) { assert(controlMessage != NULL); @@ -1020,6 +1061,7 @@ static struct cmsghdr* GET_CMSG_NXTHDR(struct msghdr* mhdr, struct cmsghdr* cmsg #pragma clang diagnostic pop #endif } +#endif // !TARGET_WASI int32_t SystemNative_TryGetIPPacketInformation(MessageHeader* messageHeader, int32_t isIPv4, IPPacketInformation* packetInfo) @@ -1029,6 +1071,7 @@ SystemNative_TryGetIPPacketInformation(MessageHeader* messageHeader, int32_t isI return 0; } +#if !defined(TARGET_WASI) struct msghdr header; ConvertMessageHeaderToMsghdr(&header, messageHeader, -1); @@ -1057,6 +1100,9 @@ SystemNative_TryGetIPPacketInformation(MessageHeader* messageHeader, int32_t isI } return 0; +#else // TARGET_WASI + return Error_ENOTSUP; +#endif // TARGET_WASI } static int8_t GetMulticastOptionName(int32_t multicastOption, int8_t isIPv6, int* optionName) @@ -1257,6 +1303,7 @@ int32_t SystemNative_GetLingerOption(intptr_t socket, LingerOption* option) return Error_EFAULT; } +#if !defined(TARGET_WASI) int fd = ToFileDescriptor(socket); struct linger opt; @@ -1271,6 +1318,11 @@ int32_t SystemNative_GetLingerOption(intptr_t socket, LingerOption* option) option->OnOff = opt.l_onoff; option->Seconds = opt.l_linger; return Error_SUCCESS; +#else // TARGET_WASI + (void)socket; + (void)option; + return Error_ENOTSUP; +#endif // TARGET_WASI } int32_t SystemNative_SetLingerOption(intptr_t socket, LingerOption* option) @@ -1285,6 +1337,7 @@ int32_t SystemNative_SetLingerOption(intptr_t socket, LingerOption* option) return Error_EINVAL; } +#if !defined(TARGET_WASI) int fd = ToFileDescriptor(socket); struct linger opt; @@ -1304,6 +1357,9 @@ int32_t SystemNative_SetLingerOption(intptr_t socket, LingerOption* option) #endif return err == 0 ? Error_SUCCESS : SystemNative_ConvertErrorPlatformToPal(errno); +#else // TARGET_WASI + return Error_ENOTSUP; +#endif // TARGET_WASI } static int32_t SetTimeoutOption(int32_t socket, int32_t millisecondsTimeout, int optionName) @@ -1333,6 +1389,12 @@ int32_t SystemNative_SetSendTimeout(intptr_t socket, int32_t millisecondsTimeout static int8_t ConvertSocketFlagsPalToPlatform(int32_t palFlags, int* platformFlags) { +#if defined(TARGET_WASI) + if (palFlags != 0) + { + return false; + } +#else // TARGET_WASI const int32_t SupportedFlagsMask = #ifdef MSG_ERRQUEUE SocketFlags_MSG_ERRQUEUE | @@ -1356,9 +1418,11 @@ static int8_t ConvertSocketFlagsPalToPlatform(int32_t palFlags, int* platformFla *platformFlags |= MSG_ERRQUEUE; } #endif +#endif // !TARGET_WASI return true; } +#if !defined(TARGET_WASI) static int32_t ConvertSocketFlagsPlatformToPal(int platformFlags) { const int SupportedFlagsMask = MSG_OOB | MSG_DONTROUTE | MSG_TRUNC | MSG_CTRUNC; @@ -1370,6 +1434,7 @@ static int32_t ConvertSocketFlagsPlatformToPal(int platformFlags) ((platformFlags & MSG_TRUNC) == 0 ? 0 : SocketFlags_MSG_TRUNC) | ((platformFlags & MSG_CTRUNC) == 0 ? 0 : SocketFlags_MSG_CTRUNC); } +#endif // !TARGET_WASI int32_t SystemNative_Receive(intptr_t socket, void* buffer, int32_t bufferLen, int32_t flags, int32_t* received) { @@ -1469,10 +1534,14 @@ int32_t SystemNative_ReceiveMessage(intptr_t socket, MessageHeader* messageHeade return Error_ENOTSUP; } + ssize_t res; +#if defined(TARGET_WASI) + // TODO https://github.com/dotnet/runtime/issues/98957 + assert_msg(false, "Not supported on WASI yet", 0); +#else // TARGET_WASI struct msghdr header; ConvertMessageHeaderToMsghdr(&header, messageHeader, fd); - ssize_t res; while ((res = recvmsg(fd, &header, socketFlags)) < 0 && errno == EINTR); assert(header.msg_name == messageHeader->SocketAddress); // should still be the same location as set in ConvertMessageHeaderToMsghdr @@ -1485,6 +1554,7 @@ int32_t SystemNative_ReceiveMessage(intptr_t socket, MessageHeader* messageHeade messageHeader->ControlBufferLen = Min((int32_t)header.msg_controllen, messageHeader->ControlBufferLen); messageHeader->Flags = ConvertSocketFlagsPlatformToPal(header.msg_flags); +#endif // !TARGET_WASI if (res != -1) { @@ -1547,10 +1617,11 @@ int32_t SystemNative_SendMessage(intptr_t socket, MessageHeader* messageHeader, return Error_ENOTSUP; } + ssize_t res; +#if !defined(TARGET_WASI) struct msghdr header; ConvertMessageHeaderToMsghdr(&header, messageHeader, fd); - ssize_t res; #if defined(__APPLE__) && __APPLE__ // possible OSX kernel bug: https://github.com/dotnet/runtime/issues/27221 // According to https://github.com/dotnet/runtime/issues/63291 the EPROTOTYPE may be @@ -1560,6 +1631,11 @@ int32_t SystemNative_SendMessage(intptr_t socket, MessageHeader* messageHeader, #else while ((res = sendmsg(fd, &header, socketFlags)) < 0 && errno == EINTR); #endif +#else // TARGET_WASI + // TODO https://github.com/dotnet/runtime/issues/98957 + assert_msg(false, "Not supported on WASI yet", 0); +#endif // !TARGET_WASI + if (res != -1) { *sent = res; @@ -1699,7 +1775,7 @@ int32_t SystemNative_Connectx(intptr_t socket, uint8_t* socketAddress, int32_t s } #endif // avoid possible warning about unused parameters - (void*)data; + (void)data; (void)dataLen; (void)tfo; sent = 0; @@ -1791,9 +1867,11 @@ static bool TryGetPlatformSocketOption(int32_t socketOptionLevel, int32_t socket switch (socketOptionName) { +#if !defined(TARGET_WASI) case SocketOptionName_SO_DEBUG: *optName = SO_DEBUG; return true; +#endif // !TARGET_WASI case SocketOptionName_SO_ACCEPTCONN: *optName = SO_ACCEPTCONN; @@ -1807,6 +1885,7 @@ static bool TryGetPlatformSocketOption(int32_t socketOptionLevel, int32_t socket *optName = SO_KEEPALIVE; return true; +#if !defined(TARGET_WASI) case SocketOptionName_SO_DONTROUTE: *optName = SO_DONTROUTE; return true; @@ -1824,6 +1903,7 @@ static bool TryGetPlatformSocketOption(int32_t socketOptionLevel, int32_t socket case SocketOptionName_SO_OOBINLINE: *optName = SO_OOBINLINE; return true; +#endif // !TARGET_WASI // case SocketOptionName_SO_DONTLINGER: @@ -1837,6 +1917,7 @@ static bool TryGetPlatformSocketOption(int32_t socketOptionLevel, int32_t socket *optName = SO_RCVBUF; return true; +#if !defined(TARGET_WASI) case SocketOptionName_SO_SNDLOWAT: *optName = SO_SNDLOWAT; return true; @@ -1845,6 +1926,7 @@ static bool TryGetPlatformSocketOption(int32_t socketOptionLevel, int32_t socket *optName = SO_RCVLOWAT; return true; +#endif // !TARGET_WASI case SocketOptionName_SO_SNDTIMEO: *optName = SO_SNDTIMEO; return true; @@ -2064,9 +2146,11 @@ static bool TryConvertSocketTypePlatformToPal(int platformSocketType, int32_t* p *palSocketType = SocketType_SOCK_DGRAM; return true; +#if !defined(TARGET_WASI) case SOCK_RAW: *palSocketType = SocketType_SOCK_RAW; return true; +#endif // !TARGET_WASI #ifdef SOCK_RDM case SOCK_RDM: @@ -2074,9 +2158,11 @@ static bool TryConvertSocketTypePlatformToPal(int platformSocketType, int32_t* p return true; #endif +#if !defined(TARGET_WASI) case SOCK_SEQPACKET: *palSocketType = SocketType_SOCK_SEQPACKET; return true; +#endif // !TARGET_WASI default: *palSocketType = (int32_t)platformSocketType; @@ -2336,9 +2422,11 @@ static bool TryConvertSocketTypePalToPlatform(int32_t palSocketType, int* platfo *platformSocketType = SOCK_DGRAM; return true; +#if !defined(TARGET_WASI) case SocketType_SOCK_RAW: *platformSocketType = SOCK_RAW; return true; +#endif // !TARGET_WASI #ifdef SOCK_RDM case SocketType_SOCK_RDM: @@ -2346,9 +2434,11 @@ static bool TryConvertSocketTypePalToPlatform(int32_t palSocketType, int* platfo return true; #endif +#if !defined(TARGET_WASI) case SocketType_SOCK_SEQPACKET: *platformSocketType = SOCK_SEQPACKET; return true; +#endif // !TARGET_WASI default: *platformSocketType = (int)palSocketType; @@ -2392,9 +2482,11 @@ static bool TryConvertProtocolTypePalToPlatform(int32_t palAddressFamily, int32_ *platformProtocolType = 0; return true; +#if !defined(TARGET_WASI) case ProtocolType_PT_ICMP: *platformProtocolType = IPPROTO_ICMP; return true; +#endif // !TARGET_WASI case ProtocolType_PT_TCP: *platformProtocolType = IPPROTO_TCP; @@ -2404,9 +2496,11 @@ static bool TryConvertProtocolTypePalToPlatform(int32_t palAddressFamily, int32_ *platformProtocolType = IPPROTO_UDP; return true; +#if !defined(TARGET_WASI) case ProtocolType_PT_IGMP: *platformProtocolType = IPPROTO_IGMP; return true; +#endif // !TARGET_WASI case ProtocolType_PT_RAW: *platformProtocolType = IPPROTO_RAW; @@ -2424,10 +2518,12 @@ static bool TryConvertProtocolTypePalToPlatform(int32_t palAddressFamily, int32_ *platformProtocolType = 0; return true; +#if !defined(TARGET_WASI) case ProtocolType_PT_ICMPV6: case ProtocolType_PT_ICMP: *platformProtocolType = IPPROTO_ICMPV6; return true; +#endif // !TARGET_WASI case ProtocolType_PT_TCP: *platformProtocolType = IPPROTO_TCP; @@ -2437,14 +2533,17 @@ static bool TryConvertProtocolTypePalToPlatform(int32_t palAddressFamily, int32_ *platformProtocolType = IPPROTO_UDP; return true; +#if !defined(TARGET_WASI) case ProtocolType_PT_IGMP: *platformProtocolType = IPPROTO_IGMP; return true; +#endif // !TARGET_WASI case ProtocolType_PT_RAW: *platformProtocolType = IPPROTO_RAW; return true; +#if !defined(TARGET_WASI) case ProtocolType_PT_DSTOPTS: *platformProtocolType = IPPROTO_DSTOPTS; return true; @@ -2460,6 +2559,7 @@ static bool TryConvertProtocolTypePalToPlatform(int32_t palAddressFamily, int32_ case ProtocolType_PT_FRAGMENT: *platformProtocolType = IPPROTO_FRAGMENT; return true; +#endif // !TARGET_WASI default: *platformProtocolType = (int)palProtocolType; @@ -2515,9 +2615,11 @@ static bool TryConvertProtocolTypePlatformToPal(int32_t palAddressFamily, int pl *palProtocolType = ProtocolType_PT_UNSPECIFIED; return true; +#if !defined(TARGET_WASI) case IPPROTO_ICMP: *palProtocolType = ProtocolType_PT_ICMP; return true; +#endif // !TARGET_WASI case IPPROTO_TCP: *palProtocolType = ProtocolType_PT_TCP; @@ -2527,9 +2629,11 @@ static bool TryConvertProtocolTypePlatformToPal(int32_t palAddressFamily, int pl *palProtocolType = ProtocolType_PT_UDP; return true; +#if !defined(TARGET_WASI) case IPPROTO_IGMP: *palProtocolType = ProtocolType_PT_IGMP; return true; +#endif // !TARGET_WASI case IPPROTO_RAW: *palProtocolType = ProtocolType_PT_RAW; @@ -2547,9 +2651,11 @@ static bool TryConvertProtocolTypePlatformToPal(int32_t palAddressFamily, int pl *palProtocolType = ProtocolType_PT_UNSPECIFIED; return true; +#if !defined(TARGET_WASI) case IPPROTO_ICMPV6: *palProtocolType = ProtocolType_PT_ICMPV6; return true; +#endif // !TARGET_WASI case IPPROTO_TCP: *palProtocolType = ProtocolType_PT_TCP; @@ -2559,14 +2665,17 @@ static bool TryConvertProtocolTypePlatformToPal(int32_t palAddressFamily, int pl *palProtocolType = ProtocolType_PT_UDP; return true; +#if !defined(TARGET_WASI) case IPPROTO_IGMP: *palProtocolType = ProtocolType_PT_IGMP; return true; +#endif // !TARGET_WASI case IPPROTO_RAW: *palProtocolType = ProtocolType_PT_RAW; return true; +#if !defined(TARGET_WASI) case IPPROTO_DSTOPTS: *palProtocolType = ProtocolType_PT_DSTOPTS; return true; @@ -2582,6 +2691,7 @@ static bool TryConvertProtocolTypePlatformToPal(int32_t palAddressFamily, int pl case IPPROTO_FRAGMENT: *palProtocolType = ProtocolType_PT_FRAGMENT; return true; +#endif // !TARGET_WASI default: *palProtocolType = (int)platformProtocolType; @@ -2723,6 +2833,7 @@ int32_t SystemNative_GetSocketType(intptr_t socket, int32_t* addressFamily, int3 int32_t SystemNative_GetAtOutOfBandMark(intptr_t socket, int32_t* atMark) { +#if !defined(TARGET_WASI) if (atMark == NULL) { return Error_EFAULT; @@ -2741,6 +2852,9 @@ int32_t SystemNative_GetAtOutOfBandMark(intptr_t socket, int32_t* atMark) *atMark = (int32_t)result; return Error_SUCCESS; +#else // TARGET_WASI + return Error_ENOTSUP; +#endif // !TARGET_WASI } int32_t SystemNative_GetBytesAvailable(intptr_t socket, int32_t* available) @@ -2847,11 +2961,15 @@ int32_t SystemNative_Select(int* readFds, int readFdsCount, int* writeFds, int w return Error_SUCCESS; #else // avoid unused parameters warnings - (void*)readFds; - (void*)writeFds; - (void*)errorFds; - (void*)triggered; - readFdsCount + writeFdsCount + errorFdsCount + microseconds + maxFd; + (void)readFds; + (void)writeFds; + (void)errorFds; + (void)triggered; + (void)readFdsCount; + (void)writeFdsCount; + (void)errorFdsCount; + (void)microseconds; + (void)maxFd; return SystemNative_ConvertErrorPlatformToPal(ENOTSUP); #endif } @@ -3151,10 +3269,6 @@ static int32_t WaitForSocketEventsInner(int32_t port, SocketEvent* buffer, int32 #else static const size_t SocketEventBufferElementSize = 0; -static SocketEvents GetSocketEvents(int16_t filter, uint16_t flags) -{ - return SocketEvents_SA_NONE; -} static int32_t CloseSocketEventPortInner(int32_t port) { return Error_ENOSYS; @@ -3266,11 +3380,17 @@ void SystemNative_GetDomainSocketSizes(int32_t* pathOffset, int32_t* pathSize, i assert(pathSize != NULL); assert(addressSize != NULL); +#if !defined(TARGET_WASI) struct sockaddr_un domainSocket; *pathOffset = offsetof(struct sockaddr_un, sun_path); *pathSize = sizeof(domainSocket.sun_path); *addressSize = sizeof(domainSocket); +#else // TARGET_WASI + *pathOffset = 0; + *pathSize = 0; + *addressSize = 0; +#endif // TARGET_WASI } int32_t SystemNative_GetMaximumAddressSize(void) @@ -3449,8 +3569,13 @@ int32_t SystemNative_SendFile(intptr_t out_fd, intptr_t in_fd, int64_t offset, i uint32_t SystemNative_InterfaceNameToIndex(char* interfaceName) { +#if !defined(TARGET_WASI) assert(interfaceName != NULL); if (interfaceName[0] == '%') interfaceName++; return if_nametoindex(interfaceName); +#else // TARGET_WASI + (void)interfaceName; + return 0; +#endif // !TARGET_WASI } diff --git a/src/native/libs/System.Native/pal_networking.h b/src/native/libs/System.Native/pal_networking.h index a0904f295267d..8044ce00b0266 100644 --- a/src/native/libs/System.Native/pal_networking.h +++ b/src/native/libs/System.Native/pal_networking.h @@ -24,6 +24,7 @@ typedef enum GetAddrInfoErrorFlags_EAI_BADARG = 6, // One or more input arguments were invalid. GetAddrInfoErrorFlags_EAI_NOMORE = 7, // No more entries are present in the list. GetAddrInfoErrorFlags_EAI_MEMORY = 8, // Out of memory. + GetAddrInfoErrorFlags_EAI_SYSTEM = 9, // Other system error; errno is set to indicate the error. } GetAddrInfoErrorFlags; /** diff --git a/src/native/libs/System.Native/pal_networking_wasi.c b/src/native/libs/System.Native/pal_networking_wasi.c deleted file mode 100644 index baeb6494b31e7..0000000000000 --- a/src/native/libs/System.Native/pal_networking_wasi.c +++ /dev/null @@ -1,443 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -#include "pal_config.h" -#include "pal_networking.h" -#include "pal_safecrt.h" -#include "pal_utilities.h" -#include -#include - -#include -#include -int32_t SystemNative_GetHostEntryForName(const uint8_t* address, int32_t addressFamily, HostEntry* entry) -{ - return -1; -} - -void SystemNative_FreeHostEntry(HostEntry* entry) -{ - if (entry != NULL) - { - free(entry->CanonicalName); - free(entry->IPAddressList); - - entry->CanonicalName = NULL; - entry->IPAddressList = NULL; - entry->IPAddressCount = 0; - } -} - -int32_t SystemNative_GetNameInfo(const uint8_t* address, - int32_t addressLength, - int8_t isIPv6, - uint8_t* host, - int32_t hostLength, - uint8_t* service, - int32_t serviceLength, - int32_t flags) -{ - assert(address != NULL); - assert(addressLength > 0); - assert((host != NULL) || (service != NULL)); - assert((hostLength > 0) || (serviceLength > 0)); - - return Error_EINVAL; -} - -int32_t SystemNative_GetDomainName(uint8_t* name, int32_t nameLength) -{ - assert(name != NULL); - assert(nameLength > 0); - return Error_EFAULT; -} - -int32_t SystemNative_GetHostName(uint8_t* name, int32_t nameLength) -{ - assert(name != NULL); - assert(nameLength > 0); - - size_t unsignedSize = (uint32_t)nameLength; - return gethostname((char*)name, unsignedSize); -} - -int32_t SystemNative_GetSocketAddressSizes(int32_t* ipv4SocketAddressSize, int32_t* ipv6SocketAddressSize, int32_t*udsSocketAddressSize, int* maxSocketAddressSize) -{ - return Error_EFAULT; -} - -int32_t SystemNative_GetAddressFamily(const uint8_t* socketAddress, int32_t socketAddressLen, int32_t* addressFamily) -{ - return Error_EFAULT; -} - -int32_t SystemNative_SetAddressFamily(uint8_t* socketAddress, int32_t socketAddressLen, int32_t addressFamily) -{ - return Error_EFAULT; -} - -int32_t SystemNative_GetPort(const uint8_t* socketAddress, int32_t socketAddressLen, uint16_t* port) -{ - return Error_EFAULT; -} - -int32_t SystemNative_SetPort(uint8_t* socketAddress, int32_t socketAddressLen, uint16_t port) -{ - return Error_EFAULT; -} - -int32_t SystemNative_GetIPv4Address(const uint8_t* socketAddress, int32_t socketAddressLen, uint32_t* address) -{ - return Error_EFAULT; -} - -int32_t SystemNative_SetIPv4Address(uint8_t* socketAddress, int32_t socketAddressLen, uint32_t address) -{ - return Error_EFAULT; -} - -int32_t SystemNative_GetIPv6Address( - const uint8_t* socketAddress, int32_t socketAddressLen, uint8_t* address, int32_t addressLen, uint32_t* scopeId) -{ - return Error_EFAULT; -} - -int32_t -SystemNative_SetIPv6Address(uint8_t* socketAddress, int32_t socketAddressLen, uint8_t* address, int32_t addressLen, uint32_t scopeId) -{ - return Error_EFAULT; -} - -int32_t SystemNative_GetControlMessageBufferSize(int32_t isIPv4, int32_t isIPv6) -{ - return Error_EFAULT; -} - - -int32_t -SystemNative_TryGetIPPacketInformation(MessageHeader* messageHeader, int32_t isIPv4, IPPacketInformation* packetInfo) -{ - if (messageHeader == NULL || packetInfo == NULL) - { - return 0; - } - - return Error_EINVAL; -} - -int32_t SystemNative_GetIPv4MulticastOption(intptr_t socket, int32_t multicastOption, IPv4MulticastOption* option) -{ - return Error_EINVAL; -} - -int32_t SystemNative_SetIPv4MulticastOption(intptr_t socket, int32_t multicastOption, IPv4MulticastOption* option) -{ - if (option == NULL) - { - return Error_EFAULT; - } - - return Error_EINVAL; -} - -int32_t SystemNative_GetIPv6MulticastOption(intptr_t socket, int32_t multicastOption, IPv6MulticastOption* option) -{ - if (option == NULL) - { - return Error_EFAULT; - } - - return Error_EINVAL; -} - -int32_t SystemNative_SetIPv6MulticastOption(intptr_t socket, int32_t multicastOption, IPv6MulticastOption* option) -{ - if (option == NULL) - { - return Error_EFAULT; - } - return Error_EINVAL; -} - - -int32_t SystemNative_GetLingerOption(intptr_t socket, LingerOption* option) -{ - if (option == NULL) - { - return Error_EFAULT; - } - - return Error_EINVAL; -} - -int32_t SystemNative_SetLingerOption(intptr_t socket, LingerOption* option) -{ - if (option == NULL) - { - return Error_EFAULT; - } - - return Error_EINVAL; -} - -int32_t SystemNative_SetReceiveTimeout(intptr_t socket, int32_t millisecondsTimeout) -{ - return Error_EINVAL; -} - -int32_t SystemNative_SetSendTimeout(intptr_t socket, int32_t millisecondsTimeout) -{ - return Error_EINVAL; -} -int32_t SystemNative_Receive(intptr_t socket, void* buffer, int32_t bufferLen, int32_t flags, int32_t* received) -{ - if (buffer == NULL || bufferLen < 0 || received == NULL) - { - return Error_EFAULT; - } - - return Error_EINVAL; -} - -int32_t SystemNative_ReceiveMessage(intptr_t socket, MessageHeader* messageHeader, int32_t flags, int64_t* received) -{ - if (messageHeader == NULL || received == NULL || messageHeader->SocketAddressLen < 0 || - messageHeader->ControlBufferLen < 0 || messageHeader->IOVectorCount < 0) - { - return Error_EFAULT; - } - - return Error_EINVAL; -} - -int32_t SystemNative_Send(intptr_t socket, void* buffer, int32_t bufferLen, int32_t flags, int32_t* sent) -{ - return Error_EINVAL; -} - -int32_t SystemNative_SendMessage(intptr_t socket, MessageHeader* messageHeader, int32_t flags, int64_t* sent) -{ - return Error_EINVAL; -} - -int32_t SystemNative_Accept(intptr_t socket, uint8_t* socketAddress, int32_t* socketAddressLen, intptr_t* acceptedSocket) -{ - if (socketAddress == NULL || socketAddressLen == NULL || acceptedSocket == NULL || *socketAddressLen < 0) - { - return Error_EFAULT; - } - - return Error_EINVAL; -} - -int32_t SystemNative_Bind(intptr_t socket, int32_t protocolType, uint8_t* socketAddress, int32_t socketAddressLen) -{ - if (socketAddress == NULL || socketAddressLen < 0) - { - return Error_EFAULT; - } - - return Error_EINVAL; -} - -int32_t SystemNative_Connect(intptr_t socket, uint8_t* socketAddress, int32_t socketAddressLen) -{ - return Error_EINVAL; -} - -int32_t SystemNative_GetPeerName(intptr_t socket, uint8_t* socketAddress, int32_t* socketAddressLen) -{ - if (socketAddress == NULL || socketAddressLen == NULL || *socketAddressLen < 0) - { - return Error_EFAULT; - } - - return Error_EINVAL; -} - -int32_t SystemNative_GetSockName(intptr_t socket, uint8_t* socketAddress, int32_t* socketAddressLen) -{ - if (socketAddress == NULL || socketAddressLen == NULL || *socketAddressLen < 0) - { - return Error_EFAULT; - } - - return Error_EINVAL; -} - -int32_t SystemNative_Listen(intptr_t socket, int32_t backlog) -{ - return Error_EINVAL; -} - -int32_t SystemNative_Shutdown(intptr_t socket, int32_t socketShutdown) -{ - return Error_EINVAL; -} - -int32_t SystemNative_GetSocketErrorOption(intptr_t socket, int32_t* error) -{ - if (error == NULL) - { - return Error_EFAULT; - } - - return Error_EINVAL; -} - -int32_t SystemNative_GetSockOpt( - intptr_t socket, int32_t socketOptionLevel, int32_t socketOptionName, uint8_t* optionValue, int32_t* optionLen) -{ - if (optionLen == NULL || *optionLen < 0) - { - return Error_EFAULT; - } - - return Error_EINVAL; -} - -int32_t SystemNative_GetRawSockOpt( - intptr_t socket, int32_t socketOptionLevel, int32_t socketOptionName, uint8_t* optionValue, int32_t* optionLen) -{ - if (optionLen == NULL || *optionLen < 0) - { - return Error_EFAULT; - } - - return Error_EINVAL; -} - -int32_t -SystemNative_SetSockOpt(intptr_t socket, int32_t socketOptionLevel, int32_t socketOptionName, uint8_t* optionValue, int32_t optionLen) -{ - return Error_EINVAL; -} - -int32_t SystemNative_SetRawSockOpt( - intptr_t socket, int32_t socketOptionLevel, int32_t socketOptionName, uint8_t* optionValue, int32_t optionLen) -{ - if (optionLen < 0 || optionValue == NULL) - { - return Error_EFAULT; - } - - return Error_EINVAL; -} - -int32_t SystemNative_Socket(int32_t addressFamily, int32_t socketType, int32_t protocolType, intptr_t* createdSocket) -{ - if (createdSocket == NULL) - { - return Error_EFAULT; - } - - return Error_EINVAL; -} - -int32_t SystemNative_GetSocketType(intptr_t socket, int32_t* addressFamily, int32_t* socketType, int32_t* protocolType, int32_t* isListening) -{ - if (addressFamily == NULL || socketType == NULL || protocolType == NULL || isListening == NULL) - { - return Error_EFAULT; - } - - return Error_EINVAL; -} - -int32_t SystemNative_GetAtOutOfBandMark(intptr_t socket, int32_t* atMark) -{ - if (atMark == NULL) - { - return Error_EFAULT; - } - - return Error_EINVAL; -} - -int32_t SystemNative_GetBytesAvailable(intptr_t socket, int32_t* available) -{ - if (available == NULL) - { - return Error_EFAULT; - } - - return Error_EINVAL; -} - -int32_t SystemNative_CreateSocketEventPort(intptr_t* port) -{ - if (port == NULL) - { - return Error_EFAULT; - } - - return Error_EINVAL; -} - -int32_t SystemNative_CloseSocketEventPort(intptr_t port) -{ - return Error_EINVAL; -} - -int32_t SystemNative_CreateSocketEventBuffer(int32_t count, SocketEvent** buffer) -{ - if (buffer == NULL || count < 0) - { - return Error_EFAULT; - } - - return Error_EINVAL; -} - -int32_t SystemNative_FreeSocketEventBuffer(SocketEvent* buffer) -{ - free(buffer); - return Error_SUCCESS; -} - -int32_t -SystemNative_TryChangeSocketEventRegistration(intptr_t port, intptr_t socket, int32_t currentEvents, int32_t newEvents, uintptr_t data) -{ - return Error_EINVAL; -} - -int32_t SystemNative_WaitForSocketEvents(intptr_t port, SocketEvent* buffer, int32_t* count) -{ - return Error_EINVAL; -} - -int32_t SystemNative_PlatformSupportsDualModeIPv4PacketInfo(void) -{ - return 0; -} - -void SystemNative_GetDomainSocketSizes(int32_t* pathOffset, int32_t* pathSize, int32_t* addressSize) -{ - *pathOffset = -1; - *pathSize = -1; - *addressSize = -1; -} - -int32_t SystemNative_GetMaximumAddressSize(void) -{ - return sizeof(struct sockaddr_storage); -} - -int32_t SystemNative_Disconnect(intptr_t socket) -{ - return Error_EINVAL; -} - -int32_t SystemNative_SendFile(intptr_t out_fd, intptr_t in_fd, int64_t offset, int64_t count, int64_t* sent) -{ - assert(sent != NULL); - - return Error_EINVAL; -} - -uint32_t SystemNative_InterfaceNameToIndex(char* interfaceName) -{ - assert(interfaceName != NULL); - return Error_EINVAL; -} - diff --git a/src/native/libs/configure.cmake b/src/native/libs/configure.cmake index 477f9f1f14a03..946702894fe62 100644 --- a/src/native/libs/configure.cmake +++ b/src/native/libs/configure.cmake @@ -562,7 +562,10 @@ elseif(CLR_CMAKE_TARGET_ANDROID) unset(HAVE_ALIGNED_ALLOC) # only exists on newer Android set(HAVE_CLOCK_MONOTONIC 1) set(HAVE_CLOCK_REALTIME 1) -elseif(CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI) +elseif(CLR_CMAKE_TARGET_WASI) + set(HAVE_FORK 0) + set(HAVE_GETIFADDRS 0) +elseif(CLR_CMAKE_TARGET_BROWSER) set(HAVE_FORK 0) else() check_symbol_exists( From a473a2a84909f369e461fb3140cce8f0b2b1ff92 Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Mon, 9 Sep 2024 10:14:26 +0200 Subject: [PATCH 02/19] fix build --- .../src/System.Net.NameResolution.csproj | 8 ++++---- .../PalTests/System.Net.NameResolution.Pal.Tests.csproj | 2 +- src/native/libs/System.Native/pal_networking.c | 3 ++- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/libraries/System.Net.NameResolution/src/System.Net.NameResolution.csproj b/src/libraries/System.Net.NameResolution/src/System.Net.NameResolution.csproj index 2be977f33fe7b..4e669d80fa1c2 100644 --- a/src/libraries/System.Net.NameResolution/src/System.Net.NameResolution.csproj +++ b/src/libraries/System.Net.NameResolution/src/System.Net.NameResolution.csproj @@ -97,6 +97,10 @@ Link="Common\Interop\Unix\System.Native\Interop.SocketAddress.cs" /> + + + + @@ -130,10 +134,6 @@ Link="Common\Interop\Unix\System.Native\Interop.SocketAddress.cs" /> - - - - diff --git a/src/libraries/System.Net.NameResolution/tests/PalTests/System.Net.NameResolution.Pal.Tests.csproj b/src/libraries/System.Net.NameResolution/tests/PalTests/System.Net.NameResolution.Pal.Tests.csproj index c9bce86798b0d..5eba286642c0f 100644 --- a/src/libraries/System.Net.NameResolution/tests/PalTests/System.Net.NameResolution.Pal.Tests.csproj +++ b/src/libraries/System.Net.NameResolution/tests/PalTests/System.Net.NameResolution.Pal.Tests.csproj @@ -76,7 +76,7 @@ - + ControlBufferLen = Min((int32_t)header.msg_controllen, messageHeader->ControlBufferLen); messageHeader->Flags = ConvertSocketFlagsPlatformToPal(header.msg_flags); -#endif // !TARGET_WASI if (res != -1) { @@ -1564,6 +1564,7 @@ int32_t SystemNative_ReceiveMessage(intptr_t socket, MessageHeader* messageHeade *received = 0; return SystemNative_ConvertErrorPlatformToPal(errno); +#endif // !TARGET_WASI } int32_t SystemNative_Send(intptr_t socket, void* buffer, int32_t bufferLen, int32_t flags, int32_t* sent) From 68c42655c25d595eb8b4119cfd42a12b43ef94d4 Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Mon, 9 Sep 2024 10:57:00 +0200 Subject: [PATCH 03/19] fix build --- src/native/libs/System.Native/pal_networking.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/native/libs/System.Native/pal_networking.c b/src/native/libs/System.Native/pal_networking.c index 132693851bb42..d5b3af8adfffe 100644 --- a/src/native/libs/System.Native/pal_networking.c +++ b/src/native/libs/System.Native/pal_networking.c @@ -1618,8 +1618,12 @@ int32_t SystemNative_SendMessage(intptr_t socket, MessageHeader* messageHeader, return Error_ENOTSUP; } +#if defined(TARGET_WASI) + // TODO https://github.com/dotnet/runtime/issues/98957 + assert_msg(false, "Not supported on WASI yet", 0); + return Error_ENOTSUP; +#else // TARGET_WASI ssize_t res; -#if !defined(TARGET_WASI) struct msghdr header; ConvertMessageHeaderToMsghdr(&header, messageHeader, fd); @@ -1632,10 +1636,6 @@ int32_t SystemNative_SendMessage(intptr_t socket, MessageHeader* messageHeader, #else while ((res = sendmsg(fd, &header, socketFlags)) < 0 && errno == EINTR); #endif -#else // TARGET_WASI - // TODO https://github.com/dotnet/runtime/issues/98957 - assert_msg(false, "Not supported on WASI yet", 0); -#endif // !TARGET_WASI if (res != -1) { @@ -1645,6 +1645,7 @@ int32_t SystemNative_SendMessage(intptr_t socket, MessageHeader* messageHeader, *sent = 0; return SystemNative_ConvertErrorPlatformToPal(errno); +#endif // !TARGET_WASI } int32_t SystemNative_Accept(intptr_t socket, uint8_t* socketAddress, int32_t* socketAddressLen, intptr_t* acceptedSocket) From 787a123b1490ca6cfd866a9c0a390bd5bc422495 Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Mon, 9 Sep 2024 16:16:01 +0200 Subject: [PATCH 04/19] fix linux --- src/libraries/System.Net.NameResolution/src/System/Net/Dns.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Net.NameResolution/src/System/Net/Dns.cs b/src/libraries/System.Net.NameResolution/src/System/Net/Dns.cs index e1c9866929ab1..282d2d1dcee29 100644 --- a/src/libraries/System.Net.NameResolution/src/System/Net/Dns.cs +++ b/src/libraries/System.Net.NameResolution/src/System/Net/Dns.cs @@ -205,7 +205,7 @@ public static IPAddress[] GetHostAddresses(string hostNameOrAddress, AddressFami // See if it's an IP Address. IPAddress[] addresses; -#if TARGET_WASI +#if !TARGET_WASI if (IPAddress.TryParse(hostNameOrAddress, out IPAddress? address)) { if (address.Equals(IPAddress.Any) || address.Equals(IPAddress.IPv6Any)) From 3bbccad914d26d9ce1c170336e6aa90e682d5999 Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Wed, 11 Sep 2024 15:08:23 +0200 Subject: [PATCH 05/19] feedback --- .../Unix/System.Native/Interop.GetHostName.cs | 9 +- .../src/System.Net.NameResolution.csproj | 6 +- .../src/System/Net/Dns.cs | 58 ++-- .../src/System/Net/NameResolutionPal.Unix.cs | 15 +- .../System/Net/NameResolutionPal.Windows.cs | 3 + .../Net/NameResolutionTelemetry.Wasi.cs | 44 --- .../src/System/Net/NameResolutionTelemetry.cs | 4 +- src/native/libs/Common/pal_config.h.in | 4 + .../libs/System.Native/pal_networking.c | 265 ++++++++++-------- src/native/libs/configure.cmake | 18 ++ 10 files changed, 206 insertions(+), 220 deletions(-) delete mode 100644 src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionTelemetry.Wasi.cs diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetHostName.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetHostName.cs index 3f109bf1a5c96..888c243521f83 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetHostName.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetHostName.cs @@ -14,7 +14,11 @@ internal static partial class Sys internal static unsafe string GetHostName() { -#if !TARGET_WASI + if (OperatingSystem.IsWasi()) + { + return "localhost"; + } + const int HOST_NAME_MAX = 255; const int ArrLength = HOST_NAME_MAX + 1; @@ -35,9 +39,6 @@ internal static unsafe string GetHostName() name[ArrLength - 1] = 0; return Marshal.PtrToStringUTF8((IntPtr)name)!; -#else - return "localhost"; -#endif } } } diff --git a/src/libraries/System.Net.NameResolution/src/System.Net.NameResolution.csproj b/src/libraries/System.Net.NameResolution/src/System.Net.NameResolution.csproj index 4e669d80fa1c2..1faa2e0480d09 100644 --- a/src/libraries/System.Net.NameResolution/src/System.Net.NameResolution.csproj +++ b/src/libraries/System.Net.NameResolution/src/System.Net.NameResolution.csproj @@ -18,8 +18,8 @@ - - + + @@ -107,8 +107,6 @@ - - diff --git a/src/libraries/System.Net.NameResolution/src/System/Net/Dns.cs b/src/libraries/System.Net.NameResolution/src/System/Net/Dns.cs index 282d2d1dcee29..5bedc17d253f8 100644 --- a/src/libraries/System.Net.NameResolution/src/System/Net/Dns.cs +++ b/src/libraries/System.Net.NameResolution/src/System/Net/Dns.cs @@ -38,9 +38,8 @@ public static string GetHostName() public static IPHostEntry GetHostEntry(IPAddress address) { -#if TARGET_WASI if (OperatingSystem.IsWasi()) throw new PlatformNotSupportedException(); // TODO remove with https://github.com/dotnet/runtime/pull/107185 -#endif // TARGET_WASI + ArgumentNullException.ThrowIfNull(address); if (address.Equals(IPAddress.Any) || address.Equals(IPAddress.IPv6Any)) @@ -72,8 +71,7 @@ public static IPHostEntry GetHostEntry(string hostNameOrAddress, AddressFamily f // See if it's an IP Address. IPHostEntry ipHostEntry; -#if !TARGET_WASI - if (IPAddress.TryParse(hostNameOrAddress, out IPAddress? address)) + if (NameResolutionPal.SupportsGetNameInfo && IPAddress.TryParse(hostNameOrAddress, out IPAddress? address)) { if (address.Equals(IPAddress.Any) || address.Equals(IPAddress.IPv6Any)) { @@ -84,7 +82,6 @@ public static IPHostEntry GetHostEntry(string hostNameOrAddress, AddressFamily f ipHostEntry = GetHostEntryCore(address, family); } else -#endif // TARGET_WASI { ipHostEntry = GetHostEntryCore(hostNameOrAddress, family); } @@ -153,9 +150,8 @@ public static Task GetHostEntryAsync(string hostNameOrAddress, Addr public static Task GetHostEntryAsync(IPAddress address) { -#if TARGET_WASI - throw new PlatformNotSupportedException(); // TODO remove with https://github.com/dotnet/runtime/pull/107185 -#else + if (OperatingSystem.IsWasi()) throw new PlatformNotSupportedException(); // TODO remove with https://github.com/dotnet/runtime/pull/107185 + ArgumentNullException.ThrowIfNull(address); if (address.Equals(IPAddress.Any) || address.Equals(IPAddress.IPv6Any)) @@ -165,11 +161,12 @@ public static Task GetHostEntryAsync(IPAddress address) } return RunAsync(static (s, activity) => { + if (OperatingSystem.IsWasi()) throw new PlatformNotSupportedException(); // TODO remove with https://github.com/dotnet/runtime/pull/107185 + IPHostEntry ipHostEntry = GetHostEntryCore((IPAddress)s, AddressFamily.Unspecified, activity); if (NetEventSource.Log.IsEnabled()) NetEventSource.Info((IPAddress)s, $"{ipHostEntry} with {ipHostEntry.AddressList.Length} entries"); return ipHostEntry; }, address, CancellationToken.None); -#endif // TARGET_WASI } public static IAsyncResult BeginGetHostEntry(IPAddress address, AsyncCallback? requestCallback, object? stateObject) => @@ -180,9 +177,8 @@ public static IAsyncResult BeginGetHostEntry(string hostNameOrAddress, AsyncCall public static IPHostEntry EndGetHostEntry(IAsyncResult asyncResult) { -#if TARGET_WASI if (OperatingSystem.IsWasi()) throw new PlatformNotSupportedException(); // TODO remove with https://github.com/dotnet/runtime/pull/107185 -#endif // TARGET_WASI + ArgumentNullException.ThrowIfNull(asyncResult); return TaskToAsyncResult.End(asyncResult); @@ -205,7 +201,6 @@ public static IPAddress[] GetHostAddresses(string hostNameOrAddress, AddressFami // See if it's an IP Address. IPAddress[] addresses; -#if !TARGET_WASI if (IPAddress.TryParse(hostNameOrAddress, out IPAddress? address)) { if (address.Equals(IPAddress.Any) || address.Equals(IPAddress.IPv6Any)) @@ -217,7 +212,6 @@ public static IPAddress[] GetHostAddresses(string hostNameOrAddress, AddressFami addresses = (family == AddressFamily.Unspecified || address.AddressFamily == family) ? new IPAddress[] { address } : Array.Empty(); } else -#endif // TARGET_WASI { addresses = GetHostAddressesCore(hostNameOrAddress, family); } @@ -259,9 +253,8 @@ public static IAsyncResult BeginGetHostAddresses(string hostNameOrAddress, Async public static IPAddress[] EndGetHostAddresses(IAsyncResult asyncResult) { -#if TARGET_WASI if (OperatingSystem.IsWasi()) throw new PlatformNotSupportedException(); // TODO remove with https://github.com/dotnet/runtime/pull/107185 -#endif // TARGET_WASI + ArgumentNullException.ThrowIfNull(asyncResult); return TaskToAsyncResult.End(asyncResult); @@ -287,9 +280,8 @@ public static IAsyncResult BeginGetHostByName(string hostName, AsyncCallback? re [Obsolete("EndGetHostByName has been deprecated. Use EndGetHostEntry instead.")] public static IPHostEntry EndGetHostByName(IAsyncResult asyncResult) { -#if TARGET_WASI if (OperatingSystem.IsWasi()) throw new PlatformNotSupportedException(); // TODO remove with https://github.com/dotnet/runtime/pull/107185 -#endif // TARGET_WASI + ArgumentNullException.ThrowIfNull(asyncResult); return TaskToAsyncResult.End(asyncResult); @@ -298,9 +290,8 @@ public static IPHostEntry EndGetHostByName(IAsyncResult asyncResult) [Obsolete("GetHostByAddress has been deprecated. Use GetHostEntry instead.")] public static IPHostEntry GetHostByAddress(string address) { -#if TARGET_WASI if (OperatingSystem.IsWasi()) throw new PlatformNotSupportedException(); // TODO remove with https://github.com/dotnet/runtime/pull/107185 -#endif // TARGET_WASI + ArgumentNullException.ThrowIfNull(address); IPHostEntry ipHostEntry = GetHostEntryCore(IPAddress.Parse(address), AddressFamily.Unspecified); @@ -312,9 +303,8 @@ public static IPHostEntry GetHostByAddress(string address) [Obsolete("GetHostByAddress has been deprecated. Use GetHostEntry instead.")] public static IPHostEntry GetHostByAddress(IPAddress address) { -#if TARGET_WASI if (OperatingSystem.IsWasi()) throw new PlatformNotSupportedException(); // TODO remove with https://github.com/dotnet/runtime/pull/107185 -#endif // TARGET_WASI + ArgumentNullException.ThrowIfNull(address); IPHostEntry ipHostEntry = GetHostEntryCore(address, AddressFamily.Unspecified); @@ -330,8 +320,7 @@ public static IPHostEntry Resolve(string hostName) // See if it's an IP Address. IPHostEntry ipHostEntry; -#if !TARGET_WASI - if (IPAddress.TryParse(hostName, out IPAddress? address) && + if (NameResolutionPal.SupportsGetNameInfo && IPAddress.TryParse(hostName, out IPAddress? address) && (address.AddressFamily != AddressFamily.InterNetworkV6 || SocketProtocolSupportPal.OSSupportsIPv6)) { try @@ -345,7 +334,6 @@ public static IPHostEntry Resolve(string hostName) } } else -#endif // TARGET_WASI { ipHostEntry = GetHostEntryCore(hostName, AddressFamily.Unspecified); } @@ -361,9 +349,8 @@ public static IAsyncResult BeginResolve(string hostName, AsyncCallback? requestC [Obsolete("EndResolve has been deprecated. Use EndGetHostEntry instead.")] public static IPHostEntry EndResolve(IAsyncResult asyncResult) { -#if TARGET_WASI if (OperatingSystem.IsWasi()) throw new PlatformNotSupportedException(); // TODO remove with https://github.com/dotnet/runtime/pull/107185 -#endif // TARGET_WASI + IPHostEntry ipHostEntry; try @@ -437,18 +424,17 @@ private static object GetHostEntryOrAddressesCore(string hostName, bool justAddr return result; } - [UnsupportedOSPlatform("wasi")] private static IPHostEntry GetHostEntryCore(IPAddress address, AddressFamily addressFamily, NameResolutionActivity? activityOrDefault = default) => (IPHostEntry)GetHostEntryOrAddressesCore(address, justAddresses: false, addressFamily, activityOrDefault); - [UnsupportedOSPlatform("wasi")] private static IPAddress[] GetHostAddressesCore(IPAddress address, AddressFamily addressFamily, NameResolutionActivity? activityOrDefault = default) => (IPAddress[])GetHostEntryOrAddressesCore(address, justAddresses: true, addressFamily, activityOrDefault); // Does internal IPAddress reverse and then forward lookups (for Legacy and current public methods). - [UnsupportedOSPlatform("wasi")] private static object GetHostEntryOrAddressesCore(IPAddress address, bool justAddresses, AddressFamily addressFamily, NameResolutionActivity? activityOrDefault = default) { + if (OperatingSystem.IsWasi()) throw new PlatformNotSupportedException(); // TODO remove with https://github.com/dotnet/runtime/pull/107185 + // Try to get the data for the host from its address. // We need to call getnameinfo first, because getaddrinfo w/ the ipaddress string // will only return that address and not the full list. @@ -534,9 +520,8 @@ private static Task GetHostEntryOrAddressesCoreAsync(string hostName, bool justR object asyncState; -#if !TARGET_WASI // See if it's an IP Address. - if (IPAddress.TryParse(hostName, out IPAddress? ipAddress)) + if (NameResolutionPal.SupportsGetNameInfo && IPAddress.TryParse(hostName, out IPAddress? ipAddress)) { if (throwOnIIPAny && (ipAddress.Equals(IPAddress.Any) || ipAddress.Equals(IPAddress.IPv6Any))) { @@ -554,7 +539,6 @@ private static Task GetHostEntryOrAddressesCoreAsync(string hostName, bool justR asyncState = family == AddressFamily.Unspecified ? (object)ipAddress : new KeyValuePair(ipAddress, family); } else -#endif // TARGET_WASI { if (NameResolutionPal.SupportsGetAddrInfoAsync) { @@ -595,13 +579,8 @@ private static Task GetHostEntryOrAddressesCoreAsync(string hostName, bool justR { string h => GetHostAddressesCore(h, AddressFamily.Unspecified, activity), KeyValuePair t => GetHostAddressesCore(t.Key, t.Value, activity), -#if !TARGET_WASI IPAddress a => GetHostAddressesCore(a, AddressFamily.Unspecified, activity), KeyValuePair t => GetHostAddressesCore(t.Key, t.Value, activity), -#else - IPAddress => throw new PlatformNotSupportedException(), - KeyValuePair => throw new PlatformNotSupportedException(), -#endif // TARGET_WASI _ => null }, asyncState, cancellationToken); } @@ -611,13 +590,8 @@ private static Task GetHostEntryOrAddressesCoreAsync(string hostName, bool justR { string h => GetHostEntryCore(h, AddressFamily.Unspecified, activity), KeyValuePair t => GetHostEntryCore(t.Key, t.Value, activity), -#if !TARGET_WASI IPAddress a => GetHostEntryCore(a, AddressFamily.Unspecified, activity), KeyValuePair t => GetHostEntryCore(t.Key, t.Value, activity), -#else - IPAddress => throw new PlatformNotSupportedException(), - KeyValuePair => throw new PlatformNotSupportedException(), -#endif // TARGET_WASI _ => null }, asyncState, cancellationToken); } diff --git a/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionPal.Unix.cs b/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionPal.Unix.cs index 29674b806a1fe..604a9890ff564 100644 --- a/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionPal.Unix.cs +++ b/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionPal.Unix.cs @@ -8,6 +8,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; +using System.Runtime.Versioning; namespace System.Net { @@ -15,6 +16,9 @@ internal static partial class NameResolutionPal { public const bool SupportsGetAddrInfoAsync = false; + [UnsupportedOSPlatformGuard("wasi")] + public static bool SupportsGetNameInfo = !OperatingSystem.IsWasi(); + #pragma warning disable IDE0060 internal static Task? GetAddrInfoAsync(string hostName, bool justAddresses, AddressFamily family, CancellationToken cancellationToken) => throw new NotSupportedException(); @@ -40,11 +44,8 @@ private static SocketError GetSocketErrorForNativeError(int error) case (int)Interop.Sys.GetAddrInfoErrorFlags.EAI_MEMORY: throw new OutOfMemoryException(); case (int)Interop.Sys.GetAddrInfoErrorFlags.EAI_SYSTEM: -#if !TARGET_WASI + Debug.Fail($"Unexpected error: {error} errno: {Interop.Sys.GetErrNo()}"); return SocketError.SocketError; -#else - throw new Exception("ErrNo: " + Interop.Sys.GetErrNo()); -#endif default: Debug.Fail($"Unexpected error: {error}"); return SocketError.SocketError; @@ -152,7 +153,8 @@ public static unsafe SocketError TryGetAddrInfo(string name, bool justAddresses, public static unsafe string? TryGetNameInfo(IPAddress addr, out SocketError socketError, out int nativeErrorCode) { -#if !TARGET_WASI + if (OperatingSystem.IsWasi()) throw new PlatformNotSupportedException(); // TODO remove with https://github.com/dotnet/runtime/pull/107185 + byte* buffer = stackalloc byte[Interop.Sys.NI_MAXHOST + 1 /*for null*/]; byte isIPv6; @@ -185,9 +187,6 @@ public static unsafe SocketError TryGetAddrInfo(string name, bool justAddresses, socketError = GetSocketErrorForNativeError(error); nativeErrorCode = error; return socketError == SocketError.Success ? Marshal.PtrToStringUTF8((IntPtr)buffer) : null; -#else - throw new PlatformNotSupportedException(); -#endif } public static string GetHostName() => Interop.Sys.GetHostName(); diff --git a/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionPal.Windows.cs b/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionPal.Windows.cs index 72fc7685dffe9..a044e20461273 100644 --- a/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionPal.Windows.cs +++ b/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionPal.Windows.cs @@ -9,6 +9,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.Win32.SafeHandles; +using System.Runtime.Versioning; namespace System.Net { @@ -43,6 +44,8 @@ static void Initialize() } } + public const bool SupportsGetNameInfo = true; + public static unsafe SocketError TryGetAddrInfo(string name, bool justAddresses, AddressFamily addressFamily, out string? hostName, out string[] aliases, out IPAddress[] addresses, out int nativeErrorCode) { Interop.Winsock.EnsureInitialized(); diff --git a/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionTelemetry.Wasi.cs b/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionTelemetry.Wasi.cs deleted file mode 100644 index d4842f1656946..0000000000000 --- a/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionTelemetry.Wasi.cs +++ /dev/null @@ -1,44 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.Collections.Generic; -using System.Diagnostics; -using System.Diagnostics.Tracing; -using System.Net.Sockets; -using System.Threading; -using System.Runtime.Versioning; - -namespace System.Net -{ -#pragma warning disable IDE0060 -#pragma warning disable CA1822 - internal sealed class NameResolutionTelemetry : EventSource - { - public static readonly NameResolutionTelemetry Log = new NameResolutionTelemetry(); - - [NonEvent] - public static bool AnyDiagnosticsEnabled() - { - return false; - } - - [NonEvent] - public NameResolutionActivity BeforeResolution(object hostNameOrAddress, long startingTimestamp = 0) - { - return default; - } - - [NonEvent] - public void AfterResolution(object hostNameOrAddress, in NameResolutionActivity activity, object? answer, Exception? exception = null) - { - } - } - - internal readonly struct NameResolutionActivity - { - public static bool IsTracingEnabled() - { - return false; - } - } -} diff --git a/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionTelemetry.cs b/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionTelemetry.cs index 07a252fbd250c..cbc844f24eb55 100644 --- a/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionTelemetry.cs +++ b/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionTelemetry.cs @@ -59,7 +59,7 @@ protected override void OnEventCommand(EventCommandEventArgs command) private void ResolutionFailed() => WriteEvent(ResolutionFailedEventId); [NonEvent] - public static bool AnyDiagnosticsEnabled() => Log.IsEnabled() || NameResolutionMetrics.IsEnabled() || NameResolutionActivity.IsTracingEnabled(); + public static bool AnyDiagnosticsEnabled() => !OperatingSystem.IsWasi() && Log.IsEnabled() || NameResolutionMetrics.IsEnabled() || NameResolutionActivity.IsTracingEnabled(); [NonEvent] public NameResolutionActivity BeforeResolution(object hostNameOrAddress, long startingTimestamp = 0) @@ -91,6 +91,8 @@ public NameResolutionActivity BeforeResolution(object hostNameOrAddress, long st [NonEvent] public void AfterResolution(object hostNameOrAddress, in NameResolutionActivity activity, object? answer, Exception? exception = null) { + if (OperatingSystem.IsWasi()) return; + if (!activity.Stop(answer, exception, out TimeSpan duration)) { // We stopped the System.Diagnostics.Activity at this point and neither metrics nor EventSource is enabled. diff --git a/src/native/libs/Common/pal_config.h.in b/src/native/libs/Common/pal_config.h.in index 4439e8cebfeaa..f1432497a9832 100644 --- a/src/native/libs/Common/pal_config.h.in +++ b/src/native/libs/Common/pal_config.h.in @@ -56,6 +56,10 @@ #cmakedefine01 HAVE_ETHTOOL_H #cmakedefine01 HAVE_SYS_POLL_H #cmakedefine01 HAVE_EPOLL +#cmakedefine01 HAVE_GETHOSTNAME +#cmakedefine01 HAVE_GETNAMEINFO +#cmakedefine01 HAVE_CMSGHDR +#cmakedefine01 HAVE_SOCKADDR_UN_SUN_PATH #cmakedefine01 HAVE_ACCEPT4 #cmakedefine01 HAVE_KQUEUE #cmakedefine01 HAVE_SENDFILE_4 diff --git a/src/native/libs/System.Native/pal_networking.c b/src/native/libs/System.Native/pal_networking.c index d5b3af8adfffe..3bb631a77f60a 100644 --- a/src/native/libs/System.Native/pal_networking.c +++ b/src/native/libs/System.Native/pal_networking.c @@ -143,16 +143,11 @@ struct in_pktinfo #define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP #endif -#if !defined(TARGET_WASI) -enum -{ -#if defined(__APPLE__) && __APPLE__ - LINGER_OPTION_NAME = SO_LINGER_SEC -#else - LINGER_OPTION_NAME = SO_LINGER, +#if defined(__APPLE__) && __APPLE__ && defined(SO_LINGER_SEC) + #define LINGER_OPTION_NAME SO_LINGER_SEC +#elif defined(SO_LINGER) + #define LINGER_OPTION_NAME SO_LINGER #endif -}; -#endif // TARGET_WASI enum { @@ -277,28 +272,26 @@ static void ConvertByteArrayToSockAddrIn6(struct sockaddr_in6* addr, const uint8 addr->sin6_family = AF_INET6; } -#if !defined(TARGET_WASI) -static void ConvertByteArrayToInAddr(struct in_addr* addr, const uint8_t* buffer, int32_t bufferLength) +static void ConvertInAddrToByteArray(uint8_t* buffer, int32_t bufferLength, const struct in_addr* addr) { assert(bufferLength == NUM_BYTES_IN_IPV4_ADDRESS); - memcpy_s(&addr->s_addr, NUM_BYTES_IN_IPV4_ADDRESS, buffer, (uint32_t)bufferLength); // Send back in network byte order. + memcpy_s(buffer, (uint32_t)bufferLength, &addr->s_addr, NUM_BYTES_IN_IPV4_ADDRESS); // Send back in network byte order. } -#endif // !TARGET_WASI -static void ConvertInAddrToByteArray(uint8_t* buffer, int32_t bufferLength, const struct in_addr* addr) +#if HAVE_GETNAMEINFO +static void ConvertByteArrayToInAddr(struct in_addr* addr, const uint8_t* buffer, int32_t bufferLength) { assert(bufferLength == NUM_BYTES_IN_IPV4_ADDRESS); - memcpy_s(buffer, (uint32_t)bufferLength, &addr->s_addr, NUM_BYTES_IN_IPV4_ADDRESS); // Send back in network byte order. + memcpy_s(&addr->s_addr, NUM_BYTES_IN_IPV4_ADDRESS, buffer, (uint32_t)bufferLength); // Send back in network byte order. } -#if !defined(TARGET_WASI) static void ConvertByteArrayToSockAddrIn(struct sockaddr_in* addr, const uint8_t* buffer, int32_t bufferLength) { ConvertByteArrayToInAddr(&addr->sin_addr, buffer, bufferLength); addr->sin_family = AF_INET; } -#endif // !TARGET_WASI +#endif // HAVE_GETNAMEINFO static int32_t ConvertGetAddrInfoAndGetNameInfoErrorsToPal(int32_t error) { @@ -558,7 +551,7 @@ typedef int32_t NativeFlagsType; typedef uint32_t NativeFlagsType; #endif -#if !defined(TARGET_WASI) +#if HAVE_GETNAMEINFO static inline NativeFlagsType ConvertGetNameInfoFlagsToNative(int32_t flags) { NativeFlagsType outFlags = 0; @@ -573,7 +566,7 @@ static inline NativeFlagsType ConvertGetNameInfoFlagsToNative(int32_t flags) return outFlags; } -#endif // !TARGET_WASI +#endif // HAVE_GETNAMEINFO int32_t SystemNative_GetNameInfo(const uint8_t* address, int32_t addressLength, @@ -584,7 +577,7 @@ int32_t SystemNative_GetNameInfo(const uint8_t* address, int32_t serviceLength, int32_t flags) { -#if !defined(TARGET_WASI) +#if HAVE_GETNAMEINFO assert(address != NULL); assert(addressLength > 0); assert((host != NULL) || (service != NULL)); @@ -621,7 +614,7 @@ int32_t SystemNative_GetNameInfo(const uint8_t* address, } return ConvertGetAddrInfoAndGetNameInfoErrorsToPal(result); -#else // TARGET_WASI +#else // HAVE_GETNAMEINFO (void)address; (void)addressLength, (void)isIPv6, @@ -631,7 +624,7 @@ int32_t SystemNative_GetNameInfo(const uint8_t* address, (void)serviceLength, (void)flags; return ConvertGetAddrInfoAndGetNameInfoErrorsToPal(EAI_FAIL); -#endif // !TARGET_WASI +#endif // HAVE_GETNAMEINFO } int32_t SystemNative_GetDomainName(uint8_t* name, int32_t nameLength) @@ -678,17 +671,17 @@ int32_t SystemNative_GetDomainName(uint8_t* name, int32_t nameLength) int32_t SystemNative_GetHostName(uint8_t* name, int32_t nameLength) { -#if !defined(TARGET_WASI) +#if HAVE_GETHOSTNAME assert(name != NULL); assert(nameLength > 0); size_t unsignedSize = (uint32_t)nameLength; return gethostname((char*)name, unsignedSize); -#else // TARGET_WASI +#else // HAVE_GETHOSTNAME (void)name; (void)nameLength; return Error_ENOTSUP; -#endif // !TARGET_WASI +#endif // HAVE_GETHOSTNAME } static bool IsInBounds(const void* void_baseAddr, size_t len, const void* void_valueAddr, size_t valueSize) @@ -939,7 +932,7 @@ SystemNative_SetIPv6Address(uint8_t* socketAddress, int32_t socketAddressLen, ui return Error_SUCCESS; } -#if !defined(TARGET_WASI) +#if HAVE_CMSGHDR static int8_t IsStreamSocket(int socket) { int type; @@ -966,23 +959,23 @@ static void ConvertMessageHeaderToMsghdr(struct msghdr* header, const MessageHea header->msg_controllen = (uint32_t)messageHeader->ControlBufferLen; header->msg_flags = 0; } -#endif // !TARGET_WASI +#endif // HAVE_CMSGHDR int32_t SystemNative_GetControlMessageBufferSize(int32_t isIPv4, int32_t isIPv6) { // Note: it is possible that the address family of the socket is neither // AF_INET nor AF_INET6. In this case both inputs will be 0 and // the control message buffer size should be zero. -#if !defined(TARGET_WASI) +#ifdef CMSG_SPACE return (isIPv4 != 0 ? CMSG_SPACE(sizeof(struct in_pktinfo)) : 0) + (isIPv6 != 0 ? CMSG_SPACE(sizeof(struct in6_pktinfo)) : 0); -#else // TARGET_WASI +#else // CMSG_SPACE (void)isIPv4; (void)isIPv6; return 0; -#endif // TARGET_WASI +#endif // CMSG_SPACE } -#if !defined(TARGET_WASI) +#if HAVE_CMSGHDR static int32_t GetIPv4PacketInformation(struct cmsghdr* controlMessage, IPPacketInformation* packetInfo) { assert(controlMessage != NULL); @@ -1061,7 +1054,7 @@ static struct cmsghdr* GET_CMSG_NXTHDR(struct msghdr* mhdr, struct cmsghdr* cmsg #pragma clang diagnostic pop #endif } -#endif // !TARGET_WASI +#endif // HAVE_CMSGHDR int32_t SystemNative_TryGetIPPacketInformation(MessageHeader* messageHeader, int32_t isIPv4, IPPacketInformation* packetInfo) @@ -1071,7 +1064,7 @@ SystemNative_TryGetIPPacketInformation(MessageHeader* messageHeader, int32_t isI return 0; } -#if !defined(TARGET_WASI) +#if HAVE_CMSGHDR struct msghdr header; ConvertMessageHeaderToMsghdr(&header, messageHeader, -1); @@ -1100,9 +1093,9 @@ SystemNative_TryGetIPPacketInformation(MessageHeader* messageHeader, int32_t isI } return 0; -#else // TARGET_WASI +#else // HAVE_CMSGHDR return Error_ENOTSUP; -#endif // TARGET_WASI +#endif // HAVE_CMSGHDR } static int8_t GetMulticastOptionName(int32_t multicastOption, int8_t isIPv6, int* optionName) @@ -1303,7 +1296,7 @@ int32_t SystemNative_GetLingerOption(intptr_t socket, LingerOption* option) return Error_EFAULT; } -#if !defined(TARGET_WASI) +#if defined(LINGER_OPTION_NAME) int fd = ToFileDescriptor(socket); struct linger opt; @@ -1318,11 +1311,11 @@ int32_t SystemNative_GetLingerOption(intptr_t socket, LingerOption* option) option->OnOff = opt.l_onoff; option->Seconds = opt.l_linger; return Error_SUCCESS; -#else // TARGET_WASI +#else // LINGER_OPTION_NAME (void)socket; (void)option; return Error_ENOTSUP; -#endif // TARGET_WASI +#endif // LINGER_OPTION_NAME } int32_t SystemNative_SetLingerOption(intptr_t socket, LingerOption* option) @@ -1337,7 +1330,7 @@ int32_t SystemNative_SetLingerOption(intptr_t socket, LingerOption* option) return Error_EINVAL; } -#if !defined(TARGET_WASI) +#if defined(LINGER_OPTION_NAME) int fd = ToFileDescriptor(socket); struct linger opt; @@ -1357,9 +1350,9 @@ int32_t SystemNative_SetLingerOption(intptr_t socket, LingerOption* option) #endif return err == 0 ? Error_SUCCESS : SystemNative_ConvertErrorPlatformToPal(errno); -#else // TARGET_WASI +#else // LINGER_OPTION_NAME return Error_ENOTSUP; -#endif // TARGET_WASI +#endif // LINGER_OPTION_NAME } static int32_t SetTimeoutOption(int32_t socket, int32_t millisecondsTimeout, int optionName) @@ -1389,40 +1382,62 @@ int32_t SystemNative_SetSendTimeout(intptr_t socket, int32_t millisecondsTimeout static int8_t ConvertSocketFlagsPalToPlatform(int32_t palFlags, int* platformFlags) { -#if defined(TARGET_WASI) - if (palFlags != 0) - { - return false; - } -#else // TARGET_WASI - const int32_t SupportedFlagsMask = + const int32_t SupportedFlagsMask = 0 #ifdef MSG_ERRQUEUE - SocketFlags_MSG_ERRQUEUE | + | SocketFlags_MSG_ERRQUEUE +#endif +#ifdef MSG_OOB + | SocketFlags_MSG_OOB +#endif +#ifdef MSG_PEEK + | SocketFlags_MSG_PEEK +#endif +#ifdef MSG_DONTWAIT + | SocketFlags_MSG_DONTWAIT +#endif +#ifdef MSG_DONTROUTE + | SocketFlags_MSG_DONTROUTE +#endif +#ifdef MSG_TRUNC + | SocketFlags_MSG_TRUNC +#endif +#ifdef MSG_CTRUNC + | SocketFlags_MSG_CTRUNC #endif - SocketFlags_MSG_OOB | SocketFlags_MSG_PEEK | SocketFlags_MSG_DONTROUTE | SocketFlags_MSG_TRUNC | SocketFlags_MSG_CTRUNC | SocketFlags_MSG_DONTWAIT; + ; if ((palFlags & ~SupportedFlagsMask) != 0) { return false; } - *platformFlags = ((palFlags & SocketFlags_MSG_OOB) == 0 ? 0 : MSG_OOB) | - ((palFlags & SocketFlags_MSG_PEEK) == 0 ? 0 : MSG_PEEK) | - ((palFlags & SocketFlags_MSG_DONTROUTE) == 0 ? 0 : MSG_DONTROUTE) | - ((palFlags & SocketFlags_MSG_DONTWAIT) == 0 ? 0 : MSG_DONTWAIT) | - ((palFlags & SocketFlags_MSG_TRUNC) == 0 ? 0 : MSG_TRUNC) | - ((palFlags & SocketFlags_MSG_CTRUNC) == 0 ? 0 : MSG_CTRUNC); + *platformFlags = 0 #ifdef MSG_ERRQUEUE - if ((palFlags & SocketFlags_MSG_ERRQUEUE) != 0) - { - *platformFlags |= MSG_ERRQUEUE; - } + | ((palFlags & SocketFlags_MSG_ERRQUEUE) == 0 ? 0 : MSG_ERRQUEUE) +#endif +#ifdef MSG_OOB + | ((palFlags & SocketFlags_MSG_OOB) == 0 ? 0 : MSG_OOB) +#endif +#ifdef MSG_PEEK + | ((palFlags & SocketFlags_MSG_PEEK) == 0 ? 0 : MSG_PEEK) +#endif +#ifdef MSG_DONTROUTE + | ((palFlags & SocketFlags_MSG_DONTROUTE) == 0 ? 0 : MSG_DONTROUTE) +#endif +#ifdef MSG_DONTWAIT + | ((palFlags & SocketFlags_MSG_DONTWAIT) == 0 ? 0 : MSG_DONTWAIT) +#endif +#ifdef MSG_TRUNC + | ((palFlags & SocketFlags_MSG_TRUNC) == 0 ? 0 : MSG_TRUNC) #endif -#endif // !TARGET_WASI +#ifdef MSG_CTRUNC + | ((palFlags & SocketFlags_MSG_CTRUNC) == 0 ? 0 : MSG_CTRUNC) +#endif + ; return true; } -#if !defined(TARGET_WASI) +#if HAVE_CMSGHDR static int32_t ConvertSocketFlagsPlatformToPal(int platformFlags) { const int SupportedFlagsMask = MSG_OOB | MSG_DONTROUTE | MSG_TRUNC | MSG_CTRUNC; @@ -1434,7 +1449,7 @@ static int32_t ConvertSocketFlagsPlatformToPal(int platformFlags) ((platformFlags & MSG_TRUNC) == 0 ? 0 : SocketFlags_MSG_TRUNC) | ((platformFlags & MSG_CTRUNC) == 0 ? 0 : SocketFlags_MSG_CTRUNC); } -#endif // !TARGET_WASI +#endif // HAVE_CMSGHDR int32_t SystemNative_Receive(intptr_t socket, void* buffer, int32_t bufferLen, int32_t flags, int32_t* received) { @@ -1535,11 +1550,10 @@ int32_t SystemNative_ReceiveMessage(intptr_t socket, MessageHeader* messageHeade } ssize_t res; -#if defined(TARGET_WASI) +#if !HAVE_CMSGHDR // TODO https://github.com/dotnet/runtime/issues/98957 - assert_msg(false, "Not supported on WASI yet", 0); return Error_ENOTSUP; -#else // TARGET_WASI +#else // !HAVE_CMSGHDR struct msghdr header; ConvertMessageHeaderToMsghdr(&header, messageHeader, fd); @@ -1564,7 +1578,7 @@ int32_t SystemNative_ReceiveMessage(intptr_t socket, MessageHeader* messageHeade *received = 0; return SystemNative_ConvertErrorPlatformToPal(errno); -#endif // !TARGET_WASI +#endif // !HAVE_CMSGHDR } int32_t SystemNative_Send(intptr_t socket, void* buffer, int32_t bufferLen, int32_t flags, int32_t* sent) @@ -1618,11 +1632,10 @@ int32_t SystemNative_SendMessage(intptr_t socket, MessageHeader* messageHeader, return Error_ENOTSUP; } -#if defined(TARGET_WASI) +#if !HAVE_CMSGHDR // TODO https://github.com/dotnet/runtime/issues/98957 - assert_msg(false, "Not supported on WASI yet", 0); return Error_ENOTSUP; -#else // TARGET_WASI +#else // !HAVE_CMSGHDR ssize_t res; struct msghdr header; ConvertMessageHeaderToMsghdr(&header, messageHeader, fd); @@ -1636,7 +1649,6 @@ int32_t SystemNative_SendMessage(intptr_t socket, MessageHeader* messageHeader, #else while ((res = sendmsg(fd, &header, socketFlags)) < 0 && errno == EINTR); #endif - if (res != -1) { *sent = res; @@ -1645,7 +1657,7 @@ int32_t SystemNative_SendMessage(intptr_t socket, MessageHeader* messageHeader, *sent = 0; return SystemNative_ConvertErrorPlatformToPal(errno); -#endif // !TARGET_WASI +#endif // !HAVE_CMSGHDR } int32_t SystemNative_Accept(intptr_t socket, uint8_t* socketAddress, int32_t* socketAddressLen, intptr_t* acceptedSocket) @@ -1869,11 +1881,11 @@ static bool TryGetPlatformSocketOption(int32_t socketOptionLevel, int32_t socket switch (socketOptionName) { -#if !defined(TARGET_WASI) +#if defined(SO_DEBUG) case SocketOptionName_SO_DEBUG: *optName = SO_DEBUG; return true; -#endif // !TARGET_WASI +#endif case SocketOptionName_SO_ACCEPTCONN: *optName = SO_ACCEPTCONN; @@ -1887,25 +1899,31 @@ static bool TryGetPlatformSocketOption(int32_t socketOptionLevel, int32_t socket *optName = SO_KEEPALIVE; return true; -#if !defined(TARGET_WASI) +#if defined(SO_DONTROUTE) case SocketOptionName_SO_DONTROUTE: *optName = SO_DONTROUTE; return true; +#endif +#if defined(SO_BROADCAST) case SocketOptionName_SO_BROADCAST: *optName = SO_BROADCAST; return true; +#endif // case SocketOptionName_SO_USELOOPBACK: +#if defined(SO_LINGER) case SocketOptionName_SO_LINGER: *optName = SO_LINGER; return true; +#endif +#if defined(SO_OOBINLINE) case SocketOptionName_SO_OOBINLINE: *optName = SO_OOBINLINE; return true; -#endif // !TARGET_WASI +#endif // case SocketOptionName_SO_DONTLINGER: @@ -1919,16 +1937,18 @@ static bool TryGetPlatformSocketOption(int32_t socketOptionLevel, int32_t socket *optName = SO_RCVBUF; return true; -#if !defined(TARGET_WASI) +#if defined(SO_SNDLOWAT) case SocketOptionName_SO_SNDLOWAT: *optName = SO_SNDLOWAT; return true; +#endif +#if defined(SO_RCVLOWAT) case SocketOptionName_SO_RCVLOWAT: *optName = SO_RCVLOWAT; return true; -#endif // !TARGET_WASI +#endif case SocketOptionName_SO_SNDTIMEO: *optName = SO_SNDTIMEO; return true; @@ -2148,11 +2168,11 @@ static bool TryConvertSocketTypePlatformToPal(int platformSocketType, int32_t* p *palSocketType = SocketType_SOCK_DGRAM; return true; -#if !defined(TARGET_WASI) +#if defined(SOCK_RAW) case SOCK_RAW: *palSocketType = SocketType_SOCK_RAW; return true; -#endif // !TARGET_WASI +#endif // SOCK_RAW #ifdef SOCK_RDM case SOCK_RDM: @@ -2160,11 +2180,11 @@ static bool TryConvertSocketTypePlatformToPal(int platformSocketType, int32_t* p return true; #endif -#if !defined(TARGET_WASI) +#if defined(SOCK_SEQPACKET) case SOCK_SEQPACKET: *palSocketType = SocketType_SOCK_SEQPACKET; return true; -#endif // !TARGET_WASI +#endif // SOCK_SEQPACKET default: *palSocketType = (int32_t)platformSocketType; @@ -2424,11 +2444,11 @@ static bool TryConvertSocketTypePalToPlatform(int32_t palSocketType, int* platfo *platformSocketType = SOCK_DGRAM; return true; -#if !defined(TARGET_WASI) +#if defined(SOCK_RAW) case SocketType_SOCK_RAW: *platformSocketType = SOCK_RAW; return true; -#endif // !TARGET_WASI +#endif // SOCK_RAW #ifdef SOCK_RDM case SocketType_SOCK_RDM: @@ -2436,11 +2456,11 @@ static bool TryConvertSocketTypePalToPlatform(int32_t palSocketType, int* platfo return true; #endif -#if !defined(TARGET_WASI) +#if defined(SOCK_SEQPACKET) case SocketType_SOCK_SEQPACKET: *platformSocketType = SOCK_SEQPACKET; return true; -#endif // !TARGET_WASI +#endif // SOCK_SEQPACKET default: *platformSocketType = (int)palSocketType; @@ -2484,11 +2504,11 @@ static bool TryConvertProtocolTypePalToPlatform(int32_t palAddressFamily, int32_ *platformProtocolType = 0; return true; -#if !defined(TARGET_WASI) +#if defined(IPPROTO_ICMP) case ProtocolType_PT_ICMP: *platformProtocolType = IPPROTO_ICMP; return true; -#endif // !TARGET_WASI +#endif case ProtocolType_PT_TCP: *platformProtocolType = IPPROTO_TCP; @@ -2498,11 +2518,11 @@ static bool TryConvertProtocolTypePalToPlatform(int32_t palAddressFamily, int32_ *platformProtocolType = IPPROTO_UDP; return true; -#if !defined(TARGET_WASI) +#if defined(IPPROTO_IGMP) case ProtocolType_PT_IGMP: *platformProtocolType = IPPROTO_IGMP; return true; -#endif // !TARGET_WASI +#endif case ProtocolType_PT_RAW: *platformProtocolType = IPPROTO_RAW; @@ -2520,12 +2540,12 @@ static bool TryConvertProtocolTypePalToPlatform(int32_t palAddressFamily, int32_ *platformProtocolType = 0; return true; -#if !defined(TARGET_WASI) +#if defined(IPPROTO_ICMPV6) case ProtocolType_PT_ICMPV6: case ProtocolType_PT_ICMP: *platformProtocolType = IPPROTO_ICMPV6; return true; -#endif // !TARGET_WASI +#endif case ProtocolType_PT_TCP: *platformProtocolType = IPPROTO_TCP; @@ -2535,33 +2555,39 @@ static bool TryConvertProtocolTypePalToPlatform(int32_t palAddressFamily, int32_ *platformProtocolType = IPPROTO_UDP; return true; -#if !defined(TARGET_WASI) +#if defined(IPPROTO_IGMP) case ProtocolType_PT_IGMP: *platformProtocolType = IPPROTO_IGMP; return true; -#endif // !TARGET_WASI +#endif case ProtocolType_PT_RAW: *platformProtocolType = IPPROTO_RAW; return true; -#if !defined(TARGET_WASI) +#if defined(IPPROTO_DSTOPTS) case ProtocolType_PT_DSTOPTS: *platformProtocolType = IPPROTO_DSTOPTS; return true; +#endif +#if defined(IPPROTO_NONE) case ProtocolType_PT_NONE: *platformProtocolType = IPPROTO_NONE; return true; +#endif +#if defined(IPPROTO_ROUTING) case ProtocolType_PT_ROUTING: *platformProtocolType = IPPROTO_ROUTING; return true; +#endif +#if defined(IPPROTO_FRAGMENT) case ProtocolType_PT_FRAGMENT: *platformProtocolType = IPPROTO_FRAGMENT; return true; -#endif // !TARGET_WASI +#endif default: *platformProtocolType = (int)palProtocolType; @@ -2617,11 +2643,11 @@ static bool TryConvertProtocolTypePlatformToPal(int32_t palAddressFamily, int pl *palProtocolType = ProtocolType_PT_UNSPECIFIED; return true; -#if !defined(TARGET_WASI) +#if defined(IPPROTO_ICMP) case IPPROTO_ICMP: *palProtocolType = ProtocolType_PT_ICMP; return true; -#endif // !TARGET_WASI +#endif case IPPROTO_TCP: *palProtocolType = ProtocolType_PT_TCP; @@ -2631,11 +2657,11 @@ static bool TryConvertProtocolTypePlatformToPal(int32_t palAddressFamily, int pl *palProtocolType = ProtocolType_PT_UDP; return true; -#if !defined(TARGET_WASI) +#if defined(IPPROTO_IGMP) case IPPROTO_IGMP: *palProtocolType = ProtocolType_PT_IGMP; return true; -#endif // !TARGET_WASI +#endif case IPPROTO_RAW: *palProtocolType = ProtocolType_PT_RAW; @@ -2653,11 +2679,11 @@ static bool TryConvertProtocolTypePlatformToPal(int32_t palAddressFamily, int pl *palProtocolType = ProtocolType_PT_UNSPECIFIED; return true; -#if !defined(TARGET_WASI) +#if defined(IPPROTO_ICMPV6) case IPPROTO_ICMPV6: *palProtocolType = ProtocolType_PT_ICMPV6; return true; -#endif // !TARGET_WASI +#endif case IPPROTO_TCP: *palProtocolType = ProtocolType_PT_TCP; @@ -2667,33 +2693,39 @@ static bool TryConvertProtocolTypePlatformToPal(int32_t palAddressFamily, int pl *palProtocolType = ProtocolType_PT_UDP; return true; -#if !defined(TARGET_WASI) +#if defined(IPPROTO_IGMP) case IPPROTO_IGMP: *palProtocolType = ProtocolType_PT_IGMP; return true; -#endif // !TARGET_WASI +#endif case IPPROTO_RAW: *palProtocolType = ProtocolType_PT_RAW; return true; -#if !defined(TARGET_WASI) +#if defined(IPPROTO_DSTOPTS) case IPPROTO_DSTOPTS: *palProtocolType = ProtocolType_PT_DSTOPTS; return true; +#endif +#if defined(IPPROTO_NONE) case IPPROTO_NONE: *palProtocolType = ProtocolType_PT_NONE; return true; +#endif +#if defined(IPPROTO_ROUTING) case IPPROTO_ROUTING: *palProtocolType = ProtocolType_PT_ROUTING; return true; +#endif +#if defined(IPPROTO_FRAGMENT) case IPPROTO_FRAGMENT: *palProtocolType = ProtocolType_PT_FRAGMENT; return true; -#endif // !TARGET_WASI +#endif default: *palProtocolType = (int)platformProtocolType; @@ -2835,7 +2867,7 @@ int32_t SystemNative_GetSocketType(intptr_t socket, int32_t* addressFamily, int3 int32_t SystemNative_GetAtOutOfBandMark(intptr_t socket, int32_t* atMark) { -#if !defined(TARGET_WASI) +#if defined(SIOCATMARK) if (atMark == NULL) { return Error_EFAULT; @@ -2854,9 +2886,9 @@ int32_t SystemNative_GetAtOutOfBandMark(intptr_t socket, int32_t* atMark) *atMark = (int32_t)result; return Error_SUCCESS; -#else // TARGET_WASI +#else // SIOCATMARK return Error_ENOTSUP; -#endif // !TARGET_WASI +#endif // SIOCATMARK } int32_t SystemNative_GetBytesAvailable(intptr_t socket, int32_t* available) @@ -3382,17 +3414,16 @@ void SystemNative_GetDomainSocketSizes(int32_t* pathOffset, int32_t* pathSize, i assert(pathSize != NULL); assert(addressSize != NULL); -#if !defined(TARGET_WASI) struct sockaddr_un domainSocket; +#if HAVE_SOCKADDR_UN_SUN_PATH *pathOffset = offsetof(struct sockaddr_un, sun_path); *pathSize = sizeof(domainSocket.sun_path); - *addressSize = sizeof(domainSocket); -#else // TARGET_WASI +#else // HAVE_SOCKADDR_UN_SUN_PATH *pathOffset = 0; *pathSize = 0; - *addressSize = 0; -#endif // TARGET_WASI +#endif // HAVE_SOCKADDR_UN_SUN_PATH + *addressSize = sizeof(domainSocket); } int32_t SystemNative_GetMaximumAddressSize(void) @@ -3571,13 +3602,13 @@ int32_t SystemNative_SendFile(intptr_t out_fd, intptr_t in_fd, int64_t offset, i uint32_t SystemNative_InterfaceNameToIndex(char* interfaceName) { -#if !defined(TARGET_WASI) +#if HAVE_NET_IF_H assert(interfaceName != NULL); if (interfaceName[0] == '%') interfaceName++; return if_nametoindex(interfaceName); -#else // TARGET_WASI +#else // HAVE_NET_IF_H (void)interfaceName; return 0; -#endif // !TARGET_WASI +#endif // HAVE_NET_IF_H } diff --git a/src/native/libs/configure.cmake b/src/native/libs/configure.cmake index 946702894fe62..ed273eb350bfd 100644 --- a/src/native/libs/configure.cmake +++ b/src/native/libs/configure.cmake @@ -458,6 +458,23 @@ check_symbol_exists( sys/epoll.h HAVE_EPOLL) +check_symbol_exists( + gethostname + unistd.h + HAVE_GETHOSTNAME) + +check_symbol_exists( + cmsghdr + socket.h + HAVE_CMSGHDR) + +check_symbol_exists( + getnameinfo + netdb.h + HAVE_GETNAMEINFO) + +check_struct_has_member("struct sockaddr_un" sin_len "netinet/un.h" HAVE_SOCKADDR_UN_SUN_PATH) + check_symbol_exists( accept4 sys/socket.h @@ -565,6 +582,7 @@ elseif(CLR_CMAKE_TARGET_ANDROID) elseif(CLR_CMAKE_TARGET_WASI) set(HAVE_FORK 0) set(HAVE_GETIFADDRS 0) + set(HAVE_GETNAMEINFO 0) elseif(CLR_CMAKE_TARGET_BROWSER) set(HAVE_FORK 0) else() From c6dc3da7423539ebf75d6adbab8ecb82c72322ba Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Wed, 11 Sep 2024 15:17:47 +0200 Subject: [PATCH 06/19] more --- src/native/libs/System.Native/pal_networking.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/native/libs/System.Native/pal_networking.c b/src/native/libs/System.Native/pal_networking.c index 3bb631a77f60a..752df3926a73c 100644 --- a/src/native/libs/System.Native/pal_networking.c +++ b/src/native/libs/System.Native/pal_networking.c @@ -966,13 +966,13 @@ int32_t SystemNative_GetControlMessageBufferSize(int32_t isIPv4, int32_t isIPv6) // Note: it is possible that the address family of the socket is neither // AF_INET nor AF_INET6. In this case both inputs will be 0 and // the control message buffer size should be zero. -#ifdef CMSG_SPACE +#if HAVE_CMSGHDR return (isIPv4 != 0 ? CMSG_SPACE(sizeof(struct in_pktinfo)) : 0) + (isIPv6 != 0 ? CMSG_SPACE(sizeof(struct in6_pktinfo)) : 0); -#else // CMSG_SPACE +#else // HAVE_CMSGHDR (void)isIPv4; (void)isIPv6; return 0; -#endif // CMSG_SPACE +#endif // HAVE_CMSGHDR } #if HAVE_CMSGHDR @@ -3609,6 +3609,6 @@ uint32_t SystemNative_InterfaceNameToIndex(char* interfaceName) return if_nametoindex(interfaceName); #else // HAVE_NET_IF_H (void)interfaceName; - return 0; + return Error_ENOTSUP; #endif // HAVE_NET_IF_H } From cb122e8a2059955a1e5788632ca78051f2113e3b Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Wed, 11 Sep 2024 16:13:14 +0200 Subject: [PATCH 07/19] fix --- src/native/libs/System.Native/pal_networking.c | 3 +++ src/native/libs/configure.cmake | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/native/libs/System.Native/pal_networking.c b/src/native/libs/System.Native/pal_networking.c index 752df3926a73c..36f3fd0800360 100644 --- a/src/native/libs/System.Native/pal_networking.c +++ b/src/native/libs/System.Native/pal_networking.c @@ -1094,6 +1094,9 @@ SystemNative_TryGetIPPacketInformation(MessageHeader* messageHeader, int32_t isI return 0; #else // HAVE_CMSGHDR + (void)messageHeader; + (void)isIPv4; + (void)packetInfo; return Error_ENOTSUP; #endif // HAVE_CMSGHDR } diff --git a/src/native/libs/configure.cmake b/src/native/libs/configure.cmake index ed273eb350bfd..e6503254a8303 100644 --- a/src/native/libs/configure.cmake +++ b/src/native/libs/configure.cmake @@ -465,7 +465,7 @@ check_symbol_exists( check_symbol_exists( cmsghdr - socket.h + sys/socket.h HAVE_CMSGHDR) check_symbol_exists( From 43360f994a0c98cdf4bd7adcf829cfed87e10b2c Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Wed, 11 Sep 2024 18:18:35 +0200 Subject: [PATCH 08/19] fix --- src/native/libs/Common/pal_config.h.in | 1 - .../libs/System.Native/pal_networking.c | 36 +++++++++---------- src/native/libs/configure.cmake | 5 --- 3 files changed, 18 insertions(+), 24 deletions(-) diff --git a/src/native/libs/Common/pal_config.h.in b/src/native/libs/Common/pal_config.h.in index f1432497a9832..c8e43fa37dd6a 100644 --- a/src/native/libs/Common/pal_config.h.in +++ b/src/native/libs/Common/pal_config.h.in @@ -58,7 +58,6 @@ #cmakedefine01 HAVE_EPOLL #cmakedefine01 HAVE_GETHOSTNAME #cmakedefine01 HAVE_GETNAMEINFO -#cmakedefine01 HAVE_CMSGHDR #cmakedefine01 HAVE_SOCKADDR_UN_SUN_PATH #cmakedefine01 HAVE_ACCEPT4 #cmakedefine01 HAVE_KQUEUE diff --git a/src/native/libs/System.Native/pal_networking.c b/src/native/libs/System.Native/pal_networking.c index 36f3fd0800360..82e3960e6fc33 100644 --- a/src/native/libs/System.Native/pal_networking.c +++ b/src/native/libs/System.Native/pal_networking.c @@ -932,7 +932,7 @@ SystemNative_SetIPv6Address(uint8_t* socketAddress, int32_t socketAddressLen, ui return Error_SUCCESS; } -#if HAVE_CMSGHDR +#if defined(CMSG_SPACE) static int8_t IsStreamSocket(int socket) { int type; @@ -959,23 +959,23 @@ static void ConvertMessageHeaderToMsghdr(struct msghdr* header, const MessageHea header->msg_controllen = (uint32_t)messageHeader->ControlBufferLen; header->msg_flags = 0; } -#endif // HAVE_CMSGHDR +#endif // CMSG_SPACE int32_t SystemNative_GetControlMessageBufferSize(int32_t isIPv4, int32_t isIPv6) { // Note: it is possible that the address family of the socket is neither // AF_INET nor AF_INET6. In this case both inputs will be 0 and // the control message buffer size should be zero. -#if HAVE_CMSGHDR +#if defined(CMSG_SPACE) return (isIPv4 != 0 ? CMSG_SPACE(sizeof(struct in_pktinfo)) : 0) + (isIPv6 != 0 ? CMSG_SPACE(sizeof(struct in6_pktinfo)) : 0); -#else // HAVE_CMSGHDR +#else // CMSG_SPACE (void)isIPv4; (void)isIPv6; return 0; -#endif // HAVE_CMSGHDR +#endif // CMSG_SPACE } -#if HAVE_CMSGHDR +#if defined(CMSG_SPACE) static int32_t GetIPv4PacketInformation(struct cmsghdr* controlMessage, IPPacketInformation* packetInfo) { assert(controlMessage != NULL); @@ -1054,7 +1054,7 @@ static struct cmsghdr* GET_CMSG_NXTHDR(struct msghdr* mhdr, struct cmsghdr* cmsg #pragma clang diagnostic pop #endif } -#endif // HAVE_CMSGHDR +#endif // CMSG_SPACE int32_t SystemNative_TryGetIPPacketInformation(MessageHeader* messageHeader, int32_t isIPv4, IPPacketInformation* packetInfo) @@ -1064,7 +1064,7 @@ SystemNative_TryGetIPPacketInformation(MessageHeader* messageHeader, int32_t isI return 0; } -#if HAVE_CMSGHDR +#if defined(CMSG_SPACE) struct msghdr header; ConvertMessageHeaderToMsghdr(&header, messageHeader, -1); @@ -1093,12 +1093,12 @@ SystemNative_TryGetIPPacketInformation(MessageHeader* messageHeader, int32_t isI } return 0; -#else // HAVE_CMSGHDR +#else // CMSG_SPACE (void)messageHeader; (void)isIPv4; (void)packetInfo; return Error_ENOTSUP; -#endif // HAVE_CMSGHDR +#endif // CMSG_SPACE } static int8_t GetMulticastOptionName(int32_t multicastOption, int8_t isIPv6, int* optionName) @@ -1440,7 +1440,7 @@ static int8_t ConvertSocketFlagsPalToPlatform(int32_t palFlags, int* platformFla return true; } -#if HAVE_CMSGHDR +#if defined(CMSG_SPACE) static int32_t ConvertSocketFlagsPlatformToPal(int platformFlags) { const int SupportedFlagsMask = MSG_OOB | MSG_DONTROUTE | MSG_TRUNC | MSG_CTRUNC; @@ -1452,7 +1452,7 @@ static int32_t ConvertSocketFlagsPlatformToPal(int platformFlags) ((platformFlags & MSG_TRUNC) == 0 ? 0 : SocketFlags_MSG_TRUNC) | ((platformFlags & MSG_CTRUNC) == 0 ? 0 : SocketFlags_MSG_CTRUNC); } -#endif // HAVE_CMSGHDR +#endif // CMSG_SPACE int32_t SystemNative_Receive(intptr_t socket, void* buffer, int32_t bufferLen, int32_t flags, int32_t* received) { @@ -1553,10 +1553,10 @@ int32_t SystemNative_ReceiveMessage(intptr_t socket, MessageHeader* messageHeade } ssize_t res; -#if !HAVE_CMSGHDR +#if !defined(CMSG_SPACE) // TODO https://github.com/dotnet/runtime/issues/98957 return Error_ENOTSUP; -#else // !HAVE_CMSGHDR +#else // !CMSG_SPACE struct msghdr header; ConvertMessageHeaderToMsghdr(&header, messageHeader, fd); @@ -1581,7 +1581,7 @@ int32_t SystemNative_ReceiveMessage(intptr_t socket, MessageHeader* messageHeade *received = 0; return SystemNative_ConvertErrorPlatformToPal(errno); -#endif // !HAVE_CMSGHDR +#endif // !CMSG_SPACE } int32_t SystemNative_Send(intptr_t socket, void* buffer, int32_t bufferLen, int32_t flags, int32_t* sent) @@ -1635,10 +1635,10 @@ int32_t SystemNative_SendMessage(intptr_t socket, MessageHeader* messageHeader, return Error_ENOTSUP; } -#if !HAVE_CMSGHDR +#if !defined(CMSG_SPACE) // TODO https://github.com/dotnet/runtime/issues/98957 return Error_ENOTSUP; -#else // !HAVE_CMSGHDR +#else // !CMSG_SPACE ssize_t res; struct msghdr header; ConvertMessageHeaderToMsghdr(&header, messageHeader, fd); @@ -1660,7 +1660,7 @@ int32_t SystemNative_SendMessage(intptr_t socket, MessageHeader* messageHeader, *sent = 0; return SystemNative_ConvertErrorPlatformToPal(errno); -#endif // !HAVE_CMSGHDR +#endif // !CMSG_SPACE } int32_t SystemNative_Accept(intptr_t socket, uint8_t* socketAddress, int32_t* socketAddressLen, intptr_t* acceptedSocket) diff --git a/src/native/libs/configure.cmake b/src/native/libs/configure.cmake index e6503254a8303..377b7442b51d7 100644 --- a/src/native/libs/configure.cmake +++ b/src/native/libs/configure.cmake @@ -463,11 +463,6 @@ check_symbol_exists( unistd.h HAVE_GETHOSTNAME) -check_symbol_exists( - cmsghdr - sys/socket.h - HAVE_CMSGHDR) - check_symbol_exists( getnameinfo netdb.h From f8ba745bdd2add50ed236444962d7c89ab3873af Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Wed, 11 Sep 2024 19:45:33 +0200 Subject: [PATCH 09/19] fix --- .../src/System.Net.NameResolution.csproj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libraries/System.Net.NameResolution/src/System.Net.NameResolution.csproj b/src/libraries/System.Net.NameResolution/src/System.Net.NameResolution.csproj index 1faa2e0480d09..8fd47689329d1 100644 --- a/src/libraries/System.Net.NameResolution/src/System.Net.NameResolution.csproj +++ b/src/libraries/System.Net.NameResolution/src/System.Net.NameResolution.csproj @@ -81,6 +81,8 @@ Link="Common\Interop\CoreLib\Unix\Interop.Errors.cs" /> + Date: Wed, 11 Sep 2024 20:43:01 +0200 Subject: [PATCH 10/19] fix --- src/native/libs/configure.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/native/libs/configure.cmake b/src/native/libs/configure.cmake index 377b7442b51d7..3242414720bcc 100644 --- a/src/native/libs/configure.cmake +++ b/src/native/libs/configure.cmake @@ -468,7 +468,7 @@ check_symbol_exists( netdb.h HAVE_GETNAMEINFO) -check_struct_has_member("struct sockaddr_un" sin_len "netinet/un.h" HAVE_SOCKADDR_UN_SUN_PATH) +check_struct_has_member("struct sockaddr_un" sun_path "netinet/un.h" HAVE_SOCKADDR_UN_SUN_PATH) check_symbol_exists( accept4 From 7e40a3d47471fbc9c9b06783846b1085483f6add Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Wed, 11 Sep 2024 22:55:49 +0200 Subject: [PATCH 11/19] fix --- src/native/libs/configure.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/native/libs/configure.cmake b/src/native/libs/configure.cmake index 3242414720bcc..529517899b571 100644 --- a/src/native/libs/configure.cmake +++ b/src/native/libs/configure.cmake @@ -468,7 +468,7 @@ check_symbol_exists( netdb.h HAVE_GETNAMEINFO) -check_struct_has_member("struct sockaddr_un" sun_path "netinet/un.h" HAVE_SOCKADDR_UN_SUN_PATH) +check_struct_has_member("struct sockaddr_un" sun_path "syn/un.h" HAVE_SOCKADDR_UN_SUN_PATH) check_symbol_exists( accept4 From 69421fb0914f763510964832865344ad9fd4785c Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Wed, 11 Sep 2024 23:46:20 +0200 Subject: [PATCH 12/19] fix? --- src/native/libs/configure.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/native/libs/configure.cmake b/src/native/libs/configure.cmake index 529517899b571..aa62b4af307e8 100644 --- a/src/native/libs/configure.cmake +++ b/src/native/libs/configure.cmake @@ -468,7 +468,7 @@ check_symbol_exists( netdb.h HAVE_GETNAMEINFO) -check_struct_has_member("struct sockaddr_un" sun_path "syn/un.h" HAVE_SOCKADDR_UN_SUN_PATH) +check_struct_has_member("struct sockaddr_un" sun_path "sys/types.h;syn/un.h" HAVE_SOCKADDR_UN_SUN_PATH) check_symbol_exists( accept4 From 9aea115d8606ac6d0ad5c5cdcdabd7104092ad21 Mon Sep 17 00:00:00 2001 From: Pavel Savara Date: Thu, 12 Sep 2024 10:55:33 +0200 Subject: [PATCH 13/19] Update src/native/libs/configure.cmake MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Alexander Köplinger --- src/native/libs/configure.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/native/libs/configure.cmake b/src/native/libs/configure.cmake index aa62b4af307e8..868bd7c30d6d8 100644 --- a/src/native/libs/configure.cmake +++ b/src/native/libs/configure.cmake @@ -468,7 +468,7 @@ check_symbol_exists( netdb.h HAVE_GETNAMEINFO) -check_struct_has_member("struct sockaddr_un" sun_path "sys/types.h;syn/un.h" HAVE_SOCKADDR_UN_SUN_PATH) +check_struct_has_member("struct sockaddr_un" sun_path "sys/types.h;sys/un.h" HAVE_SOCKADDR_UN_SUN_PATH) check_symbol_exists( accept4 From 195a475cfc2e209a4e07b2c395b84991864add74 Mon Sep 17 00:00:00 2001 From: Pavel Savara Date: Thu, 12 Sep 2024 10:57:33 +0200 Subject: [PATCH 14/19] Update src/libraries/System.Net.NameResolution/tests/FunctionalTests/LoggingTest.cs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Alexander Köplinger --- .../tests/FunctionalTests/LoggingTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/LoggingTest.cs b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/LoggingTest.cs index 9c443cc991135..43f3db17b3e90 100644 --- a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/LoggingTest.cs +++ b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/LoggingTest.cs @@ -15,7 +15,7 @@ namespace System.Net.NameResolution.Tests using Configuration = System.Net.Test.Common.Configuration; [Collection(nameof(DisableParallelization))] - [SkipOnPlatform(TestPlatforms.Wasi, "WASI has event source yet")] + [SkipOnPlatform(TestPlatforms.Wasi, "WASI doesn't have event source yet")] public class LoggingTest { [Fact] From aac1d37381900db4ca4454f76f512c7d3e4fd838 Mon Sep 17 00:00:00 2001 From: Pavel Savara Date: Thu, 12 Sep 2024 10:57:44 +0200 Subject: [PATCH 15/19] Update src/libraries/System.Net.NameResolution/tests/FunctionalTests/TelemetryTest.cs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Alexander Köplinger --- .../tests/FunctionalTests/TelemetryTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/TelemetryTest.cs b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/TelemetryTest.cs index 50e38a22c206f..3da2983720572 100644 --- a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/TelemetryTest.cs +++ b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/TelemetryTest.cs @@ -12,7 +12,7 @@ namespace System.Net.NameResolution.Tests { - [SkipOnPlatform(TestPlatforms.Wasi, "WASI has event source yet")] + [SkipOnPlatform(TestPlatforms.Wasi, "WASI doesn't have event source yet")] public class TelemetryTest { [Fact] From 806179da0c3ac961b9e50716e4addb3e5a1ddfb4 Mon Sep 17 00:00:00 2001 From: Pavel Savara Date: Thu, 12 Sep 2024 10:57:57 +0200 Subject: [PATCH 16/19] Update src/libraries/System.Net.NameResolution/tests/FunctionalTests/MetricsTest.cs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Alexander Köplinger --- .../tests/FunctionalTests/MetricsTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/MetricsTest.cs b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/MetricsTest.cs index cf9819cd9940f..ebee4d90e8dd1 100644 --- a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/MetricsTest.cs +++ b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/MetricsTest.cs @@ -12,7 +12,7 @@ namespace System.Net.NameResolution.Tests { - [SkipOnPlatform(TestPlatforms.Wasi, "WASI has event source yet")] + [SkipOnPlatform(TestPlatforms.Wasi, "WASI doesn't have event source yet")] public class MetricsTest { private const string DnsLookupDuration = "dns.lookup.duration"; From 4da7bc986a054b8fab0fa6fdc23d4128703d09af Mon Sep 17 00:00:00 2001 From: Pavel Savara Date: Thu, 12 Sep 2024 10:58:40 +0200 Subject: [PATCH 17/19] Update src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionPal.Unix.cs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Alexander Köplinger --- .../src/System/Net/NameResolutionPal.Unix.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionPal.Unix.cs b/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionPal.Unix.cs index 604a9890ff564..c2924830c07be 100644 --- a/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionPal.Unix.cs +++ b/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionPal.Unix.cs @@ -17,7 +17,7 @@ internal static partial class NameResolutionPal public const bool SupportsGetAddrInfoAsync = false; [UnsupportedOSPlatformGuard("wasi")] - public static bool SupportsGetNameInfo = !OperatingSystem.IsWasi(); + public static bool SupportsGetNameInfo => !OperatingSystem.IsWasi(); #pragma warning disable IDE0060 internal static Task? GetAddrInfoAsync(string hostName, bool justAddresses, AddressFamily family, CancellationToken cancellationToken) => From 145ca0ccd37b867c3f813eae79c9ffc344b637e7 Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Thu, 12 Sep 2024 12:18:17 +0200 Subject: [PATCH 18/19] feedback --- .../src/System.Net.NameResolution.csproj | 1 - .../src/System/Net/NameResolutionTelemetry.cs | 2 +- .../tests/FunctionalTests/GetHostEntryTest.cs | 5 +++-- .../System.Net.NameResolution.Functional.Tests.csproj | 4 ---- .../PalTests/System.Net.NameResolution.Pal.Tests.csproj | 4 ---- 5 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/libraries/System.Net.NameResolution/src/System.Net.NameResolution.csproj b/src/libraries/System.Net.NameResolution/src/System.Net.NameResolution.csproj index 8fd47689329d1..582fe6cc88241 100644 --- a/src/libraries/System.Net.NameResolution/src/System.Net.NameResolution.csproj +++ b/src/libraries/System.Net.NameResolution/src/System.Net.NameResolution.csproj @@ -11,7 +11,6 @@ $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) SR.SystemNetNameResolution_PlatformNotSupported ExcludeApiList.PNSE.Browser.txt - $(DefineConstants);TARGET_WASI diff --git a/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionTelemetry.cs b/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionTelemetry.cs index cbc844f24eb55..defa4da90564b 100644 --- a/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionTelemetry.cs +++ b/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionTelemetry.cs @@ -59,7 +59,7 @@ protected override void OnEventCommand(EventCommandEventArgs command) private void ResolutionFailed() => WriteEvent(ResolutionFailedEventId); [NonEvent] - public static bool AnyDiagnosticsEnabled() => !OperatingSystem.IsWasi() && Log.IsEnabled() || NameResolutionMetrics.IsEnabled() || NameResolutionActivity.IsTracingEnabled(); + public static bool AnyDiagnosticsEnabled() => !OperatingSystem.IsWasi() && (Log.IsEnabled() || NameResolutionMetrics.IsEnabled() || NameResolutionActivity.IsTracingEnabled()); [NonEvent] public NameResolutionActivity BeforeResolution(object hostNameOrAddress, long startingTimestamp = 0) diff --git a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostEntryTest.cs b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostEntryTest.cs index 5ca558b9316bd..c4988cef81672 100644 --- a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostEntryTest.cs +++ b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostEntryTest.cs @@ -274,11 +274,12 @@ public async Task DnsGetHostEntry_LocalHost_ReturnsFqdnAndLoopbackIPs(int mode) [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] [InlineData(0)] [InlineData(1)] -#if !TARGET_WASI [InlineData(2)] -#endif public async Task DnsGetHostEntry_LoopbackIP_MatchesGetHostEntryLoopbackString(int mode) { + if (OperatingSystem.IsWasi() && mode == 2) + throw new SkipTestException("mode 2 is not supported on WASI"); + IPAddress address = IPAddress.Loopback; IPHostEntry ipEntry = mode switch diff --git a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/System.Net.NameResolution.Functional.Tests.csproj b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/System.Net.NameResolution.Functional.Tests.csproj index 993acdec9d57f..9741c993ccdba 100644 --- a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/System.Net.NameResolution.Functional.Tests.csproj +++ b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/System.Net.NameResolution.Functional.Tests.csproj @@ -6,10 +6,6 @@ true true - - $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) - $(DefineConstants);TARGET_WASI - diff --git a/src/libraries/System.Net.NameResolution/tests/PalTests/System.Net.NameResolution.Pal.Tests.csproj b/src/libraries/System.Net.NameResolution/tests/PalTests/System.Net.NameResolution.Pal.Tests.csproj index 5eba286642c0f..7daa5977519b0 100644 --- a/src/libraries/System.Net.NameResolution/tests/PalTests/System.Net.NameResolution.Pal.Tests.csproj +++ b/src/libraries/System.Net.NameResolution/tests/PalTests/System.Net.NameResolution.Pal.Tests.csproj @@ -6,10 +6,6 @@ true true - - $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) - $(DefineConstants);TARGET_WASI - From 240f9e841278b994194f3eab63b4b5d2931a765f Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Thu, 12 Sep 2024 12:29:21 +0200 Subject: [PATCH 19/19] feedback --- src/native/libs/configure.cmake | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/native/libs/configure.cmake b/src/native/libs/configure.cmake index 868bd7c30d6d8..945fbed855ce8 100644 --- a/src/native/libs/configure.cmake +++ b/src/native/libs/configure.cmake @@ -576,8 +576,7 @@ elseif(CLR_CMAKE_TARGET_ANDROID) set(HAVE_CLOCK_REALTIME 1) elseif(CLR_CMAKE_TARGET_WASI) set(HAVE_FORK 0) - set(HAVE_GETIFADDRS 0) - set(HAVE_GETNAMEINFO 0) + unset(HAVE_GETNAMEINFO) # WASIp2 libc has empty function with TODO and abort() elseif(CLR_CMAKE_TARGET_BROWSER) set(HAVE_FORK 0) else()