diff options
author | Jan Kotas <jkotas@microsoft.com> | 2015-12-22 10:40:14 +0300 |
---|---|---|
committer | Jan Kotas <jkotas@microsoft.com> | 2015-12-22 10:40:14 +0300 |
commit | ca7ce91a101d1e5f796394046b8326af6dc9012e (patch) | |
tree | fd5e43bdbd797d379b76b47249cc034d1fe1b7db /src/System.Private.CoreLib | |
parent | 119b9959ae527e708fdd39889125ba00797e3c12 (diff) |
Refactoring Windows error codes to match corefx conventions
Diffstat (limited to 'src/System.Private.CoreLib')
10 files changed, 54 insertions, 79 deletions
diff --git a/src/System.Private.CoreLib/src/Interop/Interop.manual.cs b/src/System.Private.CoreLib/src/Interop/Interop.manual.cs index 0f26ef0a8..b08beefa6 100644 --- a/src/System.Private.CoreLib/src/Interop/Interop.manual.cs +++ b/src/System.Private.CoreLib/src/Interop/Interop.manual.cs @@ -11,30 +11,17 @@ internal partial class Interop { WaitObject0 = 0x0u, SOk = 0x0u, - ErrorSuccess = 0x0u, FailFastGenerateExceptionAddress = 0x1u, ExceptionNonContinuable = 0x1u, CreateMutexInitialOwner = 0x1u, CreateEventManualReset = 0x1u, MutexModifyState = 0x1u, CreateEventInitialSet = 0x2u, - ErrorFileNotFound = 0x2u, DuplicateSameAccess = 0x2u, SemaphoreModifyState = 0x2u, EventModifyState = 0x2u, FileTypeChar = 0x2u, - ErrorPathNotFound = 0x3u, - ErrorAccessDenied = 0x5u, - ErrorInvalidHandle = 0x6u, - ErrorNotEnoughMemory = 0x8u, - ErrorInvalidDrive = 0xFu, - ErrorSharingViolation = 0x20u, - ErrorInvalidParameter = 0x57u, - ErrorInvalidName = 0x7Bu, WaitAbandoned0 = 0x80u, - ErrorBadPathname = 0xA1u, - ErrorAlreadyExists = 0xB7u, - ErrorFilenameExcedRange = 0xCEu, WaitTimeout = 0x102u, MaxPath = 0x104u, Synchronize = 0x100000u, @@ -42,9 +29,6 @@ internal partial class Interop EventAllAccess = 0x1F0003u, EFail = 0x80004005u, CoENotInitialized = 0x800401F0u, - StdErrorHandle = 0xFFFFFFF4u, - StdOutputHandle = 0xFFFFFFF5u, - StdInputHandle = 0xFFFFFFF6u, WaitFailed = 0xFFFFFFFFu, } @@ -981,11 +965,6 @@ internal partial class Interop else s_sleepHandle.WaitOne((int)milliseconds); } - - // constants for EnumDynamicTimeZone return values - internal const uint ERROR_NO_MORE_ITEMS = 259; - internal const uint ERROR_INVALID_PARAMETERS = 87; - internal const uint ERROR_SUCCESS = 0; } internal partial class mincore_obsolete diff --git a/src/System.Private.CoreLib/src/System.Private.CoreLib.csproj b/src/System.Private.CoreLib/src/System.Private.CoreLib.csproj index fee18b27f..afabb1ec7 100644 --- a/src/System.Private.CoreLib/src/System.Private.CoreLib.csproj +++ b/src/System.Private.CoreLib/src/System.Private.CoreLib.csproj @@ -486,6 +486,8 @@ <Compile Include="System\Runtime\CommandLine.Win32.cs" /> + <Compile Include="..\..\Common\src\Interop\Windows\mincore\Interop.Errors.cs" /> + <Compile Condition="'$(IsProjectNLibrary)' == 'true'" Include="System\Environment.EnvironmentVariables.UWP.cs" /> <Compile Condition="'$(IsProjectNLibrary)' != 'true'" Include="System\Environment.EnvironmentVariables.Win32.cs" /> <Compile Include="..\..\Common\src\Interop\Windows\mincore\Interop.Environment.cs" /> diff --git a/src/System.Private.CoreLib/src/System/Decimal.DecCalc.cs b/src/System.Private.CoreLib/src/System/Decimal.DecCalc.cs index bd79d7bfe..030200548 100644 --- a/src/System.Private.CoreLib/src/System/Decimal.DecCalc.cs +++ b/src/System.Private.CoreLib/src/System/Decimal.DecCalc.cs @@ -2248,7 +2248,7 @@ namespace System //********************************************************************** // VarDecRound - Decimal Round //********************************************************************** - internal static uint VarDecRound(ref Decimal input, int decimals, ref Decimal result) + internal static void VarDecRound(ref Decimal input, int decimals, ref Decimal result) { uint[] tmpNum = new uint[3]; uint remainder; @@ -2256,8 +2256,7 @@ namespace System uint power; int scale; - if (decimals < 0) - return (uint)Interop.Constants.ErrorInvalidParameter; + System.Diagnostics.Debug.Assert(decimals >= 0); scale = input.Scale - decimals; if (scale > 0) @@ -2294,11 +2293,9 @@ namespace System result._mid = tmpNum[1]; result._hi = tmpNum[2]; result.Scale = decimals; - return 0; } result = input; - return 0; } //********************************************************************** diff --git a/src/System.Private.CoreLib/src/System/Decimal.cs b/src/System.Private.CoreLib/src/System/Decimal.cs index 988b9b2d3..b1c76b574 100644 --- a/src/System.Private.CoreLib/src/System/Decimal.cs +++ b/src/System.Private.CoreLib/src/System/Decimal.cs @@ -569,8 +569,7 @@ namespace System if (decimals < 0 || decimals > 28) throw new ArgumentOutOfRangeException("decimals", SR.ArgumentOutOfRange_DecimalRound); - if (DecCalc.VarDecRound(ref d, decimals, ref result) < 0) - throw new OverflowException(SR.Overflow_Decimal); + DecCalc.VarDecRound(ref d, decimals, ref result); d = result; return d; @@ -588,9 +587,7 @@ namespace System if (mode == MidpointRounding.ToEven) { Decimal result = new Decimal(); - if (DecCalc.VarDecRound(ref d, decimals, ref result) < 0) - throw new OverflowException(SR.Overflow_Decimal); - + DecCalc.VarDecRound(ref d, decimals, ref result); d = result; } else diff --git a/src/System.Private.CoreLib/src/System/Threading/EventWaitHandle.cs b/src/System.Private.CoreLib/src/System/Threading/EventWaitHandle.cs index 47123ef1b..c816da94e 100644 --- a/src/System.Private.CoreLib/src/System/Threading/EventWaitHandle.cs +++ b/src/System.Private.CoreLib/src/System/Threading/EventWaitHandle.cs @@ -55,13 +55,13 @@ namespace System.Threading }; unsafeHandle = Interop.mincore.CreateEventEx(IntPtr.Zero, name, eventFlags, (uint)Interop.Constants.EventAllAccess); - uint errorCode = Interop.mincore.GetLastError(); + int errorCode = (int)Interop.mincore.GetLastError(); SafeWaitHandle _handle = new SafeWaitHandle(unsafeHandle, true); if (_handle.IsInvalid) { _handle.SetHandleAsInvalid(); - if (null != name && 0 != name.Length && (uint)Interop.Constants.ErrorInvalidHandle == errorCode) + if (null != name && 0 != name.Length && Interop.mincore.Errors.ERROR_INVALID_HANDLE == errorCode) throw new WaitHandleCannotBeOpenedException(SR.Format(SR.Threading_WaitHandleCannotBeOpenedException_InvalidHandle, name)); throw ExceptionFromCreationError(errorCode, name); @@ -93,18 +93,18 @@ namespace System.Threading }; IntPtr unsafeHandle = Interop.mincore.CreateEventEx(IntPtr.Zero, name, eventFlags, (uint)Interop.Constants.EventAllAccess); - uint errorCode = Interop.mincore.GetLastError(); + int errorCode = (int)Interop.mincore.GetLastError(); _handle = new SafeWaitHandle(unsafeHandle, true); if (_handle.IsInvalid) { _handle.SetHandleAsInvalid(); - if (null != name && 0 != name.Length && (uint)Interop.Constants.ErrorInvalidHandle == errorCode) + if (null != name && 0 != name.Length && Interop.mincore.Errors.ERROR_INVALID_HANDLE == errorCode) throw new WaitHandleCannotBeOpenedException(SR.Format(SR.Threading_WaitHandleCannotBeOpenedException_InvalidHandle, name)); throw ExceptionFromCreationError(errorCode, name); } - createdNew = errorCode != (uint)Interop.Constants.ErrorAlreadyExists; + createdNew = errorCode != Interop.mincore.Errors.ERROR_ALREADY_EXISTS; SafeWaitHandle = _handle; } @@ -164,16 +164,16 @@ namespace System.Threading IntPtr unsafeHandle = Interop.mincore.OpenEvent((uint)(Interop.Constants.EventModifyState | Interop.Constants.Synchronize), false, name); - uint errorCode = Interop.mincore.GetLastError(); + int errorCode = (int)Interop.mincore.GetLastError(); SafeWaitHandle myHandle = new SafeWaitHandle(unsafeHandle, true); if (myHandle.IsInvalid) { - if ((uint)Interop.Constants.ErrorFileNotFound == errorCode || (uint)Interop.Constants.ErrorInvalidName == errorCode) + if (Interop.mincore.Errors.ERROR_FILE_NOT_FOUND == errorCode || Interop.mincore.Errors.ERROR_INVALID_NAME == errorCode) return OpenExistingResult.NameNotFound; - if ((uint)Interop.Constants.ErrorPathNotFound == errorCode) + if (Interop.mincore.Errors.ERROR_PATH_NOT_FOUND == errorCode) return OpenExistingResult.PathNotFound; - if (null != name && 0 != name.Length && (uint)Interop.Constants.ErrorInvalidHandle == errorCode) + if (null != name && 0 != name.Length && Interop.mincore.Errors.ERROR_INVALID_HANDLE == errorCode) return OpenExistingResult.NameInvalid; //this is for passed through Win32Native Errors throw ExceptionFromCreationError(errorCode, name); diff --git a/src/System.Private.CoreLib/src/System/Threading/LowLevelThread.cs b/src/System.Private.CoreLib/src/System/Threading/LowLevelThread.cs index f789faabc..ebcf1214d 100644 --- a/src/System.Private.CoreLib/src/System/Threading/LowLevelThread.cs +++ b/src/System.Private.CoreLib/src/System/Threading/LowLevelThread.cs @@ -68,21 +68,21 @@ namespace System.Threading if (result == WAIT_FAILED) { - uint error = Interop.mincore.GetLastError(); + int error = (int)Interop.mincore.GetLastError(); switch (error) { - case (uint)Interop.Constants.ErrorInvalidParameter: + case Interop.mincore.Errors.ERROR_INVALID_PARAMETER: throw new ArgumentException(); - case (uint)Interop.Constants.ErrorAccessDenied: + case Interop.mincore.Errors.ERROR_ACCESS_DENIED: throw new UnauthorizedAccessException(); - case (uint)Interop.Constants.ErrorNotEnoughMemory: + case Interop.mincore.Errors.ERROR_NOT_ENOUGH_MEMORY: throw new OutOfMemoryException(); default: Exception ex = new Exception(); - ex.SetErrorCode((int)error); + ex.SetErrorCode(error); throw ex; } } diff --git a/src/System.Private.CoreLib/src/System/Threading/Mutex.cs b/src/System.Private.CoreLib/src/System/Threading/Mutex.cs index 6988e902f..21b754aef 100644 --- a/src/System.Private.CoreLib/src/System/Threading/Mutex.cs +++ b/src/System.Private.CoreLib/src/System/Threading/Mutex.cs @@ -38,16 +38,16 @@ namespace System.Threading Contract.EndContractBlock(); SafeWaitHandle mutexHandle; - uint errorCode = CreateMutexHandle(initiallyOwned, name, out mutexHandle); + int errorCode = CreateMutexHandle(initiallyOwned, name, out mutexHandle); if (mutexHandle.IsInvalid) { mutexHandle.SetHandleAsInvalid(); - if (null != name && 0 != name.Length && (uint)Interop.Constants.ErrorInvalidHandle == errorCode) + if (null != name && 0 != name.Length && Interop.mincore.Errors.ERROR_INVALID_HANDLE == errorCode) throw new WaitHandleCannotBeOpenedException(SR.Format(SR.Threading_WaitHandleCannotBeOpenedException_InvalidHandle, name)); throw ExceptionFromCreationError(errorCode, name); } - createdNew = errorCode != (int)Interop.Constants.ErrorAlreadyExists; + createdNew = errorCode != Interop.mincore.Errors.ERROR_ALREADY_EXISTS; SafeWaitHandle = mutexHandle; } @@ -129,16 +129,16 @@ namespace System.Threading // If that happens, ask for less permissions. SafeWaitHandle myHandle = new SafeWaitHandle(Interop.mincore.OpenMutex((uint)(Interop.Constants.MutexModifyState | Interop.Constants.Synchronize), false, name), true); - uint errorCode = 0; + int errorCode = 0; if (myHandle.IsInvalid) { - errorCode = Interop.mincore.GetLastError(); + errorCode = (int)Interop.mincore.GetLastError(); - if ((uint)Interop.Constants.ErrorFileNotFound == errorCode || (uint)Interop.Constants.ErrorInvalidName == errorCode) + if (Interop.mincore.Errors.ERROR_FILE_NOT_FOUND == errorCode || Interop.mincore.Errors.ERROR_INVALID_NAME == errorCode) return OpenExistingResult.NameNotFound; - if ((uint)Interop.Constants.ErrorPathNotFound == errorCode) + if (Interop.mincore.Errors.ERROR_PATH_NOT_FOUND == errorCode) return OpenExistingResult.PathNotFound; - if (null != name && 0 != name.Length && (uint)Interop.Constants.ErrorInvalidHandle == errorCode) + if (null != name && 0 != name.Length && Interop.mincore.Errors.ERROR_INVALID_HANDLE == errorCode) return OpenExistingResult.NameInvalid; // this is for passed through Win32Native Errors @@ -168,20 +168,20 @@ namespace System.Threading } [System.Security.SecurityCritical] // auto-generated - private static uint CreateMutexHandle(bool initiallyOwned, String name, out SafeWaitHandle mutexHandle) + private static int CreateMutexHandle(bool initiallyOwned, String name, out SafeWaitHandle mutexHandle) { - uint errorCode; + int errorCode; while (true) { mutexHandle = new SafeWaitHandle(Interop.mincore.CreateMutexEx(IntPtr.Zero, name, initiallyOwned ? (uint)Interop.Constants.CreateMutexInitialOwner : 0, (uint)Interop.Constants.MutexAllAccess), true); - errorCode = Interop.mincore.GetLastError(); + errorCode = (int)Interop.mincore.GetLastError(); if (!mutexHandle.IsInvalid) { break; } - if (errorCode == (uint)Interop.Constants.ErrorAccessDenied) + if (errorCode == Interop.mincore.Errors.ERROR_ACCESS_DENIED) { // If a mutex with the name already exists, OS will try to open it with FullAccess. // It might fail if we don't have enough access. In that case, we try to open the mutex will modify and synchronize access. @@ -189,20 +189,20 @@ namespace System.Threading mutexHandle = new SafeWaitHandle(Interop.mincore.OpenMutex((uint)(Interop.Constants.MutexModifyState | Interop.Constants.Synchronize), false, name), true); if (!mutexHandle.IsInvalid) { - errorCode = (uint)Interop.Constants.ErrorAlreadyExists; + errorCode = Interop.mincore.Errors.ERROR_ALREADY_EXISTS; } else { - errorCode = Interop.mincore.GetLastError(); + errorCode = (int)Interop.mincore.GetLastError(); } // There could be a race here, the other owner of the mutex can free the mutex, // We need to retry creation in that case. - if (errorCode != (uint)Interop.Constants.ErrorFileNotFound) + if (errorCode != Interop.mincore.Errors.ERROR_FILE_NOT_FOUND) { - if (errorCode == (uint)Interop.Constants.ErrorSuccess) + if (errorCode == Interop.mincore.Errors.ERROR_SUCCESS) { - errorCode = (uint)Interop.Constants.ErrorAlreadyExists; + errorCode = Interop.mincore.Errors.ERROR_ALREADY_EXISTS; } break; } diff --git a/src/System.Private.CoreLib/src/System/Threading/Semaphore.cs b/src/System.Private.CoreLib/src/System/Threading/Semaphore.cs index 3bf191b33..2f0dce885 100644 --- a/src/System.Private.CoreLib/src/System/Threading/Semaphore.cs +++ b/src/System.Private.CoreLib/src/System/Threading/Semaphore.cs @@ -44,9 +44,9 @@ namespace System.Threading if (myHandle.IsInvalid) { - uint errorCode = Interop.mincore.GetLastError(); + int errorCode = (int)Interop.mincore.GetLastError(); - if (null != name && 0 != name.Length && (uint)Interop.Constants.ErrorInvalidHandle == errorCode) + if (null != name && 0 != name.Length && Interop.mincore.Errors.ERROR_INVALID_HANDLE == errorCode) throw new WaitHandleCannotBeOpenedException(SR.Format(SR.Threading_WaitHandleCannotBeOpenedException_InvalidHandle, name)); throw ExceptionFromCreationError(errorCode, name); @@ -80,14 +80,14 @@ namespace System.Threading SafeWaitHandle myHandle; myHandle = new SafeWaitHandle(Interop.mincore.CreateSemaphoreEx(IntPtr.Zero, initialCount, maximumCount, name, 0, (uint)(Interop.Constants.SemaphoreModifyState | Interop.Constants.Synchronize)), true); - uint errorCode = Interop.mincore.GetLastError(); + int errorCode = (int)Interop.mincore.GetLastError(); if (myHandle.IsInvalid) { - if (null != name && 0 != name.Length && (uint)Interop.Constants.ErrorInvalidHandle == errorCode) + if (null != name && 0 != name.Length && Interop.mincore.Errors.ERROR_INVALID_HANDLE == errorCode) throw new WaitHandleCannotBeOpenedException(SR.Format(SR.Threading_WaitHandleCannotBeOpenedException_InvalidHandle, name)); throw ExceptionFromCreationError(errorCode, name); } - createdNew = errorCode != (uint)Interop.Constants.ErrorAlreadyExists; + createdNew = errorCode != Interop.mincore.Errors.ERROR_ALREADY_EXISTS; SafeWaitHandle = myHandle; } @@ -142,13 +142,13 @@ namespace System.Threading if (myHandle.IsInvalid) { - uint errorCode = Interop.mincore.GetLastError(); + int errorCode = (int)Interop.mincore.GetLastError(); - if ((uint)Interop.Constants.ErrorFileNotFound == errorCode || (uint)Interop.Constants.ErrorInvalidName == errorCode) + if (Interop.mincore.Errors.ERROR_FILE_NOT_FOUND == errorCode || Interop.mincore.Errors.ERROR_INVALID_NAME == errorCode) return OpenExistingResult.NameNotFound; - if ((uint)Interop.Constants.ErrorPathNotFound == errorCode) + if (Interop.mincore.Errors.ERROR_PATH_NOT_FOUND == errorCode) return OpenExistingResult.PathNotFound; - if (null != name && 0 != name.Length && (uint)Interop.Constants.ErrorInvalidHandle == errorCode) + if (null != name && 0 != name.Length && Interop.mincore.Errors.ERROR_INVALID_HANDLE == errorCode) return OpenExistingResult.NameInvalid; //this is for passed through NativeMethods Errors throw ExceptionFromCreationError(errorCode, name); diff --git a/src/System.Private.CoreLib/src/System/Threading/WaitHandle.cs b/src/System.Private.CoreLib/src/System/Threading/WaitHandle.cs index bbaafb691..babd4f12c 100644 --- a/src/System.Private.CoreLib/src/System/Threading/WaitHandle.cs +++ b/src/System.Private.CoreLib/src/System/Threading/WaitHandle.cs @@ -361,24 +361,24 @@ namespace System.Threading GC.SuppressFinalize(this); } - internal static Exception ExceptionFromCreationError(uint errorCode, string path) + internal static Exception ExceptionFromCreationError(int errorCode, string path) { - switch ((Interop.Constants)errorCode) + switch (errorCode) { - case Interop.Constants.ErrorPathNotFound: + case Interop.mincore.Errors.ERROR_PATH_NOT_FOUND: return new IOException(SR.Format(SR.IO_PathNotFound_Path, path)); - case Interop.Constants.ErrorAccessDenied: + case Interop.mincore.Errors.ERROR_ACCESS_DENIED: return new UnauthorizedAccessException(SR.Format(SR.UnauthorizedAccess_IODenied_Path, path)); - case Interop.Constants.ErrorAlreadyExists: + case Interop.mincore.Errors.ERROR_ALREADY_EXISTS: return new IOException(SR.Format(SR.IO_AlreadyExists_Name, path)); - case Interop.Constants.ErrorFilenameExcedRange: + case Interop.mincore.Errors.ERROR_FILENAME_EXCED_RANGE: return new PathTooLongException(); default: - return new IOException(SR.Arg_IOException, (int)errorCode); + return new IOException(SR.Arg_IOException, errorCode); } } } diff --git a/src/System.Private.CoreLib/src/System/TimeZoneInfo.cs b/src/System.Private.CoreLib/src/System/TimeZoneInfo.cs index 71f12954c..11c597f7e 100644 --- a/src/System.Private.CoreLib/src/System/TimeZoneInfo.cs +++ b/src/System.Private.CoreLib/src/System/TimeZoneInfo.cs @@ -194,7 +194,7 @@ namespace System LowLevelListWithIList<TimeZoneInfo> enumeratedTimeZoneList = new LowLevelListWithIList<TimeZoneInfo>(); uint index = 0; Interop._TIME_DYNAMIC_ZONE_INFORMATION tdzi; - while (Interop.mincore.EnumDynamicTimeZoneInformation(index, out tdzi) != Interop.mincore.ERROR_NO_MORE_ITEMS) + while (Interop.mincore.EnumDynamicTimeZoneInformation(index, out tdzi) != Interop.mincore.Errors.ERROR_NO_MORE_ITEMS) { TimeZoneInformation timeZoneInformation = new TimeZoneInformation(tdzi); TimeZoneInfo value; |