Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/noun/allocate.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ STATIC_ASSERT( u3a_vits <= u3a_min_log,

/* u3a_is_north(): yes if road [r] is north road.
*/
# define u3a_is_north(r) __((r)->cap_p > (r)->hat_p)
# define u3a_is_north(r) __((r)->mat_p > (r)->rut_p)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A road is north if the heap is low and the stack is high; south is opposite. This check has always been implemented using the innermost bounds of the stack ("cap") and heap ("hat").

The heap growing over the stack is guarded by explicit checks in the allocator, but the stack growing over the heap is not (the "cap" is constantly moving, so such checks have a measurable cost). Instead, a PROT_NONE guard page floats between the heap and the stack. Stores into it are caught by a global SIGSEGV handler and the page is repositioned if possible. If not the fault is handled with u3m_signal(c3__meme). In that state, the old implementation of u3a_is_north() will give the wrong answer, which wreaks havoc on refcounting and de/allocation logic.

This change makes u3a_is_north() robust against overflow states, by comparing the immutable outermost bounds of the heap ("rut") and stack ("mat").


/* u3a_is_south(): yes if road [r] is south road.
*/
Expand Down
9 changes: 3 additions & 6 deletions pkg/noun/manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,7 @@ _cm_signal_deep(void)
// go utterly haywire.
//
if ( 0 == u3H->rod_u.bug.mer ) {
u3H->rod_u.bug.mer = u3i_string(
"emergency buffer with sufficient space to cons the trace and bail"
);
u3H->rod_u.bug.mer = u3i_tape("emergency buffer");
}

u3t_boot();
Expand Down Expand Up @@ -1217,13 +1215,12 @@ u3m_hate(c3_w pad_w)
c3_w fag_w = u3R->how.fag_w;
u3m_leap(pad_w);

u3R->bug.mer = u3i_tape("emergency buffer");

// inherit forward-flowing flags
//
u3R->how.fag_w |= (fag_w & u3a_flag_cash);

u3R->bug.mer = u3i_string(
"emergency buffer with sufficient space to cons the trace and bail"
);
}

// RETAINS `now`.
Expand Down
4 changes: 4 additions & 0 deletions pkg/vere/melt.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ u3_melt_all(FILE *fil_u)
//
u3_assert( &(u3H->rod_u) == u3R );

u3z(u3H->rod_u.bug.mer);

can_u.siz_w = 32;
can_u.tac = c3_malloc(sizeof(*can_u.tac) * can_u.siz_w);

Expand Down Expand Up @@ -194,6 +196,8 @@ u3_melt_all(FILE *fil_u)

c3_free(can_u.tac);

u3H->rod_u.bug.mer = u3i_tape("emergency buffer");

return u3a_idle(u3R) - pre_w;
}

Expand Down
Loading