aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Zhu <peter@peterzhu.ca>2021-05-05 16:20:40 +0000
committerPeter Zhu <peter@peterzhu.ca>2021-05-05 15:31:30 -0400
commit23a98237df28ad01d17b163eb650dfbd321b13ba (patch)
tree5fb24b61788114b3a83bece3d1561f9555dc7b0d
parent192150051144c0242ee44df26952dfe31b83cac2 (diff)
downloadruby-23a98237df28ad01d17b163eb650dfbd321b13ba.tar.gz
Fix PAGE_SIZE macro detection in autoconf
The current fix for PAGE_SIZE macro detection in autoconf does not work correctly. I see the following output with running configure on Linux: ``` checking PAGE_SIZE is defined... no ``` Linux has PAGE_SIZE macro. This is happening because the macro exists in sys/user.h and not in the malloc headers.
-rw-r--r--configure.ac19
-rw-r--r--gc.c37
2 files changed, 29 insertions, 27 deletions
diff --git a/configure.ac b/configure.ac
index 1eb4be412c..e49c128a45 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2727,23 +2727,26 @@ main(int argc, char *argv[])
test x$rb_cv_fork_with_pthread = xyes || AC_DEFINE(CANNOT_FORK_WITH_PTHREAD)
])
-AS_IF([test "x$ac_cv_func_mmap" = xyes], [
- malloc_headers=`sed -n '/MALLOC_HEADERS_BEGIN/,/MALLOC_HEADERS_END/p' ${srcdir}/gc.c`
+AC_CHECK_HEADERS([sys/user.h])
+AS_IF([test "x$ac_cv_func_mmap:$ac_cv_header_sys_user_h" = xyes:yes], [
AC_CACHE_CHECK([PAGE_SIZE is defined], rb_cv_page_size,
- [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[${malloc_headers}
+ [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+ @%:@include <sys/user.h>
typedef char conftest_page[PAGE_SIZE];
]], [[]])],
[rb_cv_page_size=const],
- [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[${malloc_headers}]], [[
+ [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+ @%:@include <sys/user.h>
+ ]], [[
int page_size = (int)PAGE_SIZE;
(void)page_size;
]])],
[rb_cv_page_size=variable], [rb_cv_page_size=no])])])
- AS_CASE([$rb_cv_page_size],
- [const], [AC_DEFINE(USE_MMAP_ALIGNED_ALLOC, [(PAGE_SIZE <= HEAP_PAGE_SIZE)])],
- [no], [AC_DEFINE(USE_MMAP_ALIGNED_ALLOC, 1)],
+ AS_IF([test "x$rb_cv_page_size" = xconst],
+ [AC_DEFINE(HAVE_CONST_PAGE_SIZE, 1)],
+ [AC_DEFINE(HAVE_CONST_PAGE_SIZE, 0)]
)
-], [AC_DEFINE(USE_MMAP_ALIGNED_ALLOC, 0)])
+], [AC_DEFINE(HAVE_CONST_PAGE_SIZE, 0)])
}
: "runtime section" && {
diff --git a/gc.c b/gc.c
index c899228299..721e2440a3 100644
--- a/gc.c
+++ b/gc.c
@@ -32,7 +32,6 @@
#include <stdarg.h>
#include <stdio.h>
-/* MALLOC_HEADERS_BEGIN */
#ifndef HAVE_MALLOC_USABLE_SIZE
# ifdef _WIN32
# define HAVE_MALLOC_USABLE_SIZE
@@ -54,7 +53,6 @@
# include <malloc/malloc.h>
# endif
#endif
-/* MALLOC_HEADERS_END */
#ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
@@ -73,6 +71,10 @@
#include <sys/types.h>
+#ifdef HAVE_SYS_USER_H
+# include <sys/user.h>
+#endif
+
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#endif
@@ -832,23 +834,17 @@ enum {
};
#define HEAP_PAGE_ALIGN (1 << HEAP_PAGE_ALIGN_LOG)
#define HEAP_PAGE_SIZE HEAP_PAGE_ALIGN
-#ifdef USE_MMAP_ALIGNED_ALLOC
-# define Init_use_mmap_aligned_alloc() (void)0
-#elif !defined(HAVE_MMAP)
-# define USE_MMAP_ALIGNED_ALLOC 0
-# define Init_use_mmap_aligned_alloc() (void)0
-#elif defined(PAGE_MAX_SIZE) && (PAGE_MAX_SIZE <= HEAP_PAGE_SIZE)
-/* PAGE_SIZE <= HEAP_PAGE_SIZE */
-# define USE_MMAP_ALIGNED_ALLOC 1
-# define Init_use_mmap_aligned_alloc() (void)0
-#else
-# define USE_MMAP_ALIGNED_ALLOC (use_mmap_aligned_alloc != false)
+
+#if defined(HAVE_MMAP) && defined(PAGE_SIZE)
+# if HAVE_CONST_PAGE_SIZE
+# define USE_MMAP_ALIGNED_ALLOC (PAGE_SIZE <= HEAP_PAGE_SIZE)
+# else
+# define USE_MMAP_ALIGNED_ALLOC (use_mmap_aligned_alloc != false)
+
static bool use_mmap_aligned_alloc;
-static inline void
-Init_use_mmap_aligned_alloc(void)
-{
- use_mmap_aligned_alloc = (PAGE_SIZE <= HEAP_PAGE_SIZE);
-}
+# endif
+#else
+# define USE_MMAP_ALIGNED_ALLOC 0
#endif
struct heap_page {
@@ -3212,7 +3208,10 @@ Init_heap(void)
{
rb_objspace_t *objspace = &rb_objspace;
- Init_use_mmap_aligned_alloc();
+#if defined(HAVE_MMAP) && defined(PAGE_SIZE) && !HAVE_CONST_PAGE_SIZE
+ use_mmap_aligned_alloc = PAGE_SIZE <= HEAP_PAGE_SIZE;
+#endif
+
#if defined(HAVE_SYSCONF) && defined(_SC_PAGE_SIZE)
/* If Ruby's heap pages are not a multiple of the system page size, we
* cannot use mprotect for the read barrier, so we must disable automatic