Attempt to 'JLI_Launch' for JVDroid OpenJDK

This commit is contained in:
khanhduytran0 2020-08-27 17:37:07 +07:00
parent 588594d2d8
commit 46f9d1aa88
3 changed files with 36 additions and 13 deletions

View File

@ -55,9 +55,9 @@ public class YggdrasilAuthenticator {
return this.gson.fromJson(outString, responseClass); return this.gson.fromJson(outString, responseClass);
} }
throw new RuntimeException("Invalid username or password"); throw new RuntimeException("Invalid username or password, status code: " + statusCode);
} catch (UnknownHostException e) { } catch (UnknownHostException e) {
throw new RuntimeException("Can't connect to the server"); throw new RuntimeException("Can't connect to the server", e);
} catch (Throwable th2) { } catch (Throwable th2) {
th = th2; th = th2;
if (is != null) { if (is != null) {

View File

@ -33,7 +33,8 @@ public class BinaryExecutor
public static native void setLdLibraryPath(String ldLibraryPath); public static native void setLdLibraryPath(String ldLibraryPath);
public static native void setupBridgeEGL(); public static native void setupBridgeEGL();
// Load and execute PIE binary using dlopen and dlsym("main") // BEFORE Load and execute PIE binary using dlopen and dlsym("main")
// AFTER: Execute a binary in forked process
public static native int executeBinary(String[] args); public static native int executeBinary(String[] args);
static { static {

View File

@ -122,8 +122,9 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
private boolean isLogAllow = false; private boolean isLogAllow = false;
private int navBarHeight = 40; private int navBarHeight = 40;
private static final int LTYPE_INVOCATION = 0; private static final int LTYPE_PROCESS = 0;
private static final int LTYPE_PROCESS = 1; private static final int LTYPE_INVOCATION = 1;
private static final int LTYPE_BINARYEXEC = 2;
private final int LAUNCH_TYPE = LTYPE_INVOCATION; private final int LAUNCH_TYPE = LTYPE_INVOCATION;
// LTYPE_INVOCATION; // LTYPE_INVOCATION;
@ -238,7 +239,7 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
// Menu // Menu
drawerLayout = (DrawerLayout) findViewById(R.id.main_drawer_options); drawerLayout = (DrawerLayout) findViewById(R.id.main_drawer_options);
navDrawer = (NavigationView) findViewById(R.id.main_navigation_view); navDrawer = findViewById(R.id.main_navigation_view);
navDrawer.setNavigationItemSelectedListener( navDrawer.setNavigationItemSelectedListener(
new NavigationView.OnNavigationItemSelectedListener() { new NavigationView.OnNavigationItemSelectedListener() {
@Override @Override
@ -1002,17 +1003,20 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
String[] launchArgs = getMCArgs(); String[] launchArgs = getMCArgs();
List<String> javaArgList = new ArrayList<String>(); List<String> javaArgList = new ArrayList<String>();
/*
if (LAUNCH_TYPE == LTYPE_PROCESS) javaArgList.add(Tools.homeJreDir + "/bin/java"); if (LAUNCH_TYPE == LTYPE_PROCESS || LAUNCH_TYPE == LTYPE_BINARYEXEC) javaArgList.add(Tools.homeJreDir + "/bin/java");
else javaArgList.add("java"); else javaArgList.add("java");
*/
javaArgList.add(Tools.homeJreDir + "/bin/java");
// javaArgList.add("-Xms512m"); // javaArgList.add("-Xms512m");
javaArgList.add("-Xmx512m"); javaArgList.add("-Xmx512m");
/*
javaArgList.add("-Djava.library.path=" + javaArgList.add("-Djava.library.path=" +
// TODO lwjgl2 vs lwjgl3 native path // TODO lwjgl2 vs lwjgl3 native path
getApplicationInfo().nativeLibraryDir getApplicationInfo().nativeLibraryDir
); );
*/
javaArgList.add("-Dos.name=Linux"); javaArgList.add("-Dos.name=Linux");
// javaArgList.add("-Dorg.lwjgl.system.jemalloc.libname=libjemalloc.so"); // javaArgList.add("-Dorg.lwjgl.system.jemalloc.libname=libjemalloc.so");
@ -1068,6 +1072,9 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
setEnvironment("MESA_GLSL_CACHE_DIR", getCacheDir().getAbsolutePath()); setEnvironment("MESA_GLSL_CACHE_DIR", getCacheDir().getAbsolutePath());
setEnvironment("LD_LIBRARY_PATH", "$JAVA_HOME/lib:$JAVA_HOME/lib/jli:$JAVA_HOME/lib/server"); setEnvironment("LD_LIBRARY_PATH", "$JAVA_HOME/lib:$JAVA_HOME/lib/jli:$JAVA_HOME/lib/server");
// can fix java?
setEnvironment("ORIGIN", "$JAVA_HOME/lib");
if (LAUNCH_TYPE == LTYPE_PROCESS) { if (LAUNCH_TYPE == LTYPE_PROCESS) {
mLaunchShell.writeToProcess("cd $HOME"); mLaunchShell.writeToProcess("cd $HOME");
@ -1076,7 +1083,7 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
if (exitCode != 0) { if (exitCode != 0) {
Tools.showError(this, new ErrnoException("java", exitCode), false); Tools.showError(this, new ErrnoException("java", exitCode), false);
} }
} else { // Type Invocation } else { // Type Invocation or BinaryExec
final FileDescriptor logFile = BinaryExecutor.redirectStdio(); final FileDescriptor logFile = BinaryExecutor.redirectStdio();
new Thread(new Runnable() { new Thread(new Runnable() {
@ -1096,7 +1103,7 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
}, "RuntimeLogThread").start(); }, "RuntimeLogThread").start();
String libName = System.getProperty("os.arch").contains("64") ? "lib64" : "lib"; String libName = System.getProperty("os.arch").contains("64") ? "lib64" : "lib";
BinaryExecutor.setLdLibraryPath( String ldLibraryPath = (
"/system/" + libName + ":" + "/system/" + libName + ":" +
"/vendor/" + libName + ":" + "/vendor/" + libName + ":" +
"/vendor/" + libName + "/hw:" + "/vendor/" + libName + "/hw:" +
@ -1106,6 +1113,9 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
Tools.homeJreDir + "/lib/server:" + Tools.homeJreDir + "/lib/server:" +
Tools.homeJreDir + "/lib" Tools.homeJreDir + "/lib"
); );
BinaryExecutor.setLdLibraryPath(ldLibraryPath);
Os.setenv("LD_LIBRARY_PATH", ldLibraryPath, true);
BinaryExecutor.initJavaRuntime(); BinaryExecutor.initJavaRuntime();
BinaryExecutor.chdir(Tools.MAIN_PATH); BinaryExecutor.chdir(Tools.MAIN_PATH);
@ -1113,7 +1123,19 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
startStrace(android.os.Process.myTid()); startStrace(android.os.Process.myTid());
} }
VMLauncher.launchJVM(javaArgList.toArray(new String[0])); if (LAUNCH_TYPE == LTYPE_BINARYEXEC) {
BinaryExecutor.executeBinary(javaArgList.toArray(new String[0]));
} else {
// Test
/*
VMLauncher.launchJVM(new String[]{
Tools.homeJreDir + "/bin/java",
"-invalidarg"
});
*/
VMLauncher.launchJVM(javaArgList.toArray(new String[0]));
}
} }
} }