diff --git a/multiboot2-header/src/address.rs b/multiboot2-header/src/address.rs index 726a13b3..95f4f140 100644 --- a/multiboot2-header/src/address.rs +++ b/multiboot2-header/src/address.rs @@ -5,7 +5,7 @@ use core::mem::size_of; /// format, but it must be provided if the image is in a.out format or in some /// other format. Required for legacy boot (BIOS). /// Determines load addresses. -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(C)] pub struct AddressHeaderTag { typ: HeaderTagType, diff --git a/multiboot2-header/src/builder/header.rs b/multiboot2-header/src/builder/header.rs index a9c23dc3..0139cd73 100644 --- a/multiboot2-header/src/builder/header.rs +++ b/multiboot2-header/src/builder/header.rs @@ -14,7 +14,7 @@ use core::mem::size_of; /// Builder to construct a valid Multiboot2 header dynamically at runtime. /// The tags will appear in the order of their corresponding enumeration, /// except for the END tag. -#[derive(Debug)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct Multiboot2HeaderBuilder { arch: HeaderTagISA, // first diff --git a/multiboot2-header/src/builder/information_request.rs b/multiboot2-header/src/builder/information_request.rs index 849d822a..689302a8 100644 --- a/multiboot2-header/src/builder/information_request.rs +++ b/multiboot2-header/src/builder/information_request.rs @@ -11,7 +11,7 @@ use multiboot2::TagTypeId; /// at runtime. The information request tag has a dedicated builder because this way one /// can dynamically attach several requests to it. Otherwise, the number of requested tags /// must be known at compile time. -#[derive(Debug)] +#[derive(Clone, Debug, PartialEq, Eq)] #[cfg(feature = "builder")] pub struct InformationRequestHeaderTagBuilder { flag: HeaderTagFlag, diff --git a/multiboot2-header/src/console.rs b/multiboot2-header/src/console.rs index b1997bd4..e7ee920f 100644 --- a/multiboot2-header/src/console.rs +++ b/multiboot2-header/src/console.rs @@ -3,7 +3,7 @@ use core::mem::size_of; /// Possible flags for [`ConsoleHeaderTag`]. #[repr(u32)] -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum ConsoleHeaderTagFlags { /// Console required. ConsoleRequired = 0, @@ -13,7 +13,7 @@ pub enum ConsoleHeaderTagFlags { /// Tells that a console must be available in MBI. /// Only relevant for legacy BIOS. -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(C)] pub struct ConsoleHeaderTag { typ: HeaderTagType, diff --git a/multiboot2-header/src/end.rs b/multiboot2-header/src/end.rs index 4cc4aeb9..ef73e5f0 100644 --- a/multiboot2-header/src/end.rs +++ b/multiboot2-header/src/end.rs @@ -2,7 +2,7 @@ use crate::{HeaderTagFlag, HeaderTagType}; use core::mem::size_of; /// Terminates a list of optional tags in a Multiboot2 header. -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(C)] pub struct EndHeaderTag { // u16 value diff --git a/multiboot2-header/src/entry_address.rs b/multiboot2-header/src/entry_address.rs index 24a4ddcc..7af4f052 100644 --- a/multiboot2-header/src/entry_address.rs +++ b/multiboot2-header/src/entry_address.rs @@ -5,7 +5,7 @@ use core::mem::size_of; /// Specifies the physical address to which the boot loader should jump in /// order to start running the operating system. Not needed for ELF files. -#[derive(Copy, Clone)] +#[derive(Copy, Clone, PartialEq, Eq)] #[repr(C)] pub struct EntryAddressHeaderTag { typ: HeaderTagType, diff --git a/multiboot2-header/src/entry_efi_32.rs b/multiboot2-header/src/entry_efi_32.rs index 02150f05..c5aeda96 100644 --- a/multiboot2-header/src/entry_efi_32.rs +++ b/multiboot2-header/src/entry_efi_32.rs @@ -9,7 +9,7 @@ use core::mem::size_of; /// /// Technically, this is equivalent to the [`crate::EntryAddressHeaderTag`] but with a different /// [`crate::HeaderTagType`]. -#[derive(Copy, Clone)] +#[derive(Copy, Clone, PartialEq, Eq)] #[repr(C)] pub struct EntryEfi32HeaderTag { typ: HeaderTagType, diff --git a/multiboot2-header/src/entry_efi_64.rs b/multiboot2-header/src/entry_efi_64.rs index ec5f84c9..86574abd 100644 --- a/multiboot2-header/src/entry_efi_64.rs +++ b/multiboot2-header/src/entry_efi_64.rs @@ -9,7 +9,7 @@ use core::mem::size_of; /// /// Technically, this is equivalent to the [`crate::EntryAddressHeaderTag`] but with a different /// [`crate::HeaderTagType`]. -#[derive(Copy, Clone)] +#[derive(Copy, Clone, PartialEq, Eq)] #[repr(C)] pub struct EntryEfi64HeaderTag { typ: HeaderTagType, diff --git a/multiboot2-header/src/framebuffer.rs b/multiboot2-header/src/framebuffer.rs index 41d2fead..289ee075 100644 --- a/multiboot2-header/src/framebuffer.rs +++ b/multiboot2-header/src/framebuffer.rs @@ -5,7 +5,7 @@ use core::mem::size_of; /// is present the bootloader assumes that the payload /// has framebuffer support. Note: This is only a /// recommended mode. Only relevant on legacy BIOS. -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(C)] pub struct FramebufferHeaderTag { typ: HeaderTagType, diff --git a/multiboot2-header/src/header.rs b/multiboot2-header/src/header.rs index 820362a1..851826e1 100644 --- a/multiboot2-header/src/header.rs +++ b/multiboot2-header/src/header.rs @@ -200,7 +200,7 @@ impl<'a> Debug for Multiboot2Header<'a> { /// Errors that can occur when parsing a header from a slice. /// See [`Multiboot2Header::find_header`]. -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum LoadError { /// The checksum does not match the data. ChecksumMismatch, @@ -226,7 +226,7 @@ impl core::error::Error for LoadError {} /// /// The "basic" Multiboot2 header. This means only the properties, that are known during /// compile time. All other information are derived during runtime from the size property. -#[derive(Copy, Clone)] +#[derive(Copy, Clone, PartialEq, Eq)] #[repr(C)] pub struct Multiboot2BasicHeader { /// Must be the value of [`MULTIBOOT2_HEADER_MAGIC`]. diff --git a/multiboot2-header/src/information_request.rs b/multiboot2-header/src/information_request.rs index bf2f920b..50d3fac9 100644 --- a/multiboot2-header/src/information_request.rs +++ b/multiboot2-header/src/information_request.rs @@ -8,7 +8,7 @@ use multiboot2::TagType; /// Specifies what specific tag types the bootloader should provide /// inside the mbi. -#[derive(Copy, Clone)] +#[derive(Copy, Clone, PartialEq, Eq)] #[repr(C)] pub struct InformationRequestHeaderTag { typ: HeaderTagType, @@ -126,7 +126,7 @@ impl<'a> Iterator for InformationRequestHeaderTagIter<'a> { impl<'a> Debug for InformationRequestHeaderTagIter<'a> { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { let mut debug = f.debug_list(); - (*self).for_each(|e| { + self.for_each(|e| { debug.entry(&e); }); debug.finish() diff --git a/multiboot2-header/src/module_align.rs b/multiboot2-header/src/module_align.rs index 546f920e..0d9a66e5 100644 --- a/multiboot2-header/src/module_align.rs +++ b/multiboot2-header/src/module_align.rs @@ -2,7 +2,7 @@ use crate::{HeaderTagFlag, HeaderTagType}; use core::mem::size_of; /// If this tag is present, provided boot modules must be page aligned. -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(C)] pub struct ModuleAlignHeaderTag { typ: HeaderTagType, diff --git a/multiboot2-header/src/relocatable.rs b/multiboot2-header/src/relocatable.rs index 09581b08..dd6dbe17 100644 --- a/multiboot2-header/src/relocatable.rs +++ b/multiboot2-header/src/relocatable.rs @@ -8,7 +8,7 @@ use core::mem::size_of; /// but not lower than min addr and ‘2’ means load image at highest possible /// address but not higher than max addr. #[repr(u32)] -#[derive(Copy, Clone, Debug, PartialEq)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum RelocatableHeaderTagPreference { /// Let boot loader decide. None = 0, @@ -19,7 +19,7 @@ pub enum RelocatableHeaderTagPreference { } /// This tag indicates that the image is relocatable. -#[derive(Copy, Clone)] +#[derive(Copy, Clone, PartialEq, Eq)] #[repr(C)] pub struct RelocatableHeaderTag { typ: HeaderTagType, diff --git a/multiboot2-header/src/tags.rs b/multiboot2-header/src/tags.rs index 681117a6..38b0dd75 100644 --- a/multiboot2-header/src/tags.rs +++ b/multiboot2-header/src/tags.rs @@ -4,7 +4,7 @@ /// ISA/ARCH in Multiboot2 header. #[repr(u32)] -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum HeaderTagISA { /// Spec: "means 32-bit (protected) mode of i386". /// Caution: This is confusing. If you use the EFI64-tag @@ -19,7 +19,7 @@ pub enum HeaderTagISA { /// from the example C code at the bottom of the Multiboot2 specification. This value /// stands in the `typ` property of [`crate::tags::HeaderTag`]. #[repr(u16)] -#[derive(Copy, Clone, Debug, PartialEq)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum HeaderTagType { /// Type for [`crate::EndHeaderTag`]. End = 0, @@ -54,7 +54,7 @@ impl HeaderTagType { /// Flags for Multiboot2 header tags. #[repr(u16)] -#[derive(Copy, Clone, Debug, PartialEq)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum HeaderTagFlag { Required = 0, Optional = 1, @@ -63,7 +63,7 @@ pub enum HeaderTagFlag { /// Common properties for all header tags. Other tags may have additional fields /// that depend on the `typ` and the `size` field. All tags share the same beginning of the /// struct. -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(C)] pub struct HeaderTag { // u16 value diff --git a/multiboot2-header/src/uefi_bs.rs b/multiboot2-header/src/uefi_bs.rs index a16606e6..9cc52312 100644 --- a/multiboot2-header/src/uefi_bs.rs +++ b/multiboot2-header/src/uefi_bs.rs @@ -3,7 +3,7 @@ use core::mem::size_of; /// This tag indicates that payload supports starting without terminating UEFI boot services. /// Or in other words: The payload wants to use UEFI boot services. -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(C)] pub struct EfiBootServiceHeaderTag { typ: HeaderTagType, diff --git a/multiboot2/src/boot_loader_name.rs b/multiboot2/src/boot_loader_name.rs index 9a4977f0..3d7769a1 100644 --- a/multiboot2/src/boot_loader_name.rs +++ b/multiboot2/src/boot_loader_name.rs @@ -12,8 +12,8 @@ use { const METADATA_SIZE: usize = size_of::() + size_of::(); /// The bootloader name tag. -#[derive(ptr_meta::Pointee)] -#[repr(C, packed)] // only repr(C) would add unwanted padding before first_section +#[derive(ptr_meta::Pointee, PartialEq, Eq)] +#[repr(C)] pub struct BootLoaderNameTag { typ: TagTypeId, size: u32, diff --git a/multiboot2/src/builder/information.rs b/multiboot2/src/builder/information.rs index 3f06cebb..5cb635a7 100644 --- a/multiboot2/src/builder/information.rs +++ b/multiboot2/src/builder/information.rs @@ -15,6 +15,7 @@ use core::mem::size_of; /// The tags will appear in the order of their corresponding enumeration, /// except for the END tag. #[derive(Debug)] +// #[derive(Debug, PartialEq, Eq)] // wait for uefi-raw 0.3.0 pub struct Multiboot2InformationBuilder { basic_memory_info_tag: Option, boot_loader_name_tag: Option>, diff --git a/multiboot2/src/command_line.rs b/multiboot2/src/command_line.rs index 39e396a6..25456897 100644 --- a/multiboot2/src/command_line.rs +++ b/multiboot2/src/command_line.rs @@ -18,8 +18,8 @@ pub(crate) const METADATA_SIZE: usize = mem::size_of::() + mem::size_ /// /// The string is a normal C-style UTF-8 zero-terminated string that can be /// obtained via the `command_line` method. -#[repr(C, packed)] // only repr(C) would add unwanted padding before first_section -#[derive(ptr_meta::Pointee)] +#[derive(ptr_meta::Pointee, PartialEq, Eq)] +#[repr(C)] pub struct CommandLineTag { typ: TagTypeId, size: u32, diff --git a/multiboot2/src/efi.rs b/multiboot2/src/efi.rs index 7cee3b54..ef514c09 100644 --- a/multiboot2/src/efi.rs +++ b/multiboot2/src/efi.rs @@ -9,8 +9,8 @@ use core::mem::size_of; use crate::builder::traits::StructAsBytes; /// EFI system table in 32 bit mode -#[derive(Clone, Copy, Debug)] -#[repr(C, packed)] // only repr(C) would add unwanted padding before first_section +#[derive(Copy, Clone, Debug, PartialEq, Eq)] +#[repr(C)] pub struct EFISdt32 { typ: TagTypeId, size: u32, @@ -41,7 +41,7 @@ impl StructAsBytes for EFISdt32 { } /// EFI system table in 64 bit mode -#[derive(Clone, Copy, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(C)] pub struct EFISdt64 { typ: TagTypeId, @@ -73,7 +73,7 @@ impl StructAsBytes for EFISdt64 { } /// Contains pointer to boot loader image handle. -#[derive(Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(C)] pub struct EFIImageHandle32 { typ: TagTypeId, @@ -105,7 +105,7 @@ impl StructAsBytes for EFIImageHandle32 { } /// Contains pointer to boot loader image handle. -#[derive(Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(C)] pub struct EFIImageHandle64 { typ: TagTypeId, diff --git a/multiboot2/src/elf_sections.rs b/multiboot2/src/elf_sections.rs index 669b23cf..c0385b2c 100644 --- a/multiboot2/src/elf_sections.rs +++ b/multiboot2/src/elf_sections.rs @@ -15,8 +15,8 @@ const METADATA_SIZE: usize = size_of::() + 4 * size_of::(); /// This tag contains section header table from an ELF kernel. /// /// The sections iterator is provided via the `sections` method. -#[derive(ptr_meta::Pointee)] -#[repr(C, packed)] +#[derive(ptr_meta::Pointee, PartialEq, Eq)] +#[repr(C)] pub struct ElfSectionsTag { typ: TagTypeId, pub(crate) size: u32, @@ -142,7 +142,7 @@ impl Default for ElfSectionIter { } /// A single generic ELF Section. -#[derive(Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] pub struct ElfSection { inner: *const u8, string_section: *const u8, @@ -353,7 +353,7 @@ impl ElfSectionInner for ElfSectionInner64 { } /// An enum abstraction over raw ELF section types. -#[derive(PartialEq, Eq, Debug, Copy, Clone)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] #[repr(u32)] pub enum ElfSectionType { /// This value marks the section header as inactive; it does not have an diff --git a/multiboot2/src/framebuffer.rs b/multiboot2/src/framebuffer.rs index 7bbcba73..18423afe 100644 --- a/multiboot2/src/framebuffer.rs +++ b/multiboot2/src/framebuffer.rs @@ -51,8 +51,8 @@ const METADATA_SIZE: usize = size_of::() + 2 * size_of::(); /// The VBE Framebuffer information Tag. -#[derive(Eq, ptr_meta::Pointee)] -#[repr(C, packed)] +#[derive(ptr_meta::Pointee, Eq)] +#[repr(C)] pub struct FramebufferTag { typ: TagTypeId, size: u32, @@ -244,7 +244,7 @@ impl TryFrom for FramebufferTypeId { } /// The type of framebuffer. -#[derive(Debug, PartialEq, Eq)] +#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum FramebufferType<'a> { /// Indexed color. Indexed { @@ -300,7 +300,7 @@ impl<'a> FramebufferType<'a> { } /// An RGB color type field. -#[derive(Debug, PartialEq, Eq)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct FramebufferField { /// Color field position. pub position: u8, @@ -317,8 +317,8 @@ impl StructAsBytes for FramebufferField { } /// A framebuffer color descriptor in the palette. -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -#[repr(C, packed)] // only repr(C) would add unwanted padding at the end +#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[repr(C)] // no align(8) here is correct pub struct FramebufferColor { /// The Red component of the color. pub red: u8, @@ -344,3 +344,14 @@ impl StructAsBytes for FramebufferColor { size_of::() } } + +#[cfg(test)] +mod tests { + use super::*; + + // Compile time test + #[test] + fn test_size() { + assert_eq!(size_of::(), 3) + } +} diff --git a/multiboot2/src/image_load_addr.rs b/multiboot2/src/image_load_addr.rs index 9dca5281..bd5b314f 100644 --- a/multiboot2/src/image_load_addr.rs +++ b/multiboot2/src/image_load_addr.rs @@ -7,7 +7,7 @@ use { /// If the image has relocatable header tag, this tag contains the image's /// base physical address. -#[derive(Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(C)] pub struct ImageLoadPhysAddr { typ: TagTypeId, diff --git a/multiboot2/src/lib.rs b/multiboot2/src/lib.rs index f2a00cd6..d05883e1 100644 --- a/multiboot2/src/lib.rs +++ b/multiboot2/src/lib.rs @@ -173,7 +173,7 @@ pub unsafe fn load_with_offset( /// Error type that describes errors while loading/parsing a multiboot2 information structure /// from a given address. -#[derive(Debug, Display)] +#[derive(Display, Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum MbiLoadError { /// The address is invalid. Make sure that the address is 8-byte aligned, /// according to the spec. @@ -385,7 +385,7 @@ impl BootInformation { /// use std::str::Utf8Error; /// use multiboot2::{Tag, TagTrait, TagTypeId}; /// - /// #[repr(C, align(8))] + /// #[repr(C)] /// #[derive(multiboot2::Pointee)] // Only needed for DSTs. /// struct CustomTag { /// // new type from the lib: has repr(u32) diff --git a/multiboot2/src/memory_map.rs b/multiboot2/src/memory_map.rs index c5ec451c..e69ea81a 100644 --- a/multiboot2/src/memory_map.rs +++ b/multiboot2/src/memory_map.rs @@ -22,7 +22,7 @@ const METADATA_SIZE: usize = mem::size_of::() + 3 * mem::size_of::