[utils] Explicitly check if the system has mincore instead of relying on mmap been...
authorRodrigo Kumpera <kumpera@gmail.com>
Mon, 26 Jan 2015 21:29:51 +0000 (16:29 -0500)
committerRodrigo Kumpera <kumpera@gmail.com>
Mon, 26 Jan 2015 21:30:42 +0000 (16:30 -0500)
configure.ac
mono/utils/mono-mmap.c

index c2d45b2bb0163106d221d56bfee3890a0f7eec39..be446d2dbbc52c4a74f089cfc1d622e9cb979b02 100644 (file)
@@ -1710,6 +1710,24 @@ if test x$target_win32 = xno; then
        AC_CHECK_FUNCS(pthread_attr_getstack pthread_attr_getstacksize)
        AC_CHECK_FUNCS(pthread_get_stacksize_np pthread_get_stackaddr_np)
 
+       dnl **********************************
+       dnl *** Check for mincore ***
+       dnl **********************************
+       AC_MSG_CHECKING(for mincore)
+               AC_TRY_LINK([
+               #include <stdio.h>
+               #include <sys/types.h>
+               #include <sys/mman.h>
+       ], [
+               mincore(NULL, 0, NULL);
+       ], [
+               # Yes, we have it...
+               AC_MSG_RESULT(yes)
+               AC_DEFINE(HAVE_MINCORE, 1, [Have mincore])
+       ], [
+               AC_MSG_RESULT(no)
+       ])
+
        dnl ***********************************
        dnl *** Checks for working __thread ***
        dnl ***********************************
index f200a266125ec47da6ec3dadcefaf8a47e3be385..06106605e21b953c2b8af52a8d4011c1e8bdbb43 100644 (file)
@@ -246,12 +246,6 @@ mono_shared_area_instances (void **array, int count)
        return 0;
 }
 
-int
-mono_pages_not_faulted (void *addr, size_t length)
-{
-       return -1;
-}
-
 #else
 #if defined(HAVE_MMAP)
 
@@ -452,30 +446,6 @@ mono_mprotect (void *addr, size_t length, int flags)
 }
 #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 */
@@ -515,12 +485,6 @@ mono_mprotect (void *addr, size_t length, int flags)
        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)
@@ -768,3 +732,31 @@ 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);
+
+       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
+       return -1;
+#endif
+}