diff options
author | Jiyoung Yun <jy910.yun@samsung.com> | 2016-12-27 16:46:08 +0900 |
---|---|---|
committer | Jiyoung Yun <jy910.yun@samsung.com> | 2016-12-27 16:46:08 +0900 |
commit | db20f3f1bb8595633a7e16c8900fd401a453a6b5 (patch) | |
tree | e5435159cd1bf0519276363a6fe1663d1721bed3 /src/mscorlib/corefx/Interop/Windows/mincore | |
parent | 4b4aad7217d3292650e77eec2cf4c198ea9c3b4b (diff) | |
download | coreclr-db20f3f1bb8595633a7e16c8900fd401a453a6b5.tar.gz coreclr-db20f3f1bb8595633a7e16c8900fd401a453a6b5.tar.bz2 coreclr-db20f3f1bb8595633a7e16c8900fd401a453a6b5.zip |
Imported Upstream version 1.0.0.9127upstream/1.0.0.9127
Diffstat (limited to 'src/mscorlib/corefx/Interop/Windows/mincore')
30 files changed, 855 insertions, 0 deletions
diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.CancelIoEx.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.CancelIoEx.cs new file mode 100644 index 0000000000..868d409321 --- /dev/null +++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.CancelIoEx.cs @@ -0,0 +1,16 @@ +// 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; +using System.Runtime.InteropServices; +using System.Threading; + +internal partial class Interop +{ + internal partial class mincore + { + [DllImport(Libraries.IO, SetLastError = true)] + internal static unsafe extern bool CancelIoEx(SafeHandle handle, NativeOverlapped* lpOverlapped); + } +} diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.CloseHandle.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.CloseHandle.cs new file mode 100644 index 0000000000..029937b6d5 --- /dev/null +++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.CloseHandle.cs @@ -0,0 +1,16 @@ +// 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 System; +using System.Runtime.InteropServices; + +internal partial class Interop +{ + internal partial class mincore + { + [DllImport(Libraries.Handle, SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + internal static extern bool CloseHandle(IntPtr handle); + } +} diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.CreateFile.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.CreateFile.cs new file mode 100644 index 0000000000..670037d52e --- /dev/null +++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.CreateFile.cs @@ -0,0 +1,40 @@ +// 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; +using System; +using System.IO; +using System.Runtime.InteropServices; + +internal partial class Interop +{ + internal partial class mincore + { + /// <summary> + /// WARNING: This method does not implicitly handle long paths. Use CreateFile. + /// </summary> + [DllImport(Libraries.CoreFile_L1, EntryPoint = "CreateFileW", SetLastError = true, CharSet = CharSet.Unicode, BestFitMapping = false)] + private static extern SafeFileHandle CreateFilePrivate( + string lpFileName, + int dwDesiredAccess, + System.IO.FileShare dwShareMode, + [In] ref SECURITY_ATTRIBUTES securityAttrs, + System.IO.FileMode dwCreationDisposition, + int dwFlagsAndAttributes, + IntPtr hTemplateFile); + + internal static SafeFileHandle CreateFile( + string lpFileName, + int dwDesiredAccess, + System.IO.FileShare dwShareMode, + [In] ref SECURITY_ATTRIBUTES securityAttrs, + System.IO.FileMode dwCreationDisposition, + int dwFlagsAndAttributes, + IntPtr hTemplateFile) + { + lpFileName = PathInternal.EnsureExtendedPrefixOverMaxPath(lpFileName); + return CreateFilePrivate(lpFileName, dwDesiredAccess, dwShareMode, ref securityAttrs, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile); + } + } +} diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.Errors.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.Errors.cs new file mode 100644 index 0000000000..05b2250830 --- /dev/null +++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.Errors.cs @@ -0,0 +1,74 @@ +// 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. + +internal partial class Interop +{ + internal partial class mincore + { + internal partial class Errors + { + internal const int ERROR_SUCCESS = 0x0; + internal const int ERROR_INVALID_FUNCTION = 0x1; + internal const int ERROR_FILE_NOT_FOUND = 0x2; + internal const int ERROR_PATH_NOT_FOUND = 0x3; + internal const int ERROR_ACCESS_DENIED = 0x5; + internal const int ERROR_INVALID_HANDLE = 0x6; + internal const int ERROR_NOT_ENOUGH_MEMORY = 0x8; + internal const int ERROR_INVALID_DATA = 0xD; + internal const int ERROR_INVALID_DRIVE = 0xF; + internal const int ERROR_NO_MORE_FILES = 0x12; + internal const int ERROR_NOT_READY = 0x15; + internal const int ERROR_BAD_LENGTH = 0x18; + internal const int ERROR_SHARING_VIOLATION = 0x20; + internal const int ERROR_LOCK_VIOLATION = 0x21; + internal const int ERROR_HANDLE_EOF = 0x26; + internal const int ERROR_FILE_EXISTS = 0x50; + internal const int ERROR_INVALID_PARAMETER = 0x57; + internal const int ERROR_BROKEN_PIPE = 0x6D; + internal const int ERROR_INSUFFICIENT_BUFFER = 0x7A; + internal const int ERROR_INVALID_NAME = 0x7B; + internal const int ERROR_NEGATIVE_SEEK = 0x83; + internal const int ERROR_DIR_NOT_EMPTY = 0x91; + internal const int ERROR_BAD_PATHNAME = 0xA1; + internal const int ERROR_LOCK_FAILED = 0xA7; + internal const int ERROR_BUSY = 0xAA; + internal const int ERROR_ALREADY_EXISTS = 0xB7; + internal const int ERROR_BAD_EXE_FORMAT = 0xC1; + internal const int ERROR_ENVVAR_NOT_FOUND = 0xCB; + internal const int ERROR_FILENAME_EXCED_RANGE = 0xCE; + internal const int ERROR_EXE_MACHINE_TYPE_MISMATCH = 0xD8; + internal const int ERROR_PIPE_BUSY = 0xE7; + internal const int ERROR_NO_DATA = 0xE8; + internal const int ERROR_PIPE_NOT_CONNECTED = 0xE9; + internal const int ERROR_MORE_DATA = 0xEA; + internal const int ERROR_NO_MORE_ITEMS = 0x103; + internal const int ERROR_PARTIAL_COPY = 0x12B; + internal const int ERROR_ARITHMETIC_OVERFLOW = 0x216; + internal const int ERROR_PIPE_CONNECTED = 0x217; + internal const int ERROR_PIPE_LISTENING = 0x218; + internal const int ERROR_OPERATION_ABORTED = 0x3E3; + internal const int ERROR_IO_PENDING = 0x3E5; + internal const int ERROR_NO_TOKEN = 0x3f0; + internal const int ERROR_DLL_INIT_FAILED = 0x45A; + internal const int ERROR_NOT_FOUND = 0x490; + internal const int ERROR_NON_ACCOUNT_SID = 0x4E9; + internal const int ERROR_NOT_ALL_ASSIGNED = 0x514; + internal const int ERROR_UNKNOWN_REVISION = 0x519; + internal const int ERROR_INVALID_OWNER = 0x51B; + internal const int ERROR_INVALID_PRIMARY_GROUP = 0x51C; + internal const int ERROR_NO_SUCH_PRIVILEGE = 0x521; + internal const int ERROR_PRIVILEGE_NOT_HELD = 0x522; + internal const int ERROR_INVALID_ACL = 0x538; + internal const int ERROR_INVALID_SECURITY_DESCR = 0x53A; + internal const int ERROR_INVALID_SID = 0x539; + internal const int ERROR_BAD_IMPERSONATION_LEVEL = 0x542; + internal const int ERROR_CANT_OPEN_ANONYMOUS = 0x543; + internal const int ERROR_NO_SECURITY_ON_OBJECT = 0x546; + internal const int ERROR_TRUSTED_RELATIONSHIP_FAILURE = 0x6FD; + internal const int ERROR_RESOURCE_LANG_NOT_FOUND = 0x717; + internal const int EFail = unchecked((int)0x80004005); + internal const int E_FILENOTFOUND = unchecked((int)0x80070002); + } + } +} diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.FileOperations.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.FileOperations.cs new file mode 100644 index 0000000000..4369760042 --- /dev/null +++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.FileOperations.cs @@ -0,0 +1,35 @@ +// 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. + +internal partial class Interop +{ + internal partial class mincore + { + internal partial class IOReparseOptions + { + internal const uint IO_REPARSE_TAG_FILE_PLACEHOLDER = 0x80000015; + internal const uint IO_REPARSE_TAG_MOUNT_POINT = 0xA0000003; + } + + internal partial class FileOperations + { + internal const int OPEN_EXISTING = 3; + internal const int COPY_FILE_FAIL_IF_EXISTS = 0x00000001; + + internal const int FILE_ACTION_ADDED = 1; + internal const int FILE_ACTION_REMOVED = 2; + internal const int FILE_ACTION_MODIFIED = 3; + internal const int FILE_ACTION_RENAMED_OLD_NAME = 4; + internal const int FILE_ACTION_RENAMED_NEW_NAME = 5; + + internal const int FILE_FLAG_BACKUP_SEMANTICS = 0x02000000; + internal const int FILE_FLAG_FIRST_PIPE_INSTANCE = 0x00080000; + internal const int FILE_FLAG_OVERLAPPED = 0x40000000; + + internal const int FILE_LIST_DIRECTORY = 0x0001; + } + + internal const uint SEM_FAILCRITICALERRORS = 1; + } +} diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.FileTypes.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.FileTypes.cs new file mode 100644 index 0000000000..a24813e8d6 --- /dev/null +++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.FileTypes.cs @@ -0,0 +1,16 @@ +// 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. + +internal partial class Interop +{ + internal partial class mincore + { + internal partial class FileTypes + { + internal const int FILE_TYPE_DISK = 0x0001; + internal const int FILE_TYPE_CHAR = 0x0002; + internal const int FILE_TYPE_PIPE = 0x0003; + } + } +} diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.FlushFileBuffers.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.FlushFileBuffers.cs new file mode 100644 index 0000000000..69f4fe07ce --- /dev/null +++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.FlushFileBuffers.cs @@ -0,0 +1,17 @@ +// 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; +using System; +using System.Runtime.InteropServices; + +internal partial class Interop +{ + internal partial class mincore + { + [DllImport(Libraries.CoreFile_L1, SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + internal static extern bool FlushFileBuffers(SafeHandle hHandle); + } +} diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.FormatMessage.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.FormatMessage.cs new file mode 100644 index 0000000000..02ecbb8a63 --- /dev/null +++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.FormatMessage.cs @@ -0,0 +1,112 @@ +// 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 System; +using System.Text; +using System.Runtime.InteropServices; + +internal partial class Interop +{ + internal partial class mincore + { + private const int FORMAT_MESSAGE_IGNORE_INSERTS = 0x00000200; + private const int FORMAT_MESSAGE_FROM_HMODULE = 0x00000800; + private const int FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000; + private const int FORMAT_MESSAGE_ARGUMENT_ARRAY = 0x00002000; + + + private const int ERROR_INSUFFICIENT_BUFFER = 0x7A; + + [DllImport(Libraries.Localization, CharSet = CharSet.Unicode, EntryPoint = "FormatMessageW", SetLastError = true, BestFitMapping = true)] + private static extern int FormatMessage( + int dwFlags, + IntPtr lpSource, + uint dwMessageId, + int dwLanguageId, + [Out] StringBuilder lpBuffer, + int nSize, + IntPtr[] arguments); + + /// <summary> + /// Returns a string message for the specified Win32 error code. + /// </summary> + internal static string GetMessage(int errorCode) + { + return GetMessage(IntPtr.Zero, errorCode); + } + + internal static string GetMessage(IntPtr moduleHandle, int errorCode) + { + var sb = new StringBuilder(InitialBufferSize); + do + { + string errorMsg; + if (TryGetErrorMessage(moduleHandle, errorCode, sb, out errorMsg)) + { + return errorMsg; + } + else + { + // increase the capacity of the StringBuilder. + sb.Capacity *= BufferSizeIncreaseFactor; + } + } + while (sb.Capacity < MaxAllowedBufferSize); + + // If you come here then a size as large as 65K is also not sufficient and so we give the generic errorMsg. + return string.Format("Unknown error (0x{0:x})", errorCode); + } + + private static bool TryGetErrorMessage(IntPtr moduleHandle, int errorCode, StringBuilder sb, out string errorMsg) + { + errorMsg = ""; + + int flags = FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY; + if (moduleHandle != IntPtr.Zero) + { + flags |= FORMAT_MESSAGE_FROM_HMODULE; + } + + int result = FormatMessage(flags, moduleHandle, (uint)errorCode, 0, sb, sb.Capacity, null); + if (result != 0) + { + int i = sb.Length; + while (i > 0) + { + char ch = sb[i - 1]; + if (ch > 32 && ch != '.') break; + i--; + } + errorMsg = sb.ToString(0, i); + } + else if (Marshal.GetLastWin32Error() == ERROR_INSUFFICIENT_BUFFER) + { + return false; + } + else + { + errorMsg = string.Format("Unknown error (0x{0:x})", errorCode); + } + + return true; + } + + // Windows API FormatMessage lets you format a message string given an errorcode. + // Unlike other APIs this API does not support a way to query it for the total message size. + // + // So the API can only be used in one of these two ways. + // a. You pass a buffer of appropriate size and get the resource. + // b. Windows creates a buffer and passes the address back and the onus of releasing the buffer lies on the caller. + // + // Since the error code is coming from the user, it is not possible to know the size in advance. + // Unfortunately we can't use option b. since the buffer can only be freed using LocalFree and it is a private API on onecore. + // Also, using option b is ugly for the managed code and could cause memory leak in situations where freeing is unsuccessful. + // + // As a result we use the following approach. + // We initially call the API with a buffer size of 256 and then gradually increase the size in case of failure until we reach the maximum allowed limit of 65K. + private const int InitialBufferSize = 256; + private const int BufferSizeIncreaseFactor = 4; + private const int MaxAllowedBufferSize = 65 * 1024; + } +} diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.GetFileInformationByHandleEx.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.GetFileInformationByHandleEx.cs new file mode 100644 index 0000000000..c4739a5ddc --- /dev/null +++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.GetFileInformationByHandleEx.cs @@ -0,0 +1,26 @@ +// 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; +using System; +using System.Runtime.InteropServices; + +internal partial class Interop +{ + internal partial class mincore + { + [DllImport(Libraries.CoreFile_L2, SetLastError = true)] + internal static extern bool GetFileInformationByHandleEx(SafeFileHandle hFile, FILE_INFO_BY_HANDLE_CLASS FileInformationClass, out FILE_STANDARD_INFO lpFileInformation, uint dwBufferSize); + + internal partial struct FILE_STANDARD_INFO + { + internal long AllocationSize; + internal long EndOfFile; + internal uint NumberOfLinks; + internal BOOL DeletePending; + internal BOOL Directory; + } + + } +} diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.GetFileType_SafeHandle.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.GetFileType_SafeHandle.cs new file mode 100644 index 0000000000..3e2567b6bf --- /dev/null +++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.GetFileType_SafeHandle.cs @@ -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. + +using Microsoft.Win32.SafeHandles; +using System.Runtime.InteropServices; + +internal partial class Interop +{ + internal partial class mincore + { + [DllImport(Libraries.CoreFile_L1, SetLastError = true)] + internal extern static int GetFileType(SafeHandle hFile); + } +} diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.GetFullPathNameW.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.GetFullPathNameW.cs new file mode 100644 index 0000000000..a34cc33db3 --- /dev/null +++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.GetFullPathNameW.cs @@ -0,0 +1,18 @@ +// 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 System; +using System.Runtime.InteropServices; + +internal partial class Interop +{ + internal partial class mincore + { + /// <summary> + /// WARNING: This method does not implicitly handle long paths. Use GetFullPathName or PathHelper. + /// </summary> + [DllImport(Libraries.CoreFile_L1, SetLastError = true, CharSet = CharSet.Unicode, BestFitMapping = false, ExactSpelling = true)] + unsafe internal static extern uint GetFullPathNameW(char* path, uint numBufferChars, SafeHandle buffer, IntPtr mustBeZero); + } +} diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.GetLongPathNameW.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.GetLongPathNameW.cs new file mode 100644 index 0000000000..d50db6650b --- /dev/null +++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.GetLongPathNameW.cs @@ -0,0 +1,18 @@ +// 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 System; +using System.Runtime.InteropServices; + +partial class Interop +{ + partial class mincore + { + /// <summary> + /// WARNING: This method does not implicitly handle long paths. Use GetFullPath/PathHelper. + /// </summary> + [DllImport(Libraries.CoreFile_L1, SetLastError = true, CharSet = CharSet.Unicode, BestFitMapping = false, ExactSpelling = true)] + internal static extern uint GetLongPathNameW(SafeHandle lpszShortPath, SafeHandle lpszLongPath, uint cchBuffer); + } +} diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.GetTempFileNameW.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.GetTempFileNameW.cs new file mode 100644 index 0000000000..f06d11be52 --- /dev/null +++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.GetTempFileNameW.cs @@ -0,0 +1,16 @@ +// 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 System; +using System.Text; +using System.Runtime.InteropServices; + +partial class Interop +{ + partial class mincore + { + [DllImport(Libraries.CoreFile_L1, CharSet = CharSet.Unicode, SetLastError = true, BestFitMapping = false)] + internal static extern uint GetTempFileNameW(string tmpPath, string prefix, uint uniqueIdOrZero, [Out]StringBuilder tmpFileName); + } +} diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.GetTempPathW.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.GetTempPathW.cs new file mode 100644 index 0000000000..0ccc27c9ec --- /dev/null +++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.GetTempPathW.cs @@ -0,0 +1,16 @@ +// 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 System.IO; +using System.Text; +using System.Runtime.InteropServices; + +partial class Interop +{ + partial class mincore + { + [DllImport(Libraries.CoreFile_L1_2, CharSet = CharSet.Unicode, BestFitMapping = false)] + internal static extern uint GetTempPathW(int bufferLen, [Out]StringBuilder buffer); + } +} diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.Idna.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.Idna.cs new file mode 100644 index 0000000000..e14f16b048 --- /dev/null +++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.Idna.cs @@ -0,0 +1,37 @@ +// 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 System; +using System.Runtime.InteropServices; + +internal partial class Interop +{ + internal partial class mincore + { + // + // Idn APIs + // + + [DllImport("api-ms-win-core-localization-l1-2-0.dll", CharSet = CharSet.Unicode, SetLastError = true)] + internal static extern int IdnToAscii( + uint dwFlags, + IntPtr lpUnicodeCharStr, + int cchUnicodeChar, + [System.Runtime.InteropServices.OutAttribute()] + IntPtr lpASCIICharStr, + int cchASCIIChar); + + [DllImport("api-ms-win-core-localization-l1-2-0.dll", CharSet = CharSet.Unicode, SetLastError = true)] + internal static extern int IdnToUnicode( + uint dwFlags, + IntPtr lpASCIICharStr, + int cchASCIIChar, + [System.Runtime.InteropServices.OutAttribute()] + IntPtr lpUnicodeCharStr, + int cchUnicodeChar); + + internal const int IDN_ALLOW_UNASSIGNED = 0x1; + internal const int IDN_USE_STD3_ASCII_RULES = 0x2; + } +} diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.LockFile.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.LockFile.cs new file mode 100644 index 0000000000..ee9a98ecce --- /dev/null +++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.LockFile.cs @@ -0,0 +1,20 @@ +// 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; +using System; +using System.IO; +using System.Runtime.InteropServices; + +internal partial class Interop +{ + internal partial class mincore + { + [DllImport(Libraries.CoreFile_L1, SetLastError = true)] + internal static extern bool LockFile(SafeFileHandle handle, int offsetLow, int offsetHigh, int countLow, int countHigh); + + [DllImport(Libraries.CoreFile_L1, SetLastError = true)] + internal static extern bool UnlockFile(SafeFileHandle handle, int offsetLow, int offsetHigh, int countLow, int countHigh); + } +} diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.ReadFile_SafeHandle_IntPtr.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.ReadFile_SafeHandle_IntPtr.cs new file mode 100644 index 0000000000..093a993c10 --- /dev/null +++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.ReadFile_SafeHandle_IntPtr.cs @@ -0,0 +1,21 @@ +// 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; +using System; +using System.Runtime.InteropServices; + +internal partial class Interop +{ + internal partial class mincore + { + [DllImport(Libraries.CoreFile_L1, SetLastError = true)] + unsafe internal static extern int ReadFile( + SafeHandle handle, + byte* bytes, + int numBytesToRead, + out int numBytesRead, + IntPtr mustBeZero); + } +} diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.ReadFile_SafeHandle_NativeOverlapped.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.ReadFile_SafeHandle_NativeOverlapped.cs new file mode 100644 index 0000000000..ac238cb802 --- /dev/null +++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.ReadFile_SafeHandle_NativeOverlapped.cs @@ -0,0 +1,22 @@ +// 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; +using System; +using System.Runtime.InteropServices; +using System.Threading; + +internal partial class Interop +{ + internal partial class mincore + { + [DllImport(Libraries.CoreFile_L1, SetLastError = true)] + unsafe internal static extern int ReadFile( + SafeHandle handle, + byte* bytes, + int numBytesToRead, + IntPtr numBytesRead_mustBeZero, + NativeOverlapped* overlapped); + } +} diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.SECURITY_ATTRIBUTES.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.SECURITY_ATTRIBUTES.cs new file mode 100644 index 0000000000..0f5c224022 --- /dev/null +++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.SECURITY_ATTRIBUTES.cs @@ -0,0 +1,21 @@ +// 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; +using System; +using System.Runtime.InteropServices; + +internal partial class Interop +{ + internal partial class mincore + { + [StructLayout(LayoutKind.Sequential)] + internal struct SECURITY_ATTRIBUTES + { + internal uint nLength; + internal IntPtr lpSecurityDescriptor; + internal BOOL bInheritHandle; + } + } +} diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.SafeCreateFile.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.SafeCreateFile.cs new file mode 100644 index 0000000000..edfc66d2c9 --- /dev/null +++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.SafeCreateFile.cs @@ -0,0 +1,45 @@ +// 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 System; +using System.IO; +using System.Runtime.InteropServices; +using Microsoft.Win32.SafeHandles; + +internal partial class Interop +{ + internal partial class mincore + { + internal static readonly IntPtr INVALID_HANDLE_VALUE = new IntPtr(-1); // WinBase.h + + /// <summary> + /// Does not allow access to non-file devices. This disallows DOS devices like "con:", "com1:", + /// "lpt1:", etc. Use this to avoid security problems, like allowing a web client asking a server + /// for "http://server/com1.aspx" and then causing a worker process to hang. + /// </summary> + internal static SafeFileHandle SafeCreateFile( + String lpFileName, + int dwDesiredAccess, + System.IO.FileShare dwShareMode, + ref Interop.mincore.SECURITY_ATTRIBUTES securityAttrs, + FileMode dwCreationDisposition, + int dwFlagsAndAttributes, + IntPtr hTemplateFile) + { + SafeFileHandle handle = UnsafeCreateFile(lpFileName, dwDesiredAccess, dwShareMode, ref securityAttrs, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile); + + if (!handle.IsInvalid) + { + int fileType = Interop.mincore.GetFileType(handle); + if (fileType != Interop.mincore.FileTypes.FILE_TYPE_DISK) + { + handle.Dispose(); + throw new NotSupportedException(SR.NotSupported_FileStreamOnNonFiles); + } + } + + return handle; + } + } +} diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.SecurityOptions.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.SecurityOptions.cs new file mode 100644 index 0000000000..767d7f528f --- /dev/null +++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.SecurityOptions.cs @@ -0,0 +1,18 @@ +// 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. + +internal partial class Interop +{ + internal partial class mincore + { + internal partial class SecurityOptions + { + internal const int SECURITY_SQOS_PRESENT = 0x00100000; + internal const int SECURITY_ANONYMOUS = 0 << 16; + internal const int SECURITY_IDENTIFICATION = 1 << 16; + internal const int SECURITY_IMPERSONATION = 2 << 16; + internal const int SECURITY_DELEGATION = 3 << 16; + } + } +} diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.SetEndOfFile.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.SetEndOfFile.cs new file mode 100644 index 0000000000..ee0d3b4bc8 --- /dev/null +++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.SetEndOfFile.cs @@ -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. + +using Microsoft.Win32.SafeHandles; +using System.Runtime.InteropServices; + +internal partial class Interop +{ + internal partial class mincore + { + [DllImport(Libraries.CoreFile_L1, SetLastError = true)] + internal static extern bool SetEndOfFile(SafeFileHandle hFile); + } +} diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.SetErrorMode.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.SetErrorMode.cs new file mode 100644 index 0000000000..a845990ded --- /dev/null +++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.SetErrorMode.cs @@ -0,0 +1,14 @@ +// 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 System.Runtime.InteropServices; + +internal partial class Interop +{ + internal partial class mincore + { + [DllImport(Libraries.ErrorHandling, SetLastError = false, EntryPoint = "SetErrorMode", ExactSpelling = true)] + internal static extern uint SetErrorMode(uint newMode); + } +} diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.SetFileInformationByHandle.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.SetFileInformationByHandle.cs new file mode 100644 index 0000000000..0519219132 --- /dev/null +++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.SetFileInformationByHandle.cs @@ -0,0 +1,72 @@ +// 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; +using System; +using System.Runtime.InteropServices; + +internal partial class Interop +{ + internal partial class mincore + { + [DllImport(Libraries.CoreFile_L1, SetLastError = true)] + internal static extern bool SetFileInformationByHandle(SafeFileHandle hFile, FILE_INFO_BY_HANDLE_CLASS FileInformationClass, ref FILE_BASIC_INFO lpFileInformation, uint dwBufferSize); + + // Default values indicate "no change". Use defaults so that we don't force callsites to be aware of the default values + internal unsafe static bool SetFileTime( + SafeFileHandle hFile, + long creationTime = -1, + long lastAccessTime = -1, + long lastWriteTime = -1, + long changeTime = -1, + uint fileAttributes = 0) + { + FILE_BASIC_INFO basicInfo = new FILE_BASIC_INFO() + { + CreationTime = creationTime, + LastAccessTime = lastAccessTime, + LastWriteTime = lastWriteTime, + ChangeTime = changeTime, + FileAttributes = fileAttributes + }; + + return SetFileInformationByHandle(hFile, FILE_INFO_BY_HANDLE_CLASS.FileBasicInfo, ref basicInfo, (uint)Marshal.SizeOf<FILE_BASIC_INFO>()); + } + + internal struct FILE_BASIC_INFO + { + internal long CreationTime; + internal long LastAccessTime; + internal long LastWriteTime; + internal long ChangeTime; + internal uint FileAttributes; + } + + internal enum FILE_INFO_BY_HANDLE_CLASS : uint + { + FileBasicInfo = 0x0u, + FileStandardInfo = 0x1u, + FileNameInfo = 0x2u, + FileRenameInfo = 0x3u, + FileDispositionInfo = 0x4u, + FileAllocationInfo = 0x5u, + FileEndOfFileInfo = 0x6u, + FileStreamInfo = 0x7u, + FileCompressionInfo = 0x8u, + FileAttributeTagInfo = 0x9u, + FileIdBothDirectoryInfo = 0xAu, + FileIdBothDirectoryRestartInfo = 0xBu, + FileIoPriorityHintInfo = 0xCu, + FileRemoteProtocolInfo = 0xDu, + FileFullDirectoryInfo = 0xEu, + FileFullDirectoryRestartInfo = 0xFu, + FileStorageInfo = 0x10u, + FileAlignmentInfo = 0x11u, + FileIdInfo = 0x12u, + FileIdExtdDirectoryInfo = 0x13u, + FileIdExtdDirectoryRestartInfo = 0x14u, + MaximumFileInfoByHandleClass = 0x15u, + } + } +} diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.SetFilePointerEx.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.SetFilePointerEx.cs new file mode 100644 index 0000000000..09f8e1feb3 --- /dev/null +++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.SetFilePointerEx.cs @@ -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. + +using Microsoft.Win32.SafeHandles; +using System.Runtime.InteropServices; + +internal partial class Interop +{ + internal partial class mincore + { + [DllImport(Libraries.CoreFile_L1, SetLastError = true)] + internal static extern bool SetFilePointerEx(SafeFileHandle hFile, long liDistanceToMove, out long lpNewFilePointer, uint dwMoveMethod); + } +} diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.ThreadPoolIO.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.ThreadPoolIO.cs new file mode 100644 index 0000000000..a0afed5d1a --- /dev/null +++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.ThreadPoolIO.cs @@ -0,0 +1,27 @@ +// 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 System; +using System.Runtime.InteropServices; +using Microsoft.Win32.SafeHandles; + +internal static partial class Interop +{ + internal static partial class mincore + { + [DllImport(Libraries.ThreadPool, SetLastError = true)] + internal static unsafe extern SafeThreadPoolIOHandle CreateThreadpoolIo(SafeHandle fl, [MarshalAs(UnmanagedType.FunctionPtr)] NativeIoCompletionCallback pfnio, IntPtr context, IntPtr pcbe); + + [DllImport(Libraries.ThreadPool)] + internal static unsafe extern void CloseThreadpoolIo(IntPtr pio); + + [DllImport(Libraries.ThreadPool)] + internal static unsafe extern void StartThreadpoolIo(SafeThreadPoolIOHandle pio); + + [DllImport(Libraries.ThreadPool)] + internal static unsafe extern void CancelThreadpoolIo(SafeThreadPoolIOHandle pio); + } + + internal delegate void NativeIoCompletionCallback(IntPtr instance, IntPtr context, IntPtr overlapped, uint ioResult, UIntPtr numberOfBytesTransferred, IntPtr io); +} diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.UnsafeCreateFile.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.UnsafeCreateFile.cs new file mode 100644 index 0000000000..e7e4f0513a --- /dev/null +++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.UnsafeCreateFile.cs @@ -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 System; +using System.IO; +using Microsoft.Win32.SafeHandles; + +internal partial class Interop +{ + internal partial class mincore + { + internal static SafeFileHandle UnsafeCreateFile( + string lpFileName, + int dwDesiredAccess, + FileShare dwShareMode, + ref Interop.mincore.SECURITY_ATTRIBUTES securityAttrs, + FileMode dwCreationDisposition, + int dwFlagsAndAttributes, + IntPtr hTemplateFile) + { + return CreateFile(lpFileName, dwDesiredAccess, dwShareMode, ref securityAttrs, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile); + } + } +} diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.WideCharToMultiByte.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.WideCharToMultiByte.cs new file mode 100644 index 0000000000..b1a2975696 --- /dev/null +++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.WideCharToMultiByte.cs @@ -0,0 +1,22 @@ +// 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 System; +using System.Runtime.InteropServices; + +internal partial class Interop +{ + internal partial class mincore + { + [DllImport(Libraries.String_L1)] + internal static extern unsafe int WideCharToMultiByte( + uint CodePage, uint dwFlags, + char* lpWideCharStr, int cchWideChar, + byte* lpMultiByteStr, int cbMultiByte, + IntPtr lpDefaultChar, IntPtr lpUsedDefaultChar); + + internal const uint CP_ACP = 0; + internal const uint WC_NO_BEST_FIT_CHARS = 0x00000400; + } +} diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.WriteFile_SafeHandle_IntPtr.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.WriteFile_SafeHandle_IntPtr.cs new file mode 100644 index 0000000000..052ba3ce7d --- /dev/null +++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.WriteFile_SafeHandle_IntPtr.cs @@ -0,0 +1,24 @@ +// 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; +using System; +using System.Runtime.InteropServices; + +internal partial class Interop +{ + internal partial class mincore + { + // Note there are two different WriteFile prototypes - this is to use + // the type system to force you to not trip across a "feature" in + // Win32's async IO support. You can't do the following three things + // simultaneously: overlapped IO, free the memory for the overlapped + // struct in a callback (or an EndWrite method called by that callback), + // and pass in an address for the numBytesRead parameter. + + [DllImport(Libraries.CoreFile_L1, SetLastError = true)] + internal static unsafe extern int WriteFile(SafeHandle handle, byte* bytes, int numBytesToWrite, out int numBytesWritten, IntPtr mustBeZero); + + } +} diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.WriteFile_SafeHandle_NativeOverlapped.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.WriteFile_SafeHandle_NativeOverlapped.cs new file mode 100644 index 0000000000..e9d2953045 --- /dev/null +++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.WriteFile_SafeHandle_NativeOverlapped.cs @@ -0,0 +1,22 @@ +// 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; +using System; +using System.Runtime.InteropServices; +using System.Threading; +internal partial class Interop +{ + internal partial class mincore + { + // Note there are two different WriteFile prototypes - this is to use + // the type system to force you to not trip across a "feature" in + // Win32's async IO support. You can't do the following three things + // simultaneously: overlapped IO, free the memory for the overlapped + // struct in a callback (or an EndWrite method called by that callback), + // and pass in an address for the numBytesRead parameter. + [DllImport(Libraries.CoreFile_L1, SetLastError = true)] + internal static unsafe extern int WriteFile(SafeHandle handle, byte* bytes, int numBytesToWrite, IntPtr numBytesWritten_mustBeZero, NativeOverlapped* lpOverlapped); + } +} |