From bdb88db54f05efff89feed12f435f321d18b5998 Mon Sep 17 00:00:00 2001 From: Putta Khunchalee Date: Mon, 30 Dec 2024 19:27:16 +0700 Subject: [PATCH] Implements vCPU exit handler (#1217) --- gui/src/log/mod.rs | 13 ++++++++++--- gui/src/main.rs | 16 ++++++++++++++-- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/gui/src/log/mod.rs b/gui/src/log/mod.rs index f14db3439..af40458df 100644 --- a/gui/src/log/mod.rs +++ b/gui/src/log/mod.rs @@ -3,7 +3,7 @@ use anstyle_parse::Parser; use obconf::ConsoleType; use std::fs::File; use std::io::{stderr, stdout, Write}; -use std::path::Path; +use std::path::{Path, PathBuf}; mod file; @@ -11,18 +11,25 @@ mod file; pub struct LogWriter { file: LogFile, parser: Parser, + path: PathBuf, } impl LogWriter { - pub fn new(file: &Path) -> Result { - let file = File::create(file)?; + pub fn new(file: impl Into) -> Result { + let path = file.into(); + let file = File::create(&path)?; Ok(Self { file: LogFile::new(file), parser: Parser::default(), + path, }) } + pub fn path(&self) -> &Path { + &self.path + } + pub fn write(&mut self, ty: ConsoleType, msg: String) { // Write console. let msg = msg.as_bytes(); diff --git a/gui/src/main.rs b/gui/src/main.rs index 6dcfe1ca1..ff5544805 100644 --- a/gui/src/main.rs +++ b/gui/src/main.rs @@ -9,7 +9,7 @@ use self::ui::{ MainWindow, PlatformExt, ProfileModel, ResolutionModel, RuntimeExt, SlintBackend, WaitForDebugger, }; -use self::vmm::{Vmm, VmmError, VmmEvent}; +use self::vmm::{CpuError, Vmm, VmmError, VmmEvent}; use async_net::{TcpListener, TcpStream}; use clap::{Parser, ValueEnum}; use erdp::ErrorDisplay; @@ -281,7 +281,13 @@ async fn run(args: ProgramArgs, exe: PathBuf) -> Result<(), ProgramError> { // Process VMM event. if let Some(vmm) = vmm { match vmm { - VmmEvent::Exit(_, _) => todo!(), + VmmEvent::Exit(id, r) => { + if !r.map_err(ProgramError::CpuThread)? { + return Err(ProgramError::CpuPanic(id, logs.path().into())); + } else if id == 0 { + break; + } + } VmmEvent::Log(t, m) => logs.write(t, m), } } @@ -531,4 +537,10 @@ enum ProgramError { #[error("couldn't start VMM for {0}")] StartVmm(PathBuf, #[source] VmmError), + + #[error("thread for vCPU #{0} was stopped unexpectedly")] + CpuThread(#[source] CpuError), + + #[error("vCPU #{0} was panic, see {1} for more information")] + CpuPanic(usize, PathBuf), }