From bf3c5ca78465f33184e7883665fc0d6023a18d44 Mon Sep 17 00:00:00 2001 From: Tom Dohrmann Date: Mon, 25 Oct 2021 14:03:47 +0200 Subject: [PATCH 1/3] add derives to number and range types --- src/addr.rs | 4 ++-- src/instructions/tlb.rs | 2 +- src/registers/segmentation.rs | 2 +- src/structures/paging/frame.rs | 6 +++--- src/structures/paging/page.rs | 6 +++--- src/structures/paging/page_table.rs | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/addr.rs b/src/addr.rs index 4c962e2b4..d796a0e35 100644 --- a/src/addr.rs +++ b/src/addr.rs @@ -17,7 +17,7 @@ use bit_field::BitField; /// On `x86_64`, only the 48 lower bits of a virtual address can be used. The top 16 bits need /// to be copies of bit 47, i.e. the most significant bit. Addresses that fulfil this criterium /// are called “canonical”. This type guarantees that it always represents a canonical address. -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] #[repr(transparent)] pub struct VirtAddr(u64); @@ -30,7 +30,7 @@ pub struct VirtAddr(u64); /// /// On `x86_64`, only the 52 lower bits of a physical address can be used. The top 12 bits need /// to be zero. This type guarantees that it always represents a valid physical address. -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] #[repr(transparent)] pub struct PhysAddr(u64); diff --git a/src/instructions/tlb.rs b/src/instructions/tlb.rs index 6e93f905d..008dfadff 100644 --- a/src/instructions/tlb.rs +++ b/src/instructions/tlb.rs @@ -49,7 +49,7 @@ struct InvpcidDescriptor { /// Structure of a PCID. A PCID has to be <= 4096 for x86_64. #[repr(transparent)] -#[derive(Debug)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct Pcid(u16); impl Pcid { diff --git a/src/registers/segmentation.rs b/src/registers/segmentation.rs index c62fff281..be497d075 100644 --- a/src/registers/segmentation.rs +++ b/src/registers/segmentation.rs @@ -62,7 +62,7 @@ pub trait Segment64: Segment { /// with some additional flags). /// /// See Intel 3a, Section 3.4.2 "Segment Selectors" -#[derive(Clone, Copy, PartialEq, Eq)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] #[repr(transparent)] pub struct SegmentSelector(pub u16); diff --git a/src/structures/paging/frame.rs b/src/structures/paging/frame.rs index f125404fc..bc11f9de3 100644 --- a/src/structures/paging/frame.rs +++ b/src/structures/paging/frame.rs @@ -8,7 +8,7 @@ use core::marker::PhantomData; use core::ops::{Add, AddAssign, Sub, SubAssign}; /// A physical memory frame. -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] #[repr(C)] pub struct PhysFrame { pub(crate) start_address: PhysAddr, // TODO: remove when start_address() is const @@ -133,7 +133,7 @@ impl Sub> for PhysFrame { } /// An range of physical memory frames, exclusive the upper bound. -#[derive(Clone, Copy, PartialEq, Eq)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] #[repr(C)] pub struct PhysFrameRange { /// The start of the range, inclusive. @@ -175,7 +175,7 @@ impl fmt::Debug for PhysFrameRange { } /// An range of physical memory frames, inclusive the upper bound. -#[derive(Clone, Copy, PartialEq, Eq)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] #[repr(C)] pub struct PhysFrameRangeInclusive { /// The start of the range, inclusive. diff --git a/src/structures/paging/page.rs b/src/structures/paging/page.rs index 0e9136dd0..003315922 100644 --- a/src/structures/paging/page.rs +++ b/src/structures/paging/page.rs @@ -53,7 +53,7 @@ impl PageSize for Size1GiB { } /// A virtual memory page. -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] #[repr(C)] pub struct Page { start_address: VirtAddr, @@ -279,7 +279,7 @@ impl Sub for Page { } /// A range of pages with exclusive upper bound. -#[derive(Clone, Copy, PartialEq, Eq)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] #[repr(C)] pub struct PageRange { /// The start of the range, inclusive. @@ -332,7 +332,7 @@ impl fmt::Debug for PageRange { } /// A range of pages with inclusive upper bound. -#[derive(Clone, Copy, PartialEq, Eq)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] #[repr(C)] pub struct PageRangeInclusive { /// The start of the range, inclusive. diff --git a/src/structures/paging/page_table.rs b/src/structures/paging/page_table.rs index 3481b184a..b827c8a5a 100644 --- a/src/structures/paging/page_table.rs +++ b/src/structures/paging/page_table.rs @@ -268,7 +268,7 @@ impl fmt::Debug for PageTable { /// Can be used to select one of the 512 entries of a page table. /// /// Guaranteed to only ever contain 0..512. -#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct PageTableIndex(u16); impl PageTableIndex { @@ -319,7 +319,7 @@ impl From for usize { /// This type is returned by the `VirtAddr::page_offset` method. /// /// Guaranteed to only ever contain 0..4096. -#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct PageOffset(u16); impl PageOffset { From f1560137dd7e060497430576560b280ef3291d61 Mon Sep 17 00:00:00 2001 From: Tom Dohrmann Date: Mon, 25 Oct 2021 14:04:14 +0200 Subject: [PATCH 2/3] add derives to enum types --- src/lib.rs | 2 +- src/structures/idt.rs | 2 +- src/structures/paging/page_table.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 73a6c5061..9bdab155d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -67,7 +67,7 @@ pub mod registers; pub mod structures; /// Represents a protection ring level. -#[derive(Debug, Copy, Clone, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[repr(u8)] pub enum PrivilegeLevel { /// Privilege-level 0 (most privilege): This level is used by critical system-software diff --git a/src/structures/idt.rs b/src/structures/idt.rs index 5b0d9d1ba..a3c0611f2 100644 --- a/src/structures/idt.rs +++ b/src/structures/idt.rs @@ -1001,7 +1001,7 @@ impl fmt::Debug for SelectorErrorCode { /// The possible descriptor table values. /// /// Used by the [`SelectorErrorCode`] to indicate which table caused the error. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum DescriptorTable { /// Global Descriptor Table. Gdt, diff --git a/src/structures/paging/page_table.rs b/src/structures/paging/page_table.rs index b827c8a5a..5ae35298e 100644 --- a/src/structures/paging/page_table.rs +++ b/src/structures/paging/page_table.rs @@ -365,7 +365,7 @@ impl From for usize { } } -#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] /// A value between 1 and 4. pub enum PageTableLevel { /// Represents the level for a page table. From 640d425b2a52640c6b5a49794d8b10a001679abe Mon Sep 17 00:00:00 2001 From: Tom Dohrmann Date: Sun, 7 Nov 2021 12:23:27 +0100 Subject: [PATCH 3/3] remove some `PartialOrd`, `Ord` derives --- src/lib.rs | 2 +- src/structures/idt.rs | 2 +- src/structures/paging/frame.rs | 4 ++-- src/structures/paging/page.rs | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 9bdab155d..652dd5130 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -67,7 +67,7 @@ pub mod registers; pub mod structures; /// Represents a protection ring level. -#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] #[repr(u8)] pub enum PrivilegeLevel { /// Privilege-level 0 (most privilege): This level is used by critical system-software diff --git a/src/structures/idt.rs b/src/structures/idt.rs index a3c0611f2..5b0d9d1ba 100644 --- a/src/structures/idt.rs +++ b/src/structures/idt.rs @@ -1001,7 +1001,7 @@ impl fmt::Debug for SelectorErrorCode { /// The possible descriptor table values. /// /// Used by the [`SelectorErrorCode`] to indicate which table caused the error. -#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub enum DescriptorTable { /// Global Descriptor Table. Gdt, diff --git a/src/structures/paging/frame.rs b/src/structures/paging/frame.rs index bc11f9de3..e95f82a17 100644 --- a/src/structures/paging/frame.rs +++ b/src/structures/paging/frame.rs @@ -133,7 +133,7 @@ impl Sub> for PhysFrame { } /// An range of physical memory frames, exclusive the upper bound. -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Clone, Copy, PartialEq, Eq, Hash)] #[repr(C)] pub struct PhysFrameRange { /// The start of the range, inclusive. @@ -175,7 +175,7 @@ impl fmt::Debug for PhysFrameRange { } /// An range of physical memory frames, inclusive the upper bound. -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Clone, Copy, PartialEq, Eq, Hash)] #[repr(C)] pub struct PhysFrameRangeInclusive { /// The start of the range, inclusive. diff --git a/src/structures/paging/page.rs b/src/structures/paging/page.rs index 003315922..4f7f62c76 100644 --- a/src/structures/paging/page.rs +++ b/src/structures/paging/page.rs @@ -279,7 +279,7 @@ impl Sub for Page { } /// A range of pages with exclusive upper bound. -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Clone, Copy, PartialEq, Eq, Hash)] #[repr(C)] pub struct PageRange { /// The start of the range, inclusive. @@ -332,7 +332,7 @@ impl fmt::Debug for PageRange { } /// A range of pages with inclusive upper bound. -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Clone, Copy, PartialEq, Eq, Hash)] #[repr(C)] pub struct PageRangeInclusive { /// The start of the range, inclusive.