Skip to content

Conversation

@hgarvison
Copy link

Add tool to VmgsTool to read the IGVMfile from a DLL (passed in as a data file) and write it to VMGS FileId 8 (GUEST_FIRMWARE). To do this pass one of three resource codes (nonconfidential, snp, tdx) into the cmdline tool:

vmgstool.exe copy-igvmfile --filepath --keypath --datapath --resource-code

@hgarvison hgarvison requested a review from a team as a code owner December 15, 2025 20:24
Copilot AI review requested due to automatic review settings December 15, 2025 20:24
@hgarvison hgarvison requested a review from a team as a code owner December 15, 2025 20:24
@github-actions github-actions bot added Guide unsafe Related to unsafe code labels Dec 15, 2025
@github-actions
Copy link

⚠️ Unsafe Code Detected

This PR modifies files containing unsafe Rust code. Extra scrutiny is required during review.

For more on why we check whole files, instead of just diffs, check out the Rustonomicon

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds functionality to vmgstool for reading IGVM firmware files from Windows DLLs and writing them to VMGS file ID 8 (GUEST_FIRMWARE). The implementation uses Windows API calls to extract resources from DLLs and supports multiple resource codes (nonconfidential, snp, snp_no_hcl, tdx, tdx_no_hcl) for different VM configurations.

Key changes:

  • New copy-igvmfile command that extracts IGVM files from DLLs using Windows resource APIs
  • Support for encrypted and unencrypted VMGS files when writing IGVM data
  • Platform-specific implementation for Windows x86_64 only

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 7 comments.

File Description
vm/vmgs/vmgstool/src/main.rs Implements the copy-igvmfile command with Windows API resource loading, adds error handling, command-line parsing, and test cases
vm/vmgs/vmgstool/build.rs Adds rustc-check-cfg directive for guest_arch configuration
vm/vmgs/vmgstool/Cargo.toml Adds winapi dependency with required Windows API features
Guide/src/dev_guide/dev_tools/vmgstool.md Documents the new copy-igvmfile command usage

@github-actions
Copy link

@github-actions
Copy link

// SAFETY: We are loading a DLL and reading its resources as a datafile or image resource,
// which means we will not be executing any of its potentially unsafe functions. We are also
// taking precautions to ensure safety by validating all pointers and handling errors appropriately.
unsafe {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using LoadLibrary (which requires unsafe) could we instead just parse the dll using object? See the hvlite_pcat_locator crate for an example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Guide unsafe Related to unsafe code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants