image->raw_buffer_used = TRUE;
image->raw_data_len = mono_file_map_size (filed);
image->raw_data = mono_file_map (image->raw_data_len, MONO_MMAP_READ|MONO_MMAP_PRIVATE, mono_file_map_fd (filed), 0, &image->raw_data_handle);
+#if defined(HAVE_MMAP) && !defined (HOST_WIN32)
+ if (!image->raw_data) {
+ image->fileio_used = TRUE;
+ image->raw_data = mono_file_map_fileio (image->raw_data_len, MONO_MMAP_READ|MONO_MMAP_PRIVATE, mono_file_map_fd (filed), 0, &image->raw_data_handle);
+ }
+#endif
if (!image->raw_data) {
mono_file_map_close (filed);
g_free (image);
#endif
if (image->raw_buffer_used) {
- if (image->raw_data != NULL)
- mono_file_unmap (image->raw_data, image->raw_data_handle);
+ if (image->raw_data != NULL) {
+#ifndef HOST_WIN32
+ if (image->fileio_used)
+ mono_file_unmap_fileio (image->raw_data, image->raw_data_handle);
+ else
+#endif
+ mono_file_unmap (image->raw_data, image->raw_data_handle);
+ }
}
if (image->raw_data_allocated) {
guint32 raw_data_len;
guint8 raw_buffer_used : 1;
guint8 raw_data_allocated : 1;
+ guint8 fileio_used : 1;
#ifdef HOST_WIN32
/* Module was loaded using LoadLibrary. */
return fclose ((FILE*)fmap);
}
-#if !defined(HAVE_MMAP) && !defined (HOST_WIN32)
+#if !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 (size_t length, int flags, int fd, guint64 offset, void **ret_handle)
+mono_file_map_fileio (size_t length, int flags, int fd, guint64 offset, void **ret_handle)
{
guint64 cur_offset;
size_t bytes_read;
return NULL;
cur_offset = lseek (fd, 0, SEEK_CUR);
if (lseek (fd, offset, SEEK_SET) != offset) {
- free (ptr);
+ (*release_fn) (ptr);
return NULL;
}
bytes_read = read (fd, ptr, length);
}
int
-mono_file_unmap (void *addr, void *handle)
+mono_file_unmap_fileio (void *addr, void *handle)
{
(*release_fn) (addr);
return 0;
}
+#if !defined(HAVE_MMAP)
+void *
+mono_file_map (size_t length, int flags, int fd, guint64 offset, void **ret_handle)
+{
+ return mono_file_map_fileio (length, flags, fd, offset, ret_handle);
+}
+
+int
+mono_file_unmap (void *addr, void *handle)
+{
+ return mono_file_unmap_fileio(addr, handle);
+}
+#endif
#endif
int mono_vfree (void *addr, size_t length);
void* mono_file_map (size_t length, int flags, int fd, guint64 offset, void **ret_handle);
int mono_file_unmap (void *addr, void *handle);
+#ifndef HOST_WIN32
+void* mono_file_map_fileio (size_t length, int flags, int fd, guint64 offset, void **ret_handle);
+int mono_file_unmap_fileio (void *addr, void *handle);
+#endif
int mono_mprotect (void *addr, size_t length, int flags);
void* mono_shared_area (void);