Permalink
Browse files

Enable PInvoke analyzer for S.P.CoreLib.dll

  • Loading branch information...
1 parent 97b9927 commit b2c6ab752c7a71b726695f783a5a0381196cc1fe John Chen (CLR) committed Jan 9, 2017
Showing with 229 additions and 289 deletions.
  1. +1 −1 BuildToolsVersion.txt
  2. +8 −1 src/mscorlib/System.Private.CoreLib.csproj
  3. +71 −0 src/mscorlib/corefx/Interop/Windows/Interop.Errors.cs
  4. +3 −3 src/mscorlib/corefx/Interop/Windows/{mincore → kernel32}/Interop.CancelIoEx.cs
  5. +2 −2 src/mscorlib/corefx/Interop/Windows/{mincore → kernel32}/Interop.CloseHandle.cs
  6. +2 −2 src/mscorlib/corefx/Interop/Windows/{mincore → kernel32}/Interop.CreateFile.cs
  7. +1 −1 src/mscorlib/corefx/Interop/Windows/{mincore → kernel32}/Interop.FileOperations.cs
  8. +1 −1 src/mscorlib/corefx/Interop/Windows/{mincore → kernel32}/Interop.FileTypes.cs
  9. +2 −2 src/mscorlib/corefx/Interop/Windows/{mincore → kernel32}/Interop.FlushFileBuffers.cs
  10. +2 −2 src/mscorlib/corefx/Interop/Windows/{mincore → kernel32}/Interop.FormatMessage.cs
  11. +2 −2 src/mscorlib/corefx/Interop/Windows/{mincore → kernel32}/Interop.GetFileInformationByHandleEx.cs
  12. +2 −2 src/mscorlib/corefx/Interop/Windows/{mincore → kernel32}/Interop.GetFileType_SafeHandle.cs
  13. +2 −2 src/mscorlib/corefx/Interop/Windows/{mincore → kernel32}/Interop.GetFullPathNameW.cs
  14. +2 −2 src/mscorlib/corefx/Interop/Windows/{mincore → kernel32}/Interop.GetLongPathNameW.cs
  15. +2 −2 src/mscorlib/corefx/Interop/Windows/{mincore → kernel32}/Interop.GetTempFileNameW.cs
  16. +2 −2 src/mscorlib/corefx/Interop/Windows/{mincore → kernel32}/Interop.GetTempPathW.cs
  17. +3 −3 src/mscorlib/corefx/Interop/Windows/{mincore → kernel32}/Interop.LockFile.cs
  18. +3 −3 src/mscorlib/corefx/Interop/Windows/{mincore → kernel32}/Interop.ReadFile_SafeHandle_IntPtr.cs
  19. +3 −3 ...orlib/corefx/Interop/Windows/{mincore → kernel32}/Interop.ReadFile_SafeHandle_NativeOverlapped.cs
  20. +1 −1 src/mscorlib/corefx/Interop/Windows/{mincore → kernel32}/Interop.SECURITY_ATTRIBUTES.cs
  21. +4 −4 src/mscorlib/corefx/Interop/Windows/{mincore → kernel32}/Interop.SafeCreateFile.cs
  22. +1 −1 src/mscorlib/corefx/Interop/Windows/{mincore → kernel32}/Interop.SecurityOptions.cs
  23. +2 −2 src/mscorlib/corefx/Interop/Windows/{mincore → kernel32}/Interop.SetEndOfFile.cs
  24. +2 −2 src/mscorlib/corefx/Interop/Windows/{mincore → kernel32}/Interop.SetErrorMode.cs
  25. +3 −3 src/mscorlib/corefx/Interop/Windows/{mincore → kernel32}/Interop.SetFileInformationByHandle.cs
  26. +2 −2 src/mscorlib/corefx/Interop/Windows/{mincore → kernel32}/Interop.SetFilePointerEx.cs
  27. +2 −2 src/mscorlib/corefx/Interop/Windows/{mincore → kernel32}/Interop.UnsafeCreateFile.cs
  28. +2 −2 src/mscorlib/corefx/Interop/Windows/{mincore → kernel32}/Interop.WideCharToMultiByte.cs
  29. +3 −3 src/mscorlib/corefx/Interop/Windows/{mincore → kernel32}/Interop.WriteFile_SafeHandle_IntPtr.cs
  30. +3 −3 ...rlib/corefx/Interop/Windows/{mincore → kernel32}/Interop.WriteFile_SafeHandle_NativeOverlapped.cs
  31. +0 −74 src/mscorlib/corefx/Interop/Windows/mincore/Interop.Errors.cs
  32. +0 −37 src/mscorlib/corefx/Interop/Windows/mincore/Interop.Idna.cs
  33. +0 −27 src/mscorlib/corefx/Interop/Windows/mincore/Interop.ThreadPoolIO.cs
  34. +1 −1 src/mscorlib/corefx/Microsoft/Win32/SafeHandles/SafeFileHandle.Windows.cs
  35. +36 −36 src/mscorlib/corefx/System/IO/FileStream.Win32.cs
  36. +3 −3 src/mscorlib/corefx/System/IO/FileStreamCompletionSource.Win32.cs
  37. +2 −2 src/mscorlib/corefx/System/IO/Path.Windows.cs
  38. +5 −5 src/mscorlib/corefx/System/IO/PathHelper.Windows.cs
  39. +10 −10 src/mscorlib/corefx/System/IO/Win32Marshal.cs
  40. +4 −4 src/mscorlib/corefx/System/Security/SecureString.Windows.cs
  41. +28 −28 src/mscorlib/mscorlib.shared.sources.props
  42. +1 −1 src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/NativeMethods.cs
@@ -1 +1 @@
-1.0.27-prerelease-01205-03
+1.0.27-prerelease-01209-01
@@ -205,7 +205,14 @@
</EmbeddedResource>
</ItemGroup>
- <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.Targets" />
+ <PropertyGroup Condition="'$(BuildOS)' == 'Windows_NT'">
+ <EnableDotnetAnalyzers Condition="'$(EnableDotnetAnalyzers)'==''">true</EnableDotnetAnalyzers>
+ <UseWin32Apis>true</UseWin32Apis>
+ <OSGroup>Windows_NT</OSGroup>
+ </PropertyGroup>
+ <Import Project="$(ToolsDir)\codeAnalysis.targets" />
+
+ <Import Project="$(ToolsDir)\Microsoft.CSharp.Targets" />
<PropertyGroup>
<StrongNameSig>Silverlight</StrongNameSig>
@@ -0,0 +1,71 @@
+// 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 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);
+ }
+}
@@ -8,9 +8,9 @@
internal partial class Interop
{
- internal partial class mincore
+ internal partial class Kernel32
{
- [DllImport(Libraries.IO, SetLastError = true)]
- internal static unsafe extern bool CancelIoEx(SafeHandle handle, NativeOverlapped* lpOverlapped);
+ [DllImport(Libraries.Kernel32, SetLastError = true)]
+ internal static extern unsafe bool CancelIoEx(SafeHandle handle, NativeOverlapped* lpOverlapped);
}
}
@@ -7,9 +7,9 @@
internal partial class Interop
{
- internal partial class mincore
+ internal partial class Kernel32
{
- [DllImport(Libraries.Handle, SetLastError = true)]
+ [DllImport(Libraries.Kernel32, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool CloseHandle(IntPtr handle);
}
@@ -9,12 +9,12 @@
internal partial class Interop
{
- internal partial class mincore
+ internal partial class Kernel32
{
/// <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)]
+ [DllImport(Libraries.Kernel32, EntryPoint = "CreateFileW", SetLastError = true, CharSet = CharSet.Unicode, BestFitMapping = false)]
private static extern SafeFileHandle CreateFilePrivate(
string lpFileName,
int dwDesiredAccess,
@@ -4,7 +4,7 @@
internal partial class Interop
{
- internal partial class mincore
+ internal partial class Kernel32
{
internal partial class IOReparseOptions
{
@@ -4,7 +4,7 @@
internal partial class Interop
{
- internal partial class mincore
+ internal partial class Kernel32
{
internal partial class FileTypes
{
@@ -8,9 +8,9 @@
internal partial class Interop
{
- internal partial class mincore
+ internal partial class Kernel32
{
- [DllImport(Libraries.CoreFile_L1, SetLastError = true)]
+ [DllImport(Libraries.Kernel32, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool FlushFileBuffers(SafeHandle hHandle);
}
@@ -8,7 +8,7 @@
internal partial class Interop
{
- internal partial class mincore
+ internal partial class Kernel32
{
private const int FORMAT_MESSAGE_IGNORE_INSERTS = 0x00000200;
private const int FORMAT_MESSAGE_FROM_HMODULE = 0x00000800;
@@ -18,7 +18,7 @@ internal partial class mincore
private const int ERROR_INSUFFICIENT_BUFFER = 0x7A;
- [DllImport(Libraries.Localization, CharSet = CharSet.Unicode, EntryPoint = "FormatMessageW", SetLastError = true, BestFitMapping = true)]
+ [DllImport(Libraries.Kernel32, CharSet = CharSet.Unicode, EntryPoint = "FormatMessageW", SetLastError = true, BestFitMapping = true)]
private static extern int FormatMessage(
int dwFlags,
IntPtr lpSource,
@@ -8,9 +8,9 @@
internal partial class Interop
{
- internal partial class mincore
+ internal partial class Kernel32
{
- [DllImport(Libraries.CoreFile_L2, SetLastError = true)]
+ [DllImport(Libraries.Kernel32, 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
@@ -7,9 +7,9 @@
internal partial class Interop
{
- internal partial class mincore
+ internal partial class Kernel32
{
- [DllImport(Libraries.CoreFile_L1, SetLastError = true)]
+ [DllImport(Libraries.Kernel32, SetLastError = true)]
internal extern static int GetFileType(SafeHandle hFile);
}
}
@@ -7,12 +7,12 @@
internal partial class Interop
{
- internal partial class mincore
+ internal partial class Kernel32
{
/// <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)]
+ [DllImport(Libraries.Kernel32, SetLastError = true, CharSet = CharSet.Unicode, BestFitMapping = false, ExactSpelling = true)]
unsafe internal static extern uint GetFullPathNameW(char* path, uint numBufferChars, char[] buffer, IntPtr mustBeZero);
}
}
@@ -7,12 +7,12 @@
partial class Interop
{
- partial class mincore
+ partial class Kernel32
{
/// <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)]
+ [DllImport(Libraries.Kernel32, SetLastError = true, CharSet = CharSet.Unicode, BestFitMapping = false, ExactSpelling = true)]
internal static extern uint GetLongPathNameW(char[] lpszShortPath, char[] lpszLongPath, uint cchBuffer);
}
}
@@ -8,9 +8,9 @@
partial class Interop
{
- partial class mincore
+ partial class Kernel32
{
- [DllImport(Libraries.CoreFile_L1, CharSet = CharSet.Unicode, SetLastError = true, BestFitMapping = false)]
+ [DllImport(Libraries.Kernel32, CharSet = CharSet.Unicode, SetLastError = true, BestFitMapping = false)]
internal static extern uint GetTempFileNameW(string tmpPath, string prefix, uint uniqueIdOrZero, [Out]StringBuilder tmpFileName);
}
}
@@ -8,9 +8,9 @@
partial class Interop
{
- partial class mincore
+ partial class Kernel32
{
- [DllImport(Libraries.CoreFile_L1_2, CharSet = CharSet.Unicode, BestFitMapping = false)]
+ [DllImport(Libraries.Kernel32, CharSet = CharSet.Unicode, BestFitMapping = false)]
internal static extern uint GetTempPathW(int bufferLen, [Out]StringBuilder buffer);
}
}
@@ -9,12 +9,12 @@
internal partial class Interop
{
- internal partial class mincore
+ internal partial class Kernel32
{
- [DllImport(Libraries.CoreFile_L1, SetLastError = true)]
+ [DllImport(Libraries.Kernel32, SetLastError = true)]
internal static extern bool LockFile(SafeFileHandle handle, int offsetLow, int offsetHigh, int countLow, int countHigh);
- [DllImport(Libraries.CoreFile_L1, SetLastError = true)]
+ [DllImport(Libraries.Kernel32, SetLastError = true)]
internal static extern bool UnlockFile(SafeFileHandle handle, int offsetLow, int offsetHigh, int countLow, int countHigh);
}
}
@@ -8,10 +8,10 @@
internal partial class Interop
{
- internal partial class mincore
+ internal partial class Kernel32
{
- [DllImport(Libraries.CoreFile_L1, SetLastError = true)]
- unsafe internal static extern int ReadFile(
+ [DllImport(Libraries.Kernel32, SetLastError = true)]
+ internal static extern unsafe int ReadFile(
SafeHandle handle,
byte* bytes,
int numBytesToRead,
@@ -9,10 +9,10 @@
internal partial class Interop
{
- internal partial class mincore
+ internal partial class Kernel32
{
- [DllImport(Libraries.CoreFile_L1, SetLastError = true)]
- unsafe internal static extern int ReadFile(
+ [DllImport(Libraries.Kernel32, SetLastError = true)]
+ internal static extern unsafe int ReadFile(
SafeHandle handle,
byte* bytes,
int numBytesToRead,
@@ -8,7 +8,7 @@
internal partial class Interop
{
- internal partial class mincore
+ internal partial class Kernel32
{
[StructLayout(LayoutKind.Sequential)]
internal struct SECURITY_ATTRIBUTES
@@ -9,7 +9,7 @@
internal partial class Interop
{
- internal partial class mincore
+ internal partial class Kernel32
{
internal static readonly IntPtr INVALID_HANDLE_VALUE = new IntPtr(-1); // WinBase.h
@@ -22,7 +22,7 @@ internal partial class mincore
String lpFileName,
int dwDesiredAccess,
System.IO.FileShare dwShareMode,
- ref Interop.mincore.SECURITY_ATTRIBUTES securityAttrs,
+ ref Interop.Kernel32.SECURITY_ATTRIBUTES securityAttrs,
FileMode dwCreationDisposition,
int dwFlagsAndAttributes,
IntPtr hTemplateFile)
@@ -31,8 +31,8 @@ internal partial class mincore
if (!handle.IsInvalid)
{
- int fileType = Interop.mincore.GetFileType(handle);
- if (fileType != Interop.mincore.FileTypes.FILE_TYPE_DISK)
+ int fileType = Interop.Kernel32.GetFileType(handle);
+ if (fileType != Interop.Kernel32.FileTypes.FILE_TYPE_DISK)
{
handle.Dispose();
throw new NotSupportedException(SR.NotSupported_FileStreamOnNonFiles);
@@ -4,7 +4,7 @@
internal partial class Interop
{
- internal partial class mincore
+ internal partial class Kernel32
{
internal partial class SecurityOptions
{
@@ -7,9 +7,9 @@
internal partial class Interop
{
- internal partial class mincore
+ internal partial class Kernel32
{
- [DllImport(Libraries.CoreFile_L1, SetLastError = true)]
+ [DllImport(Libraries.Kernel32, SetLastError = true)]
internal static extern bool SetEndOfFile(SafeFileHandle hFile);
}
}
@@ -6,9 +6,9 @@
internal partial class Interop
{
- internal partial class mincore
+ internal partial class Kernel32
{
- [DllImport(Libraries.ErrorHandling, SetLastError = false, EntryPoint = "SetErrorMode", ExactSpelling = true)]
+ [DllImport(Libraries.Kernel32, SetLastError = false, EntryPoint = "SetErrorMode", ExactSpelling = true)]
internal static extern uint SetErrorMode(uint newMode);
}
}
@@ -8,13 +8,13 @@
internal partial class Interop
{
- internal partial class mincore
+ internal partial class Kernel32
{
- [DllImport(Libraries.CoreFile_L1, SetLastError = true)]
+ [DllImport(Libraries.Kernel32, 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(
+ internal static unsafe bool SetFileTime(
SafeFileHandle hFile,
long creationTime = -1,
long lastAccessTime = -1,
Oops, something went wrong.

0 comments on commit b2c6ab7

Please sign in to comment.