Kernel: Allow demand paging only for userspace threads

This commit is contained in:
Bananymous 2024-04-17 00:55:45 +03:00
parent f9943b60e4
commit a40ef610a2
2 changed files with 20 additions and 16 deletions

View File

@ -61,7 +61,7 @@ namespace Kernel
vaddr_t kernel_stack_top() const { return m_kernel_stack->vaddr() + m_kernel_stack->size(); } vaddr_t kernel_stack_top() const { return m_kernel_stack->vaddr() + m_kernel_stack->size(); }
VirtualRange& kernel_stack() { return *m_kernel_stack; } VirtualRange& kernel_stack() { return *m_kernel_stack; }
vaddr_t userspace_stack_bottom() const { return is_userspace() ? m_userspace_stack->vaddr() : 0; } vaddr_t userspace_stack_bottom() const { return is_userspace() ? m_userspace_stack->vaddr() : UINTPTR_MAX; }
vaddr_t userspace_stack_top() const { return is_userspace() ? m_userspace_stack->vaddr() + m_userspace_stack->size() : 0; } vaddr_t userspace_stack_top() const { return is_userspace() ? m_userspace_stack->vaddr() + m_userspace_stack->size() : 0; }
VirtualRange& userspace_stack() { ASSERT(is_userspace()); return *m_userspace_stack; } VirtualRange& userspace_stack() { ASSERT(is_userspace()); return *m_userspace_stack; }

View File

@ -194,23 +194,27 @@ namespace Kernel
goto done; goto done;
} }
// Try demand paging on non present pages // Demand paging is only supported in userspace
PageFaultError page_fault_error; if (thread.is_userspace())
page_fault_error.raw = error;
if (!page_fault_error.present)
{ {
Processor::set_interrupt_state(InterruptState::Enabled); // Try demand paging on non present pages
auto result = Process::current().allocate_page_for_demand_paging(regs->cr2); PageFaultError page_fault_error;
Processor::set_interrupt_state(InterruptState::Disabled); page_fault_error.raw = error;
if (!page_fault_error.present)
if (!result.is_error() && result.value())
goto done;
if (result.is_error())
{ {
dwarnln("Demand paging: {}", result.error()); Processor::set_interrupt_state(InterruptState::Enabled);
Thread::current().handle_signal(SIGKILL); auto result = Process::current().allocate_page_for_demand_paging(regs->cr2);
goto done; Processor::set_interrupt_state(InterruptState::Disabled);
if (!result.is_error() && result.value())
goto done;
if (result.is_error())
{
dwarnln("Demand paging: {}", result.error());
Thread::current().handle_signal(SIGKILL);
goto done;
}
} }
} }
} }