Skip to content

Commit

Permalink
detect macos crashlog recursion
Browse files Browse the repository at this point in the history
  • Loading branch information
qimiko committed Dec 28, 2024
1 parent 100be49 commit a69c4c2
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions loader/src/platform/mac/crashlog.mm
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
static ucontext_t* s_context = nullptr;
static size_t s_backtraceSize = 0;
static std::array<void*, FRAME_SIZE> s_backtrace;
static int s_crashIter = 0;

static std::string_view getSignalCodeString() {
switch(s_signal) {
Expand Down Expand Up @@ -169,6 +170,12 @@ size_t getImageSize(struct mach_header_64 const* header) {
}

extern "C" void signalHandler(int signal, siginfo_t* signalInfo, void* vcontext) {
if (s_crashIter > 3) {
// the crashlog crashed too much so maybe we shouldn't try
std::abort();
}
s_crashIter++;

auto context = reinterpret_cast<ucontext_t*>(vcontext);
s_backtraceSize = backtrace(s_backtrace.data(), FRAME_SIZE);

Expand All @@ -192,6 +199,8 @@ size_t getImageSize(struct mach_header_64 const* header) {
s_cv.notify_all();
std::unique_lock<std::mutex> lock(s_mutex);
s_cv.wait(lock, [] { return s_signal == 0; });

s_crashIter--;
std::_Exit(EXIT_FAILURE);
}

Expand Down

0 comments on commit a69c4c2

Please sign in to comment.