Tor  0.4.7.0-alpha-dev
Macros | Functions
map_anon.c File Reference

Manage anonymous mappings. More...

#include "orconfig.h"
#include "lib/malloc/map_anon.h"
#include "lib/malloc/malloc.h"
#include "lib/err/torerr.h"
#include <string.h>
#include <errno.h>

Go to the source code of this file.

Macros

#define HIGH_SIZE_T_BYTES(sz)   (0)
 

Functions

static int lock_mem (void *mem, size_t sz)
 
static int nodump_mem (void *mem, size_t sz)
 
static int noinherit_mem (void *mem, size_t sz, inherit_res_t *inherit_result_out)
 
void * tor_mmap_anonymous (size_t sz, unsigned flags, inherit_res_t *inherit_result_out)
 
void tor_munmap_anonymous (void *mapping, size_t sz)
 

Detailed Description

Manage anonymous mappings.

Definition in file map_anon.c.

Macro Definition Documentation

◆ HIGH_SIZE_T_BYTES

#define HIGH_SIZE_T_BYTES (   sz)    (0)

Macro to get the high bytes of a size_t, if there are high bytes. Windows needs this; other operating systems define a size_t that does what it should.

Definition at line 41 of file map_anon.c.

Function Documentation

◆ lock_mem()

static int lock_mem ( void *  mem,
size_t  sz 
)
static

Helper: try to prevent the sz bytes at mem from being swapped to disk. Return 0 on success or if the facility is not available on this OS; return -1 on failure.

Definition at line 91 of file map_anon.c.

◆ nodump_mem()

static int nodump_mem ( void *  mem,
size_t  sz 
)
static

Helper: try to prevent the sz bytes at mem from appearing in a core dump. Return 0 on success or if the facility is not available on this OS; return -1 on failure.

Definition at line 111 of file map_anon.c.

◆ noinherit_mem()

static int noinherit_mem ( void *  mem,
size_t  sz,
inherit_res_t inherit_result_out 
)
static

Helper: try to prevent the sz bytes at mem from being accessible in child processes – ideally by having them set to 0 after a fork, and if that doesn't work, by having them unmapped after a fork. Return 0 on success or if the facility is not available on this OS; return -1 on failure.

If we successfully make the memory uninheritable, adjust the value of *inherit_result_out.

Definition at line 143 of file map_anon.c.

◆ tor_mmap_anonymous()

void* tor_mmap_anonymous ( size_t  sz,
unsigned  flags,
inherit_res_t inherit_result_out 
)

Return a new anonymous memory mapping that holds sz bytes.

Memory mappings are unlike the results from malloc() in that they are handled separately by the operating system, and as such can have different kernel-level flags set on them.

The "flags" argument may be zero or more of ANONMAP_PRIVATE and ANONMAP_NOINHERIT.

Memory returned from this function must be released with tor_munmap_anonymous().

If inherit_result_out 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 anonymity that Tor is trying to provide.]

Definition at line 203 of file map_anon.c.

Referenced by crypto_fast_rng_new_from_seed().

◆ tor_munmap_anonymous()

void tor_munmap_anonymous ( void *  mapping,
size_t  sz 
)

Release sz bytes of memory that were previously mapped at mapping by tor_mmap_anonymous().

Definition at line 257 of file map_anon.c.

Referenced by crypto_fast_rng_free_().