Actually, we can protect the GDT behind a proper mutex
This commit is contained in:
parent
f29161fd0b
commit
21c5ef0822
@ -6,13 +6,11 @@ use x86_64::registers::segmentation::{CS, SS, Segment, SegmentSelector};
|
||||
use x86_64::PrivilegeLevel;
|
||||
use spin::Mutex;
|
||||
|
||||
static mut GDT: GlobalDescriptorTable = GlobalDescriptorTable::new();
|
||||
static GDT_LOCK: Mutex<u64> = Mutex::new(0); // we cannot lock the GDT directly as it must stay in the same place in memory and that behaves weirdly with mutexes
|
||||
static GDT: Mutex<GlobalDescriptorTable> = Mutex::new(GlobalDescriptorTable::new());
|
||||
|
||||
fn add_entry(descriptor: Descriptor)
|
||||
{
|
||||
GDT_LOCK.lock();
|
||||
unsafe { GDT.add_entry(descriptor); }
|
||||
GDT.lock().add_entry(descriptor);
|
||||
}
|
||||
|
||||
pub fn init()
|
||||
@ -26,9 +24,8 @@ pub fn init()
|
||||
|
||||
pub fn load_and_reload_segment_registers()
|
||||
{
|
||||
GDT_LOCK.lock();
|
||||
unsafe {
|
||||
GDT.load();
|
||||
unsafe {
|
||||
GDT.lock().load_unsafe();
|
||||
CS::set_reg(SegmentSelector::new(1, PrivilegeLevel::Ring0));
|
||||
SS::set_reg(SegmentSelector::new(2, PrivilegeLevel::Ring0));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user