Select Git revision
-
Timo Kreuzer authored
The emulator had a mutable reference to the callbacks structure, which made it extremely difficult to use, due to the inability to hold any other references on it and the inability to make this part of a structure. To get rid of the reference, the callback is now passed as a parameter to the try_io_emulation method, replacing the PVOID context (helping to avoid unsafe casts).
Timo Kreuzer authoredThe emulator had a mutable reference to the callbacks structure, which made it extremely difficult to use, due to the inability to hold any other references on it and the inability to make this part of a structure. To get rid of the reference, the callback is now passed as a parameter to the try_io_emulation method, replacing the PVOID context (helping to avoid unsafe casts).
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
demo.rs 23.28 KiB
// Copyright 2018 Cloudbase Solutions Srl
// Copyright 2018-2019 CrowdStrike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
extern crate libc;
extern crate libwhp;
use libwhp::instruction_emulator::*;
use libwhp::memory::*;
use libwhp::*;
use std::cell::RefCell;
use std::fs::File;
use std::io::prelude::*;
use std::io::{self, Write};
use std::path::PathBuf;
const CPUID_EXT_HYPERVISOR: UINT32 = 1 << 31;
const PDE64_PRESENT: u64 = 1;
const PDE64_RW: u64 = 1 << 1;
const PDE64_USER: u64 = 1 << 2;
const PDE64_PS: u64 = 1 << 7;
const CR4_PAE: u64 = 1 << 5;
const CR4_OSFXSR: u64 = 1 << 9;
const CR4_OSXMMEXCPT: u64 = 1 << 10;
const CR0_PE: u64 = 1;
const CR0_MP: u64 = 1 << 1;
const CR0_ET: u64 = 1 << 4;
const CR0_NE: u64 = 1 << 5;
const CR0_WP: u64 = 1 << 16;
const CR0_AM: u64 = 1 << 18;
const CR0_PG: u64 = 1 << 31;
const EFER_LME: u64 = 1 << 8;
const EFER_LMA: u64 = 1 << 10;
const INT_VECTOR: u32 = 0x35;
#[allow(non_snake_case)]
#[derive(Debug, Copy, Clone, Default)]
#[repr(C)]
struct CpuInfo {
apic_enabled: bool,
}
fn main() {
check_hypervisor();
let mut p = Partition::new().unwrap();
let apic_present = is_apic_present();
let mut cpu_info = CpuInfo {
apic_enabled: false,
};
setup_partition(&mut p, &mut cpu_info, apic_present);