diff --git a/build/src/main.rs b/build/src/main.rs index 237040f69..b8e797df8 100644 --- a/build/src/main.rs +++ b/build/src/main.rs @@ -112,8 +112,13 @@ fn main() { let exit_status = qemu_cmd.status().unwrap(); if !exit_status.success() { // FIXME: Exit code manipulation is not needed when using non-x86 QEMU - let exit_code = exit_status.code().unwrap_or(0b10) >> 1; - std::process::exit(exit_code); + let qemu_exit_code = exit_status.code().unwrap(); + let kernel_exit_code = qemu_exit_code >> 1; + match kernel_exit_code { + 0x10 /*jinux_frame::QemuExitCode::Success*/ => { std::process::exit(0); }, + 0x20 /*jinux_frame::QemuExitCode::Failed*/ => { std::process::exit(1); }, + _ => { std::process::exit(qemu_exit_code) }, + } } } diff --git a/framework/jinux-frame/src/lib.rs b/framework/jinux-frame/src/lib.rs index a93a90bc3..81cc23b55 100644 --- a/framework/jinux-frame/src/lib.rs +++ b/framework/jinux-frame/src/lib.rs @@ -147,15 +147,17 @@ pub fn panic_handler() { // } } -/// The exit code of x86 QEMU. In `qemu-system-x86_64` the exit code will be -/// `(code << 1) | 1`. So you could never let QEMU invoke `exit(0)`. Check -/// if the result is `0b01` instead. +/// The exit code of x86 QEMU isa debug device. In `qemu-system-x86_64` the +/// exit code will be `(code << 1) | 1`. So you could never let QEMU invoke +/// `exit(0)`. We also need to check if the exit code is returned by the +/// kernel, so we couldn't use 0 as exit_success because this may conflict +/// with QEMU return value 1, which indicates that QEMU itself fails. #[cfg(target_arch = "x86_64")] #[derive(Debug, Clone, Copy, PartialEq, Eq)] #[repr(u32)] pub enum QemuExitCode { - Success = 0b0, - Failed = 0b1, + Success = 0x10, + Failed = 0x20, } pub fn exit_qemu(exit_code: QemuExitCode) -> ! {