Skip to content

Commit

Permalink
Version 5.11.4
Browse files Browse the repository at this point in the history
  • Loading branch information
ufrisk committed Sep 8, 2024
1 parent 5a50667 commit 4de3e9e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
12 changes: 11 additions & 1 deletion vmmrust/memprocfs/src/lib_memprocfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1572,7 +1572,7 @@ impl VmmScatterMemory<'_> {
/// ```
#[derive(Debug)]
pub struct VmmProcess<'a> {
vmm : &'a Vmm<'a>,
pub vmm : &'a Vmm<'a>,
pub pid : u32,
}

Expand Down Expand Up @@ -4648,6 +4648,16 @@ impl Drop for Vmm<'_> {
}
}

impl Clone for Vmm<'_> {
fn clone(&self) -> Self {
let vmmid = self.get_config(CONFIG_OPT_CORE_VMM_ID).unwrap();
let vmmid_str = vmmid.to_string();
let vmm_clone_args = ["-create-from-vmmid", &vmmid_str].to_vec();
let vmm_clone = Vmm::new(&self.path_vmm, &vmm_clone_args).unwrap();
return vmm_clone;
}
}

impl fmt::Display for Vmm<'_> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Vmm")
Expand Down
23 changes: 8 additions & 15 deletions vmmrust/memprocfs_example/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -886,36 +886,29 @@ pub fn main_example() -> ResultEx<()> {



// Example: Duplicate the Vmm struct creating a duplicate Vmm struct.
// Example: Clone the Vmm struct creating a duplicate Vmm struct.
// The primary use case would be to create a linked thread-safe Vmm
// instance that can be used safely in a separate thread. First the
// vmmid is retrieved as a numeric u64 value. This u64 value may be
// forwarded to a separate thread in which a new linked dublicated
// Vmm object is created.
// instance that can be used safely in a separate thread.
// Both Vmm objects will follow normal rules, the native Vmm instance
// will be closed with all Rust Vmm instances have been dropped.
let vmmid = vmm.get_config(CONFIG_OPT_CORE_VMM_ID).unwrap();

{
println!("========================================");
println!("Vmm::new(): (duplicate)");
let vmmid_str = vmmid.to_string();
let vmm_duplicate_args = ["-create-from-vmmid", &vmmid_str].to_vec();
let vmm_duplicate = Vmm::new(vmm_lib_path, &vmm_duplicate_args).unwrap();
println!("Vmm.clone():");
let vmm_clone = vmm.clone();

// Example: vmm.mem_read():
// Read 0x100 bytes from physical address 0x1000.
println!("========================================");
println!("Vmm.mem_read(): (duplicate)");
if let Ok(data_read) = vmm_duplicate.mem_read(0x1000, 0x100) {
println!("Vmm.mem_read(): (clone)");
if let Ok(data_read) = vmm_clone.mem_read(0x1000, 0x100) {
println!("{:?}", data_read.hex_dump());
}

// Example: vmm.process_from_pid():
// Retrieve the 'System' process by its PID.
println!("========================================");
println!("Vmm.process_from_pid(): (duplicate)");
if let Ok(process) = vmm_duplicate.process_from_pid(4) {
println!("Vmm.process_from_pid(): (clone)");
if let Ok(process) = vmm_clone.process_from_pid(4) {
println!("{}", process);
}
}
Expand Down

0 comments on commit 4de3e9e

Please sign in to comment.