From cd3421fd9b7cdb0911610534318247f4a235149f Mon Sep 17 00:00:00 2001 From: Maxython Date: Thu, 30 May 2024 00:32:02 +0300 Subject: [PATCH] gpkg/glibc: global update - added the glibc32 subpackage - updated fakesyscall handling scheme - added all disabled syscalls to fakesyscall list - added new syscalls to fakesyscall list - disabled removal of old locales in `locale-gen` - implemented syslog function, which is configured to work with the android log system - implemented analog variables `LD_*` to customize glibc environment without affecting bionic environment - improved source code for flexible glibc compilation --- get-build-package.sh | 2 +- gpkg/glibc/_Fork.c.patch | 11 - gpkg/glibc/accept.c.patch | 16 - gpkg/glibc/android_passwd_group.c | 36 +- gpkg/glibc/android_passwd_group.h | 13 +- gpkg/glibc/build.sh | 195 ++++++- gpkg/glibc/chmod.c.patch | 14 - gpkg/glibc/clock_gettime.c.patch | 28 +- gpkg/glibc/disabled-syscalls | 31 -- gpkg/glibc/dl-tls_init_tp.c.patch | 17 - gpkg/glibc/epoll_pwait2.c.patch | 32 -- gpkg/glibc/fake-syscall.h | 33 -- gpkg/glibc/fake_epoll_pwait2.c | 20 + gpkg/glibc/fakesyscall-base.h | 42 ++ gpkg/glibc/fakesyscall.h | 12 + gpkg/glibc/fakesyscall.json | 61 +++ gpkg/glibc/fstatat64.c.patch | 38 +- gpkg/glibc/ftruncate.c.patch | 15 - gpkg/glibc/fxstat64.c.patch | 17 - gpkg/glibc/fxstatat64.c.patch | 20 - gpkg/glibc/glibc32.subpackage.sh | 7 + gpkg/glibc/kernel-features.h.patch | 26 + gpkg/glibc/linux-Makefile.patch | 4 +- gpkg/glibc/local-setxid.h.patch | 20 - gpkg/glibc/locale-gen | 4 - gpkg/glibc/lxstat64.c.patch | 21 - gpkg/glibc/mprotect.c | 15 +- gpkg/glibc/pthread_create.c.patch | 19 - gpkg/glibc/recv.c.patch | 16 - gpkg/glibc/rmdir.c.patch | 13 - gpkg/glibc/rseq-internal.h.patch | 31 -- gpkg/glibc/send.c.patch | 16 - gpkg/glibc/{setdirs.patch => set-dirs.patch} | 162 ++++-- gpkg/glibc/set-fakesyscalls.patch | 316 +++++++++++ gpkg/glibc/set-ld-variables.patch | 124 +++++ gpkg/glibc/set-nptl-syscalls.patch | 87 +++ gpkg/glibc/setegid.c.patch | 17 - gpkg/glibc/setgid.c.patch | 15 - gpkg/glibc/setresgid.c.patch | 15 - gpkg/glibc/setuid.c.patch | 15 - gpkg/glibc/shmat.c | 6 +- gpkg/glibc/shmctl.c | 80 ++- gpkg/glibc/shmdt.c | 6 +- gpkg/glibc/shmem-android.c | 248 +++++++++ gpkg/glibc/shmem-android.h | 283 ++-------- gpkg/glibc/shmget.c | 7 +- gpkg/glibc/sigrestorer.S.patch | 10 + gpkg/glibc/spawni.c.patch | 11 - gpkg/glibc/statx.c.patch | 18 - gpkg/glibc/syscall.c | 23 +- gpkg/glibc/syslog.c | 543 +++++++++++++++++++ gpkg/glibc/sysvipc-Makefile.patch | 19 + gpkg/glibc/tst-rseq-disable.c.patch | 24 - gpkg/glibc/tst-rseq.h.patch | 23 - gpkg/glibc/xstat64.c.patch | 20 - gpkg/libuv/build.sh | 1 + gpkg/libuv/linux.c.patch | 32 -- 57 files changed, 2003 insertions(+), 947 deletions(-) delete mode 100644 gpkg/glibc/_Fork.c.patch delete mode 100644 gpkg/glibc/accept.c.patch delete mode 100644 gpkg/glibc/chmod.c.patch delete mode 100644 gpkg/glibc/disabled-syscalls delete mode 100644 gpkg/glibc/dl-tls_init_tp.c.patch delete mode 100644 gpkg/glibc/epoll_pwait2.c.patch delete mode 100644 gpkg/glibc/fake-syscall.h create mode 100644 gpkg/glibc/fake_epoll_pwait2.c create mode 100644 gpkg/glibc/fakesyscall-base.h create mode 100644 gpkg/glibc/fakesyscall.h create mode 100644 gpkg/glibc/fakesyscall.json delete mode 100644 gpkg/glibc/ftruncate.c.patch delete mode 100644 gpkg/glibc/fxstat64.c.patch delete mode 100644 gpkg/glibc/fxstatat64.c.patch create mode 100644 gpkg/glibc/glibc32.subpackage.sh create mode 100644 gpkg/glibc/kernel-features.h.patch delete mode 100644 gpkg/glibc/local-setxid.h.patch delete mode 100644 gpkg/glibc/lxstat64.c.patch delete mode 100644 gpkg/glibc/pthread_create.c.patch delete mode 100644 gpkg/glibc/recv.c.patch delete mode 100644 gpkg/glibc/rmdir.c.patch delete mode 100644 gpkg/glibc/rseq-internal.h.patch delete mode 100644 gpkg/glibc/send.c.patch rename gpkg/glibc/{setdirs.patch => set-dirs.patch} (89%) create mode 100644 gpkg/glibc/set-fakesyscalls.patch create mode 100644 gpkg/glibc/set-ld-variables.patch create mode 100644 gpkg/glibc/set-nptl-syscalls.patch delete mode 100644 gpkg/glibc/setegid.c.patch delete mode 100644 gpkg/glibc/setgid.c.patch delete mode 100644 gpkg/glibc/setresgid.c.patch delete mode 100644 gpkg/glibc/setuid.c.patch create mode 100644 gpkg/glibc/shmem-android.c create mode 100644 gpkg/glibc/sigrestorer.S.patch delete mode 100644 gpkg/glibc/spawni.c.patch delete mode 100644 gpkg/glibc/statx.c.patch create mode 100644 gpkg/glibc/syslog.c create mode 100644 gpkg/glibc/sysvipc-Makefile.patch delete mode 100644 gpkg/glibc/tst-rseq-disable.c.patch delete mode 100644 gpkg/glibc/tst-rseq.h.patch delete mode 100644 gpkg/glibc/xstat64.c.patch delete mode 100644 gpkg/libuv/linux.c.patch diff --git a/get-build-package.sh b/get-build-package.sh index 0212bc94e..2bc7b6447 100755 --- a/get-build-package.sh +++ b/get-build-package.sh @@ -2,7 +2,7 @@ # Script that installs build-package.sh to compile glibc packages -BRANCH="master" +BRANCH="adding-glibc32-prefix" git clone --depth 1 -b ${BRANCH} --single-branch https://github.com/termux/termux-packages.git diff --git a/gpkg/glibc/_Fork.c.patch b/gpkg/glibc/_Fork.c.patch deleted file mode 100644 index e43e03ae6..000000000 --- a/gpkg/glibc/_Fork.c.patch +++ /dev/null @@ -1,11 +0,0 @@ ---- glibc-2.39/sysdeps/nptl/_Fork.c 2021-08-02 01:33:43.000000000 +0000 -+++ glibc-2.39/sysdeps/nptl/_Fork.c.path 2022-01-20 08:39:46.858400434 +0000 -@@ -44,8 +44,6 @@ - self->robust_prev = &self->robust_head; - #endif - self->robust_head.list = &self->robust_head; -- INTERNAL_SYSCALL_CALL (set_robust_list, &self->robust_head, -- sizeof (struct robust_list_head)); - } - return pid; - } diff --git a/gpkg/glibc/accept.c.patch b/gpkg/glibc/accept.c.patch deleted file mode 100644 index 58a17e9f4..000000000 --- a/gpkg/glibc/accept.c.patch +++ /dev/null @@ -1,16 +0,0 @@ ---- glibc-2.39/sysdeps/unix/sysv/linux/accept.c 2023-02-01 06:27:45.000000000 +0300 -+++ glibc-2.39/sysdeps/unix/sysv/linux/accept.c.patch 2023-06-01 13:54:57.311645074 +0300 -@@ -22,13 +22,7 @@ - int - __libc_accept (int fd, __SOCKADDR_ARG addr, socklen_t *len) - { --#ifdef __ASSUME_ACCEPT_SYSCALL -- return SYSCALL_CANCEL (accept, fd, addr.__sockaddr__, len); --#elif defined __ASSUME_ACCEPT4_SYSCALL - return SYSCALL_CANCEL (accept4, fd, addr.__sockaddr__, len, 0); --#else -- return SOCKETCALL_CANCEL (accept, fd, addr.__sockaddr__, len); --#endif - } - weak_alias (__libc_accept, accept) - libc_hidden_def (accept) diff --git a/gpkg/glibc/android_passwd_group.c b/gpkg/glibc/android_passwd_group.c index dc8aee64a..c7530aa8f 100644 --- a/gpkg/glibc/android_passwd_group.c +++ b/gpkg/glibc/android_passwd_group.c @@ -3,14 +3,10 @@ structures are created. */ -#ifndef _ANDROID_PASSWD_GROUP -#define _ANDROID_PASSWD_GROUP - #include -#include -#include #include #include +#include "android_ids.h" #include "android_passwd_group.h" struct android_id_info * find_android_id_info_by_id(unsigned id) { @@ -67,7 +63,7 @@ int is_valid_id_android(id_t id, int is_group) { return 0; } -static id_t oem_id_from_name_android(const char* name) { +id_t oem_id_from_name_android(const char* name) { unsigned int id; if (sscanf(name, "oem_%u", &id) != 1) { return 0; @@ -78,7 +74,7 @@ static id_t oem_id_from_name_android(const char* name) { return (id_t)id; } -static id_t app_id_from_name_android(const char* name, int is_group) { +id_t app_id_from_name_android(const char* name, int is_group) { char* end; unsigned long userid; struct android_id_info* info; @@ -87,7 +83,7 @@ static id_t app_id_from_name_android(const char* name, int is_group) { if (is_group && name[0] == 'a' && name[1] == 'l' && name[2] == 'l') { end = malloc(strlen(name)); for (int i=3; i #include -#include "android_ids.h" struct android_id_info * find_android_id_info_by_id(unsigned id); struct android_id_info * find_android_id_info_by_name(const char* name); int is_oem_id_android(id_t id); int is_valid_id_android(id_t id, int is_group); -static id_t oem_id_from_name_android(const char* name); -static id_t app_id_from_name_android(const char* name, int is_group); +id_t oem_id_from_name_android(const char* name); +id_t app_id_from_name_android(const char* name, int is_group); void get_name_by_uid_android(uid_t uid, char *name_u); void get_name_by_gid_android(gid_t gid, char *name_g); -struct passwd * get_passwd_android(char* name, uid_t uid); -struct group * get_group_android(char* name, gid_t gid); +struct passwd * get_passwd_android(const char* name, uid_t uid); +struct group * get_group_android(const char* name, gid_t gid); struct passwd * getpwuid_android(uid_t uid); struct group * getgrgid_android(gid_t gid); -struct passwd * getpwnam_android(char* name); -struct group * getgrnam_android(char* name); +struct passwd * getpwnam_android(const char* name); +struct group * getgrnam_android(const char* name); #endif // _ANDROID_PASSWD_GROUP_H diff --git a/gpkg/glibc/build.sh b/gpkg/glibc/build.sh index 96ff270f9..397f1a32f 100644 --- a/gpkg/glibc/build.sh +++ b/gpkg/glibc/build.sh @@ -3,74 +3,163 @@ TERMUX_PKG_DESCRIPTION="GNU C Library" TERMUX_PKG_LICENSE="GPL-3.0, LGPL-3.0" TERMUX_PKG_MAINTAINER="@termux-pacman" TERMUX_PKG_VERSION=2.39 -TERMUX_PKG_REVISION=4 +TERMUX_PKG_REVISION=5 TERMUX_PKG_SRCURL=https://ftp.gnu.org/gnu/libc/glibc-$TERMUX_PKG_VERSION.tar.xz TERMUX_PKG_SHA256=f77bd47cf8170c57365ae7bf86696c118adb3b120d3259c64c502d3dc1e2d926 TERMUX_PKG_DEPENDS="linux-api-headers-glibc" TERMUX_PKG_RECOMMENDS="glibc-runner" TERMUX_PKG_NO_STATICSPLIT=true TERMUX_PKG_CONFFILES="glibc/etc/gai.conf, glibc/etc/locale.gen" +TERMUX_PKG_SEPARATE_SUB_DEPENDS=true + +# Variables for glibc32 compilation +TERMUX_PKG_BUILD32=$(test "$TERMUX_ARCH" = "aarch64" || test "$TERMUX_ARCH" = "arm" && \ + test "$TERMUX_ON_DEVICE_BUILD" = "false" && echo "true" || echo "false") +TERMUX_PKG_BUILDDIR32="${TERMUX_TOPDIR}/${TERMUX_PKG_NAME}/build32" +#if [ "$TERMUX_PKG_BUILD32" = "true" ]; then +# TERMUX_PKG_BUILD_DEPENDS="glibc32" +#fi + +termux_setup_build32() { + case $TERMUX_ARCH in + "aarch64") + TERMUX_ARCH="arm" + TERMUX_HOST_PLATFORM="arm-linux-gnueabihf";; + "x86_64") + TERMUX_ARCH="i686" + TERMUX_HOST_PLATFORM="i686-linux-gnu";; + esac + termux_step_setup_toolchain + cd ${TERMUX_PKG_BUILDDIR32} +} termux_step_pre_configure() { if [ "$TERMUX_PACKAGE_LIBRARY" != "glibc" ]; then termux_error_exit "Compilation is only possible based on glibc" fi - for i in shmem-android.h shmat.c shmctl.c shmdt.c shmget.c mprotect.c syscall.c fake-syscall.h; do - install -Dm644 "${TERMUX_PKG_BUILDER_DIR}/${i}" "${TERMUX_PKG_SRCDIR}/sysdeps/unix/sysv/linux/${i}" - done - + # disabling clone3 function rm ${TERMUX_PKG_SRCDIR}/sysdeps/unix/sysv/linux/*/clone3.S + # disabling editing of `ldd` script for x86_64 arch rm ${TERMUX_PKG_SRCDIR}/sysdeps/unix/sysv/linux/x86_64/configure* - if [ "$TERMUX_ARCH" = "i686" ]; then - mv ${TERMUX_PKG_SRCDIR}/sysdeps/unix/sysv/linux/i386/syscall.S \ - ${TERMUX_PKG_SRCDIR}/sysdeps/unix/sysv/linux/i386/syscallS.S - else - mv ${TERMUX_PKG_SRCDIR}/sysdeps/unix/sysv/linux/${TERMUX_ARCH}/syscall.S \ - ${TERMUX_PKG_SRCDIR}/sysdeps/unix/sysv/linux/${TERMUX_ARCH}/syscallS.S - fi + # installing special scripts for correct operation of system calls + for i in ${TERMUX_PKG_BUILDER_DIR}/{shm{at,ctl,dt,get}.c,mprotect.c,syscall.c,fakesyscall*.h,fake_epoll_pwait2.c}; do + cp ${i} ${TERMUX_PKG_SRCDIR}/sysdeps/unix/sysv/linux/ + done - for i in android_passwd_group.h android_passwd_group.c android_system_user_ids.h; do - cp ${TERMUX_PKG_BUILDER_DIR}/${i} ${TERMUX_PKG_SRCDIR}/nss/ + # installing and configuring scripts for parsing users/groups according to the android standard + for i in ${TERMUX_PKG_BUILDER_DIR}/{android_passwd_group.*,android_system_user_ids.h}; do + cp ${i} ${TERMUX_PKG_SRCDIR}/nss/ done bash ${TERMUX_PKG_BUILDER_DIR}/gen-android-ids.sh ${TERMUX_BASE_DIR} \ ${TERMUX_PKG_SRCDIR}/nss/android_ids.h \ ${TERMUX_PKG_BUILDER_DIR}/android_system_user_ids.h - # `disabled-syscalls` - a file that contains a list of system calls that should be disabled + # installing a syslog script that can work with the android log system + cp ${TERMUX_PKG_BUILDER_DIR}/syslog.c ${TERMUX_PKG_SRCDIR}/misc/ + + # installing shmem-android scripts for system V shared memory emulation + cp ${TERMUX_PKG_BUILDER_DIR}/shmem-android.* ${TERMUX_PKG_SRCDIR}/sysvipc/ + + # `fakesyscall.json` - json file that stores a list of unsupported syscalls for Termux in keys, + # the name of which indicates the fakesyscall function and how it will be launched + # == Syntax == + # { + # "fakesyscall_1()": [ + # "syscall_1", + # "syscall_2" + # ], + # "fakesyscall_2(a0, a1, a2, a3, a4, a5)": [ + # "syscall_3", + # "syscall_4" + # ] + # } + # == Rules === + # - The name syscall and the name of the function fakesyscall must not be repeated + # - Specify the syscall name without the leading `__NR_` prefix + # ============ for i in aarch64 arm i386 x86_64/64; do + mv ${TERMUX_PKG_SRCDIR}/sysdeps/unix/sysv/linux/${i///*/}/syscall.S \ + ${TERMUX_PKG_SRCDIR}/sysdeps/unix/sysv/linux/${i///*/}/syscallS.S + local header_disabled_syscall="${TERMUX_PKG_SRCDIR}/sysdeps/unix/sysv/linux/${i}/disabled-syscall.h" + { + for j in $(jq -r '.[] | .[]' ${TERMUX_PKG_BUILDER_DIR}/fakesyscall.json); do + grep "#define __NR_${j} " ${TERMUX_PKG_SRCDIR}/sysdeps/unix/sysv/linux/${i}/arch-syscall.h || true + sed -i "/#define __NR_${j} /d" ${TERMUX_PKG_SRCDIR}/sysdeps/unix/sysv/linux/${i}/arch-syscall.h + done + } >> $header_disabled_syscall { - for j in $(awk '{printf "__NR_" $1 " "}' ${TERMUX_PKG_BUILDER_DIR}/disabled-syscalls); do - grep "#define ${j} " ${TERMUX_PKG_SRCDIR}/sysdeps/unix/sysv/linux/${i}/arch-syscall.h || true - sed -i "/#define ${j} /d" ${TERMUX_PKG_SRCDIR}/sysdeps/unix/sysv/linux/${i}/arch-syscall.h + echo -e "\n#define DISABLED_SYSCALL_WITH_FAKESYSCALL \\" + local IFS=$'\n' + for j in $(jq -r '. | keys | .[]' ${TERMUX_PKG_BUILDER_DIR}/fakesyscall.json); do + local need_return=false + for z in $(jq -r '."'${j}'" | .[]' ${TERMUX_PKG_BUILDER_DIR}/fakesyscall.json); do + if grep -q "^#define __NR_${z} " $header_disabled_syscall; then + echo -e "\tcase __NR_${z}: \\" + need_return=true + elif [[ ${z} =~ ^[0-9]+$ ]]; then + echo -e "\tcase ${z}: \\" + need_return=true + fi + done + [ "${need_return}" = "true" ] && echo -e "\t\treturn ${j}; \\" done - } >> ${TERMUX_PKG_SRCDIR}/sysdeps/unix/sysv/linux/${i}/disabled-syscall.h + unset IFS + } >> $header_disabled_syscall + sed -i '$ s| \\||' $header_disabled_syscall + done + + # replacing some hard paths that may not exist in some device + for i in /dev/stderr:/proc/self/fd/2 \ + /dev/stdin:/proc/self/fd/0 \ + /dev/stdout:/proc/self/fd/1; do + for j in $(grep -s -r -l ${i%%:*} ${TERMUX_PKG_SRCDIR}); do + sed -i "s|${i%%:*}|${i//*:}|g" ${j} + done done + + # adding revision to glibc version + sed -i "s/${TERMUX_PKG_VERSION}/${TERMUX_PKG_FULLVERSION_FOR_PACMAN}/" ${TERMUX_PKG_SRCDIR}/version.h + + # specifying the current release (use only when developing glibc) + sed -i "s/stable/dev.$(git -C ${TERMUX_PKG_BUILDER_DIR} rev-parse --short HEAD).$(date +%Y%m%d%H%M%S)/" ${TERMUX_PKG_SRCDIR}/version.h + + if [ "$TERMUX_PKG_BUILD32" = "true" ]; then + rm -fr ${TERMUX_PKG_BUILDDIR32} + mkdir -p ${TERMUX_PKG_BUILDDIR32} + fi } -termux_step_configure() { - echo "slibdir=${TERMUX_PREFIX}/lib" > configparms - echo "rtlddir=${TERMUX_PREFIX}/lib" >> configparms +termux_glibc_configure() { + local libdir="${1}" + + echo "slibdir=${TERMUX_PREFIX}/${libdir}" > configparms + echo "rtlddir=${TERMUX_PREFIX}/${libdir}" >> configparms echo "sbindir=${TERMUX_PREFIX}/bin" >> configparms echo "rootsbindir=${TERMUX_PREFIX}/bin" >> configparms local _configure_flags=() case $TERMUX_ARCH in "aarch64") _configure_flags+=(--enable-memory-tagging --enable-fortify-source);; - "arm") _configure_flags+=(--enable-fortify-source);; + "arm"|"i686") _configure_flags+=(--enable-fortify-source);; "x86_64") _configure_flags+=(--enable-cet);; - "i686") _configure_flags+=(--enable-fortify-source);; esac + local _pkgversion="GNU libc for Android" + if [ -n "${TERMUX_APP_PACKAGE-}" ]; then + _pkgversion+="/${TERMUX_APP_PACKAGE}" + fi + ${TERMUX_PKG_SRCDIR}/configure \ --prefix=$TERMUX_PREFIX \ - --libdir=${TERMUX_PREFIX}/lib \ - --libexecdir=${TERMUX_PREFIX}/lib \ + --libdir=${TERMUX_PREFIX}/${libdir} \ + --libexecdir=${TERMUX_PREFIX}/${libdir} \ --host=$TERMUX_HOST_PLATFORM \ --build=$TERMUX_HOST_PLATFORM \ --target=$TERMUX_HOST_PLATFORM \ --with-bugurl=https://github.com/termux-pacman/glibc-packages/issues \ + --with-pkgversion="${_pkgversion}" \ --enable-bind-now \ --disable-multi-arch \ --enable-stack-protector=strong \ @@ -82,11 +171,37 @@ termux_step_configure() { "${_configure_flags[@]}" } +termux_step_configure() { + termux_glibc_configure "lib" + + if [ "$TERMUX_PKG_BUILD32" = "true" ]; then + ( + termux_setup_build32 + termux_glibc_configure "lib32" + echo 'build-programs=no' >> configparms + ) + fi +} + termux_step_make() { make -O make info - elf/ld.so --library-path "$PWD" locale/localedef -c -f ${TERMUX_PKG_SRCDIR}/localedata/charmaps/UTF-8 -i ${TERMUX_PKG_SRCDIR}/localedata/locales/C ./C.UTF-8/ + if [ "$TERMUX_PKG_BUILD32" = "true" ]; then + ( + termux_setup_build32 + make -O + ) + fi +} + +termux_glibc_make_syscall_without_fsc() { + local libname="libsyscall_without_fsc.so" + local libdir="$1" + echo "Compiling '${libname}'..." + $CC ${TERMUX_PKG_BUILDER_DIR}/syscall.c -o ${TERMUX_PREFIX}/${libdir}/${libname} \ + -shared -DWITHOUT_FAKESYSCALL + echo "DONE" } termux_step_make_install() { @@ -113,12 +228,32 @@ termux_step_make_install() { ${TERMUX_PKG_SRCDIR}/localedata/SUPPORTED > ${TERMUX_PREFIX}/share/i18n/SUPPORTED install -dm755 ${TERMUX_PREFIX}/lib/locale - cp -r ./C.UTF-8 -t ${TERMUX_PREFIX}/lib/locale + make -C ${TERMUX_PKG_SRCDIR}/localedata objdir=${TERMUX_PKG_BUILDDIR} \ + SUPPORTED-LOCALES="C.UTF-8/UTF-8 en_US.UTF-8/UTF-8" install-locale-files sed -i '/#C\.UTF-8 /d' ${TERMUX_PREFIX}/etc/locale.gen install -Dm644 ${TERMUX_PKG_BUILDER_DIR}/sdt.h ${TERMUX_PREFIX}/include/sys/sdt.h install -Dm644 ${TERMUX_PKG_BUILDER_DIR}/sdt-config.h ${TERMUX_PREFIX}/include/sys/sdt-config.h - ln -sf $PATH_DYNAMIC_LINKER $TERMUX_PREFIX/bin/ld.so - ln -sf $PATH_DYNAMIC_LINKER $TERMUX_PREFIX/lib/ld.so + ln -sfr $PATH_DYNAMIC_LINKER ${TERMUX_PREFIX}/bin/ld.so + ln -sfr $PATH_DYNAMIC_LINKER ${TERMUX_PREFIX}/lib/ld.so + + termux_glibc_make_syscall_without_fsc "lib" + + if [ "$TERMUX_PKG_BUILD32" = "true" ]; then + ( + termux_setup_build32 + + make DESTDIR=${TERMUX_PKG_BUILDDIR32} install + + cp -r ${TERMUX_PKG_BUILDDIR32}/${TERMUX_PREFIX}/lib32 $TERMUX_PREFIX + + ln -sfr ${TERMUX_PREFIX}/lib/locale ${TERMUX_PREFIX}/lib32/locale + + ln -sfr ${TERMUX_PREFIX}/lib32/${DYNAMIC_LINKER} $PATH_DYNAMIC_LINKER + ln -sfr ${TERMUX_PREFIX}/lib32/${DYNAMIC_LINKER} ${TERMUX_PREFIX}/lib32/ld.so + + termux_glibc_make_syscall_without_fsc "lib32" + ) + fi } diff --git a/gpkg/glibc/chmod.c.patch b/gpkg/glibc/chmod.c.patch deleted file mode 100644 index 298ab19ce..000000000 --- a/gpkg/glibc/chmod.c.patch +++ /dev/null @@ -1,14 +0,0 @@ ---- glibc-2.39/sysdeps/unix/sysv/linux/chmod.c 2023-02-01 06:27:45.000000000 +0300 -+++ glibc-2.39/sysdeps/unix/sysv/linux/chmod.c.patch 2023-04-05 09:24:47.264497804 +0300 -@@ -23,11 +23,7 @@ - int - __chmod (const char *file, mode_t mode) - { --#ifdef __NR_chmod -- return INLINE_SYSCALL_CALL (chmod, file, mode); --#else - return INLINE_SYSCALL_CALL (fchmodat, AT_FDCWD, file, mode); --#endif - } - - libc_hidden_def (__chmod) diff --git a/gpkg/glibc/clock_gettime.c.patch b/gpkg/glibc/clock_gettime.c.patch index 19bc31dc5..dcab4bf8a 100644 --- a/gpkg/glibc/clock_gettime.c.patch +++ b/gpkg/glibc/clock_gettime.c.patch @@ -1,6 +1,17 @@ ---- glibc-2.39/sysdeps/unix/sysv/linux/clock_gettime.c 2022-07-30 01:03:09.000000000 +0300 -+++ glibc-2.39/sysdeps/unix/sysv/linux/clock_gettime.c.patch 2022-10-18 22:31:17.784495202 +0300 -@@ -65,12 +65,6 @@ +--- glibc-2.39/sysdeps/unix/sysv/linux/clock_gettime.c 2024-01-31 03:34:58.000000000 +0300 ++++ glibc-2.39/sysdeps/unix/sysv/linux/clock_gettime.c.patch 2024-12-29 23:33:28.406119388 +0300 +@@ -30,10 +30,6 @@ + { + int r; + +-#ifndef __NR_clock_gettime64 +-# define __NR_clock_gettime64 __NR_clock_gettime +-#endif +- + #ifdef HAVE_CLOCK_GETTIME64_VSYSCALL + int (*vdso_time64) (clockid_t clock_id, struct __timespec64 *tp) + = GLRO(dl_vdso_clock_gettime64); +@@ -65,13 +61,6 @@ } #endif @@ -10,6 +21,15 @@ - if (r != -ENOSYS) - return INLINE_SYSCALL_ERROR_RETURN_VALUE (-r); - - #ifndef __ASSUME_TIME64_SYSCALLS +-#ifndef __ASSUME_TIME64_SYSCALLS /* Fallback code that uses 32-bit support. */ struct timespec tp32; + r = INTERNAL_SYSCALL_CALL (clock_gettime, clock_id, &tp32); +@@ -80,7 +69,6 @@ + *tp = valid_timespec_to_timespec64 (tp32); + return 0; + } +-#endif + + return INLINE_SYSCALL_ERROR_RETURN_VALUE (-r); + } diff --git a/gpkg/glibc/disabled-syscalls b/gpkg/glibc/disabled-syscalls deleted file mode 100644 index da957efeb..000000000 --- a/gpkg/glibc/disabled-syscalls +++ /dev/null @@ -1,31 +0,0 @@ -accept -chmod -chown -chown32 -clock_gettime64 -clone3 -close_range -epoll_pwait2 -faccessat2 -fchmodat2 -futex_waitv -getpgrp -landlock_create_ruleset -pidfd_send_signal -recv -rmdir -rseq -send -set_robust_list -setfsgid -setfsgid32 -setfsuid -setfsuid32 -setgid -setgid32 -setresgid -setresgid32 -setuid -setuid32 -statx -symlink diff --git a/gpkg/glibc/dl-tls_init_tp.c.patch b/gpkg/glibc/dl-tls_init_tp.c.patch deleted file mode 100644 index 7b093b9c3..000000000 --- a/gpkg/glibc/dl-tls_init_tp.c.patch +++ /dev/null @@ -1,17 +0,0 @@ ---- glibc-2.39/sysdeps/nptl/dl-tls_init_tp.c 2021-08-02 01:33:43.000000000 +0000 -+++ glibc-2.39/sysdeps/nptl/dl-tls_init_tp.c.path 2022-01-20 08:42:04.148400381 +0000 -@@ -80,14 +80,9 @@ - pd->robust_head.futex_offset = (offsetof (pthread_mutex_t, __data.__lock) - - offsetof (pthread_mutex_t, - __data.__list.__next)); -- int res = INTERNAL_SYSCALL_CALL (set_robust_list, &pd->robust_head, -- sizeof (struct robust_list_head)); -- if (!INTERNAL_SYSCALL_ERROR_P (res)) -- { - #ifndef __ASSUME_SET_ROBUST_LIST - __nptl_set_robust_list_avail = true; - #endif -- } - } - - /* Set initial thread's stack block from 0 up to __libc_stack_end. diff --git a/gpkg/glibc/epoll_pwait2.c.patch b/gpkg/glibc/epoll_pwait2.c.patch deleted file mode 100644 index c79253d3b..000000000 --- a/gpkg/glibc/epoll_pwait2.c.patch +++ /dev/null @@ -1,32 +0,0 @@ ---- glibc-2.39/sysdeps/unix/sysv/linux/epoll_pwait2.c 2024-01-31 03:34:58.000000000 +0300 -+++ glibc-2.39/sysdeps/unix/sysv/linux/epoll_pwait2.c.patch 2024-04-10 22:25:45.538639010 +0300 -@@ -16,15 +16,26 @@ - License along with the GNU C Library; if not, see - . */ - -+#include -+#include -+#include - #include --#include -+#include -+ -+#define MSEC_PER_SEC 1000L -+#define NSEC_PER_MSEC 1000000L - - int - __epoll_pwait2_time64 (int fd, struct epoll_event *ev, int maxev, - const struct __timespec64 *tmo, const sigset_t *s) - { -- /* The syscall only supports 64-bit time_t. */ -- return SYSCALL_CANCEL (epoll_pwait2, fd, ev, maxev, tmo, s, __NSIG_BYTES); -+ long timeout = tmo->tv_sec * MSEC_PER_SEC; -+ if (tmo->tv_nsec > 0) { -+ timeout += tmo->tv_nsec / NSEC_PER_MSEC; -+ if (tmo->tv_nsec % NSEC_PER_MSEC > 0) -+ timeout += 1; -+ } -+ return epoll_pwait (fd, ev, maxev, timeout, s); - } - #if __TIMESIZE != 64 - libc_hidden_def (__epoll_pwait2_time64) diff --git a/gpkg/glibc/fake-syscall.h b/gpkg/glibc/fake-syscall.h deleted file mode 100644 index e0dc8d914..000000000 --- a/gpkg/glibc/fake-syscall.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef _FAKE_SYSCALL -#define _FAKE_SYSCALL - -#include -#include - -extern int close_range (unsigned int __fd, unsigned int __max_fd, int __flags) __THROW; - -struct FakeSyscall { - int id; - long int (*func)(long int, - long int, - long int, - long int, - long int, - long int); -}; - -long int JustReturnZero() { - return 0; -} - -static struct FakeSyscall FakeSyscalls[] = { - { __NR_close_range, close_range }, - { __NR_mbind, JustReturnZero }, - { __NR_get_mempolicy, JustReturnZero }, - { __NR_set_mempolicy, JustReturnZero }, - { 1008, JustReturnZero }, // for some reason used in julia -}; - -#define CountFakeSyscalls (sizeof(FakeSyscalls) / sizeof(FakeSyscalls[0])) - -#endif //_FAKE_SYSCALL diff --git a/gpkg/glibc/fake_epoll_pwait2.c b/gpkg/glibc/fake_epoll_pwait2.c new file mode 100644 index 000000000..aa42ac4d2 --- /dev/null +++ b/gpkg/glibc/fake_epoll_pwait2.c @@ -0,0 +1,20 @@ +#include +#include +#include +#include +#include + +#define MSEC_PER_SEC 1000L +#define NSEC_PER_MSEC 1000000L + +static __attribute__((unused)) int +fake_epoll_pwait2 (int epfd, struct epoll_event *events, int maxevents, + const struct __timespec64 *timeout, const sigset_t *sigmask, size_t sigsetsize) { + long timeout_long = timeout->tv_sec * MSEC_PER_SEC; + if (timeout->tv_nsec > 0) { + timeout_long += timeout->tv_nsec / NSEC_PER_MSEC; + if (timeout->tv_nsec % NSEC_PER_MSEC > 0) + timeout_long += 1; + } + return SYSCALL_CANCEL (epoll_pwait, epfd, events, maxevents, timeout_long, sigmask, sigsetsize); +} diff --git a/gpkg/glibc/fakesyscall-base.h b/gpkg/glibc/fakesyscall-base.h new file mode 100644 index 000000000..4aaedc80a --- /dev/null +++ b/gpkg/glibc/fakesyscall-base.h @@ -0,0 +1,42 @@ +#ifndef _FAKE_SYSCALL_BASE +#define _FAKE_SYSCALL_BASE + +#include +#include +#include +#include + +// close_range +// fchownat +// ftruncate +// getpgrp +// unlinkat +// symlink +// link +// faccessat +#include + +// accept4 +// recvfrom +// sendto +#include + +// fchmodat +#include + +// clock_gettime +#include + +// shmat +// shmctl +// shmdt +// shmget +#include + +// statx_generic +#include "io/statx_generic.c" + +// fake_epoll_pwait2 +#include "fake_epoll_pwait2.c" + +#endif //_FAKE_SYSCALL_BASE diff --git a/gpkg/glibc/fakesyscall.h b/gpkg/glibc/fakesyscall.h new file mode 100644 index 000000000..102807e21 --- /dev/null +++ b/gpkg/glibc/fakesyscall.h @@ -0,0 +1,12 @@ +#ifndef _FAKE_SYSCALL +#define _FAKE_SYSCALL + +#include +#include +#undef DISABLED_SYSCALL_WITH_FAKESYSCALL + +#ifndef _UNISTD_H +extern long int syscall (long int __sysno, ...) __THROW; +#endif + +#endif //_FAKE_SYSCALL diff --git a/gpkg/glibc/fakesyscall.json b/gpkg/glibc/fakesyscall.json new file mode 100644 index 000000000..d6e0dc919 --- /dev/null +++ b/gpkg/glibc/fakesyscall.json @@ -0,0 +1,61 @@ +{ + "accept4(a0, (struct sockaddr *)a1, (socklen_t *)a2, 0)": [ "accept" ], + "faccessat(a0, (const char *)a1, a2, a3)": [ "faccessat2" ], + "fchmodat(AT_FDCWD, (const char *)a0, a1, 0)": [ "chmod" ], + "fchmodat(a0, (const char*)a1, a2, a3)": [ "fchmodat2" ], + "fchownat(AT_FDCWD, (const char *)a0, a1, a2, 0)": [ "chown", "chown32" ], + "ftruncate(a0, a1)": [ "ftruncate64" ], + "clock_gettime(a0, (struct timespec *)a1)": [ "clock_gettime64" ], + "fake_epoll_pwait2(a0, (struct epoll_event *)a1, a2, (const struct __timespec64 *)a3, (const __sigset_t *)a4, a5)": [ "epoll_pwait2" ], + "getpgrp()": [ "getpgrp" ], + "recvfrom(a0, (void *__restrict)a1, a2, a3, NULL, NULL)": [ "recv" ], + "unlinkat(AT_FDCWD, (const char *)a0, AT_REMOVEDIR)": [ "rmdir" ], + "sendto(a0, (const void *)a1, a2, a3, NULL, 0)": [ "send" ], + "statx_generic(a0, (const char *)a1, a2, a3, (struct statx *)a4)": [ "statx" ], + "symlink((const char *)a0, (const char *)a1)": [ "symlink" ], + "link((const char *)a0, (const char *)a1)": [ "link" ], + "close_range(a0, a1, a2)": [ "close_range" ], + "(long int)shmat(a0, (const void *)a1, a2)": [ "shmat" ], + "shmctl(a0, a1, (struct shmid_ds *)a2)": [ "shmctl" ], + "shmdt((const void *)a0)": [ "shmdt" ], + "shmget(a0, a1, a2)": [ "shmget" ], + "0": [ + "setuid", + "setuid32", + "setgid", + "setgid32", + "setreuid", + "setreuid32", + "setregid", + "setregid32", + "setresuid", + "setresuid32", + "setresgid", + "setresgid32", + "setfsuid", + "setfsuid32", + "setfsgid", + "setfsgid32", + 1008 + ], + "INLINE_SYSCALL_ERROR_RETURN_VALUE(ENOSYS)": [ + "clone3", + "futex_waitv", + "landlock_create_ruleset", + "pidfd_send_signal", + "rseq", + "set_robust_list", + "get_robust_list", + "io_uring_setup", + "io_uring_enter", + "io_uring_register", + "name_to_handle_at", + "open_by_handle_at", + "kcmp", + "mbind", + "get_mempolicy", + "set_mempolicy", + "mq_open", + "rt_sigreturn" + ] +} diff --git a/gpkg/glibc/fstatat64.c.patch b/gpkg/glibc/fstatat64.c.patch index c58ac00f9..f6a09e939 100644 --- a/gpkg/glibc/fstatat64.c.patch +++ b/gpkg/glibc/fstatat64.c.patch @@ -1,6 +1,6 @@ ---- glibc-2.39/sysdeps/unix/sysv/linux/fstatat64.c 2024-01-31 03:34:58.000000000 +0300 -+++ glibc-2.39/sysdeps/unix/sysv/linux/fstatat64.c.patch 2024-02-09 11:13:53.292656710 +0300 -@@ -38,43 +38,6 @@ +--- glibc-2.39/sysdeps/unix/sysv/linux/fstatat64.c 2024-12-11 13:13:54.323887003 +0300 ++++ glibc-2.39/sysdeps/unix/sysv/linux/fstatat64.c.patch 2024-12-11 13:16:09.283886951 +0300 +@@ -38,46 +38,8 @@ "__blkcnt_t and __blkcnt64_t must match"); #endif @@ -43,17 +43,33 @@ - /* Only statx supports 64-bit timestamps for 32-bit architectures with __ASSUME_STATX, so there is no point in building the fallback. */ - #if !FSTATAT_USE_STATX || (FSTATAT_USE_STATX && !defined __ASSUME_STATX) -@@ -147,11 +110,7 @@ - int r; +-#if !FSTATAT_USE_STATX || (FSTATAT_USE_STATX && !defined __ASSUME_STATX) + static inline int + fstatat64_time64_stat (int fd, const char *file, struct __stat64_t64 *buf, + int flag) +@@ -138,24 +100,12 @@ - #if FSTATAT_USE_STATX + return r; + } +-#endif + + int + __fstatat64_time64 (int fd, const char *file, struct __stat64_t64 *buf, + int flag) + { +- int r; +- +-#if FSTATAT_USE_STATX - r = fstatat64_time64_statx (fd, file, buf, flag); -# ifndef __ASSUME_STATX - if (r == -ENOSYS) - r = fstatat64_time64_stat (fd, file, buf, flag); -# endif -+ r = fstatat64_time64_stat (fd, file, buf, flag); - #else - r = fstatat64_time64_stat (fd, file, buf, flag); - #endif +-#else +- r = fstatat64_time64_stat (fd, file, buf, flag); +-#endif +- ++ int r = fstatat64_time64_stat (fd, file, buf, flag); + return INTERNAL_SYSCALL_ERROR_P (r) + ? INLINE_SYSCALL_ERROR_RETURN_VALUE (-r) + : 0; diff --git a/gpkg/glibc/ftruncate.c.patch b/gpkg/glibc/ftruncate.c.patch deleted file mode 100644 index fe84dc132..000000000 --- a/gpkg/glibc/ftruncate.c.patch +++ /dev/null @@ -1,15 +0,0 @@ ---- glibc-2.39/sysdeps/unix/sysv/linux/ftruncate.c 2023-02-01 06:27:45.000000000 +0300 -+++ glibc-2.39/sysdeps/unix/sysv/linux/ftruncate.c.patch 2023-06-18 13:16:42.961374902 +0300 -@@ -24,12 +24,8 @@ - int - __ftruncate (int fd, off_t length) - { --# ifndef __NR_ftruncate - return INLINE_SYSCALL_CALL (ftruncate64, fd, - __ALIGNMENT_ARG SYSCALL_LL (length)); --# else -- return INLINE_SYSCALL_CALL (ftruncate, fd, length); --# endif - } - weak_alias (__ftruncate, ftruncate) - #endif diff --git a/gpkg/glibc/fxstat64.c.patch b/gpkg/glibc/fxstat64.c.patch deleted file mode 100644 index f12fd7ceb..000000000 --- a/gpkg/glibc/fxstat64.c.patch +++ /dev/null @@ -1,17 +0,0 @@ ---- glibc-2.39/sysdeps/unix/sysv/linux/fxstat64.c 2022-07-30 01:03:09.000000000 +0300 -+++ glibc-2.39/sysdeps/unix/sysv/linux/fxstat64.c.patch 2022-10-07 22:35:03.954262517 +0300 -@@ -50,14 +50,6 @@ - if (vers == _STAT_VER_KERNEL || vers == _STAT_VER_LINUX) - return INLINE_SYSCALL_CALL (fstat, fd, buf); - return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL); --# else -- /* New 32-bit kABIs with only 64-bit time_t support, e.g. arc, riscv32. */ -- struct statx tmp; -- int r = INLINE_SYSCALL_CALL (statx, fd, "", AT_EMPTY_PATH, -- STATX_BASIC_STATS, &tmp); -- if (r == 0) -- __cp_stat64_statx (buf, &tmp); -- return r; - # endif - #else - /* All kABIs with non-LFS support, e.g. arm, csky, i386, hppa, m68k, diff --git a/gpkg/glibc/fxstatat64.c.patch b/gpkg/glibc/fxstatat64.c.patch deleted file mode 100644 index 7b4d91a9f..000000000 --- a/gpkg/glibc/fxstatat64.c.patch +++ /dev/null @@ -1,20 +0,0 @@ ---- glibc-2.39/sysdeps/unix/sysv/linux/fxstatat64.c 2022-07-30 01:03:09.000000000 +0300 -+++ glibc-2.39/sysdeps/unix/sysv/linux/fxstatat64.c.patch 2022-10-07 22:31:59.294262587 +0300 -@@ -44,17 +44,6 @@ - struct stat64 st64; - int r = INLINE_SYSCALL_CALL (fstatat64, fd, file, &st64, flag); - return r ?: __xstat32_conv (vers, &st64, (struct stat *) st); --# else -- /* New 32-bit kABIs with only 64-bit time_t support, e.g. arc, riscv32. */ -- if (vers == _STAT_VER_KERNEL) -- { -- struct statx tmp; -- int r = INLINE_SYSCALL_CALL (statx, fd, file, AT_NO_AUTOMOUNT | flag, -- STATX_BASIC_STATS, &tmp); -- if (r == 0) -- __cp_stat64_statx (st, &tmp); -- return r; -- } - # endif - #else - /* All kABIs with non-LFS support, e.g. arm, csky, i386, hppa, m68k, diff --git a/gpkg/glibc/glibc32.subpackage.sh b/gpkg/glibc/glibc32.subpackage.sh new file mode 100644 index 000000000..fbc333fa3 --- /dev/null +++ b/gpkg/glibc/glibc32.subpackage.sh @@ -0,0 +1,7 @@ +TERMUX_SUBPKG_DESCRIPTION="GNU C Library (32-bit)" +TERMUX_SUBPKG_DEPENDS="linux-api-headers-glibc" +TERMUX_SUBPKG_EXCLUDED_ARCHES="arm, i686" +TERMUX_SUBPKG_INCLUDE=" +glibc/lib32/ +glibc/lib/ld-linux-armhf.so.3 +glibc/lib/ld-linux.so.2" diff --git a/gpkg/glibc/kernel-features.h.patch b/gpkg/glibc/kernel-features.h.patch new file mode 100644 index 000000000..50a59d637 --- /dev/null +++ b/gpkg/glibc/kernel-features.h.patch @@ -0,0 +1,26 @@ +diff --git a/sysdeps/unix/sysv/linux/arm/kernel-features.h b/sysdeps/unix/sysv/linux/arm/kernel-features.h +index f17c2f9e..c38df3e1 100644 +--- a/sysdeps/unix/sysv/linux/arm/kernel-features.h ++++ b/sysdeps/unix/sysv/linux/arm/kernel-features.h +@@ -38,9 +38,6 @@ + non-standard name. */ + #define __NR_fadvise64_64 __NR_arm_fadvise64_64 + +-#define __ASSUME_RECV_SYSCALL 1 +-#define __ASSUME_SEND_SYSCALL 1 +- + /* Support for the mlock2 and copy_file_range syscalls was added to + the compat syscall table for 64-bit kernels in 4.7, although + present in 32-bit kernels from 4.4 and 4.5 respectively. */ +diff --git a/sysdeps/unix/sysv/linux/kernel-features.h b/sysdeps/unix/sysv/linux/kernel-features.h +index a25cf07e..00ec9c2d 100644 +--- a/sysdeps/unix/sysv/linux/kernel-features.h ++++ b/sysdeps/unix/sysv/linux/kernel-features.h +@@ -70,7 +70,6 @@ + separate syscalls were only added later. */ + #define __ASSUME_SENDMSG_SYSCALL 1 + #define __ASSUME_RECVMSG_SYSCALL 1 +-#define __ASSUME_ACCEPT_SYSCALL 1 + #define __ASSUME_CONNECT_SYSCALL 1 + #define __ASSUME_RECVFROM_SYSCALL 1 + #define __ASSUME_SENDTO_SYSCALL 1 diff --git a/gpkg/glibc/linux-Makefile.patch b/gpkg/glibc/linux-Makefile.patch index a75afbd96..df8871701 100644 --- a/gpkg/glibc/linux-Makefile.patch +++ b/gpkg/glibc/linux-Makefile.patch @@ -1,5 +1,5 @@ ---- src/sysdeps/unix/sysv/linux/Makefile 2024-01-31 03:34:58.000000000 +0300 -+++ src/sysdeps/unix/sysv/linux/Makefile.patch 2024-02-09 09:06:27.474952654 +0300 +--- glibc-2.39/sysdeps/unix/sysv/linux/Makefile 2024-01-31 03:34:58.000000000 +0300 ++++ glibc-2.39/sysdeps/unix/sysv/linux/Makefile.patch 2024-10-01 09:55:41.944107645 +0300 @@ -95,8 +95,6 @@ process_vm_writev \ pselect32 \ diff --git a/gpkg/glibc/local-setxid.h.patch b/gpkg/glibc/local-setxid.h.patch deleted file mode 100644 index 7b07205a5..000000000 --- a/gpkg/glibc/local-setxid.h.patch +++ /dev/null @@ -1,20 +0,0 @@ ---- glibc-2.39/sysdeps/unix/sysv/linux/local-setxid.h 2023-07-31 20:54:16.000000000 +0300 -+++ glibc-2.39/sysdeps/unix/sysv/linux/local-setxid.h.patch 2023-10-20 12:25:43.428519924 +0300 -@@ -1,6 +1,7 @@ - /* SETxID functions which only have to change the local thread and - none of the possible other threads. */ - #include -+#include - - #ifdef __NR_setresuid32 - # define local_seteuid(id) INLINE_SYSCALL (setresuid32, 3, -1, id, -1) -@@ -9,8 +10,4 @@ - #endif - - --#ifdef __NR_setresgid32 --# define local_setegid(id) INLINE_SYSCALL (setresgid32, 3, -1, id, -1) --#else --# define local_setegid(id) INLINE_SYSCALL (setresgid, 3, -1, id, -1) --#endif -+#define local_setegid(id) __setresgid (-1, id, -1) diff --git a/gpkg/glibc/locale-gen b/gpkg/glibc/locale-gen index 16b1f27e2..23c97e431 100644 --- a/gpkg/glibc/locale-gen +++ b/gpkg/glibc/locale-gen @@ -11,10 +11,6 @@ fi [ -f $LOCALEGEN -a -s $LOCALEGEN ] || exit 0; -# Remove all old locale dir and locale-archive before generating new -# locale data. -rm -rf @TERMUX_PREFIX@/lib/locale/* || true - umask 022 is_entry_ok() { diff --git a/gpkg/glibc/lxstat64.c.patch b/gpkg/glibc/lxstat64.c.patch deleted file mode 100644 index 92dd689f3..000000000 --- a/gpkg/glibc/lxstat64.c.patch +++ /dev/null @@ -1,21 +0,0 @@ ---- glibc-2.39/sysdeps/unix/sysv/linux/lxstat64.c 2022-07-30 01:03:09.000000000 +0300 -+++ glibc-2.39/sysdeps/unix/sysv/linux/lxstat64.c.patch 2022-10-07 22:27:46.944262684 +0300 -@@ -53,18 +53,6 @@ - if (vers == _STAT_VER_KERNEL) - return INLINE_SYSCALL_CALL (newfstatat, AT_FDCWD, name, buf, - AT_SYMLINK_NOFOLLOW); --# else -- /* New 32-bit kABIs with only 64-bit time_t support, e.g. arc, riscv32. */ -- if (vers == _STAT_VER_KERNEL) -- { -- struct statx tmp; -- int r = INLINE_SYSCALL_CALL (statx, AT_FDCWD, name, -- AT_NO_AUTOMOUNT | AT_SYMLINK_NOFOLLOW, -- STATX_BASIC_STATS, &tmp); -- if (r == 0) -- __cp_stat64_statx (buf, &tmp); -- return r; -- } - # endif - #else - # if STAT_IS_KERNEL_STAT diff --git a/gpkg/glibc/mprotect.c b/gpkg/glibc/mprotect.c index 187b03ddb..22a3bbcca 100644 --- a/gpkg/glibc/mprotect.c +++ b/gpkg/glibc/mprotect.c @@ -22,7 +22,7 @@ /* - String To Unsigned Long Int There are two chairs - one is called "strtoul", the other "stuli"... */ -unsigned long int __stuli(char *value) { +static unsigned long int __stuli(char *value) { unsigned long int val, res = 0; int len = strlen(value); @@ -42,23 +42,21 @@ unsigned long int __stuli(char *value) { static int __is_mmaped(void *addr) { char buff[GLOBAL_READ_SIZE]; - char *buff2 = ""; - char *cont = ""; + char *buff2 = NULL; + char *cont = NULL; int res = 0; int strlc, strlb; memset(buff, 0, sizeof(buff)); int map = __open_nocancel("/proc/self/maps", O_RDONLY|O_CLOEXEC); if (map >= 0) { while (__read_nocancel(map, buff, GLOBAL_READ_SIZE) > 0) { - buff[GLOBAL_READ_SIZE] = '\0'; - strlc = strlen(cont); + strlc = cont ? strlen(cont) : 0; if (strlc > 0) { buff2 = malloc(sizeof(char)*strlc); memcpy(buff2, cont, strlc); } - cont = malloc(sizeof(char)*(strlc+strlen(buff))); - memset(cont, 0, sizeof(cont)); - strlb = strlen(buff2); + cont = calloc(strlc+strlen(buff), sizeof(char)); + strlb = buff2 ? strlen(buff2): 0; if (strlb > 0) memcpy(cont, buff2, strlb); __strncat(cont, buff, GLOBAL_READ_SIZE); @@ -89,7 +87,6 @@ int __mprotect(void *addr, size_t len, int prot) { caddr = malloc(saddr); memcpy(caddr, addr, saddr); } - free(addr); addr = mmap(addr, len, PROT_READ|PROT_WRITE|PROT_EXEC, mmap_flags, -1, 0); if (saddr > 1) memcpy(addr, caddr, saddr); diff --git a/gpkg/glibc/pthread_create.c.patch b/gpkg/glibc/pthread_create.c.patch deleted file mode 100644 index f8fe6543a..000000000 --- a/gpkg/glibc/pthread_create.c.patch +++ /dev/null @@ -1,19 +0,0 @@ ---- glibc-2.39/nptl/pthread_create.c 2021-08-02 01:33:43.000000000 +0000 -+++ glibc-2.39/nptl/pthread_create.c.path 2022-01-20 08:16:09.293375256 +0000 -@@ -366,16 +366,6 @@ - /* Initialize pointers to locale data. */ - __ctype_init (); - --#ifndef __ASSUME_SET_ROBUST_LIST -- if (__nptl_set_robust_list_avail) --#endif -- { -- /* This call should never fail because the initial call in init.c -- succeeded. */ -- INTERNAL_SYSCALL_CALL (set_robust_list, &pd->robust_head, -- sizeof (struct robust_list_head)); -- } -- - /* This is where the try/finally block should be created. For - compilers without that support we do use setjmp. */ - struct pthread_unwind_buf unwind_buf; diff --git a/gpkg/glibc/recv.c.patch b/gpkg/glibc/recv.c.patch deleted file mode 100644 index a39c8e177..000000000 --- a/gpkg/glibc/recv.c.patch +++ /dev/null @@ -1,16 +0,0 @@ ---- glibc-2.39/sysdeps/unix/sysv/linux/recv.c 2023-02-01 06:27:45.000000000 +0300 -+++ glibc-2.39/sysdeps/unix/sysv/linux/recv.c.patch 2023-04-07 19:29:20.454418049 +0300 -@@ -22,13 +22,7 @@ - ssize_t - __libc_recv (int fd, void *buf, size_t len, int flags) - { --#ifdef __ASSUME_RECV_SYSCALL -- return SYSCALL_CANCEL (recv, fd, buf, len, flags); --#elif defined __ASSUME_RECVFROM_SYSCALL - return SYSCALL_CANCEL (recvfrom, fd, buf, len, flags, NULL, NULL); --#else -- return SOCKETCALL_CANCEL (recv, fd, buf, len, flags); --#endif - } - weak_alias (__libc_recv, recv) - weak_alias (__libc_recv, __recv) diff --git a/gpkg/glibc/rmdir.c.patch b/gpkg/glibc/rmdir.c.patch deleted file mode 100644 index f3a25f6b2..000000000 --- a/gpkg/glibc/rmdir.c.patch +++ /dev/null @@ -1,13 +0,0 @@ ---- glibc-2.39/sysdeps/unix/sysv/linux/rmdir.c 2023-07-31 20:54:16.000000000 +0300 -+++ glibc-2.39/sysdeps/unix/sysv/linux/rmdir.c.patch 2023-08-03 17:53:35.086156996 +0300 -@@ -24,10 +24,6 @@ - int - __rmdir (const char *path) - { --#ifdef __NR_rmdir -- return INLINE_SYSCALL_CALL (rmdir, path); --#else - return INLINE_SYSCALL_CALL (unlinkat, AT_FDCWD, path, AT_REMOVEDIR); --#endif - } - weak_alias (__rmdir, rmdir) diff --git a/gpkg/glibc/rseq-internal.h.patch b/gpkg/glibc/rseq-internal.h.patch deleted file mode 100644 index b73a4f7a8..000000000 --- a/gpkg/glibc/rseq-internal.h.patch +++ /dev/null @@ -1,31 +0,0 @@ ---- glibc-2.39/sysdeps/unix/sysv/linux/rseq-internal.h 2022-02-03 05:27:54.000000000 +0000 -+++ glibc-2.39/sysdeps/unix/sysv/linux/rseq-internal.h.patch 2022-06-17 12:19:02.380504902 +0000 -@@ -25,28 +25,11 @@ - #include - #include - --#ifdef RSEQ_SIG - static inline bool - rseq_register_current_thread (struct pthread *self, bool do_rseq) - { -- if (do_rseq) -- { -- int ret = INTERNAL_SYSCALL_CALL (rseq, &self->rseq_area, -- sizeof (self->rseq_area), -- 0, RSEQ_SIG); -- if (!INTERNAL_SYSCALL_ERROR_P (ret)) -- return true; -- } - THREAD_SETMEM (self, rseq_area.cpu_id, RSEQ_CPU_ID_REGISTRATION_FAILED); - return false; - } --#else /* RSEQ_SIG */ --static inline bool --rseq_register_current_thread (struct pthread *self, bool do_rseq) --{ -- THREAD_SETMEM (self, rseq_area.cpu_id, RSEQ_CPU_ID_REGISTRATION_FAILED); -- return false; --} --#endif /* RSEQ_SIG */ - - #endif /* rseq-internal.h */ diff --git a/gpkg/glibc/send.c.patch b/gpkg/glibc/send.c.patch deleted file mode 100644 index 5e5a1636e..000000000 --- a/gpkg/glibc/send.c.patch +++ /dev/null @@ -1,16 +0,0 @@ ---- glibc-2.39/sysdeps/unix/sysv/linux/send.c 2023-02-01 06:27:45.000000000 +0300 -+++ glibc-2.39/sysdeps/unix/sysv/linux/send.c.patch 2023-04-07 10:31:50.374430351 +0300 -@@ -22,13 +22,7 @@ - ssize_t - __libc_send (int fd, const void *buf, size_t len, int flags) - { --#ifdef __ASSUME_SEND_SYSCALL -- return SYSCALL_CANCEL (send, fd, buf, len, flags); --#elif defined __ASSUME_SENDTO_SYSCALL - return SYSCALL_CANCEL (sendto, fd, buf, len, flags, NULL, 0); --#else -- return SOCKETCALL_CANCEL (send, fd, buf, len, flags); --#endif - } - weak_alias (__libc_send, send) - weak_alias (__libc_send, __send) diff --git a/gpkg/glibc/setdirs.patch b/gpkg/glibc/set-dirs.patch similarity index 89% rename from gpkg/glibc/setdirs.patch rename to gpkg/glibc/set-dirs.patch index 04e84aec2..a37a1ae1a 100644 --- a/gpkg/glibc/setdirs.patch +++ b/gpkg/glibc/set-dirs.patch @@ -1,3 +1,15 @@ +diff --git a/bits/syslog-path.h b/bits/syslog-path.h +index badf60d3..098bfb26 100644 +--- a/bits/syslog-path.h ++++ b/bits/syslog-path.h +@@ -23,6 +23,6 @@ + #ifndef _BITS_SYSLOG_PATH_H + #define _BITS_SYSLOG_PATH_H 1 + +-#define _PATH_LOG "/dev/log" ++#define _PATH_LOG "/dev/socket/logdw" + + #endif /* bits/syslog-path.h */ diff --git a/dirent/bug-readdir1.c b/dirent/bug-readdir1.c index 4c3521db..06b6faa7 100644 --- a/dirent/bug-readdir1.c @@ -12,19 +24,19 @@ index 4c3521db..06b6faa7 100644 { if (errno == ENOENT) diff --git a/elf/rtld.c b/elf/rtld.c -index a91e2a44..382a12f8 100644 +index ac4bb236..49850121 100644 --- a/elf/rtld.c +++ b/elf/rtld.c -@@ -360,7 +360,7 @@ +@@ -360,7 +360,7 @@ struct rtld_global_ro _rtld_global_ro attribute_relro = ._dl_fpu_control = _FPU_DEFAULT, ._dl_pagesize = EXEC_PAGESIZE, ._dl_inhibit_cache = 0, - ._dl_profile_output = "/var/tmp", + ._dl_profile_output = "@TERMUX_PREFIX@/var/tmp", - + /* Function pointers. */ ._dl_debug_printf = _dl_debug_printf, -@@ -1862,7 +1862,7 @@ dl_main (const ElfW(Phdr) *phdr, +@@ -1859,7 +1859,7 @@ dl_main (const ElfW(Phdr) *phdr, open(). So we do this first. If it succeeds we do almost twice the work but this does not matter, since it is not for production use. */ @@ -34,7 +46,7 @@ index a91e2a44..382a12f8 100644 { /* Read the contents of the file. */ diff --git a/elf/sprof.c b/elf/sprof.c -index 3eaa4758..9a44ac2c 100644 +index b19aca32..ecb588a2 100644 --- a/elf/sprof.c +++ b/elf/sprof.c @@ -618,7 +618,7 @@ load_shobj (const char *name) @@ -57,8 +69,21 @@ index 3eaa4758..9a44ac2c 100644 name = ext_name; fd = open (ext_name, O_RDONLY); +diff --git a/hesiod/hesiod.c b/hesiod/hesiod.c +index ee087b03..22c50837 100644 +--- a/hesiod/hesiod.c ++++ b/hesiod/hesiod.c +@@ -60,7 +60,7 @@ + #include "hesiod.h" + #include "hesiod_p.h" + +-#define _PATH_HESIOD_CONF "/etc/hesiod.conf" ++#define _PATH_HESIOD_CONF "@TERMUX_PREFIX@/etc/hesiod.conf" + + /* Forward */ + diff --git a/include/shm-directory.h b/include/shm-directory.h -index 79256131..02f73070 100644 +index 5ba63e8a..6dad34ab 100644 --- a/include/shm-directory.h +++ b/include/shm-directory.h @@ -23,7 +23,7 @@ @@ -86,7 +111,7 @@ index 19740f49..214af2b0 100644 char *dname2; int r; diff --git a/io/bug-ftw4.c b/io/bug-ftw4.c -index bfbf4544..93971f99 100644 +index 51738dbd..cd1eb424 100644 --- a/io/bug-ftw4.c +++ b/io/bug-ftw4.c @@ -35,7 +35,7 @@ cb (const char *name, const struct stat64 *st, int type) @@ -99,7 +124,7 @@ index bfbf4544..93971f99 100644 if (mkdtemp (name) == NULL) diff --git a/libio/oldiopopen.c b/libio/oldiopopen.c -index b3eccc13..e88a4c66 100644 +index 2a004fca..0e685497 100644 --- a/libio/oldiopopen.c +++ b/libio/oldiopopen.c @@ -106,7 +106,7 @@ _IO_old_proc_open (FILE *fp, const char *command, const char *mode) @@ -112,10 +137,10 @@ index b3eccc13..e88a4c66 100644 } __close (child_end); diff --git a/libio/stdio.h b/libio/stdio.h -index 4cf9f1c0..a0e0e0a5 100644 +index 6762cffb..1e9d5e2e 100644 --- a/libio/stdio.h +++ b/libio/stdio.h -@@ -117,7 +117,7 @@ typedef __fpos64_t fpos64_t; +@@ -118,7 +118,7 @@ typedef __fpos64_t fpos64_t; #if defined __USE_MISC || defined __USE_XOPEN /* Default path prefix for `tempnam' and `tmpnam'. */ @@ -125,7 +150,7 @@ index 4cf9f1c0..a0e0e0a5 100644 #define L_tmpnam 20 diff --git a/manual/examples/filecli.c b/manual/examples/filecli.c -index 1ade5efe..0d7eecf2 100644 +index 9ee20d1d..ecbb0c6a 100644 --- a/manual/examples/filecli.c +++ b/manual/examples/filecli.c @@ -22,8 +22,8 @@ @@ -140,7 +165,7 @@ index 1ade5efe..0d7eecf2 100644 #define MESSAGE "Yow!!! Are we having fun yet?!?" diff --git a/manual/examples/filesrv.c b/manual/examples/filesrv.c -index 75c6ff87..f0ede166 100644 +index 2a5bbc17..25d7bc1f 100644 --- a/manual/examples/filesrv.c +++ b/manual/examples/filesrv.c @@ -21,7 +21,7 @@ @@ -153,7 +178,7 @@ index 75c6ff87..f0ede166 100644 int diff --git a/manual/examples/ofdlocks.c b/manual/examples/ofdlocks.c -index 9d777f73..f85b6f5e 100644 +index f1339b52..27dc8e42 100644 --- a/manual/examples/ofdlocks.c +++ b/manual/examples/ofdlocks.c @@ -23,7 +23,7 @@ @@ -175,7 +200,7 @@ index 9d777f73..f85b6f5e 100644 for (i = 0; i < ITERATIONS; i++) { diff --git a/nis/ypclnt.c b/nis/ypclnt.c -index 19a53a10..416985a4 100644 +index 8f883fc9..61d889dc 100644 --- a/nis/ypclnt.c +++ b/nis/ypclnt.c @@ -33,7 +33,7 @@ @@ -188,7 +213,7 @@ index 19a53a10..416985a4 100644 struct dom_binding diff --git a/nscd/nscd-client.h b/nscd/nscd-client.h -index 5588ade9..ff08ae36 100644 +index 3ec350e8..0ee1addf 100644 --- a/nscd/nscd-client.h +++ b/nscd/nscd-client.h @@ -35,13 +35,13 @@ @@ -208,8 +233,21 @@ index 5588ade9..ff08ae36 100644 /* Maximum allowed length for the key. */ #define MAXKEYLEN 1024 +diff --git a/nss/bug-erange.c b/nss/bug-erange.c +index b709418b..0aff48d1 100644 +--- a/nss/bug-erange.c ++++ b/nss/bug-erange.c +@@ -37,7 +37,7 @@ main (void) + { + printf ("gethostbyname_r failed: %s (errno: %m)\n", strerror (res)); + +- if (access ("/etc/resolv.conf", R_OK)) ++ if (access ("@TERMUX_PREFIX@/etc/resolv.conf", R_OK)) + { + puts ("DNS probably not set up"); + return 0; diff --git a/nss/db-Makefile b/nss/db-Makefile -index 0dcf764c..d39025b9 100644 +index ab37e62b..1c0c4f75 100644 --- a/nss/db-Makefile +++ b/nss/db-Makefile @@ -17,11 +17,11 @@ @@ -309,8 +347,34 @@ index 0dcf764c..d39025b9 100644 @printf %s "$(patsubst %.db,%,$(@F))... " @$(AWK) 'BEGIN { ini=1 } \ /^[ \t]*$$/ { next } \ +diff --git a/nss/getaddrinfo.c b/nss/getaddrinfo.c +index 3ccd3905..c132aa88 100644 +--- a/nss/getaddrinfo.c ++++ b/nss/getaddrinfo.c +@@ -1726,7 +1726,7 @@ in6aicmp (const void *p1, const void *p2) + + + /* Name of the config file for RFC 3484 sorting (for now). */ +-#define GAICONF_FNAME "/etc/gai.conf" ++#define GAICONF_FNAME "@TERMUX_PREFIX@/etc/gai.conf" + + + /* Non-zero if we are supposed to reload the config file automatically +diff --git a/nss/lckpwdf.c b/nss/lckpwdf.c +index ce0401a8..58a5dda5 100644 +--- a/nss/lckpwdf.c ++++ b/nss/lckpwdf.c +@@ -29,7 +29,7 @@ + + + /* Name of the lock file. */ +-#define PWD_LOCKFILE "/etc/.pwd.lock" ++#define PWD_LOCKFILE "@TERMUX_PREFIX@/etc/.pwd.lock" + + /* How long to wait for getting the lock before returning with an + error. */ diff --git a/nss/nss_compat/compat-grp.c b/nss/nss_compat/compat-grp.c -index 92d099eb..78a17631 100644 +index ede7503d..151773ab 100644 --- a/nss/nss_compat/compat-grp.c +++ b/nss/nss_compat/compat-grp.c @@ -108,7 +108,7 @@ internal_setgrent (ent_t *ent, int stayopen, int needent) @@ -323,7 +387,7 @@ index 92d099eb..78a17631 100644 if (ent->stream == NULL) status = errno == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL; diff --git a/nss/nss_compat/compat-initgroups.c b/nss/nss_compat/compat-initgroups.c -index 90bcdb97..b25d416f 100644 +index 2598cfbc..66563c22 100644 --- a/nss/nss_compat/compat-initgroups.c +++ b/nss/nss_compat/compat-initgroups.c @@ -122,7 +122,7 @@ internal_setgrent (ent_t *ent) @@ -336,7 +400,7 @@ index 90bcdb97..b25d416f 100644 if (ent->stream == NULL) status = errno == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL; diff --git a/nss/nss_compat/compat-pwd.c b/nss/nss_compat/compat-pwd.c -index f9ad9400..7c11f9d4 100644 +index 2f37e0f6..978d59f2 100644 --- a/nss/nss_compat/compat-pwd.c +++ b/nss/nss_compat/compat-pwd.c @@ -223,7 +223,7 @@ internal_setpwent (ent_t *ent, int stayopen, int needent) @@ -349,7 +413,7 @@ index f9ad9400..7c11f9d4 100644 if (ent->stream == NULL) status = errno == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL; diff --git a/nss/nss_compat/compat-spwd.c b/nss/nss_compat/compat-spwd.c -index c3ce41b1..28d520b9 100644 +index fac1e766..ea3c1bc3 100644 --- a/nss/nss_compat/compat-spwd.c +++ b/nss/nss_compat/compat-spwd.c @@ -178,7 +178,7 @@ internal_setspent (ent_t *ent, int stayopen, int needent) @@ -362,7 +426,7 @@ index c3ce41b1..28d520b9 100644 if (ent->stream == NULL) status = errno == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL; diff --git a/nss/nss_files/files-XXX.c b/nss/nss_files/files-XXX.c -index 2ed7184c..fb67afb0 100644 +index 558b2c36..3458b312 100644 --- a/nss/nss_files/files-XXX.c +++ b/nss/nss_files/files-XXX.c @@ -39,7 +39,7 @@ @@ -375,7 +439,7 @@ index 2ed7184c..fb67afb0 100644 #ifdef NEED_H_ERRNO # include diff --git a/nss/nss_files/files-alias.c b/nss/nss_files/files-alias.c -index 4601cb6c..a2ab1271 100644 +index 14a59b46..77a4acef 100644 --- a/nss/nss_files/files-alias.c +++ b/nss/nss_files/files-alias.c @@ -42,7 +42,7 @@ internal_setent (FILE **stream) @@ -406,7 +470,7 @@ index 4601cb6c..a2ab1271 100644 return status; diff --git a/nss/nss_files/files-init.c b/nss/nss_files/files-init.c -index d5c2795b..95b8f266 100644 +index 45fb49cb..bb8f0813 100644 --- a/nss/nss_files/files-init.c +++ b/nss/nss_files/files-init.c @@ -41,12 +41,12 @@ register_file (void (*cb) (size_t, struct traced_file *), @@ -429,7 +493,7 @@ index d5c2795b..95b8f266 100644 libc_hidden_def (_nss_files_init) diff --git a/nss/nss_files/files-initgroups.c b/nss/nss_files/files-initgroups.c -index 929039af..4b3eea49 100644 +index 65189d39..77c12334 100644 --- a/nss/nss_files/files-initgroups.c +++ b/nss/nss_files/files-initgroups.c @@ -33,7 +33,7 @@ _nss_files_initgroups_dyn (const char *user, gid_t group, long int *start, @@ -442,7 +506,7 @@ index 929039af..4b3eea49 100644 { *errnop = errno; diff --git a/nss/nss_files/files-netgrp.c b/nss/nss_files/files-netgrp.c -index 28ab40da..09dbc877 100644 +index 92d8062e..c50f7197 100644 --- a/nss/nss_files/files-netgrp.c +++ b/nss/nss_files/files-netgrp.c @@ -27,7 +27,7 @@ @@ -455,7 +519,7 @@ index 28ab40da..09dbc877 100644 libc_hidden_proto (_nss_files_endnetgrent) diff --git a/posix/annexc.c b/posix/annexc.c -index ca50ac96..6dc33aad 100644 +index ad3d4654..1f238a6e 100644 --- a/posix/annexc.c +++ b/posix/annexc.c @@ -26,7 +26,7 @@ @@ -533,7 +597,7 @@ index 4f67d9b2..11645956 100644 if (fd == -1) { diff --git a/posix/bug-regex9.c b/posix/bug-regex9.c -index d74bc9b9..3d1327f1 100644 +index 84dc81a4..841b2d80 100644 --- a/posix/bug-regex9.c +++ b/posix/bug-regex9.c @@ -23,7 +23,7 @@ @@ -546,7 +610,7 @@ index d74bc9b9..3d1327f1 100644 int main (void) diff --git a/resolv/netdb.h b/resolv/netdb.h -index ace9e482..75e9c00c 100644 +index 14228b0d..9e97ed4d 100644 --- a/resolv/netdb.h +++ b/resolv/netdb.h @@ -40,12 +40,12 @@ @@ -554,12 +618,13 @@ index ace9e482..75e9c00c 100644 /* Absolute file name for network data base files. */ -#define _PATH_HEQUIV "/etc/hosts.equiv" -+#define _PATH_HEQUIV "@TERMUX_PREFIX@/etc/hosts.equiv" - #define _PATH_HOSTS "/etc/hosts" +-#define _PATH_HOSTS "/etc/hosts" -#define _PATH_NETWORKS "/etc/networks" -#define _PATH_NSSWITCH_CONF "/etc/nsswitch.conf" -#define _PATH_PROTOCOLS "/etc/protocols" -#define _PATH_SERVICES "/etc/services" ++#define _PATH_HEQUIV "@TERMUX_PREFIX@/etc/hosts.equiv" ++#define _PATH_HOSTS "@TERMUX_PREFIX@/etc/hosts" +#define _PATH_NETWORKS "@TERMUX_PREFIX@/etc/networks" +#define _PATH_NSSWITCH_CONF "@TERMUX_PREFIX@/etc/nsswitch.conf" +#define _PATH_PROTOCOLS "@TERMUX_PREFIX@/etc/protocols" @@ -567,6 +632,19 @@ index ace9e482..75e9c00c 100644 __BEGIN_DECLS +diff --git a/resolv/res_hconf.c b/resolv/res_hconf.c +index e1158943..6c9624cc 100644 +--- a/resolv/res_hconf.c ++++ b/resolv/res_hconf.c +@@ -48,7 +48,7 @@ + # define fgets_unlocked __fgets_unlocked + #endif + +-#define _PATH_HOSTCONF "/etc/host.conf" ++#define _PATH_HOSTCONF "@TERMUX_PREFIX@/etc/host.conf" + + /* Environment vars that all user to override default behavior: */ + #define ENV_HOSTCONF "RESOLV_HOST_CONF" diff --git a/resolv/resolv.h b/resolv/resolv.h index f40d6c58..a982e162 100644 --- a/resolv/resolv.h @@ -605,7 +683,7 @@ index c9c2ef51..053f7227 100644 int fd1 = mkstemp (filename1); diff --git a/stdio-common/scanf14.c b/stdio-common/scanf14.c -index 09f47d36..6dbd23f4 100644 +index e58214ea..5351faec 100644 --- a/stdio-common/scanf14.c +++ b/stdio-common/scanf14.c @@ -82,7 +82,7 @@ main (void) @@ -618,7 +696,7 @@ index 09f47d36..6dbd23f4 100644 char fname[strlen (tmpdir) + sizeof "/tst-scanf14.XXXXXX"]; sprintf (fname, "%s/tst-scanf14.XXXXXX", tmpdir); diff --git a/stdio-common/scanf15.c b/stdio-common/scanf15.c -index acd01e7b..488d624c 100644 +index faef45bf..bf85fb83 100644 --- a/stdio-common/scanf15.c +++ b/stdio-common/scanf15.c @@ -65,7 +65,7 @@ main (void) @@ -631,7 +709,7 @@ index acd01e7b..488d624c 100644 char fname[strlen (tmpdir) + sizeof "/tst-scanf15.XXXXXX"]; sprintf (fname, "%s/tst-scanf15.XXXXXX", tmpdir); diff --git a/stdio-common/scanf16.c b/stdio-common/scanf16.c -index 97d1082d..a163a7d3 100644 +index 0dbe214d..19ae4a98 100644 --- a/stdio-common/scanf16.c +++ b/stdio-common/scanf16.c @@ -113,7 +113,7 @@ main (void) @@ -644,7 +722,7 @@ index 97d1082d..a163a7d3 100644 char fname[strlen (tmpdir) + sizeof "/tst-scanf16.XXXXXX"]; sprintf (fname, "%s/tst-scanf16.XXXXXX", tmpdir); diff --git a/stdio-common/scanf17.c b/stdio-common/scanf17.c -index 3099689e..439039a6 100644 +index d4392437..703b0e6e 100644 --- a/stdio-common/scanf17.c +++ b/stdio-common/scanf17.c @@ -96,7 +96,7 @@ main (void) @@ -657,7 +735,7 @@ index 3099689e..439039a6 100644 char fname[strlen (tmpdir) + sizeof "/tst-scanf17.XXXXXX"]; sprintf (fname, "%s/tst-scanf17.XXXXXX", tmpdir); diff --git a/stdio-common/tstscanf.c b/stdio-common/tstscanf.c -index 7e92df47..7ffbea37 100644 +index 80c3cf83..58a6a82b 100644 --- a/stdio-common/tstscanf.c +++ b/stdio-common/tstscanf.c @@ -62,7 +62,7 @@ main (int argc, char **argv) @@ -692,7 +770,7 @@ index 06f74aff..c80db63e 100644 ReadFile(&buffer, input); diff --git a/stdlib/isomac.c b/stdlib/isomac.c -index a371bb25..6e2b588b 100644 +index 7fcb4f2c..05d04f16 100644 --- a/stdlib/isomac.c +++ b/stdlib/isomac.c @@ -74,7 +74,7 @@ @@ -705,10 +783,10 @@ index a371bb25..6e2b588b 100644 /* ISO C header names including Amendment 1 (without ".h" suffix). */ static char *header[] = diff --git a/support/support_test_main.c b/support/support_test_main.c -index c20c19e7..f2b33978 100644 +index cca82d8d..372796be 100644 --- a/support/support_test_main.c +++ b/support/support_test_main.c -@@ -353,7 +353,7 @@ support_test_main (int argc, char **argv, const struct test_config *config) +@@ -351,7 +351,7 @@ support_test_main (int argc, char **argv, const struct test_config *config) { test_dir = getenv ("TMPDIR"); if (test_dir == NULL || test_dir[0] == '\0') @@ -791,7 +869,7 @@ index 893b4c22..6c38ca05 100644 #endif /* !_PATHS_H_ */ diff --git a/sysdeps/posix/system.c b/sysdeps/posix/system.c -index 488b9516..6287b0ea 100644 +index 01e8bc45..9c420a82 100644 --- a/sysdeps/posix/system.c +++ b/sysdeps/posix/system.c @@ -31,7 +31,7 @@ @@ -804,7 +882,7 @@ index 488b9516..6287b0ea 100644 diff --git a/sysdeps/posix/tempname.c b/sysdeps/posix/tempname.c -index f24d9622..b744a541 100644 +index 2af22386..21424f01 100644 --- a/sysdeps/posix/tempname.c +++ b/sysdeps/posix/tempname.c @@ -28,7 +28,7 @@ @@ -835,7 +913,7 @@ index 15859c3b..3bc390f5 100644 -#define CS_PATH "/bin:/usr/bin" +#define CS_PATH "@TERMUX_PREFIX@/bin:@TERMUX_PREFIX_CLASSICAL@/bin:/system/bin" diff --git a/sysdeps/unix/sysv/linux/gentempfd.c b/sysdeps/unix/sysv/linux/gentempfd.c -index 86b0a914..b3054e55 100644 +index 963e9d72..ea3c2e80 100644 --- a/sysdeps/unix/sysv/linux/gentempfd.c +++ b/sysdeps/unix/sysv/linux/gentempfd.c @@ -26,8 +26,8 @@ __gen_tempfd (int flags) @@ -922,7 +1000,7 @@ index 1342ab3a..357120b4 100644 #endif /* !_PATHS_H_ */ diff --git a/sysdeps/unix/sysv/linux/riscv/dl-cache.h b/sysdeps/unix/sysv/linux/riscv/dl-cache.h -index 2f82ed4e..29aa8ff8 100644 +index 4b6e50fa..9fc91fae 100644 --- a/sysdeps/unix/sysv/linux/riscv/dl-cache.h +++ b/sysdeps/unix/sysv/linux/riscv/dl-cache.h @@ -58,7 +58,7 @@ diff --git a/gpkg/glibc/set-fakesyscalls.patch b/gpkg/glibc/set-fakesyscalls.patch new file mode 100644 index 000000000..2eb3b37d1 --- /dev/null +++ b/gpkg/glibc/set-fakesyscalls.patch @@ -0,0 +1,316 @@ +diff --git a/sysdeps/unix/sysv/linux/epoll_pwait2.c b/sysdeps/unix/sysv/linux/epoll_pwait2.c +index 0f6ac3e1..9b111ad2 100644 +--- a/sysdeps/unix/sysv/linux/epoll_pwait2.c ++++ b/sysdeps/unix/sysv/linux/epoll_pwait2.c +@@ -18,13 +18,14 @@ + + #include + #include ++#include + + int + __epoll_pwait2_time64 (int fd, struct epoll_event *ev, int maxev, + const struct __timespec64 *tmo, const sigset_t *s) + { + /* The syscall only supports 64-bit time_t. */ +- return SYSCALL_CANCEL (epoll_pwait2, fd, ev, maxev, tmo, s, __NSIG_BYTES); ++ return syscall (__NR_epoll_pwait2, fd, ev, maxev, tmo, s, __NSIG_BYTES); + } + #if __TIMESIZE != 64 + libc_hidden_def (__epoll_pwait2_time64) +diff --git a/sysdeps/unix/sysv/linux/local-setxid.h b/sysdeps/unix/sysv/linux/local-setxid.h +index 97d787d9..c975fa86 100644 +--- a/sysdeps/unix/sysv/linux/local-setxid.h ++++ b/sysdeps/unix/sysv/linux/local-setxid.h +@@ -1,16 +1,17 @@ + /* SETxID functions which only have to change the local thread and + none of the possible other threads. */ + #include ++#include + + #ifdef __NR_setresuid32 +-# define local_seteuid(id) INLINE_SYSCALL (setresuid32, 3, -1, id, -1) ++# define local_seteuid(id) syscall (__NR_setresuid32, 3, -1, id, -1) + #else +-# define local_seteuid(id) INLINE_SYSCALL (setresuid, 3, -1, id, -1) ++# define local_seteuid(id) syscall (__NR_setresuid, 3, -1, id, -1) + #endif + + + #ifdef __NR_setresgid32 +-# define local_setegid(id) INLINE_SYSCALL (setresgid32, 3, -1, id, -1) ++# define local_setegid(id) syscall (__NR_setresgid32, 3, -1, id, -1) + #else +-# define local_setegid(id) INLINE_SYSCALL (setresgid, 3, -1, id, -1) ++# define local_setegid(id) syscall (__NR_setresgid, 3, -1, id, -1) + #endif +diff --git a/sysdeps/unix/sysv/linux/mq_open.c b/sysdeps/unix/sysv/linux/mq_open.c +index 936001b8..eb381a01 100644 +--- a/sysdeps/unix/sysv/linux/mq_open.c ++++ b/sysdeps/unix/sysv/linux/mq_open.c +@@ -22,6 +22,7 @@ + #include + #include + #include ++#include + + /* Establish connection between a process and a message queue NAME and + return message queue descriptor or (mqd_t) -1 on error. OFLAG determines +@@ -48,7 +49,7 @@ __mq_open (const char *name, int oflag, ...) + va_end (ap); + } + +- return INLINE_SYSCALL (mq_open, 4, name + 1, oflag, mode, attr); ++ return syscall (__NR_mq_open, 4, name + 1, oflag, mode, attr); + } + versioned_symbol (libc, __mq_open, mq_open, GLIBC_2_34); + #if OTHER_SHLIB_COMPAT (librt, GLIBC_2_3_4, GLIBC_2_34) +diff --git a/sysdeps/unix/sysv/linux/open_by_handle_at.c b/sysdeps/unix/sysv/linux/open_by_handle_at.c +index 730059d7..23ec12ad 100644 +--- a/sysdeps/unix/sysv/linux/open_by_handle_at.c ++++ b/sysdeps/unix/sysv/linux/open_by_handle_at.c +@@ -20,9 +20,10 @@ + #include + #include + #include ++#include + + int + open_by_handle_at (int mount_fd, struct file_handle *handle, int flags) + { +- return SYSCALL_CANCEL (open_by_handle_at, mount_fd, handle, flags); ++ return syscall (__NR_open_by_handle_at, mount_fd, handle, flags); + } +diff --git a/sysdeps/unix/sysv/linux/setegid.c b/sysdeps/unix/sysv/linux/setegid.c +index 4a608532..e4ff2bc3 100644 +--- a/sysdeps/unix/sysv/linux/setegid.c ++++ b/sysdeps/unix/sysv/linux/setegid.c +@@ -18,6 +18,7 @@ + #include + #include + #include ++#include + + + int +@@ -29,9 +30,9 @@ setegid (gid_t gid) + return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL); + + #ifdef __NR_setresgid32 +- result = INLINE_SETXID_SYSCALL (setresgid32, 3, -1, gid, -1); ++ result = syscall (__NR_setresgid32, 3, -1, gid, -1); + #else +- result = INLINE_SETXID_SYSCALL (setresgid, 3, -1, gid, -1); ++ result = syscall (__NR_setresgid, 3, -1, gid, -1); + #endif + + return result; +diff --git a/sysdeps/unix/sysv/linux/seteuid.c b/sysdeps/unix/sysv/linux/seteuid.c +index 64d3c84f..75e7497c 100644 +--- a/sysdeps/unix/sysv/linux/seteuid.c ++++ b/sysdeps/unix/sysv/linux/seteuid.c +@@ -18,6 +18,7 @@ + #include + #include + #include ++#include + + + int +@@ -29,9 +30,9 @@ seteuid (uid_t uid) + return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL); + + #ifdef __NR_setresuid32 +- result = INLINE_SETXID_SYSCALL (setresuid32, 3, -1, uid, -1); ++ result = syscall (__NR_setresuid32, 3, -1, uid, -1); + #else +- result = INLINE_SETXID_SYSCALL (setresuid, 3, -1, uid, -1); ++ result = syscall (__NR_setresuid, 3, -1, uid, -1); + #endif + + return result; +diff --git a/sysdeps/unix/sysv/linux/setgid.c b/sysdeps/unix/sysv/linux/setgid.c +index 51d4df8a..8b065c03 100644 +--- a/sysdeps/unix/sysv/linux/setgid.c ++++ b/sysdeps/unix/sysv/linux/setgid.c +@@ -18,15 +18,16 @@ + #include + #include + #include ++#include + + + int + __setgid (gid_t gid) + { + #ifdef __NR_setgid32 +- return INLINE_SETXID_SYSCALL (setgid32, 1, gid); ++ return syscall (__NR_setgid32, 1, gid); + #else +- return INLINE_SETXID_SYSCALL (setgid, 1, gid); ++ return syscall (__NR_setgid, 1, gid); + #endif + } + #ifndef __setgid +diff --git a/sysdeps/unix/sysv/linux/setregid.c b/sysdeps/unix/sysv/linux/setregid.c +index 2e89677a..4c3ea415 100644 +--- a/sysdeps/unix/sysv/linux/setregid.c ++++ b/sysdeps/unix/sysv/linux/setregid.c +@@ -18,15 +18,16 @@ + #include + #include + #include ++#include + + + int + __setregid (gid_t rgid, gid_t egid) + { + #ifdef __NR_setregid32 +- return INLINE_SETXID_SYSCALL (setregid32, 2, rgid, egid); ++ return syscall (__NR_setregid32, 2, rgid, egid); + #else +- return INLINE_SETXID_SYSCALL (setregid, 2, rgid, egid); ++ return syscall (__NR_setregid, 2, rgid, egid); + #endif + } + #ifndef __setregid +diff --git a/sysdeps/unix/sysv/linux/setresgid.c b/sysdeps/unix/sysv/linux/setresgid.c +index 6b44503c..7b1a9f39 100644 +--- a/sysdeps/unix/sysv/linux/setresgid.c ++++ b/sysdeps/unix/sysv/linux/setresgid.c +@@ -18,15 +18,16 @@ + #include + #include + #include ++#include + + + int + __setresgid (gid_t rgid, gid_t egid, gid_t sgid) + { + #ifdef __NR_setresgid32 +- return INLINE_SETXID_SYSCALL (setresgid32, 3, rgid, egid, sgid); ++ return syscall (__NR_setresgid32, 3, rgid, egid, sgid); + #else +- return INLINE_SETXID_SYSCALL (setresgid, 3, rgid, egid, sgid); ++ return syscall (__NR_setresgid, 3, rgid, egid, sgid); + #endif + } + libc_hidden_def (__setresgid) +diff --git a/sysdeps/unix/sysv/linux/setresuid.c b/sysdeps/unix/sysv/linux/setresuid.c +index 3339779a..f104b2a2 100644 +--- a/sysdeps/unix/sysv/linux/setresuid.c ++++ b/sysdeps/unix/sysv/linux/setresuid.c +@@ -18,15 +18,16 @@ + #include + #include + #include ++#include + + + int + __setresuid (uid_t ruid, uid_t euid, uid_t suid) + { + #ifdef __NR_setresuid32 +- return INLINE_SETXID_SYSCALL (setresuid32, 3, ruid, euid, suid); ++ return syscall (__NR_setresuid32, 3, ruid, euid, suid); + #else +- return INLINE_SETXID_SYSCALL (setresuid, 3, ruid, euid, suid); ++ return syscall (__NR_setresuid, 3, ruid, euid, suid); + #endif + } + libc_hidden_def (__setresuid) +diff --git a/sysdeps/unix/sysv/linux/setreuid.c b/sysdeps/unix/sysv/linux/setreuid.c +index a3889b3f..8728cd10 100644 +--- a/sysdeps/unix/sysv/linux/setreuid.c ++++ b/sysdeps/unix/sysv/linux/setreuid.c +@@ -18,15 +18,16 @@ + #include + #include + #include ++#include + + + int + __setreuid (uid_t ruid, uid_t euid) + { + #ifdef __NR_setreuid32 +- return INLINE_SETXID_SYSCALL (setreuid32, 2, ruid, euid); ++ return syscall (__NR_setreuid32, 2, ruid, euid); + #else +- return INLINE_SETXID_SYSCALL (setreuid, 2, ruid, euid); ++ return syscall (__NR_setreuid, 2, ruid, euid); + #endif + } + #ifndef __setreuid +diff --git a/sysdeps/unix/sysv/linux/setuid.c b/sysdeps/unix/sysv/linux/setuid.c +index 39d5e0cf..3e1e0bcb 100644 +--- a/sysdeps/unix/sysv/linux/setuid.c ++++ b/sysdeps/unix/sysv/linux/setuid.c +@@ -18,14 +18,15 @@ + #include + #include + #include ++#include + + int + __setuid (uid_t uid) + { + #ifdef __NR_setuid32 +- return INLINE_SETXID_SYSCALL (setuid32, 1, uid); ++ return syscall (__NR_setuid32, 1, uid); + #else +- return INLINE_SETXID_SYSCALL (setuid, 1, uid); ++ return syscall (__NR_setuid, 1, uid); + #endif + } + #ifndef __setuid +diff --git a/sysdeps/unix/sysv/linux/spawni.c b/sysdeps/unix/sysv/linux/spawni.c +index e8ed2bab..7a4ab68b 100644 +--- a/sysdeps/unix/sysv/linux/spawni.c ++++ b/sysdeps/unix/sysv/linux/spawni.c +@@ -27,6 +27,7 @@ + #include + #include + #include ++#include + + /* The Linux implementation of posix_spawn{p} uses the clone syscall directly + with CLONE_VM and CLONE_VFORK flags and an allocated stack. The new stack +@@ -265,7 +266,7 @@ __spawni_child (void *arguments) + case spawn_do_closefrom: + { + int lowfd = action->action.closefrom_action.from; +- int r = INLINE_SYSCALL_CALL (close_range, lowfd, ~0U, 0); ++ int r = syscall (__NR_close_range, lowfd, ~0U, 0); + if (r != 0 && !__closefrom_fallback (lowfd, false)) + goto fail; + } break; +diff --git a/sysdeps/unix/sysv/linux/statx.c b/sysdeps/unix/sysv/linux/statx.c +index a6295a15..db970a8d 100644 +--- a/sysdeps/unix/sysv/linux/statx.c ++++ b/sysdeps/unix/sysv/linux/statx.c +@@ -19,20 +19,11 @@ + #include + #include + #include +-#include "statx_generic.c" ++#include + + int + statx (int fd, const char *path, int flags, + unsigned int mask, struct statx *buf) + { +- int ret = INLINE_SYSCALL_CALL (statx, fd, path, flags, mask, buf); +-#ifdef __ASSUME_STATX +- return ret; +-#else +- if (ret == 0 || errno != ENOSYS) +- /* Preserve non-error/non-ENOSYS return values. */ +- return ret; +- else +- return statx_generic (fd, path, flags, mask, buf); +-#endif ++ return syscall (__NR_statx, fd, path, flags, mask, buf); + } diff --git a/gpkg/glibc/set-ld-variables.patch b/gpkg/glibc/set-ld-variables.patch new file mode 100644 index 000000000..09740e980 --- /dev/null +++ b/gpkg/glibc/set-ld-variables.patch @@ -0,0 +1,124 @@ +diff --git a/elf/dl-environ.c b/elf/dl-environ.c +index cb759a44..998c5a57 100644 +--- a/elf/dl-environ.c ++++ b/elf/dl-environ.c +@@ -21,6 +21,22 @@ + #include + #include + ++#define HAVE_LD_SUFFIX \ ++ __builtin_expect ((*current)[0] == 'L', 0) && \ ++ (*current)[1] == 'D' && \ ++ (*current)[2] == '_' ++ ++#define HAVE_GLIBC_SUFFIX \ ++ __builtin_expect ((*current)[0] == 'G', 0) && \ ++ (*current)[1] == 'L' && \ ++ (*current)[2] == 'I' && \ ++ (*current)[3] == 'B' && \ ++ (*current)[4] == 'C' && \ ++ (*current)[5] == '_' && \ ++ (*current)[6] == 'L' && \ ++ (*current)[7] == 'D' && \ ++ (*current)[8] == '_' ++ + /* Walk through the environment of the process and return all entries + starting with `LD_'. */ + char * +@@ -31,16 +47,15 @@ _dl_next_ld_env_entry (char ***position) + + while (*current != NULL) + { +- if (__builtin_expect ((*current)[0] == 'L', 0) +- && (*current)[1] == 'D' && (*current)[2] == '_') +- { +- result = &(*current)[3]; +- +- /* Save current position for next visit. */ +- *position = ++current; +- +- break; +- } ++ if (HAVE_LD_SUFFIX) { ++ result = &(*current)[3]; ++ *position = ++current; ++ break; ++ } else if (HAVE_GLIBC_SUFFIX) { ++ result = &(*current)[9]; ++ *position = ++current; ++ break; ++ } + + ++current; + } +diff --git a/elf/dl-support.c b/elf/dl-support.c +index 2f502c8b..e1614c76 100644 +--- a/elf/dl-support.c ++++ b/elf/dl-support.c +@@ -293,11 +293,11 @@ _dl_non_dynamic_init (void) + } + } + +- _dl_verbose = *(getenv ("LD_WARN") ?: "") == '\0' ? 0 : 1; ++ _dl_verbose = *(getenv ("GLIBC_LD_WARN") ?: getenv ("LD_WARN") ?: "") == '\0' ? 0 : 1; + + /* Initialize the data structures for the search paths for shared + objects. */ +- _dl_init_paths (getenv ("LD_LIBRARY_PATH"), "LD_LIBRARY_PATH", ++ _dl_init_paths (getenv ("GLIBC_LD_LIBRARY_PATH") ?: getenv ("LD_LIBRARY_PATH"), "LD_LIBRARY_PATH", + /* No glibc-hwcaps selection support in statically + linked binaries. */ + NULL, NULL); +@@ -305,11 +305,11 @@ _dl_non_dynamic_init (void) + /* Remember the last search directory added at startup. */ + _dl_init_all_dirs = GL(dl_all_dirs); + +- _dl_lazy = *(getenv ("LD_BIND_NOW") ?: "") == '\0'; ++ _dl_lazy = *(getenv ("GLIBC_LD_BIND_NOW") ?: getenv ("LD_BIND_NOW") ?: "") == '\0'; + +- _dl_bind_not = *(getenv ("LD_BIND_NOT") ?: "") != '\0'; ++ _dl_bind_not = *(getenv ("GLIBC_LD_BIND_NOT") ?: getenv ("LD_BIND_NOT") ?: "") != '\0'; + +- _dl_dynamic_weak = *(getenv ("LD_DYNAMIC_WEAK") ?: "") == '\0'; ++ _dl_dynamic_weak = *(getenv ("GLIBC_LD_DYNAMIC_WEAK") ?: getenv ("LD_DYNAMIC_WEAK") ?: "") == '\0'; + + #ifdef DL_PLATFORM_INIT + DL_PLATFORM_INIT; +diff --git a/elf/dl-usage.c b/elf/dl-usage.c +index 5baac4ba..77ac93d4 100644 +--- a/elf/dl-usage.c ++++ b/elf/dl-usage.c +@@ -187,7 +187,7 @@ setting environment variables (which would be inherited by subprocesses).\n\ + object we can handle\n\ + --inhibit-cache Do not use " LD_SO_CACHE "\n\ + --library-path PATH use given PATH instead of content of the environment\n\ +- variable LD_LIBRARY_PATH\n\ ++ variable LD_LIBRARY_PATH or GLIBC_LD_LIBRARY_PATH\n\ + --glibc-hwcaps-prepend LIST\n\ + search glibc-hwcaps subdirectories in LIST\n\ + --glibc-hwcaps-mask LIST\n\ +diff --git a/sysdeps/generic/unsecvars.h b/sysdeps/generic/unsecvars.h +index f1724efe..8f0fa1a9 100644 +--- a/sysdeps/generic/unsecvars.h ++++ b/sysdeps/generic/unsecvars.h +@@ -20,6 +20,20 @@ + "LD_SHOW_AUXV\0" \ + "LD_VERBOSE\0" \ + "LD_WARN\0" \ ++ "GLIBC_LD_AUDIT\0" \ ++ "GLIBC_LD_BIND_NOT\0" \ ++ "GLIBC_LD_BIND_NOW\0" \ ++ "GLIBC_LD_DEBUG\0" \ ++ "GLIBC_LD_DEBUG_OUTPUT\0" \ ++ "GLIBC_LD_DYNAMIC_WEAK\0" \ ++ "GLIBC_LD_HWCAP_MASK\0" \ ++ "GLIBC_LD_LIBRARY_PATH\0" \ ++ "GLIBC_LD_ORIGIN_PATH\0" \ ++ "GLIBC_LD_PRELOAD\0" \ ++ "GLIBC_LD_PROFILE\0" \ ++ "GLIBC_LD_SHOW_AUXV\0" \ ++ "GLIBC_LD_VERBOSE\0" \ ++ "GLIBC_LD_WARN\0" \ + "LOCALDOMAIN\0" \ + "LOCPATH\0" \ + "MALLOC_ARENA_MAX\0" \ diff --git a/gpkg/glibc/set-nptl-syscalls.patch b/gpkg/glibc/set-nptl-syscalls.patch new file mode 100644 index 000000000..9f226bfc6 --- /dev/null +++ b/gpkg/glibc/set-nptl-syscalls.patch @@ -0,0 +1,87 @@ +diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c +index 1d3665d5..1d02267e 100644 +--- a/nptl/pthread_create.c ++++ b/nptl/pthread_create.c +@@ -379,16 +379,6 @@ start_thread (void *arg) + __libc_fatal ("Fatal glibc error: rseq registration failed\n"); + } + +-#ifndef __ASSUME_SET_ROBUST_LIST +- if (__nptl_set_robust_list_avail) +-#endif +- { +- /* This call should never fail because the initial call in init.c +- succeeded. */ +- INTERNAL_SYSCALL_CALL (set_robust_list, &pd->robust_head, +- sizeof (struct robust_list_head)); +- } +- + /* This is where the try/finally block should be created. For + compilers without that support we do use setjmp. */ + struct pthread_unwind_buf unwind_buf; +diff --git a/sysdeps/nptl/_Fork.c b/sysdeps/nptl/_Fork.c +index ef199ddb..7d8afcec 100644 +--- a/sysdeps/nptl/_Fork.c ++++ b/sysdeps/nptl/_Fork.c +@@ -41,8 +41,6 @@ _Fork (void) + self->robust_prev = &self->robust_head; + #endif + self->robust_head.list = &self->robust_head; +- INTERNAL_SYSCALL_CALL (set_robust_list, &self->robust_head, +- sizeof (struct robust_list_head)); + } + return pid; + } +diff --git a/sysdeps/nptl/dl-tls_init_tp.c b/sysdeps/nptl/dl-tls_init_tp.c +index 092c274f..dcc9de5f 100644 +--- a/sysdeps/nptl/dl-tls_init_tp.c ++++ b/sysdeps/nptl/dl-tls_init_tp.c +@@ -90,14 +90,9 @@ __tls_init_tp (void) + pd->robust_head.futex_offset = (offsetof (pthread_mutex_t, __data.__lock) + - offsetof (pthread_mutex_t, + __data.__list.__next)); +- int res = INTERNAL_SYSCALL_CALL (set_robust_list, &pd->robust_head, +- sizeof (struct robust_list_head)); +- if (!INTERNAL_SYSCALL_ERROR_P (res)) +- { + #ifndef __ASSUME_SET_ROBUST_LIST +- __nptl_set_robust_list_avail = true; ++ __nptl_set_robust_list_avail = false; + #endif +- } + } + + { +diff --git a/sysdeps/unix/sysv/linux/rseq-internal.h b/sysdeps/unix/sysv/linux/rseq-internal.h +index 48eebc1e..84c878f3 100644 +--- a/sysdeps/unix/sysv/linux/rseq-internal.h ++++ b/sysdeps/unix/sysv/linux/rseq-internal.h +@@ -25,28 +25,11 @@ + #include + #include + +-#ifdef RSEQ_SIG + static inline bool + rseq_register_current_thread (struct pthread *self, bool do_rseq) + { +- if (do_rseq) +- { +- int ret = INTERNAL_SYSCALL_CALL (rseq, &self->rseq_area, +- sizeof (self->rseq_area), +- 0, RSEQ_SIG); +- if (!INTERNAL_SYSCALL_ERROR_P (ret)) +- return true; +- } + THREAD_SETMEM (self, rseq_area.cpu_id, RSEQ_CPU_ID_REGISTRATION_FAILED); + return false; + } +-#else /* RSEQ_SIG */ +-static inline bool +-rseq_register_current_thread (struct pthread *self, bool do_rseq) +-{ +- THREAD_SETMEM (self, rseq_area.cpu_id, RSEQ_CPU_ID_REGISTRATION_FAILED); +- return false; +-} +-#endif /* RSEQ_SIG */ + + #endif /* rseq-internal.h */ diff --git a/gpkg/glibc/setegid.c.patch b/gpkg/glibc/setegid.c.patch deleted file mode 100644 index 8f3e6fe4a..000000000 --- a/gpkg/glibc/setegid.c.patch +++ /dev/null @@ -1,17 +0,0 @@ ---- glibc-2.39/sysdeps/unix/sysv/linux/setegid.c 2023-07-31 20:54:16.000000000 +0300 -+++ glibc-2.39/sysdeps/unix/sysv/linux/setegid.c.patch 2023-10-20 13:41:29.056169208 +0300 -@@ -28,13 +28,7 @@ - if (gid == (gid_t) ~0) - return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL); - --#ifdef __NR_setresgid32 -- result = INLINE_SETXID_SYSCALL (setresgid32, 3, -1, gid, -1); --#else -- result = INLINE_SETXID_SYSCALL (setresgid, 3, -1, gid, -1); --#endif -- -- return result; -+ return 0; - } - #ifndef setegid - libc_hidden_def (setegid) diff --git a/gpkg/glibc/setgid.c.patch b/gpkg/glibc/setgid.c.patch deleted file mode 100644 index 71cdf346a..000000000 --- a/gpkg/glibc/setgid.c.patch +++ /dev/null @@ -1,15 +0,0 @@ ---- glibc-2.39/sysdeps/unix/sysv/linux/setgid.c 2023-07-31 20:54:16.000000000 +0300 -+++ glibc-2.39/sysdeps/unix/sysv/linux/setgid.c.patch 2023-10-20 18:56:19.607101054 +0300 -@@ -23,11 +23,7 @@ - int - __setgid (gid_t gid) - { --#ifdef __NR_setgid32 -- return INLINE_SETXID_SYSCALL (setgid32, 1, gid); --#else -- return INLINE_SETXID_SYSCALL (setgid, 1, gid); --#endif -+ return 0; - } - #ifndef __setgid - weak_alias (__setgid, setgid) diff --git a/gpkg/glibc/setresgid.c.patch b/gpkg/glibc/setresgid.c.patch deleted file mode 100644 index 95709665f..000000000 --- a/gpkg/glibc/setresgid.c.patch +++ /dev/null @@ -1,15 +0,0 @@ ---- glibc-2.39/sysdeps/unix/sysv/linux/setresgid.c 2023-07-31 20:54:16.000000000 +0300 -+++ glibc-2.39/sysdeps/unix/sysv/linux/setresgid.c.patch 2023-10-20 13:46:15.746169098 +0300 -@@ -23,11 +23,7 @@ - int - __setresgid (gid_t rgid, gid_t egid, gid_t sgid) - { --#ifdef __NR_setresgid32 -- return INLINE_SETXID_SYSCALL (setresgid32, 3, rgid, egid, sgid); --#else -- return INLINE_SETXID_SYSCALL (setresgid, 3, rgid, egid, sgid); --#endif -+ return 0; - } - libc_hidden_def (__setresgid) - #ifndef __setresgid diff --git a/gpkg/glibc/setuid.c.patch b/gpkg/glibc/setuid.c.patch deleted file mode 100644 index 928fed314..000000000 --- a/gpkg/glibc/setuid.c.patch +++ /dev/null @@ -1,15 +0,0 @@ ---- glibc-2.39/sysdeps/unix/sysv/linux/setuid.c 2023-07-31 20:54:16.000000000 +0300 -+++ glibc-2.39/sysdeps/unix/sysv/linux/setuid.c.patch 2023-10-20 18:54:34.107101094 +0300 -@@ -22,11 +22,7 @@ - int - __setuid (uid_t uid) - { --#ifdef __NR_setuid32 -- return INLINE_SETXID_SYSCALL (setuid32, 1, uid); --#else -- return INLINE_SETXID_SYSCALL (setuid, 1, uid); --#endif -+ return 0; - } - #ifndef __setuid - weak_alias (__setuid, setuid) diff --git a/gpkg/glibc/shmat.c b/gpkg/glibc/shmat.c index 4d636ddd7..2e0141d73 100644 --- a/gpkg/glibc/shmat.c +++ b/gpkg/glibc/shmat.c @@ -1,6 +1,3 @@ -#include -#include -#include #include #include @@ -8,8 +5,7 @@ segment of the calling process. SHMADDR and SHMFLG determine how and where the segment is attached. */ -void* shmat(int shmid, void const* shmaddr, int shmflg) -{ +void* shmat(int shmid, const void* shmaddr, int shmflg) { ashv_check_pid(); int socket_id = ashv_socket_id_from_shmid(shmid); diff --git a/gpkg/glibc/shmctl.c b/gpkg/glibc/shmctl.c index 9af84d58d..bb306e317 100644 --- a/gpkg/glibc/shmctl.c +++ b/gpkg/glibc/shmctl.c @@ -1,18 +1,10 @@ +#include #include -#include -#include #include -#include -#include #include #include -#ifndef shmid_ds -# define shmid_ds shmid64_ds -#endif - -int shmctl(int shmid, int cmd, struct shmid_ds *buf) -{ +int __shmctl64(int shmid, int cmd, struct __shmid64_ds *buf) { ashv_check_pid(); if (cmd == IPC_RMID) { @@ -55,13 +47,13 @@ int shmctl(int shmid, int cmd, struct shmid_ds *buf) memset(buf, 0, sizeof(struct shmid_ds)); buf->shm_segsz = shmem[idx].size; buf->shm_nattch = 1; - buf->shm_perm.key = shmem[idx].key; + buf->shm_perm.__key = shmem[idx].key; buf->shm_perm.uid = geteuid(); buf->shm_perm.gid = getegid(); buf->shm_perm.cuid = geteuid(); buf->shm_perm.cgid = getegid(); buf->shm_perm.mode = 0666; - buf->shm_perm.seq = 1; + buf->shm_perm.__seq = 1; pthread_mutex_unlock (&mutex); return 0; @@ -72,4 +64,66 @@ int shmctl(int shmid, int cmd, struct shmid_ds *buf) return -1; } -weak_alias (shmctl, __shmctl64) +#if __TIMESIZE != 64 +libc_hidden_def(__shmctl64) + +static void shmid_to_shmid64(struct __shmid64_ds *shm64, const struct shmid_ds *shm) { + shm64->shm_perm = shm->shm_perm; + shm64->shm_segsz = shm->shm_segsz; + shm64->shm_atime = shm->shm_atime | ((__time64_t) shm->__shm_atime_high << 32); + shm64->shm_dtime = shm->shm_dtime | ((__time64_t) shm->__shm_dtime_high << 32); + shm64->shm_ctime = shm->shm_ctime | ((__time64_t) shm->__shm_ctime_high << 32); + shm64->shm_cpid = shm->shm_cpid; + shm64->shm_lpid = shm->shm_lpid; + shm64->shm_nattch = shm->shm_nattch; +} + +static void shmid64_to_shmid(struct shmid_ds *shm, const struct __shmid64_ds *shm64) { + shm->shm_perm = shm64->shm_perm; + shm->shm_segsz = shm64->shm_segsz; + shm->shm_atime = shm64->shm_atime; + shm->__shm_atime_high = 0; + shm->shm_dtime = shm64->shm_dtime; + shm->__shm_dtime_high = 0; + shm->shm_ctime = shm64->shm_ctime; + shm->__shm_ctime_high = 0; + shm->shm_cpid = shm64->shm_cpid; + shm->shm_lpid = shm64->shm_lpid; + shm->shm_nattch = shm64->shm_nattch; +} + +int __shmctl(int shmid, int cmd, struct shmid_ds *buf) { + struct __shmid64_ds shmid64, *buf64 = NULL; + if (buf != NULL) { + if (cmd == IPC_INFO || cmd == SHM_INFO) + buf64 = (struct __shmid64_ds *) buf; + else { + shmid_to_shmid64 (&shmid64, buf); + buf64 = &shmid64; + } + } + + int ret = __shmctl64 (shmid, cmd, buf64); + if (ret < 0) + return ret; + + switch (cmd) { + case IPC_STAT: + case SHM_STAT: + case SHM_STAT_ANY: + shmid64_to_shmid (buf, buf64); + } + + return ret; +} +#endif + +#ifndef DEFAULT_VERSION +# ifndef __ASSUME_SYSVIPC_BROKEN_MODE_T +# define DEFAULT_VERSION GLIBC_2_2 +# else +# define DEFAULT_VERSION GLIBC_2_31 +# endif +#endif + +versioned_symbol(libc, __shmctl, shmctl, DEFAULT_VERSION); diff --git a/gpkg/glibc/shmdt.c b/gpkg/glibc/shmdt.c index 06827fa75..a1ab382a3 100644 --- a/gpkg/glibc/shmdt.c +++ b/gpkg/glibc/shmdt.c @@ -1,14 +1,10 @@ -#include -#include -#include #include #include /* Detach shared memory segment starting at address specified by SHMADDR from the caller's data segment. */ -int shmdt(void const* shmaddr) -{ +int shmdt(const void* shmaddr) { ashv_check_pid(); pthread_mutex_lock(&mutex); diff --git a/gpkg/glibc/shmem-android.c b/gpkg/glibc/shmem-android.c new file mode 100644 index 000000000..a4a16edca --- /dev/null +++ b/gpkg/glibc/shmem-android.c @@ -0,0 +1,248 @@ +/* - dependencies (values ​​and commands) for system V shared + * memory emulation on Android using ashmem. Needed in the following files: + * - shmat.c + * - shmctl.c + * - shmdt.c + * - shmget.c + * + * The code was taken from the libandroid-shmem repo: + * + * + * PS: it's adding libandroid-shmem to the glibc system with some modifications + * to make it work on a glibc basis. + */ + +#include + +pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; +shmem_t* shmem = NULL; +size_t shmem_amount = 0; +int ashv_local_socket_id = 0; +int ashv_pid_setup = 0; +pthread_t ashv_listening_thread_id = 0; + +static int ancil_send_fd(int sock, int fd) { + char nothing = '!'; + struct iovec nothing_ptr = { .iov_base = ¬hing, .iov_len = 1 }; + + struct { + struct cmsghdr align; + int fd[1]; + } ancillary_data_buffer; + + struct msghdr message_header = { + .msg_name = NULL, + .msg_namelen = 0, + .msg_iov = ¬hing_ptr, + .msg_iovlen = 1, + .msg_flags = 0, + .msg_control = &ancillary_data_buffer, + .msg_controllen = sizeof(struct cmsghdr) + sizeof(int) + }; + + struct cmsghdr* cmsg = CMSG_FIRSTHDR(&message_header); + cmsg->cmsg_len = message_header.msg_controllen; // sizeof(int); + cmsg->cmsg_level = SOL_SOCKET; + cmsg->cmsg_type = SCM_RIGHTS; + ((int*) CMSG_DATA(cmsg))[0] = fd; + + return sendmsg(sock, &message_header, 0) >= 0 ? 0 : -1; +} + +static int ancil_recv_fd(int sock) { + char nothing = '!'; + struct iovec nothing_ptr = { .iov_base = ¬hing, .iov_len = 1 }; + + struct { + struct cmsghdr align; + int fd[1]; + } ancillary_data_buffer; + + struct msghdr message_header = { + .msg_name = NULL, + .msg_namelen = 0, + .msg_iov = ¬hing_ptr, + .msg_iovlen = 1, + .msg_flags = 0, + .msg_control = &ancillary_data_buffer, + .msg_controllen = sizeof(struct cmsghdr) + sizeof(int) + }; + + struct cmsghdr* cmsg = CMSG_FIRSTHDR(&message_header); + cmsg->cmsg_len = message_header.msg_controllen; + cmsg->cmsg_level = SOL_SOCKET; + cmsg->cmsg_type = SCM_RIGHTS; + ((int*) CMSG_DATA(cmsg))[0] = -1; + + if (recvmsg(sock, &message_header, 0) < 0) return -1; + + return ((int*) CMSG_DATA(cmsg))[0]; +} + +static int ashmem_get_size_region(int fd) { + //int ret = __ashmem_is_ashmem(fd, 1); + //if (ret < 0) return ret; + return TEMP_FAILURE_RETRY(ioctl(fd, ASHMEM_GET_SIZE, NULL)); +} + +/* + * From https://android.googlesource.com/platform/system/core/+/master/libcutils/ashmem-dev.c + * + * ashmem_create_region - creates a new named ashmem region and returns the file + * descriptor, or <0 on error. + * + * `name' is the label to give the region (visible in /proc/pid/maps) + * `size' is the size of the region, in page-aligned bytes + */ +int ashmem_create_region(char const* name, size_t size) { + int fd = open("/dev/ashmem", O_RDWR); + if (fd < 0) return fd; + + char name_buffer[ASHMEM_NAME_LEN] = {0}; + strncpy(name_buffer, name, sizeof(name_buffer)); + name_buffer[sizeof(name_buffer)-1] = 0; + + int ret = ioctl(fd, ASHMEM_SET_NAME, name_buffer); + if (ret < 0) goto error; + + ret = ioctl(fd, ASHMEM_SET_SIZE, size); + if (ret < 0) goto error; + + return fd; +error: + close(fd); + return ret; +} + +void ashv_check_pid(void) { + pid_t mypid = getpid(); + if (ashv_pid_setup == 0) { + ashv_pid_setup = mypid; + } else if (ashv_pid_setup != mypid) { + DBG("%s: Cleaning to new pid=%d from oldpid=%d", __PRETTY_FUNCTION__, mypid, ashv_pid_setup); + // We inherited old state across a fork. + ashv_pid_setup = mypid; + ashv_local_socket_id = 0; + ashv_listening_thread_id = 0; + shmem_amount = 0; + // Unlock if fork left us with held lock from parent thread. + pthread_mutex_unlock(&mutex); + if (shmem != NULL) free(shmem); + shmem = NULL; + } +} + + +// Store index in the lower 15 bits and the socket id in the +// higher 16 bits. +int ashv_shmid_from_counter(unsigned int counter) { + return ashv_local_socket_id * 0x10000 + counter; +} + +int ashv_socket_id_from_shmid(int shmid) { + return shmid / 0x10000; +} + +int ashv_find_local_index(int shmid) { + for (size_t i = 0; i < shmem_amount; i++) + if (shmem[i].id == shmid) + return i; + return -1; +} + +void* ashv_thread_function(void* arg) { + int sock = *(int*)arg; + free(arg); + struct sockaddr_un addr; + socklen_t len = sizeof(addr); + int sendsock; + DBG("%s: thread started", __PRETTY_FUNCTION__); + while ((sendsock = accept(sock, (struct sockaddr *)&addr, &len)) != -1) { + int shmid; + if (recv(sendsock, &shmid, sizeof(shmid), 0) != sizeof(shmid)) { + DBG("%s: ERROR: recv() returned not %zu bytes", __PRETTY_FUNCTION__, sizeof(shmid)); + close(sendsock); + continue; + } + pthread_mutex_lock(&mutex); + int idx = ashv_find_local_index(shmid); + if (idx != -1) { + if (write(sendsock, &shmem[idx].key, sizeof(key_t)) != sizeof(key_t)) { + DBG("%s: ERROR: write failed: %s", __PRETTY_FUNCTION__, strerror(errno)); + } + if (ancil_send_fd(sendsock, shmem[idx].descriptor) != 0) { + DBG("%s: ERROR: ancil_send_fd() failed: %s", __PRETTY_FUNCTION__, strerror(errno)); + } + } else { + DBG("%s: ERROR: cannot find shmid 0x%x", __PRETTY_FUNCTION__, shmid); + } + pthread_mutex_unlock(&mutex); + close(sendsock); + len = sizeof(addr); + } + DBG ("%s: ERROR: listen() failed, thread stopped", __PRETTY_FUNCTION__); + return NULL; +} + +void android_shmem_delete(int idx) { + if (shmem[idx].descriptor) close(shmem[idx].descriptor); + shmem_amount--; + memmove(&shmem[idx], &shmem[idx+1], (shmem_amount - idx) * sizeof(shmem_t)); +} + +int ashv_read_remote_segment(int shmid) { + struct sockaddr_un addr; + memset(&addr, 0, sizeof(addr)); + addr.sun_family = AF_UNIX; + sprintf(&addr.sun_path[1], ANDROID_SHMEM_SOCKNAME, ashv_socket_id_from_shmid(shmid)); + int addrlen = sizeof(addr.sun_family) + strlen(&addr.sun_path[1]) + 1; + + int recvsock = socket(AF_UNIX, SOCK_STREAM, 0); + if (recvsock == -1) { + DBG ("%s: cannot create UNIX socket: %s", __PRETTY_FUNCTION__, strerror(errno)); + return -1; + } + if (connect(recvsock, (struct sockaddr*) &addr, addrlen) != 0) { + DBG("%s: Cannot connect to UNIX socket %s: %s, len %d", __PRETTY_FUNCTION__, addr.sun_path + 1, strerror(errno), addrlen); + close(recvsock); + return -1; + } + + if (send(recvsock, &shmid, sizeof(shmid), 0) != sizeof(shmid)) { + DBG ("%s: send() failed on socket %s: %s", __PRETTY_FUNCTION__, addr.sun_path + 1, strerror(errno)); + close(recvsock); + return -1; + } + + key_t key; + if (read(recvsock, &key, sizeof(key_t)) != sizeof(key_t)) { + DBG("%s: ERROR: failed read", __PRETTY_FUNCTION__); + close(recvsock); + return -1; + } + + int descriptor = ancil_recv_fd(recvsock); + if (descriptor < 0) { + DBG("%s: ERROR: ancil_recv_fd() failed on socket %s: %s", __PRETTY_FUNCTION__, addr.sun_path + 1, strerror(errno)); + close(recvsock); + return -1; + } + close(recvsock); + + int size = ashmem_get_size_region(descriptor); + if (size == 0 || size == -1) { + DBG ("%s: ERROR: ashmem_get_size_region() returned %d on socket %s: %s", __PRETTY_FUNCTION__, size, addr.sun_path + 1, strerror(errno)); + return -1; + } + + int idx = shmem_amount; + shmem_amount ++; + shmem = realloc(shmem, shmem_amount * sizeof(shmem_t)); + shmem[idx].id = shmid; + shmem[idx].descriptor = descriptor; + shmem[idx].size = size; + shmem[idx].addr = NULL; + shmem[idx].markedForDeletion = false; + shmem[idx].key = key; + return idx; +} diff --git a/gpkg/glibc/shmem-android.h b/gpkg/glibc/shmem-android.h index 127a70c4c..6c7907a27 100644 --- a/gpkg/glibc/shmem-android.h +++ b/gpkg/glibc/shmem-android.h @@ -1,17 +1,3 @@ -/* - dependencies (values ​​and commands) for system V shared - * memory emulation on Android using ashmem. Needed in the following files: - * - shmat.c - * - shmctl.c - * - shmdt.c - * - shmget.c - * - * The code was taken from the libandroid-shmem repo: - * - * - * PS: it's adding libandroid-shmem to the glibc system with some modifications - * to make it work on a glibc basis. - */ - #ifndef __SHMEM_ANDROID #define __SHMEM_ANDROID @@ -20,10 +6,14 @@ #include #include #include +#include #include #include - -#define __u32 uint32_t +#include +#include +#include +#include +#include #ifdef ENABLE_DEBUG_SHMEM_ANDROID # define DBG(...) printf(__VA_ARGS__) @@ -50,249 +40,46 @@ typedef struct { key_t key; } shmem_t; -static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; - -static shmem_t* shmem = NULL; -static size_t shmem_amount = 0; -static int ashv_local_socket_id = 0; -static int ashv_pid_setup = 0; -static pthread_t ashv_listening_thread_id = 0; - -static int ancil_send_fd(int sock, int fd) -{ - char nothing = '!'; - struct iovec nothing_ptr = { .iov_base = ¬hing, .iov_len = 1 }; - - struct { - struct cmsghdr align; - int fd[1]; - } ancillary_data_buffer; - - struct msghdr message_header = { - .msg_name = NULL, - .msg_namelen = 0, - .msg_iov = ¬hing_ptr, - .msg_iovlen = 1, - .msg_flags = 0, - .msg_control = &ancillary_data_buffer, - .msg_controllen = sizeof(struct cmsghdr) + sizeof(int) - }; - - struct cmsghdr* cmsg = CMSG_FIRSTHDR(&message_header); - cmsg->cmsg_len = message_header.msg_controllen; // sizeof(int); - cmsg->cmsg_level = SOL_SOCKET; - cmsg->cmsg_type = SCM_RIGHTS; - ((int*) CMSG_DATA(cmsg))[0] = fd; - - return sendmsg(sock, &message_header, 0) >= 0 ? 0 : -1; -} - -static int ancil_recv_fd(int sock) -{ - char nothing = '!'; - struct iovec nothing_ptr = { .iov_base = ¬hing, .iov_len = 1 }; - - struct { - struct cmsghdr align; - int fd[1]; - } ancillary_data_buffer; - - struct msghdr message_header = { - .msg_name = NULL, - .msg_namelen = 0, - .msg_iov = ¬hing_ptr, - .msg_iovlen = 1, - .msg_flags = 0, - .msg_control = &ancillary_data_buffer, - .msg_controllen = sizeof(struct cmsghdr) + sizeof(int) - }; - - struct cmsghdr* cmsg = CMSG_FIRSTHDR(&message_header); - cmsg->cmsg_len = message_header.msg_controllen; - cmsg->cmsg_level = SOL_SOCKET; - cmsg->cmsg_type = SCM_RIGHTS; - ((int*) CMSG_DATA(cmsg))[0] = -1; +extern pthread_mutex_t mutex; +extern shmem_t* shmem; +extern size_t shmem_amount; +extern int ashv_local_socket_id; +extern int ashv_pid_setup; +extern pthread_t ashv_listening_thread_id; - if (recvmsg(sock, &message_header, 0) < 0) return -1; +// PS: some functions are not available for including because they are used only inside shmem-android - return ((int*) CMSG_DATA(cmsg))[0]; -} +//extern int ancil_send_fd(int sock, int fd) __THROW; +//libc_hidden_proto(ancil_send_fd) -static int ashmem_get_size_region(int fd) -{ - //int ret = __ashmem_is_ashmem(fd, 1); - //if (ret < 0) return ret; - return TEMP_FAILURE_RETRY(ioctl(fd, ASHMEM_GET_SIZE, NULL)); -} +//extern int ancil_recv_fd(int sock) __THROW; +//libc_hidden_proto(ancil_recv_fd) -/* - * From https://android.googlesource.com/platform/system/core/+/master/libcutils/ashmem-dev.c - * - * ashmem_create_region - creates a new named ashmem region and returns the file - * descriptor, or <0 on error. - * - * `name' is the label to give the region (visible in /proc/pid/maps) - * `size' is the size of the region, in page-aligned bytes - */ -static int ashmem_create_region(char const* name, size_t size) -{ - int fd = open("/dev/ashmem", O_RDWR); - if (fd < 0) return fd; +//extern int ashmem_get_size_region(int fd) __THROW; +//libc_hidden_proto(ashmem_get_size_region) - char name_buffer[ASHMEM_NAME_LEN] = {0}; - strncpy(name_buffer, name, sizeof(name_buffer)); - name_buffer[sizeof(name_buffer)-1] = 0; +extern int ashmem_create_region(char const* name, size_t size) __THROW; +libc_hidden_proto(ashmem_create_region) - int ret = ioctl(fd, ASHMEM_SET_NAME, name_buffer); - if (ret < 0) goto error; +extern void ashv_check_pid(void) __THROW; +libc_hidden_proto(ashv_check_pid) - ret = ioctl(fd, ASHMEM_SET_SIZE, size); - if (ret < 0) goto error; +extern int ashv_shmid_from_counter(unsigned int counter) __THROW; +libc_hidden_proto(ashv_shmid_from_counter) - return fd; -error: - close(fd); - return ret; -} +extern int ashv_socket_id_from_shmid(int shmid) __THROW; +libc_hidden_proto(ashv_socket_id_from_shmid) -static void ashv_check_pid() -{ - pid_t mypid = getpid(); - if (ashv_pid_setup == 0) { - ashv_pid_setup = mypid; - } else if (ashv_pid_setup != mypid) { - DBG("%s: Cleaning to new pid=%d from oldpid=%d", __PRETTY_FUNCTION__, mypid, ashv_pid_setup); - // We inherited old state across a fork. - ashv_pid_setup = mypid; - ashv_local_socket_id = 0; - ashv_listening_thread_id = 0; - shmem_amount = 0; - // Unlock if fork left us with held lock from parent thread. - pthread_mutex_unlock(&mutex); - if (shmem != NULL) free(shmem); - shmem = NULL; - } -} - - -// Store index in the lower 15 bits and the socket id in the -// higher 16 bits. -static int ashv_shmid_from_counter(unsigned int counter) -{ - return ashv_local_socket_id * 0x10000 + counter; -} - -static int ashv_socket_id_from_shmid(int shmid) -{ - return shmid / 0x10000; -} - -static int ashv_find_local_index(int shmid) -{ - for (size_t i = 0; i < shmem_amount; i++) - if (shmem[i].id == shmid) - return i; - return -1; -} - -static void* ashv_thread_function(void* arg) -{ - int sock = *(int*)arg; - free(arg); - struct sockaddr_un addr; - socklen_t len = sizeof(addr); - int sendsock; - DBG("%s: thread started", __PRETTY_FUNCTION__); - while ((sendsock = accept(sock, (struct sockaddr *)&addr, &len)) != -1) { - int shmid; - if (recv(sendsock, &shmid, sizeof(shmid), 0) != sizeof(shmid)) { - DBG("%s: ERROR: recv() returned not %zu bytes", __PRETTY_FUNCTION__, sizeof(shmid)); - close(sendsock); - continue; - } - pthread_mutex_lock(&mutex); - int idx = ashv_find_local_index(shmid); - if (idx != -1) { - if (write(sendsock, &shmem[idx].key, sizeof(key_t)) != sizeof(key_t)) { - DBG("%s: ERROR: write failed: %s", __PRETTY_FUNCTION__, strerror(errno)); - } - if (ancil_send_fd(sendsock, shmem[idx].descriptor) != 0) { - DBG("%s: ERROR: ancil_send_fd() failed: %s", __PRETTY_FUNCTION__, strerror(errno)); - } - } else { - DBG("%s: ERROR: cannot find shmid 0x%x", __PRETTY_FUNCTION__, shmid); - } - pthread_mutex_unlock(&mutex); - close(sendsock); - len = sizeof(addr); - } - DBG ("%s: ERROR: listen() failed, thread stopped", __PRETTY_FUNCTION__); - return NULL; -} - -static void android_shmem_delete(int idx) -{ - if (shmem[idx].descriptor) close(shmem[idx].descriptor); - shmem_amount--; - memmove(&shmem[idx], &shmem[idx+1], (shmem_amount - idx) * sizeof(shmem_t)); -} - -static int ashv_read_remote_segment(int shmid) -{ - struct sockaddr_un addr; - memset(&addr, 0, sizeof(addr)); - addr.sun_family = AF_UNIX; - sprintf(&addr.sun_path[1], ANDROID_SHMEM_SOCKNAME, ashv_socket_id_from_shmid(shmid)); - int addrlen = sizeof(addr.sun_family) + strlen(&addr.sun_path[1]) + 1; - - int recvsock = socket(AF_UNIX, SOCK_STREAM, 0); - if (recvsock == -1) { - DBG ("%s: cannot create UNIX socket: %s", __PRETTY_FUNCTION__, strerror(errno)); - return -1; - } - if (connect(recvsock, (struct sockaddr*) &addr, addrlen) != 0) { - DBG("%s: Cannot connect to UNIX socket %s: %s, len %d", __PRETTY_FUNCTION__, addr.sun_path + 1, strerror(errno), addrlen); - close(recvsock); - return -1; - } - - if (send(recvsock, &shmid, sizeof(shmid), 0) != sizeof(shmid)) { - DBG ("%s: send() failed on socket %s: %s", __PRETTY_FUNCTION__, addr.sun_path + 1, strerror(errno)); - close(recvsock); - return -1; - } - - key_t key; - if (read(recvsock, &key, sizeof(key_t)) != sizeof(key_t)) { - DBG("%s: ERROR: failed read", __PRETTY_FUNCTION__); - close(recvsock); - return -1; - } +extern int ashv_find_local_index(int shmid) __THROW; +libc_hidden_proto(ashv_find_local_index) - int descriptor = ancil_recv_fd(recvsock); - if (descriptor < 0) { - DBG("%s: ERROR: ancil_recv_fd() failed on socket %s: %s", __PRETTY_FUNCTION__, addr.sun_path + 1, strerror(errno)); - close(recvsock); - return -1; - } - close(recvsock); +extern void* ashv_thread_function(void* arg) __THROW; +libc_hidden_proto(ashv_thread_function) - int size = ashmem_get_size_region(descriptor); - if (size == 0 || size == -1) { - DBG ("%s: ERROR: ashmem_get_size_region() returned %d on socket %s: %s", __PRETTY_FUNCTION__, size, addr.sun_path + 1, strerror(errno)); - return -1; - } +extern void android_shmem_delete(int idx) __THROW; +libc_hidden_proto(android_shmem_delete) - int idx = shmem_amount; - shmem_amount ++; - shmem = realloc(shmem, shmem_amount * sizeof(shmem_t)); - shmem[idx].id = shmid; - shmem[idx].descriptor = descriptor; - shmem[idx].size = size; - shmem[idx].addr = NULL; - shmem[idx].markedForDeletion = false; - shmem[idx].key = key; - return idx; -} +extern int ashv_read_remote_segment(int shmid) __THROW; +libc_hidden_proto(ashv_read_remote_segment) #endif /* __SHMEM_ANDROID */ diff --git a/gpkg/glibc/shmget.c b/gpkg/glibc/shmget.c index 6eaa740e4..9299562b9 100644 --- a/gpkg/glibc/shmget.c +++ b/gpkg/glibc/shmget.c @@ -1,14 +1,11 @@ +#include #include #include -#include -#include -#include /* Return an identifier for an shared memory segment of at least size SIZE which is associated with KEY. */ -int shmget(key_t key, size_t size, int flags) -{ +int shmget(key_t key, size_t size, int flags) { (void) flags; ashv_check_pid(); diff --git a/gpkg/glibc/sigrestorer.S.patch b/gpkg/glibc/sigrestorer.S.patch new file mode 100644 index 000000000..7f0982fca --- /dev/null +++ b/gpkg/glibc/sigrestorer.S.patch @@ -0,0 +1,10 @@ +--- glibc-2.39/sysdeps/unix/sysv/linux/arm/sigrestorer.S 2024-01-31 03:34:58.000000000 +0300 ++++ glibc-2.39/sysdeps/unix/sysv/linux/arm/sigrestorer.S.patch 2024-09-01 15:21:37.555593719 +0300 +@@ -16,6 +16,7 @@ + . */ + + #include ++#include + + /* If no SA_RESTORER function was specified by the application we use + one of these. This avoids the need for the kernel to synthesise a return diff --git a/gpkg/glibc/spawni.c.patch b/gpkg/glibc/spawni.c.patch deleted file mode 100644 index cfa79ad5f..000000000 --- a/gpkg/glibc/spawni.c.patch +++ /dev/null @@ -1,11 +0,0 @@ ---- glibc-2.39/sysdeps/unix/sysv/linux/spawni.c 2023-07-31 20:54:16.000000000 +0300 -+++ glibc-2.39/sysdeps/unix/sysv/linux/spawni.c.patch 2023-10-07 00:31:27.595087508 +0300 -@@ -264,7 +264,7 @@ - case spawn_do_closefrom: - { - int lowfd = action->action.closefrom_action.from; -- int r = INLINE_SYSCALL_CALL (close_range, lowfd, ~0U, 0); -+ int r = close_range (lowfd, ~0U, 0); - if (r != 0 && !__closefrom_fallback (lowfd, false)) - goto fail; - } break; diff --git a/gpkg/glibc/statx.c.patch b/gpkg/glibc/statx.c.patch deleted file mode 100644 index acb88385e..000000000 --- a/gpkg/glibc/statx.c.patch +++ /dev/null @@ -1,18 +0,0 @@ ---- glibc-2.39/sysdeps/unix/sysv/linux/statx.c 2022-02-03 08:27:54.000000000 +0300 -+++ glibc-2.39/sysdeps/unix/sysv/linux/statx.c.patch 2022-10-07 10:17:06.418934334 +0300 -@@ -25,14 +25,5 @@ - statx (int fd, const char *path, int flags, - unsigned int mask, struct statx *buf) - { -- int ret = INLINE_SYSCALL_CALL (statx, fd, path, flags, mask, buf); --#ifdef __ASSUME_STATX -- return ret; --#else -- if (ret == 0 || errno != ENOSYS) -- /* Preserve non-error/non-ENOSYS return values. */ -- return ret; -- else -- return statx_generic (fd, path, flags, mask, buf); --#endif -+ return statx_generic (fd, path, flags, mask, buf); - } diff --git a/gpkg/glibc/syscall.c b/gpkg/glibc/syscall.c index a411fe7a3..90e59b164 100644 --- a/gpkg/glibc/syscall.c +++ b/gpkg/glibc/syscall.c @@ -1,8 +1,9 @@ +#ifndef WITHOUT_FAKESYSCALL +# include +#else +# include +#endif #include -#include -#include - -extern long int syscallS (long int __sysno, ...) __THROW; long int syscall (long int number, ...) @@ -17,8 +18,14 @@ syscall (long int number, ...) long int a5 = va_arg (args, long int); va_end (args); - for (int i=0; i +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define ANDROID_LOG_VERBOSE 2 // not used :/ +#define ANDROID_LOG_DEBUG 3 +#define ANDROID_LOG_INFO 4 +#define ANDROID_LOG_WARN 5 +#define ANDROID_LOG_ERROR 6 +#define ANDROID_LOG_FATAL 7 + +#define LOG_ID_CRASH 4 +#define LOG_ID_MAIN 0 + +static const char* syslog_log_tag = NULL; +static int syslog_priority_mask = 0xff; +static int syslog_options = 0; +extern char *__progname; + +typedef struct log_time { + uint32_t tv_sec; + uint32_t tv_nsec; +} __attribute__((__packed__)) log_time; + +struct BufferOutputStream { + size_t total; + char* pos_; + size_t avail_; +}; + +struct BufferOutputStream BufferOutput(char* buffer, size_t size) { + struct BufferOutputStream buff; + buff.total = 0; + buff.pos_ = buffer; + buff.avail_ = size; + if (buff.avail_ > 0) + buff.pos_[0] = '\0'; + return buff; +} + +void Send(struct BufferOutputStream* buff, const char* data, int len) { + if (len < 0) + len = strlen(data); + buff->total += len; + + if (buff->avail_ <= 1) + // No space to put anything else. + return; + + if ((size_t)len >= buff->avail_) + len = buff->avail_ - 1; + memcpy(buff->pos_, data, len); + buff->pos_ += len; + buff->pos_[0] = '\0'; + buff->avail_ -= len; +} + +static unsigned parse_decimal(const char* format, int* ppos) { + const char* p = format + *ppos; + unsigned result = 0; + + for (;;) { + int ch = *p; + unsigned d = (unsigned)(ch - '0'); + + if (d >= 10U) + break; + + result = result * 10 + d; + p++; + } + *ppos = p - format; + return result; +} + +static void format_unsigned(char* buf, size_t buf_size, uint64_t value, int base, bool caps) { + char* p = buf; + char* end = buf + buf_size - 1; + + // Generate digit string in reverse order. + while (value) { + unsigned d = value % base; + value /= base; + if (p != end) { + char ch; + if (d < 10) + ch = '0' + d; + else + ch = (caps ? 'A' : 'a') + (d - 10); + *p++ = ch; + } + } + + // Special case for 0. + if (p == buf) + if (p != end) + *p++ = '0'; + *p = '\0'; + + // Reverse digit string in-place. + size_t length = p - buf; + for (size_t i = 0, j = length - 1; i < j; ++i, --j) { + char ch = buf[i]; + buf[i] = buf[j]; + buf[j] = ch; + } +} + +static void format_integer(char* buf, size_t buf_size, uint64_t value, char conversion) { + // Decode the conversion specifier. + int is_signed = (conversion == 'd' || conversion == 'i' || conversion == 'o'); + int base = 10; + if (tolower(conversion) == 'x') + base = 16; + else if (conversion == 'o') + base = 8; + else if (tolower(conversion) == 'b') + base = 2; + bool caps = (conversion == 'X'); + + if (is_signed && (int64_t)value < 0) { + buf[0] = '-'; + buf += 1; + buf_size -= 1; + value = (uint64_t)(-(int64_t)value); + } + format_unsigned(buf, buf_size, value, base, caps); +} + +static void SendRepeat(struct BufferOutputStream* buff, char ch, int count) { + char pad[8]; + memset(pad, ch, sizeof(pad)); + + const int pad_size = (int)sizeof(pad); + while (count > 0) { + int avail = count; + if (avail > pad_size) + avail = pad_size; + Send(buff, pad, avail); + count -= avail; + } +} + +static void out_vformat(struct BufferOutputStream* buff, const char* format, va_list args) { + int nn = 0; + + for (;;) { + int mm; + int padZero = 0; + int padLeft = 0; + char sign = '\0'; + int width = -1; + int prec = -1; + bool alternate = false; + size_t bytelen = sizeof(int); + int slen; + char buffer[64]; // temporary buffer used to format numbers/format errno string + + char c; + + /* first, find all characters that are not 0 or '%' */ + /* then send them to the output directly */ + mm = nn; + do { + c = format[mm]; + if (c == '\0' || c == '%') break; + mm++; + } while (1); + + if (mm > nn) { + Send(buff, format + nn, mm - nn); + nn = mm; + } + + /* is this it ? then exit */ + if (c == '\0') break; + + /* nope, we are at a '%' modifier */ + nn++; // skip it + + /* parse flags */ + for (;;) { + c = format[nn++]; + if (c == '\0') { /* single trailing '%' ? */ + c = '%'; + Send(buff, &c, 1); + return; + } else if (c == '0') { + padZero = 1; + continue; + } else if (c == '-') { + padLeft = 1; + continue; + } else if (c == ' ' || c == '+') { + sign = c; + continue; + } else if (c == '#') { + alternate = true; + continue; + } + break; + } + + /* parse field width */ + if ((c >= '0' && c <= '9')) { + nn--; + width = (int)parse_decimal(format, &nn); + c = format[nn++]; + } + + /* parse precision */ + if (c == '.') { + prec = (int)parse_decimal(format, &nn); + c = format[nn++]; + } + + /* length modifier */ + switch (c) { + case 'h': + bytelen = sizeof(short); + if (format[nn] == 'h') { + bytelen = sizeof(char); + nn += 1; + } + c = format[nn++]; + break; + case 'l': + bytelen = sizeof(long); + if (format[nn] == 'l') { + bytelen = sizeof(long long); + nn += 1; + } + c = format[nn++]; + break; + case 'z': + bytelen = sizeof(size_t); + c = format[nn++]; + break; + case 't': + bytelen = sizeof(ptrdiff_t); + c = format[nn++]; + break; + default:; + } + + /* conversion specifier */ + const char* str = buffer; + if (c == 's') { + /* string */ + str = va_arg(args, const char*); + } else if (c == 'c') { + /* character */ + /* NOTE: char is promoted to int when passed through the stack */ + buffer[0] = (char)va_arg(args, int); + buffer[1] = '\0'; + } else if (c == 'p') { + uint64_t value = (uintptr_t)va_arg(args, void*); + buffer[0] = '0'; + buffer[1] = 'x'; + format_integer(buffer + 2, sizeof(buffer) - 2, value, 'x'); + } else if (c == 'm') { + { + strerror_r(errno, buffer, sizeof(buffer)); + } + } else if (tolower(c) == 'b' || c == 'd' || c == 'i' || c == 'o' || c == 'u' || + tolower(c) == 'x') { + /* integers - first read value from stack */ + uint64_t value; + int is_signed = (c == 'd' || c == 'i' || c == 'o'); + + /* NOTE: int8_t and int16_t are promoted to int when passed + * through the stack + */ + switch (bytelen) { + case 1: + value = (uint8_t)va_arg(args, int); + break; + case 2: + value = (uint16_t)va_arg(args, int); + break; + case 4: + value = va_arg(args, uint32_t); + break; + case 8: + value = va_arg(args, uint64_t); + break; + default: + return; /* should not happen */ + } + + /* sign extension, if needed */ + if (is_signed) { + int shift = 64 - 8 * bytelen; + value = (uint64_t)(((int64_t)(value << shift)) >> shift); + } + + if (alternate && value != 0 && (tolower(c) == 'x' || c == 'o' || tolower(c) == 'b')) { + if (tolower(c) == 'x' || tolower(c) == 'b') { + buffer[0] = '0'; + buffer[1] = c; + format_integer(buffer + 2, sizeof(buffer) - 2, value, c); + } else { + buffer[0] = '0'; + format_integer(buffer + 1, sizeof(buffer) - 1, value, c); + } + } else + /* format the number properly into our buffer */ + format_integer(buffer, sizeof(buffer), value, c); + } else if (c == '%') { + buffer[0] = '%'; + buffer[1] = '\0'; + } else + __assert("conversion specifier unsupported", __FILE__, __LINE__); + + if (str == NULL) + str = "(null)"; + + /* if we are here, 'str' points to the content that must be + * outputted. handle padding and alignment now */ + + slen = strlen(str); + + if (sign != '\0' || prec != -1) + __assert("sign/precision unsupported", __FILE__, __LINE__); + + if (slen < width && !padLeft) { + char padChar = padZero ? '0' : ' '; + SendRepeat(buff, padChar, width - slen); + } + + Send(buff, str, slen); + + if (slen < width && padLeft) { + char padChar = padZero ? '0' : ' '; + SendRepeat(buff, padChar, width - slen); + } + } +} + +static int open_log_socket(void) { + // ToDo: Ideally we want this to fail if the gid of the current + // process is AID_LOGD, but will have to wait until we have + // registered this in private/android_filesystem_config.h. We have + // found that all logd crashes thus far have had no problem stuffing + // the UNIX domain socket and moving on so not critical *today*. + + int log_fd = TEMP_FAILURE_RETRY(socket(PF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0)); + if (log_fd == -1) + return -1; + + union { + struct sockaddr addr; + struct sockaddr_un addrUn; + } u; + memset(&u, 0, sizeof(u)); + u.addrUn.sun_family = AF_UNIX; + strlcpy(u.addrUn.sun_path, _PATH_LOG, sizeof(u.addrUn.sun_path)); + + if (TEMP_FAILURE_RETRY(connect(log_fd, &u.addr, sizeof(u.addrUn))) != 0) { + close(log_fd); + return -1; + } + + return log_fd; +} + +static int write_stderr(const char* tag, const char* msg) { + struct iovec vec[4]; + vec[0].iov_base = (char*)tag; + vec[0].iov_len = strlen(tag); + vec[1].iov_base = (char*)": "; + vec[1].iov_len = 2; + vec[2].iov_base = (char*)msg; + vec[2].iov_len = strlen(msg); + vec[3].iov_base = (char*)"\n"; + vec[3].iov_len = 1; + + return TEMP_FAILURE_RETRY(writev(STDERR_FILENO, vec, 4)); +} + +int async_safe_write_log(int priority, const char* tag, const char* msg) { + int main_log_fd = open_log_socket(); + if (main_log_fd == -1) + // Try stderr instead. + return write_stderr(tag, msg); + + struct iovec vec[6]; + char log_id = (priority == ANDROID_LOG_FATAL) ? LOG_ID_CRASH : LOG_ID_MAIN; + vec[0].iov_base = &log_id; + vec[0].iov_len = sizeof(log_id); + uint16_t tid = INTERNAL_SYSCALL_CALL(gettid); + vec[1].iov_base = &tid; + vec[1].iov_len = sizeof(tid); + struct timespec ts; + clock_gettime(CLOCK_REALTIME, &ts); + struct log_time realtime_ts; + realtime_ts.tv_sec = ts.tv_sec; + realtime_ts.tv_nsec = ts.tv_nsec; + vec[2].iov_base = &realtime_ts; + vec[2].iov_len = sizeof(realtime_ts); + + vec[3].iov_base = &priority; + vec[3].iov_len = 1; + vec[4].iov_base = (char*)tag; + vec[4].iov_len = strlen(tag) + 1; + vec[5].iov_base = (char*)msg; + vec[5].iov_len = strlen(msg) + 1; + + int result = TEMP_FAILURE_RETRY(writev(main_log_fd, vec, sizeof(vec) / sizeof(vec[0]))); + close(main_log_fd); + return result; +} + +int async_safe_format_log_va_list(int priority, const char* tag, const char* format, va_list args) { + //ErrnoRestorer errno_restorer; + char buffer[1024]; + struct BufferOutputStream os = BufferOutput(buffer, sizeof(buffer)); + out_vformat(&os, format, args); + return async_safe_write_log(priority, tag, buffer); +} + +int async_safe_format_log(int priority, const char* tag, const char* format, ...) { + va_list args; + va_start(args, format); + int result = async_safe_format_log_va_list(priority, tag, format, args); + va_end(args); + return result; +} + +// ====================== +// syslog functions + +void closelog(void) { + syslog_log_tag = NULL; + syslog_options = 0; +} + +void openlog(const char* log_tag, int options, int /*facility*/) { + syslog_log_tag = log_tag; + syslog_options = options; +} + +int setlogmask(int new_mask) { + int old_mask = syslog_priority_mask; + // 0 is used to query the current mask. + if (new_mask != 0) + syslog_priority_mask = new_mask; + return old_mask; +} + +void __vsyslog_internal(int priority, const char* fmt, va_list args, unsigned int mode_flags) { + // Check whether we're supposed to be logging messages of this priority. + if ((syslog_priority_mask & LOG_MASK(LOG_PRI(priority))) == 0) + return; + + // What's our log tag? + const char* log_tag = syslog_log_tag; + if (log_tag == NULL) + log_tag = __progname; + + // What's our Android log priority? + priority &= LOG_PRIMASK; + int android_log_priority; + if (priority <= LOG_CRIT) // LOG_ALERT LOG_EMERG + android_log_priority = ANDROID_LOG_FATAL; + else if (priority == LOG_ERR) + android_log_priority = ANDROID_LOG_ERROR; + else if (priority <= LOG_NOTICE) // LOG_WARNING + android_log_priority = ANDROID_LOG_WARN; + else if (priority == LOG_INFO) + android_log_priority = ANDROID_LOG_INFO; + else // LOG_DEBUG + android_log_priority = ANDROID_LOG_DEBUG; + + // We can't let async_safe_format_log do the formatting because it doesn't + // support all the printf functionality. + char log_line[1024]; + int n = __vsnprintf_internal(log_line, sizeof(log_line), fmt, args, mode_flags); + if (n < 0) return; + + async_safe_format_log(android_log_priority, log_tag, "%s", log_line); + if ((syslog_options & LOG_PERROR) != 0) { + bool have_newline = + (n > 0 && n < (int)sizeof(log_line) && log_line[n - 1] == '\n'); + dprintf(STDERR_FILENO, "%s: %s%s", log_tag, log_line, have_newline ? "" : "\n"); + } +} + +void __syslog(int pri, const char *fmt, ...) { + va_list ap; + va_start(ap, fmt); + __vsyslog_internal(pri, fmt, ap, 0); + va_end(ap); +} +ldbl_hidden_def(__syslog, syslog) +ldbl_strong_alias(__syslog, syslog) + +void __vsyslog(int pri, const char *fmt, va_list ap) { + __vsyslog_internal(pri, fmt, ap, 0); +} +ldbl_weak_alias(__vsyslog, vsyslog) + +void ___syslog_chk(int pri, int flag, const char *fmt, ...) { + va_list ap; + va_start(ap, fmt); + __vsyslog_internal(pri, fmt, ap, (flag > 0) ? PRINTF_FORTIFY : 0); + va_end(ap); +} +ldbl_hidden_def(___syslog_chk, __syslog_chk) +ldbl_strong_alias(___syslog_chk, __syslog_chk) + +void __vsyslog_chk(int pri, int flag, const char *fmt, va_list ap) { + __vsyslog_internal(pri, fmt, ap, (flag > 0) ? PRINTF_FORTIFY : 0); +} diff --git a/gpkg/glibc/sysvipc-Makefile.patch b/gpkg/glibc/sysvipc-Makefile.patch new file mode 100644 index 000000000..9074e5b3c --- /dev/null +++ b/gpkg/glibc/sysvipc-Makefile.patch @@ -0,0 +1,19 @@ +--- glibc-2.39/sysvipc/Makefile 2024-01-31 03:34:58.000000000 +0300 ++++ glibc-2.39/sysvipc/Makefile.patch 2024-12-15 19:21:41.049560753 +0300 +@@ -23,12 +23,14 @@ + include ../Makeconfig + + headers := sys/ipc.h sys/msg.h sys/sem.h sys/shm.h \ +- bits/ipctypes.h bits/ipc.h bits/msq.h bits/sem.h bits/shm.h ++ bits/ipctypes.h bits/ipc.h bits/msq.h bits/sem.h bits/shm.h \ ++ shmem-android.h + + routines := ftok \ + msgsnd msgrcv msgget msgctl \ + semop semget semctl semtimedop \ +- shmat shmdt shmget shmctl ++ shmat shmdt shmget shmctl \ ++ shmem-android + + tests := test-sysvmsg test-sysvsem test-sysvshm + diff --git a/gpkg/glibc/tst-rseq-disable.c.patch b/gpkg/glibc/tst-rseq-disable.c.patch deleted file mode 100644 index 3ca9e5e31..000000000 --- a/gpkg/glibc/tst-rseq-disable.c.patch +++ /dev/null @@ -1,24 +0,0 @@ ---- glibc-2.39/sysdeps/unix/sysv/linux/tst-rseq-disable.c 2022-02-03 05:27:54.000000000 +0000 -+++ glibc-2.39/sysdeps/unix/sysv/linux/tst-rseq-disable.c.patch 2022-06-17 10:38:05.170507213 +0000 -@@ -38,20 +38,7 @@ - TEST_COMPARE (__rseq_size, 0); - TEST_COMPARE ((int) pd->rseq_area.cpu_id, RSEQ_CPU_ID_REGISTRATION_FAILED); - -- int ret = syscall (__NR_rseq, &pd->rseq_area, sizeof (pd->rseq_area), -- 0, RSEQ_SIG); -- if (ret == 0) -- { -- ret = syscall (__NR_rseq, &pd->rseq_area, sizeof (pd->rseq_area), -- RSEQ_FLAG_UNREGISTER, RSEQ_SIG); -- TEST_COMPARE (ret, 0); -- pd->rseq_area.cpu_id = RSEQ_CPU_ID_REGISTRATION_FAILED; -- } -- else -- { -- TEST_VERIFY (errno != -EINVAL); -- TEST_VERIFY (errno != -EBUSY); -- } -+ pd->rseq_area.cpu_id = RSEQ_CPU_ID_REGISTRATION_FAILED; - } - - static void * diff --git a/gpkg/glibc/tst-rseq.h.patch b/gpkg/glibc/tst-rseq.h.patch deleted file mode 100644 index 76791534b..000000000 --- a/gpkg/glibc/tst-rseq.h.patch +++ /dev/null @@ -1,23 +0,0 @@ ---- glibc-2.39/sysdeps/unix/sysv/linux/tst-rseq.h 2022-02-03 05:27:54.000000000 +0000 -+++ glibc-2.39/sysdeps/unix/sysv/linux/tst-rseq.h.patch 2022-06-17 10:35:31.250507272 +0000 -@@ -30,20 +30,9 @@ - return THREAD_GETMEM_VOLATILE (THREAD_SELF, rseq_area.cpu_id) >= 0; - } - --static inline int --sys_rseq (struct rseq *rseq_abi, uint32_t rseq_len, int flags, uint32_t sig) --{ -- return syscall (__NR_rseq, rseq_abi, rseq_len, flags, sig); --} -- - static inline bool - rseq_available (void) - { -- int rc; -- -- rc = sys_rseq (NULL, 0, 0, 0); -- if (rc != -1) -- FAIL_EXIT1 ("Unexpected rseq return value %d", rc); - switch (errno) - { - case ENOSYS: diff --git a/gpkg/glibc/xstat64.c.patch b/gpkg/glibc/xstat64.c.patch deleted file mode 100644 index 76dc61399..000000000 --- a/gpkg/glibc/xstat64.c.patch +++ /dev/null @@ -1,20 +0,0 @@ ---- glibc-2.39/sysdeps/unix/sysv/linux/xstat64.c 2022-07-30 01:03:09.000000000 +0300 -+++ glibc-2.39/sysdeps/unix/sysv/linux/xstat64.c.patch 2022-10-07 22:26:06.884262722 +0300 -@@ -52,17 +52,6 @@ - /* New kABIs which uses generic 64-bit Linux ABI, e.g. aarch64, riscv64. */ - if (vers == _STAT_VER_KERNEL) - return INLINE_SYSCALL_CALL (newfstatat, AT_FDCWD, name, buf, 0); --# else -- /* New 32-bit kABIs with only 64-bit time_t support, e.g. arc, riscv32. */ -- if (vers == _STAT_VER_KERNEL) -- { -- struct statx tmp; -- int r = INLINE_SYSCALL_CALL (statx, AT_FDCWD, name, AT_NO_AUTOMOUNT, -- STATX_BASIC_STATS, &tmp); -- if (r == 0) -- __cp_stat64_statx (buf, &tmp); -- return r; -- } - # endif - #else - # if STAT_IS_KERNEL_STAT diff --git a/gpkg/libuv/build.sh b/gpkg/libuv/build.sh index 3a0a56826..b138ebc0f 100644 --- a/gpkg/libuv/build.sh +++ b/gpkg/libuv/build.sh @@ -4,6 +4,7 @@ TERMUX_PKG_LICENSE="MIT, BSD 2-Clause, ISC, BSD 3-Clause" TERMUX_PKG_LICENSE_FILE="LICENSE" TERMUX_PKG_MAINTAINER="@termux-pacman" TERMUX_PKG_VERSION=1.49.2 +TERMUX_PKG_REVISION=1 TERMUX_PKG_SRCURL=https://dist.libuv.org/dist/v${TERMUX_PKG_VERSION}/libuv-v${TERMUX_PKG_VERSION}.tar.gz TERMUX_PKG_SHA256=8c10706bd2cf129045c42b94799a92df9aaa75d05f07e99cf083507239bae5a8 TERMUX_PKG_DEPENDS="libnsl-glibc" diff --git a/gpkg/libuv/linux.c.patch b/gpkg/libuv/linux.c.patch deleted file mode 100644 index 186c51aff..000000000 --- a/gpkg/libuv/linux.c.patch +++ /dev/null @@ -1,32 +0,0 @@ ---- libuv-v1.46.0/src/unix/linux.c 2023-06-30 21:31:51.000000000 +0300 -+++ libuv-v1.46.0/src/unix/linux.c.patch 2023-09-21 12:25:13.696050386 +0300 -@@ -392,7 +392,7 @@ - - - int uv__io_uring_setup(int entries, struct uv__io_uring_params* params) { -- return syscall(__NR_io_uring_setup, entries, params); -+ return errno = ENOSYS, -1; - } - - -@@ -404,18 +404,12 @@ - * in newer kernels unless IORING_ENTER_EXT_ARG is set, - * in which case it takes a struct io_uring_getevents_arg. - */ -- return syscall(__NR_io_uring_enter, -- fd, -- to_submit, -- min_complete, -- flags, -- NULL, -- 0L); -+ return errno = ENOSYS, -1; - } - - - int uv__io_uring_register(int fd, unsigned opcode, void* arg, unsigned nargs) { -- return syscall(__NR_io_uring_register, fd, opcode, arg, nargs); -+ return errno = ENOSYS, -1; - } - -