|
120 | 120 | //!
|
121 | 121 | //! ## Rustc Requirements
|
122 | 122 | //!
|
123 |
| -//! The allocation space that Rust requires for types is a multiple of the |
| 123 | +//! The required allocation space that Rust uses for types is a multiple of the |
124 | 124 | //! alignment. This means that if we cast between byte slices and specific
|
125 |
| -//! types, Rust doesn't just see the size reported by the header but also |
126 |
| -//! any necessary padding bytes. If this is not the case, for example we |
127 |
| -//! cast to a structure from a `&[u8; 15]`, Miri will complain as it expects |
128 |
| -//! `&[u8; 16]` |
| 125 | +//! types, Rust doesn't just see the "trimmed down actual payload" defined by |
| 126 | +//! struct members, but also any necessary, but hidden, padding bytes. If we |
| 127 | +//! don't guarantee the correct is not the case, for example we cast the bytes |
| 128 | +//! from a `&[u8; 15]` to an 8-byte aligned struct, Miri will complain as it |
| 129 | +//! expects `&[u8; 16]`. |
129 | 130 | //!
|
130 | 131 | //! See <https://doc.rust-lang.org/reference/type-layout.html> for information.
|
131 | 132 | //!
|
| 133 | +//! Further, this also means that we can't cast smaller structs to |
| 134 | +//! |
132 | 135 | //! Further, the [`Layout`]
|
133 | 136 | //!
|
| 137 | +//! |
| 138 | +//! |
134 | 139 | //! # Provided Abstractions
|
135 | 140 | //!
|
136 | 141 | //! Figure 2 in the [README](https://crates.io/crates/multiboot2-common)
|
@@ -317,10 +322,17 @@ impl<H: Header> DynSizedStructure<H> {
|
317 | 322 | &self.payload
|
318 | 323 | }
|
319 | 324 |
|
320 |
| - /// Casts the structure tag to a specific [`MaybeDynSized`] implementation which |
321 |
| - /// may be a ZST or DST typed tag. The output type will have the exact same |
322 |
| - /// size as `*self`. The target type must be sufficient for that. If not, |
323 |
| - /// the function will panic. |
| 325 | + /// Performs a memory-safe same-size cast from the base-structure to a |
| 326 | + /// specific [`MaybeDynSized`]. The idea here is to cast the generic |
| 327 | + /// mostly semantic-free version to a specific type with fields that have |
| 328 | + /// a semantic. |
| 329 | + /// |
| 330 | + /// The provided `T` of type [`MaybeDynSized`] might be may be sized type |
| 331 | + /// or DST. This depends on the type. |
| 332 | + /// |
| 333 | + /// # Panic |
| 334 | + /// Panics if base assumptions are violated. For example, the |
| 335 | + /// `T` of type [`MaybeDynSized`] must allow a proper casting to it. |
324 | 336 | ///
|
325 | 337 | /// # Safety
|
326 | 338 | /// This function is safe due to various sanity checks and the overall
|
|
0 commit comments