Use an enum for inherit_result_out.

This commit is contained in:
Nick Mathewson 2019-04-03 10:57:06 -04:00
parent 8c06f02c94
commit 76912bf140
2 changed files with 16 additions and 13 deletions

View file

@ -118,7 +118,7 @@ nodump_mem(void *mem, size_t sz)
* *<b>inherit_result_out</b>. * *<b>inherit_result_out</b>.
*/ */
static int static int
noinherit_mem(void *mem, size_t sz, unsigned *inherit_result_out) noinherit_mem(void *mem, size_t sz, inherit_res_t *inherit_result_out)
{ {
#ifdef FLAG_ZERO #ifdef FLAG_ZERO
int r = MINHERIT(mem, sz, FLAG_ZERO); int r = MINHERIT(mem, sz, FLAG_ZERO);
@ -163,10 +163,11 @@ noinherit_mem(void *mem, size_t sz, unsigned *inherit_result_out)
* anonymity that Tor is trying to provide.] * anonymity that Tor is trying to provide.]
*/ */
void * void *
tor_mmap_anonymous(size_t sz, unsigned flags, unsigned *inherit_result_out) tor_mmap_anonymous(size_t sz, unsigned flags,
inherit_res_t *inherit_result_out)
{ {
void *ptr; void *ptr;
unsigned itmp=0; inherit_res_t itmp=0;
if (inherit_result_out == NULL) { if (inherit_result_out == NULL) {
inherit_result_out = &itmp; inherit_result_out = &itmp;
} }

View file

@ -31,15 +31,17 @@
*/ */
#define ANONMAP_NOINHERIT (1u<<1) #define ANONMAP_NOINHERIT (1u<<1)
/** Possible value for inherit_result_out: the memory will be kept typedef enum {
/** Possible value for inherit_result_out: the memory will be kept
* by any child process. */ * by any child process. */
#define INHERIT_RES_KEEP 0 INHERIT_RES_KEEP=0,
/** Possible value for inherit_result_out: the memory will be dropped in /** Possible value for inherit_result_out: the memory will be dropped in the
* the child process. Attempting to access it will likely cause a segfault. */ * child process. Attempting to access it will likely cause a segfault. */
#define INHERIT_RES_DROP 1 INHERIT_RES_DROP,
/** Possible value for inherit_result_out: the memory will be cleared in /** Possible value for inherit_result_out: the memory will be cleared in
* the child process. */ * the child process. */
#define INHERIT_RES_ZERO 2 INHERIT_RES_ZERO
} inherit_res_t;
/* Here we define the NOINHERIT_CAN_FAIL macro if and only if /* Here we define the NOINHERIT_CAN_FAIL macro if and only if
* it's possible that ANONMAP_NOINHERIT might yield inheritable memory. * it's possible that ANONMAP_NOINHERIT might yield inheritable memory.
@ -63,7 +65,7 @@
#endif #endif
void *tor_mmap_anonymous(size_t sz, unsigned flags, void *tor_mmap_anonymous(size_t sz, unsigned flags,
unsigned *inherit_result_out); inherit_res_t *inherit_result_out);
void tor_munmap_anonymous(void *mapping, size_t sz); void tor_munmap_anonymous(void *mapping, size_t sz);
#endif /* !defined(TOR_MAP_ANON_H) */ #endif /* !defined(TOR_MAP_ANON_H) */