diff options
author | Nick Mathewson <nickm@torproject.org> | 2019-02-05 16:58:56 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2019-02-06 22:03:30 -0500 |
commit | 8ca808f81d28bbae9e9059172a7b7479d20e9594 (patch) | |
tree | fa9eb7ccf4db3015134db06cfadc48d72621e670 /src/lib/malloc/map_anon.h | |
parent | bfd1d702433fde0c551a1c79d410d87fe22feb30 (diff) | |
download | tor-8ca808f81d28bbae9e9059172a7b7479d20e9594.tar.gz tor-8ca808f81d28bbae9e9059172a7b7479d20e9594.zip |
Code for anonymous mappings via mmap() or CreateFileMapping().
Using an anonymous mmap() is a good way to get pages that we can set
kernel-level flags on, like minherit() or madvise() or mlock().
We're going to use that so that we can make uninheritable locked
pages to store PRNG data.
Diffstat (limited to 'src/lib/malloc/map_anon.h')
-rw-r--r-- | src/lib/malloc/map_anon.h | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/lib/malloc/map_anon.h b/src/lib/malloc/map_anon.h new file mode 100644 index 0000000000..cc5797e4ec --- /dev/null +++ b/src/lib/malloc/map_anon.h @@ -0,0 +1,37 @@ +/* Copyright (c) 2003-2004, Roger Dingledine + * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson. + * Copyright (c) 2007-2019, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ + +/** + * \file map_anon.h + * \brief Headers for map_anon.c + **/ + +#ifndef TOR_MAP_ANON_H +#define TOR_MAP_ANON_H + +#include "lib/malloc/malloc.h" +#include <stddef.h> + +/** + * When this flag is specified, try to prevent the mapping from being + * swapped or dumped. + * + * In some operating systems, this flag is not implemented. + */ +#define ANONMAP_PRIVATE (1u<<0) +/** + * 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. + */ +#define ANONMAP_NOINHERIT (1u<<1) + +void *tor_mmap_anonymous(size_t sz, unsigned flags); +void tor_munmap_anonymous(void *mapping, size_t sz); + +#endif /* !defined(TOR_MAP_ANON_H) */ |