Skip to content

Commit 2313b30

Browse files
authored
Use SegmentSelector in InterruptStackFrame (#263)
This makes the value easier to use and slightly improves the `Debug` implementation. Also, change the `InterruptStackFrame` to `#[repr(transparent)]`. It doesn't really matter but makes it clear that `InterruptStackFrame` and `InterruptStackFrameValue` are ABI compatible. Note that this now makes `InterruptStackFrameValue`s imposible to construct, but that seems fine. Signed-off-by: Joe Richey <[email protected]>
1 parent 66952eb commit 2313b30

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/structures/idt.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -781,10 +781,8 @@ impl EntryOptions {
781781
/// This wrapper type ensures that no accidental modification of the interrupt stack frame
782782
/// occurs, which can cause undefined behavior (see the [`as_mut`](InterruptStackFrame::as_mut)
783783
/// method for more information).
784-
#[repr(C)]
785-
pub struct InterruptStackFrame {
786-
value: InterruptStackFrameValue,
787-
}
784+
#[repr(transparent)]
785+
pub struct InterruptStackFrame(InterruptStackFrameValue);
788786

789787
impl InterruptStackFrame {
790788
/// Gives mutable access to the contents of the interrupt stack frame.
@@ -803,7 +801,7 @@ impl InterruptStackFrame {
803801
/// officially supported by LLVM's x86 interrupt calling convention.
804802
#[inline]
805803
pub unsafe fn as_mut(&mut self) -> Volatile<&mut InterruptStackFrameValue> {
806-
Volatile::new(&mut self.value)
804+
Volatile::new(&mut self.0)
807805
}
808806
}
809807

@@ -812,14 +810,14 @@ impl Deref for InterruptStackFrame {
812810

813811
#[inline]
814812
fn deref(&self) -> &Self::Target {
815-
&self.value
813+
&self.0
816814
}
817815
}
818816

819817
impl fmt::Debug for InterruptStackFrame {
820818
#[inline]
821819
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
822-
self.value.fmt(f)
820+
self.0.fmt(f)
823821
}
824822
}
825823

@@ -833,14 +831,16 @@ pub struct InterruptStackFrameValue {
833831
/// this value points to the faulting instruction, so that the instruction is restarted on
834832
/// return. See the documentation of the [`InterruptDescriptorTable`] fields for more details.
835833
pub instruction_pointer: VirtAddr,
836-
/// The code segment selector, padded with zeros.
837-
pub code_segment: u64,
834+
/// The code segment selector at the time of the interrupt.
835+
pub code_segment: SegmentSelector,
836+
_reserved1: [u8; 6],
838837
/// The flags register before the interrupt handler was invoked.
839838
pub cpu_flags: u64,
840839
/// The stack pointer at the time of the interrupt.
841840
pub stack_pointer: VirtAddr,
842841
/// The stack segment descriptor at the time of the interrupt (often zero in 64-bit mode).
843-
pub stack_segment: u64,
842+
pub stack_segment: SegmentSelector,
843+
_reserved2: [u8; 6],
844844
}
845845

846846
impl fmt::Debug for InterruptStackFrameValue {
@@ -899,6 +899,8 @@ mod test {
899899
use core::mem::size_of;
900900
assert_eq!(size_of::<Entry<HandlerFunc>>(), 16);
901901
assert_eq!(size_of::<InterruptDescriptorTable>(), 256 * 16);
902+
assert_eq!(size_of::<InterruptStackFrame>(), 40);
903+
assert_eq!(size_of::<InterruptStackFrameValue>(), 40);
902904
}
903905

904906
#[test]

0 commit comments

Comments
 (0)