Skip to content

Commit 8e725f4

Browse files
author
Alexandra Iordache
committed
add x86_64 and aarch64 modules
Phase 2 of code reorganization: separate x86_64 from aarch64 functionality in modules. Signed-off-by: Alexandra Iordache <aghecen@amazon.com>
1 parent 16767d4 commit 8e725f4

File tree

13 files changed

+52
-19
lines changed

13 files changed

+52
-19
lines changed

coverage_config_aarch64.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"coverage_score": 70.9,
2+
"coverage_score": 74.1,
33
"exclude_path": "",
44
"crate_features": ""
55
}

coverage_config_x86_64.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"coverage_score": 76.3,
2+
"coverage_score": 74,
33
"exclude_path": "",
44
"crate_features": ""
55
}

src/loader/aarch64/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright (c) 2019 Intel Corporation. All rights reserved.
2+
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
//
4+
// Copyright 2017 The Chromium OS Authors. All rights reserved.
5+
// Use of this source code is governed by a BSD-style license that can be
6+
// found in the LICENSE-BSD-3-Clause file.
7+
//
8+
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause
9+
10+
//! Traits and structs for loading `aarch64` kernels into guest memory.
11+
12+
#![cfg(target_arch = "aarch64")]

src/loader/mod.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//
1010
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause
1111

12-
//! Traits and Structs
12+
//! Traits and Structs for loading kernels into guest memory.
1313
//! - [KernelLoader](trait.KernelLoader.html): load kernel image into guest memory
1414
//! - [KernelLoaderResult](struct.KernelLoaderResult.html): the structure which loader
1515
//! returns to VMM to assist zero page construction and boot environment setup
@@ -33,23 +33,24 @@ use vm_memory::{Address, Bytes, GuestAddress, GuestMemory, GuestUsize};
3333
#[cfg_attr(feature = "cargo-clippy", allow(clippy::all))]
3434
pub mod bootparam;
3535

36-
#[cfg(all(feature = "elf", any(target_arch = "x86", target_arch = "x86_64")))]
37-
pub mod elf;
38-
39-
#[cfg(all(feature = "bzimage", any(target_arch = "x86", target_arch = "x86_64")))]
40-
pub mod bzimage;
41-
36+
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
4237
mod struct_util;
4338

44-
#[cfg(all(feature = "elf", any(target_arch = "x86", target_arch = "x86_64")))]
45-
pub use elf::Elf;
46-
#[cfg(all(feature = "elf", any(target_arch = "x86", target_arch = "x86_64")))]
47-
pub use elf::Error as ElfError;
39+
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
40+
mod x86_64;
41+
42+
#[cfg(target_arch = "aarch64")]
43+
mod aarch64;
4844

4945
#[cfg(all(feature = "bzimage", any(target_arch = "x86", target_arch = "x86_64")))]
50-
pub use bzimage::BzImage;
46+
pub use x86_64::bzimage::BzImage;
5147
#[cfg(all(feature = "bzimage", any(target_arch = "x86", target_arch = "x86_64")))]
52-
pub use bzimage::Error as BzImageError;
48+
pub use x86_64::bzimage::Error as BzImageError;
49+
50+
#[cfg(all(feature = "elf", any(target_arch = "x86", target_arch = "x86_64")))]
51+
pub use x86_64::elf::Elf;
52+
#[cfg(all(feature = "elf", any(target_arch = "x86", target_arch = "x86_64")))]
53+
pub use x86_64::elf::Error as ElfError;
5354

5455
#[derive(Debug, PartialEq)]
5556
/// Kernel loader errors.

src/loader/bzimage/mod.rs renamed to src/loader/x86_64/bzimage/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use std::io::{Read, Seek, SeekFrom};
1717

1818
use vm_memory::{Address, Bytes, GuestAddress, GuestMemory, GuestUsize};
1919

20-
use super::{
20+
use super::super::{
2121
bootparam, struct_util, Error as KernelLoaderError, KernelLoader, KernelLoaderResult, Result,
2222
};
2323

File renamed without changes.

src/loader/elf/mod.rs renamed to src/loader/x86_64/elf/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ use std::mem;
1818

1919
use vm_memory::{Address, Bytes, GuestAddress, GuestMemory, GuestUsize};
2020

21-
use super::{struct_util, Error as KernelLoaderError, KernelLoader, KernelLoaderResult, Result};
21+
use super::super::{
22+
struct_util, Error as KernelLoaderError, KernelLoader, KernelLoaderResult, Result,
23+
};
2224

2325
#[allow(dead_code)]
2426
#[allow(non_camel_case_types)]
@@ -178,7 +180,7 @@ impl KernelLoader for Elf {
178180

179181
if let Some(addr) = highmem_start_address {
180182
if (ehdr.e_entry as u64) < addr.raw_value() {
181-
Err(Error::InvalidEntryAddress)?;
183+
return Err(Error::InvalidEntryAddress.into());
182184
}
183185
}
184186

@@ -300,7 +302,7 @@ where
300302
// The PVH entry point is a 32-bit address, so the descriptor field
301303
// must be capable of storing all such addresses.
302304
if (nhdr.n_descsz as usize) < mem::size_of::<u32>() {
303-
Err(Error::InvalidPvhNote)?;
305+
return Err(Error::InvalidPvhNote.into());
304306
}
305307

306308
let mut pvh_addr_bytes = [0; mem::size_of::<u32>()];
File renamed without changes.
File renamed without changes.

src/loader/x86_64/mod.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) 2019 Intel Corporation. All rights reserved.
2+
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
//
4+
// Copyright 2017 The Chromium OS Authors. All rights reserved.
5+
// Use of this source code is governed by a BSD-style license that can be
6+
// found in the LICENSE-BSD-3-Clause file.
7+
//
8+
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause
9+
10+
//! Traits and structs for loading `x86_64` kernels into guest memory.
11+
12+
#![cfg(any(target_arch = "x86", target_arch = "x86_64"))]
13+
14+
#[cfg(feature = "elf")]
15+
pub mod elf;
16+
17+
#[cfg(feature = "bzimage")]
18+
pub mod bzimage;

0 commit comments

Comments
 (0)