JVM Halt через несуществующий нативный метод

This commit is contained in:
Gravit 2018-10-25 15:57:58 +07:00
parent d6f203d9bf
commit a944282469
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
4 changed files with 37 additions and 4 deletions

View file

@ -9,6 +9,7 @@
import net.minecraftforge.fml.SafeExitJVM; import net.minecraftforge.fml.SafeExitJVM;
import ru.gravit.launcher.hasher.DirWatcher; import ru.gravit.launcher.hasher.DirWatcher;
import ru.gravit.launcher.hasher.HashedDir; import ru.gravit.launcher.hasher.HashedDir;
import ru.gravit.utils.NativeJVMHalt;
import ru.gravit.utils.helper.CommonHelper; import ru.gravit.utils.helper.CommonHelper;
import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.IOHelper;
import ru.gravit.utils.helper.JVMHelper; import ru.gravit.utils.helper.JVMHelper;
@ -51,11 +52,19 @@ public void run() {
static void safeHalt(int exitcode) static void safeHalt(int exitcode)
{ {
try { try {
SafeExitJVM.exit(exitcode);
} catch (Throwable e)
{
SafeExitJVMLegacy.exit(exitcode); SafeExitJVMLegacy.exit(exitcode);
} catch (Throwable ignored)
{
} }
try {
SafeExitJVM.exit(exitcode);
} catch (Throwable ignored)
{
}
NativeJVMHalt halt = new NativeJVMHalt(exitcode);
halt.halt();
} }
public static final String NAME = Launcher.getConfig().projectname; public static final String NAME = Launcher.getConfig().projectname;

View file

@ -19,6 +19,7 @@
import net.minecraftforge.fml.SafeExitJVM; import net.minecraftforge.fml.SafeExitJVM;
import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.LauncherAPI;
import ru.gravit.launcher.hasher.HashedEntry.Type; import ru.gravit.launcher.hasher.HashedEntry.Type;
import ru.gravit.utils.NativeJVMHalt;
import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.IOHelper;
import ru.gravit.utils.helper.JVMHelper; import ru.gravit.utils.helper.JVMHelper;
import ru.gravit.utils.helper.JVMHelper.OS; import ru.gravit.utils.helper.JVMHelper.OS;
@ -72,8 +73,16 @@ private static void handleError(Throwable e) {
SafeExitJVMLegacy.exit(-123); SafeExitJVMLegacy.exit(-123);
} catch (Throwable ignored) } catch (Throwable ignored)
{ {
SafeExitJVM.exit(-123);
} }
try {
SafeExitJVM.exit(-123);
} catch (Throwable ignored)
{
}
NativeJVMHalt halt = new NativeJVMHalt(-123);
halt.halt();
} }
private static Deque<String> toPath(Iterable<Path> path) { private static Deque<String> toPath(Iterable<Path> path) {

View file

@ -0,0 +1,14 @@
package ru.gravit.utils;
import ru.gravit.utils.helper.LogHelper;
public class NativeJVMHalt {
public NativeJVMHalt(int haltCode) {
this.haltCode = haltCode;
LogHelper.error("JVM exit code %d",haltCode);
halt();
}
public int haltCode;
public native void halt();
}

View file

@ -118,6 +118,7 @@ public static URL[] getClassPathURL() {
} }
public static void checkStackTrace(Class mainClass) public static void checkStackTrace(Class mainClass)
{ {
LogHelper.debug("Testing stacktrace");
Exception e = new Exception("Testing stacktrace"); Exception e = new Exception("Testing stacktrace");
StackTraceElement[] list = e.getStackTrace(); StackTraceElement[] list = e.getStackTrace();
if(!list[list.length - 1].getClassName().equals(mainClass.getName())) if(!list[list.length - 1].getClassName().equals(mainClass.getName()))