Changeset View
Changeset View
Standalone View
Standalone View
lib/asan/asan_new_delete.cc
Show First 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | |||||
namespace std { | namespace std { | ||||
struct nothrow_t {}; | struct nothrow_t {}; | ||||
enum class align_val_t: size_t {}; | enum class align_val_t: size_t {}; | ||||
} // namespace std | } // namespace std | ||||
// TODO(alekseyshl): throw std::bad_alloc instead of dying on OOM. | // TODO(alekseyshl): throw std::bad_alloc instead of dying on OOM. | ||||
// For local pool allocation, align to SHADOW_GRANULARITY to match asan | // For local pool allocation, align to SHADOW_GRANULARITY to match asan | ||||
// allocator behavior. | // allocator behavior. | ||||
#define OPERATOR_NEW_BODY(type, nothrow) \ | #define OPERATOR_NEW_BODY(type, nothrow) \ | ||||
if (ALLOCATE_FROM_LOCAL_POOL) {\ | MAYBE_ALLOCATE_FROM_LOCAL_POOL(nothrow); \ | ||||
void *res = MemalignFromLocalPool(SHADOW_GRANULARITY, size);\ | |||||
if (!nothrow) CHECK(res);\ | |||||
return res;\ | |||||
}\ | |||||
GET_STACK_TRACE_MALLOC;\ | GET_STACK_TRACE_MALLOC; \ | ||||
void *res = asan_memalign(0, size, &stack, type);\ | void *res = asan_memalign(0, size, &stack, type); \ | ||||
if (!nothrow && UNLIKELY(!res)) ReportOutOfMemory(size, &stack);\ | if (!nothrow && UNLIKELY(!res)) \ | ||||
ReportOutOfMemory(size, &stack); \ | |||||
return res; | return res; | ||||
#define OPERATOR_NEW_BODY_ALIGN(type, nothrow) \ | #define OPERATOR_NEW_BODY_ALIGN(type, nothrow) \ | ||||
if (ALLOCATE_FROM_LOCAL_POOL) {\ | MAYBE_ALLOCATE_FROM_LOCAL_POOL(nothrow); \ | ||||
void *res = MemalignFromLocalPool((uptr)align, size);\ | |||||
if (!nothrow) CHECK(res);\ | |||||
return res;\ | |||||
}\ | |||||
GET_STACK_TRACE_MALLOC;\ | GET_STACK_TRACE_MALLOC; \ | ||||
void *res = asan_memalign((uptr)align, size, &stack, type);\ | void *res = asan_memalign((uptr)align, size, &stack, type); \ | ||||
if (!nothrow && UNLIKELY(!res)) ReportOutOfMemory(size, &stack);\ | if (!nothrow && UNLIKELY(!res)) \ | ||||
ReportOutOfMemory(size, &stack); \ | |||||
return res; | return res; | ||||
// On OS X it's not enough to just provide our own 'operator new' and | // On OS X it's not enough to just provide our own 'operator new' and | ||||
// 'operator delete' implementations, because they're going to be in the | // 'operator delete' implementations, because they're going to be in the | ||||
// runtime dylib, and the main executable will depend on both the runtime | // runtime dylib, and the main executable will depend on both the runtime | ||||
// dylib and libstdc++, each of those'll have its implementation of new and | // dylib and libstdc++, each of those'll have its implementation of new and | ||||
// delete. | // delete. | ||||
// To make sure that C++ allocation/deallocation operators are overridden on | // To make sure that C++ allocation/deallocation operators are overridden on | ||||
▲ Show 20 Lines • Show All 110 Lines • Show Last 20 Lines |