Skip to main content

Module launch

Module launch 

Source
Expand description

s9vm : guest entry/exit trampoline.

The only reliable way to enter the guest is an assembly routine that honors the hardware contract:

  1. save the host callee-saved registers;
  2. load the guest general-purpose registers from EnterFrame;
  3. execute vmlaunch (first entry) or vmresume (subsequent entries);
  4. on exit, the hardware loads HOST_RSP/HOST_RIP: control arrives at the s9vm_guest_exit label, which saves the guest registers and restores the host.

§Contract

s9vm_enter_guest(frame, host_stack_top) -> u64

  • frame: *mut EnterFrame, live for the whole call;
  • host_stack_top: top (16-byte aligned) of a dedicated host stack, written into HOST_RSP before entry;
  • return: 0 = normal guest exit (read the reason from the control block), 1 = entry failure (VMfail, read the status).

The frame is referenced by a pointer stored on the host stack ([host_stack_top - 8]), which makes it possible to find it again on return without depending on a register (all GPRs belong to the guest).

The S9VM_F_* offsets are shared between the assembler and the Rust structure; a host test verifies that they match (offset_of!).

Re-exports§

use core::arch::global_asm; 🔒

Structs§

EnterFrame
Exchange area between the kernel and the trampoline for one guest entry.

Constants§

S9VM_ENTER_FRAME_SIZE
Total size of the frame.
S9VM_F_HOST_R12
S9VM_F_HOST_R13
S9VM_F_HOST_R14
S9VM_F_HOST_R15
S9VM_F_HOST_RBP
S9VM_F_HOST_RBX
S9VM_F_HOST_RSP
S9VM_F_LAUNCHED
S9VM_F_R8
S9VM_F_R9
S9VM_F_R10
S9VM_F_R11
S9VM_F_R12
S9VM_F_R13
S9VM_F_R14
S9VM_F_R15
S9VM_F_RAX
Guest general-purpose registers, in save order.
S9VM_F_RBP
S9VM_F_RBX
S9VM_F_RCX
S9VM_F_RDI
S9VM_F_RDX
S9VM_F_RFLAGS
S9VM_F_RIP
S9VM_F_RSI
S9VM_F_RSP
S9VM_F_STATUS

Functions§

s9vm_enter_guest⚠
Assembly entry point (defined by [S9VM_TRAMPOLINE]).
s9vm_guest_entry⚠
Assembly guest entry (address used for HOST_RIP).
s9vm_guest_exit⚠
Resume label after a guest exit (address placed in HOST_RIP). This is not a callable function: only its address is taken.