diff --git a/Kernel/MemoryManager.cpp b/Kernel/MemoryManager.cpp index 755f33c0cd..159a535f32 100644 --- a/Kernel/MemoryManager.cpp +++ b/Kernel/MemoryManager.cpp @@ -304,12 +304,11 @@ bool MemoryManager::page_in_from_inode(Region& region, unsigned page_index_in_re auto& vmo_page = vmo.physical_pages()[region.first_page_index() + page_index_in_region]; - // FIXME: Maybe this should have a separate class like InterruptFlagSaver? - InterruptDisabler disabler; + InterruptFlagSaver saver; - disabler.temporarily_sti(); + sti(); LOCKER(vmo.m_paging_lock); - disabler.temporarily_cli(); + cli(); if (!vmo_page.is_null()) { kprintf("MM: page_in_from_inode() but page already present. Fine with me!\n"); @@ -320,7 +319,7 @@ bool MemoryManager::page_in_from_inode(Region& region, unsigned page_index_in_re #ifdef MM_DEBUG dbgprintf("MM: page_in_from_inode ready to read from inode\n"); #endif - disabler.temporarily_sti(); + sti(); byte page_buffer[PAGE_SIZE]; auto& inode = *vmo.inode(); auto nread = inode.read_bytes(vmo.inode_offset() + ((region.first_page_index() + page_index_in_region) * PAGE_SIZE), PAGE_SIZE, page_buffer, nullptr); @@ -332,7 +331,7 @@ bool MemoryManager::page_in_from_inode(Region& region, unsigned page_index_in_re // If we read less than a page, zero out the rest to avoid leaking uninitialized data. memset(page_buffer + nread, 0, PAGE_SIZE - nread); } - disabler.temporarily_cli(); + cli(); vmo_page = allocate_physical_page(ShouldZeroFill::No); if (vmo_page.is_null()) { kprintf("MM: page_in_from_inode was unable to allocate a physical page\n"); diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 6876776597..40ae38c30e 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -2181,10 +2181,10 @@ int Process::sys$chmod(const char* pathname, mode_t mode) void Process::die() { + destroy_all_windows(); set_state(Dead); m_fds.clear(); m_tty = nullptr; - destroy_all_windows(); InterruptDisabler disabler; if (auto* parent_process = Process::from_pid(m_ppid)) { diff --git a/Kernel/ProcessGUI.cpp b/Kernel/ProcessGUI.cpp index dce8974ecf..b1ec74795b 100644 --- a/Kernel/ProcessGUI.cpp +++ b/Kernel/ProcessGUI.cpp @@ -262,6 +262,8 @@ int Process::gui$set_global_cursor_tracking_enabled(int window_id, bool enabled) void Process::destroy_all_windows() { + InterruptFlagSaver saver; + sti(); for (auto& it : m_windows) { auto message = make(WSMessage::WM_DestroyWindow); it.value->notify_process_died(Badge()); diff --git a/Kernel/Scheduler.cpp b/Kernel/Scheduler.cpp index 377455c569..d63e25ac95 100644 --- a/Kernel/Scheduler.cpp +++ b/Kernel/Scheduler.cpp @@ -12,7 +12,7 @@ static const dword time_slice = 5; // *10 = 50ms Process* current; Process* g_last_fpu_process; static Process* s_colonel_process; -static bool s_in_yield; +static volatile bool s_in_yield; struct TaskRedirectionData { word selector; diff --git a/Kernel/i386.h b/Kernel/i386.h index 23a84e0ab9..bede94a97c 100644 --- a/Kernel/i386.h +++ b/Kernel/i386.h @@ -106,6 +106,25 @@ inline bool are_interrupts_enabled() return cpu_flags() & 0x200; } +class InterruptFlagSaver { +public: + InterruptFlagSaver() + { + m_flags = cpu_flags(); + } + + ~InterruptFlagSaver() + { + if (m_flags & 0x200) + sti(); + else + cli(); + } + +private: + dword m_flags; +}; + class InterruptDisabler { public: InterruptDisabler() @@ -120,16 +139,6 @@ public: sti(); } - void temporarily_cli() - { - cli(); - } - - void temporarily_sti() - { - sti(); - } - private: dword m_flags; };