From 819824e020bf6ab001077b4ae48de9f33d778349 Mon Sep 17 00:00:00 2001 From: Pawel Dziepak Date: Mon, 27 Jan 2014 02:23:41 +0100 Subject: [PATCH] kernel/{x86, vm}: Add more error checks in VM initialization --- .../kernel/arch/x86/paging/32bit/X86PagingMethod32Bit.cpp | 5 +++++ src/system/kernel/arch/x86/paging/pae/X86PagingMethodPAE.cpp | 5 +++++ src/system/kernel/vm/vm.cpp | 4 ++++ 3 files changed, 14 insertions(+) diff --git a/src/system/kernel/arch/x86/paging/32bit/X86PagingMethod32Bit.cpp b/src/system/kernel/arch/x86/paging/32bit/X86PagingMethod32Bit.cpp index 64c93cf8be..c75942adf4 100644 --- a/src/system/kernel/arch/x86/paging/32bit/X86PagingMethod32Bit.cpp +++ b/src/system/kernel/arch/x86/paging/32bit/X86PagingMethod32Bit.cpp @@ -101,6 +101,11 @@ X86PagingMethod32Bit::PhysicalPageSlotPool::InitInitial(kernel_args* args) size_t areaSize = B_PAGE_SIZE + sizeof(PhysicalPageSlot[1024]); page_table_entry* pageTable = (page_table_entry*)vm_allocate_early(args, areaSize, ~0L, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA, 0); + if (pageTable == 0) { + panic("X86PagingMethod32Bit::PhysicalPageSlotPool::InitInitial(): " + "Failed to allocate memory for page table!"); + return B_ERROR; + } // prepare the page table _EarlyPreparePageTables(pageTable, virtualBase, 1024 * B_PAGE_SIZE); diff --git a/src/system/kernel/arch/x86/paging/pae/X86PagingMethodPAE.cpp b/src/system/kernel/arch/x86/paging/pae/X86PagingMethodPAE.cpp index 089f0ccb84..73fafd55ad 100644 --- a/src/system/kernel/arch/x86/paging/pae/X86PagingMethodPAE.cpp +++ b/src/system/kernel/arch/x86/paging/pae/X86PagingMethodPAE.cpp @@ -409,6 +409,11 @@ X86PagingMethodPAE::PhysicalPageSlotPool::InitInitial( + sizeof(PhysicalPageSlot[kPAEPageTableEntryCount]); pae_page_table_entry* pageTable = (pae_page_table_entry*)vm_allocate_early( args, areaSize, ~0L, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA, 0); + if (pageTable == 0) { + panic("X86PagingMethodPAE::PhysicalPageSlotPool::InitInitial(): Failed " + "to allocate memory for page table!"); + return B_ERROR; + } // clear the page table and put it in the page dir memset(pageTable, 0, B_PAGE_SIZE); diff --git a/src/system/kernel/vm/vm.cpp b/src/system/kernel/vm/vm.cpp index d700fe5e52..0f705ceb26 100644 --- a/src/system/kernel/vm/vm.cpp +++ b/src/system/kernel/vm/vm.cpp @@ -3910,6 +3910,10 @@ vm_allocate_early(kernel_args* args, size_t virtualSize, size_t physicalSize, // find the vaddr to allocate at addr_t virtualBase = allocate_early_virtual(args, virtualSize, alignment); //dprintf("vm_allocate_early: vaddr 0x%lx\n", virtualBase); + if (virtualBase == 0) { + panic("vm_allocate_early: could not allocate virtual address\n"); + return 0; + } // map the pages for (uint32 i = 0; i < PAGE_ALIGN(physicalSize) / B_PAGE_SIZE; i++) {