Skip to content

Commit

Permalink
Implements vCPU exit handler (#1217)
Browse files Browse the repository at this point in the history
  • Loading branch information
ultimaweapon authored Dec 30, 2024
1 parent 9334072 commit bdb88db
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
13 changes: 10 additions & 3 deletions gui/src/log/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,33 @@ 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;

/// Provides method to write kernel logs.
pub struct LogWriter {
file: LogFile,
parser: Parser,
path: PathBuf,
}

impl LogWriter {
pub fn new(file: &Path) -> Result<Self, std::io::Error> {
let file = File::create(file)?;
pub fn new(file: impl Into<PathBuf>) -> Result<Self, std::io::Error> {
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();
Expand Down
16 changes: 14 additions & 2 deletions gui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
}
}
Expand Down Expand Up @@ -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),
}

0 comments on commit bdb88db

Please sign in to comment.