| 230 | } |
| 231 | |
| 232 | extern "C" BOOST_SYMBOL_EXPORT |
| 233 | void* __cxa_allocate_exception(size_t thrown_size) throw() { |
| 234 | static const auto orig_allocate_exception = []() { |
| 235 | void* const ptr = ::dlsym(RTLD_NEXT, "__cxa_allocate_exception"); |
| 236 | BOOST_ASSERT_MSG(ptr, "Failed to find '__cxa_allocate_exception'"); |
| 237 | return reinterpret_cast<void*(*)(size_t)>(ptr); |
| 238 | }(); |
| 239 | |
| 240 | if (!boost::stacktrace::impl::ref_capture_stacktraces_at_throw()) { |
| 241 | return orig_allocate_exception(thrown_size); |
| 242 | } |
| 243 | |
| 244 | #ifndef NDEBUG |
| 245 | static thread_local std::size_t in_allocate_exception = 0; |
| 246 | BOOST_ASSERT_MSG(in_allocate_exception < 10, "Suspicious recursion"); |
| 247 | ++in_allocate_exception; |
| 248 | const decrement_on_destroy guard{in_allocate_exception}; |
| 249 | #endif |
| 250 | |
| 251 | static constexpr std::size_t kAlign = alignof(std::max_align_t); |
| 252 | thrown_size = (thrown_size + kAlign - 1) & (~(kAlign - 1)); |
| 253 | |
| 254 | void* const ptr = orig_allocate_exception(thrown_size + kStacktraceDumpSize); |
| 255 | char* const dump_ptr = static_cast<char*>(ptr) + thrown_size; |
| 256 | |
| 257 | constexpr size_t kSkip = 1; |
| 258 | boost::stacktrace::safe_dump_to(kSkip, dump_ptr, kStacktraceDumpSize); |
| 259 | |
| 260 | #if !BOOST_STACKTRACE_ALWAYS_STORE_IN_PADDING |
| 261 | if (is_libcpp_runtime()) { |
| 262 | const std::lock_guard<std::mutex> guard{g_mapping_mutex}; |
| 263 | g_exception_to_dump_mapping[ptr] = dump_ptr; |
| 264 | } else |
| 265 | #endif |
| 266 | { |
| 267 | BOOST_ASSERT_MSG( |
| 268 | reference_to_empty_padding(ptr) == nullptr, |
| 269 | "Not zeroed out, unsupported implementation" |
| 270 | ); |
| 271 | reference_to_empty_padding(ptr) = dump_ptr; |
| 272 | } |
| 273 | |
| 274 | return ptr; |
| 275 | } |
| 276 | |
| 277 | #if !BOOST_STACKTRACE_ALWAYS_STORE_IN_PADDING |
| 278 |
nothing calls this directly
no test coverage detected