X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Futils%2Fmono-mmap.c;h=799506684adf8a2c7a44def47e2e8fe33bcd7051;hb=adb9681393a8dfec2ca9c2e8c5a4ed72d663878d;hp=fe8a98079f8fee5a5c54edb850b21f161c7ed6d5;hpb=0da40ef41b44c5c44e2b8a47f8e6206dccc93926;p=mono.git diff --git a/mono/utils/mono-mmap.c b/mono/utils/mono-mmap.c index fe8a98079f8..799506684ad 100644 --- a/mono/utils/mono-mmap.c +++ b/mono/utils/mono-mmap.c @@ -20,15 +20,18 @@ #if HAVE_SYS_MMAN_H #include #endif +#ifdef HAVE_SIGNAL_H +#include +#endif #include #include #include #include -#include #include #endif #include "mono-mmap.h" +#include "mono-mmap-internal.h" #include "mono-proclib.h" #ifndef MAP_ANONYMOUS @@ -65,8 +68,8 @@ malloc_shared_area (int pid) static char* aligned_address (char *mem, size_t size, size_t alignment) { - char *aligned = (char*)((gulong)(mem + (alignment - 1)) & ~(alignment - 1)); - g_assert (aligned >= mem && aligned + size <= mem + size + alignment && !((gulong)aligned & (alignment - 1))); + char *aligned = (char*)((size_t)(mem + (alignment - 1)) & ~(alignment - 1)); + g_assert (aligned >= mem && aligned + size <= mem + size + alignment && !((size_t)aligned & (alignment - 1))); return aligned; } @@ -308,13 +311,13 @@ mono_valloc (void *addr, size_t length, int flags) mflags |= MAP_PRIVATE; ptr = mmap (addr, length, prot, mflags, -1, 0); - if (ptr == (void*)-1) { + if (ptr == MAP_FAILED) { int fd = open ("/dev/zero", O_RDONLY); if (fd != -1) { ptr = mmap (addr, length, prot, mflags, fd, 0); close (fd); } - if (ptr == (void*)-1) + if (ptr == MAP_FAILED) return NULL; } return ptr; @@ -368,7 +371,7 @@ mono_file_map (size_t length, int flags, int fd, guint64 offset, void **ret_hand mflags |= MAP_32BIT; ptr = mmap (0, length, prot, mflags, fd, offset); - if (ptr == (void*)-1) + if (ptr == MAP_FAILED) return NULL; *ret_handle = (void*)length; return ptr; @@ -481,8 +484,11 @@ mono_mprotect (void *addr, size_t length, int flags) } return 0; } + #endif // HAVE_MMAP +#if defined(HAVE_SHM_OPEN) && !defined (DISABLE_SHARED_PERFCOUNTERS) + static int use_shared_area; static gboolean @@ -497,8 +503,6 @@ shared_area_disabled (void) return use_shared_area == -1; } -#if defined(HAVE_SHM_OPEN) && !defined (DISABLE_SHARED_PERFCOUNTERS) - static int mono_shared_area_instances_slow (void **array, int count, gboolean cleanup) { @@ -607,7 +611,7 @@ mono_shared_area (void) header->stats_start = sizeof (SAreaHeader); header->stats_end = sizeof (SAreaHeader); - atexit (mono_shared_area_remove); + mono_atexit (mono_shared_area_remove); return res; } @@ -728,3 +732,35 @@ mono_valloc_aligned (size_t size, size_t alignment, int flags) return aligned; } #endif + +int +mono_pages_not_faulted (void *addr, size_t size) +{ +#ifdef HAVE_MINCORE + int i; + gint64 count; + int pagesize = mono_pagesize (); + int npages = (size + pagesize - 1) / pagesize; + char *faulted = g_malloc0 (sizeof (char*) * npages); + + /* + * We cast `faulted` to void* because Linux wants an unsigned + * char* while BSD wants a char*. + */ + if (mincore (addr, size, (void*)faulted) != 0) { + count = -1; + } else { + count = 0; + for (i = 0; i < npages; ++i) { + if (faulted [i] != 0) + ++count; + } + } + + g_free (faulted); + + return count; +#else + return -1; +#endif +}