u3: control presence of guard page using macro

This commit is contained in:
Peter McEvoy 2022-07-07 09:33:41 -07:00
parent 53af044d18
commit b7cd97664d
4 changed files with 16 additions and 9 deletions

View File

@ -68,6 +68,7 @@ in stdenv.mkDerivation {
CFLAGS = oFlags ++ lib.optionals (!enableDebug) [ "-Werror" ]; CFLAGS = oFlags ++ lib.optionals (!enableDebug) [ "-Werror" ];
GUARD_PAGE = true;
MEMORY_DEBUG = enableDebug; MEMORY_DEBUG = enableDebug;
CPU_DEBUG = enableDebug; CPU_DEBUG = enableDebug;
EVENT_TIME_DEBUG = false; EVENT_TIME_DEBUG = false;

1
pkg/urbit/configure vendored
View File

@ -64,6 +64,7 @@ do
shift shift
done done
[ -n "${GUARD_PAGE-}" ] && defmacro U3_GUARD_PAGE 1
[ -n "${MEMORY_DEBUG-}" ] && defmacro U3_MEMORY_DEBUG 1 [ -n "${MEMORY_DEBUG-}" ] && defmacro U3_MEMORY_DEBUG 1
[ -n "${MEMORY_LOG-}" ] && defmacro U3_MEMORY_LOG 1 [ -n "${MEMORY_LOG-}" ] && defmacro U3_MEMORY_LOG 1
[ -n "${CPU_DEBUG-}" ] && defmacro U3_CPU_DEBUG 1 [ -n "${CPU_DEBUG-}" ] && defmacro U3_CPU_DEBUG 1

View File

@ -398,28 +398,26 @@
{ {
u3R->cap_p += pil_u->mov_ws; u3R->cap_p += pil_u->mov_ws;
// XX define symbol to control guard page #ifndef U3_GUARD_PAGE
//
#if 0
// !off means we're on a north road // !off means we're on a north road
// //
if ( !pil_u->off_ws ) { if ( !pil_u->off_ws ) {
if( !(u3R->cap_p > u3R->hat_p) ) { if( !(u3R->cap_p > u3R->hat_p) ) {
u3m_bail(c3__meme); u3m_bail(c3__meme);
} }
#ifdef U3_MEMORY_DEBUG # ifdef U3_MEMORY_DEBUG
c3_assert( pil_u->top_p >= u3R->cap_p ); c3_assert( pil_u->top_p >= u3R->cap_p );
#endif # endif
} }
else { else {
if( !(u3R->cap_p < u3R->hat_p) ) { if( !(u3R->cap_p < u3R->hat_p) ) {
u3m_bail(c3__meme); u3m_bail(c3__meme);
} }
#ifdef U3_MEMORY_DEBUG # ifdef U3_MEMORY_DEBUG
c3_assert( pil_u->top_p <= u3R->cap_p ); c3_assert( pil_u->top_p <= u3R->cap_p );
#endif # endif
} }
#endif #endif /* ifndef U3_GUARD_PAGE */
#ifdef U3_MEMORY_DEBUG #ifdef U3_MEMORY_DEBUG
c3_assert( pil_u->rod_u == u3R ); c3_assert( pil_u->rod_u == u3R );

View File

@ -186,6 +186,7 @@ _ce_mapfree(void* map_v)
} }
#endif #endif
#ifdef U3_GUARD_PAGE
//! Place a guard page at the (approximate) middle of the free space between //! 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 //! the heap and stack of the current road, bailing if memory has been
//! exhausted. //! exhausted.
@ -237,6 +238,7 @@ _ce_center_guard_page(void)
fail: fail:
u3m_signal(c3__meme); u3m_signal(c3__meme);
} }
#endif /* ifdef U3_GUARD_PAGE */
/* u3e_fault(): handle a memory event with libsigsegv protocol. /* 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 blk_w = (pag_w >> 5);
c3_w bit_w = (pag_w & 31); c3_w bit_w = (pag_w & 31);
#ifdef U3_GUARD_PAGE
// The fault happened in the guard page. // The fault happened in the guard page.
if ( gar_pag_p <= adr_p && adr_p < gar_pag_p + pag_wiz_i ) { if ( gar_pag_p <= adr_p && adr_p < gar_pag_p + pag_wiz_i ) {
_ce_center_guard_page(); _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); fprintf(stderr, "strange page: %d, at %p, off %x\r\n", pag_w, adr_w, adr_p);
c3_assert(0); c3_assert(0);
return 0; return 0;
@ -1093,5 +1098,7 @@ u3e_foul(void)
void void
u3e_init(void) u3e_init(void)
{ {
#ifdef U3_GUARD_PAGE
_ce_center_guard_page(); _ce_center_guard_page();
#endif
} }