From: Anirudh Agnihotry Date: Mon, 11 Jun 2018 14:29:58 +0000 (-0700) Subject: Removed length restrictions on named synchronization primitives lengths on Windows... X-Git-Tag: submit/tizen/20210909.063632~11030^2~4630 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2d1828b78fc9b3cbecf879c1dff2112d6a6ed9aa;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Removed length restrictions on named synchronization primitives lengths on Windows (dotnet/coreclr#18402) * Removed Path Length check * waitHandleNameMax removed Commit migrated from https://github.com/dotnet/coreclr/commit/422b0e81797d5428812c6ef825e22565e2dc63f3 --- diff --git a/src/coreclr/src/System.Private.CoreLib/Resources/Strings.resx b/src/coreclr/src/System.Private.CoreLib/Resources/Strings.resx index b21ebe9..7c208cf 100644 --- a/src/coreclr/src/System.Private.CoreLib/Resources/Strings.resx +++ b/src/coreclr/src/System.Private.CoreLib/Resources/Strings.resx @@ -1577,7 +1577,7 @@ The unmanaged Version information is too large to persist. - The name '{0}' can be no more than {1} characters in length. + The length of the name exceeds the maximum limit. Cannot marshal type '{0}' to Windows Runtime. Only 'System.RuntimeType' is supported. diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Threading/EventWaitHandle.cs b/src/coreclr/src/System.Private.CoreLib/src/System/Threading/EventWaitHandle.cs index 4a02876..241c9a3 100644 --- a/src/coreclr/src/System.Private.CoreLib/src/System/Threading/EventWaitHandle.cs +++ b/src/coreclr/src/System.Private.CoreLib/src/System/Threading/EventWaitHandle.cs @@ -49,11 +49,6 @@ namespace System.Threading { #if PLATFORM_UNIX throw new PlatformNotSupportedException(SR.PlatformNotSupported_NamedSynchronizationPrimitives); -#else - if (Interop.Kernel32.MAX_PATH < name.Length) - { - throw new ArgumentException(SR.Format(SR.Argument_WaitHandleNameTooLong, name, Interop.Kernel32.MAX_PATH), nameof(name)); - } #endif } @@ -97,11 +92,6 @@ namespace System.Threading { #if PLATFORM_UNIX throw new PlatformNotSupportedException(SR.PlatformNotSupported_NamedSynchronizationPrimitives); -#else - if (Interop.Kernel32.MAX_PATH < name.Length) - { - throw new ArgumentException(SR.Format(SR.Argument_WaitHandleNameTooLong, name, Interop.Kernel32.MAX_PATH), nameof(name)); - } #endif } Win32Native.SECURITY_ATTRIBUTES secAttrs = null; @@ -184,14 +174,7 @@ namespace System.Threading throw new ArgumentException(SR.Argument_EmptyName, nameof(name)); } - if (null != name && Interop.Kernel32.MAX_PATH < name.Length) - { - throw new ArgumentException(SR.Format(SR.Argument_WaitHandleNameTooLong, name, Interop.Kernel32.MAX_PATH), nameof(name)); - } - - result = null; - SafeWaitHandle myHandle = Win32Native.OpenEvent(AccessRights, false, name); if (myHandle.IsInvalid) diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Threading/Semaphore.cs b/src/coreclr/src/System.Private.CoreLib/src/System/Threading/Semaphore.cs index 8380c56..d4b600c 100644 --- a/src/coreclr/src/System.Private.CoreLib/src/System/Threading/Semaphore.cs +++ b/src/coreclr/src/System.Private.CoreLib/src/System/Threading/Semaphore.cs @@ -92,9 +92,6 @@ namespace System.Threading { #if PLATFORM_UNIX throw new PlatformNotSupportedException(SR.PlatformNotSupported_NamedSynchronizationPrimitives); -#else - if (name.Length > Interop.Kernel32.MAX_PATH) - throw new ArgumentException(SR.Format(SR.Argument_WaitHandleNameTooLong, name, Interop.Kernel32.MAX_PATH), nameof(name)); #endif } @@ -135,8 +132,6 @@ namespace System.Threading throw new ArgumentNullException(nameof(name)); if (name.Length == 0) throw new ArgumentException(SR.Argument_EmptyName, nameof(name)); - if (name.Length > Interop.Kernel32.MAX_PATH) - throw new ArgumentException(SR.Format(SR.Argument_WaitHandleNameTooLong, name, Interop.Kernel32.MAX_PATH), nameof(name)); //Pass false to OpenSemaphore to prevent inheritedHandles SafeWaitHandle myHandle = Win32Native.OpenSemaphore(AccessRights, false, name); diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Mutex.Windows.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Mutex.Windows.cs index e3fa7b7..321deca 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/Mutex.Windows.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Mutex.Windows.cs @@ -18,21 +18,6 @@ namespace System.Threading private const uint AccessRights = (uint)Interop.Kernel32.MAXIMUM_ALLOWED | Interop.Kernel32.SYNCHRONIZE | Interop.Kernel32.MUTEX_MODIFY_STATE; -#if PLATFORM_UNIX - // Maximum file name length on tmpfs file system. - private const int WaitHandleNameMax = 255; -#endif - - private static void VerifyNameForCreate(string name) - { -#if PLATFORM_WINDOWS - if (name != null && (Interop.Kernel32.MAX_PATH < name.Length)) - { - throw new ArgumentException(SR.Format(SR.Argument_WaitHandleNameTooLong, name, Interop.Kernel32.MAX_PATH), nameof(name)); - } -#endif - } - private void CreateMutexCore(bool initiallyOwned, string name, out bool createdNew) { uint mutexFlags = initiallyOwned ? Interop.Kernel32.CREATE_MUTEX_INITIAL_OWNER : 0; @@ -45,7 +30,7 @@ namespace System.Threading #if PLATFORM_UNIX if (errorCode == Interop.Errors.ERROR_FILENAME_EXCED_RANGE) // On Unix, length validation is done by CoreCLR's PAL after converting to utf-8 - throw new ArgumentException(SR.Format(SR.Argument_WaitHandleNameTooLong, name, WaitHandleNameMax), nameof(name)); + throw new ArgumentException(SR.Argument_WaitHandleNameTooLong, nameof(name)); #endif if (errorCode == Interop.Errors.ERROR_INVALID_HANDLE) throw new WaitHandleCannotBeOpenedException(SR.Format(SR.Threading_WaitHandleCannotBeOpenedException_InvalidHandle, name)); @@ -69,7 +54,6 @@ namespace System.Threading throw new ArgumentException(SR.Argument_EmptyName, nameof(name)); } - VerifyNameForCreate(name); result = null; // To allow users to view & edit the ACL's, call OpenMutex // with parameters to allow us to view & edit the ACL. This will @@ -84,7 +68,7 @@ namespace System.Threading if (errorCode == Interop.Errors.ERROR_FILENAME_EXCED_RANGE) { // On Unix, length validation is done by CoreCLR's PAL after converting to utf-8 - throw new ArgumentException(SR.Format(SR.Argument_WaitHandleNameTooLong, name, WaitHandleNameMax), nameof(name)); + throw new ArgumentException(SR.Argument_WaitHandleNameTooLong, nameof(name)); } #endif if (Interop.Errors.ERROR_FILE_NOT_FOUND == errorCode || Interop.Errors.ERROR_INVALID_NAME == errorCode) diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Mutex.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Mutex.cs index bcc4ac7..d852428 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/Mutex.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Mutex.cs @@ -17,13 +17,11 @@ namespace System.Threading { public Mutex(bool initiallyOwned, string name, out bool createdNew) { - VerifyNameForCreate(name); CreateMutexCore(initiallyOwned, name, out createdNew); } public Mutex(bool initiallyOwned, string name) { - VerifyNameForCreate(name); CreateMutexCore(initiallyOwned, name, out _); }