Skip to content

manage: fix emergency buffer and north road calculation#993

Merged
pkova merged 3 commits into
developfrom
pkova/meme-fiz
May 6, 2026
Merged

manage: fix emergency buffer and north road calculation#993
pkova merged 3 commits into
developfrom
pkova/meme-fiz

Conversation

@pkova
Copy link
Copy Markdown
Collaborator

@pkova pkova commented Apr 1, 2026

Resolves #

@pkova pkova requested a review from a team as a code owner April 1, 2026 16:45
Comment thread pkg/noun/manage.c Outdated
Copy link
Copy Markdown
Collaborator

@joemfb joemfb left a comment

Choose a reason for hiding this comment

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

u3_melt_all() / u3_meld_all() should be changed to lose and reallocate the emergency buffer (or simply not canonicalize it). Its purpose is defeated if it ends up structurally shared with any other part of the state.

Comment thread pkg/noun/allocate.h
/* 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").

Comment thread pkg/noun/manage.c Outdated
u3R->bug.mer = u3i_string(
"emergency buffer with sufficient space to cons the trace and bail"
u3R->bug.mer = u3i_tape(
"emergency buffer"
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.

This is overkill, since at-most three cells are required for re-consing the bail mote and trace in u3m_bail(). At the same time, since this is a fresh road, we'll be allocating a full page of cells and putting the remainder in the cell pool. So I'm not sure if the difference matters.

@pkova pkova force-pushed the pkova/meme-fiz branch from b888579 to 5268aab Compare May 6, 2026 16:21
@pkova pkova force-pushed the pkova/meme-fiz branch from 5268aab to 9e4ead9 Compare May 6, 2026 16:39
@pkova pkova merged commit 7e84fee into develop May 6, 2026
2 checks passed
@pkova pkova deleted the pkova/meme-fiz branch May 6, 2026 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants