diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2021-10-23 22:03:06 +0300 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2021-10-24 10:58:42 +0300 |
commit | 66f273f4d5705eb5c841e2992330d3c221e2949b (patch) | |
tree | 9ce34f65de1b81fb47660c12734310ac1b790614 | |
parent | c407fe3d113011d286d149390db9ac65d8c3ae24 (diff) | |
download | libmicrohttpd-66f273f4d5705eb5c841e2992330d3c221e2949b.tar.gz libmicrohttpd-66f273f4d5705eb5c841e2992330d3c221e2949b.zip |
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.ac | 69 | ||||
-rw-r--r-- | src/microhttpd/memorypool.c | 35 |
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) | |||
1362 | ] | 1362 | ] |
1363 | ) | 1363 | ) |
1364 | 1364 | ||
1365 | AC_CACHE_CHECK([for usable PAGESIZE macro], [mhd_cv_macro_pagesize_usable], | ||
1366 | [ | ||
1367 | AC_LINK_IFELSE( | ||
1368 | [ | ||
1369 | AC_LANG_PROGRAM( | ||
1370 | [[ | ||
1371 | #ifdef HAVE_UNISTD_H | ||
1372 | #include <unistd.h> | ||
1373 | #endif | ||
1374 | #ifdef HAVE_LIMITS_H | ||
1375 | #include <limits.h> | ||
1376 | #endif | ||
1377 | #ifdef HAVE_SYS_PARAM_H | ||
1378 | #include <sys/param.h> | ||
1379 | #endif | ||
1380 | #ifndef PAGESIZE | ||
1381 | #error No PAGESIZE macro defined | ||
1382 | choke me now | ||
1383 | #endif | ||
1384 | ]], | ||
1385 | [[ | ||
1386 | long pgsz = PAGESIZE + 0; | ||
1387 | if (1 > pgsz) return 1; | ||
1388 | ]] | ||
1389 | ) | ||
1390 | ], | ||
1391 | [[mhd_cv_macro_pagesize_usable="yes"]], [[mhd_cv_macro_pagesize_usable="no"]] | ||
1392 | ) | ||
1393 | ] | ||
1394 | ) | ||
1395 | AS_VAR_IF([[mhd_cv_macro_pagesize_usable]], [["yes"]], | ||
1396 | [AC_DEFINE([[MHD_USE_PAGESIZE_MACRO]],[[1]],[Define if you have usable PAGESIZE macro])], | ||
1397 | [ | ||
1398 | AC_CACHE_CHECK([for usable PAGE_SIZE macro], [mhd_cv_macro_page_size_usable], | ||
1399 | [ | ||
1400 | AC_LINK_IFELSE( | ||
1401 | [ | ||
1402 | AC_LANG_PROGRAM( | ||
1403 | [[ | ||
1404 | #ifdef HAVE_UNISTD_H | ||
1405 | #include <unistd.h> | ||
1406 | #endif | ||
1407 | #ifdef HAVE_LIMITS_H | ||
1408 | #include <limits.h> | ||
1409 | #endif | ||
1410 | #ifdef HAVE_SYS_PARAM_H | ||
1411 | #include <sys/param.h> | ||
1412 | #endif | ||
1413 | #ifndef PAGE_SIZE | ||
1414 | #error No PAGE_SIZE macro defined | ||
1415 | choke me now | ||
1416 | #endif | ||
1417 | ]], | ||
1418 | [[ | ||
1419 | long pgsz = PAGE_SIZE + 0; | ||
1420 | if (1 > pgsz) return 1; | ||
1421 | ]] | ||
1422 | ) | ||
1423 | ], | ||
1424 | [[mhd_cv_macro_page_size_usable="yes"]], [[mhd_cv_macro_page_size_usable="no"]] | ||
1425 | ) | ||
1426 | ] | ||
1427 | ) | ||
1428 | AS_VAR_IF([[mhd_cv_macro_page_size_usable]], [["yes"]], | ||
1429 | [AC_DEFINE([[MHD_USE_PAGE_SIZE_MACRO]],[[1]],[Define if you have usable PAGE_SIZE macro])] | ||
1430 | ) | ||
1431 | ] | ||
1432 | ) | ||
1433 | |||
1365 | # Check for inter-thread signaling type | 1434 | # Check for inter-thread signaling type |
1366 | AC_ARG_ENABLE([[itc]], | 1435 | AC_ARG_ENABLE([[itc]], |
1367 | [AS_HELP_STRING([[--enable-itc=TYPE]], [use TYPE of inter-thread communication (pipe, socketpair, eventfd) [auto]])], [], | 1436 | [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 @@ | |||
45 | #define MHD_SC_PAGESIZE _SC_PAGESIZE | 45 | #define MHD_SC_PAGESIZE _SC_PAGESIZE |
46 | #endif /* _SC_PAGESIZE */ | 46 | #endif /* _SC_PAGESIZE */ |
47 | #endif /* HAVE_SYSCONF */ | 47 | #endif /* HAVE_SYSCONF */ |
48 | #include "mhd_limits.h" /* for SIZE_MAX */ | 48 | #include "mhd_limits.h" /* for SIZE_MAX, PAGESIZE / PAGE_SIZE */ |
49 | |||
50 | #if defined(MHD_USE_PAGESIZE_MACRO) || defined (MHD_USE_PAGE_SIZE_MACRO) | ||
51 | #ifndef HAVE_SYSCONF /* Avoid duplicate include */ | ||
52 | #include <unistd.h> | ||
53 | #endif /* HAVE_SYSCONF */ | ||
54 | #ifdef HAVE_SYS_PARAM_H | ||
55 | #include <sys/param.h> | ||
56 | #endif /* HAVE_SYS_PARAM_H */ | ||
57 | #endif /* MHD_USE_PAGESIZE_MACRO || MHD_USE_PAGE_SIZE_MACRO */ | ||
58 | |||
59 | /** | ||
60 | * Fallback value of page size | ||
61 | */ | ||
62 | #define _MHD_FALLBACK_PAGE_SIZE (4096) | ||
63 | |||
64 | #if defined(MHD_USE_PAGESIZE_MACRO) | ||
65 | #define MHD_DEF_PAGE_SIZE_ PAGESIZE | ||
66 | #elif defined(MHD_USE_PAGE_SIZE_MACRO) | ||
67 | #define MHD_DEF_PAGE_SIZE_ PAGE_SIZE | ||
68 | #else /* ! PAGESIZE */ | ||
69 | #define MHD_DEF_PAGE_SIZE_ _MHD_FALLBACK_PAGE_SIZE | ||
70 | #endif /* ! PAGESIZE */ | ||
71 | |||
49 | 72 | ||
50 | #ifdef MHD_ASAN_POISON_ACTIVE | 73 | #ifdef MHD_ASAN_POISON_ACTIVE |
51 | #include <sanitizer/asan_interface.h> | 74 | #include <sanitizer/asan_interface.h> |
@@ -94,18 +117,10 @@ | |||
94 | ASAN_UNPOISON_MEMORY_REGION ((pointer), (size)) | 117 | ASAN_UNPOISON_MEMORY_REGION ((pointer), (size)) |
95 | #endif /* MHD_ASAN_POISON_ACTIVE */ | 118 | #endif /* MHD_ASAN_POISON_ACTIVE */ |
96 | 119 | ||
97 | #if defined(PAGE_SIZE) && (0 < (PAGE_SIZE + 0)) | ||
98 | #define MHD_DEF_PAGE_SIZE_ PAGE_SIZE | ||
99 | #elif defined(PAGESIZE) && (0 < (PAGESIZE + 0)) | ||
100 | #define MHD_DEF_PAGE_SIZE_ PAGESIZE | ||
101 | #else /* ! PAGESIZE */ | ||
102 | #define MHD_DEF_PAGE_SIZE_ (4096) | ||
103 | #endif /* ! PAGESIZE */ | ||
104 | |||
105 | /** | 120 | /** |
106 | * Size of memory page | 121 | * Size of memory page |
107 | */ | 122 | */ |
108 | static size_t MHD_sys_page_size_ = MHD_DEF_PAGE_SIZE_; /* Default fallback value */ | 123 | static size_t MHD_sys_page_size_ = _MHD_FALLBACK_PAGE_SIZE; /* Default fallback value */ |
109 | 124 | ||
110 | /** | 125 | /** |
111 | * Initialise values for memory pools | 126 | * Initialise values for memory pools |