feat(arm64): init system, proper heap allocator, TTBR0 and ERET fixes#165
Merged
feat(arm64): init system, proper heap allocator, TTBR0 and ERET fixes#165
Conversation
…0 on syscall resume Implement ARM64 init system (/sbin/init) that spawns telnetd and init_shell, replacing direct init_shell boot. Fix three critical bugs discovered during testing: 1. Heap exhaustion (OOM): Replace bump allocator with linked_list_allocator. The bump allocator never reclaimed freed memory, exhausting the 32MB heap within seconds of boot as temporary Vec/String/BTreeMap allocations permanently consumed space. Also remove unnecessary Box::leak calls in exec syscall paths (ARM64 and x86_64) that leaked entire ELF binaries. 2. TTBR0 stale after blocking syscall: When a userspace thread blocked in a syscall (e.g., read() on stdin) was context-switched back in, setup_kernel_thread_return_arm64 did not restore the process's page table. TTBR0 retained the previously-running process's value, causing instruction abort permission faults when the thread returned to EL0 with the wrong address space. 3. Register clobber fixes in ERET paths: Use per-CPU eret_scratch field to save/restore registers across SP switches in both syscall and IRQ return paths, preventing x0/x1 corruption (syscall) and x16 corruption (IRQ). 4. TTBR0 restoration after exec: Update saved_process_cr3 after exec switches to the new program's page table, preventing the assembly ERET path from restoring the old (freed) page table. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
/sbin/initbinary that spawns telnetd and init_shell, with zombie reaping and service respawnlinked_list_allocator— the bump allocator never reclaimed freed memory, causing OOM within seconds of bootBox::leakof ELF data and program names in exec syscall paths (ARM64 + x86_64)Test plan
breenix>prompt)🤖 Generated with Claude Code