Skip to content

Commit d54cddc

Browse files
committed
tree-wide: streamline default derives and repr attributes
1 parent 9dd5c2a commit d54cddc

29 files changed

+97
-85
lines changed

multiboot2-header/src/address.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use core::mem::size_of;
55
/// format, but it must be provided if the image is in a.out format or in some
66
/// other format. Required for legacy boot (BIOS).
77
/// Determines load addresses.
8-
#[derive(Copy, Clone, Debug)]
9-
#[repr(C)]
8+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
9+
#[repr(C, align(8))]
1010
pub struct AddressHeaderTag {
1111
typ: HeaderTagType,
1212
flags: HeaderTagFlag,

multiboot2-header/src/builder/header.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use core::mem::size_of;
1414
/// Builder to construct a valid Multiboot2 header dynamically at runtime.
1515
/// The tags will appear in the order of their corresponding enumeration,
1616
/// except for the END tag.
17-
#[derive(Debug)]
17+
#[derive(Clone, Debug, PartialEq, Eq)]
1818
pub struct Multiboot2HeaderBuilder {
1919
arch: HeaderTagISA,
2020
// first

multiboot2-header/src/builder/information_request.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use multiboot2::TagTypeId;
1111
/// at runtime. The information request tag has a dedicated builder because this way one
1212
/// can dynamically attach several requests to it. Otherwise, the number of requested tags
1313
/// must be known at compile time.
14-
#[derive(Debug)]
14+
#[derive(Clone, Debug, PartialEq, Eq)]
1515
#[cfg(feature = "builder")]
1616
pub struct InformationRequestHeaderTagBuilder {
1717
flag: HeaderTagFlag,

multiboot2-header/src/console.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use core::mem::size_of;
33

44
/// Possible flags for [`ConsoleHeaderTag`].
55
#[repr(u32)]
6-
#[derive(Copy, Clone, Debug)]
6+
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
77
pub enum ConsoleHeaderTagFlags {
88
/// Console required.
99
ConsoleRequired = 0,
@@ -13,7 +13,7 @@ pub enum ConsoleHeaderTagFlags {
1313

1414
/// Tells that a console must be available in MBI.
1515
/// Only relevant for legacy BIOS.
16-
#[derive(Copy, Clone, Debug)]
16+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
1717
#[repr(C)]
1818
pub struct ConsoleHeaderTag {
1919
typ: HeaderTagType,

multiboot2-header/src/end.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use crate::{HeaderTagFlag, HeaderTagType};
22
use core::mem::size_of;
33

44
/// Terminates a list of optional tags in a Multiboot2 header.
5-
#[derive(Copy, Clone, Debug)]
6-
#[repr(C)]
5+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
6+
#[repr(C, align(8))]
77
pub struct EndHeaderTag {
88
// u16 value
99
typ: HeaderTagType,

multiboot2-header/src/entry_address.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use core::mem::size_of;
55

66
/// Specifies the physical address to which the boot loader should jump in
77
/// order to start running the operating system. Not needed for ELF files.
8-
#[derive(Copy, Clone)]
8+
#[derive(Copy, Clone, PartialEq, Eq)]
99
#[repr(C)]
1010
pub struct EntryAddressHeaderTag {
1111
typ: HeaderTagType,

multiboot2-header/src/entry_efi_32.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use core::mem::size_of;
99
///
1010
/// Technically, this is equivalent to the [`crate::EntryAddressHeaderTag`] but with a different
1111
/// [`crate::HeaderTagType`].
12-
#[derive(Copy, Clone)]
12+
#[derive(Copy, Clone, PartialEq, Eq)]
1313
#[repr(C)]
1414
pub struct EntryEfi32HeaderTag {
1515
typ: HeaderTagType,

multiboot2-header/src/entry_efi_64.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use core::mem::size_of;
99
///
1010
/// Technically, this is equivalent to the [`crate::EntryAddressHeaderTag`] but with a different
1111
/// [`crate::HeaderTagType`].
12-
#[derive(Copy, Clone)]
12+
#[derive(Copy, Clone, PartialEq, Eq)]
1313
#[repr(C)]
1414
pub struct EntryEfi64HeaderTag {
1515
typ: HeaderTagType,

multiboot2-header/src/framebuffer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use core::mem::size_of;
55
/// is present the bootloader assumes that the payload
66
/// has framebuffer support. Note: This is only a
77
/// recommended mode. Only relevant on legacy BIOS.
8-
#[derive(Copy, Clone, Debug)]
8+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
99
#[repr(C)]
1010
pub struct FramebufferHeaderTag {
1111
typ: HeaderTagType,

multiboot2-header/src/header.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ impl<'a> Debug for Multiboot2Header<'a> {
200200

201201
/// Errors that can occur when parsing a header from a slice.
202202
/// See [`Multiboot2Header::find_header`].
203-
#[derive(Debug, Clone, PartialEq, Eq)]
203+
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
204204
pub enum LoadError {
205205
/// The checksum does not match the data.
206206
ChecksumMismatch,
@@ -226,8 +226,8 @@ impl core::error::Error for LoadError {}
226226
///
227227
/// The "basic" Multiboot2 header. This means only the properties, that are known during
228228
/// compile time. All other information are derived during runtime from the size property.
229-
#[derive(Copy, Clone)]
230-
#[repr(C)]
229+
#[derive(Copy, Clone, PartialEq, Eq)]
230+
#[repr(C, align(8))]
231231
pub struct Multiboot2BasicHeader {
232232
/// Must be the value of [`MULTIBOOT2_HEADER_MAGIC`].
233233
header_magic: u32,

multiboot2-header/src/information_request.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use multiboot2::TagType;
88

99
/// Specifies what specific tag types the bootloader should provide
1010
/// inside the mbi.
11-
#[derive(Copy, Clone)]
11+
#[derive(Copy, Clone, PartialEq, Eq)]
1212
#[repr(C)]
1313
pub struct InformationRequestHeaderTag<const N: usize> {
1414
typ: HeaderTagType,
@@ -126,7 +126,7 @@ impl<'a> Iterator for InformationRequestHeaderTagIter<'a> {
126126
impl<'a> Debug for InformationRequestHeaderTagIter<'a> {
127127
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
128128
let mut debug = f.debug_list();
129-
(*self).for_each(|e| {
129+
self.for_each(|e| {
130130
debug.entry(&e);
131131
});
132132
debug.finish()

multiboot2-header/src/module_align.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use crate::{HeaderTagFlag, HeaderTagType};
22
use core::mem::size_of;
33

44
/// If this tag is present, provided boot modules must be page aligned.
5-
#[derive(Copy, Clone, Debug)]
6-
#[repr(C)]
5+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
6+
#[repr(C, align(8))]
77
pub struct ModuleAlignHeaderTag {
88
typ: HeaderTagType,
99
flags: HeaderTagFlag,

multiboot2-header/src/relocatable.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use core::mem::size_of;
88
/// but not lower than min addr and ‘2’ means load image at highest possible
99
/// address but not higher than max addr.
1010
#[repr(u32)]
11-
#[derive(Copy, Clone, Debug, PartialEq)]
11+
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
1212
pub enum RelocatableHeaderTagPreference {
1313
/// Let boot loader decide.
1414
None = 0,
@@ -19,8 +19,8 @@ pub enum RelocatableHeaderTagPreference {
1919
}
2020

2121
/// This tag indicates that the image is relocatable.
22-
#[derive(Copy, Clone)]
23-
#[repr(C)]
22+
#[derive(Copy, Clone, PartialEq, Eq)]
23+
#[repr(C, align(8))]
2424
pub struct RelocatableHeaderTag {
2525
typ: HeaderTagType,
2626
flags: HeaderTagFlag,

multiboot2-header/src/tags.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
/// ISA/ARCH in Multiboot2 header.
66
#[repr(u32)]
7-
#[derive(Copy, Clone, Debug)]
7+
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
88
pub enum HeaderTagISA {
99
/// Spec: "means 32-bit (protected) mode of i386".
1010
/// Caution: This is confusing. If you use the EFI64-tag
@@ -19,7 +19,7 @@ pub enum HeaderTagISA {
1919
/// from the example C code at the bottom of the Multiboot2 specification. This value
2020
/// stands in the `typ` property of [`crate::tags::HeaderTag`].
2121
#[repr(u16)]
22-
#[derive(Copy, Clone, Debug, PartialEq)]
22+
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
2323
pub enum HeaderTagType {
2424
/// Type for [`crate::EndHeaderTag`].
2525
End = 0,
@@ -54,7 +54,7 @@ impl HeaderTagType {
5454

5555
/// Flags for Multiboot2 header tags.
5656
#[repr(u16)]
57-
#[derive(Copy, Clone, Debug, PartialEq)]
57+
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
5858
pub enum HeaderTagFlag {
5959
Required = 0,
6060
Optional = 1,
@@ -63,8 +63,8 @@ pub enum HeaderTagFlag {
6363
/// Common properties for all header tags. Other tags may have additional fields
6464
/// that depend on the `typ` and the `size` field. All tags share the same beginning of the
6565
/// struct.
66-
#[derive(Copy, Clone, Debug)]
67-
#[repr(C)]
66+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
67+
#[repr(C, align(8))]
6868
pub struct HeaderTag {
6969
// u16 value
7070
typ: HeaderTagType,

multiboot2-header/src/uefi_bs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use core::mem::size_of;
33

44
/// This tag indicates that payload supports starting without terminating UEFI boot services.
55
/// Or in other words: The payload wants to use UEFI boot services.
6-
#[derive(Copy, Clone, Debug)]
7-
#[repr(C)]
6+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
7+
#[repr(C, align(8))]
88
pub struct EfiBootServiceHeaderTag {
99
typ: HeaderTagType,
1010
flags: HeaderTagFlag,

multiboot2/src/boot_loader_name.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ const METADATA_SIZE: usize = size_of::<TagTypeId>() + size_of::<u32>();
1313

1414
/// The bootloader name tag.
1515
#[derive(ptr_meta::Pointee)]
16-
#[repr(C, packed)] // only repr(C) would add unwanted padding before first_section
16+
#[derive(PartialEq, Eq)]
17+
#[repr(C, align(8))]
1718
pub struct BootLoaderNameTag {
1819
typ: TagTypeId,
1920
size: u32,

multiboot2/src/builder/information.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use core::mem::size_of;
1515
/// The tags will appear in the order of their corresponding enumeration,
1616
/// except for the END tag.
1717
#[derive(Debug)]
18+
// #[derive(Debug, PartialEq, Eq)] // wait for uefi-raw 0.3.0
1819
pub struct Multiboot2InformationBuilder {
1920
basic_memory_info_tag: Option<BasicMemoryInfoTag>,
2021
boot_loader_name_tag: Option<Box<BootLoaderNameTag>>,

multiboot2/src/command_line.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ pub(crate) const METADATA_SIZE: usize = mem::size_of::<TagTypeId>() + mem::size_
1818
///
1919
/// The string is a normal C-style UTF-8 zero-terminated string that can be
2020
/// obtained via the `command_line` method.
21-
#[repr(C, packed)] // only repr(C) would add unwanted padding before first_section
2221
#[derive(ptr_meta::Pointee)]
22+
#[derive(PartialEq, Eq)]
23+
#[repr(C, align(8))]
2324
pub struct CommandLineTag {
2425
typ: TagTypeId,
2526
size: u32,

multiboot2/src/efi.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use core::mem::size_of;
99
use crate::builder::traits::StructAsBytes;
1010

1111
/// EFI system table in 32 bit mode
12-
#[derive(Clone, Copy, Debug)]
13-
#[repr(C, packed)] // only repr(C) would add unwanted padding before first_section
12+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
13+
#[repr(C, align(8))]
1414
pub struct EFISdt32 {
1515
typ: TagTypeId,
1616
size: u32,
@@ -41,8 +41,8 @@ impl StructAsBytes for EFISdt32 {
4141
}
4242

4343
/// EFI system table in 64 bit mode
44-
#[derive(Clone, Copy, Debug)]
45-
#[repr(C)]
44+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
45+
#[repr(C, align(8))]
4646
pub struct EFISdt64 {
4747
typ: TagTypeId,
4848
size: u32,
@@ -73,8 +73,8 @@ impl StructAsBytes for EFISdt64 {
7373
}
7474

7575
/// Contains pointer to boot loader image handle.
76-
#[derive(Debug)]
77-
#[repr(C)]
76+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
77+
#[repr(C, align(8))]
7878
pub struct EFIImageHandle32 {
7979
typ: TagTypeId,
8080
size: u32,
@@ -105,8 +105,8 @@ impl StructAsBytes for EFIImageHandle32 {
105105
}
106106

107107
/// Contains pointer to boot loader image handle.
108-
#[derive(Debug)]
109-
#[repr(C)]
108+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
109+
#[repr(C, align(8))]
110110
pub struct EFIImageHandle64 {
111111
typ: TagTypeId,
112112
size: u32,

multiboot2/src/elf_sections.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ const METADATA_SIZE: usize = size_of::<TagTypeId>() + 4 * size_of::<u32>();
1616
///
1717
/// The sections iterator is provided via the `sections` method.
1818
#[derive(ptr_meta::Pointee)]
19-
#[repr(C, packed)]
19+
#[derive(PartialEq, Eq)]
20+
#[repr(C, align(8))]
2021
pub struct ElfSectionsTag {
2122
typ: TagTypeId,
2223
pub(crate) size: u32,
@@ -142,7 +143,7 @@ impl Default for ElfSectionIter {
142143
}
143144

144145
/// A single generic ELF Section.
145-
#[derive(Debug)]
146+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
146147
pub struct ElfSection {
147148
inner: *const u8,
148149
string_section: *const u8,
@@ -353,7 +354,7 @@ impl ElfSectionInner for ElfSectionInner64 {
353354
}
354355

355356
/// An enum abstraction over raw ELF section types.
356-
#[derive(PartialEq, Eq, Debug, Copy, Clone)]
357+
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
357358
#[repr(u32)]
358359
pub enum ElfSectionType {
359360
/// This value marks the section header as inactive; it does not have an

multiboot2/src/framebuffer.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ const METADATA_SIZE: usize = size_of::<TagTypeId>()
5151
+ 2 * size_of::<u8>();
5252

5353
/// The VBE Framebuffer information Tag.
54-
#[derive(Eq, ptr_meta::Pointee)]
55-
#[repr(C, packed)]
54+
#[derive(ptr_meta::Pointee)]
55+
#[derive(Eq)]
56+
#[repr(C, align(8))]
5657
pub struct FramebufferTag {
5758
typ: TagTypeId,
5859
size: u32,
@@ -244,7 +245,7 @@ impl TryFrom<u8> for FramebufferTypeId {
244245
}
245246

246247
/// The type of framebuffer.
247-
#[derive(Debug, PartialEq, Eq)]
248+
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
248249
pub enum FramebufferType<'a> {
249250
/// Indexed color.
250251
Indexed {
@@ -300,7 +301,7 @@ impl<'a> FramebufferType<'a> {
300301
}
301302

302303
/// An RGB color type field.
303-
#[derive(Debug, PartialEq, Eq)]
304+
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
304305
pub struct FramebufferField {
305306
/// Color field position.
306307
pub position: u8,
@@ -317,8 +318,8 @@ impl StructAsBytes for FramebufferField {
317318
}
318319

319320
/// A framebuffer color descriptor in the palette.
320-
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
321-
#[repr(C, packed)] // only repr(C) would add unwanted padding at the end
321+
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
322+
#[repr(C)] // no align(8) here is correct
322323
pub struct FramebufferColor {
323324
/// The Red component of the color.
324325
pub red: u8,
@@ -344,3 +345,14 @@ impl StructAsBytes for FramebufferColor {
344345
size_of::<Self>()
345346
}
346347
}
348+
349+
#[cfg(test)]
350+
mod tests {
351+
use super::*;
352+
353+
// Compile time test
354+
#[test]
355+
fn test_size() {
356+
assert_eq!(size_of::<FramebufferColor>(), 3)
357+
}
358+
}

multiboot2/src/image_load_addr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use {
77

88
/// If the image has relocatable header tag, this tag contains the image's
99
/// base physical address.
10-
#[derive(Debug)]
11-
#[repr(C)]
10+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
11+
#[repr(C, align(8))]
1212
pub struct ImageLoadPhysAddr {
1313
typ: TagTypeId,
1414
size: u32,

multiboot2/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ pub unsafe fn load_with_offset(
173173

174174
/// Error type that describes errors while loading/parsing a multiboot2 information structure
175175
/// from a given address.
176-
#[derive(Debug, Display)]
176+
#[derive(Display)]
177+
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
177178
pub enum MbiLoadError {
178179
/// The address is invalid. Make sure that the address is 8-byte aligned,
179180
/// according to the spec.

0 commit comments

Comments
 (0)