Guest User

Untitled

a guest
Mar 20th, 2022
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 5.00 KB | None | 0 0
  1. diff --git a/base/allocator/partition_allocator/address_space_randomization.h b/base/allocator/partition_allocator/address_space_randomization.h
  2. index 43033d728050a..4287cd5644823 100644
  3. --- a/base/allocator/partition_allocator/address_space_randomization.h
  4. +++ b/base/allocator/partition_allocator/address_space_randomization.h
  5. @@ -125,10 +125,10 @@ AslrMask(uintptr_t bits) {
  6.  
  7.        // ARM64 on Linux has 39-bit user space. Use 38 bits since ASLROffset()
  8.        // could cause a carry.
  9. -      constexpr ALWAYS_INLINE uintptr_t ASLRMask() {
  10. +      PAGE_ALLOCATOR_CONSTANTS_DECLARE_CONSTEXPR ALWAYS_INLINE uintptr_t ASLRMask() {
  11.          return AslrMask(38);
  12.        }
  13. -      constexpr ALWAYS_INLINE uintptr_t ASLROffset() {
  14. +      PAGE_ALLOCATOR_CONSTANTS_DECLARE_CONSTEXPR ALWAYS_INLINE uintptr_t ASLROffset() {
  15.          return AslrAddress(0x1000000000ULL);
  16.        }
  17.  
  18. diff --git a/base/allocator/partition_allocator/page_allocator.cc b/base/allocator/partition_allocator/page_allocator.cc
  19. index 524e107418501..d2cbf866212e7 100644
  20. --- a/base/allocator/partition_allocator/page_allocator.cc
  21. +++ b/base/allocator/partition_allocator/page_allocator.cc
  22. @@ -28,6 +28,22 @@
  23.  #error Platform not supported.
  24.  #endif
  25.  
  26. +#if BUILDFLAG(IS_LINUX) && defined(ARCH_CPU_ARM64)
  27. +
  28. +#include <unistd.h>
  29. +
  30. +#pragma GCC diagnostic push
  31. +#pragma GCC diagnostic ignored "-Wglobal-constructors"
  32. +
  33. +const PageCharacteristics kPage = []() {
  34. +  int size = getpagesize();
  35. +  return PageCharacteristics{size, __builtin_ctz(size)};
  36. +}();
  37. +
  38. +#pragma GCC diagnostic pop
  39. +
  40. +#endif
  41. +
  42.  namespace partition_alloc {
  43.  
  44.  namespace {
  45. diff --git a/base/allocator/partition_allocator/page_allocator_constants.h b/base/allocator/partition_allocator/page_allocator_constants.h
  46. index 12515b9a02865..bec35d191e738 100644
  47. --- a/base/allocator/partition_allocator/page_allocator_constants.h
  48. +++ b/base/allocator/partition_allocator/page_allocator_constants.h
  49. @@ -24,6 +24,18 @@
  50.  // elimination.
  51.  #define PAGE_ALLOCATOR_CONSTANTS_DECLARE_CONSTEXPR __attribute__((const))
  52.  
  53. +#elif BUILDFLAG(IS_LINUX) && defined(ARCH_CPU_ARM64)
  54. +
  55. +// Linux ARM64 can have different page sizes depending on the kernel.
  56. +#define PAGE_ALLOCATOR_CONSTANTS_DECLARE_CONSTEXPR __attribute__((const))
  57. +
  58. +struct PageCharacteristics {
  59. +  int size;
  60. +  int shift;
  61. +};
  62. +
  63. +extern const PageCharacteristics kPage;
  64. +
  65.  #else
  66.  
  67.  // When defined, page size constants are fixed at compile time. When not
  68. @@ -50,6 +62,8 @@ PageAllocationGranularityShift() {
  69.    return 14;  // 16kB
  70.  #elif BUILDFLAG(IS_APPLE) && defined(ARCH_CPU_64_BITS)
  71.    return vm_page_shift;
  72. +#elif BUILDFLAG(IS_LINUX) && defined(ARCH_CPU_ARM64)
  73. +  return kPage.shift;
  74.  #else
  75.    return 12;  // 4kB
  76.  #endif
  77. diff --git a/base/allocator/partition_allocator/partition_alloc_constants.h b/base/allocator/partition_allocator/partition_alloc_constants.h
  78. index e0c871d6f60fe..e0d5702ac71ea 100644
  79. --- a/base/allocator/partition_allocator/partition_alloc_constants.h
  80. +++ b/base/allocator/partition_allocator/partition_alloc_constants.h
  81. @@ -84,6 +84,11 @@ PAGE_ALLOCATOR_CONSTANTS_DECLARE_CONSTEXPR ALWAYS_INLINE size_t
  82.  PartitionPageShift() {
  83.    return vm_page_shift + 2;
  84.  }
  85. +#elif BUILDFLAG(IS_LINUX) && defined(ARCH_CPU_ARM64)
  86. +PAGE_ALLOCATOR_CONSTANTS_DECLARE_CONSTEXPR ALWAYS_INLINE size_t
  87. +PartitionPageShift() {
  88. +  return kPage.shift + 2;
  89. +}
  90.  #else
  91.  PAGE_ALLOCATOR_CONSTANTS_DECLARE_CONSTEXPR ALWAYS_INLINE size_t
  92.  PartitionPageShift() {
  93. diff --git a/base/allocator/partition_allocator/partition_page.h b/base/allocator/partition_allocator/partition_page.h
  94. index 9419fa4c44f2d..de5907d6a324c 100644
  95. --- a/base/allocator/partition_allocator/partition_page.h
  96. +++ b/base/allocator/partition_allocator/partition_page.h
  97. @@ -134,6 +134,9 @@ struct __attribute__((packed)) SlotSpanMetadata {
  98.    // PartitionPageSize() is 4 times the OS page size.
  99.    static constexpr size_t kMaxSlotsPerSlotSpan =
  100.        4 * (1 << 14) / kSmallestBucket;
  101. +#elif BUILDFLAG(IS_LINUX) && defined(ARCH_CPU_ARM64)
  102. +  static constexpr size_t kMaxSlotsPerSlotSpan =
  103. +      4 * (1 << 14) / kSmallestBucket;
  104.  #else
  105.    // A slot span can "span" multiple PartitionPages, but then its slot size is
  106.    // larger, so it doesn't have as many slots.
  107. diff --git a/base/allocator/partition_allocator/partition_root.cc b/base/allocator/partition_allocator/partition_root.cc
  108. index 70d7d63ff4c65..c31356e0f0421 100644
  109. --- a/base/allocator/partition_allocator/partition_root.cc
  110. +++ b/base/allocator/partition_allocator/partition_root.cc
  111. @@ -309,7 +309,7 @@ static size_t PartitionPurgeSlotSpan(
  112.    constexpr size_t kMaxSlotCount =
  113.        (PartitionPageSize() * kMaxPartitionPagesPerRegularSlotSpan) /
  114.        SystemPageSize();
  115. -#elif BUILDFLAG(IS_APPLE)
  116. +#elif BUILDFLAG(IS_APPLE) || (BUILDFLAG(IS_LINUX) && defined(ARCH_CPU_ARM64))
  117.    // It's better for slot_usage to be stack-allocated and fixed-size, which
  118.    // demands that its size be constexpr. On OS_APPLE, PartitionPageSize() is
  119.    // always SystemPageSize() << 2, so regardless of what the run time page size
Add Comment
Please, Sign In to add comment