mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 11:08:12 +00:00
Kernel: Add an InterruptFlagSaver helper class.
This is useful instead of InterruptDisabler in some cases.
This commit is contained in:
parent
cd1bbdf052
commit
b782055b96
5 changed files with 28 additions and 18 deletions
|
@ -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];
|
auto& vmo_page = vmo.physical_pages()[region.first_page_index() + page_index_in_region];
|
||||||
|
|
||||||
// FIXME: Maybe this should have a separate class like InterruptFlagSaver?
|
InterruptFlagSaver saver;
|
||||||
InterruptDisabler disabler;
|
|
||||||
|
|
||||||
disabler.temporarily_sti();
|
sti();
|
||||||
LOCKER(vmo.m_paging_lock);
|
LOCKER(vmo.m_paging_lock);
|
||||||
disabler.temporarily_cli();
|
cli();
|
||||||
|
|
||||||
if (!vmo_page.is_null()) {
|
if (!vmo_page.is_null()) {
|
||||||
kprintf("MM: page_in_from_inode() but page already present. Fine with me!\n");
|
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
|
#ifdef MM_DEBUG
|
||||||
dbgprintf("MM: page_in_from_inode ready to read from inode\n");
|
dbgprintf("MM: page_in_from_inode ready to read from inode\n");
|
||||||
#endif
|
#endif
|
||||||
disabler.temporarily_sti();
|
sti();
|
||||||
byte page_buffer[PAGE_SIZE];
|
byte page_buffer[PAGE_SIZE];
|
||||||
auto& inode = *vmo.inode();
|
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);
|
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.
|
// If we read less than a page, zero out the rest to avoid leaking uninitialized data.
|
||||||
memset(page_buffer + nread, 0, PAGE_SIZE - nread);
|
memset(page_buffer + nread, 0, PAGE_SIZE - nread);
|
||||||
}
|
}
|
||||||
disabler.temporarily_cli();
|
cli();
|
||||||
vmo_page = allocate_physical_page(ShouldZeroFill::No);
|
vmo_page = allocate_physical_page(ShouldZeroFill::No);
|
||||||
if (vmo_page.is_null()) {
|
if (vmo_page.is_null()) {
|
||||||
kprintf("MM: page_in_from_inode was unable to allocate a physical page\n");
|
kprintf("MM: page_in_from_inode was unable to allocate a physical page\n");
|
||||||
|
|
|
@ -2181,10 +2181,10 @@ int Process::sys$chmod(const char* pathname, mode_t mode)
|
||||||
|
|
||||||
void Process::die()
|
void Process::die()
|
||||||
{
|
{
|
||||||
|
destroy_all_windows();
|
||||||
set_state(Dead);
|
set_state(Dead);
|
||||||
m_fds.clear();
|
m_fds.clear();
|
||||||
m_tty = nullptr;
|
m_tty = nullptr;
|
||||||
destroy_all_windows();
|
|
||||||
|
|
||||||
InterruptDisabler disabler;
|
InterruptDisabler disabler;
|
||||||
if (auto* parent_process = Process::from_pid(m_ppid)) {
|
if (auto* parent_process = Process::from_pid(m_ppid)) {
|
||||||
|
|
|
@ -262,6 +262,8 @@ int Process::gui$set_global_cursor_tracking_enabled(int window_id, bool enabled)
|
||||||
|
|
||||||
void Process::destroy_all_windows()
|
void Process::destroy_all_windows()
|
||||||
{
|
{
|
||||||
|
InterruptFlagSaver saver;
|
||||||
|
sti();
|
||||||
for (auto& it : m_windows) {
|
for (auto& it : m_windows) {
|
||||||
auto message = make<WSMessage>(WSMessage::WM_DestroyWindow);
|
auto message = make<WSMessage>(WSMessage::WM_DestroyWindow);
|
||||||
it.value->notify_process_died(Badge<Process>());
|
it.value->notify_process_died(Badge<Process>());
|
||||||
|
|
|
@ -12,7 +12,7 @@ static const dword time_slice = 5; // *10 = 50ms
|
||||||
Process* current;
|
Process* current;
|
||||||
Process* g_last_fpu_process;
|
Process* g_last_fpu_process;
|
||||||
static Process* s_colonel_process;
|
static Process* s_colonel_process;
|
||||||
static bool s_in_yield;
|
static volatile bool s_in_yield;
|
||||||
|
|
||||||
struct TaskRedirectionData {
|
struct TaskRedirectionData {
|
||||||
word selector;
|
word selector;
|
||||||
|
|
|
@ -106,6 +106,25 @@ inline bool are_interrupts_enabled()
|
||||||
return cpu_flags() & 0x200;
|
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 {
|
class InterruptDisabler {
|
||||||
public:
|
public:
|
||||||
InterruptDisabler()
|
InterruptDisabler()
|
||||||
|
@ -120,16 +139,6 @@ public:
|
||||||
sti();
|
sti();
|
||||||
}
|
}
|
||||||
|
|
||||||
void temporarily_cli()
|
|
||||||
{
|
|
||||||
cli();
|
|
||||||
}
|
|
||||||
|
|
||||||
void temporarily_sti()
|
|
||||||
{
|
|
||||||
sti();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
dword m_flags;
|
dword m_flags;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue