Skip to content

Commit 564933d

Browse files
committed
multiboot2: attempt to use more lifetime magic for miri
Unfortunately, this doesn't enables the from_base_tag in miri.
1 parent e32026b commit 564933d

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

multiboot2/src/lib.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ impl BootInformationInner {
202202
#[repr(transparent)]
203203
pub struct BootInformation<'a>(&'a BootInformationInner);
204204

205-
impl BootInformation<'_> {
205+
impl<'a> BootInformation<'a> {
206206
/// Loads the [`BootInformation`] from a pointer. The pointer must be valid
207207
/// and aligned to an 8-byte boundary, as defined by the spec.
208208
///
@@ -454,10 +454,10 @@ impl BootInformation<'_> {
454454
/// .unwrap();
455455
/// assert_eq!(tag.name(), Ok("name"));
456456
/// ```
457-
pub fn get_tag<TagT: TagTrait + ?Sized, TagType: Into<TagTypeId>>(
458-
&self,
457+
pub fn get_tag<TagT: TagTrait + ?Sized + 'a, TagType: Into<TagTypeId>>(
458+
&'a self,
459459
typ: TagType,
460-
) -> Option<&TagT> {
460+
) -> Option<&'a TagT> {
461461
let typ = typ.into();
462462
self.tags()
463463
.find(|tag| tag.typ == typ)
@@ -553,8 +553,8 @@ pub trait TagTrait: Pointee {
553553
/// sane and the underlying memory valid. The implementation of this trait
554554
/// **must have** a correct [`Self::dst_size`] implementation.
555555
unsafe fn from_base_tag<'a>(tag: &Tag) -> &'a Self {
556-
let ptr = tag as *const _ as *const ();
557-
let ptr = ptr_meta::from_raw_parts(ptr, Self::dst_size(tag));
556+
let ptr = core::ptr::addr_of!(*tag);
557+
let ptr = ptr_meta::from_raw_parts(ptr.cast(), Self::dst_size(tag));
558558
&*ptr
559559
}
560560
}

multiboot2/src/tag_type.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -297,14 +297,15 @@ mod partial_eq_impls {
297297
#[derive(Clone, Copy)]
298298
#[repr(C)]
299299
pub struct Tag {
300-
pub typ: TagTypeId, // u32
300+
// u32
301+
pub typ: TagTypeId,
301302
pub size: u32,
302303
// additional, tag specific fields
303304
}
304305

305306
impl Tag {
306307
/// Casts the base tag to the specific tag type.
307-
pub fn cast_tag<'a, T: TagTrait + ?Sized>(&self) -> &'a T {
308+
pub fn cast_tag<'a, T: TagTrait + ?Sized + 'a>(&'a self) -> &'a T {
308309
// Safety: At this point, we trust that "self.size" and the size hint
309310
// for DST tags are sane.
310311
unsafe { TagTrait::from_base_tag(self) }

0 commit comments

Comments
 (0)