Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
FixR
Posts: 2 Joined: Thu Aug 11, 2016 8:29 am
Post
by FixR » 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:
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));
}
FixR
Posts: 2 Joined: Thu Aug 11, 2016 8:29 am
Post
by FixR » Thu Aug 18, 2016 7:54 am
The problem is in alloc_chunk function, because the text doesn't appear.
Code: Select all
alloc_chunk (chunk_start, l);
printf("It works!");
cur_header = (header_t *)chunk_start;
cur_header->prev = prev_header;
cur_header->next = 0;
cur_header->allocated = 1;
cur_header->length = l;
Here's the function:
Code: Select all
void alloc_chunk (uint32_t start, uint32_t len)
{
while (start + len > heap_max)
{
uint32_t page = pmm_alloc_page ();
map (heap_max, page, PAGE_PRESENT | PAGE_WRITE);
heap_max += 0x1000;
}
}
max
Member
Posts: 616 Joined: Mon Mar 05, 2012 11:23 am
Libera.chat IRC: maxdev
Location: Germany
Contact:
Post
by max » Thu Aug 18, 2016 7:58 am
You will not get any help by simply posting your code and saying it doesn't work. We're not the support crew of jamesm's tutorial stuff. Probably an issue with your pmm as chunk_alloc calls it, but it's your job to debug that stuff.