Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2fea033

Browse files
committed
uefi: allocator: test page-aligned allocation
We can look at the TRACE messages of `cargo xtask run` to verify that the shortcut is taken.
1 parent 79e88d3 commit 2fea033

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

‎uefi-test-runner/src/boot/memory.rs

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,12 @@ mod bootservices {
5858
/// Tests that use [`uefi::allocator::Allocator`], which is configured as the
5959
/// global allocator.
6060
mod global {
61+
use alloc::boxed::Box;
62+
use uefi_raw::table::boot::PAGE_SIZE;
63+
6164
/// Simple test to ensure our custom allocator works with the `alloc` crate.
6265
pub fn alloc_vec() {
63-
info!("Allocating a vector through the `alloc` crate");
66+
info!("Allocating a vector using the global allocator");
6467

6568
#[allow(clippy::useless_vec)]
6669
let mut values = vec![-5, 16, 23, 4, 0];
@@ -71,17 +74,27 @@ mod global {
7174
}
7275

7376
/// Simple test to ensure our custom allocator works with correct alignment.
77+
#[allow(dead_code)] // Ignore warning due to field not being read.
7478
pub fn alloc_alignment() {
75-
info!("Allocating a structure with alignment to 0x100");
76-
77-
#[repr(align(0x100))]
78-
struct Block(
79-
// Ignore warning due to field not being read.
80-
#[allow(dead_code)] [u8; 0x100],
81-
);
79+
{
80+
info!("Allocating a structure with alignment of 0x100 using the global allocator");
81+
#[repr(align(0x100))]
82+
struct Block([u8; 0x100]);
8283

83-
let value = vec![Block([1; 0x100])];
84-
assert_eq!(value.as_ptr() as usize % 0x100, 0, "Wrong alignment");
84+
let value = vec![Block([1; 0x100])];
85+
assert_eq!(value.as_ptr() as usize % 0x100, 0, "Wrong alignment");
86+
}
87+
{
88+
info!("Allocating a memory page ({PAGE_SIZE}) using the global allocator");
89+
#[repr(align(4096))]
90+
struct Page([u8; PAGE_SIZE]);
91+
let value = Box::new(Page([0; PAGE_SIZE]));
92+
assert_eq!(
93+
value.0.as_ptr().align_offset(PAGE_SIZE),
94+
0,
95+
"Wrong alignment"
96+
);
97+
}
8598
}
8699
}
87100

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /