Skip to main content

tmk_protocol/
lib.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Definitions for the protocol between `tmk_vmm` and the test microkernel.
5
6#![no_std]
7#![forbid(unsafe_code)]
8
9use bitfield_struct::bitfield;
10use zerocopy::FromBytes;
11use zerocopy::Immutable;
12use zerocopy::IntoBytes;
13use zerocopy::KnownLayout;
14use zerocopy::TryFromBytes;
15
16/// Start input from the VMM to the TMK.
17#[repr(C)]
18#[derive(Debug, IntoBytes, Immutable)]
19pub struct StartInput {
20    /// The address to write commands to.
21    pub command: u64,
22    /// The test index.
23    pub test_index: u64,
24}
25
26/// Test metadata flags.
27#[bitfield(u64)]
28#[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
29pub struct TestFlags64 {
30    #[bits(1)]
31    pub expected_failure: bool,
32    #[bits(1)]
33    pub linux_only: bool,
34    #[bits(62)]
35    reserved: u64,
36}
37
38/// A 64-bit TMK test descriptor.
39#[repr(C)]
40#[derive(IntoBytes, FromBytes, Immutable)]
41pub struct TestDescriptor64 {
42    /// The address of the test's name.
43    pub name: u64,
44    /// The length of the test's name.
45    pub name_len: u64,
46    /// The test entry point.
47    pub entrypoint: u64,
48    /// Test metadata flags.
49    pub flags: TestFlags64,
50}
51
52/// TMK command.
53#[repr(u32)]
54#[derive(TryFromBytes)]
55pub enum Command {
56    /// Log a UTF-8 message string.
57    Log(StrDescriptor),
58    /// The test panicked.
59    Panic {
60        /// The panic message.
61        message: StrDescriptor,
62        /// The file and line where the panic occurred.
63        filename: StrDescriptor,
64        /// The line where the panic occurred.
65        line: u32,
66    },
67    /// Complete the test.
68    Complete {
69        /// Success status of the test.
70        success: bool,
71    },
72}
73
74/// A UTF-8 string in guest memory.
75#[repr(C)]
76#[derive(FromBytes)]
77pub struct StrDescriptor {
78    /// Pointer to the string.
79    pub gpa: u64,
80    /// Length of the string.
81    pub len: u64,
82}