Skip to main content

Machine

Struct Machine 

Source
pub struct Machine {
    devices: Devices,
    memory: HhdmMemory,
    cpuid: CpuidPolicy,
}
Expand description

Device model, CPU description and emulation state of one world.

The CPUID policy is stored per world, not per vCPU: every vCPU of the world must observe the same processor, and a guest that migrates a thread between vCPUs must not see the feature set change under it. A future SMP extension may refine this into a per-vCPU policy.

Fields§

§devices: Devices§memory: HhdmMemory§cpuid: CpuidPolicy

Implementations§

Source§

impl Machine

Source

pub fn new() -> Self

Creates the machine of a world.

Source

pub fn new_legacy() -> Self

Creates the machine of a legacy PC: no PCI virtio functions.

Used by worlds that boot a real firmware (SeaBIOS) from a floppy: the firmware enumerates PCI and would otherwise attach its own virtio drivers to the s9vm functions.

Source

fn with_devices(devices: Devices) -> Self

Source

pub fn cpuid_policy(&self) -> CpuidPolicy

Current guest CPU description.

Source

pub fn set_cpuid_policy(&mut self, policy: CpuidPolicy)

Replaces the guest CPU description.

The change applies to the next guest entry: while a vCPU is running, the machine is moved out of the world registry, so a concurrent update reaches the registry copy and is overwritten when the execution copy is restored at the end of RUN. This is intentional and benign : the policy is not meant to change mid-run, and the syscall reports success for an existing world so the caller does not need to retry.

Source

pub fn devices(&self) -> &Devices

Device model (diagnostics and event routing by the kernel).

Source

pub fn devices_mut(&mut self) -> &mut Devices

Mutable device model (kernel-side interrupt delivery).

Source

pub fn drain_console(&mut self) -> Vec<u8> ⓘ

Takes the bytes the guest wrote to the virtio console.

Source

pub fn drain_serial(&mut self) -> Vec<u8> ⓘ

Takes the bytes the guest wrote to the legacy COM1 UART.

Source

pub fn push_serial_input(&mut self, bytes: &[u8]) -> usize

Queues bytes on the guest’s COM1 receive path.

The receive FIFO is bounded by the model; the number of bytes accepted is returned so a console front-end can retry the rest later.

Source

pub fn advance_time(&mut self, apic: &mut LocalApic, cycles: u64, tsc_hz: u64)

Advances the legacy time base by the host time the guest consumed.

Called by the execution loop once per VM exit with the measured TSC delta. The 8254 counts at its nominal 1.193182 MHz and raises its IRQ0 line when channel 0 expires; the CMOS RTC advances its calendar and raises its interrupt line when a programmed event (periodic, update ended or alarm) occurs and the corresponding status-B enable bit is set. tsc_hz == 0 means the host frequency is unknown: the raw cycle count is used, the documented degradation of the timer model.

Source

pub fn drain_network(&mut self) -> Vec<u8> ⓘ

Takes the frames the guest transmitted on the virtio network device.

Source

pub fn drain_network_frames(&mut self) -> Vec<Vec<u8>>

Takes the individual frames the guest transmitted.

Source

pub fn push_network_frame(&mut self, frame: &[u8])

Queues a frame for the guest’s receive path.

Source

pub unsafe fn service_devices<V: VcpuOps>(&mut self, vcpu: &mut V)

Services the device receive queues against the current guest memory.

Called before a guest entry: input and frames queued by the user side are moved into the driver’s available buffers.

§Safety

The control block must be loaded and the guest must not be running.

Source

pub unsafe fn handle<V: VcpuOps>( &mut self, vcpu: &mut V, apic: &mut LocalApic, exit: &ExitInfo, ) -> Result<bool, EmuError>

Tries to consume an exit by replaying the faulting instruction against the device model.

Returns true when the exit was fully handled and the guest can be resumed; false (or an error) means the exit must be reported to policy.

§Safety

The control block must be loaded and the guest must not be running: this is only called from an exit handler, before resuming.

Source

unsafe fn replay_cpuid<V: VcpuOps>(&self, vcpu: &mut V)

Replays the intercepted CPUID instruction against the policy.

Inputs are the architectural EAX (leaf) and ECX (subleaf) registers; outputs are EAX, EBX, ECX and EDX in that order. The 32-bit results are written through the 64-bit general-purpose registers, whose upper halves are zeroed exactly like a hardware 32-bit destination. RIP then advances past the fixed two-byte 0F A2 encoding.

§Safety

Same contract as Machine::handle: the control block is loaded and the guest is not running.

Trait Implementations§

Source§

impl Default for Machine

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.