#define USE_WIN32_API 1
#endif
+#ifdef HAVE_UNISTD_H
#include <unistd.h>
+#endif
#include <errno.h>
#ifdef USE_WIN32_API
#include <winsock2.h>
static GHashTable *mmap_map = NULL;
static size_t alignment = 0;
+#define mono_mmap_lock() EnterCriticalSection (&mmap_mutex)
+#define mono_mmap_unlock() LeaveCriticalSection (&mmap_mutex)
static CRITICAL_SECTION mmap_mutex;
static gboolean make_unreadable = FALSE;
static guint32 n_pagefaults = 0;
mmap_map = g_hash_table_new (NULL, NULL);
}
+void
+mono_raw_buffer_cleanup (void)
+{
+ g_hash_table_destroy (mmap_map);
+
+ DeleteCriticalSection (&mmap_mutex);
+}
+
static void *
mono_raw_buffer_load_mmap (int fd, int is_writable, guint32 base, size_t size)
{
return 0;
}
- EnterCriticalSection (&mmap_mutex);
+ mono_mmap_lock ();
g_hash_table_insert (mmap_map, ptr, GINT_TO_POINTER (mapping));
- LeaveCriticalSection (&mmap_mutex);
+ mono_mmap_unlock ();
return ((char *)ptr) + (base - start);
* 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));
+ mprotect (ptr, end - start, prot | PROT_EXEC);
if (make_unreadable) {
int res = mprotect (ptr, end - start, 0);
g_assert (res == 0);
}
- EnterCriticalSection (&mmap_mutex);
+ mono_mmap_lock ();
g_hash_table_insert (mmap_map, ptr, GINT_TO_POINTER (size));
- LeaveCriticalSection (&mmap_mutex);
+ mono_mmap_unlock ();
return ((char *)ptr) + (base - start);
#endif
{
int value;
- EnterCriticalSection (&mmap_mutex);
+ mono_mmap_lock ();
value = GPOINTER_TO_INT (g_hash_table_lookup (mmap_map, base));
- LeaveCriticalSection (&mmap_mutex);
+ mono_mmap_unlock ();
#ifdef USE_WIN32_API
UnmapViewOfFile (base);
mmap_base = (gpointer)(ROUND_DOWN ((UINTPTR_TYPE) (buffer), alignment));
- EnterCriticalSection (&mmap_mutex);
+ mono_mmap_lock ();
exists = g_hash_table_lookup (mmap_map, mmap_base) != NULL;
- LeaveCriticalSection (&mmap_mutex);
+ mono_mmap_unlock ();
if (exists)
mono_raw_buffer_update_mmap (mmap_base, size);
}
data.found = FALSE;
data.ptr = ptr;
- EnterCriticalSection (&mmap_mutex);
+ mono_mmap_lock ();
g_hash_table_foreach (mmap_map, (GHFunc)find_map, &data);
- LeaveCriticalSection (&mmap_mutex);
+ mono_mmap_unlock ();
return data.found;
}
guint8* start = (guint8*)ROUND_DOWN (((gssize)ptr), alignment);
int res;
- EnterCriticalSection (&mmap_mutex);
+ mono_mmap_lock ();
res = mprotect (start, alignment, PROT_READ);
g_assert (res == 0);
n_pagefaults ++;
- LeaveCriticalSection (&mmap_mutex);
+ mono_mmap_unlock ();
#endif
}