Skip to content

Commit

Permalink
Backport to the branch
Browse files Browse the repository at this point in the history
svn path=/branches/wii/mono/; revision=131032
  • Loading branch information
migueldeicaza committed Apr 3, 2009
1 parent f5d8d3e commit 056c053
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
6 changes: 6 additions & 0 deletions mono/utils/ChangeLog
@@ -1,3 +1,9 @@
2009-04-03 Miguel de Icaza <miguel@novell.com>

* mono-filemap.c: Move mono_file_unmap for the not-mmap case to
the mono-filemap.c file so it can be plugged in platform-specific
code as well.

2009-02-16 Mark Probst <mark.probst@gmail.com>

Contributed under the terms of the MIT/X11 license by Steven
Expand Down
20 changes: 19 additions & 1 deletion mono/utils/mono-filemap.c
Expand Up @@ -50,12 +50,23 @@ mono_file_map_close (MonoFileMap *fmap)
}

#if !defined(HAVE_MMAP) && !defined (PLATFORM_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);
Expand All @@ -68,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
7 changes: 0 additions & 7 deletions mono/utils/mono-mmap.c
Expand Up @@ -409,13 +409,6 @@ mono_vfree (void *addr, size_t length)
return 0;
}

int
mono_file_unmap (void *addr, void *handle)
{
free (addr);
return 0;
}

int
mono_mprotect (void *addr, size_t length, int flags)
{
Expand Down
10 changes: 10 additions & 0 deletions mono/utils/mono-mmap.h
Expand Up @@ -42,5 +42,15 @@ void* mono_shared_area_for_pid (void *pid);
void mono_shared_area_unload (void *area);
int mono_shared_area_instances (void **array, int count);

/*
* On systems where we have to load code into memory instead of mmaping
* we allow for the allocator to be set. This function is only
* defined on those platforms.
*/
typedef void *(*mono_file_map_alloc_fn) (size_t length);
typedef void (*mono_file_map_release_fn) (void *addr);

void mono_file_map_set_allocator (mono_file_map_alloc_fn alloc, mono_file_map_release_fn release);

#endif /* __MONO_UTILS_MMAP_H__ */

0 comments on commit 056c053

Please sign in to comment.