From 8f4ca193b8083ebc2cf083bbbfead35ede217a61 Mon Sep 17 00:00:00 2001 From: Zhengyu Gu Date: Mon, 22 Sep 2025 15:27:01 -0400 Subject: [PATCH 1/2] Fix MacOSX signal handler --- ddprof-lib/src/main/cpp/os_dd.h | 6 +++--- ddprof-lib/src/main/cpp/os_macos_dd.cpp | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ddprof-lib/src/main/cpp/os_dd.h b/ddprof-lib/src/main/cpp/os_dd.h index 3a897d0ce..f3aeb4623 100644 --- a/ddprof-lib/src/main/cpp/os_dd.h +++ b/ddprof-lib/src/main/cpp/os_dd.h @@ -7,12 +7,12 @@ namespace ddprof { class OS : public ::OS { public: - inline static SigAction replaceSigsegvHandler(SigAction action) { + static SigAction replaceSigsegvHandler(SigAction action); + + inline static SigAction replaceSigbusHandler(SigAction action) { return ::OS::replaceCrashHandler(action); } - static SigAction replaceSigbusHandler(SigAction action); - inline static int getMaxThreadId(int floor) { int maxThreadId = ::OS::getMaxThreadId(); return maxThreadId < floor ? floor : maxThreadId; diff --git a/ddprof-lib/src/main/cpp/os_macos_dd.cpp b/ddprof-lib/src/main/cpp/os_macos_dd.cpp index fa8ad2c9e..f56a237c2 100644 --- a/ddprof-lib/src/main/cpp/os_macos_dd.cpp +++ b/ddprof-lib/src/main/cpp/os_macos_dd.cpp @@ -16,12 +16,12 @@ void ddprof::OS::mallocArenaMax(int arena_max) { // Not supported on macOS } -SigAction ddprof::OS::replaceSigbusHandler(SigAction action) { +SigAction ddprof::OS::replaceSigsegvHandler(SigAction action) { struct sigaction sa; - sigaction(SIGBUS, NULL, &sa); + sigaction(SIGSEGV, NULL, &sa); SigAction old_action = sa.sa_sigaction; sa.sa_sigaction = action; - sigaction(SIGBUS, &sa, NULL); + sigaction(SIGSEGV, &sa, NULL); return old_action; } From d61f338737250755163697524120e60504be23f2 Mon Sep 17 00:00:00 2001 From: Zhengyu Gu Date: Mon, 22 Sep 2025 16:05:30 -0400 Subject: [PATCH 2/2] Fix --- ddprof-lib/src/main/cpp/os_dd.h | 5 +---- ddprof-lib/src/main/cpp/os_linux_dd.cpp | 4 ++++ ddprof-lib/src/main/cpp/os_macos_dd.cpp | 4 ++++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/ddprof-lib/src/main/cpp/os_dd.h b/ddprof-lib/src/main/cpp/os_dd.h index f3aeb4623..c9f6b0345 100644 --- a/ddprof-lib/src/main/cpp/os_dd.h +++ b/ddprof-lib/src/main/cpp/os_dd.h @@ -8,10 +8,7 @@ namespace ddprof { class OS : public ::OS { public: static SigAction replaceSigsegvHandler(SigAction action); - - inline static SigAction replaceSigbusHandler(SigAction action) { - return ::OS::replaceCrashHandler(action); - } + static SigAction replaceSigbusHandler(SigAction action); inline static int getMaxThreadId(int floor) { int maxThreadId = ::OS::getMaxThreadId(); diff --git a/ddprof-lib/src/main/cpp/os_linux_dd.cpp b/ddprof-lib/src/main/cpp/os_linux_dd.cpp index 56bb2b569..e28f7f0db 100644 --- a/ddprof-lib/src/main/cpp/os_linux_dd.cpp +++ b/ddprof-lib/src/main/cpp/os_linux_dd.cpp @@ -29,6 +29,10 @@ void ddprof::OS::mallocArenaMax(int arena_max) { #endif } +SigAction ddprof::OS::replaceSigsegvHandler(SigAction action) { + return ::OS::replaceCrashHandler(action); +} + SigAction ddprof::OS::replaceSigbusHandler(SigAction action) { struct sigaction sa; sigaction(SIGBUS, NULL, &sa); diff --git a/ddprof-lib/src/main/cpp/os_macos_dd.cpp b/ddprof-lib/src/main/cpp/os_macos_dd.cpp index f56a237c2..7a9c090b7 100644 --- a/ddprof-lib/src/main/cpp/os_macos_dd.cpp +++ b/ddprof-lib/src/main/cpp/os_macos_dd.cpp @@ -16,6 +16,10 @@ void ddprof::OS::mallocArenaMax(int arena_max) { // Not supported on macOS } +SigAction ddprof::OS::replaceSigbusHandler(SigAction action) { + return ::OS::replaceCrashHandler(action); +} + SigAction ddprof::OS::replaceSigsegvHandler(SigAction action) { struct sigaction sa; sigaction(SIGSEGV, NULL, &sa);