16 #ifdef HAVE_SYS_MMAN_H
19 #ifdef HAVE_SYS_TYPES_H
20 #include <sys/types.h>
22 #ifdef HAVE_MACH_VM_INHERIT_H
23 #include <mach/vm_inherit.h>
39 #define HIGH_SIZE_T_BYTES(sz) ((sz) >> 32)
41 #define HIGH_SIZE_T_BYTES(sz) (0)
51 #if defined(HAVE_MINHERIT)
52 #define MINHERIT minherit
55 #define FLAG_ZERO INHERIT_ZERO
56 #elif defined(MAP_INHERIT_ZERO)
57 #define FLAG_ZERO MAP_INHERIT_ZERO
60 #define FLAG_NOINHERIT INHERIT_NONE
61 #elif defined(VM_INHERIT_NONE)
62 #define FLAG_NOINHERIT VM_INHERIT_NONE
63 #elif defined(MAP_INHERIT_NONE)
64 #define FLAG_NOINHERIT MAP_INHERIT_NONE
67 #elif defined(HAVE_MADVISE)
69 #define MINHERIT madvise
71 #ifdef MADV_WIPEONFORK
72 #define FLAG_ZERO MADV_WIPEONFORK
75 #define FLAG_NOINHERIT MADV_DONTFORK
80 #if defined(HAVE_MINHERIT) && !defined(FLAG_ZERO) && !defined(FLAG_NOINHERIT)
81 #warning "minherit() is defined, but FLAG_ZERO/NOINHERIT are not."
82 #warning "This is probably a bug in Tor's support for this platform."
94 return VirtualLock(mem, sz) ? 0 : -1;
95 #elif defined(HAVE_MLOCK)
96 return mlock(mem, sz);
113 #if defined(MADV_DONTDUMP)
114 int rv = madvise(mem, sz, MADV_DONTDUMP);
117 }
else if (errno == ENOSYS || errno == EINVAL) {
146 int r = MINHERIT(mem, sz, FLAG_ZERO);
153 #ifdef FLAG_NOINHERIT
154 int r2 = MINHERIT(mem, sz, FLAG_NOINHERIT);
161 #if defined(FLAG_ZERO) || defined(FLAG_NOINHERIT)
164 if (errno == ENOSYS || errno == EINVAL) {
174 (void)inherit_result_out;
208 if (inherit_result_out == NULL) {
209 inherit_result_out = &itmp;
214 HANDLE mapping = CreateFileMapping(INVALID_HANDLE_VALUE,
220 raw_assert(mapping != NULL);
221 ptr = MapViewOfFile(mapping, FILE_MAP_WRITE,
225 CloseHandle(mapping);
226 #elif defined(HAVE_SYS_MMAN_H)
228 PROT_READ|PROT_WRITE,
229 MAP_ANON|MAP_PRIVATE,
231 raw_assert(ptr != MAP_FAILED);
232 raw_assert(ptr != NULL);
234 ptr = tor_malloc_zero(sz);
238 int lock_result =
lock_mem(ptr, sz);
239 raw_assert(lock_result == 0);
241 raw_assert(nodump_result == 0);
245 int noinherit_result =
noinherit_mem(ptr, sz, inherit_result_out);
246 raw_assert(noinherit_result == 0);
264 UnmapViewOfFile(mapping);
265 #elif defined(HAVE_SYS_MMAN_H)
Headers for util_malloc.c.
static int noinherit_mem(void *mem, size_t sz, inherit_res_t *inherit_result_out)
static int nodump_mem(void *mem, size_t sz)
#define HIGH_SIZE_T_BYTES(sz)
void tor_munmap_anonymous(void *mapping, size_t sz)
static int lock_mem(void *mem, size_t sz)
void * tor_mmap_anonymous(size_t sz, unsigned flags, inherit_res_t *inherit_result_out)
#define ANONMAP_NOINHERIT
void tor_log_err_sigsafe(const char *m,...)