mirror of
https://github.com/urbit/ares.git
synced 2024-11-25 22:29:57 +03:00
wip: debugging ~2024.1.30
This commit is contained in:
parent
fa316f664b
commit
680d2d254c
@ -17,8 +17,7 @@ use crate::trace::{write_nock_trace, TraceInfo, TraceStack};
|
||||
use crate::unifying_equality::unifying_equality;
|
||||
use ares_guard::*;
|
||||
use ares_macros::tas;
|
||||
use assert_no_alloc::permit_alloc;
|
||||
use assert_no_alloc::{assert_no_alloc, ensure_alloc_counters};
|
||||
use assert_no_alloc::{assert_no_alloc, ensure_alloc_counters, permit_alloc};
|
||||
use bitvec::prelude::{BitSlice, Lsb0};
|
||||
use either::*;
|
||||
use std::convert::TryFrom;
|
||||
@ -433,11 +432,8 @@ impl<'closure> CCallback<'closure> {
|
||||
let cb: &mut F = user_data.cast::<F>().as_mut().unwrap();
|
||||
let v = (*cb)();
|
||||
permit_alloc(|| {
|
||||
// eprint!("call_closure: v: {:?}\r\n", v);
|
||||
let v_box = Box::new(v);
|
||||
let v_ptr = Box::into_raw(v_box);
|
||||
// let v_ptr = &mut v as *mut _ as *mut c_void;
|
||||
// eprint!("call_closure: v_ptr: {:p}\r\n", v_ptr);
|
||||
v_ptr as *mut c_void
|
||||
})
|
||||
}
|
||||
@ -465,10 +461,11 @@ pub fn call_with_guard<F: FnMut() -> Result>(
|
||||
if let Ok(err) = GuardError::try_from(err) {
|
||||
match err {
|
||||
GuardError::GuardSound => {
|
||||
let result = *(ret_p as *mut Result);
|
||||
// eprint!("call_with_guard: ret_p: {:p}\r\n", ret_p);
|
||||
// eprint!("call_with_guard: result: {:?}\r\n", result);
|
||||
return result;
|
||||
permit_alloc(|| {
|
||||
let result_box = Box::from_raw(ret_p as *mut Result);
|
||||
let result = *result_box;
|
||||
return result;
|
||||
})
|
||||
}
|
||||
GuardError::GuardArmor => {
|
||||
return Err(Error::Deterministic(Mote::Exit, D(0)));
|
||||
|
@ -424,9 +424,6 @@ fn goof(context: &mut Context, mote: Mote, traces: Noun) -> Noun {
|
||||
let tang = mook(&mut context.nock_context, tone, false)
|
||||
.expect("serf: goof: +mook crashed on bail")
|
||||
.tail();
|
||||
// XX: noun::Error should use a bail enum system similar to u3m_bail motes;
|
||||
// might be able to replace NockErr with mote and map determinism to individual motes;
|
||||
// for, always set to %exit
|
||||
T(&mut context.nock_context.stack, &[D(mote as u64), tang])
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ guard_err _focus_guard()
|
||||
|
||||
// Check for strange situations.
|
||||
if (stack_p == 0 || alloc_p == 0) {
|
||||
// fprintf(stderr, "guard: stack or alloc pointer is null\r\n");
|
||||
fprintf(stderr, "guard: stack or alloc pointer is null\r\n");
|
||||
return guard_weird;
|
||||
}
|
||||
|
||||
@ -46,7 +46,7 @@ guard_err _focus_guard()
|
||||
guard_p = stack_p + ((alloc_p - stack_p) / 2);
|
||||
}
|
||||
else {
|
||||
// fprintf(stderr, "guard: weird; stack and alloc pointers are equal\r\n");
|
||||
fprintf(stderr, "guard: weird; stack and alloc pointers are equal\r\n");
|
||||
return guard_weird;
|
||||
}
|
||||
guard_p = (void *)((uintptr_t)guard_p & ~(GD_PAGESIZE - 1));
|
||||
@ -60,16 +60,17 @@ guard_err _focus_guard()
|
||||
return guard_spent;
|
||||
}
|
||||
|
||||
// fprintf(stderr, "guard: installed guard page at %p\r\n", (void *) guard_p);
|
||||
fprintf(stderr, "guard: installed guard page at %p\r\n", (void *) guard_p);
|
||||
|
||||
return guard_sound;
|
||||
}
|
||||
|
||||
guard_err _slash_guard(void *si_addr) {
|
||||
if (si_addr >= (void *)guard_p && si_addr < (void *)guard_p + GD_PAGESIZE) {
|
||||
// fprintf(stderr, "guard: slash in guard\r\n");
|
||||
fprintf(stderr, "guard: slash in guard\r\n");
|
||||
return _focus_guard();
|
||||
}
|
||||
fprintf(stderr, "guard: slash outside guard\r\n");
|
||||
|
||||
return guard_weird;
|
||||
}
|
||||
@ -78,11 +79,11 @@ void _signal_handler(int sig, siginfo_t *si, void *unused)
|
||||
{
|
||||
switch (sig) {
|
||||
case SIGSEGV:
|
||||
// fprintf(stderr, "guard: sigsegv at %p\r\n", si->si_addr);
|
||||
fprintf(stderr, "guard: sigsegv at %p\r\n", si->si_addr);
|
||||
err = _slash_guard(si->si_addr);
|
||||
break;
|
||||
case SIGINT:
|
||||
// fprintf(stderr, "guard: sigint\r\n");
|
||||
fprintf(stderr, "guard: sigint\r\n");
|
||||
err = guard_erupt;
|
||||
break;
|
||||
default:
|
||||
@ -90,7 +91,7 @@ void _signal_handler(int sig, siginfo_t *si, void *unused)
|
||||
}
|
||||
|
||||
if (err != guard_sound) {
|
||||
// fprintf(stderr, "guard: error %d; long jumping\r\n", err);
|
||||
fprintf(stderr, "guard: error %d; long jumping\r\n", err);
|
||||
longjmp(env_buffer, 1);
|
||||
}
|
||||
}
|
||||
@ -104,6 +105,7 @@ guard_err _register_handler() {
|
||||
|
||||
// if (sigaction(SIGSEGV, &sa, 0) || sigaction(SIGINT, &sa, 0)) {
|
||||
if (sigaction(SIGSEGV, &sa, 0)) {
|
||||
fprintf(stderr, "guard: failed to register handler\r\n");
|
||||
return guard_weird;
|
||||
}
|
||||
|
||||
@ -128,7 +130,7 @@ guard_err guard(
|
||||
if (guard_p == 0) {
|
||||
guard_err install_err = _focus_guard();
|
||||
if (install_err != guard_sound) {
|
||||
// fprintf(stderr, "guard: failed to install guard page\r\n");
|
||||
fprintf(stderr, "guard: failed to install guard page\r\n");
|
||||
err = install_err;
|
||||
goto fail;
|
||||
}
|
||||
@ -151,31 +153,31 @@ guard_err guard(
|
||||
|
||||
*(void **)ret = result;
|
||||
|
||||
// if (mprotect(guard_p, GD_PAGESIZE, PROT_READ | PROT_WRITE) == -1) {
|
||||
// err = guard_armor;
|
||||
// goto fail;
|
||||
// }
|
||||
if (mprotect(guard_p, GD_PAGESIZE, PROT_READ | PROT_WRITE) == -1) {
|
||||
err = guard_armor;
|
||||
goto fail;
|
||||
}
|
||||
// fprintf(stderr, "guard: sound; uninstalled guard page\r\n");
|
||||
|
||||
return guard_sound;
|
||||
|
||||
fail:
|
||||
if (mprotect(guard_p, GD_PAGESIZE, PROT_READ | PROT_WRITE) == -1) {
|
||||
// fprintf(stderr, "guard: failed to uninstall guard page\r\n");
|
||||
fprintf(stderr, "guard: failed to uninstall guard page\r\n");
|
||||
}
|
||||
// fprintf(stderr, "guard: fail; uninstalled guard page\r\n");
|
||||
fprintf(stderr, "guard: fail; uninstalled guard page\r\n");
|
||||
switch (err) {
|
||||
case guard_armor:
|
||||
// fprintf(stderr, "guard: armor error\r\n");
|
||||
fprintf(stderr, "guard: armor error\r\n");
|
||||
break;
|
||||
case guard_weird:
|
||||
// fprintf(stderr, "guard: weird error\r\n");
|
||||
fprintf(stderr, "guard: weird error\r\n");
|
||||
break;
|
||||
case guard_spent:
|
||||
// fprintf(stderr, "guard: spent error\r\n");
|
||||
fprintf(stderr, "guard: spent error\r\n");
|
||||
break;
|
||||
case guard_erupt:
|
||||
// fprintf(stderr, "guard: erupt error\r\n");
|
||||
fprintf(stderr, "guard: erupt error\r\n");
|
||||
break;
|
||||
}
|
||||
return err;
|
||||
|
@ -122,7 +122,7 @@ off2addr(vaof_t off)
|
||||
#define BT_NUMMETAS 2 /* 2 metapages */
|
||||
#define BT_META_SECTION_WIDTH (BT_NUMMETAS * BT_PAGESIZE)
|
||||
#define BT_ADDRSIZE (BT_PAGESIZE << BT_PAGEWORD)
|
||||
#define PMA_GROW_SIZE_p (1024)
|
||||
#define PMA_GROW_SIZE_p (10000000)
|
||||
#define PMA_GROW_SIZE_b (BT_PAGESIZE * PMA_GROW_SIZE_p)
|
||||
|
||||
#define BT_NOPAGE 0
|
||||
@ -1570,6 +1570,7 @@ _flist_grow(BT_state *state, size_t pages)
|
||||
/* grows the backing file by PMA_GROW_SIZE_p and appends this freespace to the
|
||||
flist */
|
||||
{
|
||||
exit(1);
|
||||
/* grow the backing file by at least PMA_GROW_SIZE_p */
|
||||
pages = MAX(pages, PMA_GROW_SIZE_p);
|
||||
off_t bytes = P2BYTES(pages);
|
||||
|
Loading…
Reference in New Issue
Block a user