From bf4604c3639d7b89b158af2e03c91404dc4a28e5 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Fri, 9 Mar 2007 21:40:56 +0000 Subject: [PATCH] Fixed incorrect loop conditions in [un]lock_memory(). If the given start address wasn't aligned and numBytes was a multiple of the page size, the last page was ignored. A subsequent get_memory_map() would return NULL as physical address for that page, if it hadn't been mapped before (that function looks generally suspicious, IMHO). E.g. reads from a device into an unaligned buffer that hadn't been touched before would hit that problem. Fixes bug #1075. Might also fix other reported problems (like #1056), since this bug could have cause all kinds of weird behavior and crashes. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20362 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/system/kernel/vm/vm.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/system/kernel/vm/vm.cpp b/src/system/kernel/vm/vm.cpp index 25e2ac2fc0..cf3d603adf 100644 --- a/src/system/kernel/vm/vm.cpp +++ b/src/system/kernel/vm/vm.cpp @@ -3702,8 +3702,9 @@ lock_memory(void *address, ulong numBytes, ulong flags) { vm_address_space *addressSpace = NULL; struct vm_translation_map *map; - addr_t base = (addr_t)address; - addr_t end = base + numBytes; + addr_t unalignedBase = (addr_t)address; + addr_t end = unalignedBase + numBytes; + addr_t base = ROUNDOWN(unalignedBase, B_PAGE_SIZE); bool isUser = IS_USER_ADDRESS(address); bool needsLocking = true; @@ -3756,7 +3757,7 @@ lock_memory(void *address, ulong numBytes, ulong flags) status = vm_soft_fault(base, (flags & B_READ_DEVICE) != 0, isUser); if (status != B_OK) { dprintf("lock_memory(address = %p, numBytes = %lu, flags = %lu) failed: %s\n", - address, numBytes, flags, strerror(status)); + unalignedBase, numBytes, flags, strerror(status)); goto out; } @@ -3787,8 +3788,9 @@ unlock_memory(void *address, ulong numBytes, ulong flags) { vm_address_space *addressSpace = NULL; struct vm_translation_map *map; - addr_t base = (addr_t)address; - addr_t end = base + numBytes; + addr_t unalignedBase = (addr_t)address; + addr_t end = unalignedBase + numBytes; + addr_t base = ROUNDOWN(unalignedBase, B_PAGE_SIZE); bool needsLocking = true; if (IS_USER_ADDRESS(address))