diff --git a/kernel/mm.c b/kernel/mm.c index 848afe4..0a5f629 100644 --- a/kernel/mm.c +++ b/kernel/mm.c @@ -51,6 +51,10 @@ void mm_add_free_region(void *start, void *end) { struct page *p; void *page; + //If region starts at 0x0, make it start at next page to not screw up null pointer detection, etc. + if (start == 0) + start = (char *)start + MM_PAGE_SIZE; + //make sure both start and end address are aligned to the size of a page if ((unsigned int)start % MM_PAGE_SIZE != 0) start = (char*)start + (MM_PAGE_SIZE - ((unsigned int)start % MM_PAGE_SIZE)); @@ -89,6 +93,11 @@ struct page* mm_get_free_pages(unsigned int power) { return (struct page*)0; } + if (!num_pages) { + print("Error: mm_get_free_pages must be called with power from 0 to 31, inclusive (power=%d)\n", power); + return (struct page*)0; + } + for_each_list(it, &mm_free_page_list, struct page, list) { unsigned int curr_pages = 1; struct page *it2;