فهرست منبع

2002-01-10 Dick Porter <[email protected]>

	* WaitHandle.cs: Added checks for too many handles and null
	handles in WaitAll() and WaitAny

svn path=/trunk/mcs/; revision=1943
Dick Porter 24 سال پیش
والد
کامیت
a4f1ad32eb
2فایلهای تغییر یافته به همراه65 افزوده شده و 0 حذف شده
  1. 6 0
      mcs/class/corlib/System.Threading/ChangeLog
  2. 59 0
      mcs/class/corlib/System.Threading/WaitHandle.cs

+ 6 - 0
mcs/class/corlib/System.Threading/ChangeLog

@@ -1,3 +1,9 @@
+2002-01-10  Dick Porter  <[email protected]>
+
+	* WaitHandle.cs: Added checks for too many handles and null
+	handles in WaitAll() and WaitAny
+	
+
 2002-01-05  Ravi Pratap  <[email protected]>
 
 	* AutoResetEvent.cs, ManualResetEvent.cs, Monitor.cs : MonoTODO

+ 59 - 0
mcs/class/corlib/System.Threading/WaitHandle.cs

@@ -17,31 +17,81 @@ namespace System.Threading
 		private static extern bool WaitAll_internal(WaitHandle[] handles, int ms, bool exitContext);
 		
 		public static bool WaitAll(WaitHandle[] waitHandles) {
+			if(waitHandles.Length>64) {
+				throw new NotSupportedException("Too many handles");
+			}
+			for(int i=0; i<waitHandles.Length; i++) {
+				if(waitHandles[i]==null) {
+					throw new ArgumentNullException("null handle");
+				}
+			}
+			
 			return(WaitAll_internal(waitHandles, 0, false));
 		}
 
 		public static bool WaitAll(WaitHandle[] waitHandles,
 					   int millisecondsTimeout,
 					   bool exitContext) {
+			if(waitHandles.Length>64) {
+				throw new NotSupportedException("Too many handles");
+			}
+			for(int i=0; i<waitHandles.Length; i++) {
+				if(waitHandles[i]==null) {
+					throw new ArgumentNullException("null handle");
+				}
+			}
+			
 			return(WaitAll_internal(waitHandles, millisecondsTimeout, false));
 		}
 
 		public static bool WaitAll(WaitHandle[] waitHandles,
 					   TimeSpan timeout,
 					   bool exitContext) {
+			if(timeout.Milliseconds < 0 ||
+			   timeout.Milliseconds > Int32.MaxValue) {
+				throw new ArgumentOutOfRangeException("Timeout out of range");
+			}
+			if(waitHandles.Length>64) {
+				throw new NotSupportedException("Too many handles");
+			}
+			for(int i=0; i<waitHandles.Length; i++) {
+				if(waitHandles[i]==null) {
+					throw new ArgumentNullException("null handle");
+				}
+			}
+			
 			return(WaitAll_internal(waitHandles, timeout.Milliseconds, exitContext));
 		}
 
 		[MethodImplAttribute(MethodImplOptions.InternalCall)]
 		private static extern int WaitAny_internal(WaitHandle[] handles, int ms, bool exitContext);
 
+		// LAMESPEC: Doesn't specify how to signal failures
 		public static int WaitAny(WaitHandle[] waitHandles) {
+			if(waitHandles.Length>64) {
+				throw new NotSupportedException("Too many handles");
+			}
+			for(int i=0; i<waitHandles.Length; i++) {
+				if(waitHandles[i]==null) {
+					throw new ArgumentNullException("null handle");
+				}
+			}
+			
 			return(WaitAny_internal(waitHandles, 0, false));
 		}
 
 		public static int WaitAny(WaitHandle[] waitHandles,
 					  int millisecondsTimeout,
 					  bool exitContext) {
+			if(waitHandles.Length>64) {
+				throw new NotSupportedException("Too many handles");
+			}
+			for(int i=0; i<waitHandles.Length; i++) {
+				if(waitHandles[i]==null) {
+					throw new ArgumentNullException("null handle");
+				}
+			}
+			
 			return(WaitAny_internal(waitHandles, millisecondsTimeout, exitContext));
 		}
 
@@ -51,6 +101,15 @@ namespace System.Threading
 			   timeout.Milliseconds > Int32.MaxValue) {
 				throw new ArgumentOutOfRangeException("Timeout out of range");
 			}
+			if(waitHandles.Length>64) {
+				throw new NotSupportedException("Too many handles");
+			}
+			for(int i=0; i<waitHandles.Length; i++) {
+				if(waitHandles[i]==null) {
+					throw new ArgumentNullException("null handle");
+				}
+			}
+			
 			return(WaitAny_internal(waitHandles, timeout.Milliseconds, exitContext));
 		}