VirGL: Attempt to workaround Android 7.0 dlopen bug(?)

This commit is contained in:
Duy Tran Khanh
2021-11-22 16:56:18 +07:00
parent d79a910d4b
commit 511ef3833c
3 changed files with 13 additions and 8 deletions

View File

@@ -772,10 +772,10 @@ bool loadSymbolsVirGL() {
loadSymbols();
config_renderer = RENDERER_VIRGL;
char* fileName = calloc(1, 1024);
// hack: set LD_LIBRARY_PATH back to workaround a dlopen bug(?) in Android 7.0
setLdLibraryPath(getenv("POJAV_NATIVEDIR"));
sprintf(fileName, "%s/libvirgl_test_server.so", getenv("POJAV_NATIVEDIR"));
void *handle = dlopen(fileName, RTLD_LAZY);
void *handle = dlopen("libvirgl_test_server.so", RTLD_LAZY);
printf("VirGL: libvirgl_test_server = %p\n", handle);
if (!handle) {
printf("VirGL: %s\n", dlerror());
@@ -783,7 +783,7 @@ bool loadSymbolsVirGL() {
vtest_main_p = dlsym(handle, "vtest_main");
vtest_swap_buffers_p = dlsym(handle, "vtest_swap_buffers");
free(fileName);
setLdLibraryPath(getenv("LD_LIBRARY_PATH"));
}
int pojavInit() {

View File

@@ -82,9 +82,7 @@ JNIEXPORT jint JNICALL Java_android_os_OpenJDKNativeRegister_nativeRegisterNativ
return (jint) result;
}
JNIEXPORT void JNICALL Java_net_kdt_pojavlaunch_utils_JREUtils_setLdLibraryPath(JNIEnv *env, jclass clazz, jstring ldLibraryPath) {
// jclass exception_cls = (*env)->FindClass(env, "java/lang/UnsatisfiedLinkError");
void setLdLibraryPath(const char* ldLibPathUtf) {
android_update_LD_LIBRARY_PATH_t android_update_LD_LIBRARY_PATH;
void *libdl_handle = dlopen("libdl.so", RTLD_LAZY);
@@ -99,8 +97,14 @@ JNIEXPORT void JNICALL Java_net_kdt_pojavlaunch_utils_JREUtils_setLdLibraryPath(
}
android_update_LD_LIBRARY_PATH = (android_update_LD_LIBRARY_PATH_t) updateLdLibPath;
const char* ldLibPathUtf = (*env)->GetStringUTFChars(env, ldLibraryPath, 0);
android_update_LD_LIBRARY_PATH(ldLibPathUtf);
}
JNIEXPORT void JNICALL Java_net_kdt_pojavlaunch_utils_JREUtils_setLdLibraryPath(JNIEnv *env, jclass clazz, jstring ldLibraryPath) {
// jclass exception_cls = (*env)->FindClass(env, "java/lang/UnsatisfiedLinkError");
const char* ldLibPathUtf = (*env)->GetStringUTFChars(env, ldLibraryPath, 0);
setLdLibraryPath(ldLibPathUtf);
(*env)->ReleaseStringUTFChars(env, ldLibraryPath, ldLibPathUtf);
}

View File

@@ -21,6 +21,7 @@ char** convert_to_char_array(JNIEnv *env, jobjectArray jstringArray);
jobjectArray convert_from_char_array(JNIEnv *env, char **charArray, int num_rows);
void free_char_array(JNIEnv *env, jobjectArray jstringArray, const char **charArray);
jstring convertStringJVM(JNIEnv* srcEnv, JNIEnv* dstEnv, jstring srcStr);
void setLdLibraryPath(const char* ldLibPathUtf);
void closeGLFWWindow();