Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | /* |
michael@0 | 8 | * Provides a common interface to the ASan (AddressSanitizer) and Valgrind |
michael@0 | 9 | * functions used to mark memory in certain ways. In detail, the following |
michael@0 | 10 | * three macros are provided: |
michael@0 | 11 | * |
michael@0 | 12 | * MOZ_MAKE_MEM_NOACCESS - Mark memory as unsafe to access (e.g. freed) |
michael@0 | 13 | * MOZ_MAKE_MEM_UNDEFINED - Mark memory as accessible, with content undefined |
michael@0 | 14 | * MOZ_MAKE_MEM_DEFINED - Mark memory as accessible, with content defined |
michael@0 | 15 | * |
michael@0 | 16 | * With Valgrind in use, these directly map to the three respective Valgrind |
michael@0 | 17 | * macros. With ASan in use, the NOACCESS macro maps to poisoning the memory, |
michael@0 | 18 | * while the UNDEFINED/DEFINED macros unpoison memory. |
michael@0 | 19 | * |
michael@0 | 20 | * With no memory checker available, all macros expand to the empty statement. |
michael@0 | 21 | */ |
michael@0 | 22 | |
michael@0 | 23 | #ifndef mozilla_MemoryChecking_h |
michael@0 | 24 | #define mozilla_MemoryChecking_h |
michael@0 | 25 | |
michael@0 | 26 | #if defined(MOZ_VALGRIND) |
michael@0 | 27 | #include "valgrind/memcheck.h" |
michael@0 | 28 | #endif |
michael@0 | 29 | |
michael@0 | 30 | #if defined(MOZ_ASAN) || defined(MOZ_VALGRIND) |
michael@0 | 31 | #define MOZ_HAVE_MEM_CHECKS 1 |
michael@0 | 32 | #endif |
michael@0 | 33 | |
michael@0 | 34 | #if defined(MOZ_ASAN) |
michael@0 | 35 | #include <stddef.h> |
michael@0 | 36 | |
michael@0 | 37 | extern "C" { |
michael@0 | 38 | /* These definitions are usually provided through the |
michael@0 | 39 | * sanitizer/asan_interface.h header installed by ASan. |
michael@0 | 40 | */ |
michael@0 | 41 | void __asan_poison_memory_region(void const volatile *addr, size_t size) |
michael@0 | 42 | __attribute__((visibility("default"))); |
michael@0 | 43 | void __asan_unpoison_memory_region(void const volatile *addr, size_t size) |
michael@0 | 44 | __attribute__((visibility("default"))); |
michael@0 | 45 | |
michael@0 | 46 | #define MOZ_MAKE_MEM_NOACCESS(addr, size) \ |
michael@0 | 47 | __asan_poison_memory_region((addr), (size)) |
michael@0 | 48 | |
michael@0 | 49 | #define MOZ_MAKE_MEM_UNDEFINED(addr, size) \ |
michael@0 | 50 | __asan_unpoison_memory_region((addr), (size)) |
michael@0 | 51 | |
michael@0 | 52 | #define MOZ_MAKE_MEM_DEFINED(addr, size) \ |
michael@0 | 53 | __asan_unpoison_memory_region((addr), (size)) |
michael@0 | 54 | } |
michael@0 | 55 | #elif defined(MOZ_VALGRIND) |
michael@0 | 56 | #define MOZ_MAKE_MEM_NOACCESS(addr, size) \ |
michael@0 | 57 | VALGRIND_MAKE_MEM_NOACCESS((addr), (size)) |
michael@0 | 58 | |
michael@0 | 59 | #define MOZ_MAKE_MEM_UNDEFINED(addr, size) \ |
michael@0 | 60 | VALGRIND_MAKE_MEM_UNDEFINED((addr), (size)) |
michael@0 | 61 | |
michael@0 | 62 | #define MOZ_MAKE_MEM_DEFINED(addr, size) \ |
michael@0 | 63 | VALGRIND_MAKE_MEM_DEFINED((addr), (size)) |
michael@0 | 64 | #else |
michael@0 | 65 | |
michael@0 | 66 | #define MOZ_MAKE_MEM_NOACCESS(addr, size) do {} while(0) |
michael@0 | 67 | #define MOZ_MAKE_MEM_UNDEFINED(addr, size) do {} while(0) |
michael@0 | 68 | #define MOZ_MAKE_MEM_DEFINED(addr, size) do {} while(0) |
michael@0 | 69 | |
michael@0 | 70 | #endif |
michael@0 | 71 | |
michael@0 | 72 | #endif /* mozilla_MemoryChecking_h */ |