Move MonoContext defines to mono-context.h on arm.
[mono.git] / mono / utils / mono-filemap.c
index c6fe0751c64c60e665c7fda4152ae3ca377ee863..5d73097ac56382d17482a066258e1221a0c0dc2b 100644 (file)
@@ -14,7 +14,9 @@
 #endif
 #include <fcntl.h>
 #include <string.h>
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
+#endif
 #include <stdlib.h>
 #include <stdio.h>
 
@@ -47,13 +49,24 @@ mono_file_map_close (MonoFileMap *fmap)
        return fclose ((FILE*)fmap);
 }
 
-#if !defined(HAVE_MMAP) && !defined (PLATFORM_WIN32)
+#if !defined(HAVE_MMAP) && !defined (HOST_WIN32)
+
+static mono_file_map_alloc_fn alloc_fn = (mono_file_map_alloc_fn) malloc;
+static mono_file_map_release_fn release_fn = (mono_file_map_release_fn) free;
+
+void
+mono_file_map_set_allocator (mono_file_map_alloc_fn alloc, mono_file_map_release_fn release)
+{
+       alloc_fn = alloc == NULL     ? (mono_file_map_alloc_fn) malloc : alloc;
+       release_fn = release == NULL ? (mono_file_map_release_fn) free : release;
+}
+
 void *
 mono_file_map (size_t length, int flags, int fd, guint64 offset, void **ret_handle)
 {
        guint64 cur_offset;
        size_t bytes_read;
-       void *ptr = malloc (length);
+       void *ptr = (*alloc_fn) (length);
        if (!ptr)
                return NULL;
        cur_offset = lseek (fd, 0, SEEK_CUR);
@@ -66,4 +79,11 @@ mono_file_map (size_t length, int flags, int fd, guint64 offset, void **ret_hand
        *ret_handle = NULL;
        return ptr;
 }
+
+int
+mono_file_unmap (void *addr, void *handle)
+{
+       (*release_fn) (addr);
+       return 0;
+}
 #endif