Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Commit

Permalink
Fix GetAddrInfoExSupportsOverlapped UAP build break
Browse files Browse the repository at this point in the history
`System.Net.NameResolutionPal.GetAddrInfoExSupportsOverlapped` uses LoadLibraryExW which is not compatible with UAP (which only supports LoadLibrary of DLLs within a container). Refactor the helper so UAP returns false.
  • Loading branch information
nattress committed Feb 28, 2018
1 parent 30d10f5 commit f3a86db
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
</ItemGroup>
<ItemGroup Condition=" '$(TargetsWindows)' == 'true'">
<Compile Include="System\Net\NameResolutionPal.Windows.cs" />
<Compile Include="System\Net\NameResolutionPal.Windows.NetCoreApp.cs" Condition="'$(TargetGroup)' != 'uap'"/>
<Compile Include="System\Net\NameResolutionPal.Windows.Uap.cs" Condition="'$(TargetGroup)' == 'uap'"/>
<Compile Include="$(CommonPath)\System\Net\ContextAwareResult.Windows.cs">
<Link>Common\System\Net\ContextAwareResult.Windows.cs</Link>
</Compile>
Expand Down Expand Up @@ -132,7 +134,7 @@
<Compile Include="$(CommonPath)\Interop\Windows\Kernel32\Interop.GetProcAddress.cs">
<Link>Interop\Windows\Kernel32\Interop.GetProcAddress.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\Interop\Windows\Kernel32\Interop.LoadLibraryEx.cs">
<Compile Include="$(CommonPath)\Interop\Windows\Kernel32\Interop.LoadLibraryEx.cs" Condition="'$(TargetGroup)' != 'uap'">
<Link>Interop\Windows\Kernel32\Interop.LoadLibraryEx.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\Interop\Windows\Kernel32\Interop.FreeLibrary.cs">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Microsoft.Win32.SafeHandles;

namespace System.Net
{
internal static partial class NameResolutionPal
{

This comment has been minimized.

Copy link
@stephentoub

stephentoub Feb 28, 2018

Member

Nit: unnecessary blank line

private static bool GetAddrInfoExSupportsOverlapped()
{
using (SafeLibraryHandle libHandle = Interop.Kernel32.LoadLibraryExW(Interop.Libraries.Ws2_32, IntPtr.Zero, Interop.Kernel32.LOAD_LIBRARY_SEARCH_SYSTEM32))
{
if (libHandle.IsInvalid)
return false;

// We can't just check that 'GetAddrInfoEx' exists, because it existed before supporting overlapped.
// The existance of 'GetAddrInfoExCancel' indicates that overlapped is supported.
return Interop.Kernel32.GetProcAddress(libHandle, Interop.Winsock.GetAddrInfoExCancelFunctionName) != IntPtr.Zero;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace System.Net
{
internal static partial class NameResolutionPal
{

This comment has been minimized.

Copy link
@stephentoub

stephentoub Feb 28, 2018

Member

Nit: unnecessary blank line

private static bool GetAddrInfoExSupportsOverlapped()
{
return false;
}

This comment has been minimized.

Copy link
@stephentoub

stephentoub Feb 28, 2018

Member

Nit: could be simplified to:

private static bool GetAddrInfoExSupportsOverlapped() => false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace System.Net
{
internal static class NameResolutionPal
internal static partial class NameResolutionPal
{
//
// used by GetHostName() to preallocate a buffer for the call to gethostname.
Expand Down Expand Up @@ -339,19 +339,6 @@ public static void EnsureSocketsAreInitialized()
}
}

private static bool GetAddrInfoExSupportsOverlapped()
{
using (SafeLibraryHandle libHandle = Interop.Kernel32.LoadLibraryExW(Interop.Libraries.Ws2_32, IntPtr.Zero, Interop.Kernel32.LOAD_LIBRARY_SEARCH_SYSTEM32))
{
if (libHandle.IsInvalid)
return false;

// We can't just check that 'GetAddrInfoEx' exists, because it existed before supporting overlapped.
// The existance of 'GetAddrInfoExCancel' indicates that overlapped is supported.
return Interop.Kernel32.GetProcAddress(libHandle, Interop.Winsock.GetAddrInfoExCancelFunctionName) != IntPtr.Zero;
}
}

public static unsafe void GetAddrInfoAsync(DnsResolveAsyncResult asyncResult)
{
GetAddrInfoExContext* context = GetAddrInfoExContext.AllocateContext();
Expand Down

1 comment on commit f3a86db

@stephentoub
Copy link
Member

Choose a reason for hiding this comment

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

Thanks.

Please sign in to comment.