#if HAVE_SYS_MMAN_H
#include <sys/mman.h>
#endif
+#ifdef HAVE_SIGNAL_H
+#include <signal.h>
+#endif
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
-#include <signal.h>
#include <errno.h>
#endif
#include "mono-mmap.h"
+#include "mono-mmap-internal.h"
#include "mono-proclib.h"
#ifndef MAP_ANONYMOUS
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;
}
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;
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;
}
return 0;
}
+
#endif // HAVE_MMAP
+#if defined(HAVE_SHM_OPEN) && !defined (DISABLE_SHARED_PERFCOUNTERS)
+
static int use_shared_area;
static gboolean
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)
{
header->stats_start = sizeof (SAreaHeader);
header->stats_end = sizeof (SAreaHeader);
- atexit (mono_shared_area_remove);
+ mono_atexit (mono_shared_area_remove);
return res;
}
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
+}