From 71b6445b048456bf198d8b622570db95f4665cb9 Mon Sep 17 00:00:00 2001 From: salmonik Date: Fri, 21 Aug 2026 21:17:44 +0200 Subject: exec: PE32+ loader, versioned ABI, first external binaries (v0.6.0) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit rsapi: the kernel<->binary ABI crate (no_std, no deps). Versioned Exports table (magic + version header), EntryPoint = extern "C" on x86_64-unknown-uefi (Win64: RCX/RDX/R8), Line/Arg/StreamResult types. Binaries link only this crate. rsnix::load: PE32+ parser — DOS/COFF/optional headers, section copy, BSS zero-fill, .reloc base relocations (DIR64) via rva_to_file mapping (the reloc directory is an RVA, not a file offset). Images are allocated at LOAD_BASE=192MiB inside the page allocator's conventional span and identity-mapped user+writable+nx. rsnix::exec: resolution name -> /disk//bin//.efi per mounted volume; spawn reserves a sched slot, stores a per-task ExecCtx (exports + argv block + image) before launch_at installs the frame — no adopt race. Trampoline calls entry(&Exports, argc, argv), posts TaskMsg::User(exit_code) to the shell. abort_current notifies the shell with u64::MAX when an exec'd binary dies, so a faulting command cannot leave the shell blocked forever. sched: reserve_slot/launch_at split out of spawn; task_exit made pub. shell: exec_external runs before non-frozen built-ins (ADR 0006 resolution rule); frozen core (help/clear/echo/halt/poweroff/exit/ rescan) is exempt. Exports v1 wires put_line to the terminal and get_line to EOF; stream injection lands in Phase 3. ^C while waiting kills the command task. bins/{hello,boom}: gate binaries. hello prints through the exports table; boom faults on 0x400000000000 to prove containment. The image entry point IS the ABI entry (efi_main carries the Exports signature). Version 0.6.0: exec exists end-to-end. Gates verified in QEMU: 'hello' loads from \\bin\\cli\\hello.efi, calls put_line across the ABI, exits 0, shell unblocks; 'boom' faults, task dies gracefully with full report, shell survives, jobs shows the corpse; built-in fallback works when the file is absent; test-disk PASS. --- bins/hello/src/main.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 bins/hello/src/main.rs (limited to 'bins/hello/src') diff --git a/bins/hello/src/main.rs b/bins/hello/src/main.rs new file mode 100644 index 0000000..d1d58df --- /dev/null +++ b/bins/hello/src/main.rs @@ -0,0 +1,33 @@ +//! hello — the first rs-dos external binary (ADR 0006 Phase 2 gate). +//! +//! Prints one line through the injected Exports table and exits 0. +//! Exercises the whole chain: PE32+ load, relocation, ABI call, task exit. + +#![no_std] +#![no_main] + +use rsapi::Exports; + +#[panic_handler] +fn panic(_info: &core::panic::PanicInfo) -> ! { + loop { + core::hint::spin_loop(); + } +} + +/// The image entry point — the loader jumps here with the ABI arguments +/// (exports table, argc, argv). The conventional UEFI name is kept so +/// the PE looks normal; the signature is the rs-dos ABI. +#[unsafe(no_mangle)] +pub extern "C" fn efi_main(exports: &'static Exports, _argc: usize, _argv: *const rsapi::Arg) -> i32 { + let msg = b"hello, world - from an external binary"; + let line = rsapi::Line { + ptr: msg.as_ptr(), + len: msg.len(), + }; + if (exports.put_line)(line) { + 0 + } else { + 1 + } +} -- cgit v1.2.3