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
This commit is contained in:
Ingo Weinhold 2007-03-09 21:40:56 +00:00
parent 75d00d2451
commit bf4604c363

View File

@ -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))