From c72d60b97ed26f2bee9a1b5b57e8631bd18f6b06 Mon Sep 17 00:00:00 2001 From: Maxython Date: Tue, 19 Dec 2023 13:27:40 +0300 Subject: [PATCH] experiment --- gpkg/glibc/build.sh | 2 +- gpkg/glibc/malloc.c.patch | 56 +++++++++++++++++++++++++++++++++++++++ gpkg/glibc/mprotect.c | 2 +- 3 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 gpkg/glibc/malloc.c.patch diff --git a/gpkg/glibc/build.sh b/gpkg/glibc/build.sh index 1fe942ab0..522a73260 100644 --- a/gpkg/glibc/build.sh +++ b/gpkg/glibc/build.sh @@ -16,7 +16,7 @@ termux_step_pre_configure() { termux_error_exit "Compilation is only possible based on glibc" fi - for i in shmem-android.h mprotect.c; do + for i in shmem-android.h; do install -Dm644 "${TERMUX_PKG_BUILDER_DIR}/${i}" "${TERMUX_PKG_SRCDIR}/sysdeps/unix/sysv/linux/${i}" done diff --git a/gpkg/glibc/malloc.c.patch b/gpkg/glibc/malloc.c.patch new file mode 100644 index 000000000..a2f5b2e60 --- /dev/null +++ b/gpkg/glibc/malloc.c.patch @@ -0,0 +1,56 @@ +--- src/malloc/malloc.c 2023-07-31 20:54:16.000000000 +0300 ++++ src/malloc/malloc.c.patch 2023-12-19 13:23:12.195766831 +0300 +@@ -1075,7 +1075,7 @@ + #include + + #ifndef RETURN_ADDRESS +-#define RETURN_ADDRESS(X_) (NULL) ++#define RETURN_ADDRESS(X_) mmap(NULL, X_, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) + #endif + + /* Forward declarations. */ +@@ -3532,7 +3532,7 @@ + if (!__malloc_initialized) + ptmalloc_init (); + +- void *address = RETURN_ADDRESS (0); ++ void *address = RETURN_ADDRESS (bytes); + return _mid_memalign (alignment, bytes, address); + } + libc_hidden_def (__libc_memalign) +@@ -3555,7 +3555,7 @@ + return 0; + } + +- void *address = RETURN_ADDRESS (0); ++ void *address = RETURN_ADDRESS (bytes); + return _mid_memalign (alignment, bytes, address); + } + +@@ -3655,7 +3655,7 @@ + if (!__malloc_initialized) + ptmalloc_init (); + +- void *address = RETURN_ADDRESS (0); ++ void *address = RETURN_ADDRESS (bytes); + size_t pagesize = GLRO (dl_pagesize); + return _mid_memalign (pagesize, bytes, address); + } +@@ -3666,7 +3666,7 @@ + if (!__malloc_initialized) + ptmalloc_init (); + +- void *address = RETURN_ADDRESS (0); ++ void *address = RETURN_ADDRESS (bytes); + size_t pagesize = GLRO (dl_pagesize); + size_t rounded_bytes; + /* ALIGN_UP with overflow check. */ +@@ -5901,7 +5901,7 @@ + return EINVAL; + + +- void *address = RETURN_ADDRESS (0); ++ void *address = RETURN_ADDRESS (size); + mem = _mid_memalign (alignment, size, address); + + if (mem != NULL) diff --git a/gpkg/glibc/mprotect.c b/gpkg/glibc/mprotect.c index 8d9f0ed02..6556a99a9 100644 --- a/gpkg/glibc/mprotect.c +++ b/gpkg/glibc/mprotect.c @@ -96,7 +96,7 @@ int __mprotect(void *addr, size_t len, int prot) { memcpy(caddr, addr, saddr); free(addr); } - addr = mmap(NULL, len*5, PROT_READ|PROT_WRITE, mmap_flags, -1, 0); + addr = mmap(NULL, len, PROT_READ|PROT_WRITE, mmap_flags, -1, 0); if (saddr > 1) { memcpy(addr, caddr, saddr); free(caddr);