mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-27 01:50:24 +00:00
Kernel: Move ring0 stacks out of kmalloc_eternal
This allows us to use all the same fun memory protection features as the rest of the system for ring0 processes. Previously a ring0 process could over- or underrun its stack and nobody cared, since kmalloc_eternal is the wild west of memory.
This commit is contained in:
parent
3aaeff483b
commit
b557aab884
Notes:
sideshowbarker
2024-07-19 10:44:29 +09:00
Author: https://github.com/deoxxa Commit: https://github.com/SerenityOS/serenity/commit/b557aab8845 Pull-request: https://github.com/SerenityOS/serenity/pull/904 Reviewed-by: https://github.com/awesomekling
1 changed files with 7 additions and 6 deletions
|
@ -84,20 +84,21 @@ Thread::Thread(Process& process)
|
|||
m_tss.cr3 = m_process.page_directory().cr3();
|
||||
|
||||
if (m_process.is_ring0()) {
|
||||
// FIXME: This memory is leaked.
|
||||
// But uh, there's also no kernel process termination, so I guess it's not technically leaked...
|
||||
m_kernel_stack_base = (u32)kmalloc_eternal(default_kernel_stack_size);
|
||||
m_kernel_stack_top = (m_kernel_stack_base + default_kernel_stack_size) & 0xfffffff8u;
|
||||
m_kernel_stack_region = MM.allocate_kernel_region(default_kernel_stack_size, String::format("Kernel Stack (Thread %d; Ring0)", m_tid), false, true);
|
||||
m_kernel_stack_base = m_kernel_stack_region->vaddr().get();
|
||||
m_kernel_stack_top = m_kernel_stack_region->vaddr().offset(default_kernel_stack_size).get() & 0xfffffff8u;
|
||||
m_tss.esp = m_kernel_stack_top;
|
||||
|
||||
kprintf("Allocated ring0 stack @ %p - %p\n", m_kernel_stack_base, m_kernel_stack_top);
|
||||
} else {
|
||||
// Ring3 processes need a separate stack for Ring0.
|
||||
m_kernel_stack_region = MM.allocate_kernel_region(default_kernel_stack_size, String::format("Kernel Stack (Thread %d)", m_tid));
|
||||
m_kernel_stack_region = MM.allocate_kernel_region(default_kernel_stack_size, String::format("Kernel Stack (Thread %d; Ring3)", m_tid), false, true);
|
||||
m_kernel_stack_base = m_kernel_stack_region->vaddr().get();
|
||||
m_kernel_stack_top = m_kernel_stack_region->vaddr().offset(default_kernel_stack_size).get() & 0xfffffff8u;
|
||||
m_tss.ss0 = 0x10;
|
||||
m_tss.esp0 = m_kernel_stack_top;
|
||||
kprintf("Allocated ring3 stack @ %p - %p\n", m_kernel_stack_base, m_kernel_stack_top);
|
||||
}
|
||||
m_process.page_directory().update_kernel_mappings();
|
||||
|
||||
// HACK: Ring2 SS in the TSS is the current PID.
|
||||
m_tss.ss2 = m_process.pid();
|
||||
|
|
Loading…
Reference in a new issue