os_metrics_mac.patch 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Cheng Zhao <[email protected]>
  3. Date: Thu, 4 Oct 2018 14:57:02 -0700
  4. Subject: fix: make os_metrics_mac work with 10.15 SDK
  5. This patch fixes the memory_instrumentation module returning 0.
  6. Backport https://chromium-review.googlesource.com/c/chromium/src/+/1967436.
  7. diff --git a/services/resource_coordinator/public/cpp/memory_instrumentation/os_metrics_mac.cc b/services/resource_coordinator/public/cpp/memory_instrumentation/os_metrics_mac.cc
  8. index a20418240d52d65a0b905df7ff8754c50d38c0fc..487336bbd48440edde753d03fc8c79b2a4dbc299 100644
  9. --- a/services/resource_coordinator/public/cpp/memory_instrumentation/os_metrics_mac.cc
  10. +++ b/services/resource_coordinator/public/cpp/memory_instrumentation/os_metrics_mac.cc
  11. @@ -50,8 +50,34 @@ struct ChromeTaskVMInfo {
  12. #else
  13. using ChromeTaskVMInfo = task_vm_info;
  14. #endif // MAC_OS_X_VERSION_10_11
  15. -mach_msg_type_number_t ChromeTaskVMInfoCount =
  16. - sizeof(ChromeTaskVMInfo) / sizeof(natural_t);
  17. +
  18. +// Don't simply use sizeof(task_vm_info) / sizeof(natural_t):
  19. +// In the 10.15 SDK, this structure is 87 32-bit words long, and in
  20. +// mach_types.defs:
  21. +//
  22. +// type task_info_t = array[*:87] of integer_t;
  23. +//
  24. +// However in the 10.14 SDK, this structure is 42 32-bit words, and in
  25. +// mach_types.defs:
  26. +//
  27. +// type task_info_t = array[*:52] of integer_t;
  28. +//
  29. +// As a result, the 10.15 SDK's task_vm_info won't fit inside the 10.14 SDK's
  30. +// task_info_t, so the *rest of the system* (on 10.14 and earlier) can't handle
  31. +// calls that request the full 10.15 structure. We have to request a prefix of
  32. +// it that 10.14 and earlier can handle by limiting the length we request. The
  33. +// rest of the fields just get ignored, but we don't use them anyway.
  34. +
  35. +constexpr mach_msg_type_number_t ChromeTaskVMInfoCount =
  36. + TASK_VM_INFO_REV2_COUNT;
  37. +
  38. +// The count field is in units of natural_t, which is the machine's word size
  39. +// (64 bits on all modern machines), but the task_info_t array is in units of
  40. +// integer_t, which is 32 bits.
  41. +constexpr mach_msg_type_number_t MAX_MIG_SIZE_FOR_1014 =
  42. + 52 / (sizeof(natural_t) / sizeof(integer_t));
  43. +static_assert(ChromeTaskVMInfoCount <= MAX_MIG_SIZE_FOR_1014,
  44. + "task_vm_info must be small enough for 10.14 MIG interfaces");
  45. using VMRegion = mojom::VmRegion;