1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 08:58:11 +00:00

Kernel: Add an InterruptFlagSaver helper class.

This is useful instead of InterruptDisabler in some cases.
This commit is contained in:
Andreas Kling 2019-02-05 11:13:34 +01:00
parent cd1bbdf052
commit b782055b96
5 changed files with 28 additions and 18 deletions

View file

@ -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");

View file

@ -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)) {

View file

@ -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>(WSMessage::WM_DestroyWindow);
it.value->notify_process_died(Badge<Process>());

View file

@ -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;

View file

@ -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;
};