mm: Never return page struct at 0x0, check for invalid number of pages
This commit is contained in:
parent
375ef2eddf
commit
787a46f2ca
@ -51,6 +51,10 @@ void mm_add_free_region(void *start, void *end) {
|
|||||||
struct page *p;
|
struct page *p;
|
||||||
void *page;
|
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
|
//make sure both start and end address are aligned to the size of a page
|
||||||
if ((unsigned int)start % MM_PAGE_SIZE != 0)
|
if ((unsigned int)start % MM_PAGE_SIZE != 0)
|
||||||
start = (char*)start + (MM_PAGE_SIZE - ((unsigned int)start % MM_PAGE_SIZE));
|
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;
|
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) {
|
for_each_list(it, &mm_free_page_list, struct page, list) {
|
||||||
unsigned int curr_pages = 1;
|
unsigned int curr_pages = 1;
|
||||||
struct page *it2;
|
struct page *it2;
|
||||||
|
Loading…
Reference in New Issue
Block a user