[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Check for getpagesize before using it to mmap files



commit 8f465808a06c739d8f81d04f6ed07fad40cacc76
Author: teor <teor2345@xxxxxxxxx>
Date:   Thu Nov 3 08:44:57 2016 +1100

    Check for getpagesize before using it to mmap files
    
    This fixes compilation in some MinGW environments.
    
    Fixes bug 20530; bugfix on commit bf72878 in tor-0.1.2.1-alpha.
    Reported by "ice".
---
 changes/bug20530    |  4 ++++
 configure.ac        |  8 ++++++++
 src/common/compat.c | 10 +++++++++-
 3 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/changes/bug20530 b/changes/bug20530
new file mode 100644
index 0000000..c21d5fb
--- /dev/null
+++ b/changes/bug20530
@@ -0,0 +1,4 @@
+  o Minor Fixes (Windows):
+    - Check for getpagesize before using it to mmap files. This fixes
+      compilation in some MinGW environments. Fixes bug 20530; bugfix on
+      commit bf72878 in tor-0.1.2.1-alpha, reported by "ice".
diff --git a/configure.ac b/configure.ac
index d35f83c..2a85794 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1410,6 +1410,14 @@ AC_CHECK_DECLS([mlockall], , , [
 #include <sys/mman.h>
 #endif])
 
+# Some MinGW environments don't have getpagesize in unistd.h. We don't use
+# AC_CHECK_FUNCS(getpagesize), because other environments rename getpagesize
+# using macros
+AC_CHECK_DECLS([getpagesize], , , [
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif])
+
 # Allow user to specify an alternate syslog facility
 AC_ARG_WITH(syslog-facility,
 AS_HELP_STRING(--with-syslog-facility=LOG, [syslog facility to use (default=LOG_DAEMON)]),
diff --git a/src/common/compat.c b/src/common/compat.c
index 4f2f977..5d751f8 100644
--- a/src/common/compat.c
+++ b/src/common/compat.c
@@ -204,7 +204,15 @@ tor_rename(const char *path_old, const char *path_new)
                 sandbox_intern_string(path_new));
 }
 
-#if defined(HAVE_SYS_MMAN_H) || defined(RUNNING_DOXYGEN)
+/* Some MinGW builds have sys/mman.h, but not the corresponding symbols.
+ * Other configs rename the symbols using macros (including getpagesize).
+ * So check for sys/mman.h and unistd.h, and a getpagesize declaration. */
+#if (defined(HAVE_SYS_MMAN_H) && defined(HAVE_UNISTD_H) && \
+     defined(HAVE_DECL_GETPAGESIZE))
+#define COMPAT_HAS_MMAN_AND_PAGESIZE
+#endif
+
+#if defined(COMPAT_HAS_MMAN_AND_PAGESIZE) || defined(RUNNING_DOXYGEN)
 /** Try to create a memory mapping for <b>filename</b> and return it.  On
  * failure, return NULL.  Sets errno properly, using ERANGE to mean
  * "empty file". */



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits