wip: sigbus on guard hit?

This commit is contained in:
Matthew LeVan 2024-02-05 17:29:44 -05:00
parent fdc3010169
commit 3f6d76b699
3 changed files with 15 additions and 11 deletions

View File

@ -44,10 +44,10 @@ name = "ares"
path = "src/main.rs"
[profile.dev]
opt-level = 3
opt-level = 0
[profile.dev.package."*"]
opt-level = 3
opt-level = 0
# run with e.g. 'cargo build --features check_forwarding,check_acyclic'
[features]

View File

@ -143,7 +143,7 @@ impl Context {
snapshot: Option<Snapshot>,
constant_hot_state: &[HotEntry],
) -> Self {
let mut stack = NockStack::new(256 << 10 << 10, 0);
let mut stack = NockStack::new(128 << 10 << 10, 0);
let newt = Newt::new();
let cache = Hamt::<Noun>::new(&mut stack);

View File

@ -50,20 +50,24 @@ _focus_guard()
}
}
// Place the new guard page in the low-aligned center.
// Calculate the new center for the guard page.
guard_p = (uint64_t *)low_p + ((high_p - low_p) / 2);
guard_p = (uint64_t *)((uintptr_t)guard_p & ~(GD_PAGESIZE - 1));
// Mark the new guard page.
if (guard_p != old_guard_p) {
fprintf(stderr, "guard: focused guard page\r\n");
// Place the new guard page or return if we're spent.
bool spent = false;
const bool same = old_guard_p == guard_p;
const bool left = (high_p - low_p) > GD_PAGESIZE;
if (same && !left) {
fprintf(stderr, "guard: spent: %p; left: %u\r\n", guard_p, left);
return guard_spent;
}
else {
fprintf(stderr, "guard: high: %p; low: %p\r\n", high_p, low_p);
fprintf(stderr, "guard: focused: %p; left: %u\r\n", guard_p, left);
if (mprotect(guard_p, GD_PAGESIZE, PROT_NONE) == -1) {
return guard_armor;
}
} else {
fprintf(stderr, "guard: spent; exiting\r\n");
exit(1);
return guard_spent;
}
return guard_sound;