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: CpuidPolicyImplementations§
Source§impl Machine
impl Machine
Sourcepub fn new_legacy() -> Self
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.
fn with_devices(devices: Devices) -> Self
Sourcepub fn cpuid_policy(&self) -> CpuidPolicy
pub fn cpuid_policy(&self) -> CpuidPolicy
Current guest CPU description.
Sourcepub fn set_cpuid_policy(&mut self, policy: CpuidPolicy)
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.
Sourcepub fn devices_mut(&mut self) -> &mut Devices
pub fn devices_mut(&mut self) -> &mut Devices
Mutable device model (kernel-side interrupt delivery).
Sourcepub fn drain_console(&mut self) -> Vec<u8> ⓘ
pub fn drain_console(&mut self) -> Vec<u8> ⓘ
Takes the bytes the guest wrote to the virtio console.
Sourcepub fn drain_serial(&mut self) -> Vec<u8> ⓘ
pub fn drain_serial(&mut self) -> Vec<u8> ⓘ
Takes the bytes the guest wrote to the legacy COM1 UART.
Sourcepub fn push_serial_input(&mut self, bytes: &[u8]) -> usize
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.
Sourcepub fn advance_time(&mut self, apic: &mut LocalApic, cycles: u64, tsc_hz: u64)
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.
Sourcepub fn drain_network(&mut self) -> Vec<u8> ⓘ
pub fn drain_network(&mut self) -> Vec<u8> ⓘ
Takes the frames the guest transmitted on the virtio network device.
Sourcepub fn drain_network_frames(&mut self) -> Vec<Vec<u8>>
pub fn drain_network_frames(&mut self) -> Vec<Vec<u8>>
Takes the individual frames the guest transmitted.
Sourcepub fn push_network_frame(&mut self, frame: &[u8])
pub fn push_network_frame(&mut self, frame: &[u8])
Queues a frame for the guest’s receive path.
Sourcepub unsafe fn service_devices<V: VcpuOps>(&mut self, vcpu: &mut V)
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.
Sourcepub unsafe fn handle<V: VcpuOps>(
&mut self,
vcpu: &mut V,
apic: &mut LocalApic,
exit: &ExitInfo,
) -> Result<bool, EmuError>
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.
Sourceunsafe fn replay_cpuid<V: VcpuOps>(&self, vcpu: &mut V)
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§
Auto Trait Implementations§
impl Forget for Machine
impl Freeze for Machine
impl Move for Machine
impl RefUnwindSafe for Machine
impl Send for Machine
impl Sync for Machine
impl Unpin for Machine
impl UnsafeUnpin for Machine
impl UnwindSafe for Machine
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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