0
0
mirror of https://github.com/termux/termux-packages.git synced 2025-03-02 14:35:57 +00:00
termux-packages/packages/openjdk-21/0018-Try-to-get-libjvm.so-path-from-proc-self-maps-on-and.patch
eval Nya 940a37f5f0 addpkg(main/openjdk-21): 21.0.3-ga
cherry-pick all patches, apply them on upstream JDK, and adapted for
newer $UPDATE version

fix: type redefinition introduced in 21.0.2
2024-10-17 14:02:06 +02:00

90 lines
2.8 KiB
Diff

From aba494431b806f8414a7139334a21348f227cec7 Mon Sep 17 00:00:00 2001
From: Duy Tran Khanh <40482367+khanhduytran0@users.noreply.github.com>
Date: Fri, 25 Jun 2021 17:19:24 +0700
Subject: [PATCH 18/37] Try to get libjvm.so path from /proc/self/maps on
android
---
src/hotspot/os/linux/os_linux.cpp | 44 +++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+)
diff --git a/src/hotspot/os/linux/os_linux.cpp b/src/hotspot/os/linux/os_linux.cpp
index 93cdec6dd..c8fb1f10c 100644
--- a/src/hotspot/os/linux/os_linux.cpp
+++ b/src/hotspot/os/linux/os_linux.cpp
@@ -217,6 +217,8 @@ static int clock_tics_per_sec = 100;
// avoid this
static bool suppress_primordial_thread_resolution = false;
+static bool read_so_path_from_maps(const char* so_name, char* buf, int buflen);
+
// utility functions
julong os::Linux::available_memory_in_container() {
@@ -1498,6 +1500,34 @@ bool os::dll_address_to_library_name(address addr, char* buf,
return false;
}
+static bool read_so_path_from_maps(const char* so_name, char* buf, int buflen) {
+ 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
+ jio_snprintf(buf, buflen, "%s", so_path);
+ fclose(fp);
+ return true;
+ }
+
+ fclose(fp);
+ return false;
+}
+
+// Loads .dll/.so and
+// in case of error it checks if .dll/.so was built for the
+// same architecture as Hotspot is running on
+
// Remember the stack's state. The Linux dynamic linker will change
// the stack to 'executable' at most once, so we must safepoint only once.
bool os::Linux::_stack_is_executable = false;
@@ -2595,6 +2625,19 @@ void os::jvm_path(char *buf, jint buflen) {
CAST_FROM_FN_PTR(address, os::jvm_path),
dli_fname, sizeof(dli_fname), nullptr);
assert(ret, "cannot locate libjvm");
+#ifdef __ANDROID__
+ if (dli_fname[0] == '\0') {
+ return;
+ }
+
+ if (strchr(dli_fname, '/') == NULL) {
+ bool ok = read_so_path_from_maps(dli_fname, buf, buflen);
+ assert(ok, "unable to turn relative libjvm.so path into absolute");
+ return;
+ }
+
+ snprintf(buf, buflen, /* "%s/lib/%s/server/%s", java_home_var, cpu_arch, */ "%s", dli_fname);
+#else // !__ANDROID__
char *rp = nullptr;
if (ret && dli_fname[0] != '\0') {
rp = os::Posix::realpath(dli_fname, buf, buflen);
@@ -2660,6 +2703,7 @@ void os::jvm_path(char *buf, jint buflen) {
}
}
}
+#endif
strncpy(saved_jvm_path, buf, MAXPATHLEN);
saved_jvm_path[MAXPATHLEN - 1] = '\0';
--
2.45.2