Skip to content

Commit abe88b3

Browse files
committed
doc: add figures and better discuss chosen design
1 parent aadcf8b commit abe88b3

File tree

13 files changed

+456
-35
lines changed

13 files changed

+456
-35
lines changed

.typos.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[files]
44
extend-exclude = [
5-
# "uefi/src/table/boot.rs"
5+
"*.drawio.xml"
66
]
77

88
[default.extend-words]

multiboot2-common/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,23 @@
55

66
Common helpers for the `multiboot2` and `multiboot2-header` crates.
77

8+
## Architecture
9+
10+
The following figures, not displayable in `lib.rs` / on `docs.rs` unfortunately,
11+
outline the design of this crate:
12+
13+
![Overview Multiboot2 Structures](./overview-multiboot2-structures.drawio.png "Overview Multiboot2 Structures")
14+
15+
Overview of Multiboot2 structures: Multiboot2 boot information, boot
16+
information tags, Multiboot2 headers, and Multiboot2 header tags all share the
17+
same technical foundation: They have a common header and a possible dynamic
18+
size, depending on the header.
19+
20+
![Crate Architecture Overview](./architecture.drawio.png "Crate Architecture Overview")
21+
22+
Overview of how raw bytes are modelled to be representable by high-level
23+
ABI-compatible rusty types.
24+
825
## MSRV
926

1027
The MSRV is 1.70.0 stable.
183 KB
Loading

multiboot2-common/architecture.drawio.xml

Lines changed: 217 additions & 0 deletions
Large diffs are not rendered by default.
Loading
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<mxfile host="app.diagrams.net" agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36" version="24.7.7">
2+
<diagram name="Seite-1" id="t28IrSg9-075dSeR9zn3">
3+
<mxGraphModel dx="989" dy="487" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
4+
<root>
5+
<mxCell id="0" />
6+
<mxCell id="1" parent="0" />
7+
<mxCell id="Sv76AHv-8cPqDwbSuwtx-1" value="" style="rounded=0;whiteSpace=wrap;html=1;verticalAlign=top;" vertex="1" parent="1">
8+
<mxGeometry x="80" y="40" width="140" height="380" as="geometry" />
9+
</mxCell>
10+
<mxCell id="Sv76AHv-8cPqDwbSuwtx-2" value="" style="rounded=0;whiteSpace=wrap;html=1;verticalAlign=top;" vertex="1" parent="1">
11+
<mxGeometry x="240" y="40" width="140" height="380" as="geometry" />
12+
</mxCell>
13+
<mxCell id="Sv76AHv-8cPqDwbSuwtx-4" value="&lt;b&gt;&lt;font data-font-src=&quot;https://fonts.googleapis.com/css?family=Roboto&quot; face=&quot;Roboto&quot;&gt;CommandLineTag&lt;/font&gt;&lt;/b&gt;&lt;br&gt;&amp;nbsp;&lt;font color=&quot;#0000cc&quot;&gt;type: u32 = 1&lt;br&gt;&amp;nbsp;size: u32 = 11&lt;/font&gt;&lt;br&gt;&amp;nbsp;str: [u8] = [&lt;br&gt;&amp;nbsp; &#39;h&#39;&lt;br&gt;&amp;nbsp; &#39;i&#39;&lt;br&gt;&amp;nbsp; &#39;\0&#39;&lt;br&gt;&amp;nbsp;]" style="rounded=0;whiteSpace=wrap;html=1;fontFamily=Source Code Pro;fontSource=https%3A%2F%2Ffonts.googleapis.com%2Fcss%3Ffamily%3DSource%2BCode%2BPro;align=left;" vertex="1" parent="1">
14+
<mxGeometry x="90" y="110" width="120" height="130" as="geometry" />
15+
</mxCell>
16+
<mxCell id="Sv76AHv-8cPqDwbSuwtx-7" value="&lt;b&gt;&lt;font data-font-src=&quot;https://fonts.googleapis.com/css?family=Roboto&quot; face=&quot;Roboto&quot;&gt;Multiboot2&lt;br&gt;Boot Information&lt;/font&gt;&lt;/b&gt;" style="rounded=0;whiteSpace=wrap;html=1;verticalAlign=top;" vertex="1" parent="1">
17+
<mxGeometry x="80" y="40" width="140" height="40" as="geometry" />
18+
</mxCell>
19+
<mxCell id="Sv76AHv-8cPqDwbSuwtx-8" value="&lt;b&gt;Multiboot2&lt;br&gt;Header&lt;/b&gt;" style="rounded=0;whiteSpace=wrap;html=1;verticalAlign=top;" vertex="1" parent="1">
20+
<mxGeometry x="240" y="40" width="140" height="40" as="geometry" />
21+
</mxCell>
22+
<mxCell id="Sv76AHv-8cPqDwbSuwtx-10" value="size: u32" style="rounded=0;whiteSpace=wrap;html=1;fontFamily=Source Code Pro;fontSource=https%3A%2F%2Ffonts.googleapis.com%2Fcss%3Ffamily%3DSource%2BCode%2BPro;" vertex="1" parent="1">
23+
<mxGeometry x="80" y="80" width="140" height="20" as="geometry" />
24+
</mxCell>
25+
<mxCell id="Sv76AHv-8cPqDwbSuwtx-11" value="size: u32" style="rounded=0;whiteSpace=wrap;html=1;fontFamily=Source Code Pro;fontSource=https%3A%2F%2Ffonts.googleapis.com%2Fcss%3Ffamily%3DSource%2BCode%2BPro;" vertex="1" parent="1">
26+
<mxGeometry x="240" y="80" width="140" height="20" as="geometry" />
27+
</mxCell>
28+
<mxCell id="Sv76AHv-8cPqDwbSuwtx-12" value="&amp;nbsp; &amp;nbsp; &lt;b&gt;&lt;font data-font-src=&quot;https://fonts.googleapis.com/css?family=Roboto&quot; face=&quot;Roboto&quot;&gt;Tag X&lt;/font&gt;&lt;/b&gt;&lt;br&gt;&amp;nbsp;&lt;font color=&quot;#0000cc&quot;&gt;type: u32 = x&lt;br&gt;&lt;/font&gt;&lt;div&gt;&lt;font color=&quot;#0000cc&quot;&gt;&amp;nbsp;size: u32 = y&lt;/font&gt;&lt;div&gt;&amp;nbsp;a: u16 = z&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;" style="rounded=0;whiteSpace=wrap;html=1;fontFamily=Source Code Pro;fontSource=https%3A%2F%2Ffonts.googleapis.com%2Fcss%3Ffamily%3DSource%2BCode%2BPro;verticalAlign=top;align=left;" vertex="1" parent="1">
29+
<mxGeometry x="90" y="250" width="120" height="70" as="geometry" />
30+
</mxCell>
31+
<mxCell id="Sv76AHv-8cPqDwbSuwtx-14" value="&lt;b&gt;&lt;font face=&quot;Roboto&quot;&gt;InformationReq&lt;/font&gt;&lt;/b&gt;&lt;br&gt;&amp;nbsp;&lt;font color=&quot;#007fff&quot;&gt;type: u16 = 1&lt;br&gt;&amp;nbsp;flags: u16 = 0&lt;br&gt;&amp;nbsp;size: u32 = 11&lt;/font&gt;&lt;br&gt;&amp;nbsp;reqs: [u32] = [&lt;br&gt;&amp;nbsp; 1&lt;br&gt;&amp;nbsp;];" style="rounded=0;whiteSpace=wrap;html=1;fontFamily=Source Code Pro;fontSource=https%3A%2F%2Ffonts.googleapis.com%2Fcss%3Ffamily%3DSource%2BCode%2BPro;align=left;verticalAlign=top;" vertex="1" parent="1">
32+
<mxGeometry x="250" y="110" width="120" height="110" as="geometry" />
33+
</mxCell>
34+
<mxCell id="Sv76AHv-8cPqDwbSuwtx-15" value="&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;b&gt;&lt;font data-font-src=&quot;https://fonts.googleapis.com/css?family=Roboto&quot; face=&quot;Roboto&quot;&gt;Tag Y&lt;/font&gt;&lt;/b&gt;&lt;br&gt;&amp;nbsp;&lt;font color=&quot;#007fff&quot;&gt;type: u16 = x&lt;br&gt;&amp;nbsp;flags: u16 = y&lt;br&gt;&amp;nbsp;size: u32 = z&lt;/font&gt;&lt;br&gt;&amp;nbsp;bar: u64 = x&lt;br&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;" style="rounded=0;whiteSpace=wrap;html=1;fontFamily=Source Code Pro;fontSource=https%3A%2F%2Ffonts.googleapis.com%2Fcss%3Ffamily%3DSource%2BCode%2BPro;verticalAlign=top;align=left;" vertex="1" parent="1">
35+
<mxGeometry x="250" y="250" width="120" height="90" as="geometry" />
36+
</mxCell>
37+
<mxCell id="Sv76AHv-8cPqDwbSuwtx-16" value="&lt;div&gt;&lt;div&gt;&lt;div&gt;...&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;" style="rounded=0;whiteSpace=wrap;html=1;fontFamily=Source Code Pro;fontSource=https%3A%2F%2Ffonts.googleapis.com%2Fcss%3Ffamily%3DSource%2BCode%2BPro;verticalAlign=middle;align=center;" vertex="1" parent="1">
38+
<mxGeometry x="90" y="390" width="120" height="20" as="geometry" />
39+
</mxCell>
40+
<mxCell id="Sv76AHv-8cPqDwbSuwtx-20" value="" style="endArrow=none;dashed=1;html=1;dashPattern=1 2;strokeWidth=2;rounded=0;strokeColor=#FF9999;" edge="1" parent="1">
41+
<mxGeometry width="50" height="50" relative="1" as="geometry">
42+
<mxPoint x="30" y="250" as="sourcePoint" />
43+
<mxPoint x="400" y="250" as="targetPoint" />
44+
</mxGeometry>
45+
</mxCell>
46+
<mxCell id="Sv76AHv-8cPqDwbSuwtx-22" value="&lt;font data-font-src=&quot;https://fonts.googleapis.com/css?family=Roboto&quot; style=&quot;font-size: 10px;&quot;&gt;8-byte&lt;br style=&quot;font-size: 10px;&quot;&gt;alignment&lt;/font&gt;" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;fontFamily=Source Code Pro;fontSource=https%3A%2F%2Ffonts.googleapis.com%2Fcss%3Ffamily%3DSource%2BCode%2BPro;fontSize=10;fontColor=#FF3333;" vertex="1" parent="1">
47+
<mxGeometry x="10" y="250" width="60" height="30" as="geometry" />
48+
</mxCell>
49+
<mxCell id="Sv76AHv-8cPqDwbSuwtx-23" value="&lt;font data-font-src=&quot;https://fonts.googleapis.com/css?family=Roboto&quot; style=&quot;font-size: 10px;&quot;&gt;8-byte&lt;br style=&quot;font-size: 10px;&quot;&gt;alignment&lt;/font&gt;" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;fontFamily=Source Code Pro;fontSource=https%3A%2F%2Ffonts.googleapis.com%2Fcss%3Ffamily%3DSource%2BCode%2BPro;fontSize=10;fontColor=#FF3333;" vertex="1" parent="1">
50+
<mxGeometry x="10" y="110" width="60" height="30" as="geometry" />
51+
</mxCell>
52+
<mxCell id="Sv76AHv-8cPqDwbSuwtx-24" value="&lt;font data-font-src=&quot;https://fonts.googleapis.com/css?family=Roboto&quot; style=&quot;font-size: 10px;&quot;&gt;8-byte&lt;br style=&quot;font-size: 10px;&quot;&gt;alignment&lt;/font&gt;" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;fontFamily=Source Code Pro;fontSource=https%3A%2F%2Ffonts.googleapis.com%2Fcss%3Ffamily%3DSource%2BCode%2BPro;fontSize=10;fontColor=#FF3333;" vertex="1" parent="1">
53+
<mxGeometry x="10" y="40" width="60" height="30" as="geometry" />
54+
</mxCell>
55+
<mxCell id="Sv76AHv-8cPqDwbSuwtx-26" value="" style="endArrow=none;dashed=1;html=1;dashPattern=1 2;strokeWidth=2;rounded=0;strokeColor=#FF9999;" edge="1" parent="1">
56+
<mxGeometry width="50" height="50" relative="1" as="geometry">
57+
<mxPoint x="30" y="110" as="sourcePoint" />
58+
<mxPoint x="400" y="110" as="targetPoint" />
59+
</mxGeometry>
60+
</mxCell>
61+
<mxCell id="Sv76AHv-8cPqDwbSuwtx-27" value="" style="endArrow=none;dashed=1;html=1;dashPattern=1 2;strokeWidth=2;rounded=0;strokeColor=#FF9999;" edge="1" parent="1">
62+
<mxGeometry width="50" height="50" relative="1" as="geometry">
63+
<mxPoint x="30" y="39.31" as="sourcePoint" />
64+
<mxPoint x="400" y="39.31" as="targetPoint" />
65+
</mxGeometry>
66+
</mxCell>
67+
<mxCell id="Sv76AHv-8cPqDwbSuwtx-28" value="" style="endArrow=none;dashed=1;html=1;dashPattern=1 2;strokeWidth=2;rounded=0;strokeColor=#FF9999;" edge="1" parent="1">
68+
<mxGeometry width="50" height="50" relative="1" as="geometry">
69+
<mxPoint x="30" y="420" as="sourcePoint" />
70+
<mxPoint x="400" y="420" as="targetPoint" />
71+
</mxGeometry>
72+
</mxCell>
73+
<mxCell id="Sv76AHv-8cPqDwbSuwtx-29" value="&lt;font data-font-src=&quot;https://fonts.googleapis.com/css?family=Roboto&quot; style=&quot;font-size: 10px;&quot;&gt;8-byte&lt;br style=&quot;font-size: 10px;&quot;&gt;alignment&lt;/font&gt;" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;fontFamily=Source Code Pro;fontSource=https%3A%2F%2Ffonts.googleapis.com%2Fcss%3Ffamily%3DSource%2BCode%2BPro;fontSize=10;fontColor=#FF3333;" vertex="1" parent="1">
74+
<mxGeometry x="10" y="390" width="60" height="30" as="geometry" />
75+
</mxCell>
76+
<mxCell id="Sv76AHv-8cPqDwbSuwtx-32" value="Overview of Multiboot2 Structures" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;fontFamily=Roboto;fontSource=https%3A%2F%2Ffonts.googleapis.com%2Fcss%3Ffamily%3DRoboto;fontSize=14;fontStyle=1" vertex="1" parent="1">
77+
<mxGeometry x="80" width="300" height="30" as="geometry" />
78+
</mxCell>
79+
<mxCell id="Sv76AHv-8cPqDwbSuwtx-33" value="&lt;div&gt;&lt;div&gt;&lt;div&gt;...&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;" style="rounded=0;whiteSpace=wrap;html=1;fontFamily=Source Code Pro;fontSource=https%3A%2F%2Ffonts.googleapis.com%2Fcss%3Ffamily%3DSource%2BCode%2BPro;verticalAlign=middle;align=center;" vertex="1" parent="1">
80+
<mxGeometry x="250" y="390" width="120" height="20" as="geometry" />
81+
</mxCell>
82+
<mxCell id="Sv76AHv-8cPqDwbSuwtx-34" value="&lt;div&gt;&lt;div&gt;&lt;div&gt;...&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;" style="rounded=0;whiteSpace=wrap;html=1;fontFamily=Source Code Pro;fontSource=https%3A%2F%2Ffonts.googleapis.com%2Fcss%3Ffamily%3DSource%2BCode%2BPro;verticalAlign=middle;align=center;" vertex="1" parent="1">
83+
<mxGeometry x="250" y="360" width="120" height="20" as="geometry" />
84+
</mxCell>
85+
<mxCell id="Sv76AHv-8cPqDwbSuwtx-35" value="&lt;div&gt;&lt;div&gt;&lt;div&gt;...&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;" style="rounded=0;whiteSpace=wrap;html=1;fontFamily=Source Code Pro;fontSource=https%3A%2F%2Ffonts.googleapis.com%2Fcss%3Ffamily%3DSource%2BCode%2BPro;verticalAlign=middle;align=center;" vertex="1" parent="1">
86+
<mxGeometry x="90" y="360" width="120" height="20" as="geometry" />
87+
</mxCell>
88+
<mxCell id="Sv76AHv-8cPqDwbSuwtx-36" value="&lt;div&gt;&lt;div&gt;&lt;div&gt;...&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;" style="rounded=0;whiteSpace=wrap;html=1;fontFamily=Source Code Pro;fontSource=https%3A%2F%2Ffonts.googleapis.com%2Fcss%3Ffamily%3DSource%2BCode%2BPro;verticalAlign=middle;align=center;" vertex="1" parent="1">
89+
<mxGeometry x="90" y="330" width="120" height="20" as="geometry" />
90+
</mxCell>
91+
<mxCell id="Sv76AHv-8cPqDwbSuwtx-39" value="Padding" style="rounded=0;whiteSpace=wrap;html=1;fontFamily=Source Code Pro;fontSource=https%3A%2F%2Ffonts.googleapis.com%2Fcss%3Ffamily%3DSource%2BCode%2BPro;verticalAlign=middle;align=center;" vertex="1" parent="1">
92+
<mxGeometry x="250" y="230" width="120" height="10" as="geometry" />
93+
</mxCell>
94+
</root>
95+
</mxGraphModel>
96+
</diagram>
97+
</mxfile>

multiboot2-common/src/lib.rs

Lines changed: 80 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@
1515
//! - header structure (whole)
1616
//! - header tags
1717
//!
18-
//! # The Problem / Difficulties
18+
//! # Solved Problem & Difficulties Along the Way
19+
//!
20+
//! Firstly, the design choice to have ABI-compatible rusty types influenced the
21+
//! requirements and difficulties along the way. They, on the other side,
22+
//! influenced the design. The outcome is what we perceive as the optimal rusty
23+
//! and convenient solution.
1924
//!
2025
//! ## Multiboot2 Structures
2126
//!
@@ -34,15 +39,21 @@
3439
//!
3540
//! Note that these structures can also be nested. So for example, the
3641
//! Multiboot2 boot information contains Multiboot2 tags, and the Multiboot2
37-
//! header contains Multiboot2 header tags - both are itself dynamic structures.
42+
//! header contains Multiboot2 header tags - both are itself **dynamically
43+
//! sized** structures. This means, you can know the size (and amount of
44+
//! elements) **only at runtime!**
3845
//!
3946
//! A final `[u8]` field in the structs is the most rusty way to model this.
4047
//! However, this makes the type a Dynamically Sized Type (DST). To create
4148
//! references to these types from a byte slice, one needs fat pointers. They
4249
//! are a language feature currently not constructable with stable Rust.
4350
//! Luckily, we can utilize [`ptr_meta`].
4451
//!
45-
//! ## Dynamic and Sized Structs
52+
//! Figure 1 in the [README](https://crates.io/crates/multiboot2-common)
53+
//! (currently not embeddable in lib.rs unfortunately) provides an overview of
54+
//! Multiboot2 structures.
55+
//!
56+
//! ## Dynamic and Sized Structs in Rust
4657
//!
4758
//! Note that we also have structures (tags) in Multiboot2 that looks like this:
4859
//!
@@ -68,31 +79,75 @@
6879
//! }
6980
//! ```
7081
//!
71-
//! ## Fat Pointer Requirements
82+
//! ## Chosen Design
83+
//!
84+
//! The overall common abstractions needed to solve the problems mentioned in
85+
//! this section are also mainly influenced by the fact that the `multiboot2`
86+
//! and `multiboot2-header` crates use a **zero-copy** design for parsing
87+
//! the corresponding structures.
88+
//!
89+
//! Further, by having **ABI-compatible types** that fully represent the
90+
//! reality, we can use the same type for parsing **and** for construction,
91+
//! as modelled in the following simplified example:
92+
//!
93+
//! ```rust,ignore
94+
//! /// ABI-compatible tag for parsing.
95+
//! pub struct MemoryMapTag {
96+
//! header: TagHeader,
97+
//! entry_size: u32,
98+
//! entry_version: u32,
99+
//! areas: [MemoryArea],
100+
//! }
101+
//!
102+
//! impl MemoryMapTag {
103+
//! // We can also create an ABI-compatible structure of that type.
104+
//! pub fn new(areas: &[MemoryArea]) -> Box<Self> {
105+
//! // omitted
106+
//! }
107+
//! }
108+
//! ```
109+
//!
110+
//! Hence, the structures can also be build at runtime. This is what we
111+
//! consider **idiomatic and rusty**.
112+
//!
113+
//! ## Creating Fat Pointers with [`ptr_meta`]
72114
//!
73115
//! To create fat pointers with [`ptr_meta`], each tag needs a `Metadata` type
74116
//! which is either `usize` (for DSTs) or `()`. A trait is needed to abstract
75117
//! above sized or unsized types.
76118
//!
77119
//! ## Multiboot2 Requirements
78120
//!
79-
//! All tags must be 8-byte aligned. Space between multiple tags may be
80-
//! filled with zeroes if necessary. These zeroes are not reflected in the
81-
//! previous tag's size.
121+
//! All tags must be 8-byte aligned. The actual payload of tags may be followed
122+
//! by padding zeroes to fill the gap until the next alignment boundary, if
123+
//! necessary. These zeroes are not reflected in the tag's size, but for Rust,
124+
//! must be reflected in the memory allocation size.
82125
//!
83126
//! ## Rustc Requirements
84127
//!
85-
//! The allocation space that Rust requires for types is a multiple of the
128+
//! The required allocation space that Rust uses for types is a multiple of the
86129
//! alignment. This means that if we cast between byte slices and specific
87-
//! types, Rust doesn't just see the size reported by the header but also
88-
//! any necessary padding bytes. If this is not the case, for example we
89-
//! cast to a structure from a `&[u8; 15]`, Miri will complain as it expects
90-
//! `&[u8; 16]`
130+
//! types, Rust doesn't just see the "trimmed down actual payload" defined by
131+
//! struct members, but also any necessary, but hidden, padding bytes. If we
132+
//! don't guarantee the correct is not the case, for example we cast the bytes
133+
//! from a `&[u8; 15]` to an 8-byte aligned struct, Miri will complain as it
134+
//! expects `&[u8; 16]`.
91135
//!
92136
//! See <https://doc.rust-lang.org/reference/type-layout.html> for information.
93137
//!
138+
//! Further, this also means that we can't cast references to smaller structs
139+
//! to bigger ones. Also, once we construct a `Box` on the heap and construct
140+
//! it using the [`new_boxed`] helper, we must ensure that the default
141+
//! [`Layout`] for the underlying type equals the one we manually used for the
142+
//! allocation.
143+
//!
94144
//! # Provided Abstractions
95145
//!
146+
//! Figure 2 in the [README](https://crates.io/crates/multiboot2-common)
147+
//! (currently not embeddable in lib.rs unfortunately) provides an overview of
148+
//! the parsing of Multiboot2 structures and how the definitions from this
149+
//! crate are used.
150+
//!
96151
//! ## Parsing and Casting
97152
//!
98153
//! First, we need byte slices which are guaranteed to be aligned and are a
@@ -122,6 +177,8 @@
122177
//! # No Public API
123178
//!
124179
//! Not meant as stable public API for others outside Multiboot2.
180+
//!
181+
//! [`Layout`]: core::alloc::Layout
125182
126183
#![no_std]
127184
#![cfg_attr(feature = "unstable", feature(error_in_core))]
@@ -270,10 +327,17 @@ impl<H: Header> DynSizedStructure<H> {
270327
&self.payload
271328
}
272329

273-
/// Casts the structure tag to a specific [`MaybeDynSized`] implementation which
274-
/// may be a ZST or DST typed tag. The output type will have the exact same
275-
/// size as `*self`. The target type must be sufficient for that. If not,
276-
/// the function will panic.
330+
/// Performs a memory-safe same-size cast from the base-structure to a
331+
/// specific [`MaybeDynSized`]. The idea here is to cast the generic
332+
/// mostly semantic-free version to a specific type with fields that have
333+
/// a semantic.
334+
///
335+
/// The provided `T` of type [`MaybeDynSized`] might be may be sized type
336+
/// or DST. This depends on the type.
337+
///
338+
/// # Panic
339+
/// Panics if base assumptions are violated. For example, the
340+
/// `T` of type [`MaybeDynSized`] must allow a proper casting to it.
277341
///
278342
/// # Safety
279343
/// This function is safe due to various sanity checks and the overall

multiboot2-common/src/tag.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ use ptr_meta::Pointee;
1010
/// [`DynSizedStructure::cast`].
1111
///
1212
/// Structs that are a DST must provide a **correct**
13-
/// [`MaybeDynSized::dst_len`] implementation.
13+
/// [`MaybeDynSized::dst_len`] implementation. Further, implementors **must**
14+
/// use `#[repr(C)]`.
1415
///
1516
/// [`ID`]: Tag::ID
1617
/// [`DynSizedStructure`]: crate::DynSizedStructure

0 commit comments

Comments
 (0)