Skip to content

Commit

Permalink
Skip NativeLibrary abstraction for Windows-specific system libraries (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jkotas committed Jan 15, 2021
1 parent 11784b0 commit ce4423a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
<!-- Interop -->
<Compile Include="$(CommonPath)Interop\Windows\Interop.Libraries.cs"
Link="Common\Interop\Windows\Interop.Libraries.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Kernel32\Interop.LoadLibraryEx_IntPtr.cs"
Link="Common\Interop\Windows\Kernel32\Interop.LoadLibraryEx_IntPtr.cs" />
<Compile Include="$(CommonPath)Interop\Windows\WinSock\AddressInfoHints.cs"
Link="Common\Interop\Windows\WinSock\AddressInfoHints.cs" />
<Compile Include="$(CommonPath)Interop\Windows\WinSock\hostent.cs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ static void Initialize()
{
Interop.Winsock.EnsureInitialized();

IntPtr libHandle = NativeLibrary.Load(Interop.Libraries.Ws2_32, typeof(NameResolutionPal).Assembly, null);
IntPtr libHandle = Interop.Kernel32.LoadLibraryEx(Interop.Libraries.Ws2_32, IntPtr.Zero, Interop.Kernel32.LOAD_LIBRARY_SEARCH_SYSTEM32);
Debug.Assert(libHandle != IntPtr.Zero);

// We can't just check that 'GetAddrInfoEx' exists, because it existed before supporting overlapped.
// The existence of 'GetAddrInfoExCancel' indicates that overlapped is supported.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
<!-- Interop -->
<Compile Include="$(CommonPath)Interop\Windows\Interop.Libraries.cs"
Link="Common\Interop\Windows\Interop.Libraries.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Kernel32\Interop.LoadLibraryEx_IntPtr.cs"
Link="Common\Interop\Windows\Kernel32\Interop.LoadLibraryEx_IntPtr.cs" />
<Compile Include="$(CommonPath)Interop\Windows\WinSock\AddressInfoHints.cs"
Link="Common\Interop\Windows\WinSock\AddressInfoHints.cs" />
<Compile Include="$(CommonPath)Interop\Windows\WinSock\hostent.cs"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

Expand Down Expand Up @@ -159,7 +160,9 @@ internal FullSystemTime(long ticks)

private static unsafe delegate* unmanaged[SuppressGCTransition]<long*, void> GetGetSystemTimeAsFileTimeFnPtr()
{
IntPtr kernel32Lib = NativeLibrary.Load("kernel32.dll", typeof(DateTime).Assembly, DllImportSearchPath.System32);
IntPtr kernel32Lib = Interop.Kernel32.LoadLibraryEx(Interop.Libraries.Kernel32, IntPtr.Zero, Interop.Kernel32.LOAD_LIBRARY_SEARCH_SYSTEM32);
Debug.Assert(kernel32Lib != IntPtr.Zero);

IntPtr pfnGetSystemTime = NativeLibrary.GetExport(kernel32Lib, "GetSystemTimeAsFileTime");

if (NativeLibrary.TryGetExport(kernel32Lib, "GetSystemTimePreciseAsFileTime", out IntPtr pfnGetSystemTimePrecise))
Expand Down

0 comments on commit ce4423a

Please sign in to comment.