diff --git a/src/Microsoft.AspNet.Security.Windows/NativeInterop/UnsafeNativeMethods.cs b/src/Microsoft.AspNet.Security.Windows/NativeInterop/UnsafeNativeMethods.cs index 2eebb1d6a9..7084e0e206 100644 --- a/src/Microsoft.AspNet.Security.Windows/NativeInterop/UnsafeNativeMethods.cs +++ b/src/Microsoft.AspNet.Security.Windows/NativeInterop/UnsafeNativeMethods.cs @@ -32,13 +32,26 @@ namespace Microsoft.AspNet.Security.Windows [System.Security.SuppressUnmanagedCodeSecurityAttribute] internal static class UnsafeNclNativeMethods { +#if ASPNETCORE50 + private const string sspicli_LIB = "sspicli.dll"; + private const string api_ms_win_core_processthreads_LIB = "api-ms-win-core-processthreads-l1-1-1.dll"; + private const string api_ms_win_core_handle_LIB = "api-ms-win-core-handle-l1-1-0.dll"; + private const string api_ms_win_core_libraryloader_LIB = "api-ms-win-core-libraryloader-l1-1-1.dll"; + private const string api_ms_win_core_heap_obsolete_LIB = "api-ms-win-core-heap-obsolete-l1-1-0.dll"; +#else private const string KERNEL32 = "kernel32.dll"; +#endif private const string SECUR32 = "secur32.dll"; private const string CRYPT32 = "crypt32.dll"; +#if ASPNETCORE50 + [DllImport(api_ms_win_core_processthreads_LIB, ExactSpelling = true, CallingConvention = CallingConvention.StdCall, SetLastError = true)] +#else [DllImport(KERNEL32, ExactSpelling = true, CallingConvention = CallingConvention.StdCall, SetLastError = true)] +#endif internal static extern uint GetCurrentThreadId(); + [System.Security.SuppressUnmanagedCodeSecurityAttribute] internal static class SafeNetHandles { @@ -164,18 +177,34 @@ namespace Microsoft.AspNet.Security.Windows [DllImport(SECUR32, ExactSpelling = true, SetLastError = true)] internal static extern int QuerySecurityContextToken(ref SSPIHandle phContext, [Out] out SafeCloseHandle handle); +#if ASPNETCORE50 + [DllImport(api_ms_win_core_handle_LIB, ExactSpelling = true, SetLastError = true)] +#else [DllImport(KERNEL32, ExactSpelling = true, SetLastError = true)] +#endif [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] internal static extern bool CloseHandle(IntPtr handle); +#if ASPNETCORE50 + [DllImport(api_ms_win_core_heap_obsolete_LIB, ExactSpelling = true, SetLastError = true)] +#else [DllImport(KERNEL32, ExactSpelling = true, SetLastError = true)] +#endif internal static extern SafeLocalFree LocalAlloc(int uFlags, UIntPtr sizetdwBytes); +#if ASPNETCORE50 + [DllImport(api_ms_win_core_heap_obsolete_LIB, ExactSpelling = true, SetLastError = true)] +#else [DllImport(KERNEL32, ExactSpelling = true, SetLastError = true)] +#endif [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] internal static extern IntPtr LocalFree(IntPtr handle); +#if ASPNETCORE50 + [DllImport(api_ms_win_core_libraryloader_LIB, ExactSpelling = true, SetLastError = true)] +#else [DllImport(KERNEL32, ExactSpelling = true, SetLastError = true)] +#endif [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] internal static extern unsafe bool FreeLibrary([In] IntPtr hModule); @@ -194,7 +223,11 @@ namespace Microsoft.AspNet.Security.Windows internal static extern bool CertFreeCertificateContext( // Suppressing returned status check, it's always==TRUE, [In] IntPtr certContext); +#if ASPNETCORE50 + [DllImport(api_ms_win_core_heap_obsolete_LIB, ExactSpelling = true, SetLastError = true)] +#else [DllImport(KERNEL32, ExactSpelling = true, SetLastError = true)] +#endif [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] internal static extern IntPtr GlobalFree(IntPtr handle); } diff --git a/src/Microsoft.Net.Http.Server/NativeInterop/UnsafeNativeMethods.cs b/src/Microsoft.Net.Http.Server/NativeInterop/UnsafeNativeMethods.cs index 641b25e963..cac47b387d 100644 --- a/src/Microsoft.Net.Http.Server/NativeInterop/UnsafeNativeMethods.cs +++ b/src/Microsoft.Net.Http.Server/NativeInterop/UnsafeNativeMethods.cs @@ -30,10 +30,20 @@ namespace Microsoft.Net.Http.Server { internal static class UnsafeNclNativeMethods { - private const string KERNEL32 = "kernel32.dll"; - private const string SECUR32 = "secur32.dll"; private const string HTTPAPI = "httpapi.dll"; +#if ASPNETCORE50 + private const string sspicli_LIB = "sspicli.dll"; + private const string api_ms_win_core_processthreads_LIB = "api-ms-win-core-processthreads-l1-1-1.dll"; + private const string api_ms_win_core_io_LIB = "api-ms-win-core-io-l1-1-1.dll"; + private const string api_ms_win_core_handle_LIB = "api-ms-win-core-handle-l1-1-0.dll"; + private const string api_ms_win_core_libraryloader_LIB = "api-ms-win-core-libraryloader-l1-1-1.dll"; + private const string api_ms_win_core_heap_obsolete_LIB = "api-ms-win-core-heap-obsolete-L1-1-0.dll"; + private const string api_ms_win_core_kernel32_legacy_LIB = "api-ms-win-core-kernel32-legacy-l1-1-0.dll"; +#else + private const string KERNEL32 = "kernel32.dll"; + private const string SECUR32 = "secur32.dll"; +#endif // CONSIDER: Make this an enum, requires changing a lot of types from uint to ErrorCodes. internal static class ErrorCodes { @@ -49,13 +59,25 @@ namespace Microsoft.Net.Http.Server internal const uint ERROR_CONNECTION_INVALID = 1229; } +#if ASPNETCORE50 + [DllImport(api_ms_win_core_processthreads_LIB, ExactSpelling = true, CallingConvention = CallingConvention.StdCall, SetLastError = true)] +#else [DllImport(KERNEL32, ExactSpelling = true, CallingConvention = CallingConvention.StdCall, SetLastError = true)] +#endif internal static extern uint GetCurrentThreadId(); +#if ASPNETCORE50 + [DllImport(api_ms_win_core_io_LIB, ExactSpelling = true, CallingConvention = CallingConvention.StdCall, SetLastError = true)] +#else [DllImport(KERNEL32, ExactSpelling = true, CallingConvention = CallingConvention.StdCall, SetLastError = true)] +#endif internal static unsafe extern uint CancelIoEx(SafeHandle handle, SafeNativeOverlapped overlapped); +#if ASPNETCORE50 + [DllImport(api_ms_win_core_kernel32_legacy_LIB, ExactSpelling = true, CallingConvention = CallingConvention.StdCall, SetLastError = true)] +#else [DllImport(KERNEL32, ExactSpelling = true, CallingConvention = CallingConvention.StdCall, SetLastError = true)] +#endif internal static unsafe extern bool SetFileCompletionNotificationModes(SafeHandle handle, FileCompletionNotificationModes modes); [Flags] @@ -68,11 +90,19 @@ namespace Microsoft.Net.Http.Server internal static class SafeNetHandles { +#if ASPNETCORE50 + [DllImport(sspicli_LIB, ExactSpelling = true, SetLastError = true)] +#else [DllImport(SECUR32, ExactSpelling = true, SetLastError = true)] +#endif internal static extern int FreeContextBuffer( [In] IntPtr contextBuffer); +#if ASPNETCORE50 + [DllImport(sspicli_LIB, ExactSpelling = true, SetLastError = true)] +#else [DllImport(SECUR32, ExactSpelling = true, SetLastError = true)] +#endif internal static unsafe extern int QueryContextAttributesW( ref SSPIHandle contextHandle, [In] ContextAttribute attribute, @@ -85,22 +115,47 @@ namespace Microsoft.Net.Http.Server [DllImport(HTTPAPI, ExactSpelling = true, CallingConvention = CallingConvention.StdCall, SetLastError = true)] internal static extern unsafe uint HttpCloseRequestQueue(IntPtr pReqQueueHandle); +#if ASPNETCORE50 + [DllImport(api_ms_win_core_handle_LIB, ExactSpelling = true, SetLastError = true)] +#else [DllImport(KERNEL32, ExactSpelling = true, SetLastError = true)] +#endif internal static extern bool CloseHandle(IntPtr handle); +#if ASPNETCORE50 + [DllImport(api_ms_win_core_heap_obsolete_LIB, ExactSpelling = true, SetLastError = true)] +#else [DllImport(KERNEL32, ExactSpelling = true, SetLastError = true)] +#endif internal static extern SafeLocalFree LocalAlloc(int uFlags, UIntPtr sizetdwBytes); +#if ASPNETCORE50 + [DllImport(api_ms_win_core_heap_obsolete_LIB, EntryPoint = "LocalAlloc", SetLastError = true)] +#else [DllImport(KERNEL32, EntryPoint = "LocalAlloc", SetLastError = true)] +#endif + internal static extern SafeLocalFreeChannelBinding LocalAllocChannelBinding(int uFlags, UIntPtr sizetdwBytes); +#if ASPNETCORE50 + [DllImport(api_ms_win_core_heap_obsolete_LIB, ExactSpelling = true, SetLastError = true)] +#else [DllImport(KERNEL32, ExactSpelling = true, SetLastError = true)] +#endif internal static extern IntPtr LocalFree(IntPtr handle); +#if ASPNETCORE50 + [DllImport(api_ms_win_core_libraryloader_LIB, ExactSpelling = true, CharSet = CharSet.Unicode, SetLastError = true)] +#else [DllImport(KERNEL32, ExactSpelling = true, CharSet = CharSet.Unicode, SetLastError = true)] +#endif internal static extern unsafe SafeLoadLibrary LoadLibraryExW([In] string lpwLibFileName, [In] void* hFile, [In] uint dwFlags); +#if ASPNETCORE50 + [DllImport(api_ms_win_core_libraryloader_LIB, ExactSpelling = true, SetLastError = true)] +#else [DllImport(KERNEL32, ExactSpelling = true, SetLastError = true)] +#endif internal static extern unsafe bool FreeLibrary([In] IntPtr hModule); } diff --git a/src/Microsoft.Net.Http.Server/fx/System/ExternDll.cs b/src/Microsoft.Net.Http.Server/fx/System/ExternDll.cs index 693cecaf1d..50235a6447 100644 --- a/src/Microsoft.Net.Http.Server/fx/System/ExternDll.cs +++ b/src/Microsoft.Net.Http.Server/fx/System/ExternDll.cs @@ -27,7 +27,11 @@ namespace System { internal static class ExternDll { +#if ASPNETCORE50 + public const string api_ms_win_core_localization_LIB = "api-ms-win-core-localization-l2-1-0.dll"; +#else public const string Kernel32 = "kernel32.dll"; +#endif } } -#endif +#endif \ No newline at end of file diff --git a/src/Microsoft.Net.Http.Server/fx/System/SafeNativeMethods.cs b/src/Microsoft.Net.Http.Server/fx/System/SafeNativeMethods.cs index 098a797cdd..da9548c88b 100644 --- a/src/Microsoft.Net.Http.Server/fx/System/SafeNativeMethods.cs +++ b/src/Microsoft.Net.Http.Server/fx/System/SafeNativeMethods.cs @@ -36,10 +36,13 @@ namespace System FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000, FORMAT_MESSAGE_ARGUMENT_ARRAY = 0x00002000; +#if ASPNETCORE50 + [DllImport(ExternDll.api_ms_win_core_localization_LIB, CharSet = System.Runtime.InteropServices.CharSet.Unicode, SetLastError = true, BestFitMapping = true)] +#else [DllImport(ExternDll.Kernel32, CharSet = System.Runtime.InteropServices.CharSet.Unicode, SetLastError = true, BestFitMapping = true)] +#endif public static unsafe extern int FormatMessage(int dwFlags, IntPtr lpSource_mustBeNull, uint dwMessageId, int dwLanguageId, StringBuilder lpBuffer, int nSize, IntPtr[] arguments); - } } #endif diff --git a/src/Microsoft.Net.WebSockets/NativeInterop/UnsafeNativeMethods.cs b/src/Microsoft.Net.WebSockets/NativeInterop/UnsafeNativeMethods.cs index de2d07588f..f522002f8b 100644 --- a/src/Microsoft.Net.WebSockets/NativeInterop/UnsafeNativeMethods.cs +++ b/src/Microsoft.Net.WebSockets/NativeInterop/UnsafeNativeMethods.cs @@ -31,15 +31,27 @@ namespace Microsoft.Net.WebSockets { internal static class UnsafeNativeMethods { +#if ASPNETCORE50 + private const string api_ms_win_core_libraryloader_LIB = "api-ms-win-core-libraryloader-l1-1-1.dll"; +#else private const string KERNEL32 = "kernel32.dll"; +#endif private const string WEBSOCKET = "websocket.dll"; internal static class SafeNetHandles { +#if ASPNETCORE50 + [DllImport(api_ms_win_core_libraryloader_LIB, ExactSpelling = true, CharSet = CharSet.Unicode, SetLastError = true)] +#else [DllImport(KERNEL32, ExactSpelling = true, CharSet=CharSet.Unicode, SetLastError = true)] +#endif internal static extern unsafe SafeLoadLibrary LoadLibraryExW([In] string lpwLibFileName, [In] void* hFile, [In] uint dwFlags); +#if ASPNETCORE50 + [DllImport(api_ms_win_core_libraryloader_LIB, ExactSpelling = true, SetLastError = true)] +#else [DllImport(KERNEL32, ExactSpelling = true, SetLastError = true)] +#endif internal static extern unsafe bool FreeLibrary([In] IntPtr hModule); } diff --git a/src/Microsoft.Net.WebSockets/fx/System/ExternDll.cs b/src/Microsoft.Net.WebSockets/fx/System/ExternDll.cs index 693cecaf1d..c1e1f5b20f 100644 --- a/src/Microsoft.Net.WebSockets/fx/System/ExternDll.cs +++ b/src/Microsoft.Net.WebSockets/fx/System/ExternDll.cs @@ -27,7 +27,11 @@ namespace System { internal static class ExternDll { +#if NETFX || ASPNET50 public const string Kernel32 = "kernel32.dll"; +#else + public const string api_ms_win_core_localization_LIB = "api-ms-win-core-localization-l2-1-0.dll"; +#endif } } -#endif +#endif \ No newline at end of file diff --git a/src/Microsoft.Net.WebSockets/fx/System/SafeNativeMethods.cs b/src/Microsoft.Net.WebSockets/fx/System/SafeNativeMethods.cs index 098a797cdd..7ee12dbbdc 100644 --- a/src/Microsoft.Net.WebSockets/fx/System/SafeNativeMethods.cs +++ b/src/Microsoft.Net.WebSockets/fx/System/SafeNativeMethods.cs @@ -36,10 +36,13 @@ namespace System FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000, FORMAT_MESSAGE_ARGUMENT_ARRAY = 0x00002000; +#if ASPNETCORE50 + [DllImport(ExternDll.api_ms_win_core_localization_LIB, CharSet = System.Runtime.InteropServices.CharSet.Unicode, SetLastError = true, BestFitMapping = true)] +#else [DllImport(ExternDll.Kernel32, CharSet = System.Runtime.InteropServices.CharSet.Unicode, SetLastError = true, BestFitMapping = true)] +#endif public static unsafe extern int FormatMessage(int dwFlags, IntPtr lpSource_mustBeNull, uint dwMessageId, int dwLanguageId, StringBuilder lpBuffer, int nSize, IntPtr[] arguments); - } } #endif