Improved get_free_resource_slot()
Table now tries to expand itself when no available slots are left
This commit is contained in:
@@ -52,7 +52,7 @@ int load_module(struct kernel_t *kernel, struct module_t *module)
|
||||
}
|
||||
load_offset += page_size;
|
||||
}
|
||||
int index = find_resource_slot(kernel);
|
||||
int index = get_free_resource_slot(kernel, kernel->page_stack);
|
||||
if(index < 0)
|
||||
{
|
||||
panic("no space left in resource table for module");
|
||||
|
||||
@@ -1,13 +1,31 @@
|
||||
#include "resource.h"
|
||||
#include "mmgr.h"
|
||||
#include "allocator.h"
|
||||
#include "types/status.h"
|
||||
|
||||
int find_resource_slot(struct resource_table_t *table)
|
||||
int get_free_resource_slot(struct resource_table_t *table, struct page_stack_t *page_stack)
|
||||
{
|
||||
for(int i = 0; i < table->capacity; i++)
|
||||
if(table == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
size_t capacity = table->limit - table->array;
|
||||
for(int i = 0; i < capacity; i++)
|
||||
{
|
||||
if(table->array[i].type == RESOURCE_UNAVAILABLE)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
void *new_limit = allocate_from_bottom(page_size);
|
||||
if(new_limit != NULL)
|
||||
{
|
||||
if(map_page(page_stack, new_limit, reserve_page(page_stack), PAGE_RW) != S_OK)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
table->limit = (struct resource_t*)(new_limit + page_size);
|
||||
return get_free_resource_slot(table, page_stack);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user