mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-19 01:27:18 -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 jboolean const_cpwildcard = JNI_TRUE;
|
||||||
static const jint const_ergo_class = 0; // DEFAULT_POLICY
|
static const jint const_ergo_class = 0; // DEFAULT_POLICY
|
||||||
static struct sigaction old_sa[NSIG];
|
static struct sigaction old_sa[NSIG];
|
||||||
|
|
||||||
void (*__old_sa)(int signal, siginfo_t *info, void *reserved);
|
void (*__old_sa)(int signal, siginfo_t *info, void *reserved);
|
||||||
void android_sigaction(int signal, siginfo_t *info, void *reserved)
|
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);
|
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 = old_sa[signal].sa_sigaction;
|
||||||
__old_sa(signal,info,reserved);
|
__old_sa(signal,info,reserved);
|
||||||
exit(1);
|
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);
|
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
|
* Signature: ([Ljava/lang/String;)I
|
||||||
*/
|
*/
|
||||||
JNIEXPORT jint JNICALL Java_com_oracle_dalvik_VMLauncher_launchJVM(JNIEnv *env, jclass clazz, jobjectArray argsArray) {
|
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;
|
jint res = 0;
|
||||||
// int i;
|
// int i;
|
||||||
//Prepare the signal trapper
|
//Prepare the signal trapper
|
||||||
struct sigaction catcher;
|
struct sigaction catcher;
|
||||||
memset(&catcher,0,sizeof(sigaction));
|
memset(&catcher,0,sizeof(sigaction));
|
||||||
catcher.sa_sigaction = android_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])
|
#define CATCHSIG(X) sigaction(X, &catcher, &old_sa[X])
|
||||||
CATCHSIG(SIGILL);
|
CATCHSIG(SIGILL);
|
||||||
CATCHSIG(SIGABRT);
|
CATCHSIG(SIGABRT);
|
||||||
CATCHSIG(SIGBUS);
|
CATCHSIG(SIGBUS);
|
||||||
CATCHSIG(SIGFPE);
|
CATCHSIG(SIGFPE);
|
||||||
//CATCHSIG(SIGSEGV);
|
CATCHSIG(SIGSEGV);
|
||||||
CATCHSIG(SIGSTKFLT);
|
CATCHSIG(SIGSTKFLT);
|
||||||
CATCHSIG(SIGPIPE);
|
CATCHSIG(SIGPIPE);
|
||||||
|
CATCHSIG(SIGXFSZ);
|
||||||
//Signal trapper ready
|
//Signal trapper ready
|
||||||
|
|
||||||
// Save dalvik JNIEnv pointer for JVM launch thread
|
// Save dalvik JNIEnv pointer for JVM launch thread
|
||||||
|
Loading…
x
Reference in New Issue
Block a user