igvmfilegen/vp_context_builder/mod.rs
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Defines the common VP context builder traits and methods for different isolation architectures.
5
6pub mod snp;
7pub mod tdx;
8pub mod vbs;
9
10use igvm::IgvmDirectiveHeader;
11use loader::importer::BootPageAcceptance;
12
13/// Holds memory state representing a VP context that should be imported.
14pub struct VpContextPageState {
15 pub page_base: u64,
16 pub page_count: u64,
17 pub acceptance: BootPageAcceptance,
18 pub data: Vec<u8>,
19}
20
21/// The finalized VP context data that should be imported or added to the IGVM file.
22pub enum VpContextState {
23 /// VP context are pages to be imported.
24 Page(VpContextPageState),
25 /// VP context is an IGVM directive header to be added to the file directly.
26 Directive(IgvmDirectiveHeader),
27}
28
29/// Common trait used to implement VP context builders for different isolation architectures.
30pub trait VpContextBuilder {
31 /// The register type which is different on different architectures.
32 type Register;
33
34 /// Import a register to the BSP at the given vtl.
35 fn import_vp_register(&mut self, register: Self::Register);
36
37 /// Define the base of the GPA range to be used for architecture-specific VP context data.
38 fn set_vp_context_memory(&mut self, page_base: u64);
39
40 /// Finalize all VP context data. Returns architecture specific data that should be either imported
41 /// into guest memory space or added directly to the IGVM file.
42 fn finalize(&mut self, state: &mut Vec<VpContextState>);
43}