22
22
#if HWASAN_REPLACE_OPERATORS_NEW_AND_DELETE
23
23
24
24
// TODO(alekseys): throw std::bad_alloc instead of dying on OOM.
25
- #define OPERATOR_NEW_BODY (nothrow ) \
26
- GET_MALLOC_STACK_TRACE; \
27
- void *res = hwasan_malloc(size, &stack);\
28
- if (!nothrow && UNLIKELY(!res)) ReportOutOfMemory(size, &stack);\
29
- return res
30
- #define OPERATOR_NEW_ALIGN_BODY (nothrow ) \
31
- GET_MALLOC_STACK_TRACE; \
32
- void *res = hwasan_aligned_alloc(static_cast <uptr>(align), size, &stack); \
33
- if (!nothrow && UNLIKELY(!res)) \
34
- ReportOutOfMemory (size, &stack); \
35
- return res
36
-
37
- #define OPERATOR_DELETE_BODY \
38
- GET_MALLOC_STACK_TRACE; \
39
- if (ptr) hwasan_free(ptr, &stack)
25
+ # define OPERATOR_NEW_BODY (nothrow ) \
26
+ GET_MALLOC_STACK_TRACE; \
27
+ void *res = hwasan_malloc(size, &stack); \
28
+ if (!nothrow && UNLIKELY(!res)) \
29
+ ReportOutOfMemory (size, &stack); \
30
+ return res
31
+ # define OPERATOR_NEW_ALIGN_BODY (nothrow ) \
32
+ GET_MALLOC_STACK_TRACE; \
33
+ void *res = hwasan_aligned_alloc(static_cast <uptr>(align), size, &stack); \
34
+ if (!nothrow && UNLIKELY(!res)) \
35
+ ReportOutOfMemory (size, &stack); \
36
+ return res
37
+
38
+ # define OPERATOR_DELETE_BODY \
39
+ GET_MALLOC_STACK_TRACE; \
40
+ if (ptr) \
41
+ hwasan_free (ptr, &stack)
40
42
41
43
#elif defined(__ANDROID__)
42
44
43
45
// We don't actually want to intercept operator new and delete on Android, but
44
46
// since we previously released a runtime that intercepted these functions,
45
47
// removing the interceptors would break ABI. Therefore we simply forward to
46
48
// malloc and free.
47
- #define OPERATOR_NEW_BODY (nothrow ) return malloc(size)
48
- #define OPERATOR_DELETE_BODY free (ptr)
49
+ # define OPERATOR_NEW_BODY (nothrow ) return malloc(size)
50
+ # define OPERATOR_DELETE_BODY free (ptr)
49
51
50
52
#endif
51
53
@@ -55,26 +57,27 @@ using namespace __hwasan;
55
57
56
58
// Fake std::nothrow_t to avoid including <new>.
57
59
namespace std {
58
- struct nothrow_t {};
60
+ struct nothrow_t {};
59
61
} // namespace std
60
62
61
-
62
-
63
- INTERCEPTOR_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
64
- void *operator new (size_t size) { OPERATOR_NEW_BODY (false /* nothrow*/ ); }
65
- INTERCEPTOR_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
66
- void *operator new [](size_t size) { OPERATOR_NEW_BODY (false /* nothrow*/ ); }
67
- INTERCEPTOR_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
68
- void *operator new (size_t size, std::nothrow_t const &) {
63
+ INTERCEPTOR_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE void *operator new (size_t size) {
64
+ OPERATOR_NEW_BODY (false /* nothrow*/ );
65
+ }
66
+ INTERCEPTOR_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE void *operator new [](
67
+ size_t size) {
68
+ OPERATOR_NEW_BODY (false /* nothrow*/ );
69
+ }
70
+ INTERCEPTOR_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE void *operator new (
71
+ size_t size, std::nothrow_t const &) {
69
72
OPERATOR_NEW_BODY (true /* nothrow*/ );
70
73
}
71
- INTERCEPTOR_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
72
- void * operator new []( size_t size, std::nothrow_t const &) {
74
+ INTERCEPTOR_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE void * operator new [](
75
+ size_t size, std::nothrow_t const &) {
73
76
OPERATOR_NEW_BODY (true /* nothrow*/ );
74
77
}
75
78
76
- INTERCEPTOR_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE void operator delete (void *ptr)
77
- NOEXCEPT {
79
+ INTERCEPTOR_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE void operator delete (
80
+ void *ptr) NOEXCEPT {
78
81
OPERATOR_DELETE_BODY;
79
82
}
80
83
INTERCEPTOR_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE void operator delete[] (
0 commit comments