From 698cb7f5009c1397aa023bd9396483e599ba7329 Mon Sep 17 00:00:00 2001 From: "Luis Guzman (AppDevForAll)" Date: Wed, 23 Sep 2026 15:54:38 -0600 Subject: [PATCH] K2GO-411 fix(proot): translate aarch32 futex_time64 to host futex for 32-bit Go on pre-5.1 kernels 32-bit Go binaries (e.g. Forgejo arm-6) crash under the K2Go proot on devices whose real kernel is older than Linux 5.1: Go's linux/arm runtime issues futex_time64 (arm #422), which the kernel lacks and proot did not translate, so it returned ENOSYS and Go aborted with "futexwakeup returned -38". Patch the bundled termux-packages proot at build time, in the proot termux_step_pre_configure block (same mechanism as the fchmodat2 patch), to remap the aarch32 futex_time64 to the host futex. Four idempotent, guarded edits: - sysnums.list: declare the abstract PR_futex_time64. - enter.c: set_sysnum(tracee, PR_futex) at sysenter. - sysnums-*.h: map raw 422 in the 32-bit ABI tables; the "[ 240 ] = PR_futex" anchor auto-scopes to arm/i386, so arm64/x86_64 skip. - seccomp.c: trace it so the rewrite runs in the default seccomp-accelerated mode. __kernel_timespec is 64-bit and byte-compatible with the host timespec, so this is a syscall-number remap, not an argument rewrite. Builds still cover both arm64-v8a and armeabi-v7a; the patch is inert in the 64-bit table. Device-verified: the futex_time64(422) C probe returns 0 (was ENOSYS) and forgejo --version runs with no crash. Not a seccomp issue; PROOT_NO_SECCOMP=1 does not help. --- tools/proot-builder/build_static.sh | 33 +++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tools/proot-builder/build_static.sh b/tools/proot-builder/build_static.sh index 7c0afd51f..42cad1905 100644 --- a/tools/proot-builder/build_static.sh +++ b/tools/proot-builder/build_static.sh @@ -137,6 +137,39 @@ int __android_log_write(int prio, const char* tag, const char* text) { return 0; STUB fi + # K2GO-411: translate aarch32 futex_time64 (#422) -> classic futex so 32-bit Go + # binaries run on pre-5.1 kernels (e.g. Android 4.14, where futex_time64 is + # ENOSYS). PRoot ships utimensat_time64 (v5.3.0); this follows the same path. + # Safe: PRoot has no futex arg handling and FUTEX_WAKE carries no timespec; + # on a 64-bit host PR_futex resolves to the native 64-bit-timespec futex. + SYSD="$TERMUX_PKG_SRCDIR/src/syscall" + # 1) abstract sysnum + grep -q 'SYSNUM(futex_time64)' "$SYSD/sysnums.list" \ + || sed -i '/^SYSNUM(futex)$/a SYSNUM(futex_time64)' "$SYSD/sysnums.list" + # 2) enter.c: rewrite PR_futex_time64 -> PR_futex at sysenter + grep -q 'PR_futex_time64' "$SYSD/enter.c" \ + || { awk '/^\tcase PR_getcwd:/ && !p { print "\tcase PR_futex_time64:"; print "\t\tset_sysnum(tracee, PR_futex);"; print "\t\tstatus = 0;"; print "\t\tbreak;"; print ""; p=1 } { print }' "$SYSD/enter.c" > "$SYSD/enter.c.tmp" && mv "$SYSD/enter.c.tmp" "$SYSD/enter.c"; } + # 3) ABI table: map the raw aarch32 number 422 -> PR_futex_time64 (i386 uses 422 + # too). WITHOUT THIS the sysnum never resolves to PR_futex_time64 and the enter.c + # case never fires (verified on device: patch present but still ENOSYS). Anchor on + # the classic futex(240) entry, which only 32-bit tables have -> arm64/x86_64 skip. + # Mirrors the fchmodat2 [452] mapping below. + for h in "$SYSD"/sysnums-*.h; do + grep -q 'PR_futex_time64' "$h" && continue + grep -q '\[ 240 \] = PR_futex,' "$h" \ + && sed -i 's/^\([[:space:]]*\)\[ 240 \] = PR_futex,/&\n\1[ 422 ] = PR_futex_time64,/' "$h" + done + # 4) seccomp: trap futex_time64 at sysenter so the rewrite runs in the DEFAULT + # seccomp-accelerated mode (proot only TRACEs a curated list; futex is not in it, + # so without this futex_time64 passes through untranslated unless PROOT_NO_SECCOMP). + grep -q '{ PR_futex_time64,' "$SYSD/seccomp.c" \ + || sed -i 's/^\([[:space:]]*\){ PR_fchmodat,[[:space:]]*0 },$/&\n\1{ PR_futex_time64, 0 },/' "$SYSD/seccomp.c" + # guards + grep -q 'SYSNUM(futex_time64)' "$SYSD/sysnums.list" || { echo "!! [IIAB] sysnums.list anchor 'SYSNUM(futex)' not found"; exit 1; } + grep -q 'case PR_futex_time64:' "$SYSD/enter.c" || { echo "!! [IIAB] enter.c anchor 'case PR_getcwd:' not found"; exit 1; } + grep -q '\[ 422 \] = PR_futex_time64,' "$SYSD/sysnums-arm.h" || { echo "!! [IIAB] sysnums-arm.h anchor '[ 240 ] = PR_futex,' not found"; exit 1; } + grep -q '{ PR_futex_time64,' "$SYSD/seccomp.c" || { echo "!! [IIAB] seccomp.c anchor '{ PR_fchmodat, 0 }' not found"; exit 1; } + # --- ADFA-5334 (ADR-5334): translate fchmodat2 (452) like fchmodat, mirroring faccessat2. --- # glibc>=2.39 restores directory modes via fchmodat2; proot passes it through untranslated, so # recursive perms-preserving copies (tar -x / cp -a) fail under proot on kernel>=6.6 build hosts.