2004-09-09 Martin Baulig <martin@ximian.com>
[mono.git] / mono / metadata / rawbuffer.c
index be7fc2a7172b102c8e1262cbed669b8210f52687..4ecd91abb7d910e6c11553e9ffc41e45a8147733 100644 (file)
@@ -12,6 +12,7 @@
 #endif
 
 #include <unistd.h>
+#include <errno.h>
 #ifdef USE_WIN32_API
 #include <windows.h>
 #include <io.h>
@@ -80,7 +81,7 @@ mono_raw_buffer_init (void)
 
        get_alignment ();
 
-       mmap_map = g_hash_table_new (g_direct_hash, g_direct_equal);
+       mmap_map = g_hash_table_new (NULL, NULL);
 }
 
 static void *
@@ -146,6 +147,16 @@ mono_raw_buffer_load_mmap (int fd, int is_writable, guint32 base, size_t size)
 
        if (ptr == (void *) -1)
                return 0;
+
+       /* 
+        * This seems to prevent segmentation faults on Fedora Linux, no
+        * idea why :). See
+        * http://bugzilla.ximian.com/show_bug.cgi?id=49499
+        * for more info.
+        */
+       if (mprotect (ptr, end - start, prot | PROT_EXEC) != 0)
+               g_warning (G_GNUC_PRETTY_FUNCTION
+                                  ": mprotect failed: %s", g_strerror (errno));
        
        EnterCriticalSection (&mmap_mutex);
        g_hash_table_insert (mmap_map, ptr, GINT_TO_POINTER (size));