From 090bb0ab414a3a6083192bf7ac45552f00b5995b Mon Sep 17 00:00:00 2001 From: artdeell Date: Thu, 16 Jan 2025 21:55:38 +0300 Subject: [PATCH] Hack[jre_launcher]: raise SIGSEGV in abort handler to get backtrace --- app_pojavlauncher/src/main/jni/jre_launcher.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app_pojavlauncher/src/main/jni/jre_launcher.c b/app_pojavlauncher/src/main/jni/jre_launcher.c index 7ae251f923..722d1b8c17 100644 --- a/app_pojavlauncher/src/main/jni/jre_launcher.c +++ b/app_pojavlauncher/src/main/jni/jre_launcher.c @@ -82,8 +82,21 @@ _Noreturn static void* abort_waiter_thread(void* extraArg) { // Die nominal_exit(signal, true); } +static bool signal_vm_first = true; + +// Writes a string constant into stdout in a signal-safe fashion +#define PRINT_SIGSAFE(x) do { \ +const char msg[] = x; \ +write(STDOUT_FILENO, msg, sizeof(msg));\ +} while(0) _Noreturn static void abort_waiter_handler(int signal) { + if(signal_vm_first) { + signal_vm_first = false; + // This is nasty and evil, but does work + PRINT_SIGSAFE("SIGABRT occured! Raising SIGSEGV to generate backtrace\n"); + raise(SIGSEGV); + } // Write the final signal into the pipe and block forever. write(abort_waiter_data.pipe[1], &signal, sizeof(int)); while(1) {}