1
- // this crate can use `std` in tests only
2
- #![ cfg_attr( not ( test ) , no_std ) ]
1
+ #! [ no_std ]
2
+ #![ cfg_attr( feature = "unstable" , feature ( error_in_core ) ) ]
3
3
#![ deny( missing_debug_implementations) ]
4
4
// --- BEGIN STYLE CHECKS ---
5
5
// These checks are optional in CI for PRs, as discussed in
6
6
// https://github.com/rust-osdev/multiboot2/pull/92
7
7
#![ deny( clippy:: all) ]
8
8
#![ deny( rustdoc:: all) ]
9
- // Forcing this would be a little bit ridiculous, because it would require code examples for
10
- // each getter and each trivial trait implementation (like Debug).
9
+ #![ allow( rustdoc:: private_doc_tests) ]
11
10
#![ allow( rustdoc:: missing_doc_code_examples) ]
12
11
// --- END STYLE CHECKS ---
13
12
40
39
extern crate std;
41
40
42
41
use core:: fmt;
42
+ use derive_more:: Display ;
43
43
44
44
pub use boot_loader_name:: BootLoaderNameTag ;
45
45
pub use command_line:: CommandLineTag ;
@@ -88,7 +88,7 @@ pub const MULTIBOOT2_BOOTLOADER_MAGIC: u32 = 0x36d76289;
88
88
89
89
/// Load the multiboot boot information struct from an address.
90
90
///
91
- /// This is the same as `load_with_offset` but the offset is omitted and set
91
+ /// This is the same as [ `load_with_offset`] but the offset is omitted and set
92
92
/// to zero.
93
93
///
94
94
/// ## Example
@@ -108,7 +108,7 @@ pub const MULTIBOOT2_BOOTLOADER_MAGIC: u32 = 0x36d76289;
108
108
/// environment (segfault) but also in UEFI-applications, where the referenced
109
109
/// memory is not (identity) mapped (UEFI does only identity mapping).
110
110
/// * The memory at `address` must not be modified after calling `load` or the
111
- /// program may observe unsychronized mutation.
111
+ /// program may observe unsynchronized mutation.
112
112
pub unsafe fn load ( address : usize ) -> Result < BootInformation , MbiLoadError > {
113
113
load_with_offset ( address, 0 )
114
114
}
@@ -117,7 +117,7 @@ pub unsafe fn load(address: usize) -> Result<BootInformation, MbiLoadError> {
117
117
///
118
118
/// ## Example
119
119
///
120
- /// ```ignore
120
+ /// ```rust,no_run
121
121
/// use multiboot2::load_with_offset;
122
122
///
123
123
/// let ptr = 0xDEADBEEF as *const u32;
@@ -131,7 +131,7 @@ pub unsafe fn load(address: usize) -> Result<BootInformation, MbiLoadError> {
131
131
/// environment (segfault) but also in UEFI-applications, where the referenced
132
132
/// memory is not (identity) mapped (UEFI does only identity mapping).
133
133
/// * The memory at `address` must not be modified after calling `load` or the
134
- /// program may observe unsychronized mutation.
134
+ /// program may observe unsynchronized mutation.
135
135
pub unsafe fn load_with_offset (
136
136
address : usize ,
137
137
offset : usize ,
@@ -161,19 +161,25 @@ pub unsafe fn load_with_offset(
161
161
162
162
/// Error type that describes errors while loading/parsing a multiboot2 information structure
163
163
/// from a given address.
164
- #[ derive( Debug ) ]
164
+ #[ derive( Debug , Display ) ]
165
165
pub enum MbiLoadError {
166
166
/// The address is invalid. Make sure that the address is 8-byte aligned,
167
167
/// according to the spec.
168
+ #[ display( fmt = "The address is invalid" ) ]
168
169
IllegalAddress ,
169
170
/// The total size of the multiboot2 information structure must be a multiple of 8.
170
171
/// (Not in spec, but it is implicitly the case, because the begin of MBI
171
172
/// and all tags are 8-byte aligned and the end tag is exactly 8 byte long).
173
+ #[ display( fmt = "The size of the MBI is unexpected" ) ]
172
174
IllegalTotalSize ( u32 ) ,
173
175
/// End tag missing. Each multiboot2 header requires to have an end tag.
176
+ #[ display( fmt = "There is no end tag" ) ]
174
177
NoEndTag ,
175
178
}
176
179
180
+ #[ cfg( feature = "unstable" ) ]
181
+ impl core:: error:: Error for MbiLoadError { }
182
+
177
183
/// A Multiboot 2 Boot Information struct.
178
184
pub struct BootInformation {
179
185
inner : * const BootInformationInner ,
@@ -197,8 +203,9 @@ impl BootInformation {
197
203
///
198
204
/// This is the same as doing:
199
205
///
200
- /// ```ignore
201
- /// let end_addr = boot_info.start_address() + boot_info.size();
206
+ /// ```rust,no_run
207
+ /// # let boot_info = unsafe { multiboot2::load(0xdeadbeef).unwrap() };
208
+ /// let end_addr = boot_info.start_address() + boot_info.total_size();
202
209
/// ```
203
210
pub fn end_address ( & self ) -> usize {
204
211
self . start_address ( ) + self . total_size ( )
@@ -1434,4 +1441,12 @@ mod tests {
1434
1441
core:: mem:: transmute :: < [ u8 ; 16 ] , EFIMemoryMapTag > ( [ 0u8 ; 16 ] ) ;
1435
1442
}
1436
1443
}
1444
+
1445
+ #[ test]
1446
+ #[ cfg( feature = "unstable" ) ]
1447
+ /// This test succeeds if it compiles.
1448
+ fn mbi_load_error_implements_error ( ) {
1449
+ fn consumer < E : core:: error:: Error > ( _e : E ) { }
1450
+ consumer ( MbiLoadError :: IllegalAddress )
1451
+ }
1437
1452
}
0 commit comments