Skip to content

Commit

Permalink
experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxython committed Dec 24, 2023
1 parent 4c719a4 commit 197dcd2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 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 ignore-syscall.h mprotect.c; do
for i in shmem-android.h ignore-syscall.h; do
install -Dm644 "${TERMUX_PKG_BUILDER_DIR}/${i}" "${TERMUX_PKG_SRCDIR}/sysdeps/unix/sysv/linux/${i}"
done

Expand Down
13 changes: 13 additions & 0 deletions gpkg/glibc/dl-load.c.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--- src/elf/dl-load.c 2023-07-31 20:54:16.000000000 +0300
+++ src/elf/dl-load.c.patch 2023-12-24 17:48:46.238884735 +0300
@@ -90,9 +90,7 @@


int __stack_prot attribute_hidden attribute_relro
-#if _STACK_GROWS_DOWN && defined PROT_GROWSDOWN
- = PROT_GROWSDOWN;
-#elif _STACK_GROWS_UP && defined PROT_GROWSUP
+#if _STACK_GROWS_UP && defined PROT_GROWSUP
= PROT_GROWSUP;
#else
= 0;
5 changes: 1 addition & 4 deletions gpkg/glibc/mprotect.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,12 @@ int __mprotect(void *addr, size_t len, int prot) {
if (res == -1 && errno == EACCES && prot & PROT_EXEC && !__is_mmaped(addr)) {
size_t saddr = strlen(addr)+1;
void *caddr;
int mmap_flags = MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED;
if (prot & PROT_GROWSDOWN)
mmap_flags |= MAP_GROWSDOWN;
if (saddr > 1) {
caddr = malloc(saddr);
memcpy(caddr, addr, saddr);
}
free(addr);
addr = mmap(addr, len, PROT_READ|PROT_WRITE|PROT_EXEC, mmap_flags, -1, 0);
addr = mmap(addr, len, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED, -1, 0);
if (saddr > 1)
memcpy(addr, caddr, saddr);
return INLINE_SYSCALL_CALL(mprotect, addr, len, prot);
Expand Down
11 changes: 11 additions & 0 deletions gpkg/glibc/rtld.c.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- src/elf/rtld.c 2023-12-13 09:28:35.942403098 +0300
+++ src/elf/rtld.c.patch 2023-12-24 17:46:54.788884778 +0300
@@ -486,7 +486,7 @@
#endif

/* Initialize the stack end variable. */
- __libc_stack_end = __builtin_frame_address (0);
+ __libc_stack_end = mmap(NULL, GLRO(dl_pagesize), PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);

/* Call the OS-dependent function to set up life so we can do things like
file access. It will call `dl_main' (below) to do all the real work

0 comments on commit 197dcd2

Please sign in to comment.