Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion uefi-raw/src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pub enum Status: usize => {

impl Status {
/// Bit indicating that an UEFI status code is an error.
pub const ERROR_BIT: usize = 1 << (core::mem::size_of::<usize>() * 8 - 1);
pub const ERROR_BIT: usize = 1 << (usize::BITS - 1);

/// Returns true if status code indicates success.
#[inline]
Expand Down
4 changes: 2 additions & 2 deletions uefi-raw/src/table/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::table::configuration::ConfigurationTable;
use crate::table::runtime::RuntimeServices;
use crate::table::Header;
use crate::{Char16, Handle};
use core::{mem, ptr};
use core::ptr;

#[derive(Clone, Debug, Eq, PartialEq)]
#[repr(C)]
Expand Down Expand Up @@ -44,7 +44,7 @@ impl Default for SystemTable {
Self {
header: Header {
signature: Self::SIGNATURE,
size: u32::try_from(mem::size_of::<Self>()).unwrap(),
size: u32::try_from(size_of::<Self>()).unwrap(),
..Header::default()
},

Expand Down
3 changes: 1 addition & 2 deletions uefi-test-runner/examples/sierpinski.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ extern crate alloc;

use alloc::vec;
use alloc::vec::Vec;
use core::mem;
use uefi::prelude::*;
use uefi::proto::console::gop::{BltOp, BltPixel, BltRegion, GraphicsOutput};
use uefi::proto::rng::Rng;
Expand Down Expand Up @@ -77,7 +76,7 @@ impl Buffer {

/// Get a random `usize` value.
fn get_random_usize(rng: &mut Rng) -> usize {
let mut buf = [0; mem::size_of::<usize>()];
let mut buf = [0; size_of::<usize>()];
rng.get_rng(None, &mut buf).expect("get_rng failed");
usize::from_le_bytes(buf)
}
Expand Down
13 changes: 5 additions & 8 deletions uefi-test-runner/src/boot/misc.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use core::ffi::c_void;
use core::mem;
use core::ptr::{self, NonNull};

use uefi::boot::{
Expand Down Expand Up @@ -121,13 +120,11 @@ fn test_register_protocol_notify() {
fn test_install_protocol_interface() {
info!("Installing TestProtocol");

let alloc: *mut TestProtocol = boot::allocate_pool(
MemoryType::BOOT_SERVICES_DATA,
mem::size_of::<TestProtocol>(),
)
.unwrap()
.cast()
.as_ptr();
let alloc: *mut TestProtocol =
boot::allocate_pool(MemoryType::BOOT_SERVICES_DATA, size_of::<TestProtocol>())
.unwrap()
.cast()
.as_ptr();
unsafe { alloc.write(TestProtocol { data: 123 }) };

let _ = unsafe {
Expand Down
6 changes: 3 additions & 3 deletions uefi/src/boot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ pub(crate) fn get_memory_map(buf: &mut [u8]) -> Result<MemoryMapMeta> {
let mut desc_version = 0;

assert_eq!(
(map_buffer as usize) % mem::align_of::<MemoryDescriptor>(),
(map_buffer as usize) % align_of::<MemoryDescriptor>(),
0,
"Memory map buffers must be aligned like a MemoryDescriptor"
);
Expand Down Expand Up @@ -793,11 +793,11 @@ pub fn locate_handle<'buf>(
SearchType::ByProtocol(guid) => (2, ptr::from_ref(guid), ptr::null()),
};

let mut buffer_size = buffer.len() * mem::size_of::<Handle>();
let mut buffer_size = buffer.len() * size_of::<Handle>();
let status =
unsafe { (bt.locate_handle)(ty, guid, key, &mut buffer_size, buffer.as_mut_ptr().cast()) };

let num_handles = buffer_size / mem::size_of::<Handle>();
let num_handles = buffer_size / size_of::<Handle>();

match status {
Status::SUCCESS => {
Expand Down
4 changes: 2 additions & 2 deletions uefi/src/data_types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ impl Event {
/// Trait for querying the alignment of a struct.
///
/// For a statically-sized type the alignment can be retrieved with
/// [`core::mem::align_of`]. For a dynamically-sized type (DST),
/// [`core::mem::align_of_val`] provides the alignment given a reference. But in
/// [`align_of`]. For a dynamically-sized type (DST),
/// [`align_of_val`] provides the alignment given a reference. But in
/// some cases it's helpful to know the alignment of a DST prior to having a
/// value, meaning there's no reference to pass to `align_of_val`. For example,
/// when using an API that creates a value using a `[u8]` buffer, the alignment
Expand Down
10 changes: 5 additions & 5 deletions uefi/src/mem/memory_map/impl_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use super::*;
use crate::boot;
use core::fmt::{Debug, Display, Formatter};
use core::ops::{Index, IndexMut};
use core::ptr;
use core::ptr::NonNull;
use core::{mem, ptr};
use uefi_raw::PhysicalAddress;

/// Errors that may happen when constructing a [`MemoryMapRef`] or
Expand Down Expand Up @@ -284,7 +284,7 @@ impl MemoryMapBackingMemory {

// Should be fine as UEFI always has allocations with a guaranteed
// alignment of 8 bytes.
assert_eq!(ptr.align_offset(mem::align_of::<MemoryDescriptor>()), 0);
assert_eq!(ptr.align_offset(align_of::<MemoryDescriptor>()), 0);

// If this panics, the UEFI implementation is broken.
assert_eq!(memory_map_meta.map_size % memory_map_meta.desc_size, 0);
Expand All @@ -293,7 +293,7 @@ impl MemoryMapBackingMemory {
}

unsafe fn from_raw(ptr: *mut u8, len: usize) -> Self {
assert_eq!(ptr.align_offset(mem::align_of::<MemoryDescriptor>()), 0);
assert_eq!(ptr.align_offset(align_of::<MemoryDescriptor>()), 0);

let ptr = NonNull::new(ptr).expect("UEFI should never return a null ptr. An error should have been reflected via an Err earlier.");
let slice = NonNull::slice_from_raw_parts(ptr, len);
Expand Down Expand Up @@ -367,7 +367,7 @@ impl MemoryMapOwned {
/// (stored inside the provided buffer) and the corresponding
/// [`MemoryMapMeta`].
pub(crate) fn from_initialized_mem(buf: MemoryMapBackingMemory, meta: MemoryMapMeta) -> Self {
assert!(meta.desc_size >= mem::size_of::<MemoryDescriptor>());
assert!(meta.desc_size >= size_of::<MemoryDescriptor>());
let len = meta.entry_count();
Self { buf, meta, len }
}
Expand Down Expand Up @@ -431,7 +431,7 @@ impl IndexMut<usize> for MemoryMapOwned {
mod tests {
use super::*;
use alloc::vec::Vec;
use core::mem::size_of;
use size_of;

const BASE_MMAP_UNSORTED: [MemoryDescriptor; 3] = [
MemoryDescriptor {
Expand Down
7 changes: 3 additions & 4 deletions uefi/src/mem/memory_map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ pub use iter::*;
pub use uefi_raw::table::boot::{MemoryAttribute, MemoryDescriptor, MemoryType};

use crate::data_types::Align;
use core::mem;

impl Align for MemoryDescriptor {
fn alignment() -> usize {
mem::align_of::<Self>()
align_of::<Self>()
}
}

Expand Down Expand Up @@ -90,7 +89,7 @@ impl MemoryMapMeta {
// extended by a future UEFI revision by a significant amount, we
// update the struct, but an old UEFI implementation reports a small
// size.
assert!(self.desc_size >= mem::size_of::<MemoryDescriptor>());
assert!(self.desc_size >= size_of::<MemoryDescriptor>());
assert!(self.map_size > 0);

// Ensure the mmap size is (somehow) sane.
Expand Down Expand Up @@ -238,8 +237,8 @@ mod tests_mmap_artificial {
mod tests_mmap_real {
use super::*;
use alloc::vec::Vec;
use core::mem::size_of;
use core::slice;
use size_of;

const MMAP_META: MemoryMapMeta = MemoryMapMeta {
map_size: MMAP_RAW.len() * size_of::<u64>(),
Expand Down
9 changes: 4 additions & 5 deletions uefi/src/proto/console/gop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ use crate::util::usize_from_u32;
use crate::{boot, Result, StatusExt};
use core::fmt::{Debug, Formatter};
use core::marker::PhantomData;
use core::mem;
use core::ptr::{self, NonNull};
use uefi_raw::protocol::console::{
GraphicsOutputBltOperation, GraphicsOutputModeInformation, GraphicsOutputProtocol,
Expand Down Expand Up @@ -181,7 +180,7 @@ impl GraphicsOutput {
dest_y,
width,
height,
px_stride * core::mem::size_of::<BltPixel>(),
px_stride * size_of::<BltPixel>(),
)
.to_result(),
}
Expand Down Expand Up @@ -221,7 +220,7 @@ impl GraphicsOutput {
dest_y,
width,
height,
px_stride * core::mem::size_of::<BltPixel>(),
px_stride * size_of::<BltPixel>(),
)
.to_result(),
}
Expand Down Expand Up @@ -620,7 +619,7 @@ impl FrameBuffer<'_> {
#[inline]
pub unsafe fn write_value<T>(&mut self, index: usize, value: T) {
debug_assert!(
index.saturating_add(mem::size_of::<T>()) <= self.size,
index.saturating_add(size_of::<T>()) <= self.size,
"Frame buffer accessed out of bounds"
);
let ptr = self.base.add(index).cast::<T>();
Expand All @@ -643,7 +642,7 @@ impl FrameBuffer<'_> {
#[must_use]
pub unsafe fn read_value<T>(&self, index: usize) -> T {
debug_assert!(
index.saturating_add(mem::size_of::<T>()) <= self.size,
index.saturating_add(size_of::<T>()) <= self.size,
"Frame buffer accessed out of bounds"
);
(self.base.add(index) as *const T).read_volatile()
Expand Down
4 changes: 2 additions & 2 deletions uefi/src/proto/device_path/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,10 @@ mod tests {
use crate::proto::device_path::messaging::{
Ipv4AddressOrigin, IscsiLoginOptions, IscsiProtocol, RestServiceAccessMode, RestServiceType,
};
use core::{mem, slice};
use core::slice;

fn path_to_bytes(path: &DevicePath) -> &[u8] {
unsafe { slice::from_raw_parts(path.as_ffi_ptr().cast::<u8>(), mem::size_of_val(path)) }
unsafe { slice::from_raw_parts(path.as_ffi_ptr().cast::<u8>(), size_of_val(path)) }
}

/// Test building an ACPI ADR node.
Expand Down
22 changes: 11 additions & 11 deletions uefi/src/proto/device_path/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ pub use uefi_raw::protocol::device_path::{DeviceSubType, DeviceType};
use crate::proto::{unsafe_protocol, ProtocolPointer};
use core::ffi::c_void;
use core::fmt::{self, Debug, Display, Formatter};
use core::mem;
use core::ops::Deref;
use ptr_meta::Pointee;

Expand All @@ -96,6 +95,7 @@ use {
crate::{CString16, Identify},
alloc::borrow::ToOwned,
alloc::boxed::Box,
core::mem,
};

opaque_type! {
Expand All @@ -122,7 +122,7 @@ impl<'a> TryFrom<&'a [u8]> for &'a DevicePathHeader {
type Error = ByteConversionError;

fn try_from(bytes: &[u8]) -> Result<Self, Self::Error> {
if mem::size_of::<DevicePathHeader>() <= bytes.len() {
if size_of::<DevicePathHeader>() <= bytes.len() {
unsafe { Ok(&*bytes.as_ptr().cast::<DevicePathHeader>()) }
} else {
Err(ByteConversionError::InvalidLength)
Expand Down Expand Up @@ -173,7 +173,7 @@ impl DevicePathNode {
pub unsafe fn from_ffi_ptr<'a>(ptr: *const FfiDevicePath) -> &'a Self {
let header = *ptr.cast::<DevicePathHeader>();

let data_len = usize::from(header.length) - mem::size_of::<DevicePathHeader>();
let data_len = usize::from(header.length) - size_of::<DevicePathHeader>();
&*ptr_meta::from_raw_parts(ptr.cast(), data_len)
}

Expand Down Expand Up @@ -748,7 +748,7 @@ mod tests {
path.push(device_type);
path.push(sub_type);
path.extend(
u16::try_from(mem::size_of::<DevicePathHeader>() + node_data.len())
u16::try_from(size_of::<DevicePathHeader>() + node_data.len())
.unwrap()
.to_le_bytes(),
);
Expand Down Expand Up @@ -787,7 +787,7 @@ mod tests {
assert_eq!(node.sub_type().0, sub_type);
assert_eq!(
node.length(),
u16::try_from(mem::size_of::<DevicePathHeader>() + node_data.len()).unwrap()
u16::try_from(size_of::<DevicePathHeader>() + node_data.len()).unwrap()
);
assert_eq!(&node.data, node_data);
}
Expand All @@ -798,7 +798,7 @@ mod tests {
let dp = unsafe { DevicePath::from_ffi_ptr(raw_data.as_ptr().cast()) };

// Check that the size is the sum of the nodes' lengths.
assert_eq!(mem::size_of_val(dp), 6 + 8 + 4 + 6 + 8 + 4);
assert_eq!(size_of_val(dp), 6 + 8 + 4 + 6 + 8 + 4);

// Check the list's node iter.
let nodes: Vec<_> = dp.node_iter().collect();
Expand All @@ -824,7 +824,7 @@ mod tests {
// Check the list's instance iter.
let mut iter = dp.instance_iter();
let mut instance = iter.next().unwrap();
assert_eq!(mem::size_of_val(instance), 6 + 8 + 4);
assert_eq!(size_of_val(instance), 6 + 8 + 4);

// Check the first instance's node iter.
let nodes: Vec<_> = instance.node_iter().collect();
Expand All @@ -835,7 +835,7 @@ mod tests {

// Check second instance.
instance = iter.next().unwrap();
assert_eq!(mem::size_of_val(instance), 6 + 8 + 4);
assert_eq!(size_of_val(instance), 6 + 8 + 4);

let nodes: Vec<_> = instance.node_iter().collect();
check_node(nodes[0], 0xa2, 0xb2, &[30, 31]);
Expand Down Expand Up @@ -876,15 +876,15 @@ mod tests {
// Raw data is long enough to hold a [`DevicePathNode`].
raw_data.push(node[1]);
raw_data.extend(
u16::try_from(mem::size_of::<DevicePathHeader>() + node_data.len())
u16::try_from(size_of::<DevicePathHeader>() + node_data.len())
.unwrap()
.to_le_bytes(),
);
raw_data.extend(node_data);
let dp = <&DevicePathNode>::try_from(raw_data.as_slice()).unwrap();

// Relevant assertions to verify the conversion is fine.
assert_eq!(mem::size_of_val(dp), 6);
assert_eq!(size_of_val(dp), 6);
check_node(dp, 0xa0, 0xb0, &[10, 11]);

// [`DevicePathNode`] data length exceeds the raw_data slice.
Expand All @@ -898,7 +898,7 @@ mod tests {
let dp = <&DevicePath>::try_from(raw_data.as_slice()).unwrap();

// Check that the size is the sum of the nodes' lengths.
assert_eq!(mem::size_of_val(dp), 6 + 8 + 4 + 6 + 8 + 4);
assert_eq!(size_of_val(dp), 6 + 8 + 4 + 6 + 8 + 4);

// Check the list's node iter.
let nodes: Vec<_> = dp.node_iter().collect();
Expand Down
6 changes: 3 additions & 3 deletions uefi/src/proto/loaded_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ impl LoadedImage {

if self.0.load_options.is_null() {
Err(LoadOptionsError::NotSet)
} else if (load_options_size % mem::size_of::<u16>() != 0)
|| (((self.0.load_options as usize) % mem::align_of::<u16>()) != 0)
} else if (load_options_size % size_of::<u16>() != 0)
|| (((self.0.load_options as usize) % align_of::<u16>()) != 0)
{
Err(LoadOptionsError::NotAligned)
} else {
let s = unsafe {
slice::from_raw_parts(
self.0.load_options.cast::<u16>(),
load_options_size / mem::size_of::<u16>(),
load_options_size / size_of::<u16>(),
)
};
CStr16::from_u16_with_nul(s).map_err(LoadOptionsError::InvalidString)
Expand Down
Loading
Loading