From 7039d84be480b73f3b755958d4d0afd9cd7a3ac5 Mon Sep 17 00:00:00 2001 From: artdeell Date: Fri, 24 Feb 2023 18:05:24 +0300 Subject: [PATCH] Add patch for AWT_OnLoad path This patch makes the runtime work properly on devices with old Android versions - originally it doesn't work due to a dlinfo bug in Android < 7 --- patches/jdk8u_android.diff | 47 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/patches/jdk8u_android.diff b/patches/jdk8u_android.diff index ffc152e..d6d1a55 100644 --- a/patches/jdk8u_android.diff +++ b/patches/jdk8u_android.diff @@ -60816,3 +60816,50 @@ index edd3bc69e1..a28d3540f0 100644 #include "utf.h" +diff --git a/jdk/src/solaris/native/sun/awt/awt_LoadLibrary.c b/jdk/src/solaris/native/sun/awt/awt_LoadLibrary.c +index 5948302713..76755e98aa 100644 +--- a/jdk/src/solaris/native/sun/awt/awt_LoadLibrary.c ++++ b/jdk/src/solaris/native/sun/awt/awt_LoadLibrary.c +@@ -93,6 +93,29 @@ JNIEXPORT jboolean JNICALL AWTIsHeadless() { + #define DEFAULT_PATH XAWT_PATH + #define HEADLESS_PATH "/libawt_headless.so" + #endif ++static bool read_so_path_from_maps(const char* so_name, char* buf) { ++ FILE *fp = fopen("/proc/self/maps", "r"); ++ assert(fp, "Failed to open /proc/self/maps"); ++ if (!fp) { ++ return false; ++ } ++ ++ char maps_buffer[2048]; ++ while (fgets(maps_buffer, 2048, fp) != NULL) { ++ if (strstr(maps_buffer, so_name) == NULL) { ++ continue; ++ } ++ ++ char *so_path = strchr(maps_buffer, '/'); ++ so_path[strlen(so_path) - 1] = '\0'; // Cut trailing \n ++ strcpy(buf,so_path); ++ fclose(fp); ++ return true; ++ } ++ ++ fclose(fp); ++ return false; ++} + + jint + AWT_OnLoad(JavaVM *vm, void *reserved) +@@ -117,7 +140,11 @@ AWT_OnLoad(JavaVM *vm, void *reserved) + + /* Get address of this library and the directory containing it. */ + dladdr((void *)AWT_OnLoad, &dlinfo); +- realpath((char *)dlinfo.dli_fname, buf); ++ if (strrchr(dlinfo.dli_fname, '/') != NULL) { ++ realpath((char *)dlinfo.dli_fname, buf); ++ }else{ ++ read_so_path_from_maps(dlinfo.dli_fname,buf); ++ } + len = strlen(buf); + p = strrchr(buf, '/'); +