diff --git a/rust/ares/Cargo.toml b/rust/ares/Cargo.toml index aa71ecc..ba1a059 100644 --- a/rust/ares/Cargo.toml +++ b/rust/ares/Cargo.toml @@ -44,12 +44,10 @@ name = "ares" path = "src/main.rs" [profile.dev] -opt-level = 0 -debug = true +opt-level = 3 [profile.dev.package."*"] -opt-level = 0 -debug = true +opt-level = 3 # 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 96b8960..ef83d79 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(1024 << 10 << 10, 0); + let mut stack = NockStack::new(256 << 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 4041368..26f6bee 100644 --- a/rust/ares_guard/c-src/guard.c +++ b/rust/ares_guard/c-src/guard.c @@ -1,6 +1,8 @@ #include #include +#include #include +#include #include #include @@ -38,11 +40,14 @@ _focus_guard() return guard_weird; } - // Unmark the old guard page. + // Unmark the old guard page if one exists. void *old_guard_p = guard_p; - if (old_guard_p != 0 - && mprotect(old_guard_p, GD_PAGESIZE, PROT_READ | PROT_WRITE) == -1) { - return guard_armor; + if (old_guard_p != NULL) { + fprintf(stderr, "guard: retiring old guard page\r\n"); + if (old_guard_p != 0 + && mprotect(old_guard_p, GD_PAGESIZE, PROT_READ | PROT_WRITE) == -1) { + return guard_armor; + } } // Place the new guard page in the low-aligned center. @@ -51,10 +56,13 @@ _focus_guard() // Mark the new guard page. if (guard_p != old_guard_p) { + fprintf(stderr, "guard: focused guard page\r\n"); 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; } @@ -81,12 +89,12 @@ _signal_handler(int sig, siginfo_t *si, void *unused) if (si->si_addr >= (void *)guard_p && si->si_addr < (void *)guard_p + GD_PAGESIZE) { - fprintf(stderr, "guard: fault in guard: %p\r\n", si->si_addr); + fprintf(stderr, "guard: hit: %p\r\n", si->si_addr); err = _focus_guard(); break; } else { - fprintf(stderr, "guard: fault outside guard %p\r\n", si->si_addr); + fprintf(stderr, "guard: weird hit: %p\r\n", si->si_addr); if (NULL != prev_sigsegv_handler) { prev_sigsegv_handler(sig, si, unused); break; @@ -126,7 +134,6 @@ _register_handler() } prev_sigsegv_handler = prev_sa.sa_sigaction; - // fprintf(stderr, "guard: registered handler\r\n"); return guard_sound; } @@ -150,16 +157,13 @@ guard( const uint64_t *low_p = low_f(bounds_data, context_p); const uint64_t *high_p = high_f(bounds_data, context_p); - // fprintf(stderr, "guard: low: %p high: %p\r\n", (void *)low_p, (void *)high_p); - - // const unsigned long free_mb = (unsigned long)(high_p - low_p) / 1024 / 1024; - // fprintf(stderr, "guard: free space: %lu MB\r\n", free_mb); - - guard_err focus_err = _focus_guard(); - if (focus_err != guard_sound && focus_err != guard_spent) { - fprintf(stderr, "guard: failed to install guard page\r\n"); - err = focus_err; - goto fail; + if (guard_p == NULL) { + guard_err focus_err = _focus_guard(); + if (focus_err != guard_sound && focus_err != guard_spent) { + fprintf(stderr, "guard: failed to install guard page\r\n"); + err = focus_err; + goto fail; + } } if (_register_handler() != guard_sound) { @@ -179,11 +183,6 @@ guard( *(void **)ret = result; - if (mprotect(guard_p, GD_PAGESIZE, PROT_READ | PROT_WRITE) == -1) { - err = guard_armor; - goto fail; - } - return guard_sound; fail: