Skip to content

Route syscalls through int $0x80 for ring 3; add Rust (full std) support - #6

Merged
IanSeyler merged 2 commits into
mainfrom
ring3
Sep 15, 2026
Merged

IanSeyler merged 2 commits into
mainfrom
ring3

Conversation

@IanSeyler

Copy link
Copy Markdown
Member

Summary

  • Routes every libBareMetal.c syscall through int $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.
  • Adds Rust support with full std (not just no_std): a custom rustc target reusing std'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). See RUST.md for the full writeup.

Test plan

  • Verified via Firecracker boot: a println! app builds with build-rust-app.sh and boots, printing to the console.
  • Verified via Firecracker boot: std::fs::write/read_to_string/remove_file work against disk.img's ext2 filesystem.
  • std::thread is known-broken (panics during thread teardown) -- documented as unsupported in RUST.md, not yet fixed.
  • std::net is architecturally expected to work but has not been smoke-tested end to end.

🤖 Generated with Claude Code

IanSeyler and others added 2 commits September 15, 2026 18:48
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>
@IanSeyler
IanSeyler merged commit 75851e0 into main Sep 15, 2026
@IanSeyler
IanSeyler deleted the ring3 branch September 15, 2026 22:53
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