Skip to content

Commit

Permalink
experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxython committed Dec 19, 2023
1 parent b4a2ab4 commit c72d60b
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gpkg/glibc/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
56 changes: 56 additions & 0 deletions gpkg/glibc/malloc.c.patch
Original file line number Diff line number Diff line change
@@ -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 <malloc.h>

#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)
2 changes: 1 addition & 1 deletion gpkg/glibc/mprotect.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c72d60b

Please sign in to comment.