Win7PlusCoreSystem

This commit is contained in:
jhawk42 2014-03-26 11:20:07 -07:00
parent 56483cb0ed
commit 4d2b2a14d5
7 changed files with 120 additions and 6 deletions

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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

View File

@ -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

View File

@ -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);
}

View File

@ -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

View File

@ -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