Better error handling

This commit is contained in:
Baptiste Wicht 2016-07-23 23:39:40 +02:00
parent 35f55cdbfa
commit 252f46692b
3 changed files with 23 additions and 5 deletions

View File

@ -10,6 +10,7 @@
#include "paging.hpp"
#include "buddy_allocator.hpp"
#include "assert.hpp"
#include "logging.hpp"
#include "fs/sysfs.hpp"
@ -153,11 +154,17 @@ void physical_allocator::finalize(){
}
size_t physical_allocator::allocate(size_t blocks){
thor_assert(blocks < free() / paging::PAGE_SIZE, "Not enough virtual memory");
thor_assert(blocks < free() / paging::PAGE_SIZE, "Not enough physical memory");
allocated_memory += buddy_type::level_size(blocks) * unit;
return allocator.allocate(blocks);
auto phys = allocator.allocate(blocks);
if(!phys){
logging::logf(logging::log_level::ERROR, "palloc: Unable to allocate %u blocks\n", size_t(blocks));
}
return phys;
}
void physical_allocator::free(size_t address, size_t blocks){

View File

@ -222,8 +222,12 @@ void AcpiOsWaitEventsComplete(){
ACPI_PHYSICAL_ADDRESS AcpiOsGetRootPointer(){
ACPI_PHYSICAL_ADDRESS root_pointer;
root_pointer = 0;
AcpiFindRootPointer(&root_pointer);
logging::logf(logging::log_level::TRACE, "acpica: Root pointer at physical address %h\n", size_t(root_pointer));
auto status = AcpiFindRootPointer(&root_pointer);
if(ACPI_FAILURE(status)){
logging::logf(logging::log_level::ERROR, "acpica: Unable to find ACPI root pointer: error: %u\n", size_t(status));
} else {
logging::logf(logging::log_level::TRACE, "acpica: ACPI Root pointer found at physical address %h\n", size_t(root_pointer));
}
return root_pointer;
}

View File

@ -11,6 +11,7 @@
#include "paging.hpp"
#include "buddy_allocator.hpp"
#include "assert.hpp"
#include "logging.hpp"
#include "fs/sysfs.hpp"
@ -85,7 +86,13 @@ size_t virtual_allocator::allocate(size_t pages){
allocated_pages += buddy_type::level_size(pages);
return allocator.allocate(pages);
auto virt = allocator.allocate(pages);
if(!virt){
logging::logf(logging::log_level::ERROR, "valloc: Unable to allocate %u pages\n", size_t(pages));
}
return virt;
}
void virtual_allocator::free(size_t address, size_t pages){