Instruction

Struct Instruction 

Source
pub struct Instruction<'a> { /* private fields */ }
Expand description

Wrapper structure for a qemu_plugin_insn *

§Safety

This structure is safe to use as long as the pointer is valid. The pointer is always opaque, and therefore may not be dereferenced.

§Example

struct MyPlugin;

impl qemu_plugin::plugin::Register for MyPlugin {}

impl qemu_plugin::plugin::HasCallbacks for MyPlugin {
    fn on_translation_block_translate(
        &mut self,
        id: qemu_plugin::PluginId,
        tb: qemu_plugin::TranslationBlock,
    ) -> Result<()> {
        for insn in tb.instructions() {
            let vaddr = insn.vaddr();
            let disas = insn.disas()?;
            // Register a callback to be run on execution of this instruction
            insn.register_execute_callback(move |vcpu_index| {
                println!("{vcpu_index}@{vaddr:#x}: {disas}");
            });
        }
        Ok(())
    }
}

Implementations§

Source§

impl<'a> Instruction<'a>

Source

pub fn read_data(&self, data: &mut [u8]) -> usize

Reads the data for this instruction returning number of bytes read. This method may only be called inside the callback in which the instruction is obtained.

Source

pub fn data(&self) -> Vec<u8>

Returns the data for this instruction. This method may only be called inside the callback in which the instruction is obtained, but the resulting data is owned.

Source

pub fn size(&self) -> usize

Returns the size of the data for this instruction

Source

pub fn vaddr(&self) -> u64

Returns the virtual address of this instruction

Source

pub fn haddr(&self) -> u64

Returns the hardware (physical) address of this instruction

Source

pub fn disas(&self) -> Result<String>

Returns the textual disassembly of this instruction

Source

pub fn symbol(&self) -> Result<Option<String>>

Returns the symbol associated with this instruction, if one exists and the binary contains a symbol table

Source

pub fn register_execute_callback<F>(&self, cb: F)
where F: FnMut(VCPUIndex) + Send + Sync + 'static,

Register a callback to be run on execution of this instruction with no capability to inspect registers

§Arguments
  • cb: The callback to be run
Source

pub fn register_execute_callback_flags<F>(&self, cb: F, flags: CallbackFlags)
where F: FnMut(VCPUIndex) + Send + Sync + 'static,

Register a callback to be run on execution of this instruction with a choice of capability whether to inspect or modify registers or not

§Arguments
  • cb: The callback to be run
  • flags: The flags for the callback specifying whether the callback needs permission to read or write registers
Source

pub fn register_conditional_execute_callback<F>( &self, cb: F, cond: PluginCondition, entry: PluginU64, immediate: u64, )
where F: FnMut(VCPUIndex) + Send + Sync + 'static,

Register a callback to be conditionally run on execution of this instruction with no capability to inspect registers

§Arguments
  • cb: The callback to be run
  • cond: The condition for the callback to be run
  • entry: The entry to increment the scoreboard for
  • immediate: The immediate value to use for the callback
Source

pub fn register_conditional_execute_callback_flags<F>( &self, cb: F, flags: CallbackFlags, cond: PluginCondition, entry: PluginU64, immediate: u64, )
where F: FnMut(VCPUIndex) + Send + Sync + 'static,

Register a callback to be conditionally run on execution of this instruction with a choice of capability whether to inspect or modify registers or not

§Arguments
  • cb: The callback to be run
  • flags: The flags for the callback specifying whether the callback needs permission to read or write registers
  • cond: The condition for the callback to be run
  • entry: The entry to increment the scoreboard for
  • immediate: The immediate value to use for the callback
Source

pub fn register_memory_access_callback<F>(&self, cb: F, rw: MemRW)
where F: for<'b> FnMut(VCPUIndex, MemoryInfo<'b>, u64) + Send + Sync + 'static,

Register a callback to be run on memory access of this instruction

§Arguments
  • cb: The callback to be run
  • rw: The type of memory access to trigger the callback on
Source

pub fn register_memory_access_callback_flags<F>( &self, cb: F, rw: MemRW, flags: CallbackFlags, )
where F: for<'b> FnMut(VCPUIndex, MemoryInfo<'b>, u64) + Send + Sync + 'static,

Register a callback to be run on memory access of this instruction

§Arguments
  • cb: The callback to be run
  • rw: The type of memory access to trigger the callback on

Trait Implementations§

Source§

impl<'a> Clone for Instruction<'a>

Source§

fn clone(&self) -> Instruction<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for Instruction<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Instruction<'a>

§

impl<'a> RefUnwindSafe for Instruction<'a>

§

impl<'a> Send for Instruction<'a>

§

impl<'a> Sync for Instruction<'a>

§

impl<'a> Unpin for Instruction<'a>

§

impl<'a> UnwindSafe for Instruction<'a>

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.