Skip to content

Fixes for self-hosting mes#12

Merged
alganet merged 2 commits into
mainfrom
mes-self-stage2-fixes
Jul 17, 2026
Merged

Fixes for self-hosting mes#12
alganet merged 2 commits into
mainfrom
mes-self-stage2-fixes

Conversation

@alganet

@alganet alganet commented Jul 17, 2026

Copy link
Copy Markdown
Owner

No description provided.

alganet added 2 commits July 17, 2026 08:20
The riscv64 counterpart of the fix aarch64 already carries. The x86 kernel
bumps next_process_num only when the exec'ing process had forked; an exec
without a fork overlays the current process (same descriptor). The riscv64
port had the forked/first/overlay three-way check but then bumped
next_process_num and allocated a new descriptor unconditionally.

stage0 uses fork-less exec chains (kaem chaining), so every chain leaked a
bogus process level: the chained process's clone saves landed at the
still-live parent's save-area base, corrupting the parent's saved image. A
later restore then resurrected mixed-epoch state and the next exec'd program
faulted.

Fix (x86 parity): create_new_process flag at globals+0x0A0, set from the
existing three-way check; the next_process_num bump and the CWD copy run only
for forked/first execs; an overlay exec reuses the caller's descriptor and
keeps its own CWD.

Both 64-bit ports now agree with x86 and with each other.
…user window

Two coupled relocations in the raspi3b memory map, both surfaced by mes
self-compiling in-image (a ~183MB process image from a 6M-cell arena). virt is
untouched; both sites already dispatch on the board id x27 (3 = raspi3b).

1. Preload buffer: VA 0x42000000 -> 0x78000000 (PA 0x02000000 -> 0x38000000).
   The 8MB CMD18 stdin preload sat at PA 0x02000000, which is inside the user
   process window (PA 0x00600000 upwards). Any process with a heap over ~26MB
   overwrote it; mes did exactly that, and the shell then read its own leftover
   heap back as stdin -- binary garbage echoed as "?" once the script ran out.
   PA 0x38000000 is the slot the save area vacates below: clear of the user
   window and of the save area, 48MB below the kernel stack, and file data
   (from PA 0x21900000) never grows the 359MB it would take to reach it.

2. Fork save area: VA 0x78000000 -> 0x90000000 (PA 0x38000000 -> 0x10000000).
   The legacy Entry-1 base left only 56MB below the kernel stack -- too little
   to hold a single mes fork image, so the fork memcpy walked into the kernel
   stack and the guest silently rebooted. VA 0x90000000 maps through Entry 2 to
   PA 0x10000000: above the user brk cap (PA 0x0FF00000) and below the
   file-name/data region (PA 0x20900000), a ~264MB hole that holds the peak
   nested save (kaem ~1MB + mes ~183MB) with margin. Only the exact base VA
   0x80000000 would alias PA 0x00000000 and clobber the kernel; 0x90000000
   clears it.
@alganet
alganet merged commit 74d8f29 into main Jul 17, 2026
6 checks passed
@alganet
alganet deleted the mes-self-stage2-fixes branch July 17, 2026 11:28
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.

1 participant