[tor-commits] [tor/master] rename inherit values to avoid conflict with system defines

asn at torproject.org asn at torproject.org
Fri Apr 5 11:52:42 UTC 2019


commit 027c536598f336014d7ef406610207ec4559d490
Author: Nick Mathewson <nickm at torproject.org>
Date:   Wed Mar 6 12:08:25 2019 -0500

    rename inherit values to avoid conflict with system defines
---
 src/lib/crypt_ops/crypto_rand_fast.c | 12 ++++++------
 src/lib/malloc/map_anon.c            | 12 ++++++------
 src/lib/malloc/map_anon.h            |  6 +++---
 src/test/test_util.c                 | 14 +++++++-------
 4 files changed, 22 insertions(+), 22 deletions(-)

diff --git a/src/lib/crypt_ops/crypto_rand_fast.c b/src/lib/crypt_ops/crypto_rand_fast.c
index 384c172c3..01817c618 100644
--- a/src/lib/crypt_ops/crypto_rand_fast.c
+++ b/src/lib/crypt_ops/crypto_rand_fast.c
@@ -152,7 +152,7 @@ crypto_fast_rng_new(void)
 crypto_fast_rng_t *
 crypto_fast_rng_new_from_seed(const uint8_t *seed)
 {
-  unsigned inherit = INHERIT_KEEP;
+  unsigned inherit = INHERIT_RES_KEEP;
   /* We try to allocate this object as securely as we can, to avoid
    * having it get dumped, swapped, or shared after fork.
    */
@@ -164,7 +164,7 @@ crypto_fast_rng_new_from_seed(const uint8_t *seed)
   result->bytes_left = 0;
   result->n_till_reseed = RESEED_AFTER;
 #ifdef CHECK_PID
-  if (inherit == INHERIT_KEEP) {
+  if (inherit == INHERIT_RES_KEEP) {
     /* This value will neither be dropped nor zeroed after fork, so we need to
      * check our pid to make sure we are not sharing it across a fork.  This
      * can be expensive if the pid value isn't cached, sadly.
@@ -176,7 +176,7 @@ crypto_fast_rng_new_from_seed(const uint8_t *seed)
 #else
   /* We decided above that noinherit would always do _something_. Assert here
    * that we were correct. */
-  tor_assert(inherit != INHERIT_KEEP);
+  tor_assert(inherit != INHERIT_RES_KEEP);
 #endif
   return result;
 }
@@ -253,12 +253,12 @@ crypto_fast_rng_getbytes_impl(crypto_fast_rng_t *rng, uint8_t *out,
   if (rng->owner) {
     /* Note that we only need to do this check when we have owner set: that
      * is, when our attempt to block inheriting failed, and the result was
-     * INHERIT_KEEP.
+     * INHERIT_RES_KEEP.
      *
-     * If the result was INHERIT_DROP, then any attempt to access the rng
+     * If the result was INHERIT_RES_DROP, then any attempt to access the rng
      * memory after forking will crash.
      *
-     * If the result was INHERIT_ZERO, then forking will set the bytes_left
+     * If the result was INHERIT_RES_ZERO, then forking will set the bytes_left
      * and n_till_reseed fields to zero.  This function will call
      * crypto_fast_rng_refill(), which will in turn reseed the PRNG.
      *
diff --git a/src/lib/malloc/map_anon.c b/src/lib/malloc/map_anon.c
index bb0a3d574..3e1c22648 100644
--- a/src/lib/malloc/map_anon.c
+++ b/src/lib/malloc/map_anon.c
@@ -123,14 +123,14 @@ noinherit_mem(void *mem, size_t sz, unsigned *inherit_result_out)
 #ifdef FLAG_ZERO
   int r = MINHERIT(mem, sz, FLAG_ZERO);
   if (r == 0) {
-    *inherit_result_out = INHERIT_ZERO;
+    *inherit_result_out = INHERIT_RES_ZERO;
     return 0;
   }
 #endif
 #ifdef FLAG_NOINHERIT
   int r2 = MINHERIT(mem, sz, FLAG_NOINHERIT);
   if (r2 == 0) {
-    *inherit_result_out = INHERIT_DROP;
+    *inherit_result_out = INHERIT_RES_DROP;
   }
   return r2;
 #else
@@ -154,9 +154,9 @@ noinherit_mem(void *mem, size_t sz, unsigned *inherit_result_out)
  * Memory returned from this function must be released with
  * tor_munmap_anonymous().
  *
- * If <b>inherit_result_out</b> is non-NULL, set it to one of INHERIT_KEEP,
- * INHERIT_DROP, and INHERIT_ZERO, depending on the properties of the returned
- * memory.
+ * If <b>inherit_result_out</b> is non-NULL, set it to one of
+ * INHERIT_RES_KEEP, INHERIT_RES_DROP, or INHERIT_RES_ZERO, depending on the
+ * properties of the returned memory.
  *
  * [Note: OS people use the word "anonymous" here to mean that the memory
  * isn't associated with any file. This has *nothing* to do with the kind of
@@ -170,7 +170,7 @@ tor_mmap_anonymous(size_t sz, unsigned flags, unsigned *inherit_result_out)
   if (inherit_result_out == NULL) {
     inherit_result_out = &itmp;
   }
-  *inherit_result_out = INHERIT_KEEP;
+  *inherit_result_out = INHERIT_RES_KEEP;
 
 #if defined(_WIN32)
   HANDLE mapping = CreateFileMapping(INVALID_HANDLE_VALUE,
diff --git a/src/lib/malloc/map_anon.h b/src/lib/malloc/map_anon.h
index 89fb9da0f..f101654eb 100644
--- a/src/lib/malloc/map_anon.h
+++ b/src/lib/malloc/map_anon.h
@@ -33,13 +33,13 @@
 
 /** Possible value for inherit_result_out: the memory will be kept
  * by any child process. */
-#define INHERIT_KEEP 0
+#define INHERIT_RES_KEEP 0
 /** Possible value for inherit_result_out: the memory will be dropped in
  * the child process. Attempting to access it will likely cause a segfault. */
-#define INHERIT_DROP 1
+#define INHERIT_RES_DROP 1
 /** Possible value for inherit_result_out: the memory will be cleared in
  * the child process. */
-#define INHERIT_ZERO 2
+#define INHERIT_RES_ZERO 2
 
 /* Here we define the NOINHERIT_CAN_FAIL macro if and only if
  * it's possible that ANONMAP_NOINHERIT might yield inheritable memory.
diff --git a/src/test/test_util.c b/src/test/test_util.c
index f6085fdb9..4f81e54d2 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -6135,7 +6135,7 @@ test_util_map_anon(void *arg)
   /* Basic checks. */
   ptr = tor_mmap_anonymous(sz, 0, &inherit);
   tt_ptr_op(ptr, OP_NE, 0);
-  tt_int_op(inherit, OP_EQ, INHERIT_KEEP);
+  tt_int_op(inherit, OP_EQ, INHERIT_RES_KEEP);
   ptr[sz-1] = 3;
   tt_int_op(ptr[0], OP_EQ, 0);
   tt_int_op(ptr[sz-2], OP_EQ, 0);
@@ -6145,7 +6145,7 @@ test_util_map_anon(void *arg)
   tor_munmap_anonymous(ptr, sz);
   ptr = tor_mmap_anonymous(sz, ANONMAP_PRIVATE, &inherit);
   tt_ptr_op(ptr, OP_NE, 0);
-  tt_int_op(inherit, OP_EQ, INHERIT_KEEP);
+  tt_int_op(inherit, OP_EQ, INHERIT_RES_KEEP);
   ptr[sz-1] = 10;
   tt_int_op(ptr[0], OP_EQ, 0);
   tt_int_op(ptr[sz/2], OP_EQ, 0);
@@ -6207,16 +6207,16 @@ test_util_map_anon_nofork(void *arg)
   char buf[1];
   ssize_t r = read(pipefd[0], buf, 1);
 
-  if (inherit == INHERIT_ZERO) {
+  if (inherit == INHERIT_RES_ZERO) {
     // We should be seeing clear-on-fork behavior.
     tt_int_op((int)r, OP_EQ, 1); // child should send us a byte.
     tt_int_op(buf[0], OP_EQ, 0); // that byte should be zero.
-  } else if (inherit == INHERIT_DROP) {
+  } else if (inherit == INHERIT_RES_DROP) {
     // We should be seeing noinherit behavior.
     tt_int_op(r, OP_LE, 0); // child said nothing; it should have crashed.
   } else {
     // noinherit isn't implemented.
-    tt_int_op(inherit, OP_EQ, INHERIT_KEEP);
+    tt_int_op(inherit, OP_EQ, INHERIT_RES_KEEP);
     tt_int_op((int)r, OP_EQ, 1); // child should send us a byte.
     tt_int_op(buf[0], OP_EQ, 0xd0); // that byte should what we set it to.
   }
@@ -6227,9 +6227,9 @@ test_util_map_anon_nofork(void *arg)
 #ifndef NOINHERIT_CAN_FAIL
   /* Only if NOINHERIT_CAN_FAIL should it be possible for us to get
    * INHERIT_KEEP behavior in this case. */
-  tt_assert(inherit, OP_NE, INHERIT_KEEP);
+  tt_assert(inherit, OP_NE, INHERIT_RES_KEEP);
 #else
-  if (inherit == INHERIT_KEEP) {
+  if (inherit == INHERIT_RES_KEEP) {
     /* Call this test "skipped", not "passed", since noinherit wasn't
      * implemented. */
     tt_skip();





More information about the tor-commits mailing list