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.
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /*
8 * A poison value that can be used to fill a memory space with
9 * an address that leads to a safe crash when dereferenced.
10 */
12 #ifndef mozilla_Poison_h
13 #define mozilla_Poison_h
15 #include "mozilla/Assertions.h"
16 #include "mozilla/Types.h"
18 #include <stdint.h>
20 MOZ_BEGIN_EXTERN_C
22 extern MFBT_DATA uintptr_t gMozillaPoisonValue;
24 /**
25 * @return the poison value.
26 */
27 inline uintptr_t mozPoisonValue()
28 {
29 return gMozillaPoisonValue;
30 }
32 /**
33 * Overwrite the memory block of aSize bytes at aPtr with the poison value.
34 * aPtr MUST be aligned at a sizeof(uintptr_t) boundary.
35 * Only an even number of sizeof(uintptr_t) bytes are overwritten, the last
36 * few bytes (if any) is not overwritten.
37 */
38 inline void mozWritePoison(void* aPtr, size_t aSize)
39 {
40 const uintptr_t POISON = mozPoisonValue();
41 char* p = (char*)aPtr;
42 char* limit = p + aSize;
43 MOZ_ASSERT((uintptr_t)aPtr % sizeof(uintptr_t) == 0, "bad alignment");
44 MOZ_ASSERT(aSize >= sizeof(uintptr_t), "poisoning this object has no effect");
45 for (; p < limit; p += sizeof(uintptr_t)) {
46 *((uintptr_t*)p) = POISON;
47 }
48 }
50 /**
51 * Initialize the poison value.
52 * This should only be called once.
53 */
54 extern MFBT_API void mozPoisonValueInit();
56 /* Values annotated by CrashReporter */
57 extern MFBT_DATA uintptr_t gMozillaPoisonBase;
58 extern MFBT_DATA uintptr_t gMozillaPoisonSize;
60 MOZ_END_EXTERN_C
62 #endif /* mozilla_Poison_h */