Conversation
Apps now run in ring 3 (see crt0.c), so a plain near call to the kernel's fixed function-pointer table can't be trusted: paging lets ring 3 execute those addresses, but a privileged instruction inside one (e.g. b_system's IRQ_ENABLE/IRQ_DISABLE) still runs at CPL 3 and #GPs, since a near call doesn't change CS/CPL. Every b_* call now traps via int $0x80 with R9 = the syscall index instead, so the kernel's own int_syscall gate can issue the call from ring 0. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Adds a custom rustc target (port/rust_port/x86_64-baremetal-firecracker.json) reusing std's Linux-musl backend, since this port's musl is stock musl 1.2.6 with only its syscall trap redirected (see musl_port/musl-1.2.6-baremetal.patch) -- ABI-compatible enough that no patch to Rust's own std source was needed, just link-time stubs for the backtrace unwinder this port has no runtime for (port/rust_port/unwind_stub.c). build-rust-app.sh mirrors build-app.sh's own two-stage compile-then-link shape. scripts/get-rust.sh pins and installs the nightly toolchain -Z build-std needs. Verified end to end under Firecracker: a println! app boots and prints, and std::fs::write/read_to_string/remove_file work against disk.img's ext2 filesystem. std::thread is not yet supported -- see RUST.md for the full writeup, what's verified, and known gaps. Co-Authored-By: Claude Sonnet 5 <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
libBareMetal.csyscall throughint $0x80(with R9 = syscall index) instead of a plain near call, since apps now run in ring 3 and a near call into a privileged instruction (e.g.b_system's IRQ_ENABLE/IRQ_DISABLE) would #GP without a real CPL change.std(not justno_std): a custom rustc target reusingstd's Linux-musl backend (this port's musl is stock musl 1.2.6 with only its syscall trap redirected, so it's ABI-compatible enough that no patch to Rust's own std source was needed -- just link-time stubs for the backtrace unwinder this port has no runtime for). SeeRUST.mdfor the full writeup.Test plan
println!app builds withbuild-rust-app.shand boots, printing to the console.std::fs::write/read_to_string/remove_filework againstdisk.img's ext2 filesystem.std::threadis known-broken (panics during thread teardown) -- documented as unsupported inRUST.md, not yet fixed.std::netis architecturally expected to work but has not been smoke-tested end to end.🤖 Generated with Claude Code