summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2016-10-09 23:46:56 -0400
committerJune McEnroe <june@causal.agency>2016-10-09 23:46:56 -0400
commit41521353345ef0681ae074d44d892fff61f74370 (patch)
treee9e9ad3321aa5b423adc7f4286ac3dc808b4640d
parentFix jrp snprintf len (diff)
downloadsrc-41521353345ef0681ae074d44d892fff61f74370.tar.gz
src-41521353345ef0681ae074d44d892fff61f74370.zip
Allocate two pages of stack for jrp
-rwxr-xr-x.bin/jrp.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/.bin/jrp.c b/.bin/jrp.c
index cde2fcce..de137cf7 100755
--- a/.bin/jrp.c
+++ b/.bin/jrp.c
@@ -133,10 +133,10 @@ static void jitInit(void) {
 }
 
 static void stackInit(void) {
-    stack.base = mmap(0, getpagesize(), PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
+    stack.base = mmap(0, 2 * getpagesize(), PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
     if (stack.base == MAP_FAILED) err(EX_OSERR, "mmap");
     stack.limit = stack.base + getpagesize() / sizeof(qvalue);
-    stack.ptr = stack.limit - 1;
+    stack.ptr = stack.limit;
 }
 
 static void jitExec(void) {
@@ -144,6 +144,7 @@ static void jitExec(void) {
     error = mprotect(code.base, getpagesize(), PROT_READ | PROT_EXEC);
     if (error) err(EX_OSERR, "mprotect");
     stack.ptr = ((jitFn)code.base)(stack.ptr);
+    if (stack.ptr > stack.limit) stack.ptr = stack.limit;
     error = mprotect(code.base, getpagesize(), PROT_READ | PROT_WRITE);
     if (error) err(EX_OSERR, "mprotect");
 }
@@ -215,6 +216,7 @@ static char *prompt(EditLine *el __attribute((unused))) {
         }
     }
     buf[0] = '[';
+    if (bufPtr == buf) bufPtr++;
     *bufPtr++ = ']';
     *bufPtr++ = ' ';
     *bufPtr = 0;