Browse Source

[io-layer] Remove shared handles cross process support

Ludovic Henry 10 years ago
parent
commit
91ddeb4a83

+ 2 - 16
configure.ac

@@ -417,7 +417,7 @@ AC_PROG_LD_GNU
 AM_ICONV()
 
 AC_CHECK_HEADERS(sys/filio.h sys/sockio.h netdb.h utime.h sys/utime.h semaphore.h sys/un.h linux/rtc.h sys/syscall.h sys/mkdev.h sys/uio.h sys/param.h sys/sysctl.h libproc.h sys/prctl.h)
-AC_CHECK_HEADERS(sys/param.h sys/socket.h sys/ipc.h sys/sem.h sys/utsname.h alloca.h ucontext.h pwd.h sys/select.h netinet/tcp.h netinet/in.h unistd.h sys/types.h link.h asm/sigcontext.h sys/inotify.h arpa/inet.h complex.h unwind.h)
+AC_CHECK_HEADERS(sys/param.h sys/socket.h sys/ipc.h sys/utsname.h alloca.h ucontext.h pwd.h sys/select.h netinet/tcp.h netinet/in.h unistd.h sys/types.h link.h asm/sigcontext.h sys/inotify.h arpa/inet.h complex.h unwind.h)
 AC_CHECK_HEADERS([linux/netlink.h linux/rtnetlink.h],
                   [], [], [#include <stddef.h>
 		  #include <sys/socket.h>
@@ -731,7 +731,7 @@ DISABLED_FEATURES=none
 AC_ARG_ENABLE(minimal, [  --enable-minimal=LIST      drop support for LIST subsystems.
      LIST is a comma-separated list from: aot, profiler, decimal, pinvoke, debug, appdomains, verifier, 
      reflection_emit, reflection_emit_save, large_code, logging, com, ssa, generics, attach, jit, simd, soft_debug, perfcounters, normalization, assembly_remapping, shared_perfcounters, remoting,
-	 security, sgen_remset, sgen_marksweep_par, sgen_marksweep_fixed, sgen_marksweep_fixed_par, sgen_copying, shared_handles.],
+	 security, sgen_remset, sgen_marksweep_par, sgen_marksweep_fixed, sgen_marksweep_fixed_par, sgen_copying.],
 [
 	for feature in `echo "$enable_minimal" | sed -e "s/,/ /g"`; do
 		eval "mono_feature_disable_$feature='yes'"
@@ -906,11 +906,6 @@ if test "x$mono_feature_disable_sgen_copying" = "xyes"; then
 	AC_MSG_NOTICE([Disabled major=copying support in SGEN.])
 fi
 
-if test "x$mono_feature_disable_shared_handles" = "xyes"; then
-	AC_DEFINE(DISABLE_SHARED_HANDLES, 1, [Disable inter-process shared handles])
-	AC_SUBST(DISABLE_SHARED_HANDLES)
-fi
-
 AC_ARG_ENABLE(executables, [  --disable-executables disable the build of the runtime executables], enable_executables=$enableval, enable_executables=yes)
 AM_CONDITIONAL(DISABLE_EXECUTABLES, test x$enable_executables = xno)
 
@@ -2443,15 +2438,6 @@ if test "x$ac_cv_have_dev_random" = "xno" \
 *** variable MONO_EGD_SOCKET to point to the daemon's socket to use that.
 ***]])
 fi
- 
-AC_MSG_CHECKING([if inter-process shared handles are requested])
-# Same as --enable-minimal=shared_handles
-AC_ARG_ENABLE(shared-handles, [  --disable-shared-handles disable inter-process shared handles], try_shared_handles=$enableval, try_shared_handles=no)
-AC_MSG_RESULT($try_shared_handles)
-if test "x$try_shared_handles" != "xyes"; then
-	AC_DEFINE(DISABLE_SHARED_HANDLES, 1, [Disable inter-process shared handles])
-	AC_SUBST(DISABLE_SHARED_HANDLES)
-fi
 
 AC_ARG_ENABLE(bcl-opt, [  --disable-bcl-opt	BCL is compiled with no optimizations (allows accurate BCL debugging)], test_bcl_opt=$enableval, test_bcl_opt=yes)
 

+ 0 - 3
mono/io-layer/Makefile.am

@@ -12,7 +12,6 @@ libwapiincludedir = $(includedir)/mono-$(API_VER)/mono/io-layer
 
 OTHER_H = \
 	access.h	\
-	collection.h	\
 	context.h	\
 	error.h		\
 	events.h	\
@@ -39,8 +38,6 @@ OTHER_H = \
 
 OTHER_SRC = \
 	access.h		\
-	collection.c		\
-	collection.h		\
 	context.c		\
 	context.h		\
 	error.c			\

+ 0 - 131
mono/io-layer/collection.c

@@ -1,131 +0,0 @@
-/*
- * collection.c:  Garbage collection for handles
- *
- * Author:
- *	Dick Porter ([email protected])
- *
- * (C) 2004-2006 Novell, Inc.
- */
-
-#include <config.h>
-#include <glib.h>
-#include <pthread.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-#include <mono/io-layer/wapi.h>
-#include <mono/io-layer/collection.h>
-#include <mono/io-layer/handles-private.h>
-#include <mono/utils/atomic.h>
-
-#if 0
-// #define DEBUG(...) g_message(__VA_ARGS__)
-#else
-#define DEBUG(...)
-#endif
-
-static pthread_t collection_thread_id;
-
-static gpointer collection_thread (gpointer unused G_GNUC_UNUSED)
-{
-	struct timespec sleepytime;
-
-	sleepytime.tv_sec = _WAPI_HANDLE_COLLECTION_UPDATE_INTERVAL;
-	sleepytime.tv_nsec = 0;
-
-	while (_wapi_has_shut_down == FALSE) {
-		nanosleep (&sleepytime, NULL);
-
-		//_wapi_handle_dump ();
-		_wapi_handle_update_refs ();
-	}
-
-	pthread_exit (NULL);
-
-	return(NULL);
-}
-
-void _wapi_collection_init (void)
-{
-	pthread_attr_t attr;
-	int ret;
-        int set_stacksize = 0;
-
- retry:
-        ret = pthread_attr_init (&attr);
-        g_assert (ret == 0);
-
-#if defined(HAVE_PTHREAD_ATTR_SETSTACKSIZE)
-        if (set_stacksize == 0) {
-			ret = pthread_attr_setstacksize (&attr, MAX (65536, PTHREAD_STACK_MIN));
-			g_assert (ret == 0);
-        } else if (set_stacksize == 1) {
-			ret = pthread_attr_setstacksize (&attr, 131072);
-			g_assert (ret == 0);
-        }
-#endif
-
-        ret = pthread_create (&collection_thread_id, &attr, collection_thread,
-                              NULL);
-        if (ret != 0 && set_stacksize < 2) {
-                set_stacksize++;
-                goto retry;
-        }
-	if (ret != 0) {
-		g_error ("%s: Couldn't create handle collection thread: %s",
-			 __func__, g_strerror (ret));
-	}
-}
-
-void _wapi_handle_collect (void)
-{
-	guint32 count = _wapi_shared_layout->collection_count;
-	int i, thr_ret;
-
-	if (!_wapi_shm_enabled ())
-		return;
-	
-	DEBUG ("%s: (%d) Starting a collection", __func__, _wapi_getpid ());
-
-	/* Become the collection master */
-	thr_ret = _wapi_handle_lock_shared_handles ();
-	g_assert (thr_ret == 0);
-	
-	thr_ret = _wapi_shm_sem_lock (_WAPI_SHARED_SEM_FILESHARE);
-	g_assert (thr_ret == 0);
-	
-	DEBUG ("%s: (%d) Master set", __func__, _wapi_getpid ());
-	
-	/* If count has changed, someone else jumped in as master */
-	if (count == _wapi_shared_layout->collection_count) {
-		guint32 too_old = (guint32)(time(NULL) & 0xFFFFFFFF) - _WAPI_HANDLE_COLLECTION_EXPIRED_INTERVAL;
-
-		for (i = 0; i < _WAPI_HANDLE_INITIAL_COUNT; i++) {
-			struct _WapiHandleShared *data;
-			
-			data = &_wapi_shared_layout->handles[i];
-			if (data->timestamp < too_old) {
-				DEBUG ("%s: (%d) Deleting handle 0x%x", __func__, _wapi_getpid (), i);
-				memset (&_wapi_shared_layout->handles[i], '\0', sizeof(struct _WapiHandleShared));
-			}
-		}
-
-		for (i = 0; i < _wapi_fileshare_layout->hwm; i++) {
-			struct _WapiFileShare *file_share = &_wapi_fileshare_layout->share_info[i];
-			
-			if (file_share->timestamp < too_old) {
-				memset (file_share, '\0',
-					sizeof(struct _WapiFileShare));
-			}
-		}
-
-		InterlockedIncrement ((gint32 *)&_wapi_shared_layout->collection_count);
-	}
-	
-	thr_ret = _wapi_shm_sem_unlock (_WAPI_SHARED_SEM_FILESHARE);
-	g_assert (thr_ret == 0);
-        
-	_wapi_handle_unlock_shared_handles ();
-
-	DEBUG ("%s: (%d) Collection done", __func__, _wapi_getpid ());
-}

+ 0 - 27
mono/io-layer/collection.h

@@ -1,27 +0,0 @@
-/*
- * collection.h:  Garbage collection for handles
- *
- * Author:
- *	Dick Porter ([email protected])
- *
- * (C) 2004 Novell, Inc.
- */
-
-#ifndef _WAPI_COLLECTION_H_
-#define _WAPI_COLLECTION_H_
-
-#include <glib.h>
-
-G_BEGIN_DECLS
-
-#define _WAPI_HANDLE_COLLECTION_UPDATE_INTERVAL		10
-#define _WAPI_HANDLE_COLLECTION_EXPIRED_INTERVAL	60
-
-#include <mono/io-layer/shared.h>
-
-extern void _wapi_collection_init (void);
-extern void _wapi_handle_collect (void);
-
-G_END_DECLS
-
-#endif /* _WAPI_COLLECTION_H_ */

+ 0 - 3
mono/io-layer/handles-private.h

@@ -17,7 +17,6 @@
 #include <sys/types.h>
 
 #include <mono/io-layer/wapi-private.h>
-#include <mono/io-layer/collection.h>
 #include <mono/io-layer/shared.h>
 #include <mono/utils/atomic.h>
 
@@ -31,7 +30,6 @@
 
 extern struct _WapiHandleUnshared *_wapi_private_handles [];
 extern struct _WapiHandleSharedLayout *_wapi_shared_layout;
-extern struct _WapiFileShareLayout *_wapi_fileshare_layout;
 
 extern guint32 _wapi_fd_reserve;
 extern mono_mutex_t *_wapi_global_signal_mutex;
@@ -89,7 +87,6 @@ extern gboolean _wapi_handle_get_or_set_share (guint64 device, guint64 inode,
 extern void _wapi_handle_check_share (struct _WapiFileShare *share_info,
 				      int fd);
 extern void _wapi_handle_dump (void);
-extern void _wapi_handle_update_refs (void);
 extern void _wapi_handle_foreach (WapiHandleType type,
 					gboolean (*on_each)(gpointer test, gpointer user),
 					gpointer user_data);

+ 40 - 186
mono/io-layer/handles.c

@@ -39,7 +39,6 @@
 #include <mono/io-layer/wapi-private.h>
 #include <mono/io-layer/handles-private.h>
 #include <mono/io-layer/shared.h>
-#include <mono/io-layer/collection.h>
 #include <mono/io-layer/process-private.h>
 
 #include <mono/utils/mono-os-mutex.h>
@@ -126,11 +125,6 @@ static guint32 _wapi_private_handle_slot_count = 0;
 
 struct _WapiHandleSharedLayout *_wapi_shared_layout = NULL;
 
-/*
- * If SHM is enabled, this will point to shared memory, otherwise it will be NULL.
- */
-struct _WapiFileShareLayout *_wapi_fileshare_layout = NULL;
-
 /*
  * If SHM is disabled, this will point to a hash of _WapiFileShare structures, otherwise
  * it will be NULL. We use this instead of _wapi_fileshare_layout to avoid allocating a
@@ -208,8 +202,7 @@ static void handle_cleanup (void)
 	
 	_wapi_shm_semaphores_remove ();
 
-	_wapi_shm_detach (WAPI_SHM_DATA);
-	_wapi_shm_detach (WAPI_SHM_FILESHARE);
+	g_free (_wapi_shared_layout);
 
 	if (file_share_hash) {
 		g_hash_table_destroy (file_share_hash);
@@ -257,20 +250,10 @@ wapi_init (void)
 	} while(_wapi_fd_reserve > _wapi_private_handle_count);
 
 	_wapi_shm_semaphores_init ();
-	
-	_wapi_shared_layout = (_WapiHandleSharedLayout *)_wapi_shm_attach (WAPI_SHM_DATA);
+
+	_wapi_shared_layout = (_WapiHandleSharedLayout *)g_malloc0 (sizeof (_WapiHandleSharedLayout));
 	g_assert (_wapi_shared_layout != NULL);
-	
-	if (_wapi_shm_enabled ()) {
-		/* This allocates a 4mb array, so do it only if SHM is enabled */
-		_wapi_fileshare_layout = (_WapiFileShareLayout *)_wapi_shm_attach (WAPI_SHM_FILESHARE);
-		g_assert (_wapi_fileshare_layout != NULL);
-	}
-	
-#if !defined (DISABLE_SHARED_HANDLES)
-	if (_wapi_shm_enabled ())
-		_wapi_collection_init ();
-#endif
+
 	_wapi_io_init ();
 	mono_os_mutex_init (&scan_mutex);
 
@@ -544,7 +527,6 @@ _wapi_handle_new (WapiHandleType type, gpointer handle_specific)
 		
 		ref = _wapi_handle_new_shared (type, handle_specific);
 		if (ref == 0) {
-			_wapi_handle_collect ();
 			ref = _wapi_handle_new_shared (type, handle_specific);
 			if (ref == 0) {
 				/* FIXME: grow the arrays */
@@ -959,11 +941,6 @@ gint32 _wapi_search_handle_namespace (WapiHandleType type,
 	DEBUG ("%s: Lookup for handle named [%s] type %s", __func__,
 		   utf8_name, _wapi_handle_typename[type]);
 
-	/* Do a handle collection before starting to look, so that any
-	 * stale cruft gets removed
-	 */
-	_wapi_handle_collect ();
-	
 	thr_ret = _wapi_handle_lock_shared_handles ();
 	g_assert (thr_ret == 0);
 	
@@ -1623,14 +1600,10 @@ _wapi_handle_timedwait_signal_handle (gpointer handle, guint32 timeout, gboolean
 void
 _wapi_free_share_info (_WapiFileShare *share_info)
 {
-	if (!_wapi_shm_enabled ()) {
-		file_share_hash_lock ();
-		g_hash_table_remove (file_share_hash, share_info);
-		file_share_hash_unlock ();
-		/* The hashtable dtor frees share_info */
-	} else {
-		memset (share_info, '\0', sizeof(struct _WapiFileShare));
-	}
+	file_share_hash_lock ();
+	g_hash_table_remove (file_share_hash, share_info);
+	file_share_hash_unlock ();
+	/* The hashtable dtor frees share_info */
 }
 
 static gint
@@ -1658,8 +1631,7 @@ gboolean _wapi_handle_get_or_set_share (guint64 device, guint64 inode,
 					struct _WapiFileShare **share_info)
 {
 	struct _WapiFileShare *file_share;
-	guint32 now = (guint32)(time(NULL) & 0xFFFFFFFF);
-	int thr_ret, i, first_unused = -1;
+	int thr_ret;
 	gboolean exists = FALSE;
 
 	/* Prevents entries from expiring under us as we search
@@ -1671,110 +1643,46 @@ gboolean _wapi_handle_get_or_set_share (guint64 device, guint64 inode,
 	thr_ret = _wapi_shm_sem_lock (_WAPI_SHARED_SEM_FILESHARE);
 	g_assert (thr_ret == 0);
 
-	if (!_wapi_shm_enabled ()) {
-		_WapiFileShare tmp;
-
-		/*
-		 * Instead of allocating a 4MB array, we use a hash table to keep track of this
-		 * info. This is needed even if SHM is disabled, to track sharing inside
-		 * the current process.
-		 */
-		if (!file_share_hash) {
-			file_share_hash = g_hash_table_new_full (wapi_share_info_hash, wapi_share_info_equal, NULL, g_free);
-			mono_os_mutex_init_recursive (&file_share_hash_mutex);
-		}
-			
-		tmp.device = device;
-		tmp.inode = inode;
+	_WapiFileShare tmp;
 
-		file_share_hash_lock ();
+	/*
+	 * Instead of allocating a 4MB array, we use a hash table to keep track of this
+	 * info. This is needed even if SHM is disabled, to track sharing inside
+	 * the current process.
+	 */
+	if (!file_share_hash) {
+		file_share_hash = g_hash_table_new_full (wapi_share_info_hash, wapi_share_info_equal, NULL, g_free);
+		mono_os_mutex_init_recursive (&file_share_hash_mutex);
+	}
 
-		file_share = (_WapiFileShare *)g_hash_table_lookup (file_share_hash, &tmp);
-		if (file_share) {
-			*old_sharemode = file_share->sharemode;
-			*old_access = file_share->access;
-			*share_info = file_share;
-			
-			InterlockedIncrement ((gint32 *)&file_share->handle_refs);
-			exists = TRUE;
-		} else {
-			file_share = g_new0 (_WapiFileShare, 1);
+	tmp.device = device;
+	tmp.inode = inode;
 
-			file_share->device = device;
-			file_share->inode = inode;
-			file_share->opened_by_pid = _wapi_getpid ();
-			file_share->sharemode = new_sharemode;
-			file_share->access = new_access;
-			file_share->handle_refs = 1;
-			*share_info = file_share;
+	file_share_hash_lock ();
 
-			g_hash_table_insert (file_share_hash, file_share, file_share);
-		}
+	file_share = (_WapiFileShare *)g_hash_table_lookup (file_share_hash, &tmp);
+	if (file_share) {
+		*old_sharemode = file_share->sharemode;
+		*old_access = file_share->access;
+		*share_info = file_share;
 
-		file_share_hash_unlock ();
+		InterlockedIncrement ((gint32 *)&file_share->handle_refs);
+		exists = TRUE;
 	} else {
-		/* If a linear scan gets too slow we'll have to fit a hash
-		 * table onto the shared mem backing store
-		 */
-		*share_info = NULL;
-		for (i = 0; i <= _wapi_fileshare_layout->hwm; i++) {
-			file_share = &_wapi_fileshare_layout->share_info[i];
+		file_share = g_new0 (_WapiFileShare, 1);
 
-			/* Make a note of an unused slot, in case we need to
-			 * store share info
-			 */
-			if (first_unused == -1 && file_share->handle_refs == 0) {
-				first_unused = i;
-				continue;
-			}
-		
-			if (file_share->handle_refs == 0) {
-				continue;
-			}
-		
-			if (file_share->device == device &&
-				file_share->inode == inode) {
-				*old_sharemode = file_share->sharemode;
-				*old_access = file_share->access;
-				*share_info = file_share;
-			
-				/* Increment the reference count while we
-				 * still have sole access to the shared area.
-				 * This makes the increment atomic wrt
-				 * collections
-				 */
-				InterlockedIncrement ((gint32 *)&file_share->handle_refs);
-			
-				exists = TRUE;
-				break;
-			}
-		}
-	
-		if (!exists) {
-			if (i == _WAPI_FILESHARE_SIZE && first_unused == -1) {
-				/* No more space */
-			} else {
-				if (first_unused == -1) {
-					file_share = &_wapi_fileshare_layout->share_info[++i];
-					_wapi_fileshare_layout->hwm = i;
-				} else {
-					file_share = &_wapi_fileshare_layout->share_info[first_unused];
-				}
-			
-				file_share->device = device;
-				file_share->inode = inode;
-				file_share->opened_by_pid = _wapi_getpid ();
-				file_share->sharemode = new_sharemode;
-				file_share->access = new_access;
-				file_share->handle_refs = 1;
-				*share_info = file_share;
-			}
-		}
+		file_share->device = device;
+		file_share->inode = inode;
+		file_share->opened_by_pid = _wapi_getpid ();
+		file_share->sharemode = new_sharemode;
+		file_share->access = new_access;
+		file_share->handle_refs = 1;
+		*share_info = file_share;
 
-		if (*share_info != NULL) {
-			InterlockedExchange ((gint32 *)&(*share_info)->timestamp, now);
-		}
+		g_hash_table_insert (file_share_hash, file_share, file_share);
 	}
+
+	file_share_hash_unlock ();
 	
 	thr_ret = _wapi_shm_sem_unlock (_WAPI_SHARED_SEM_FILESHARE);
 
@@ -1935,57 +1843,3 @@ static void _wapi_shared_details (gpointer handle_info)
 	
 	g_print ("offset: 0x%x", shared->offset);
 }
-
-void _wapi_handle_update_refs (void)
-{
-	guint32 i, k;
-	int thr_ret;
-	guint32 now = (guint32)(time (NULL) & 0xFFFFFFFF);
-	
-	thr_ret = _wapi_handle_lock_shared_handles ();
-	g_assert (thr_ret == 0);
-
-	/* Prevent file share entries racing with us */
-	thr_ret = _wapi_shm_sem_lock (_WAPI_SHARED_SEM_FILESHARE);
-	g_assert(thr_ret == 0);
-
-	thr_ret = mono_os_mutex_lock (&scan_mutex);
-	
-	for(i = SLOT_INDEX (0); i < _wapi_private_handle_slot_count; i++) {
-		if (_wapi_private_handles [i]) {
-			for (k = SLOT_OFFSET (0); k < _WAPI_HANDLE_INITIAL_COUNT; k++) {
-				struct _WapiHandleUnshared *handle = &_wapi_private_handles [i][k];
-
-				if (_WAPI_SHARED_HANDLE(handle->type)) {
-					struct _WapiHandleShared *shared_data;
-				
-					DEBUG ("%s: (%d) handle 0x%x is SHARED (%s)", __func__, _wapi_getpid (), i * _WAPI_HANDLE_INITIAL_COUNT + k, _wapi_handle_typename[handle->type]);
-
-					shared_data = &_wapi_shared_layout->handles[handle->u.shared.offset];
-
-					DEBUG ("%s: (%d) Updating timestamp of handle 0x%x", __func__, _wapi_getpid (), handle->u.shared.offset);
-
-					InterlockedExchange ((gint32 *)&shared_data->timestamp, now);
-				} else if (handle->type == WAPI_HANDLE_FILE) {
-					struct _WapiHandle_file *file_handle = &handle->u.file;
-				
-					DEBUG ("%s: (%d) handle 0x%x is FILE", __func__, _wapi_getpid (), i * _WAPI_HANDLE_INITIAL_COUNT + k);
-				
-					g_assert (file_handle->share_info != NULL);
-
-					DEBUG ("%s: (%d) Inc refs on fileshare 0x%x", __func__, _wapi_getpid (), (file_handle->share_info - &_wapi_fileshare_layout->share_info[0]) / sizeof(struct _WapiFileShare));
-
-					InterlockedExchange ((gint32 *)&file_handle->share_info->timestamp, now);
-				}
-			}
-		}
-	}
-
-	thr_ret = mono_os_mutex_unlock (&scan_mutex);
-	g_assert (thr_ret == 0);
-	
-	thr_ret = _wapi_shm_sem_unlock (_WAPI_SHARED_SEM_FILESHARE);
-
-	_wapi_handle_unlock_shared_handles ();
-}
-

+ 0 - 8
mono/io-layer/io.c

@@ -1454,14 +1454,6 @@ static gboolean share_check (struct stat *statbuf, guint32 sharemode,
 			       share_info) == TRUE) {
 		return (TRUE);
 	}
-	
-	/* Still violating.  It's possible that a process crashed
-	 * while still holding a file handle, and that a non-mono
-	 * process has the file open.  (For example, C-c mcs while
-	 * editing a source file.)  As a last resort, run a handle
-	 * collection, which will remove stale share entries.
-	 */
-	_wapi_handle_collect ();
 
 	return(share_allows_open (statbuf, sharemode, fileaccess, share_info));
 }

+ 9 - 839
mono/io-layer/shared.c

@@ -7,97 +7,26 @@
  * (C) 2002-2006 Novell, Inc.
  */
 
-
 #include <config.h>
 #include <glib.h>
-#include <stdio.h>
-#include <fcntl.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <string.h>
-#include <unistd.h>
-
-#if defined(HAVE_SYS_SEM_H) && !(defined(__native_client__) && defined(__GLIBC__))
-#  include <sys/sem.h>
-#else
-#  define DISABLE_SHARED_HANDLES
-#endif
-
-#ifndef DISABLE_SHARED_HANDLES
-#  include <sys/mman.h>
-#  include <sys/ipc.h>
-#  ifdef HAVE_SYS_UTSNAME_H
-#    include <sys/utsname.h>
-#  endif
-#endif
 
-#include <mono/io-layer/wapi.h>
 #include <mono/io-layer/wapi-private.h>
 #include <mono/io-layer/shared.h>
-#include <mono/io-layer/handles-private.h>
+#include <mono/utils/mono-os-mutex.h>
 
 #define DEBUGLOG(...)
 //#define DEBUGLOG(...) g_message(__VA_ARGS__);
 
-// Semaphores used when no-shared-memory use is in use
-
 static mono_mutex_t noshm_sems[_WAPI_SHARED_SEM_COUNT];
 
-static gpointer wapi_storage [16];
-
-static void
-noshm_semaphores_init (void)
+void
+_wapi_shm_semaphores_init (void)
 {
 	int i;
-
 	for (i = 0; i < _WAPI_SHARED_SEM_COUNT; i++) 
 		mono_os_mutex_init (&noshm_sems [i]);
 }
 
-static int
-noshm_sem_lock (int sem)
-{
-	int ret;
-	
-	DEBUGLOG ("%s: locking nosem %d", __func__, sem);
-	
-	ret = mono_os_mutex_lock (&noshm_sems[sem]);
-	
-	return ret;
-}
-
-static int
-noshm_sem_trylock (int sem)
-{
-	int ret;
-	
-	DEBUGLOG ("%s: trying to lock nosem %d", __func__, sem);
-	
-	ret = mono_os_mutex_trylock (&noshm_sems[sem]);
-	
-	return ret;
-}
-
-static int
-noshm_sem_unlock (int sem)
-{
-	int ret;
-	
-	DEBUGLOG ("%s: unlocking nosem %d", __func__, sem);
-	
-	ret = mono_os_mutex_unlock (&noshm_sems[sem]);
-	
-	return ret;
-}
-
-#ifdef DISABLE_SHARED_HANDLES
-void
-_wapi_shm_semaphores_init (void)
-{
-	noshm_semaphores_init ();
-}
-
 void
 _wapi_shm_semaphores_remove (void)
 {
@@ -107,779 +36,20 @@ _wapi_shm_semaphores_remove (void)
 int
 _wapi_shm_sem_lock (int sem)
 {
-	return noshm_sem_lock (sem);
-}
-
-int
-_wapi_shm_sem_trylock (int sem)
-{
-	return noshm_sem_trylock (sem);
-}
-
-int
-_wapi_shm_sem_unlock (int sem)
-{
-	return noshm_sem_unlock (sem);
-}
-
-gpointer
-_wapi_shm_attach (_wapi_shm_t type)
-{
-	gpointer res;
-
-	switch(type) {
-	case WAPI_SHM_DATA:
-		res = g_malloc0 (sizeof(struct _WapiHandleSharedLayout));
-		break;
-	case WAPI_SHM_FILESHARE:
-		res = g_malloc0 (sizeof(struct _WapiFileShareLayout));
-		break;
-	default:
-		g_error ("Invalid type in _wapi_shm_attach ()");
-		return NULL;
-	}
-
-	wapi_storage [type] = res;
-	return res;
-}
-
-void
-_wapi_shm_detach (_wapi_shm_t type)
-{
-	g_free (wapi_storage [type]);
-}
-
-gboolean
-_wapi_shm_enabled_internal (void)
-{
-	return FALSE;
-}
-
-#else /* DISABLE_SHARED_HANDLES */
-
-/*
- * Use POSIX shared memory if possible, it is simpler, and it has the advantage that 
- * writes to the shared area does not need to be written to disk, avoiding spinning up 
- * the disk every x secs on laptops.
- */
-#ifdef HAVE_SHM_OPEN
-#define USE_SHM 1
-#endif
-
-static gboolean _wapi_shm_disabled = TRUE;
-
-static gchar *
-_wapi_shm_base_name (_wapi_shm_t type)
-{
-	gchar *name = NULL;
-	gchar machine_name[256];
-	const gchar *fake_name;
-	struct utsname ubuf;
-	int ret;
-	int len;
-	
-	ret = uname (&ubuf);
-	if (ret == -1) {
-		ubuf.machine[0] = '\0';
-		ubuf.sysname[0] = '\0';
-	} else {
-		g_strdelimit (ubuf.sysname, "/", '_');
-		g_strdelimit (ubuf.machine, "/", '_');
-	}
-
-	fake_name = g_getenv ("MONO_SHARED_HOSTNAME");
-	if (fake_name == NULL) {
-		if (gethostname(machine_name, sizeof(machine_name)) != 0)
-			machine_name[0] = '\0';
-	} else {
-		len = MIN (strlen (fake_name), sizeof (machine_name) - 1);
-		strncpy (machine_name, fake_name, len);
-		machine_name [len] = '\0';
-	}
-	
-	switch (type) {
-	case WAPI_SHM_DATA:
-		name = g_strdup_printf ("shared_data-%s-%s-%s-%d-%d-%d",
-					machine_name, ubuf.sysname,
-					ubuf.machine,
-					(int) sizeof(struct _WapiHandleShared),
-					_WAPI_HANDLE_VERSION, 0);
-		break;
-		
-	case WAPI_SHM_FILESHARE:
-		name = g_strdup_printf ("shared_fileshare-%s-%s-%s-%d-%d-%d",
-					machine_name, ubuf.sysname,
-					ubuf.machine,
-					(int) sizeof(struct _WapiFileShare),
-					_WAPI_HANDLE_VERSION, 0);
-		break;
-	}
-
-	return name;
-}
-
-#ifdef USE_SHM
-
-static gchar *_wapi_shm_shm_name (_wapi_shm_t type)
-{
-	char *base_name = _wapi_shm_base_name (type);
-
-	/* Also add the uid to avoid permission problems */
-	char *res = g_strdup_printf ("/mono-shared-%d-%s", getuid (), base_name);
-
-	g_free (base_name);
-
-	return res;
-}
-
-static int
-_wapi_shm_open (const char *filename, int size)
-{
-	int fd;
-
-	fd = shm_open (filename, O_CREAT|O_RDWR, S_IRUSR|S_IWUSR|S_IRGRP);
-	if (fd == -1)
-		/* Maybe /dev/shm is not mounted */
-		return -1;
-	if (ftruncate (fd, size) != 0) {
-		perror ("_wapi_shm_open (): ftruncate ()");
-		g_assert_not_reached ();
-	}
-
-	return fd;
-}
-
-#endif
-
-static gchar *
-_wapi_shm_file (_wapi_shm_t type)
-{
-	static gchar file[_POSIX_PATH_MAX];
-	gchar *name = NULL, *filename;
-	const gchar *wapi_dir;
-
-	name = _wapi_shm_base_name (type);
-
-	/* I don't know how nfs affects mmap.  If mmap() of files on
-	 * nfs mounts breaks, then there should be an option to set
-	 * the directory.
-	 */
-	wapi_dir = g_getenv ("MONO_SHARED_DIR");
-	if (wapi_dir == NULL) {
-		filename = g_build_filename (g_get_home_dir (), ".wapi", name,
-					     NULL);
-	} else {
-		filename = g_build_filename (wapi_dir, ".wapi", name, NULL);
-	}
-	g_free (name);
-
-	g_snprintf (file, _POSIX_PATH_MAX, "%s", filename);
-	g_free (filename);
-	
-	return file;
-}
-
-static int
-_wapi_shm_file_open (const gchar *filename, guint32 wanted_size)
-{
-	int fd;
-	struct stat statbuf;
-	int ret, tries = 0;
-	gboolean created = FALSE;
-	mode_t oldmask;
-	gchar *dir;
-		
-	/* No need to check if the dir already exists or check
-	 * mkdir() errors, because on any error the open() call will
-	 * report the problem.
-	 */
-	dir = g_path_get_dirname (filename);
-	mkdir (dir, 0755);
-	g_free (dir);
-
-try_again:
-	if (tries++ > 10) {
-		/* Just give up */
-		return (-1);
-	} else if (tries > 5) {
-		/* Break out of a loop */
-		unlink (filename);
-	}
-	
-	/* Make sure future processes can open the shared data files */
-	oldmask = umask (066);
-
-	/* No O_CREAT yet, because we need to initialise the file if
-	 * we have to create it.
-	 */
-	fd = open (filename, O_RDWR, 0600);
-	umask (oldmask);
-	
-	if (fd == -1 && errno == ENOENT) {
-		/* OK, its up to us to create it.  O_EXCL to avoid a
-		 * race condition where two processes can
-		 * simultaneously try and create the file
-		 */
-		oldmask = umask (066);
-		fd = open (filename, O_CREAT|O_EXCL|O_RDWR, 0600);
-		umask (oldmask);
-		
-		if (fd == -1 && errno == EEXIST) {
-			/* It's possible that the file was created in
-			 * between finding it didn't exist, and trying
-			 * to create it.  Just try opening it again
-			 */
-			goto try_again;
-		} else if (fd == -1) {
-			g_critical ("%s: shared file [%s] open error: %s",
-				    __func__, filename, g_strerror (errno));
-			return -1;
-		} else {
-			/* We created the file, so we need to expand
-			 * the file.
-			 *
-			 * (wanted_size-1, because we're about to
-			 * write the other byte to actually expand the
-			 * file.)
-			 */
-			if (lseek (fd, wanted_size-1, SEEK_SET) == -1) {
-				g_critical ("%s: shared file [%s] lseek error: %s", __func__, filename, g_strerror (errno));
-				close (fd);
-				unlink (filename);
-				return -1;
-			}
-			
-			do {
-				ret = write (fd, "", 1);
-			} while (ret == -1 && errno == EINTR);
-				
-			if (ret == -1) {
-				g_critical ("%s: shared file [%s] write error: %s", __func__, filename, g_strerror (errno));
-				close (fd);
-				unlink (filename);
-				return -1;
-			}
-			
-			created = TRUE;
-
-			/* The contents of the file is set to all
-			 * zero, because it is opened up with lseek,
-			 * so we don't need to do any more
-			 * initialisation here
-			 */
-		}
-	} else if (fd == -1) {
-		g_critical ("%s: shared file [%s] open error: %s", __func__,
-			    filename, g_strerror (errno));
-		return -1;
-	}
-	
-	/* Use stat to find the file size (instead of hard coding it)
-	 * because we can expand the file later if needed (for more
-	 * handles or scratch space.)
-	 */
-	if (fstat (fd, &statbuf) == -1) {
-		g_critical ("%s: fstat error: %s", __func__,
-			    g_strerror (errno));
-		if (created == TRUE) {
-			unlink (filename);
-		}
-		close (fd);
-		return -1;
-	}
-
-	if (statbuf.st_size < wanted_size) {
-		close (fd);
-		if (created == TRUE) {
-			g_critical ("%s: shared file [%s] is not big enough! (found %ld, need %d bytes)", __func__, filename, (long)statbuf.st_size, wanted_size);
-			unlink (filename);
-			return -1;
-		} else {
-			/* We didn't create it, so just try opening it again */
-			_wapi_handle_spin (100);
-			goto try_again;
-		}
-	}
-	
-	return fd;
-}
-
-gboolean
-_wapi_shm_enabled_internal (void)
-{
-	static gboolean env_checked;
-
-	if (!env_checked) {
-		if (g_getenv ("MONO_ENABLE_SHM"))
-			_wapi_shm_disabled = FALSE;
-		env_checked = TRUE;
-	}
-
-	return !_wapi_shm_disabled;
-}
-
-/*
- * _wapi_shm_attach:
- * @success: Was it a success
- *
- * Attach to the shared memory file or create it if it did not exist.
- * Returns the memory area the file was mmapped to.
- */
-gpointer
-_wapi_shm_attach (_wapi_shm_t type)
-{
-	gpointer shm_seg;
-	int fd;
-	struct stat statbuf;
-	gchar *filename = _wapi_shm_file (type), *shm_name;
-	guint32 size;
-	
-	switch(type) {
-	case WAPI_SHM_DATA:
-		size = sizeof(struct _WapiHandleSharedLayout);
-		break;
-		
-	case WAPI_SHM_FILESHARE:
-		size = sizeof(struct _WapiFileShareLayout);
-		break;
-	default:
-		g_error ("Invalid type in _wapi_shm_attach ()");
-		return NULL;
-	}
-
-	if (!_wapi_shm_enabled ()) {
-		wapi_storage [type] = g_malloc0 (size);
-		return wapi_storage [type];
-	}
-
-#ifdef USE_SHM
-	shm_name = _wapi_shm_shm_name (type);
-	fd = _wapi_shm_open (shm_name, size);
-	g_free (shm_name);
-#else
-	fd = -1;
-#endif
-
-	/* Fall back to files if POSIX shm fails (for example, because /dev/shm is not mounted */
-	if (fd == -1)
-		fd = _wapi_shm_file_open (filename, size);
-	if (fd == -1) {
-		g_critical ("%s: shared file [%s] open error", __func__,
-			    filename);
-		return NULL;
-	}
-
-	if (fstat (fd, &statbuf)==-1) {
-		g_critical ("%s: fstat error: %s", __func__,
-			    g_strerror (errno));
-		close (fd);
-		return NULL;
-	}
-	
-	shm_seg = mmap (NULL, statbuf.st_size, PROT_READ|PROT_WRITE,
-			MAP_SHARED, fd, 0);
-	if (shm_seg == MAP_FAILED) {
-		shm_seg = mmap (NULL, statbuf.st_size, PROT_READ|PROT_WRITE,
-			MAP_PRIVATE, fd, 0);
-		if (shm_seg == MAP_FAILED) {
-			g_critical ("%s: mmap error: %s", __func__, g_strerror (errno));
-			close (fd);
-			return NULL;
-		}
-	}
-		
-	close (fd);
-	return shm_seg;
-}
-
-void
-_wapi_shm_detach (_wapi_shm_t type)
-{
-	if (!_wapi_shm_enabled ())
-		g_free (wapi_storage [type]);
-}
-
-static void
-shm_semaphores_init (void)
-{
-	key_t key;
-	key_t oldkey;
-	int thr_ret;
-	struct _WapiHandleSharedLayout *tmp_shared;
-	gchar *ftmp;
-	gchar *filename;
-	
-	/*
-	 * Yet more barmy API - this union is a well-defined parameter
-	 * in a syscall, yet I still have to define it here as it
-	 * doesn't appear in a header
-	 */
-	union semun {
-		int val;
-		struct semid_ds *buf;
-		ushort *array;
-	} defs;
-	ushort def_vals[_WAPI_SHARED_SEM_COUNT];
-	int i;
-	int retries = 0;
-	
-	for (i = 0; i < _WAPI_SHARED_SEM_COUNT; i++) {
-		def_vals[i] = 1;
-	}
-
-	/*
-	 * Process count must start at '0' - the 1 for all the others
-	 * sets the semaphore to "unlocked"
-	 */
-	def_vals[_WAPI_SHARED_SEM_PROCESS_COUNT] = 0;
-	
-	defs.array = def_vals;
-	
-	/*
-	 *Temporarily attach the shared data so we can read the
-	 * semaphore key.  We release this mapping and attach again
-	 * after getting the semaphores to avoid a race condition
-	 * where a terminating process can delete the shared files
-	 * between a new process attaching the file and getting access
-	 * to the semaphores (which increments the process count,
-	 * preventing destruction of the shared data...)
-	 */
-	tmp_shared = _wapi_shm_attach (WAPI_SHM_DATA);
-	g_assert (tmp_shared != NULL);
-	
-#ifdef USE_SHM
-	ftmp=_wapi_shm_shm_name (WAPI_SHM_DATA);
-	filename = g_build_filename ("/dev/shm", ftmp, NULL);
-	g_assert (filename!=NULL);
-	key = ftok (filename, 'M');
-	g_free (ftmp);
-	g_free (filename);
-#else
-	key = ftok ( _wapi_shm_file (WAPI_SHM_DATA), 'M');
-#endif
-
-again:
-	retries++;
-	oldkey = tmp_shared->sem_key;
-
-	if (oldkey == 0) {
-		DEBUGLOG ("%s: Creating with new key (0x%x)", __func__, key);
-
-		/*
-		 * The while loop attempts to make some sense of the
-		 * bonkers 'think of a random number' method of
-		 * picking a key without collision with other
-		 * applications
-		 */
-		while ((_wapi_sem_id = semget (key, _WAPI_SHARED_SEM_COUNT,
-					       IPC_CREAT | IPC_EXCL | 0600)) == -1) {
-			if (errno == ENOMEM) {
-				g_error ("%s: semget error: %s", __func__,
-					    g_strerror (errno));
-			} else if (errno == ENOSPC) {
-				g_error ("%s: semget error: %s.  Try deleting some semaphores with ipcs and ipcrm\nor increase the maximum number of semaphore in the system.", __func__, g_strerror (errno));
-			} else if (errno != EEXIST) {
-				if (retries > 3)
-					g_warning ("%s: semget error: %s key 0x%x - trying again", __func__,
-							g_strerror (errno), key);
-			}
-			
-			key++;
-			DEBUGLOG ("%s: Got (%s), trying with new key (0x%x)", __func__, g_strerror (errno), key);
-		}
-		/*
-		 * Got a semaphore array, so initialise it and install
-		 * the key into the shared memory
-		 */
-		
-		if (semctl (_wapi_sem_id, 0, SETALL, defs) == -1) {
-			if (retries > 3)
-				g_warning ("%s: semctl init error: %s - trying again", __func__, g_strerror (errno));
-
-			/*
-			 * Something went horribly wrong, so try
-			 * getting a new set from scratch
-			 */
-			semctl (_wapi_sem_id, 0, IPC_RMID);
-			goto again;
-		}
-
-		if (InterlockedCompareExchange (&tmp_shared->sem_key,
-						key, 0) != 0) {
-			/*
-			 * Someone else created one and installed the
-			 * key while we were working, so delete the
-			 * array we created and fall through to the
-			 * 'key already known' case.
-			 */
-			semctl (_wapi_sem_id, 0, IPC_RMID);
-			oldkey = tmp_shared->sem_key;
-		} else {
-			/*
-			 * We've installed this semaphore set's key into
-			 * the shared memory
-			 */
-			goto done;
-		}
-	}
-	
-	DEBUGLOG ("%s: Trying with old key 0x%x", __func__, oldkey);
-
-	_wapi_sem_id = semget (oldkey, _WAPI_SHARED_SEM_COUNT, 0600);
-	if (_wapi_sem_id == -1) {
-		if (retries > 3)
-			g_warning ("%s: semget error opening old key 0x%x (%s) - trying again",
-					__func__, oldkey,g_strerror (errno));
-
-		/*
-		 * Someone must have deleted the semaphore set, so
-		 * blow away the bad key and try again
-		 */
-		InterlockedCompareExchange (&tmp_shared->sem_key, 0, oldkey);
-		
-		goto again;
-	}
-
-  done:
-	/* Increment the usage count of this semaphore set */
-	thr_ret = _wapi_shm_sem_lock (_WAPI_SHARED_SEM_PROCESS_COUNT_LOCK);
-	g_assert (thr_ret == 0);
-	
-	DEBUGLOG ("%s: Incrementing the process count (%d)", __func__, _wapi_getpid ());
-
-	/*
-	 * We only ever _unlock_ this semaphore, letting the kernel
-	 * restore (ie decrement) this unlock when this process exits.
-	 * We lock another semaphore around it so we can serialise
-	 * access when we're testing the value of this semaphore when
-	 * we exit cleanly, so we can delete the whole semaphore set.
-	 */
-	_wapi_shm_sem_unlock (_WAPI_SHARED_SEM_PROCESS_COUNT);
-
-	DEBUGLOG ("%s: Process count is now %d (%d)", __func__, semctl (_wapi_sem_id, _WAPI_SHARED_SEM_PROCESS_COUNT, GETVAL), _wapi_getpid ());
-	
-	_wapi_shm_sem_unlock (_WAPI_SHARED_SEM_PROCESS_COUNT_LOCK);
-
-	if (_wapi_shm_disabled)
-		g_free (tmp_shared);
-	else
-		munmap (tmp_shared, sizeof(struct _WapiHandleSharedLayout));
-}
-
-static void
-shm_semaphores_remove (void)
-{
-	int thr_ret;
-	int proc_count;
-	gchar *shm_name;
-	
-	DEBUGLOG ("%s: Checking process count (%d)", __func__, _wapi_getpid ());
-	
-	thr_ret = _wapi_shm_sem_lock (_WAPI_SHARED_SEM_PROCESS_COUNT_LOCK);
-	g_assert (thr_ret == 0);
-	
-	proc_count = semctl (_wapi_sem_id, _WAPI_SHARED_SEM_PROCESS_COUNT,
-			     GETVAL);
-
-	g_assert (proc_count > 0);
-	if (proc_count == 1) {
-		/*
-		 * Just us, so blow away the semaphores and the shared
-		 * files
-		 */
-		DEBUGLOG ("%s: Removing semaphores! (%d)", __func__, _wapi_getpid ());
-
-		semctl (_wapi_sem_id, 0, IPC_RMID);
-#ifdef USE_SHM
-		shm_name = _wapi_shm_shm_name (WAPI_SHM_DATA);
-		shm_unlink (shm_name);
-		g_free (shm_name);
-
-		shm_name = _wapi_shm_shm_name (WAPI_SHM_FILESHARE);
-		shm_unlink (shm_name);
-		g_free (shm_name);
-#endif
-		unlink (_wapi_shm_file (WAPI_SHM_DATA));
-		unlink (_wapi_shm_file (WAPI_SHM_FILESHARE));
-	} else {
-		/*
-		 * "else" clause, because there's no point unlocking
-		 * the semaphore if we've just blown it away...
-		 */
-		_wapi_shm_sem_unlock (_WAPI_SHARED_SEM_PROCESS_COUNT_LOCK);
-	}
-}
-
-static int
-shm_sem_lock (int sem)
-{
-	struct sembuf ops;
-	int ret;
-	
-	DEBUGLOG ("%s: locking sem %d", __func__, sem);
-
-	ops.sem_num = sem;
-	ops.sem_op = -1;
-	ops.sem_flg = SEM_UNDO;
-	
-  retry:
-	do {
-		ret = semop (_wapi_sem_id, &ops, 1);
-	} while (ret == -1 && errno == EINTR);
-
-	if (ret == -1) {
-		/*
-		 * EINVAL covers the case when the semaphore was
-		 * deleted before we started the semop
-		 */
-		if (errno == EIDRM || errno == EINVAL) {
-			/*
-			 * Someone blew away this semaphore set, so
-			 * get a new one and try again
-			 */
-			DEBUGLOG ("%s: Reinitialising the semaphores!", __func__);
-
-			_wapi_shm_semaphores_init ();
-			goto retry;
-		}
-		
-		/* Turn this into a pthreads-style return value */
-		ret = errno;
-	}
-	
-	DEBUGLOG ("%s: returning %d (%s)", __func__, ret, g_strerror (ret));
-	
-	return ret;
-}
-
-static int
-shm_sem_trylock (int sem)
-{
-	struct sembuf ops;
-	int ret;
-	
-	DEBUGLOG ("%s: trying to lock sem %d", __func__, sem);
-	
-	ops.sem_num = sem;
-	ops.sem_op = -1;
-	ops.sem_flg = IPC_NOWAIT | SEM_UNDO;
-	
-  retry:
-	do {
-		ret = semop (_wapi_sem_id, &ops, 1);
-	} while (ret == -1 && errno == EINTR);
-
-	if (ret == -1) {
-		/*
-		 * EINVAL covers the case when the semaphore was
-		 * deleted before we started the semop
-		 */
-		if (errno == EIDRM || errno == EINVAL) {
-			/*
-			 * Someone blew away this semaphore set, so
-			 * get a new one and try again
-			 */
-			DEBUGLOG ("%s: Reinitialising the semaphores!", __func__);
-
-			_wapi_shm_semaphores_init ();
-			goto retry;
-		}
-		
-		/* Turn this into a pthreads-style return value */
-		ret = errno;
-	}
-	
-	if (ret == EAGAIN) {
-		/* But pthreads uses this code instead */
-		ret = EBUSY;
-	}
-	
-	DEBUGLOG ("%s: returning %d (%s)", __func__, ret, g_strerror (ret));
-	
-	return ret;
-}
-
-static int
-shm_sem_unlock (int sem)
-{
-	struct sembuf ops;
-	int ret;
-	
-	DEBUGLOG ("%s: unlocking sem %d", __func__, sem);
-	
-	ops.sem_num = sem;
-	ops.sem_op = 1;
-	ops.sem_flg = SEM_UNDO;
-	
-  retry:
-	do {
-		ret = semop (_wapi_sem_id, &ops, 1);
-	} while (ret == -1 && errno == EINTR);
-
-	if (ret == -1) {
-		/* EINVAL covers the case when the semaphore was
-		 * deleted before we started the semop
-		 */
-		if (errno == EIDRM || errno == EINVAL) {
-			/* Someone blew away this semaphore set, so
-			 * get a new one and try again (we can't just
-			 * assume that the semaphore is now unlocked)
-			 */
-			DEBUGLOG ("%s: Reinitialising the semaphores!", __func__);
-
-			_wapi_shm_semaphores_init ();
-			goto retry;
-		}
-		
-		/* Turn this into a pthreads-style return value */
-		ret = errno;
-	}
-	
-	DEBUGLOG ("%s: returning %d (%s)", __func__, ret, g_strerror (ret));
-
-	return ret;
-}
-
-void
-_wapi_shm_semaphores_init (void)
-{
-	if (!_wapi_shm_enabled ())
-		noshm_semaphores_init ();
-	else
-		shm_semaphores_init ();
-}
-
-void
-_wapi_shm_semaphores_remove (void)
-{
-	if (!_wapi_shm_disabled) 
-		shm_semaphores_remove ();
-}
-
-int
-_wapi_shm_sem_lock (int sem)
-{
-	if (_wapi_shm_disabled) 
-		return noshm_sem_lock (sem);
-	else
-		return shm_sem_lock (sem);
+	DEBUGLOG ("%s: locking nosem %d", __func__, sem);
+	return mono_os_mutex_lock (&noshm_sems[sem]);
 }
 
 int
 _wapi_shm_sem_trylock (int sem)
 {
-	if (_wapi_shm_disabled) 
-		return noshm_sem_trylock (sem);
-	else 
-		return shm_sem_trylock (sem);
+	DEBUGLOG ("%s: trying to lock nosem %d", __func__, sem);
+	return mono_os_mutex_trylock (&noshm_sems[sem]);
 }
 
 int
 _wapi_shm_sem_unlock (int sem)
 {
-	if (_wapi_shm_disabled) 
-		return noshm_sem_unlock (sem);
-	else 
-		return shm_sem_unlock (sem);
+	DEBUGLOG ("%s: unlocking nosem %d", __func__, sem);
+	return mono_os_mutex_unlock (&noshm_sems[sem]);
 }
-#endif /* !DISABLE_SHARED_HANDLES */

+ 0 - 20
mono/io-layer/shared.h

@@ -10,30 +10,10 @@
 #ifndef _WAPI_SHARED_H_
 #define _WAPI_SHARED_H_
 
-#include <mono/io-layer/wapi-private.h>
-
-typedef enum {
-	WAPI_SHM_DATA,
-	WAPI_SHM_FILESHARE
-} _wapi_shm_t;
-
-extern gpointer _wapi_shm_attach (_wapi_shm_t type);
-extern void _wapi_shm_detach (_wapi_shm_t type);
-extern gboolean _wapi_shm_enabled_internal (void);
 extern void _wapi_shm_semaphores_init (void);
 extern void _wapi_shm_semaphores_remove (void);
 extern int _wapi_shm_sem_lock (int sem);
 extern int _wapi_shm_sem_trylock (int sem);
 extern int _wapi_shm_sem_unlock (int sem);
 
-static inline gboolean
-_wapi_shm_enabled (void)
-{
-#ifdef DISABLE_SHARED_HANDLES
-	return FALSE;
-#else
-	return _wapi_shm_enabled_internal ();
-#endif
-}
-
 #endif /* _WAPI_SHARED_H_ */

+ 1 - 13
mono/io-layer/wapi-private.h

@@ -14,6 +14,7 @@
 #include <glib.h>
 #include <sys/stat.h>
 
+#include <mono/io-layer/wapi.h>
 #include <mono/io-layer/handles.h>
 #include <mono/io-layer/io.h>
 
@@ -175,8 +176,6 @@ struct _WapiHandleSharedLayout
 
 typedef struct _WapiHandleSharedLayout _WapiHandleSharedLayout;
 
-#define _WAPI_FILESHARE_SIZE 102400
-
 struct _WapiFileShare
 {
 #ifdef WAPI_FILE_SHARE_PLATFORM_EXTRA_DATA
@@ -193,17 +192,6 @@ struct _WapiFileShare
 
 typedef struct _WapiFileShare _WapiFileShare;
 
-struct _WapiFileShareLayout
-{
-	guint32 hwm;
-	
-	struct _WapiFileShare share_info[_WAPI_FILESHARE_SIZE];
-};
-
-typedef struct _WapiFileShareLayout _WapiFileShareLayout;
-
-
-
 #define _WAPI_HANDLE_INVALID (gpointer)-1
 
 #endif /* _WAPI_PRIVATE_H_ */

+ 0 - 3
winconfig.h

@@ -67,9 +67,6 @@
 /* Disable reflection emit support */
 /* #undef DISABLE_REFLECTION_EMIT */
 
-/* Disable inter-process shared handles */
-/* #undef DISABLE_SHARED_HANDLES */
-
 /* Disable advanced SSA JIT optimizations */
 /* #undef DISABLE_SSA */