Unmap(),Protect(): Removed goto programming by a do {} while loop. Also fixed

problem with potential integer overflow at the end of the address space.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37190 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2010-06-21 13:57:00 +00:00
parent 66f9974b06
commit a19f81b6c7
@@ -211,24 +211,21 @@ X86VMTranslationMap32Bit::Map(addr_t va, phys_addr_t pa, uint32 attributes,
status_t status_t
X86VMTranslationMap32Bit::Unmap(addr_t start, addr_t end) X86VMTranslationMap32Bit::Unmap(addr_t start, addr_t end)
{ {
page_directory_entry *pd = fPagingStructures->pgdir_virt;
start = ROUNDDOWN(start, B_PAGE_SIZE); start = ROUNDDOWN(start, B_PAGE_SIZE);
end = ROUNDUP(end, B_PAGE_SIZE);
TRACE("unmap_tmap: asked to free pages 0x%lx to 0x%lx\n", start, end);
restart:
if (start >= end) if (start >= end)
return B_OK; return B_OK;
TRACE("unmap_tmap: asked to free pages 0x%lx to 0x%lx\n", start, end);
page_directory_entry *pd = fPagingStructures->pgdir_virt;
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 pagetable here, move the start up to access the next page table // no page table here, move the start up to access the next page
start = ROUNDUP(start + 1, B_PAGE_SIZE * 1024); // table
if (start == 0) start = ROUNDUP(start + 1, kPageTableAlignment);
return B_OK; continue;
goto restart;
} }
struct thread* thread = thread_get_current_thread(); struct thread* thread = thread_get_current_thread();
@@ -253,15 +250,14 @@ restart:
if ((oldEntry & X86_PTE_ACCESSED) != 0) { if ((oldEntry & X86_PTE_ACCESSED) != 0) {
// Note, that we only need to invalidate the address, if the // Note, that we only need to invalidate the address, if the
// accessed flags was set, since only then the entry could have been // accessed flags was set, since only then the entry could have
// in any TLB. // been in any TLB.
InvalidatePage(start); InvalidatePage(start);
} }
} }
} while (start != 0 && start < end);
pinner.Unlock(); return B_OK;
goto restart;
} }
@@ -641,9 +637,9 @@ status_t
X86VMTranslationMap32Bit::Protect(addr_t start, addr_t end, uint32 attributes, X86VMTranslationMap32Bit::Protect(addr_t start, addr_t end, uint32 attributes,
uint32 memoryType) uint32 memoryType)
{ {
page_directory_entry *pd = fPagingStructures->pgdir_virt;
start = ROUNDDOWN(start, B_PAGE_SIZE); start = ROUNDDOWN(start, B_PAGE_SIZE);
if (start >= end)
return B_OK;
TRACE("protect_tmap: pages 0x%lx to 0x%lx, attributes %lx\n", start, end, TRACE("protect_tmap: pages 0x%lx to 0x%lx, attributes %lx\n", start, end,
attributes); attributes);
@@ -657,17 +653,15 @@ X86VMTranslationMap32Bit::Protect(addr_t start, addr_t end, uint32 attributes,
} else if ((attributes & B_KERNEL_WRITE_AREA) != 0) } else if ((attributes & B_KERNEL_WRITE_AREA) != 0)
newProtectionFlags = X86_PTE_WRITABLE; newProtectionFlags = X86_PTE_WRITABLE;
restart: page_directory_entry *pd = fPagingStructures->pgdir_virt;
if (start >= end)
return B_OK;
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 pagetable here, move the start up to access the next page table // no page table here, move the start up to access the next page
start = ROUNDUP(start + 1, B_PAGE_SIZE * 1024); // table
if (start == 0) start = ROUNDUP(start + 1, kPageTableAlignment);
return B_OK; continue;
goto restart;
} }
struct thread* thread = thread_get_current_thread(); struct thread* thread = thread_get_current_thread();
@@ -692,7 +686,8 @@ restart:
while (true) { while (true) {
oldEntry = X86PagingMethod32Bit::TestAndSetPageTableEntry( oldEntry = X86PagingMethod32Bit::TestAndSetPageTableEntry(
&pt[index], &pt[index],
(entry & ~(X86_PTE_PROTECTION_MASK | X86_PTE_MEMORY_TYPE_MASK)) (entry & ~(X86_PTE_PROTECTION_MASK
| X86_PTE_MEMORY_TYPE_MASK))
| newProtectionFlags | newProtectionFlags
| X86PagingMethod32Bit::MemoryTypeToPageTableEntryFlags( | X86PagingMethod32Bit::MemoryTypeToPageTableEntryFlags(
memoryType), memoryType),
@@ -704,15 +699,14 @@ restart:
if ((oldEntry & X86_PTE_ACCESSED) != 0) { if ((oldEntry & X86_PTE_ACCESSED) != 0) {
// Note, that we only need to invalidate the address, if the // Note, that we only need to invalidate the address, if the
// accessed flag was set, since only then the entry could have been // accessed flag was set, since only then the entry could have
// in any TLB. // been in any TLB.
InvalidatePage(start); InvalidatePage(start);
} }
} }
} while (start != 0 && start < end);
pinner.Unlock(); return B_OK;
goto restart;
} }