Page fault when using kmalloc
Posted: Thu Aug 18, 2016 5:43 am
Hi! I'm following updated JamesM's tutorial series(here's a link). I implemented vmm, pmm and heap. But when i use kmalloc(), i get a page fault.
Here's the kmalloc function:
Here's the kmalloc function:
Code: Select all
void *kmalloc (uint32_t l)
{
l += sizeof (header_t);
header_t *cur_header = heap_first, *prev_header = 0;
while (cur_header)
{
if (cur_header->allocated == 0 && cur_header->length >= l)
{
split_chunk (cur_header, l);
cur_header->allocated = 1;
return (void*) ((uint32_t)cur_header + sizeof (header_t));
}
prev_header = cur_header;
cur_header = cur_header->next;
}
uint32_t chunk_start;
if (prev_header) chunk_start = (uint32_t)prev_header + prev_header->length;
else
{
chunk_start = HEAP_START;
heap_first = (header_t *)chunk_start;
}
alloc_chunk (chunk_start, l);
cur_header = (header_t *)chunk_start;
cur_header->prev = prev_header;
cur_header->next = 0;
cur_header->allocated = 1;
cur_header->length = l;
prev_header->next = cur_header;
return (void*) (chunk_start + sizeof (header_t));
}