page: fix error in mmap_find_unmapped
This commit is contained in:
parent
ec4d266abd
commit
38918e3be3
1 changed files with 9 additions and 7 deletions
14
mem/page.c
14
mem/page.c
|
|
@ -32,7 +32,7 @@ static uint64_t *pagemap_traverse(uint64_t *this_level, size_t next_num)
|
||||||
|
|
||||||
uintptr_t mmap_find_unmapped(struct rbtree *tree, spinlock_t *lock, uintptr_t start, size_t len)
|
uintptr_t mmap_find_unmapped(struct rbtree *tree, spinlock_t *lock, uintptr_t start, size_t len)
|
||||||
{
|
{
|
||||||
len = MIN(len, 0x1000);
|
len = MAX(len, 0x1000);
|
||||||
len = npow2(len);
|
len = npow2(len);
|
||||||
|
|
||||||
spinlock_acquire(lock);
|
spinlock_acquire(lock);
|
||||||
|
|
@ -54,11 +54,13 @@ uintptr_t mmap_find_unmapped(struct rbtree *tree, spinlock_t *lock, uintptr_t st
|
||||||
size_t ret = start;
|
size_t ret = start;
|
||||||
|
|
||||||
while (node != NULL) {
|
while (node != NULL) {
|
||||||
/* node value is the physical address, node key is the virtual address
|
if (ret + len <= node->key) {
|
||||||
*
|
struct rbnode *node2 = rbt_successor(node);
|
||||||
* we want to find the lowest virtual address that is not mapped
|
if (node2->key <= ret + len) {
|
||||||
*/
|
ret = node2->key + node2->value2;
|
||||||
if (node->key > ret + len) {
|
node = node2;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
spinlock_release(lock);
|
spinlock_release(lock);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue