Skip to content

Commit 946d096

Browse files
authored
Fix Debug and PartialEq implementations for IDT entry type (#249)
* Fix Debug and PartialEq implementations for IDT entry type * Update changelog for #249
1 parent 1f62c17 commit 946d096

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Unreleased
22

33
- Add support for `sidt` instruction ([#246](https://github.com/rust-osdev/x86_64/pull/246))
4+
- Fix Debug and PartialEq implementations for IDT entry type ([#249](https://github.com/rust-osdev/x86_64/pull/249))
45

56
# 0.14.0 – 2021-04-11
67

src/structures/idt.rs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ impl IndexMut<usize> for InterruptDescriptorTable {
560560
///
561561
/// The generic parameter can either be `HandlerFunc` or `HandlerFuncWithErrCode`, depending
562562
/// on the interrupt vector.
563-
#[derive(Debug, Clone, Copy, PartialEq)]
563+
#[derive(Clone, Copy)]
564564
#[repr(C)]
565565
pub struct Entry<F> {
566566
pointer_low: u16,
@@ -572,6 +572,30 @@ pub struct Entry<F> {
572572
phantom: PhantomData<F>,
573573
}
574574

575+
impl<T> fmt::Debug for Entry<T> {
576+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
577+
f.debug_struct("Entry")
578+
.field("pointer_low", &self.pointer_low)
579+
.field("gdt_selector", &self.gdt_selector)
580+
.field("options", &self.options)
581+
.field("pointer_middle", &self.pointer_middle)
582+
.field("pointer_high", &self.pointer_high)
583+
.field("reserved", &self.reserved)
584+
.finish()
585+
}
586+
}
587+
588+
impl<T> PartialEq for Entry<T> {
589+
fn eq(&self, other: &Self) -> bool {
590+
self.pointer_low == other.pointer_low
591+
&& self.gdt_selector == other.gdt_selector
592+
&& self.options == other.options
593+
&& self.pointer_middle == other.pointer_middle
594+
&& self.pointer_high == other.pointer_high
595+
&& self.reserved == other.reserved
596+
}
597+
}
598+
575599
/// A handler function for an interrupt or an exception without error code.
576600
pub type HandlerFunc = extern "x86-interrupt" fn(InterruptStackFrame);
577601
/// A handler function for an exception that pushes an error code.
@@ -833,4 +857,19 @@ mod test {
833857
assert_eq!(size_of::<Entry<HandlerFunc>>(), 16);
834858
assert_eq!(size_of::<InterruptDescriptorTable>(), 256 * 16);
835859
}
860+
861+
#[test]
862+
fn entry_derive_test() {
863+
fn foo(_: impl Clone + Copy + PartialEq + fmt::Debug) {}
864+
865+
foo(Entry::<HandlerFuncWithErrCode> {
866+
pointer_low: 0,
867+
gdt_selector: 0,
868+
options: EntryOptions(0),
869+
pointer_middle: 0,
870+
pointer_high: 0,
871+
reserved: 0,
872+
phantom: PhantomData,
873+
})
874+
}
836875
}

0 commit comments

Comments
 (0)