From d8a5cdfb78f79b8672e29a855b93729f361a6ddf Mon Sep 17 00:00:00 2001 From: Constantin Piber <59023762+cpiber@users.noreply.github.com> Date: Sun, 8 Feb 2026 21:05:06 +0100 Subject: [PATCH] catch_abort: Remove java interop & catch SIGILL (#1891) * catch_abort: Remove java interop It won't work anyway since we're exiting the thread immediately * catch_abort: Also catch SIGILL --- scripts/bundler.sh | 2 +- scripts/resources/catch_abort.c | 38 ++++----------------------------- 2 files changed, 5 insertions(+), 35 deletions(-) diff --git a/scripts/bundler.sh b/scripts/bundler.sh index 7e598306a..9109e5621 100755 --- a/scripts/bundler.sh +++ b/scripts/bundler.sh @@ -39,7 +39,7 @@ main() { download_launcher if [ ! -f scripts/resources/catch_abort.so ]; then - gcc -fPIC -I$JAVA_HOME/include -I$JAVA_HOME/include/linux -shared scripts/resources/catch_abort.c -lpthread -o scripts/resources/catch_abort.so + gcc -fPIC -shared scripts/resources/catch_abort.c -lpthread -o scripts/resources/catch_abort.so fi JRE_ZULU="25.30.17_25.0.1" diff --git a/scripts/resources/catch_abort.c b/scripts/resources/catch_abort.c index efe54923e..17b6870e3 100644 --- a/scripts/resources/catch_abort.c +++ b/scripts/resources/catch_abort.c @@ -1,52 +1,19 @@ // Linux only: -// Attempts to catch SIGTRAP, inform Java, then exit the thread instead of bringing down the whole process +// Attempts to catch SIGTRAP and exit the thread instead of bringing down the whole process #define _GNU_SOURCE #include -#include -#include #include #include #include #include -#include - -JavaVM *g_vm; - -void load_vm() { - if (g_vm) return; - JavaVM *vms[1]; - jsize n = 0; - // JNI_OnLoad won't be called when loaded via LD_PRELOAD, so attempt to find the VM now - if (JNI_GetCreatedJavaVMs(vms, 1, &n) == JNI_OK && n > 0) { - g_vm = vms[0]; - } -} - -jint throwThreadDeath(JNIEnv *env, char *message) { - char *className = "java/lang/UnknownError"; - jclass exClass = (*env)->FindClass(env, className); - if (exClass == NULL) return JNI_ERR; - return (*env)->ThrowNew(env, exClass, message); -} - void signalHandler(int signum, siginfo_t* si, void* uc) { void *retaddrs[64]; int n = backtrace(retaddrs, sizeof(retaddrs) / sizeof(retaddrs[0])); printf("\n### ABORT :: Backtrace: ###\n"); backtrace_symbols_fd(retaddrs, n, STDERR_FILENO); printf("### ABORT :: Exiting this thread. If this causes problems, please report the above backtrace to Suwayomi. ###\n\n"); - - load_vm(); - if (g_vm) { - JNIEnv *env; - jint getEnvStat = (*g_vm)->GetEnv(g_vm, (void**) &env, JNI_VERSION_1_2); - if (getEnvStat == JNI_EDETACHED) (*g_vm)->AttachCurrentThread(g_vm, (void**) &env, NULL); - jint exStat = throwThreadDeath(env, "SIGTRAP caught"); - if (exStat != 0) printf("Exception throwing failed: %d\n", exStat); - (*g_vm)->DetachCurrentThread(g_vm); - } pthread_exit(NULL); } @@ -59,4 +26,7 @@ void dlmain() { if (sigaction(SIGTRAP, &sa, NULL) != 0) { printf("[FATAL] sigaction failed\n"); } + if (sigaction(SIGILL, &sa, NULL) != 0) { + printf("[FATAL] sigaction failed\n"); + } }