Skip to main content

CpuState

Struct CpuState 

Source
pub struct CpuState {
Show 15 fields pub gpr: [u64; 16], pub rip: u64, pub rflags: u64, pub seg: [Segment; 6], pub cr0: u64, pub cr2: u64, pub cr3: u64, pub cr4: u64, pub cr8: u64, pub efer: u64, pub gdt_base: u64, pub gdt_limit: u16, pub idt_base: u64, pub idt_limit: u16, pub tr: Segment,
}
Expand description

Architectural state of one vCPU at an instruction boundary.

General-purpose registers are stored in the hardware encoding order (rax, rcx, rdx, rbx, rsp, rbp, rsi, rdi, r8 … r15), so that gpr[n] is register number n in a ModRM byte.

Fields§

§gpr: [u64; 16]

General-purpose registers in encoding order.

§rip: u64

Instruction pointer (an offset inside CS).

§rflags: u64

RFLAGS as the guest sees it. KVM hides the TF bit it sets for single-stepping, so this is the guest’s own view.

§seg: [Segment; 6]

Segment registers, indexed by SegReg.

§cr0: u64

CR0.

§cr2: u64

CR2 (last page-fault linear address).

§cr3: u64

CR3 (page-table root, plus PCID in the low 12 bits when CR4.PCIDE is set).

§cr4: u64

CR4.

§cr8: u64

CR8 (task priority).

§efer: u64

IA32_EFER.

§gdt_base: u64

GDTR base.

§gdt_limit: u16

GDTR limit.

§idt_base: u64

IDTR base.

§idt_limit: u16

IDTR limit.

§tr: Segment

The task register (its base locates the TSS, which holds the I/O permission bitmap).

Implementations§

Source§

impl CpuState

Source

pub fn from_kvm(r: &kvm_regs, s: &kvm_sregs) -> CpuState

Builds a snapshot from the two structures KVM returns.

Source

pub fn segment(&self, r: SegReg) -> &Segment

A segment register.

Source

pub fn mode(&self) -> CpuMode

The CPU mode, worked out from CR0, EFER, RFLAGS and the CS descriptor.

Source

pub fn iopl(&self) -> u8

RFLAGS.IOPL, the privilege level needed for port I/O.

Source

pub fn cpl(&self) -> u8

Current privilege level (0 = most privileged, 3 = user).

The CPL is the DPL of the SS descriptor, which is what KVM itself uses. In real mode it is 0; in virtual-8086 mode it is 3.

Source

pub fn page_table_root(&self) -> u64

The page-table root without the PCID / flag bits.

Source

pub fn pcid(&self) -> Option<u16>

Process-context identifier, when CR4.PCIDE is set.

Source

pub fn linear_rip(&self) -> u64

Linear address of the current instruction (CS.base + RIP, truncated to the address width of the mode).

Source

pub fn effective_segment_base(&self, r: SegReg) -> u64

Segment base as used by address generation: in 64-bit mode only FS and GS have a non-zero base.

Source

pub fn linear_mask(&self) -> u64

Width of a linear address in this mode, as a mask.

Source

pub fn stack_pointer(&self) -> u64

The stack pointer, sized for the current stack segment.

Trait Implementations§

Source§

impl Clone for CpuState

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for CpuState

Source§

impl Debug for CpuState

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CpuState

Source§

fn default() -> Self

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

impl Eq for CpuState

Source§

impl PartialEq for CpuState

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for CpuState

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
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.