Fix allocation of multiple pages, which forgot to increase page number.
Particularly, it caused "vm86_addpage: overlap" panics under VirtualBox. Add a safety check before freeing memory while I am here.
This commit is contained in:
parent
f6ac23919b
commit
f10776734f
@ -121,7 +121,7 @@ x86bios_alloc(uint32_t *offset, size_t size, int flags)
|
||||
*offset = vtophys(addr);
|
||||
mtx_lock(&x86bios_lock);
|
||||
for (i = 0; i < howmany(size, PAGE_SIZE); i++)
|
||||
vm86_addpage(&x86bios_vmc, atop(*offset),
|
||||
vm86_addpage(&x86bios_vmc, atop(*offset) + i,
|
||||
addr + i * PAGE_SIZE);
|
||||
mtx_unlock(&x86bios_lock);
|
||||
}
|
||||
@ -142,6 +142,10 @@ x86bios_free(void *addr, size_t size)
|
||||
sizeof(x86bios_vmc.pmap[i]));
|
||||
last = i;
|
||||
}
|
||||
if (last < 0) {
|
||||
mtx_unlock(&x86bios_lock);
|
||||
return;
|
||||
}
|
||||
if (last == x86bios_vmc.npages - 1) {
|
||||
x86bios_vmc.npages -= howmany(size, PAGE_SIZE);
|
||||
for (i = x86bios_vmc.npages - 1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user