Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory as file descriptor #195

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
7958af3
add Memory impl
Wenzel Apr 14, 2021
35400e6
memory: add unit tests for Seek
Wenzel Apr 14, 2021
823c1a7
microvmi: expose pause, resume and get_max_physical_addr
Wenzel Apr 19, 2021
52ccd6d
microvmi: remove max_addr field
Wenzel Apr 19, 2021
eadbcb4
microvmi: clippy fixes
Wenzel Apr 19, 2021
eafe09b
microvmi: fix driver import
Wenzel Apr 19, 2021
b4c646d
memory: fix performance issues in Seek
Wenzel Apr 19, 2021
e3c45a8
mem-dump: update buffer size
Wenzel Apr 19, 2021
c5a7e1d
memory: refcell impl
Wenzel Apr 19, 2021
f1dd5ae
memory: add PaddedMemory
Wenzel Apr 19, 2021
a92de1b
memory: fix tests
Wenzel Apr 19, 2021
e53d49b
capi: update with Microvmi struct
Wenzel Apr 19, 2021
aaaa5a4
python: adapt read methods
Wenzel Apr 19, 2021
3197da0
python: add padded read
Wenzel Apr 23, 2021
bc6f49d
memory: fix seek unit tests
Wenzel Apr 23, 2021
bb4bfa0
memory: add TODO
Wenzel Apr 23, 2021
1408ae4
add doc
Wenzel Apr 23, 2021
1efcd20
examples: fix cr-events compilation
Wenzel Apr 28, 2021
820d32d
examples: fix interrupt-events
Wenzel Apr 28, 2021
75116df
examples: remove unused import
Wenzel Apr 28, 2021
39c678b
examples: fix mem-events
Wenzel Apr 28, 2021
921ed60
examples: fix msr-events
Wenzel Apr 28, 2021
9ee376d
examples: fix pause
Wenzel Apr 28, 2021
ba48425
examples: fix regs-dump
Wenzel Apr 28, 2021
38cbc76
microvmi: fix imports
Wenzel Apr 28, 2021
556182c
api: replace read_physical by read_frame
Wenzel Apr 28, 2021
4f017ad
xen: impl read_frame
Wenzel Apr 28, 2021
1fbc863
kvm: impl read_frame
Wenzel Apr 28, 2021
47fb25c
clippy: allow upper case acronyms
Wenzel Apr 28, 2021
49a0b0a
examples: use read_exact to ignore the return value
Wenzel Apr 28, 2021
cd4dc16
virtualbox: impl read_frame
Wenzel Apr 29, 2021
3381be7
microvmi: disable doctest for new example
Wenzel Apr 30, 2021
9fef107
memory: remove duplicated Seek implementation
Wenzel May 19, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
microvmi: expose pause, resume and get_max_physical_addr
Wenzel committed Apr 19, 2021
commit 823c1a73152c4c4931f1b5c1b61576bbc1f0b312
15 changes: 8 additions & 7 deletions examples/mem-dump.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use std::fs::File;
use std::io::Write;
use std::io::{Read, Write};
use std::path::Path;

use clap::{App, Arg, ArgMatches};
use indicatif::{ProgressBar, ProgressStyle};
use log::{debug, trace};
use log::trace;

use microvmi::api::{DriverInitParam, Introspectable};
use microvmi::api::DriverInitParam;
use microvmi::Microvmi;

const PAGE_SIZE: usize = 4096;

@@ -55,8 +56,8 @@ fn main() {
let spinner = ProgressBar::new_spinner();
spinner.enable_steady_tick(200);
spinner.set_message("Initializing libmicrovmi...");
let mut drv: Box<dyn Introspectable> =
microvmi::init(domain_name, None, init_option).expect("Failed to init libmicrovmi");
let mut drv =
Microvmi::new(domain_name, None, init_option).expect("Failed to init libmicrovmi");
spinner.finish_and_clear();

println!("pausing the VM");
@@ -85,8 +86,8 @@ fn main() {
// reset buffer each loop
let mut buffer: [u8; PAGE_SIZE] = [0; PAGE_SIZE];
let mut _bytes_read = 0;
drv.read_physical(cur_addr, &mut buffer, &mut _bytes_read)
.unwrap_or_else(|_| debug!("failed to read memory at {:#X}", cur_addr));
drv.read_exact(&mut buffer)
.expect(&*format!("Failed to read memory at {:#X}", cur_addr));
dump_file
.write_all(&buffer)
.expect("failed to write to file");
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ mod driver;
pub mod errors;
mod memory;
pub mod microvmi;
pub use microvmi::Microvmi;

#[macro_use]
extern crate log;
13 changes: 13 additions & 0 deletions src/microvmi.rs
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@ use driver::kvm::Kvm;
use driver::virtualbox::VBox;
#[cfg(feature = "xen")]
use driver::xen::Xen;
use std::error::Error;

/// Main struct to interact with the library
pub struct Microvmi {
@@ -85,6 +86,18 @@ impl Microvmi {
}
}
}

pub fn get_max_physical_addr(&self) -> Result<u64, Box<dyn Error>> {
Ok(self.drv.get_max_physical_addr()?)
}

pub fn pause(&mut self) -> Result<(), Box<dyn Error>> {
Ok(self.drv.pause()?)
}

pub fn resume(&mut self) -> Result<(), Box<dyn Error>> {
Ok(self.drv.resume()?)
}
}

/// Initialize a given driver type