ref: a374e069c66850906eaa241b8fcc0e312ff298bd
parent: 76214d37db206e5244c337da917316da53afd2a8
author: halfwit <michaelmisch1985@gmail.com>
date: Sat Oct 5 07:16:40 PDT 2024
Just nothing changes
--- a/kern/posix.c
+++ b/kern/posix.c
@@ -149,9 +149,8 @@
argc = nelem((char**)p->arg);
if(pthread_setspecific(prdakey, p))
panic("cannot setspecific");
- print("Greetings from TREX %lx\n", up->bin->entry+TRAMPSIZE);
/* Our entrypoint moves forward to accomodate the trampoline code */
- start(up->bin->entry+TRAMPSIZE, &tos, argc, p->arg);
+ start(up->bin->entry+(TRAMPSIZE*BY2SE), &tos, argc, p->arg);
pexit("", 0);
return 0;
}
@@ -188,7 +187,7 @@
int n;
void *text;
- text = mallocz(up->bin->ts, 1);
+ text = mmap(nil, up->bin->ts, PROT_WRITE|PROT_READ, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
n = devtab[tc->type]->read(tc, text, up->bin->ts, 0);
if(!text || n == 0)
error("unable to set up text segment");
@@ -200,12 +199,17 @@
ospatchtext(void)
{
void *text, *final;
+ int flag;
/* Set up trampoline. Mach dependent */
text = mallocz(TRAMPSIZE, 1);
trampoline(text);
- final = mmap(nil, up->bin->ts+TRAMPSIZE, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
+ flag = MAP_PRIVATE|MAP_ANONYMOUS;
+#ifdef __APPLE__
+ flag |= MAP_JIT;
+#endif
+ final = mmap(nil, up->bin->ts+TRAMPSIZE, PROT_WRITE|PROT_READ, flag, -1, 0);
memmove(final, text, TRAMPSIZE);
memmove(final+TRAMPSIZE, (void*)up->bin->text, up->bin->ts);
if(!final)
@@ -212,11 +216,11 @@
error("unable to set up text segment with trampoline");
/* Patch. Mach dependent */
- if(patch(final+TRAMPSIZE, up->bin->ts) < 0)
+ if(patch(final-TRAMPSIZE, up->bin->ts) < 0)
error("unable to patch syscalls");
- up->bin->text = (uintptr)final;
- if(mprotect((void*)up->bin->text, up->bin->ts+TRAMPSIZE, PROT_READ|PROT_EXEC) != 0)
+ if(mprotect((void*)up->bin->text, up->bin->ts+TRAMPSIZE, PROT_EXEC) != 0)
error("Unable to mprotect: %r");
+ up->bin->text = (uintptr)final;
}
void
--- a/posix-arm64/Makefile
+++ b/posix-arm64/Makefile
@@ -2,7 +2,7 @@
include ../Make.config
LIB=../libmachdep.a
# Cannot use PIE because of trampoline
-#CFLAGS+=-fpie
+CFLAGS+=-arch arm64
#LDFLAGS+=-fpie
OFILES=\
--- a/posix-arm64/mem.h
+++ b/posix-arm64/mem.h
@@ -85,7 +85,7 @@
#define _NSYS 53
#define BLOCKALIGN 64 /* only used in allocb.c */
-#define TRAMPSIZE 232 /* Size of the trampoline */
+#define TRAMPSIZE 232 /* Size of the trampoline, padded */
/*
* Sizes
*/