Removed length restrictions on named synchronization primitives lengths on Windows...
authorAnirudh Agnihotry <anirudhagnihotry098@gmail.com>
Mon, 11 Jun 2018 14:29:58 +0000 (07:29 -0700)
committerJan Kotas <jkotas@microsoft.com>
Mon, 11 Jun 2018 14:29:58 +0000 (07:29 -0700)
* Removed Path Length check

* waitHandleNameMax removed

src/System.Private.CoreLib/Resources/Strings.resx
src/System.Private.CoreLib/shared/System/Threading/Mutex.Windows.cs
src/System.Private.CoreLib/shared/System/Threading/Mutex.cs
src/System.Private.CoreLib/src/System/Threading/EventWaitHandle.cs
src/System.Private.CoreLib/src/System/Threading/Semaphore.cs

index b21ebe9..7c208cf 100644 (file)
     <value>The unmanaged Version information is too large to persist.</value>
   </data>
   <data name="Argument_WaitHandleNameTooLong" xml:space="preserve">
-    <value>The name '{0}' can be no more than {1} characters in length.</value>
+    <value>The length of the name exceeds the maximum limit.</value>
   </data>
   <data name="Argument_WinRTSystemRuntimeType" xml:space="preserve">
     <value>Cannot marshal type '{0}' to Windows Runtime. Only 'System.RuntimeType' is supported.</value>
index e3fa7b7..321deca 100644 (file)
@@ -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)
index bcc4ac7..d852428 100644 (file)
@@ -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 _);
         }
 
index 4a02876..241c9a3 100644 (file)
@@ -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)
index 8380c56..d4b600c 100644 (file)
@@ -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);