tor

The Tor anonymity network
git clone https://git.dasho.dev/tor.git
Log | Files | Refs | README | LICENSE

map_anon.h (2346B)


      1 /* Copyright (c) 2003-2004, Roger Dingledine
      2 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
      3 * Copyright (c) 2007-2021, The Tor Project, Inc. */
      4 /* See LICENSE for licensing information */
      5 
      6 /**
      7 * \file map_anon.h
      8 * \brief Headers for map_anon.c
      9 **/
     10 
     11 #ifndef TOR_MAP_ANON_H
     12 #define TOR_MAP_ANON_H
     13 
     14 #include "lib/malloc/malloc.h"
     15 #include <stddef.h>
     16 
     17 /**
     18 * When this flag is specified, try to prevent the mapping from being
     19 * swapped or dumped.
     20 *
     21 * In some operating systems, this flag is not implemented.
     22 */
     23 #define ANONMAP_PRIVATE   (1u<<0)
     24 /**
     25 * When this flag is specified, try to prevent the mapping from being
     26 * inherited after a fork().  In some operating systems, trying to access it
     27 * afterwards will cause its contents to be zero.  In others, trying to access
     28 * it afterwards will cause a crash.
     29 *
     30 * In some operating systems, this flag is not implemented at all.
     31 */
     32 #define ANONMAP_NOINHERIT (1u<<1)
     33 
     34 typedef enum {
     35  /** Possible value for inherit_result_out: the memory will be kept
     36   * by any child process. */
     37  INHERIT_RES_KEEP=0,
     38  /** Possible value for inherit_result_out: the memory will be dropped in the
     39   * child process. Attempting to access it will likely cause a segfault. */
     40  INHERIT_RES_DROP,
     41  /** Possible value for inherit_result_out: the memory will be cleared in
     42   * the child process. */
     43  INHERIT_RES_ZERO
     44 } inherit_res_t;
     45 
     46 /* Here we define the NOINHERIT_CAN_FAIL macro if and only if
     47 * it's possible that ANONMAP_NOINHERIT might yield inheritable memory.
     48 */
     49 #ifdef _WIN32
     50 /* Windows can't fork, so NOINHERIT is never needed. */
     51 #elif defined(HAVE_MINHERIT)
     52 /* minherit() will always have a working MAP_INHERIT_NONE or MAP_INHERIT_ZERO.
     53 * NOINHERIT should always work.
     54 */
     55 #elif defined(HAVE_MADVISE)
     56 /* madvise() sometimes has neither MADV_DONTFORK and MADV_WIPEONFORK.
     57 * We need to be ready for the possibility it failed.
     58 *
     59 * (Linux added DONTFORK in 2.6.16 and WIPEONFORK in 4.14. If we someday
     60 * require 2.6.16 or later, we can assume that DONTFORK will work.)
     61 */
     62 #define NOINHERIT_CAN_FAIL
     63 #else
     64 #define NOINHERIT_CAN_FAIL
     65 #endif /* defined(_WIN32) || ... */
     66 
     67 void *tor_mmap_anonymous(size_t sz, unsigned flags,
     68                         inherit_res_t *inherit_result_out);
     69 void tor_munmap_anonymous(void *mapping, size_t sz);
     70 
     71 #endif /* !defined(TOR_MAP_ANON_H) */