summaryrefslogtreecommitdiff
path: root/gc.c
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 /gc.c
parent192150051144c0242ee44df26952dfe31b83cac2 (diff)
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.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/4461
Diffstat (limited to 'gc.c')
-rw-r--r--gc.c37
1 files changed, 18 insertions, 19 deletions
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