Procházet zdrojové kódy

2004-08-17 Dick Porter <[email protected]>

	* daemon.c (process_new):
	* handles.c (_wapi_handle_new_internal): Cope when the space
	reserved for file descriptors is larger than the shared segment
	size.  Fixes the crash reported when running mono under gdb on
	macosx.

svn path=/trunk/mono/; revision=32436
Dick Porter před 21 roky
rodič
revize
9282f2f90e
3 změnil soubory, kde provedl 23 přidání a 11 odebrání
  1. 8 0
      mono/io-layer/ChangeLog
  2. 1 4
      mono/io-layer/daemon.c
  3. 14 7
      mono/io-layer/handles.c

+ 8 - 0
mono/io-layer/ChangeLog

@@ -1,3 +1,11 @@
+2004-08-17  Dick Porter  <[email protected]>
+
+	* daemon.c (process_new): 
+	* handles.c (_wapi_handle_new_internal): Cope when the space
+	reserved for file descriptors is larger than the shared segment
+	size.  Fixes the crash reported when running mono under gdb on
+	macosx.
+
 2004-08-16  Dick Porter  <[email protected]>
 
 	* sockets.c:

+ 1 - 4
mono/io-layer/daemon.c

@@ -845,8 +845,7 @@ static void process_new (GIOChannel *channel, ChannelData *channel_data,
 	guint32 handle;
 	WapiHandleResponse resp={0};
 	
-	handle=_wapi_handle_new_internal (type);
-	if(handle==0) {
+	while ((handle = _wapi_handle_new_internal (type)) == 0) {
 		/* Try and allocate a new shared segment, and have
 		 * another go
 		 */
@@ -871,8 +870,6 @@ static void process_new (GIOChannel *channel, ChannelData *channel_data,
 					channels[i].open_handles=_wapi_g_renew0 (channels[i].open_handles, old_len, new_len);
 				}
 			}
-
-			handle=_wapi_handle_new_internal (type);
 		} else {
 			/* Map failed.  Just return 0 meaning "out of
 			 * handles"

+ 14 - 7
mono/io-layer/handles.c

@@ -250,6 +250,7 @@ guint32 _wapi_handle_new_internal (WapiHandleType type)
 	guint32 i, j;
 	static guint32 last=1;
 	int thr_ret;
+	guint32 num_segments = _wapi_handle_get_shared_segment (0)->num_segments;
 	
 	/* A linear scan should be fast enough.  Start from the last
 	 * allocation, assuming that handles are allocated more often
@@ -260,8 +261,7 @@ guint32 _wapi_handle_new_internal (WapiHandleType type)
 #endif
 again:
 	_wapi_handle_segment (GUINT_TO_POINTER (last), &segment, &idx);
-	for(i=segment; i<_wapi_handle_get_shared_segment (0)->num_segments;
-	    i++) {
+	for(i=segment; i < num_segments; i++) {
 		if(i!=segment) {
 			idx=0;
 		}
@@ -272,8 +272,17 @@ again:
 			/* Make sure we dont try and assign the
 			 * handles that would clash with fds
 			 */
-			if (i==0 && j < _wapi_fd_offset_table_size) {
-				j = _wapi_fd_offset_table_size;
+			if ((i * _WAPI_HANDLES_PER_SEGMENT + j) < _wapi_fd_offset_table_size) {
+				i = _wapi_fd_offset_table_size / _WAPI_HANDLES_PER_SEGMENT;
+				j = _wapi_fd_offset_table_size - (i * _WAPI_HANDLES_PER_SEGMENT);
+				
+				if (i >= num_segments) {
+					/* Need to get the caller to
+					 * add more shared segments
+					 */
+					return(0);
+				}
+				
 				continue;
 			}
 			
@@ -349,8 +358,7 @@ again:
 		thr_ret = pthread_mutex_lock (&scan_mutex);
 		g_assert (thr_ret == 0);
 		
-		handle_idx=_wapi_handle_new_internal (type);
-		if(handle_idx==0) {
+		while ((handle_idx = _wapi_handle_new_internal (type)) == 0) {
 			/* Try and get a new segment, and have another go */
 			segment=_wapi_handle_get_shared_segment (0)->num_segments;
 			_wapi_handle_ensure_mapped (segment);
@@ -358,7 +366,6 @@ again:
 			if(_wapi_handle_get_shared_segment (segment)!=NULL) {
 				/* Got a new segment */
 				_wapi_handle_get_shared_segment (0)->num_segments++;
-				handle_idx=_wapi_handle_new_internal (type);
 			} else {
 				/* Map failed.  Just return 0 meaning
 				 * "out of handles"