mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:08:11 +00:00
Kernel: Repair unaligned regions supplied by the boot loader
We were just blindly trusting that the bootloader would only give us page-aligned memory regions. This is apparently not always the case, so now we can try to repair those regions. Fixes #601
This commit is contained in:
parent
24a51136fa
commit
fa20a447a9
1 changed files with 16 additions and 0 deletions
|
@ -102,6 +102,22 @@ void MemoryManager::initialize_paging()
|
|||
if ((mmap->addr + mmap->len) > 0xffffffff)
|
||||
continue;
|
||||
|
||||
auto diff = (u32)mmap->addr % PAGE_SIZE;
|
||||
if (diff != 0) {
|
||||
kprintf("MM: got an unaligned region base from the bootloader; correcting %p by %d bytes\n", mmap->addr, diff);
|
||||
diff = PAGE_SIZE - diff;
|
||||
mmap->addr += diff;
|
||||
mmap->len -= diff;
|
||||
}
|
||||
if ((mmap->len % PAGE_SIZE) != 0) {
|
||||
kprintf("MM: got an unaligned region length from the bootloader; correcting %d by %d bytes\n", mmap->len, mmap->len % PAGE_SIZE);
|
||||
mmap->len -= mmap->len % PAGE_SIZE;
|
||||
}
|
||||
if (mmap->len < PAGE_SIZE) {
|
||||
kprintf("MM: memory region from bootloader is too small; we want >= %d bytes, but got %d bytes\n", PAGE_SIZE, mmap->len);
|
||||
continue;
|
||||
}
|
||||
|
||||
#ifdef MM_DEBUG
|
||||
kprintf("MM: considering memory at %p - %p\n",
|
||||
(u32)mmap->addr, (u32)(mmap->addr + mmap->len));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue