From df06b3da910cb1b8d484ec8050e18152af6bfcce Mon Sep 17 00:00:00 2001 From: Nikolay Igotti Date: Thu, 14 Nov 2024 12:20:14 +0300 Subject: [PATCH 1/4] Crash on more signals Signed-off-by: Nikolay Igotti --- interop/src/cpp/common-interop.cc | 7 +++++++ interop/src/cpp/crashdump.h | 17 ++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/interop/src/cpp/common-interop.cc b/interop/src/cpp/common-interop.cc index 64a6595f6..cd9ddce22 100644 --- a/interop/src/cpp/common-interop.cc +++ b/interop/src/cpp/common-interop.cc @@ -19,6 +19,7 @@ #include "common-interop.h" #include "interop-logging.h" #include "dynamic-loader.h" +#include "crashdump.h" #if KOALA_INTEROP_PROFILER #include "profiler.h" @@ -118,6 +119,7 @@ void getKoalaJniCallbackDispatcher(jclass* clazz, jmethodID* method) { #endif KInt impl_StringLength(KNativePointer ptr) { + *(int*)1 = 1; string* s = reinterpret_cast(ptr); return s->length(); } @@ -296,3 +298,8 @@ void impl_NativeLog(const KStringPtr& str) { #endif } KOALA_INTEROP_V1(NativeLog, KStringPtr) + +void impl_InstallCrashHandlers() { + installCrashHandlers(); +} +KOALA_INTEROP_V0(InstallCrashHandlers) diff --git a/interop/src/cpp/crashdump.h b/interop/src/cpp/crashdump.h index 128f7ba61..96cbc06cb 100644 --- a/interop/src/cpp/crashdump.h +++ b/interop/src/cpp/crashdump.h @@ -20,19 +20,30 @@ #include #include -sighandler_t oldCrashHandler = nullptr; +static sighandler_t oldCrashHandlers[16] = { 0 }; static void onCrashHandler(int signo) { void* stack[20]; size_t size = backtrace(stack, 20); + fprintf(stderr, "FATAL: crash with signal %d\n", signo); backtrace_symbols_fd(stack, size, STDERR_FILENO); - if (oldCrashHandler) oldCrashHandler(signo); + if (signo < 16 && + oldCrashHandlers[signo] && + oldCrashHandlers[signo] != SIG_IGN && + oldCrashHandlers[signo] != SIG_DFL) { + oldCrashHandlers[signo](signo); + } else { + fprintf(stderr, "aborting\n"); + abort(); + } } static void installCrashHandlers() { static bool installed = false; if (!installed) { - oldCrashHandler = signal(SIGSEGV, onCrashHandler); + oldCrashHandlers[SIGSEGV] = signal(SIGSEGV, onCrashHandler); + oldCrashHandlers[SIGBUS] = signal(SIGBUS, onCrashHandler); + oldCrashHandlers[SIGILL] = signal(SIGILL, onCrashHandler); installed = true; } } -- Gitee From bf79b16789b8b7dcde311e7e33a0b32093840351 Mon Sep 17 00:00:00 2001 From: Nikolay Igotti Date: Thu, 14 Nov 2024 12:21:12 +0300 Subject: [PATCH 2/4] Fix Signed-off-by: Nikolay Igotti --- interop/src/cpp/common-interop.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/interop/src/cpp/common-interop.cc b/interop/src/cpp/common-interop.cc index cd9ddce22..51a237574 100644 --- a/interop/src/cpp/common-interop.cc +++ b/interop/src/cpp/common-interop.cc @@ -119,7 +119,6 @@ void getKoalaJniCallbackDispatcher(jclass* clazz, jmethodID* method) { #endif KInt impl_StringLength(KNativePointer ptr) { - *(int*)1 = 1; string* s = reinterpret_cast(ptr); return s->length(); } -- Gitee From e68c20171084f8d44febd4b78035b4114abc1bca Mon Sep 17 00:00:00 2001 From: Nikolay Igotti Date: Thu, 14 Nov 2024 12:39:37 +0300 Subject: [PATCH 3/4] Temp Signed-off-by: Nikolay Igotti --- interop/src/cpp/common-interop.cc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/interop/src/cpp/common-interop.cc b/interop/src/cpp/common-interop.cc index 51a237574..f25979e40 100644 --- a/interop/src/cpp/common-interop.cc +++ b/interop/src/cpp/common-interop.cc @@ -302,3 +302,11 @@ void impl_InstallCrashHandlers() { installCrashHandlers(); } KOALA_INTEROP_V0(InstallCrashHandlers) + +#if 1 +// Enable this code if you need to debug early crashes. +__attribute__((constructor)) +static void installCrashHandlersAtStartup() { + installCrashHandlers(); +} +#endif \ No newline at end of file -- Gitee From d60997eedc83d0faec87dba926a3df138ec56323 Mon Sep 17 00:00:00 2001 From: Nikolay Igotti Date: Thu, 14 Nov 2024 15:54:55 +0300 Subject: [PATCH 4/4] Temporary disable Signed-off-by: Nikolay Igotti --- interop/src/cpp/common-interop.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interop/src/cpp/common-interop.cc b/interop/src/cpp/common-interop.cc index f25979e40..26ca369a4 100644 --- a/interop/src/cpp/common-interop.cc +++ b/interop/src/cpp/common-interop.cc @@ -303,7 +303,7 @@ void impl_InstallCrashHandlers() { } KOALA_INTEROP_V0(InstallCrashHandlers) -#if 1 +#if 0 // Enable this code if you need to debug early crashes. __attribute__((constructor)) static void installCrashHandlersAtStartup() { -- Gitee