Skip to content

Commit

Permalink
Fix Debug and PartialEq implementations for IDT entry type (#249)
Browse files Browse the repository at this point in the history
* Fix Debug and PartialEq implementations for IDT entry type

* Update changelog for #249
  • Loading branch information
phil-opp authored Apr 27, 2021
1 parent 1f62c17 commit 946d096
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Unreleased

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

# 0.14.0 – 2021-04-11

Expand Down
41 changes: 40 additions & 1 deletion src/structures/idt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ impl IndexMut<usize> for InterruptDescriptorTable {
///
/// The generic parameter can either be `HandlerFunc` or `HandlerFuncWithErrCode`, depending
/// on the interrupt vector.
#[derive(Debug, Clone, Copy, PartialEq)]
#[derive(Clone, Copy)]
#[repr(C)]
pub struct Entry<F> {
pointer_low: u16,
Expand All @@ -572,6 +572,30 @@ pub struct Entry<F> {
phantom: PhantomData<F>,
}

impl<T> fmt::Debug for Entry<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Entry")
.field("pointer_low", &self.pointer_low)
.field("gdt_selector", &self.gdt_selector)
.field("options", &self.options)
.field("pointer_middle", &self.pointer_middle)
.field("pointer_high", &self.pointer_high)
.field("reserved", &self.reserved)
.finish()
}
}

impl<T> PartialEq for Entry<T> {
fn eq(&self, other: &Self) -> bool {
self.pointer_low == other.pointer_low
&& self.gdt_selector == other.gdt_selector
&& self.options == other.options
&& self.pointer_middle == other.pointer_middle
&& self.pointer_high == other.pointer_high
&& self.reserved == other.reserved
}
}

/// A handler function for an interrupt or an exception without error code.
pub type HandlerFunc = extern "x86-interrupt" fn(InterruptStackFrame);
/// A handler function for an exception that pushes an error code.
Expand Down Expand Up @@ -833,4 +857,19 @@ mod test {
assert_eq!(size_of::<Entry<HandlerFunc>>(), 16);
assert_eq!(size_of::<InterruptDescriptorTable>(), 256 * 16);
}

#[test]
fn entry_derive_test() {
fn foo(_: impl Clone + Copy + PartialEq + fmt::Debug) {}

foo(Entry::<HandlerFuncWithErrCode> {
pointer_low: 0,
gdt_selector: 0,
options: EntryOptions(0),
pointer_middle: 0,
pointer_high: 0,
reserved: 0,
phantom: PhantomData,
})
}
}

0 comments on commit 946d096

Please sign in to comment.