Found a bug in JamesM multitasking code, in clone table
Posted: Sat Aug 17, 2013 12:01 am
Hello, I recently found a bug in his code and would like to share it. Some parts of my OS are based of of his code and the time has come to improve the multitasking. After several days of banging my head against the wall, the bug was really really simple. The problem was that when I wanted to clone a page directory, the first time would work, and then the second time, it would assert (or triple fault, I added an assert in find_smallest_hole, which checks the magic of the found hole). The problem was in the clone table function which is embedded within the clone page directory function. Here is the bug...
before:
I did not notice that table was allocated a page_table_t (4096) and memset with the size of a page_directory_t (8192)
after changing the memset's clear size to sizeof(page_table_t):
Everything worked perfectly!!!
I hope this is useful to anyone else who is also trying to debug this problem.
before:
Code: Select all
// Make a new page table, which is page aligned.
page_table_t *table = (page_table_t*)kmalloc_ap(sizeof(page_table_t), physAddr);
// Ensure that the new table is blank.
memset((u8int*)table, 0, sizeof(page_directory_t));
after changing the memset's clear size to sizeof(page_table_t):
Code: Select all
// Make a new page table, which is page aligned.
page_table_t *table = (page_table_t*)kmalloc_ap(sizeof(page_table_t), physAddr);
// Ensure that the new table is blank.
memset((u8int*)table, 0, sizeof(page_table_t));
I hope this is useful to anyone else who is also trying to debug this problem.