UnmapPages(): Avoid potential integer overflow.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37192 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2010-06-21 14:28:07 +00:00
parent 8bcc0694ad
commit 86b6de1fae
@@ -332,26 +332,27 @@ void
X86VMTranslationMap32Bit::UnmapPages(VMArea* area, addr_t base, size_t size, X86VMTranslationMap32Bit::UnmapPages(VMArea* area, addr_t base, size_t size,
bool updatePageQueue) bool updatePageQueue)
{ {
page_directory_entry* pd = fPagingStructures->pgdir_virt; if (size == 0)
return;
addr_t start = base; addr_t start = base;
addr_t end = base + size; addr_t end = base + size - 1;
TRACE("X86VMTranslationMap32Bit::UnmapPages(%p, %#" B_PRIxADDR ", %#" TRACE("X86VMTranslationMap32Bit::UnmapPages(%p, %#" B_PRIxADDR ", %#"
B_PRIxADDR ")\n", area, start, end); B_PRIxADDR ")\n", area, start, end);
page_directory_entry* pd = fPagingStructures->pgdir_virt;
VMAreaMappings queue; VMAreaMappings queue;
RecursiveLocker locker(fLock); RecursiveLocker locker(fLock);
while (start < end) { do {
int index = VADDR_TO_PDENT(start); int index = VADDR_TO_PDENT(start);
if ((pd[index] & X86_PDE_PRESENT) == 0) { if ((pd[index] & X86_PDE_PRESENT) == 0) {
// no page table here, move the start up to access the next page // no page table here, move the start up to access the next page
// table // table
start = ROUNDUP(start + 1, B_PAGE_SIZE * 1024); start = ROUNDUP(start + 1, kPageTableAlignment);
if (start == 0)
break;
continue; continue;
} }
@@ -429,9 +430,7 @@ X86VMTranslationMap32Bit::UnmapPages(VMArea* area, addr_t base, size_t size,
Flush(); Flush();
// flush explicitly, since we directly use the lock // flush explicitly, since we directly use the lock
} while (start != 0 && start < end);
pinner.Unlock();
}
// TODO: As in UnmapPage() we can lose page dirty flags here. ATM it's not // TODO: As in UnmapPage() we can lose page dirty flags here. ATM it's not
// really critical here, as in all cases this method is used, the unmapped // really critical here, as in all cases this method is used, the unmapped