Skip to content

Commit

Permalink
Merge pull request #1048 from stlankes/exit
Browse files Browse the repository at this point in the history
forward error code to the host
  • Loading branch information
stlankes authored Feb 4, 2024
2 parents 7bd4bcd + 38c353a commit 4936809
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 14 deletions.
5 changes: 3 additions & 2 deletions src/arch/aarch64/kernel/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,13 @@ pub fn halt() {
}

/// Shutdown the system
pub fn shutdown() -> ! {
#[allow(unused_variables)]
pub fn shutdown(error_code: i32) -> ! {
info!("Shutting down system");

cfg_if::cfg_if! {
if #[cfg(feature = "semihosting")] {
semihosting::process::exit(0)
semihosting::process::exit(error_code)
} else {
unsafe {
const PSCI_SYSTEM_OFF: u64 = 0x84000008;
Expand Down
5 changes: 3 additions & 2 deletions src/arch/riscv64/kernel/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,13 @@ pub fn halt() {
}

/// Shutdown the system
pub fn shutdown() -> ! {
#[allow(unused_variables)]
pub fn shutdown(error_code: i32) -> ! {
info!("Shutting down system");

cfg_if::cfg_if! {
if #[cfg(feature = "semihosting")] {
semihosting::process::exit(0)
semihosting::process::exit(error_code)
} else {
// use SBI shutdown
sbi::legacy::shutdown()
Expand Down
8 changes: 6 additions & 2 deletions src/arch/x86_64/kernel/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ fn triple_fault() -> ! {
}

/// Shutdown the system
pub fn shutdown() -> ! {
pub fn shutdown(error_code: i32) -> ! {
info!("Shutting down system");
let acpi_result: Result<Infallible, ()> = {
#[cfg(feature = "acpi")]
Expand All @@ -1019,7 +1019,11 @@ pub fn shutdown() -> ! {
PlatformInfo::Multiboot { .. } => {
// Try QEMU's debug exit
let exit_handler = qemu_exit::X86::new(0xf4, 3);
exit_handler.exit_success()
if error_code == 0 {
exit_handler.exit_success()
} else {
exit_handler.exit_failure()
}
}
PlatformInfo::Uhyve { .. } => todo!(),
}
Expand Down
19 changes: 15 additions & 4 deletions src/arch/x86_64/mm/paging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use core::ptr;

use x86_64::instructions::tlb;
use x86_64::registers::control::Cr3;
use x86_64::structures::paging::mapper::UnmapError;
use x86_64::structures::paging::mapper::{TranslateResult, UnmapError};
pub use x86_64::structures::paging::PageTableFlags as PageTableEntryFlags;
use x86_64::structures::paging::{
Mapper, Page, PageTable, PageTableIndex, PhysFrame, RecursivePageTable, Size2MiB, Translate,
Expand Down Expand Up @@ -68,9 +68,20 @@ unsafe fn recursive_page_table() -> RecursivePageTable<'static> {
pub fn virtual_to_physical(virtual_address: VirtAddr) -> Option<PhysAddr> {
let virtual_address = x86_64::VirtAddr::new(virtual_address.0);
let page_table = unsafe { recursive_page_table() };
page_table
.translate_addr(virtual_address)
.map(|addr| PhysAddr(addr.as_u64()))
let translate = page_table.translate(virtual_address);

match translate {
TranslateResult::NotMapped | TranslateResult::InvalidFrameAddress(_) => {
warn!(
"Uable to determine the physical address of 0x{:X}",
virtual_address
);
None
}
TranslateResult::Mapped { frame, offset, .. } => {
Some(PhysAddr((frame.start_address() + offset).as_u64()))
}
}
}

#[no_mangle]
Expand Down
4 changes: 2 additions & 2 deletions src/syscalls/interfaces/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub trait SyscallInterface: Send + Sync {
(argc, argv, envv)
}

fn shutdown(&self, _arg: i32) -> ! {
arch::processor::shutdown()
fn shutdown(&self, error_code: i32) -> ! {
arch::processor::shutdown(error_code)
}
}
4 changes: 2 additions & 2 deletions src/syscalls/interfaces/uhyve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ impl SyscallInterface for Uhyve {
(syscmdsize.argc, argv, env)
}

fn shutdown(&self, arg: i32) -> ! {
let mut sysexit = SysExit::new(arg);
fn shutdown(&self, error_code: i32) -> ! {
let mut sysexit = SysExit::new(error_code);
uhyve_send(UHYVE_PORT_EXIT, &mut sysexit);

loop {
Expand Down
1 change: 1 addition & 0 deletions xtask/src/ci/qemu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ impl Qemu {
if self.build.cargo_build.artifact.arch == Arch::Aarch64 {
memory = memory.max(256);
}
memory = memory.max(64);
memory
}

Expand Down

0 comments on commit 4936809

Please sign in to comment.