mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 18:25:07 +00:00
Kernel: Move end_of_kernel_image after the .ksyms section
Without this we won't be able to detect whether .ksyms overlaps the end of the page table we set up for the kernel image.
This commit is contained in:
parent
acf8f2a2a3
commit
cbdb488578
5 changed files with 38 additions and 5 deletions
|
@ -29,6 +29,8 @@ extern FlatPtr start_of_unmap_after_init;
|
||||||
extern FlatPtr end_of_unmap_after_init;
|
extern FlatPtr end_of_unmap_after_init;
|
||||||
extern FlatPtr start_of_ro_after_init;
|
extern FlatPtr start_of_ro_after_init;
|
||||||
extern FlatPtr end_of_ro_after_init;
|
extern FlatPtr end_of_ro_after_init;
|
||||||
|
extern FlatPtr start_of_kernel_ksyms;
|
||||||
|
extern FlatPtr end_of_kernel_ksyms;
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
|
@ -335,6 +337,11 @@ void page_fault_handler(TrapFrame* trap)
|
||||||
PANIC("Attempt to access UNMAP_AFTER_INIT section");
|
PANIC("Attempt to access UNMAP_AFTER_INIT section");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fault_address >= (FlatPtr)&start_of_kernel_ksyms && fault_address < (FlatPtr)&end_of_kernel_ksyms) {
|
||||||
|
dump(regs);
|
||||||
|
PANIC("Attempt to access KSYMS section");
|
||||||
|
}
|
||||||
|
|
||||||
PageFault fault { regs.exception_code, VirtualAddress { fault_address } };
|
PageFault fault { regs.exception_code, VirtualAddress { fault_address } };
|
||||||
auto response = MM.handle_page_fault(fault);
|
auto response = MM.handle_page_fault(fault);
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,8 @@ extern FlatPtr start_of_ro_after_init;
|
||||||
extern FlatPtr end_of_ro_after_init;
|
extern FlatPtr end_of_ro_after_init;
|
||||||
extern FlatPtr start_of_unmap_after_init;
|
extern FlatPtr start_of_unmap_after_init;
|
||||||
extern FlatPtr end_of_unmap_after_init;
|
extern FlatPtr end_of_unmap_after_init;
|
||||||
|
extern FlatPtr start_of_kernel_ksyms;
|
||||||
|
extern FlatPtr end_of_kernel_ksyms;
|
||||||
|
|
||||||
extern multiboot_module_entry_t multiboot_copy_boot_modules_array[16];
|
extern multiboot_module_entry_t multiboot_copy_boot_modules_array[16];
|
||||||
extern size_t multiboot_copy_boot_modules_count;
|
extern size_t multiboot_copy_boot_modules_count;
|
||||||
|
@ -114,7 +116,7 @@ UNMAP_AFTER_INIT void MemoryManager::protect_readonly_after_init_memory()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MemoryManager::unmap_memory_after_init()
|
void MemoryManager::unmap_text_after_init()
|
||||||
{
|
{
|
||||||
ScopedSpinLock mm_lock(s_mm_lock);
|
ScopedSpinLock mm_lock(s_mm_lock);
|
||||||
ScopedSpinLock page_lock(kernel_page_directory().get_lock());
|
ScopedSpinLock page_lock(kernel_page_directory().get_lock());
|
||||||
|
@ -130,7 +132,24 @@ void MemoryManager::unmap_memory_after_init()
|
||||||
}
|
}
|
||||||
|
|
||||||
dmesgln("Unmapped {} KiB of kernel text after init! :^)", (end - start) / KiB);
|
dmesgln("Unmapped {} KiB of kernel text after init! :^)", (end - start) / KiB);
|
||||||
//Processor::halt();
|
}
|
||||||
|
|
||||||
|
void MemoryManager::unmap_ksyms_after_init()
|
||||||
|
{
|
||||||
|
ScopedSpinLock mm_lock(s_mm_lock);
|
||||||
|
ScopedSpinLock page_lock(kernel_page_directory().get_lock());
|
||||||
|
|
||||||
|
auto start = page_round_down((FlatPtr)&start_of_kernel_ksyms);
|
||||||
|
auto end = page_round_up((FlatPtr)&end_of_kernel_ksyms);
|
||||||
|
|
||||||
|
// Unmap the entire .ksyms section
|
||||||
|
for (auto i = start; i < end; i += PAGE_SIZE) {
|
||||||
|
auto& pte = *ensure_pte(kernel_page_directory(), VirtualAddress(i));
|
||||||
|
pte.clear();
|
||||||
|
flush_tlb(&kernel_page_directory(), VirtualAddress(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
dmesgln("Unmapped {} KiB of kernel symbols after init! :^)", (end - start) / KiB);
|
||||||
}
|
}
|
||||||
|
|
||||||
UNMAP_AFTER_INIT void MemoryManager::register_reserved_ranges()
|
UNMAP_AFTER_INIT void MemoryManager::register_reserved_ranges()
|
||||||
|
|
|
@ -126,7 +126,8 @@ public:
|
||||||
void set_page_writable_direct(VirtualAddress, bool);
|
void set_page_writable_direct(VirtualAddress, bool);
|
||||||
|
|
||||||
void protect_readonly_after_init_memory();
|
void protect_readonly_after_init_memory();
|
||||||
void unmap_memory_after_init();
|
void unmap_text_after_init();
|
||||||
|
void unmap_ksyms_after_init();
|
||||||
|
|
||||||
static void enter_process_paging_scope(Process&);
|
static void enter_process_paging_scope(Process&);
|
||||||
static void enter_space(Space&);
|
static void enter_space(Space&);
|
||||||
|
|
|
@ -273,7 +273,10 @@ void init_stage2(void*)
|
||||||
MM.protect_readonly_after_init_memory();
|
MM.protect_readonly_after_init_memory();
|
||||||
|
|
||||||
// NOTE: Everything marked UNMAP_AFTER_INIT becomes inaccessible after this point.
|
// NOTE: Everything marked UNMAP_AFTER_INIT becomes inaccessible after this point.
|
||||||
MM.unmap_memory_after_init();
|
MM.unmap_text_after_init();
|
||||||
|
|
||||||
|
// NOTE: Everything in the .ksyms section becomes inaccessible after this point.
|
||||||
|
MM.unmap_ksyms_after_init();
|
||||||
|
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
|
|
|
@ -93,10 +93,13 @@ SECTIONS
|
||||||
*(.heap)
|
*(.heap)
|
||||||
} :bss
|
} :bss
|
||||||
|
|
||||||
end_of_kernel_image = .;
|
|
||||||
|
|
||||||
.ksyms ALIGN(4K) : AT (ADDR(.ksyms) - KERNEL_VIRTUAL_BASE)
|
.ksyms ALIGN(4K) : AT (ADDR(.ksyms) - KERNEL_VIRTUAL_BASE)
|
||||||
{
|
{
|
||||||
|
start_of_kernel_ksyms = .;
|
||||||
*(.kernel_symbols)
|
*(.kernel_symbols)
|
||||||
|
end_of_kernel_ksyms = .;
|
||||||
} :ksyms
|
} :ksyms
|
||||||
|
|
||||||
|
end_of_kernel_image = .;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue