From d73f3e09ad666188c98c872ab0d9b11947d54f4c Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Sat, 18 Apr 2020 13:48:15 +0200 Subject: [PATCH] Add InterruptDescriptorTable::load_unsafe (#137) --- src/structures/idt.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/structures/idt.rs b/src/structures/idt.rs index 95fc713d1..171d3baa8 100644 --- a/src/structures/idt.rs +++ b/src/structures/idt.rs @@ -414,6 +414,22 @@ impl InterruptDescriptorTable { #[cfg(target_arch = "x86_64")] #[inline] pub fn load(&'static self) { + unsafe { self.load_unsafe() } + } + + /// Loads the IDT in the CPU using the `lidt` command. + /// + /// # Safety + /// + /// As long as it is the active IDT, you must ensure that: + /// + /// - `self` is never destroyed. + /// - `self` always stays at the same memory location. It is recommended to wrap it in + /// a `Box`. + /// + #[cfg(target_arch = "x86_64")] + #[inline] + pub unsafe fn load_unsafe(&self) { use crate::instructions::tables::{lidt, DescriptorTablePointer}; use core::mem::size_of; @@ -422,7 +438,7 @@ impl InterruptDescriptorTable { limit: (size_of::() - 1) as u16, }; - unsafe { lidt(&ptr) }; + lidt(&ptr); } /// Returns a normalized and ranged check slice range from a RangeBounds trait object