Tor 0.4.9.0-alpha-dev
Macros | Enumerations | Functions
map_anon.h File Reference

Headers for map_anon.c. More...

#include "lib/malloc/malloc.h"
#include <stddef.h>

Go to the source code of this file.

Macros

#define ANONMAP_PRIVATE   (1u<<0)
 
#define ANONMAP_NOINHERIT   (1u<<1)
 
#define NOINHERIT_CAN_FAIL
 

Enumerations

enum  inherit_res_t { INHERIT_RES_KEEP =0 , INHERIT_RES_DROP , INHERIT_RES_ZERO }
 

Functions

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

Headers for map_anon.c.

Definition in file map_anon.h.

Macro Definition Documentation

◆ ANONMAP_NOINHERIT

#define ANONMAP_NOINHERIT   (1u<<1)

When this flag is specified, try to prevent the mapping from being inherited after a fork(). In some operating systems, trying to access it afterwards will cause its contents to be zero. In others, trying to access it afterwards will cause a crash.

In some operating systems, this flag is not implemented at all.

Definition at line 32 of file map_anon.h.

◆ ANONMAP_PRIVATE

#define ANONMAP_PRIVATE   (1u<<0)

When this flag is specified, try to prevent the mapping from being swapped or dumped.

In some operating systems, this flag is not implemented.

Definition at line 23 of file map_anon.h.

◆ NOINHERIT_CAN_FAIL

#define NOINHERIT_CAN_FAIL

Definition at line 64 of file map_anon.h.

Enumeration Type Documentation

◆ inherit_res_t

Enumerator
INHERIT_RES_KEEP 

Possible value for inherit_result_out: the memory will be kept by any child process.

INHERIT_RES_DROP 

Possible value for inherit_result_out: the memory will be dropped in the child process. Attempting to access it will likely cause a segfault.

INHERIT_RES_ZERO 

Possible value for inherit_result_out: the memory will be cleared in the child process.

Definition at line 34 of file map_anon.h.

Function Documentation

◆ 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_().