summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Grin (Karlson2k) <k2k@narod.ru>2021-10-23 22:03:06 +0300
committerEvgeny Grin (Karlson2k) <k2k@narod.ru>2021-10-24 10:58:42 +0300
commit66f273f4d5705eb5c841e2992330d3c221e2949b (patch)
tree9ce34f65de1b81fb47660c12734310ac1b790614
parentc407fe3d113011d286d149390db9ac65d8c3ae24 (diff)
Added check at configure time for PAGESIZE and PAGE_SIZE macros
Some platforms may have them defined as call of function so compile-time check for valid number may not work.
-rw-r--r--configure.ac69
-rw-r--r--src/microhttpd/memorypool.c35
2 files changed, 94 insertions, 10 deletions
diff --git a/configure.ac b/configure.ac
index c9d9f767..7b363d6d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1362,6 +1362,75 @@ int main(void)
]
)
+AC_CACHE_CHECK([for usable PAGESIZE macro], [mhd_cv_macro_pagesize_usable],
+ [
+ AC_LINK_IFELSE(
+ [
+ AC_LANG_PROGRAM(
+ [[
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#ifdef HAVE_LIMITS_H
+#include <limits.h>
+#endif
+#ifdef HAVE_SYS_PARAM_H
+#include <sys/param.h>
+#endif
+#ifndef PAGESIZE
+#error No PAGESIZE macro defined
+choke me now
+#endif
+ ]],
+ [[
+ long pgsz = PAGESIZE + 0;
+ if (1 > pgsz) return 1;
+ ]]
+ )
+ ],
+ [[mhd_cv_macro_pagesize_usable="yes"]], [[mhd_cv_macro_pagesize_usable="no"]]
+ )
+ ]
+)
+AS_VAR_IF([[mhd_cv_macro_pagesize_usable]], [["yes"]],
+ [AC_DEFINE([[MHD_USE_PAGESIZE_MACRO]],[[1]],[Define if you have usable PAGESIZE macro])],
+ [
+ AC_CACHE_CHECK([for usable PAGE_SIZE macro], [mhd_cv_macro_page_size_usable],
+ [
+ AC_LINK_IFELSE(
+ [
+ AC_LANG_PROGRAM(
+ [[
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#ifdef HAVE_LIMITS_H
+#include <limits.h>
+#endif
+#ifdef HAVE_SYS_PARAM_H
+#include <sys/param.h>
+#endif
+#ifndef PAGE_SIZE
+#error No PAGE_SIZE macro defined
+choke me now
+#endif
+ ]],
+ [[
+ long pgsz = PAGE_SIZE + 0;
+ if (1 > pgsz) return 1;
+ ]]
+ )
+ ],
+ [[mhd_cv_macro_page_size_usable="yes"]], [[mhd_cv_macro_page_size_usable="no"]]
+ )
+ ]
+ )
+ AS_VAR_IF([[mhd_cv_macro_page_size_usable]], [["yes"]],
+ [AC_DEFINE([[MHD_USE_PAGE_SIZE_MACRO]],[[1]],[Define if you have usable PAGE_SIZE macro])]
+ )
+ ]
+)
+
# Check for inter-thread signaling type
AC_ARG_ENABLE([[itc]],
[AS_HELP_STRING([[--enable-itc=TYPE]], [use TYPE of inter-thread communication (pipe, socketpair, eventfd) [auto]])], [],
diff --git a/src/microhttpd/memorypool.c b/src/microhttpd/memorypool.c
index ffcaab43..cf0b897e 100644
--- a/src/microhttpd/memorypool.c
+++ b/src/microhttpd/memorypool.c
@@ -45,7 +45,30 @@
#define MHD_SC_PAGESIZE _SC_PAGESIZE
#endif /* _SC_PAGESIZE */
#endif /* HAVE_SYSCONF */
-#include "mhd_limits.h" /* for SIZE_MAX */
+#include "mhd_limits.h" /* for SIZE_MAX, PAGESIZE / PAGE_SIZE */
+
+#if defined(MHD_USE_PAGESIZE_MACRO) || defined (MHD_USE_PAGE_SIZE_MACRO)
+#ifndef HAVE_SYSCONF /* Avoid duplicate include */
+#include <unistd.h>
+#endif /* HAVE_SYSCONF */
+#ifdef HAVE_SYS_PARAM_H
+#include <sys/param.h>
+#endif /* HAVE_SYS_PARAM_H */
+#endif /* MHD_USE_PAGESIZE_MACRO || MHD_USE_PAGE_SIZE_MACRO */
+
+/**
+ * Fallback value of page size
+ */
+#define _MHD_FALLBACK_PAGE_SIZE (4096)
+
+#if defined(MHD_USE_PAGESIZE_MACRO)
+#define MHD_DEF_PAGE_SIZE_ PAGESIZE
+#elif defined(MHD_USE_PAGE_SIZE_MACRO)
+#define MHD_DEF_PAGE_SIZE_ PAGE_SIZE
+#else /* ! PAGESIZE */
+#define MHD_DEF_PAGE_SIZE_ _MHD_FALLBACK_PAGE_SIZE
+#endif /* ! PAGESIZE */
+
#ifdef MHD_ASAN_POISON_ACTIVE
#include <sanitizer/asan_interface.h>
@@ -94,18 +117,10 @@
ASAN_UNPOISON_MEMORY_REGION ((pointer), (size))
#endif /* MHD_ASAN_POISON_ACTIVE */
-#if defined(PAGE_SIZE) && (0 < (PAGE_SIZE + 0))
-#define MHD_DEF_PAGE_SIZE_ PAGE_SIZE
-#elif defined(PAGESIZE) && (0 < (PAGESIZE + 0))
-#define MHD_DEF_PAGE_SIZE_ PAGESIZE
-#else /* ! PAGESIZE */
-#define MHD_DEF_PAGE_SIZE_ (4096)
-#endif /* ! PAGESIZE */
-
/**
* Size of memory page
*/
-static size_t MHD_sys_page_size_ = MHD_DEF_PAGE_SIZE_; /* Default fallback value */
+static size_t MHD_sys_page_size_ = _MHD_FALLBACK_PAGE_SIZE; /* Default fallback value */
/**
* Initialise values for memory pools