Thu, 15 Jan 2015 15:59:08 +0100
Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
1 #define MOZ_NONHEAP_CLASS __attribute__((annotate("moz_nonheap_class")))
2 #define MOZ_HEAP_ALLOCATOR \
3 _Pragma("GCC diagnostic push") \
4 _Pragma("GCC diagnostic ignored \"-Wgcc-compat\"") \
5 __attribute__((annotate("moz_heap_allocator"))) \
6 _Pragma("GCC diagnostic pop")
8 #include <stdlib.h>
9 #include <memory>
11 struct MOZ_NONHEAP_CLASS X {
12 };
14 void *operator new(size_t x, int qual) MOZ_HEAP_ALLOCATOR {
15 return ::operator new(x);
16 }
18 template <typename T>
19 T *customAlloc() MOZ_HEAP_ALLOCATOR {
20 T *arg = static_cast<T*>(malloc(sizeof(T)));
21 return new (arg) T();
22 }
24 template <typename T>
25 void misuseX(T q) {
26 X *foo = customAlloc<X>(); // expected-error {{variable of type 'X' is not valid on the heap}}
27 X *foo2 = new (100) X(); // expected-error {{variable of type 'X' is not valid on the heap}}
28 }