Skip to main content

VmiHandler

Trait VmiHandler 

Source
pub trait VmiHandler<Os>
where Os: VmiOs,
{ type Output; // Required method fn handle_event( &mut self, event: VmiContext<'_, Os>, ) -> VmiEventResponse<Os::Architecture>; // Provided methods fn handle_timeout(&mut self, _session: &VmiSession<'_, Os>) { ... } fn handle_interrupted(&mut self, _session: &VmiSession<'_, Os>) { ... } fn cleanup(&mut self, _session: &VmiSession<'_, Os>) { ... } fn poll(&self) -> Option<Self::Output> { ... } }
Expand description

A trait for handling VMI events.

A factory that creates a handler implementing this trait is passed to the VmiSession::handle method to handle VMI events.

Required Associated Types§

Source

type Output

The output type of the handler.

Required Methods§

Source

fn handle_event( &mut self, event: VmiContext<'_, Os>, ) -> VmiEventResponse<Os::Architecture>

Called for each VMI event.

The returned VmiEventResponse tells the hypervisor how to resume the vCPU that triggered the event.

Provided Methods§

Source

fn handle_timeout(&mut self, _session: &VmiSession<'_, Os>)

Called when the event loop times out waiting for the next event.

This is useful for periodic housekeeping while the guest is idle.

Source

fn handle_interrupted(&mut self, _session: &VmiSession<'_, Os>)

Called when the event loop is interrupted by a signal.

Typically used to initiate a graceful shutdown, by setting a flag that causes poll to return Some on the next call.

Source

fn cleanup(&mut self, _session: &VmiSession<'_, Os>)

Called once before the session tears down monitoring.

This gives the handler an opportunity to release resources that depend on the session (views, memory access permissions, event monitors) before the session calls reset_state.

Source

fn poll(&self) -> Option<Self::Output>

Checks if the handler has completed.

This method is called after each event is handled. If the handler has completed, this method should return the output of the handler. Otherwise, it should return None.

Implementors§