aboutsummaryrefslogtreecommitdiff
path: root/src/lib/malloc
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2019-03-06 11:03:26 -0500
committerNick Mathewson <nickm@torproject.org>2019-04-04 12:56:52 -0400
commit361e955cf3f852caebb63f618fbae883237bf28b (patch)
treef831c65ed4f3dcb27576b8e0743d516cc83da22d /src/lib/malloc
parent12205c3cbee4e71ded2b5710a57342b510e9d6df (diff)
downloadtor-361e955cf3f852caebb63f618fbae883237bf28b.tar.gz
tor-361e955cf3f852caebb63f618fbae883237bf28b.zip
map_anon: define a macro if it is possible for noinherit to fail.
Diffstat (limited to 'src/lib/malloc')
-rw-r--r--src/lib/malloc/map_anon.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/lib/malloc/map_anon.h b/src/lib/malloc/map_anon.h
index edd7500821..89fb9da0f0 100644
--- a/src/lib/malloc/map_anon.h
+++ b/src/lib/malloc/map_anon.h
@@ -41,6 +41,27 @@
* the child process. */
#define INHERIT_ZERO 2
+/* Here we define the NOINHERIT_CAN_FAIL macro if and only if
+ * it's possible that ANONMAP_NOINHERIT might yield inheritable memory.
+ */
+#ifdef _WIN32
+/* Windows can't fork, so NOINHERIT is never needed. */
+#elif defined(HAVE_MINHERIT)
+/* minherit() will always have a working MAP_INHERIT_NONE or MAP_INHERIT_ZERO.
+ * NOINHERIT should always work.
+ */
+#elif defined(HAVE_MADVISE)
+/* madvise() sometimes has neither MADV_DONTFORK and MADV_WIPEONFORK.
+ * We need to be ready for the possibility it failed.
+ *
+ * (Linux added DONTFORK in 2.6.16 and WIPEONFORK in 4.14. If we someday
+ * require 2.6.16 or later, we can assume that DONTFORK will work.)
+ */
+#define NOINHERIT_CAN_FAIL
+#else
+#define NOINHERIT_CAN_FAIL
+#endif
+
void *tor_mmap_anonymous(size_t sz, unsigned flags,
unsigned *inherit_result_out);
void tor_munmap_anonymous(void *mapping, size_t sz);