From 085105cbf52842c4adf87f4098c6a3578978c253 Mon Sep 17 00:00:00 2001 From: Akira Moroo Date: Sun, 19 May 2024 03:25:21 +0000 Subject: [PATCH] build: Use `core::mem::offset_of!` Signed-off-by: Akira Moroo --- src/boot.rs | 2 +- src/common.rs | 14 ++------------ src/efi/mod.rs | 2 +- 3 files changed, 4 insertions(+), 14 deletions(-) diff --git a/src/boot.rs b/src/boot.rs index 61ba383e..cf192829 100644 --- a/src/boot.rs +++ b/src/boot.rs @@ -247,6 +247,6 @@ mod tests { assert_eq!(mem::size_of::(), 20); assert_eq!(mem::size_of::(), 4096); - assert_eq!(offset_of!(Params, hdr), HEADER_START); + assert_eq!(core::mem::offset_of!(Params, hdr), HEADER_START); } } diff --git a/src/common.rs b/src/common.rs index 7ece6304..056131db 100644 --- a/src/common.rs +++ b/src/common.rs @@ -1,27 +1,17 @@ // SPDX-License-Identifier: Apache-2.0 // Copyright © 2019 Intel Corporation -#[macro_export] -macro_rules! offset_of { - ($container:ty, $field:ident) => { - #[allow(deref_nullptr)] - unsafe { - &(*(core::ptr::null() as *const $container)).$field as *const _ as usize - } - }; -} - #[macro_export] macro_rules! container_of { ($ptr:ident, $container:ty, $field:ident) => {{ - (($ptr as usize) - offset_of!($container, $field)) as *const $container + (($ptr as usize) - core::mem::offset_of!($container, $field)) as *const $container }}; } #[macro_export] macro_rules! container_of_mut { ($ptr:ident, $container:ty, $field:ident) => {{ - (($ptr as usize) - offset_of!($container, $field)) as *mut $container + (($ptr as usize) - core::mem::offset_of!($container, $field)) as *mut $container }}; } diff --git a/src/efi/mod.rs b/src/efi/mod.rs index 59b54d0f..52dcbb2c 100644 --- a/src/efi/mod.rs +++ b/src/efi/mod.rs @@ -4,7 +4,7 @@ use core::{ cell::SyncUnsafeCell, ffi::c_void, - mem::{size_of, transmute}, + mem::{offset_of, size_of, transmute}, ptr::null_mut, slice::from_raw_parts, };