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 zerocopy::FromBytes;
10use zerocopy::Immutable;
11use zerocopy::IntoBytes;
12use zerocopy::TryFromBytes;
13
14/// Start input from the VMM to the TMK.
15#[repr(C)]
16#[derive(Debug, IntoBytes, Immutable)]
17pub struct StartInput {
18    /// The address to write commands to.
19    pub command: u64,
20    /// The test index.
21    pub test_index: u64,
22}
23
24/// A 64-bit TMK test descriptor.
25#[repr(C)]
26#[derive(IntoBytes, FromBytes, Immutable)]
27pub struct TestDescriptor64 {
28    /// The address of the test's name.
29    pub name: u64,
30    /// The length of the test's name.
31    pub name_len: u64,
32    /// The test entry point.
33    pub entrypoint: u64,
34}
35
36/// TMK command.
37#[repr(u32)]
38#[derive(TryFromBytes)]
39pub enum Command {
40    /// Log a UTF-8 message string.
41    Log(StrDescriptor),
42    /// The test panicked.
43    Panic {
44        /// The panic message.
45        message: StrDescriptor,
46        /// The file and line where the panic occurred.
47        filename: StrDescriptor,
48        /// The line where the panic occurred.
49        line: u32,
50    },
51    /// Complete the test.
52    Complete {
53        /// Success status of the test.
54        success: bool,
55    },
56}
57
58/// A UTF-8 string in guest memory.
59#[repr(C)]
60#[derive(FromBytes)]
61pub struct StrDescriptor {
62    /// Pointer to the string.
63    pub gpa: u64,
64    /// Length of the string.
65    pub len: u64,
66}