mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-18 09:07:48 -04:00
Attempt to redirect signal handler to JVM
This commit is contained in:
parent
2f294a9002
commit
ad726d1006
@ -48,13 +48,22 @@ static const jboolean const_javaw = JNI_FALSE;
|
||||
static const jboolean const_cpwildcard = JNI_TRUE;
|
||||
static const jint const_ergo_class = 0; // DEFAULT_POLICY
|
||||
static struct sigaction old_sa[NSIG];
|
||||
|
||||
void (*__old_sa)(int signal, siginfo_t *info, void *reserved);
|
||||
void android_sigaction(int signal, siginfo_t *info, void *reserved)
|
||||
{
|
||||
printf("process killed with signal %d code %p addr %p", signal,info->si_code,info->si_addr);
|
||||
__old_sa = old_sa[signal].sa_sigaction;
|
||||
__old_sa(signal,info,reserved);
|
||||
exit(1);
|
||||
int (*JVM_handle_linux_signal)(int signo, siginfo_t* siginfo, void* ucontext, int abort_if_unrecognized);
|
||||
|
||||
void android_sigaction(int signal, siginfo_t *info, void *reserved) {
|
||||
if (JVM_handle_linux_signal == NULL) { // should not happen, but still
|
||||
printf("process killed with signal %d code %p addr %p", signal,info->si_code,info->si_addr);
|
||||
__old_sa = old_sa[signal].sa_sigaction;
|
||||
__old_sa(signal,info,reserved);
|
||||
exit(1);
|
||||
} else {
|
||||
// Based on https://github.com/PojavLauncherTeam/openjdk-multiarch-jdk8u/blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/os/linux/vm/os_linux.cpp#L4688-4693
|
||||
int orig_errno = errno; // Preserve errno value over signal handler.
|
||||
JVM_handle_linux_signal(signal, info, reserved, true);
|
||||
errno = orig_errno;
|
||||
}
|
||||
}
|
||||
typedef jint JNI_CreateJavaVM_func(JavaVM **pvm, void **penv, void *args);
|
||||
|
||||
@ -117,21 +126,30 @@ static jint launchJVM(int margc, char** margv) {
|
||||
* Signature: ([Ljava/lang/String;)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_com_oracle_dalvik_VMLauncher_launchJVM(JNIEnv *env, jclass clazz, jobjectArray argsArray) {
|
||||
void* libjvm = dlopen("libjvm.so", RTLD_LAZY | RTLD_GLOBAL);
|
||||
if (NULL == libjvm) {
|
||||
LOGE("JVM lib = NULL: %s", dlerror());
|
||||
return -1;
|
||||
}
|
||||
JVM_handle_linux_signal = dlsym(libjvm, "JVM_handle_linux_signal");
|
||||
|
||||
jint res = 0;
|
||||
// int i;
|
||||
//Prepare the signal trapper
|
||||
struct sigaction catcher;
|
||||
memset(&catcher,0,sizeof(sigaction));
|
||||
catcher.sa_sigaction = android_sigaction;
|
||||
catcher.sa_flags = SA_RESETHAND;
|
||||
catcher.sa_flags = SA_SIGINFO|SA_RESTART;
|
||||
// SA_RESETHAND;
|
||||
#define CATCHSIG(X) sigaction(X, &catcher, &old_sa[X])
|
||||
CATCHSIG(SIGILL);
|
||||
CATCHSIG(SIGABRT);
|
||||
CATCHSIG(SIGBUS);
|
||||
CATCHSIG(SIGFPE);
|
||||
//CATCHSIG(SIGSEGV);
|
||||
CATCHSIG(SIGSEGV);
|
||||
CATCHSIG(SIGSTKFLT);
|
||||
CATCHSIG(SIGPIPE);
|
||||
CATCHSIG(SIGXFSZ);
|
||||
//Signal trapper ready
|
||||
|
||||
// Save dalvik JNIEnv pointer for JVM launch thread
|
||||
|
Loading…
x
Reference in New Issue
Block a user