Expand description
s9vm : guest entry/exit trampoline.
The only reliable way to enter the guest is an assembly routine that honors the hardware contract:
- save the host callee-saved registers;
- load the guest general-purpose registers from
EnterFrame; - execute
vmlaunch(first entry) orvmresume(subsequent entries); - on exit, the hardware loads
HOST_RSP/HOST_RIP: control arrives at thes9vm_guest_exitlabel, 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 intoHOST_RSPbefore 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§
- Enter
Frame - 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.