From 422b0e81797d5428812c6ef825e22565e2dc63f3 Mon Sep 17 00:00:00 2001 From: Anirudh Agnihotry Date: Mon, 11 Jun 2018 07:29:58 -0700 Subject: [PATCH] Removed length restrictions on named synchronization primitives lengths on Windows (#18402) * Removed Path Length check * waitHandleNameMax removed --- src/System.Private.CoreLib/Resources/Strings.resx | 2 +- .../shared/System/Threading/Mutex.Windows.cs | 20 ++------------------ .../shared/System/Threading/Mutex.cs | 2 -- .../src/System/Threading/EventWaitHandle.cs | 17 ----------------- .../src/System/Threading/Semaphore.cs | 5 ----- 5 files changed, 3 insertions(+), 43 deletions(-) diff --git a/src/System.Private.CoreLib/Resources/Strings.resx b/src/System.Private.CoreLib/Resources/Strings.resx index b21ebe9..7c208cf 100644 --- a/src/System.Private.CoreLib/Resources/Strings.resx +++ b/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/System.Private.CoreLib/shared/System/Threading/Mutex.Windows.cs b/src/System.Private.CoreLib/shared/System/Threading/Mutex.Windows.cs index e3fa7b7..321deca 100644 --- a/src/System.Private.CoreLib/shared/System/Threading/Mutex.Windows.cs +++ b/src/System.Private.CoreLib/shared/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/System.Private.CoreLib/shared/System/Threading/Mutex.cs b/src/System.Private.CoreLib/shared/System/Threading/Mutex.cs index bcc4ac7..d852428 100644 --- a/src/System.Private.CoreLib/shared/System/Threading/Mutex.cs +++ b/src/System.Private.CoreLib/shared/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 _); } diff --git a/src/System.Private.CoreLib/src/System/Threading/EventWaitHandle.cs b/src/System.Private.CoreLib/src/System/Threading/EventWaitHandle.cs index 4a02876..241c9a3 100644 --- a/src/System.Private.CoreLib/src/System/Threading/EventWaitHandle.cs +++ b/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/System.Private.CoreLib/src/System/Threading/Semaphore.cs b/src/System.Private.CoreLib/src/System/Threading/Semaphore.cs index 8380c56..d4b600c 100644 --- a/src/System.Private.CoreLib/src/System/Threading/Semaphore.cs +++ b/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); -- 2.7.4