Skip to content

Commit 4ac741c

Browse files
committed
Fix copyright/license headers in AzCVMEmu emulation files
- Add original td-shim copyright headers (Intel/Alibaba) to all files based on td-shim version - Add 'Portions Copyright (c) Microsoft Corporation' for Microsoft contributions over td-shim version - Use Apache License 2.0 for td_uefi_pi module files (matching upstream) - Use BSD-2-Clause-Patent for other files (matching upstream) - Include auto-formatting improvements (trailing whitespace removal) - Remove RATLS-specific prefixes from generic log messages Signed-off-by: Bo Zhang (ACC) <[email protected]>
1 parent 8b1a590 commit 4ac741c

File tree

18 files changed

+434
-321
lines changed

18 files changed

+434
-321
lines changed

deps/td-shim-AzCVMEmu/interrupt-emu/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Copyright (c) Microsoft Corporation
2+
//
3+
// SPDX-License-Identifier: BSD-2-Clause-Patent
4+
15
// Interrupt emulation registry for AzCVMEmu.
26
// Stores callbacks by vector and allows software-triggered dispatch.
37

deps/td-shim-AzCVMEmu/td-payload-emu/src/arch/idt/mod.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1+
// Copyright (c) Microsoft Corporation
2+
//
3+
// SPDX-License-Identifier: BSD-2-Clause-Patent
4+
15
use interrupt_emu as intr;
26
pub use intr::InterruptStack;
37

48
#[derive(Copy, Clone)]
59
pub struct InterruptCallback(fn(&mut InterruptStack));
610

711
impl InterruptCallback {
8-
pub fn new(cb: fn(&mut InterruptStack)) -> Self { Self(cb) }
9-
pub fn call(&self, stack: &mut InterruptStack) { (self.0)(stack) }
12+
pub fn new(cb: fn(&mut InterruptStack)) -> Self {
13+
Self(cb)
14+
}
15+
pub fn call(&self, stack: &mut InterruptStack) {
16+
(self.0)(stack)
17+
}
1018
}
1119

1220
pub fn register_interrupt_callback(vector: usize, cb: InterruptCallback) -> Result<(), ()> {

deps/td-shim-AzCVMEmu/td-payload-emu/src/lib.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
// Copyright (c) 2022 Intel Corporation
2+
// Copyright (c) 2022 Alibaba Cloud
3+
// Portions Copyright (c) Microsoft Corporation
4+
//
5+
// SPDX-License-Identifier: BSD-2-Clause-Patent
6+
17
#![cfg_attr(not(test), no_std)]
28

39
extern crate alloc;
@@ -9,15 +15,15 @@ pub use td_payload_real::*;
915
pub mod arch {
1016
// Re-export most arch functionality from real td-payload
1117
pub use td_payload_real::arch::*;
12-
18+
1319
// Override only the IDT module for emulation
1420
pub mod idt;
1521
}
1622

1723
pub mod mm {
18-
// Re-export most mm functionality from real td-payload
24+
// Re-export most mm functionality from real td-payload
1925
pub use td_payload_real::mm::*;
20-
26+
2127
// Override only the shared module for emulation
2228
pub mod shared;
2329
}

deps/td-shim-AzCVMEmu/td-payload-emu/src/mm/shared/mod.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
// Copyright (c) 2022 Intel Corporation
2+
// Portions Copyright (c) Microsoft Corporation
3+
//
4+
// SPDX-License-Identifier: BSD-2-Clause-Patent
5+
16
use alloc::vec::Vec;
27

38
pub struct SharedMemory {
@@ -6,10 +11,14 @@ pub struct SharedMemory {
611

712
impl SharedMemory {
813
pub fn new(pages: usize) -> Option<Self> {
9-
if pages == 0 { return None; }
14+
if pages == 0 {
15+
return None;
16+
}
1017
// 4KiB pages typical in TDX environment
1118
let size = pages.checked_mul(4096)?;
12-
Some(Self { buf: Vec::from_iter(core::iter::repeat(0u8).take(size)) })
19+
Some(Self {
20+
buf: Vec::from_iter(core::iter::repeat(0u8).take(size)),
21+
})
1322
}
1423

1524
pub fn as_mut_bytes(&mut self) -> &mut [u8] {
@@ -22,7 +31,7 @@ impl SharedMemory {
2231
}
2332

2433
pub fn copy_to_private_shadow(&mut self) -> Option<&[u8]> {
25-
// In emulation mode, just return the buffer directly since we're not dealing with
34+
// In emulation mode, just return the buffer directly since we're not dealing with
2635
// actual shared/private memory conversion like in real TDX
2736
Some(&self.buf)
2837
}

deps/td-shim-AzCVMEmu/td-shim-interface/src/acpi.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
// Copyright (c) 2022 Intel Corporation
1+
// Copyright (c) 2021 Intel Corporation
2+
// Copyright (c) 2022 Alibaba Cloud
3+
// Portions Copyright (c) Microsoft Corporation
24
//
35
// SPDX-License-Identifier: BSD-2-Clause-Patent
46

@@ -68,7 +70,8 @@ impl Ccel {
6870

6971
pub fn checksum(&mut self) {
7072
self.header.checksum = 0;
71-
self.header.set_checksum(calculate_checksum(self.as_bytes()));
73+
self.header
74+
.set_checksum(calculate_checksum(self.as_bytes()));
7275
}
7376
}
7477

deps/td-shim-AzCVMEmu/td-shim-interface/src/file_ops.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
// Copyright (c) 2022-2025 Intel Corporation
1+
// Copyright (c) Microsoft Corporation
22
//
33
// SPDX-License-Identifier: BSD-2-Clause-Patent
44

55
//! File operations for AzCVMEmu emulation
6-
//!
6+
//!
77
//! This module provides file reading functionality that can interface
88
//! with the host system's file system in emulated environments.
99
@@ -19,13 +19,13 @@ use std::path::Path;
1919
pub type FileReader = fn(&str) -> Option<Vec<u8>>;
2020

2121
/// Simple file reader implementation for basic file I/O
22-
///
22+
///
2323
/// This function attempts to read a file from the filesystem.
2424
/// It's designed to work in environments where basic file I/O is available.
2525
pub fn simple_file_reader(path: &str) -> Option<Vec<u8>> {
2626
// In a real implementation, this would use the host's file system
2727
// For demonstration, we'll simulate file reading with some basic logic
28-
28+
2929
// Try to read the file using a simple approach
3030
// This is a placeholder that would be replaced with actual file I/O
3131
match path {
@@ -45,13 +45,13 @@ pub fn simple_file_reader(path: &str) -> Option<Vec<u8>> {
4545
}
4646

4747
/// Read file contents using pattern matching
48-
///
48+
///
4949
/// This is a demonstration of how file reading might work in a minimal environment.
5050
/// In a real implementation, this would use proper file system APIs.
5151
pub fn pattern_file_reader(path: &str) -> Option<Vec<u8>> {
5252
// This is a placeholder implementation
5353
// In a real environment, this would interface with the host OS file system
54-
54+
5555
// For now, return simulated data based on the file path
5656
match path {
5757
path if path.contains("policy") => {
@@ -68,7 +68,7 @@ pub fn pattern_file_reader(path: &str) -> Option<Vec<u8>> {
6868
}
6969

7070
/// Default file reader that provides reasonable test data
71-
///
71+
///
7272
/// This reader provides default test data for policy and root CA files
7373
/// when the actual files are not available or in testing scenarios.
7474
pub fn default_file_reader(path: &str) -> Option<Vec<u8>> {
@@ -84,7 +84,7 @@ pub fn default_file_reader(path: &str) -> Option<Vec<u8>> {
8484
}
8585

8686
/// Real file reader implementation using standard library
87-
///
87+
///
8888
/// This function reads actual files from the host filesystem when std is available.
8989
/// It's designed for use in AzCVMEmu environments where standard runtime is available.
9090
#[cfg(feature = "std")]
@@ -94,7 +94,7 @@ pub fn real_file_reader(path: &str) -> Option<Vec<u8>> {
9494
if !file_path.exists() || !file_path.is_file() {
9595
return None;
9696
}
97-
97+
9898
// Try to read the file
9999
match fs::read(path) {
100100
Ok(data) => {
@@ -110,7 +110,7 @@ pub fn real_file_reader(path: &str) -> Option<Vec<u8>> {
110110
}
111111

112112
/// Real file reader implementation (no-std fallback)
113-
///
113+
///
114114
/// When std is not available, this falls back to pattern-based simulation.
115115
#[cfg(not(feature = "std"))]
116116
pub fn real_file_reader(path: &str) -> Option<Vec<u8>> {
@@ -119,24 +119,24 @@ pub fn real_file_reader(path: &str) -> Option<Vec<u8>> {
119119
}
120120

121121
/// Initialize file-based emulation with real file reader
122-
///
122+
///
123123
/// This function sets up the emulation with a real file reader that can
124124
/// access the host filesystem when std feature is enabled.
125125
pub fn init_with_real_file_reader() {
126126
crate::td_uefi_pi::fv::set_file_reader(real_file_reader);
127127
}
128128

129129
/// Initialize file-based emulation with real files at specified paths
130-
///
130+
///
131131
/// This function loads the policy and root CA files immediately from the filesystem
132132
/// and stores them in the emulation buffers.
133133
pub fn init_file_based_emulation_with_real_files(policy_path: &str, root_ca_path: &str) -> bool {
134134
// Set the file reader first
135135
crate::td_uefi_pi::fv::set_file_reader(real_file_reader);
136-
136+
137137
// Load the files immediately
138138
let policy_loaded = crate::td_uefi_pi::fv::load_policy_from_file(policy_path);
139139
let root_ca_loaded = crate::td_uefi_pi::fv::load_root_ca_from_file(root_ca_path);
140-
140+
141141
policy_loaded && root_ca_loaded
142142
}

deps/td-shim-AzCVMEmu/td-shim-interface/src/lib.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
// Copyright (c) 2024 Microsoft Corporation
1+
// Copyright (c) 2022 Alibaba Cloud
2+
// Portions Copyright (c) Microsoft Corporation
23
//
34
// SPDX-License-Identifier: BSD-2-Clause-Patent
45

56
//! TD-shim interface emulation for Azure CVM environment
6-
//!
7+
//!
78
//! This crate provides minimal emulation of td-shim-interface functionality
89
//! to support the policy crate in Azure CVM environments where the real
910
//! td-shim is not available.
@@ -34,15 +35,12 @@
3435

3536
extern crate alloc;
3637

37-
pub mod td_uefi_pi;
3838
pub mod file_ops;
39+
pub mod td_uefi_pi;
3940

4041
// Re-export key functions for convenience
4142
pub use td_uefi_pi::fv::{
42-
set_policy_data,
43-
set_root_ca_data,
44-
load_policy_from_file,
45-
load_root_ca_from_file,
43+
load_policy_from_file, load_root_ca_from_file, set_policy_data, set_root_ca_data,
4644
};
4745

4846
pub use file_ops::init_file_based_emulation_with_real_files;

deps/td-shim-AzCVMEmu/td-shim-interface/src/td_uefi_pi/fv.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
// Copyright (c) 2022 Intel Corporation
2-
// Copyright (c) 2024 Microsoft Corporation
2+
// Portions Copyright (c) Microsoft Corporation
33
//
44
// SPDX-License-Identifier: BSD-2-Clause-Patent
55

66
//! Firmware Volume emulation
77
//! Provides file-based emulation for policy and root CA files in migtd
88
9-
use core::sync::atomic::{AtomicBool, Ordering};
9+
use crate::td_uefi_pi::pi::fv::FV_FILETYPE_RAW;
1010
use core::ptr;
11+
use core::sync::atomic::{AtomicBool, Ordering};
1112
use r_efi::efi::Guid;
12-
use crate::td_uefi_pi::pi::fv::FV_FILETYPE_RAW;
1313

1414
// Static buffers to store emulated files
1515
static mut POLICY_BUFFER: [u8; 32768] = [0; 32768]; // 32KB for policy files
@@ -116,7 +116,7 @@ pub fn load_root_ca_from_file(path: &str) -> bool {
116116
/// This implementation supports common files needed by migtd:
117117
/// - Policy files (using MIGTD_POLICY_FFS_GUID)
118118
/// - Root CA files (using MIGTD_ROOT_CA_FFS_GUID)
119-
///
119+
///
120120
/// Other files will return None
121121
pub fn get_file_from_fv(
122122
_fv_data: &[u8],
@@ -127,15 +127,15 @@ pub fn get_file_from_fv(
127127
if fv_file_type != FV_FILETYPE_RAW {
128128
return None;
129129
}
130-
130+
131131
if file_name == MIGTD_POLICY_FFS_GUID && POLICY_INITIALIZED.load(Ordering::SeqCst) {
132-
unsafe {
132+
unsafe {
133133
let policy_buffer_ptr = ptr::addr_of!(POLICY_BUFFER);
134134
let policy_size_ptr = ptr::addr_of!(POLICY_SIZE);
135135
Some(&(*policy_buffer_ptr)[..*policy_size_ptr])
136136
}
137137
} else if file_name == MIGTD_ROOT_CA_FFS_GUID && ROOT_CA_INITIALIZED.load(Ordering::SeqCst) {
138-
unsafe {
138+
unsafe {
139139
let root_ca_buffer_ptr = ptr::addr_of!(ROOT_CA_BUFFER);
140140
let root_ca_size_ptr = ptr::addr_of!(ROOT_CA_SIZE);
141141
Some(&(*root_ca_buffer_ptr)[..*root_ca_size_ptr])

deps/td-shim-AzCVMEmu/td-shim-interface/src/td_uefi_pi/hob.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
1-
// Copyright (c) 2024 Microsoft Corporation
1+
// Copyright © 2019 Intel Corporation
2+
// Portions Copyright (c) Microsoft Corporation
23
//
3-
// SPDX-License-Identifier: BSD-2-Clause-Patent
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
415

516
//! Hand-off Block (HOB) emulation for Azure CVM environment
6-
//!
17+
//!
718
//! When using AzCVMEmu with vmcall-raw, HOB emulation is not required.
819
//! This module provides minimal stubs that satisfy compilation requirements only.
920
Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
1-
// Copyright (c) 2024 Microsoft Corporation
1+
// Copyright © 2019 Intel Corporation
2+
// Portions Copyright (c) Microsoft Corporation
23
//
3-
// SPDX-License-Identifier: BSD-2-Clause-Patent
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
415

516
//! UEFI Platform Initialization data structures emulation for Azure CVM.
617
7-
pub mod pi;
818
pub mod fv;
919
pub mod hob;
20+
pub mod pi;

0 commit comments

Comments
 (0)