这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions build-package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,9 @@ source "$TERMUX_SCRIPTDIR/scripts/build/termux_step_handle_hostbuild.sh"
# shellcheck source=scripts/build/termux_step_host_build.sh
source "$TERMUX_SCRIPTDIR/scripts/build/termux_step_host_build.sh"

# Setup a standalone Android NDK 25c toolchain. Called from termux_step_setup_toolchain.
# shellcheck source=scripts/build/toolchain/termux_setup_toolchain_25c.sh
source "$TERMUX_SCRIPTDIR/scripts/build/toolchain/termux_setup_toolchain_25c.sh"
# Setup a standalone Android NDK toolchain. Called from termux_step_setup_toolchain.
# shellcheck source=scripts/build/toolchain/termux_setup_toolchain_26b.sh
source "$TERMUX_SCRIPTDIR/scripts/build/toolchain/termux_setup_toolchain_26b.sh"

# Setup a standalone Android NDK 23c toolchain. Called from termux_step_setup_toolchain.
# shellcheck source=scripts/build/toolchain/termux_setup_toolchain_23c.sh
Expand Down
1 change: 0 additions & 1 deletion ndk-patches/25c

This file was deleted.

85 changes: 85 additions & 0 deletions ndk-patches/26b/bits-struct_file.h.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
--- ./usr/include/bits/struct_file.h.orig 2019-06-10 09:40:35.872857650 +1000
+++ ./usr/include/bits/struct_file.h 2019-06-10 09:55:10.890308649 +1000
@@ -31,14 +31,79 @@
#include <sys/cdefs.h>

__BEGIN_DECLS
+#if defined(__LP64__)
+struct __sbuf {
+ unsigned char* _base;
+ size_t _size;
+};
+#else
+struct __sbuf {
+ unsigned char *_base;
+ int _size;
+};
+#endif
+#if defined(__LP64__)
+typedef int64_t _struct_file_off_t;
+#else
+typedef __kernel_off_t _struct_file_off_t;
+#endif
+

/** The opaque structure implementing `FILE`. Do not make any assumptions about its content. */
struct __sFILE {
+ unsigned char *_p; /* current position in (some) buffer */
+ int _r; /* read space left for getc() */
+ int _w; /* write space left for putc() */
#if defined(__LP64__)
- char __private[152];
+ int _flags; /* flags, below; this FILE is free if 0 */
+ int _file; /* fileno, if Unix descriptor, else -1 */
#else
- char __private[84];
+ short _flags; /* flags, below; this FILE is free if 0 */
+ short _file; /* fileno, if Unix descriptor, else -1 */
#endif
-} __attribute__((aligned(sizeof(void*))));
+ struct __sbuf _bf; /* the buffer (at least 1 byte, if !NULL) */
+ int _lbfsize; /* 0 or -_bf._size, for inline putc */
+
+ /* operations */
+ void *_cookie; /* cookie passed to io functions */
+ int (*_close)(void *);
+ int (*_read)(void *, char *, int);
+ _struct_file_off_t (*_seek)(void *, _struct_file_off_t, int);
+ int (*_write)(void *, const char *, int);
+
+ /* extension data, to avoid further ABI breakage */
+ struct __sbuf _ext;
+ /* data for long sequences of ungetc() */
+ unsigned char *_up; /* saved _p when _p is doing ungetc data */
+ int _ur; /* saved _r when _r is counting ungetc data */
+
+ /* tricks to meet minimum requirements even when malloc() fails */
+ unsigned char _ubuf[3]; /* guarantee an ungetc() buffer */
+ unsigned char _nbuf[1]; /* guarantee a getc() buffer */
+
+ /* separate buffer for fgetln() when line crosses buffer boundary */
+ struct __sbuf _lb; /* buffer for fgetln() */
+
+ /* Unix stdio files get aligned to block boundaries on fseek() */
+ int _blksize; /* stat.st_blksize (may be != _bf._size) */
+ _struct_file_off_t _offset; /* current lseek offset */
+};
+#define __SLBF 0x0001 /* line buffered */
+#define __SNBF 0x0002 /* unbuffered */
+#define __SRD 0x0004 /* OK to read */
+#define __SWR 0x0008 /* OK to write */
+ /* RD and WR are never simultaneously asserted */
+#define __SRW 0x0010 /* open for reading & writing */
+#define __SEOF 0x0020 /* found EOF */
+#define __SERR 0x0040 /* found error */
+#define __SMBF 0x0080 /* _buf is from malloc */
+#define __SAPP 0x0100 /* fdopen()ed in append mode */
+#define __SSTR 0x0200 /* this is an sprintf/snprintf string */
+#define __SOPT 0x0400 /* do fseek() optimization */
+#define __SNPT 0x0800 /* do not do fseek() optimization */
+#define __SOFF 0x1000 /* set iff _offset is in fact correct */
+#define __SMOD 0x2000 /* true => fgetln modified _p text */
+#define __SALC 0x4000 /* allocate string space dynamically */
+#define __SIGN 0x8000 /* ignore this file in _fwalk */

__END_DECLS
12 changes: 12 additions & 0 deletions ndk-patches/26b/dirent.h.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--- ./usr/include/dirent.h.orig
+++ ./usr/include/dirent.h
@@ -57,6 +57,9 @@
#define DT_SOCK 12
#define DT_WHT 14

+#define IFTODT(x) ((x)>>12 & 0xF)
+#define DTTOIF(x) ((x)<<12)
+
#if defined(__LP64__)
#define __DIRENT64_INO_T ino_t
#else
28 changes: 28 additions & 0 deletions ndk-patches/26b/grp.h.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
--- ./usr/include/grp.h.orig
+++ ./usr/include/grp.h
@@ -50,21 +50,15 @@
struct group* _Nullable getgrgid(gid_t __gid);
struct group* _Nullable getgrnam(const char* _Nonnull __name);

-/* Note: Android has thousands and thousands of ids to iterate through. */
-
-#if __ANDROID_API__ >= 26
-struct group* _Nullable getgrent(void) __INTRODUCED_IN(26);
-
-void setgrent(void) __INTRODUCED_IN(26);
-void endgrent(void) __INTRODUCED_IN(26);
-#endif /* __ANDROID_API__ >= 26 */
-
-
#if __ANDROID_API__ >= 24
int getgrgid_r(gid_t __gid, struct group* __BIONIC_COMPLICATED_NULLNESS __group, char* _Nonnull __buf, size_t __n, struct group* _Nullable * _Nonnull __result) __INTRODUCED_IN(24);
int getgrnam_r(const char* _Nonnull __name, struct group* __BIONIC_COMPLICATED_NULLNESS __group, char* _Nonnull __buf, size_t __n, struct group* _Nullable *_Nonnull __result) __INTRODUCED_IN(24);
#endif /* __ANDROID_API__ >= 24 */

+static struct group* _Nullable getgrent(void) { return 0; }
+static void setgrent(void) {}
+static void endgrent(void) {}
+
int getgrouplist(const char* _Nonnull __user, gid_t __group, gid_t* __BIONIC_COMPLICATED_NULLNESS __groups, int* _Nonnull __group_count);
int initgroups(const char* _Nonnull __user, gid_t __group);

11 changes: 11 additions & 0 deletions ndk-patches/26b/linux-fcntl.h.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- ./usr/include/linux/fcntl.h
+++ ./usr/include/linux/fcntl.h
@@ -54,7 +54,7 @@
#define DN_MULTISHOT 0x80000000
#define AT_FDCWD - 100
#define AT_SYMLINK_NOFOLLOW 0x100
-#define AT_EACCESS 0x200
+#define AT_EACCESS 0
#define AT_REMOVEDIR 0x200
#define AT_SYMLINK_FOLLOW 0x400
#define AT_NO_AUTOMOUNT 0x800
29 changes: 29 additions & 0 deletions ndk-patches/26b/paths.h.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--- ./usr/include/paths.h.orig 2021-08-16 11:55:04.492150066 +0200
+++ ./usr/include/paths.h 2021-08-16 11:55:42.498804733 +0200
@@ -40,14 +40,14 @@

#ifndef _PATH_BSHELL
/** Path to the default system shell. Historically the 'B' was to specify the Bourne shell. */
-#define _PATH_BSHELL "/system/bin/sh"
+#define _PATH_BSHELL "@TERMUX_PREFIX@/bin/sh"
#endif

/** Path to the system console. */
#define _PATH_CONSOLE "/dev/console"

/** Default shell search path. */
-#define _PATH_DEFPATH "/product/bin:/apex/com.android.runtime/bin:/apex/com.android.art/bin:/system_ext/bin:/system/bin:/system/xbin:/odm/bin:/vendor/bin:/vendor/xbin"
+#define _PATH_DEFPATH "@TERMUX_PREFIX@/bin"

/** Path to the directory containing device files. */
#define _PATH_DEV "/dev/"
@@ -63,3 +63,9 @@

/** Path to the calling process' tty. */
#define _PATH_TTY "/dev/tty"
+
+#define _PATH_STDPATH _PATH_DEFPATH
+#define _PATH_TMP "@TERMUX_PREFIX@/tmp/"
+#define _PATH_VARDB "@TERMUX_PREFIX@/var/db/"
+#define _PATH_VARRUN "@TERMUX_PREFIX@/var/run/"
+#define _PATH_VARTMP "@TERMUX_PREFIX@/var/tmp/"
64 changes: 64 additions & 0 deletions ndk-patches/26b/pwd.h.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
--- ./usr/include/pwd.h.orig
+++ ./usr/include/pwd.h
@@ -89,13 +89,60 @@
struct passwd* _Nullable getpwent(void) __INTRODUCED_IN(26);

void setpwent(void) __INTRODUCED_IN(26);
-void endpwent(void) __INTRODUCED_IN(26);
#endif /* __ANDROID_API__ >= 26 */


int getpwnam_r(const char* _Nonnull __name, struct passwd* _Nonnull __pwd, char* _Nonnull __buf, size_t __n, struct passwd* _Nullable * _Nonnull __result);
int getpwuid_r(uid_t __uid, struct passwd* _Nonnull __pwd, char* _Nonnull __buf, size_t __n, struct passwd* _Nullable * _Nonnull __result);

+int access(const char* __path, int __mode);
+
+static void android_setup_pwd(struct passwd* pw) {
+ char const* result = "@TERMUX_PREFIX@/bin/login";
+ if (result == NULL || access(result, /*X_OK*/1) == -1) {
+ pw->pw_shell = "@TERMUX_PREFIX@/bin/bash";
+ } else {
+ pw->pw_shell = (char*) result;
+ }
+ pw->pw_dir = "@TERMUX_HOME@";
+ pw->pw_passwd = "*";
+#ifdef __LP64__
+ pw->pw_gecos = ""; /* Avoid NULL field. */
+#endif
+}
+
+static struct passwd* android_polyfill_getpwuid(uid_t t) {
+ struct passwd* pw = getpwuid(t);
+ if (pw == NULL) return NULL;
+ android_setup_pwd(pw);
+ return pw;
+}
+
+static struct passwd* android_polyfill_getpwnam(const char* name) {
+ struct passwd* pw = getpwnam(name);
+ if (pw == NULL) return NULL;
+ android_setup_pwd(pw);
+ return pw;
+}
+
+static int android_polyfill_getpwuid_r(uid_t uid,
+ struct passwd *pwd,
+ char *buffer,
+ size_t bufsize,
+ struct passwd **result) {
+ int ret = getpwuid_r(uid, pwd, buffer, bufsize, result);
+ if (ret != 0) return ret;
+ android_setup_pwd(pwd);
+ return 0;
+}
+
+#define getpwnam android_polyfill_getpwnam
+#define getpwuid android_polyfill_getpwuid
+#define getpwuid_r android_polyfill_getpwuid_r
+static void endpwent(void) { /* Do nothing. */ }
+
+
+
__END_DECLS

#endif
21 changes: 21 additions & 0 deletions ndk-patches/26b/redefine-TCSAFLUSH.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
diff -u -r /home/builder/lib/android-ndk/sysroot/usr/include/asm-generic/termbits.h ./usr/include/asm-generic/termbits.h
--- /home/builder/lib/android-ndk/sysroot/usr/include/asm-generic/termbits.h 2018-09-10 17:37:50.000000000 +0000
+++ ./usr/include/asm-generic/termbits.h 2019-01-16 04:54:01.117253378 +0000
@@ -190,5 +190,6 @@
#define TCIOFLUSH 2
#define TCSANOW 0
#define TCSADRAIN 1
-#define TCSAFLUSH 2
+/* TCSAFLUSH is patched to be TCSANOW in Termux to work around Android SELinux rule */
+#define TCSAFLUSH 0
#endif
--- ./usr/include/bits/termios_inlines.h.orig 2021-08-16 17:05:16.001067630 +0200
+++ ./usr/include/bits/termios_inlines.h 2021-08-16 17:05:05.851074187 +0200
@@ -117,7 +117,6 @@
switch (optional_actions) {
case TCSANOW: cmd = TCSETS; break;
case TCSADRAIN: cmd = TCSETSW; break;
- case TCSAFLUSH: cmd = TCSETSF; break;
default: errno = EINVAL; return -1;
}
return ioctl(fd, cmd, s);
18 changes: 18 additions & 0 deletions ndk-patches/26b/semaphore.h.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--- ./usr/include/semaphore.h.orig
+++ ./usr/include/semaphore.h
@@ -71,9 +71,14 @@
int sem_trywait(sem_t* _Nonnull __sem);
int sem_wait(sem_t* _Nonnull __sem);

-/* These aren't actually implemented. */
+#undef sem_open
+#define sem_open libandroid_sem_open
sem_t* _Nullable sem_open(const char* _Nonnull __name, int _flags, ...);
+#undef sem_close
+#define sem_close libandroid_sem_close
int sem_close(sem_t* _Nonnull __sem);
+#undef sem_unlink
+#define sem_unlink libandroid_sem_unlink
int sem_unlink(const char* _Nonnull __name);

__END_DECLS
80 changes: 80 additions & 0 deletions ndk-patches/26b/stdio.h.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
--- ./usr/include/stdio.h.orig 2021-08-16 11:48:44.308954400 +0200
+++ ./usr/include/stdio.h 2021-08-16 11:50:00.438924014 +0200
@@ -44,6 +44,9 @@
#include <stdarg.h>
#include <stddef.h>

+#include <string.h> /* For strcpy(3) used by ctermid() */
+#include <asm/fcntl.h> /* For O_RDWR and other O_* constants */
+
#include <bits/seek_constants.h>

#if __ANDROID_API__ < 24
@@ -165,7 +166,7 @@
__printflike(2, 0) __warnattr_strict("vsprintf is often misused; please use vsnprintf");
char* _Nullable tmpnam(char* _Nullable __s)
__warnattr("tmpnam is unsafe, use mkstemp or tmpfile instead");
-#define P_tmpdir "/tmp/" /* deprecated */
+#define P_tmpdir "@TERMUX_PREFIX@/tmp/" /* deprecated */
char* _Nullable tempnam(const char* _Nullable __dir, const char* _Nullable __prefix)
__warnattr("tempnam is unsafe, use mkstemp or tmpfile instead");

@@ -289,8 +290,6 @@
FILE* _Nullable freopen64(const char* _Nullable __path, const char* _Nonnull __mode, FILE* _Nonnull __fp) __INTRODUCED_IN(24);
#endif /* __ANDROID_API__ >= 24 */

-FILE* _Nullable tmpfile(void);
-
#if __ANDROID_API__ >= 24
FILE* _Nullable tmpfile64(void) __INTRODUCED_IN(24);
#endif /* __ANDROID_API__ >= 24 */
@@ -304,10 +303,15 @@

#define L_ctermid 1024 /* size for ctermid() */

-#if __ANDROID_API__ >= 26
-char* _Nonnull ctermid(char* _Nullable __buf) __INTRODUCED_IN(26);
-#endif /* __ANDROID_API__ >= 26 */
+/* Needed by gnulibs freading(). */
+#define __sferror(p) (((p)->_flags & __SERR) != 0)

+/* Used by perl, fish, and others. */
+static __inline__ char* _Nonnull ctermid(char* _Nullable s) {
+ if (s == 0) return (char*) "/dev/tty";
+ strcpy(s, "/dev/tty");
+ return s;
+}

FILE* fdopen(int __fd, const char* __mode);
int fileno(FILE* __fp);
@@ -376,6 +380,30 @@
#include <bits/fortify/stdio.h>
#endif

+int open(const char*, int, ...);
+extern pid_t getpid();
+extern int unlink(const char*);
+void free(void* p);
+uint32_t arc4random(void);
+static __inline__ FILE* _Nullable tmpfile() {
+ int p = getpid();
+ char* path;
+ int i;
+ for (i = 0; i < 100; i++) {
+ unsigned int r = arc4random();
+ if (asprintf(&path, "@TERMUX_PREFIX@/tmp/tmpfile.%d-%u", p, r) == -1) return NULL;
+ int fd = open(path, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE, 0600);
+ if (fd >= 0) {
+ FILE* result = fdopen(fd, "w+");
+ unlink(path);
+ free(path);
+ return result;
+ }
+ free(path);
+ }
+ return NULL;
+}
+
__END_DECLS

#endif
24 changes: 24 additions & 0 deletions ndk-patches/26b/stdlib.h.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--- ./usr/include/stdlib.h.orig 2021-08-16 11:50:47.432239182 +0200
+++ ./usr/include/stdlib.h 2021-08-16 11:51:31.102222894 +0200
@@ -33,6 +33,7 @@
#include <bits/wait.h>
#include <malloc.h>
#include <stddef.h>
+#include <stdint.h>
#include <sys/cdefs.h>
#include <xlocale.h>

@@ -223,12 +224,8 @@

size_t wcstombs(char* _Nullable __dst, const wchar_t* _Nullable __src, size_t __n) __INTRODUCED_IN_NO_GUARD_FOR_NDK(21);


-#if __ANDROID_API__ >= 21
-size_t __ctype_get_mb_cur_max(void) __INTRODUCED_IN(21);
-#endif /* __ANDROID_API__ >= 21 */
-
-#define MB_CUR_MAX __ctype_get_mb_cur_max()
+#define MB_CUR_MAX 4

#if defined(__BIONIC_INCLUDE_FORTIFY_HEADERS)
#include <bits/fortify/stdlib.h>
Loading