Skip to content

Commit

Permalink
Hidden segmentation fault catch mechanism implementation on Windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
nthnn committed Dec 21, 2024
1 parent 91c2b3e commit c3b5255
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/N8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ auto printBanner(N8Util::ArgumentParser argParse) -> void {
}

auto main(int argc, char** argv) -> int {
#if defined(__linux__) || defined(__APPLE__)
Runtime::catchSegfault();
#endif

N8Util::ArgumentParser argParse(argc, argv);
argParse.defineParameter("h", "help", "Show this help banner.");
Expand Down
9 changes: 7 additions & 2 deletions src/n8/core/Runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ void Runtime::catchSegfault() {
sigaction(SIGSEGV, &sa, NULL);
}

#if defined(__linux__) || defined(__APPLE__)
void Runtime::segfaultHandler(
int signal,
siginfo_t *si,
Expand All @@ -397,14 +398,18 @@ void Runtime::segfaultHandler(
std::cout << "\u001b[1;31mSending process ID\u001b[0m:\t" << si->si_pid << "\n";
std::cout << "\u001b[1;31mReal user ID\u001b[0m:\t\t" << si->si_uid << "\n";
std::cout << "\u001b[1;31mExit value\u001b[0m:\t\t\t" << si->si_status << "\n";
std::cout << "\u001b[1;31mBand event\u001b[0m:\t\t\t" << si->si_band << "\n";
std::cout << "\u001b[1;31mFaulting address\u001b[0m:\t" << si->si_addr << "\n";

#ifndef __APPLE__
std::cout << "\u001b[1;31mTimer overrun\u001b[0m:\t\t" << si->si_overrun << "\n";
std::cout << "\u001b[1;31mTimer ID\u001b[0m:\t\t\t" << si->si_timerid << "\n";
std::cout << "\u001b[1;31mBand event\u001b[0m:\t\t\t" << si->si_band << "\n";
std::cout << "\u001b[1;31mFile descriptor\u001b[0m:\t" << si->si_fd << "\n";
std::cout << "\u001b[1;31mFaulting address\u001b[0m:\t" << si->si_addr << "\n";
#endif

std::exit(1);
}
#endif

#else

Expand Down

0 comments on commit c3b5255

Please sign in to comment.