Skip to content

Commit f8e59a9

Browse files
committed
fix(main/openjdk-{17,21,25}): patch TMP_BUFFER_LEN to be relative to the build-time length of @TERMUX_PREFIX@/tmp
- Fixes #27045 - It is also necessary to hardcode `char* tmpdir = "@TERMUX_PREFIX@/tmp";` because OpenJDK has an internal hostbuild that will crash at build-time if it is not also redirected to use `@TERMUX_PREFIX@/tmp` instead of `/tmp` simultaneously - This is OK because `@TERMUX_PREFIX@/tmp` is already a directory excluded from packaging globally, so it is safe to use as a tmpdir at build-time of anything https://github.com/termux/termux-packages/blob/f7d37694465b0c2985a573df8992ec08a1873f16/scripts/build/termux_step_copy_into_massagedir.sh#L5 - The crash is only easily reproducible in the 32-bit ARM build of `openjdk-25`, but the same code exists possibly-dormant in every OpenJDK, so should be patched in all
1 parent f7d3769 commit f8e59a9

File tree

6 files changed

+90
-0
lines changed

6 files changed

+90
-0
lines changed

packages/openjdk-17/build.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ TERMUX_PKG_DESCRIPTION="Java development kit and runtime"
33
TERMUX_PKG_LICENSE="GPL-2.0"
44
TERMUX_PKG_MAINTAINER="@termux"
55
TERMUX_PKG_VERSION="17.0.17"
6+
TERMUX_PKG_REVISION=1
67
TERMUX_PKG_SRCURL=https://github.com/openjdk/jdk17u/archive/refs/tags/jdk-${TERMUX_PKG_VERSION}-ga.tar.gz
78
TERMUX_PKG_SHA256=e2d1d92a4a593d9a87054ea54f76fcb6119f782c57945506a2ec4adff6ddc123
89
TERMUX_PKG_AUTO_UPDATE=true
@@ -51,6 +52,14 @@ termux_pkg_auto_update() {
5152

5253
termux_step_pre_configure() {
5354
unset JAVA_HOME
55+
56+
local patch="$TERMUX_PKG_BUILDER_DIR/tmpdir-path-length.diff"
57+
local tmpdir_path="$TERMUX_PREFIX/tmp"
58+
echo "Applying patch: $(basename "$patch")"
59+
test -f "$patch" && sed \
60+
-e "s%\@TERMUX_PREFIX\@%${TERMUX_PREFIX}%g" \
61+
-e "s%\@TERMUX_TMPDIR_PATH_LENGTH\@%${#tmpdir_path}%g" \
62+
"$patch" | patch --silent -p1
5463
}
5564

5665
termux_step_configure() {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--- a/src/hotspot/os/posix/perfMemory_posix.cpp
2+
+++ b/src/hotspot/os/posix/perfMemory_posix.cpp
3+
@@ -130,15 +130,15 @@ static void save_memory_to_file(char* addr, size_t size) {
4+
// return the user specific temporary directory name.
5+
// the caller is expected to free the allocated memory.
6+
//
7+
-#define TMP_BUFFER_LEN (4+22)
8+
+#define TMP_BUFFER_LEN (@TERMUX_TMPDIR_PATH_LENGTH@+22)
9+
static char* get_user_tmp_dir(const char* user, int vmid, int nspid) {
10+
- char* tmpdir = (char *)os::get_temp_directory();
11+
+ char* tmpdir = "@TERMUX_PREFIX@/tmp";
12+
#if defined(LINUX)
13+
// On linux, if containerized process, get dirname of
14+
// /proc/{vmid}/root/tmp/{PERFDATA_NAME_user}
15+
// otherwise /tmp/{PERFDATA_NAME_user}
16+
char buffer[TMP_BUFFER_LEN];
17+
- assert(strlen(tmpdir) == 4, "No longer using /tmp - update buffer size");
18+
+ assert(strlen(tmpdir) == @TERMUX_TMPDIR_PATH_LENGTH@, "No longer using @TERMUX_PREFIX@/tmp - update buffer size");
19+
20+
if (nspid != -1) {
21+
jio_snprintf(buffer, TMP_BUFFER_LEN, "/proc/%d/root%s", vmid, tmpdir);

packages/openjdk-21/build.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ TERMUX_PKG_DESCRIPTION="Java development kit and runtime"
33
TERMUX_PKG_LICENSE="GPL-2.0"
44
TERMUX_PKG_MAINTAINER="@termux"
55
TERMUX_PKG_VERSION="21.0.9"
6+
TERMUX_PKG_REVISION=1
67
TERMUX_PKG_SRCURL=https://github.com/openjdk/jdk21u/archive/refs/tags/jdk-${TERMUX_PKG_VERSION}-ga.tar.gz
78
TERMUX_PKG_SHA256=4ffe05ff839192b01ed53ccd69835f7b5508bee7ca0d5703ac210897065e7ff0
89
TERMUX_PKG_AUTO_UPDATE=true
@@ -51,6 +52,14 @@ termux_pkg_auto_update() {
5152

5253
termux_step_pre_configure() {
5354
unset JAVA_HOME
55+
56+
local patch="$TERMUX_PKG_BUILDER_DIR/tmpdir-path-length.diff"
57+
local tmpdir_path="$TERMUX_PREFIX/tmp"
58+
echo "Applying patch: $(basename "$patch")"
59+
test -f "$patch" && sed \
60+
-e "s%\@TERMUX_PREFIX\@%${TERMUX_PREFIX}%g" \
61+
-e "s%\@TERMUX_TMPDIR_PATH_LENGTH\@%${#tmpdir_path}%g" \
62+
"$patch" | patch --silent -p1
5463
}
5564

5665
termux_step_configure() {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--- a/src/hotspot/os/posix/perfMemory_posix.cpp
2+
+++ b/src/hotspot/os/posix/perfMemory_posix.cpp
3+
@@ -130,15 +130,15 @@ static void save_memory_to_file(char* addr, size_t size) {
4+
// return the user specific temporary directory name.
5+
// the caller is expected to free the allocated memory.
6+
//
7+
-#define TMP_BUFFER_LEN (4+22)
8+
+#define TMP_BUFFER_LEN (@TERMUX_TMPDIR_PATH_LENGTH@+22)
9+
static char* get_user_tmp_dir(const char* user, int vmid, int nspid) {
10+
- char* tmpdir = (char *)os::get_temp_directory();
11+
+ char* tmpdir = "@TERMUX_PREFIX@/tmp";
12+
#if defined(LINUX)
13+
// On linux, if containerized process, get dirname of
14+
// /proc/{vmid}/root/tmp/{PERFDATA_NAME_user}
15+
// otherwise /tmp/{PERFDATA_NAME_user}
16+
char buffer[TMP_BUFFER_LEN];
17+
- assert(strlen(tmpdir) == 4, "No longer using /tmp - update buffer size");
18+
+ assert(strlen(tmpdir) == @TERMUX_TMPDIR_PATH_LENGTH@, "No longer using @TERMUX_PREFIX@/tmp - update buffer size");
19+
20+
if (nspid != -1) {
21+
jio_snprintf(buffer, TMP_BUFFER_LEN, "/proc/%d/root%s", vmid, tmpdir);

packages/openjdk-25/build.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ TERMUX_PKG_DESCRIPTION="Java development kit and runtime"
33
TERMUX_PKG_LICENSE="GPL-2.0"
44
TERMUX_PKG_MAINTAINER="@termux"
55
TERMUX_PKG_VERSION="25.0.1"
6+
TERMUX_PKG_REVISION=1
67
TERMUX_PKG_SRCURL=https://github.com/openjdk/jdk25u/archive/refs/tags/jdk-${TERMUX_PKG_VERSION}-ga.tar.gz
78
TERMUX_PKG_SHA256=99864b94b65a9d8e180ec55b8e53a9ab39b0eaebd3ba4438388bf7ea7d5e079a
89
TERMUX_PKG_AUTO_UPDATE=true
@@ -68,6 +69,14 @@ termux_step_host_build() {
6869

6970
termux_step_pre_configure() {
7071
unset JAVA_HOME
72+
73+
local patch="$TERMUX_PKG_BUILDER_DIR/tmpdir-path-length.diff"
74+
local tmpdir_path="$TERMUX_PREFIX/tmp"
75+
echo "Applying patch: $(basename "$patch")"
76+
test -f "$patch" && sed \
77+
-e "s%\@TERMUX_PREFIX\@%${TERMUX_PREFIX}%g" \
78+
-e "s%\@TERMUX_TMPDIR_PATH_LENGTH\@%${#tmpdir_path}%g" \
79+
"$patch" | patch --silent -p1
7180
}
7281

7382
termux_step_configure() {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--- a/src/hotspot/os/posix/perfMemory_posix.cpp
2+
+++ b/src/hotspot/os/posix/perfMemory_posix.cpp
3+
@@ -130,15 +130,15 @@ static void save_memory_to_file(char* addr, size_t size) {
4+
// return the user specific temporary directory name.
5+
// the caller is expected to free the allocated memory.
6+
//
7+
-#define TMP_BUFFER_LEN (4+22)
8+
+#define TMP_BUFFER_LEN (@TERMUX_TMPDIR_PATH_LENGTH@+22)
9+
static char* get_user_tmp_dir(const char* user, int vmid, int nspid) {
10+
- char* tmpdir = (char *)os::get_temp_directory();
11+
+ char* tmpdir = "@TERMUX_PREFIX@/tmp";
12+
#if defined(LINUX)
13+
// On linux, if containerized process, get dirname of
14+
// /proc/{vmid}/root/tmp/{PERFDATA_NAME_user}
15+
// otherwise /tmp/{PERFDATA_NAME_user}
16+
char buffer[TMP_BUFFER_LEN];
17+
- assert(strlen(tmpdir) == 4, "No longer using /tmp - update buffer size");
18+
+ assert(strlen(tmpdir) == @TERMUX_TMPDIR_PATH_LENGTH@, "No longer using @TERMUX_PREFIX@/tmp - update buffer size");
19+
20+
if (nspid != -1) {
21+
jio_snprintf(buffer, TMP_BUFFER_LEN, "/proc/%d/root%s", vmid, tmpdir);

0 commit comments

Comments
 (0)