From 140d02cd5516f5c430dc484a262b26bb90ca44a9 Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Tue, 23 Jan 2024 16:03:33 -0500 Subject: [PATCH] wip: got result value being passed correctly --- rust/ares/src/interpreter.rs | 19 +++++++++---------- rust/ares_guard/c-src/guard.c | 8 ++++---- rust/ares_guard/c-src/guard.h | 2 +- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/rust/ares/src/interpreter.rs b/rust/ares/src/interpreter.rs index c605de0..c21dbce 100644 --- a/rust/ares/src/interpreter.rs +++ b/rust/ares/src/interpreter.rs @@ -421,9 +421,9 @@ impl<'closure> CCallback<'closure> { { let cb: &mut F = user_data.cast::().as_mut().unwrap(); let mut v = (*cb)(); - eprint!("ares: v: {:?}\r\n", v); + eprint!("call_closure: v: {:?}\r\n", v); let v_ptr = &mut v as *mut _ as *mut c_void; - eprint!("ares: v_ptr: {:p}\r\n", v_ptr); + eprint!("call_closure: v_ptr: {:p}\r\n", v_ptr); v_ptr } } @@ -447,10 +447,9 @@ pub fn call_with_guard Result>( ) -> Result { let c = CCallback::new(f); let mut result: Result = Ok(D(0)); - let result_ptr = &mut result as *mut _ as *mut c_void; - let result_ptr_ptr = result_ptr as *mut *mut c_void; - - eprint!("ares: result_ptr_ptr: {:p}\r\n", result_ptr_ptr); + let res_ptr = &mut result as *mut _ as *mut c_void; + let res_ptr_ptr = &res_ptr as *const *mut c_void; + eprint!("call_with_guard: before res_ptr: {:p}\r\n", res_ptr); unsafe { let err = guard( @@ -458,15 +457,16 @@ pub fn call_with_guard Result>( c.user_data as *mut c_void, stack, alloc, - result_ptr_ptr, + res_ptr_ptr, ); - eprint!("ares: result_ptr: {:p}\r\n", result_ptr); + eprint!("call_with_guard: after res_ptr: {:p}\r\n", res_ptr); if let Ok(err) = GuardError::try_from(err) { match err { GuardError::GuardSound => { - eprint!("ares: result: {:?}\n", result); + let result = *(res_ptr as *mut Result); + eprint!("call_with_guard: result: {:?}\r\n", result); return result; } GuardError::GuardArmor => { @@ -1076,7 +1076,6 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res }) }); - eprint!("nock: {:?}", nock); match nock { Ok(res) => Ok(res), Err(err) => Err(exit(context, &snapshot, virtual_frame, err)), diff --git a/rust/ares_guard/c-src/guard.c b/rust/ares_guard/c-src/guard.c index faa09f3..1a9cd2f 100644 --- a/rust/ares_guard/c-src/guard.c +++ b/rust/ares_guard/c-src/guard.c @@ -112,7 +112,7 @@ guard_err guard( void *user_data, void *const *stack_pp, void *const *alloc_pp, - void **ret + void *const *ret ) { stack = (uint64_t**) stack_pp; @@ -124,7 +124,6 @@ guard_err guard( fprintf(stderr, "guard: stack pointer at %p\r\n", (void *) *stack); fprintf(stderr, "guard: alloc pointer at %p\r\n", (void *) *alloc); fprintf(stderr, "guard: ret pointer at %p\r\n", (void *) ret); - fprintf(stderr, "guard: res pointer at %p\r\n", (void *) *ret); if (guard_p == 0) { fprintf(stderr, "guard: installing guard page\r\n"); @@ -154,8 +153,9 @@ guard_err guard( } } - fprintf(stderr, "guard: assigning ret to %p\r\n", result); - *ret = result; + fprintf(stderr, "guard: assigning *ret to %p\r\n", result); + *(void **)ret = result; + fprintf(stderr, "guard: assigned *ret to %p\r\n", *ret); if (mprotect(guard_p, GD_PAGESIZE, PROT_READ | PROT_WRITE) == -1) { err = guard_armor; diff --git a/rust/ares_guard/c-src/guard.h b/rust/ares_guard/c-src/guard.h index 10a40ab..e68e5d1 100644 --- a/rust/ares_guard/c-src/guard.h +++ b/rust/ares_guard/c-src/guard.h @@ -45,7 +45,7 @@ guard_err guard( void *user_data, void *const *stack_pp, void *const *alloc_pp, - void **ret + void *const *ret );