diff --git a/nix/pkgs/urbit/default.nix b/nix/pkgs/urbit/default.nix index e9da7b305..c9023c077 100644 --- a/nix/pkgs/urbit/default.nix +++ b/nix/pkgs/urbit/default.nix @@ -68,6 +68,7 @@ in stdenv.mkDerivation { CFLAGS = oFlags ++ lib.optionals (!enableDebug) [ "-Werror" ]; + GUARD_PAGE = true; MEMORY_DEBUG = enableDebug; CPU_DEBUG = enableDebug; EVENT_TIME_DEBUG = false; diff --git a/pkg/urbit/configure b/pkg/urbit/configure index 22958e3ed..54be912e5 100755 --- a/pkg/urbit/configure +++ b/pkg/urbit/configure @@ -64,6 +64,7 @@ do shift done +[ -n "${GUARD_PAGE-}" ] && defmacro U3_GUARD_PAGE 1 [ -n "${MEMORY_DEBUG-}" ] && defmacro U3_MEMORY_DEBUG 1 [ -n "${MEMORY_LOG-}" ] && defmacro U3_MEMORY_LOG 1 [ -n "${CPU_DEBUG-}" ] && defmacro U3_CPU_DEBUG 1 diff --git a/pkg/urbit/include/noun/allocate.h b/pkg/urbit/include/noun/allocate.h index 13f4a545f..529ad6fb6 100644 --- a/pkg/urbit/include/noun/allocate.h +++ b/pkg/urbit/include/noun/allocate.h @@ -398,28 +398,26 @@ { u3R->cap_p += pil_u->mov_ws; - // XX define symbol to control guard page - // -#if 0 +#ifndef U3_GUARD_PAGE // !off means we're on a north road // if ( !pil_u->off_ws ) { if( !(u3R->cap_p > u3R->hat_p) ) { u3m_bail(c3__meme); } - #ifdef U3_MEMORY_DEBUG +# ifdef U3_MEMORY_DEBUG c3_assert( pil_u->top_p >= u3R->cap_p ); - #endif +# endif } else { if( !(u3R->cap_p < u3R->hat_p) ) { u3m_bail(c3__meme); } - #ifdef U3_MEMORY_DEBUG +# ifdef U3_MEMORY_DEBUG c3_assert( pil_u->top_p <= u3R->cap_p ); - #endif +# endif } -#endif +#endif /* ifndef U3_GUARD_PAGE */ #ifdef U3_MEMORY_DEBUG c3_assert( pil_u->rod_u == u3R ); diff --git a/pkg/urbit/noun/events.c b/pkg/urbit/noun/events.c index 455137efc..3d4d47e10 100644 --- a/pkg/urbit/noun/events.c +++ b/pkg/urbit/noun/events.c @@ -186,6 +186,7 @@ _ce_mapfree(void* map_v) } #endif +#ifdef U3_GUARD_PAGE //! Place a guard page at the (approximate) middle of the free space between //! the heap and stack of the current road, bailing if memory has been //! exhausted. @@ -237,6 +238,7 @@ _ce_center_guard_page(void) fail: u3m_signal(c3__meme); } +#endif /* ifdef U3_GUARD_PAGE */ /* u3e_fault(): handle a memory event with libsigsegv protocol. */ @@ -265,11 +267,14 @@ u3e_fault(void* adr_v, c3_i ser_i) c3_w blk_w = (pag_w >> 5); c3_w bit_w = (pag_w & 31); +#ifdef U3_GUARD_PAGE // The fault happened in the guard page. if ( gar_pag_p <= adr_p && adr_p < gar_pag_p + pag_wiz_i ) { _ce_center_guard_page(); } - else if ( 0 != (u3P.dit_w[blk_w] & (1 << bit_w)) ) { + else +#endif /* ifdef U3_GUARD_PAGE */ + if ( 0 != (u3P.dit_w[blk_w] & (1 << bit_w)) ) { fprintf(stderr, "strange page: %d, at %p, off %x\r\n", pag_w, adr_w, adr_p); c3_assert(0); return 0; @@ -1093,5 +1098,7 @@ u3e_foul(void) void u3e_init(void) { +#ifdef U3_GUARD_PAGE _ce_center_guard_page(); +#endif }