mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 20:15:17 +00:00
Kernel: Removing hardcoded offsets from Memory Manager
Now the kernel page directory and the page tables are located at a safe address, to prevent from paging data colliding with garbage.
This commit is contained in:
parent
39fcd92210
commit
c3c905aa6c
Notes:
sideshowbarker
2024-07-19 11:19:43 +09:00
Author: https://github.com/supercomputer7 Commit: https://github.com/SerenityOS/serenity/commit/c3c905aa6c3 Pull-request: https://github.com/SerenityOS/serenity/pull/741 Reviewed-by: https://github.com/awesomekling
5 changed files with 18 additions and 12 deletions
|
@ -31,6 +31,11 @@ stack_bottom:
|
|||
.skip 32768
|
||||
stack_top:
|
||||
|
||||
.section .page_tables
|
||||
.align 4096
|
||||
page_tables_start:
|
||||
.skip 4096*3
|
||||
|
||||
.section .text
|
||||
|
||||
.global start
|
||||
|
@ -52,7 +57,9 @@ start:
|
|||
|
||||
mov %ebx, multiboot_info_ptr
|
||||
|
||||
pushl $page_tables_start
|
||||
call init
|
||||
add $4, %esp
|
||||
|
||||
pushl $exit_message
|
||||
call kprintf
|
||||
|
|
|
@ -20,13 +20,11 @@ MemoryManager& MM
|
|||
return *s_the;
|
||||
}
|
||||
|
||||
MemoryManager::MemoryManager()
|
||||
MemoryManager::MemoryManager(u32 physical_address_for_kernel_page_tables)
|
||||
{
|
||||
// FIXME: Hard-coding these is stupid. Find a better way.
|
||||
m_kernel_page_directory = PageDirectory::create_at_fixed_address(PhysicalAddress(0x4000));
|
||||
m_page_table_zero = (PageTableEntry*)0x6000;
|
||||
m_page_table_one = (PageTableEntry*)0x7000;
|
||||
|
||||
m_kernel_page_directory = PageDirectory::create_at_fixed_address(PhysicalAddress(physical_address_for_kernel_page_tables));
|
||||
m_page_table_zero = (PageTableEntry*)(physical_address_for_kernel_page_tables + PAGE_SIZE);
|
||||
m_page_table_one = (PageTableEntry*)(physical_address_for_kernel_page_tables + PAGE_SIZE * 2);
|
||||
initialize_paging();
|
||||
|
||||
kprintf("MM initialized.\n");
|
||||
|
@ -262,9 +260,9 @@ void MemoryManager::create_identity_mapping(PageDirectory& page_directory, Virtu
|
|||
}
|
||||
}
|
||||
|
||||
void MemoryManager::initialize()
|
||||
void MemoryManager::initialize(u32 physical_address_for_kernel_page_tables)
|
||||
{
|
||||
s_the = new MemoryManager;
|
||||
s_the = new MemoryManager(physical_address_for_kernel_page_tables);
|
||||
}
|
||||
|
||||
Region* MemoryManager::kernel_region_from_vaddr(VirtualAddress vaddr)
|
||||
|
|
|
@ -38,7 +38,7 @@ class MemoryManager {
|
|||
public:
|
||||
static MemoryManager& the();
|
||||
|
||||
static void initialize();
|
||||
static void initialize(u32 physical_address_for_kernel_page_tables);
|
||||
|
||||
PageFaultResponse handle_page_fault(const PageFault&);
|
||||
|
||||
|
@ -79,7 +79,7 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
MemoryManager();
|
||||
MemoryManager(u32 physical_address_for_kernel_page_tables);
|
||||
~MemoryManager();
|
||||
|
||||
void register_vmo(VMObject&);
|
||||
|
|
|
@ -206,7 +206,7 @@ extern "C" int __cxa_atexit ( void (*)(void *), void *, void *)
|
|||
return 0;
|
||||
}
|
||||
|
||||
extern "C" [[noreturn]] void init()
|
||||
extern "C" [[noreturn]] void init(u32 physical_address_for_kernel_page_tables)
|
||||
{
|
||||
// this is only used one time, directly below here. we can't use this part
|
||||
// of libc at this point in the boot process, or we'd just pull strstr in
|
||||
|
@ -268,7 +268,7 @@ extern "C" [[noreturn]] void init()
|
|||
|
||||
kprintf("Starting Serenity Operating System...\n");
|
||||
|
||||
MemoryManager::initialize();
|
||||
MemoryManager::initialize(physical_address_for_kernel_page_tables);
|
||||
|
||||
if (APIC::init())
|
||||
APIC::enable(0);
|
||||
|
|
|
@ -8,6 +8,7 @@ SECTIONS
|
|||
{
|
||||
Arch/i386/Boot/boot.ao
|
||||
*(.multiboot)
|
||||
*(.page_tables)
|
||||
*(.text)
|
||||
*(.text.startup)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue