#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
return 0;
}
-int
-mono_pages_not_faulted (void *addr, size_t length)
-{
- return -1;
-}
-
#else
#if defined(HAVE_MMAP)
}
#endif // __native_client__
-int
-mono_pages_not_faulted (void *addr, size_t size)
-{
- int i;
- gint64 count;
- int pagesize = mono_pagesize ();
- int npages = (size + pagesize - 1) / pagesize;
- char *faulted = g_malloc0 (sizeof (char*) * npages);
-
- if (mincore (addr, size, faulted) != 0) {
- count = -1;
- } else {
- count = 0;
- for (i = 0; i < npages; ++i) {
- if (faulted [i] != 0)
- ++count;
- }
- }
-
- g_free (faulted);
-
- return count;
-}
-
#else
/* dummy malloc-based implementation */
return 0;
}
-int
-mono_pages_not_faulted (void *addr, size_t length)
-{
- return -1;
-}
-
#endif // HAVE_MMAP
#if defined(HAVE_SHM_OPEN) && !defined (DISABLE_SHARED_PERFCOUNTERS)
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
+}