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>
diff --git a/util/process/process_memory_mac.cc b/util/process/process_memory_mac.cc
index eba1f20..29357f3 100644
--- a/util/process/process_memory_mac.cc
+++ b/util/process/process_memory_mac.cc
@@ -94,8 +94,16 @@
         "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));
 }