forked from obhq/obliteration
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creates KVM VM and setup WHP partition (obhq#738)
- Loading branch information
1 parent
cf8251b
commit 48a82eb
Showing
9 changed files
with
359 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
fn main() { | ||
let os = std::env::var("CARGO_CFG_TARGET_OS").unwrap(); | ||
|
||
if os == "macos" { | ||
println!("cargo:rustc-link-lib=framework=Hypervisor"); | ||
match std::env::var("CARGO_CFG_TARGET_OS").unwrap().as_str() { | ||
"linux" | "android" => cc::Build::new() | ||
.cpp(true) | ||
.file("src/linux/kvm.cpp") | ||
.compile("hvkvm"), | ||
"macos" => println!("cargo:rustc-link-lib=framework=Hypervisor"), | ||
_ => {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,30 @@ | ||
#![allow(non_camel_case_types)] | ||
|
||
use crate::NewError; | ||
use std::ffi::c_int; | ||
use std::ptr::null_mut; | ||
|
||
/// RAII struct for `hv_vm_create` and `hv_vm_destroy`. | ||
pub struct Vm(()); | ||
|
||
impl Vm { | ||
pub fn new() -> Result<Self, NewError> { | ||
match unsafe { hv_vm_create(null_mut()) } { | ||
0 => Ok(Self(())), | ||
v => Err(NewError::CreateVmFailed(v)), | ||
} | ||
} | ||
} | ||
|
||
impl Drop for Vm { | ||
fn drop(&mut self) { | ||
let status = unsafe { hv_vm_destroy() }; | ||
|
||
#[repr(C)] | ||
pub struct hv_vm_config_t([u8; 0]); | ||
if status != 0 { | ||
panic!("hv_vm_destroy() fails with {status:#x}"); | ||
} | ||
} | ||
} | ||
|
||
extern "C" { | ||
pub fn hv_vm_create(config: *mut hv_vm_config_t) -> c_int; | ||
pub fn hv_vm_destroy() -> c_int; | ||
fn hv_vm_create(config: *mut ()) -> c_int; | ||
fn hv_vm_destroy() -> c_int; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.