Explicitly check mach_vm_read() size out parameter

Explicitly check that mach_vm_read() successfully read the entire
requested region. This is a speculative fix for an infrequent crash that
occurs in the wild where only part of the region read by ReadMapped()
was actually mapped into memory.

Bug: chromium:918626
Change-Id: I4f4b3902d11480dc4a003608cfb1d371ec89425b
Reviewed-on: https://chromium-review.googlesource.com/c/1455170
Commit-Queue: Vlad Tsyrklevich <vtsyrklevich@chromium.org>
Reviewed-by: Mark Mentovai <mark@chromium.org>
This commit is contained in:
Vlad Tsyrklevich 2019-02-20 13:18:05 -08:00 committed by Commit Bot
parent 03850fb6cf
commit 25ba1d6895

View File

@ -94,8 +94,16 @@ std::unique_ptr<ProcessMemoryMac::MappedMemory> ProcessMemoryMac::ReadMapped(
"mach_vm_read(0x%llx, 0x%llx)", region_address, region_size);
return std::unique_ptr<MappedMemory>();
}
if (region_count != region_size) {
LOG(ERROR) << base::StringPrintf(
"mach_vm_read() unexpected read: 0x%x != 0x%llx bytes",
region_count,
region_size);
if (region_count)
vm_deallocate(mach_task_self(), region, region_count);
return std::unique_ptr<MappedMemory>();
}
DCHECK_EQ(region_count, region_size);
return std::unique_ptr<MappedMemory>(
new MappedMemory(region, region_size, address - region_address, size));
}