From 3f6d76b6992c6abced8aadea366d5f2ad9e8ce8f Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Mon, 5 Feb 2024 17:29:44 -0500 Subject: [PATCH] wip: sigbus on guard hit? --- rust/ares/Cargo.toml | 4 ++-- rust/ares/src/serf.rs | 2 +- rust/ares_guard/c-src/guard.c | 20 ++++++++++++-------- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/rust/ares/Cargo.toml b/rust/ares/Cargo.toml index ba1a059..733b43f 100644 --- a/rust/ares/Cargo.toml +++ b/rust/ares/Cargo.toml @@ -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] diff --git a/rust/ares/src/serf.rs b/rust/ares/src/serf.rs index ef83d79..3ca2822 100644 --- a/rust/ares/src/serf.rs +++ b/rust/ares/src/serf.rs @@ -143,7 +143,7 @@ impl Context { snapshot: Option, 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::::new(&mut stack); diff --git a/rust/ares_guard/c-src/guard.c b/rust/ares_guard/c-src/guard.c index 26f6bee..0ee039d 100644 --- a/rust/ares_guard/c-src/guard.c +++ b/rust/ares_guard/c-src/guard.c @@ -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;