From 21c5ef08227b0a53e4496a51bec91652b35f8166 Mon Sep 17 00:00:00 2001 From: apio Date: Tue, 1 Nov 2022 12:19:48 +0100 Subject: [PATCH] Actually, we can protect the GDT behind a proper mutex --- moon/src/arch/x86_64/gdt.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/moon/src/arch/x86_64/gdt.rs b/moon/src/arch/x86_64/gdt.rs index 493d7043..b8b98394 100644 --- a/moon/src/arch/x86_64/gdt.rs +++ b/moon/src/arch/x86_64/gdt.rs @@ -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 = 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 = 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)); }