Skip to content

Commit 085105c

Browse files
committed
build: Use core::mem::offset_of!
Signed-off-by: Akira Moroo <retrage01@gmail.com>
1 parent 97de41f commit 085105c

File tree

3 files changed

+4
-14
lines changed

3 files changed

+4
-14
lines changed

src/boot.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,6 @@ mod tests {
247247
assert_eq!(mem::size_of::<E820Entry>(), 20);
248248
assert_eq!(mem::size_of::<Params>(), 4096);
249249

250-
assert_eq!(offset_of!(Params, hdr), HEADER_START);
250+
assert_eq!(core::mem::offset_of!(Params, hdr), HEADER_START);
251251
}
252252
}

src/common.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,17 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// Copyright © 2019 Intel Corporation
33

4-
#[macro_export]
5-
macro_rules! offset_of {
6-
($container:ty, $field:ident) => {
7-
#[allow(deref_nullptr)]
8-
unsafe {
9-
&(*(core::ptr::null() as *const $container)).$field as *const _ as usize
10-
}
11-
};
12-
}
13-
144
#[macro_export]
155
macro_rules! container_of {
166
($ptr:ident, $container:ty, $field:ident) => {{
17-
(($ptr as usize) - offset_of!($container, $field)) as *const $container
7+
(($ptr as usize) - core::mem::offset_of!($container, $field)) as *const $container
188
}};
199
}
2010

2111
#[macro_export]
2212
macro_rules! container_of_mut {
2313
($ptr:ident, $container:ty, $field:ident) => {{
24-
(($ptr as usize) - offset_of!($container, $field)) as *mut $container
14+
(($ptr as usize) - core::mem::offset_of!($container, $field)) as *mut $container
2515
}};
2616
}
2717

src/efi/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use core::{
55
cell::SyncUnsafeCell,
66
ffi::c_void,
7-
mem::{size_of, transmute},
7+
mem::{offset_of, size_of, transmute},
88
ptr::null_mut,
99
slice::from_raw_parts,
1010
};

0 commit comments

Comments
 (0)