Merge pull request #1304 from slluis/mac-proxy-autoconfig
[mono.git] / mono / io-layer / handles.c
index fcaa56df7f2ab3b43295363526a5fbf6ca003524..8cd74e9ff36abdf753f41f58f31f739c9d7ea1e6 100644 (file)
@@ -37,7 +37,6 @@
 #include <mono/io-layer/shared.h>
 #include <mono/io-layer/collection.h>
 #include <mono/io-layer/process-private.h>
-#include <mono/io-layer/critical-section-private.h>
 
 #include <mono/utils/mono-mutex.h>
 #undef DEBUG_REFS
@@ -131,10 +130,10 @@ struct _WapiFileShareLayout *_wapi_fileshare_layout = NULL;
  * 4MB array.
  */
 static GHashTable *file_share_hash;
-static CRITICAL_SECTION file_share_hash_mutex;
+static mono_mutex_t file_share_hash_mutex;
 
-#define file_share_hash_lock() EnterCriticalSection (&file_share_hash_mutex)
-#define file_share_hash_unlock() LeaveCriticalSection (&file_share_hash_mutex)
+#define file_share_hash_lock() mono_mutex_lock (&file_share_hash_mutex)
+#define file_share_hash_unlock() mono_mutex_unlock (&file_share_hash_mutex)
 
 guint32 _wapi_fd_reserve;
 
@@ -207,7 +206,7 @@ static void handle_cleanup (void)
 
        if (file_share_hash) {
                g_hash_table_destroy (file_share_hash);
-               DeleteCriticalSection (&file_share_hash_mutex);
+               mono_mutex_destroy (&file_share_hash_mutex);
        }
 
        for (i = 0; i < _WAPI_PRIVATE_MAX_SLOTS; ++i)
@@ -285,6 +284,7 @@ wapi_cleanup (void)
 
        _wapi_error_cleanup ();
        _wapi_thread_cleanup ();
+       wapi_processes_cleanup ();
 }
 
 static void _wapi_handle_init_shared (struct _WapiHandleShared *handle,
@@ -303,10 +303,57 @@ static void _wapi_handle_init_shared (struct _WapiHandleShared *handle,
        }
 }
 
+static size_t _wapi_handle_struct_size (WapiHandleType type)
+{
+       size_t type_size;
+
+       switch (type) {
+               case WAPI_HANDLE_FILE: case WAPI_HANDLE_CONSOLE: case WAPI_HANDLE_PIPE:
+                       type_size = sizeof (struct _WapiHandle_file);
+                       break;
+               case WAPI_HANDLE_THREAD:
+                       type_size = sizeof (struct _WapiHandle_thread);
+                       break;
+               case WAPI_HANDLE_SEM:
+                       type_size = sizeof (struct _WapiHandle_sem);
+                       break;
+               case WAPI_HANDLE_MUTEX:
+                       type_size = sizeof (struct _WapiHandle_mutex);
+                       break;
+               case WAPI_HANDLE_EVENT:
+                       type_size = sizeof (struct _WapiHandle_event);
+                       break;
+               case WAPI_HANDLE_SOCKET:
+                       type_size = sizeof (struct _WapiHandle_socket);
+                       break;
+               case WAPI_HANDLE_FIND:
+                       type_size = sizeof (struct _WapiHandle_find);
+                       break;
+               case WAPI_HANDLE_PROCESS:
+                       type_size = sizeof (struct _WapiHandle_process);
+                       break;
+               case WAPI_HANDLE_NAMEDMUTEX:
+                       type_size = sizeof (struct _WapiHandle_namedmutex);
+                       break;
+               case WAPI_HANDLE_NAMEDSEM:
+                       type_size = sizeof (struct _WapiHandle_namedsem);
+                       break;
+               case WAPI_HANDLE_NAMEDEVENT:
+                       type_size = sizeof (struct _WapiHandle_namedevent);
+                       break;
+
+               default:
+                       g_error ("Unknown WapiHandleType: %d\n", type);
+       }
+
+       return type_size;
+}
+
 static void _wapi_handle_init (struct _WapiHandleUnshared *handle,
                               WapiHandleType type, gpointer handle_specific)
 {
        int thr_ret;
+       int type_size;
        
        g_assert (_wapi_has_shut_down == FALSE);
        
@@ -322,8 +369,9 @@ static void _wapi_handle_init (struct _WapiHandleUnshared *handle,
                g_assert (thr_ret == 0);
 
                if (handle_specific != NULL) {
+                       type_size = _wapi_handle_struct_size (type);
                        memcpy (&handle->u, handle_specific,
-                               sizeof (handle->u));
+                               type_size);
                }
        }
 }
@@ -1615,7 +1663,7 @@ gboolean _wapi_handle_get_or_set_share (dev_t device, ino_t inode,
                 */
                if (!file_share_hash) {
                        file_share_hash = g_hash_table_new_full (wapi_share_info_hash, wapi_share_info_equal, NULL, g_free);
-                       InitializeCriticalSection (&file_share_hash_mutex);
+                       mono_mutex_init_recursive (&file_share_hash_mutex);
                }
                        
                tmp.device = device;