DEPS-in PartitionAlloc to PDFium
Replace PDFium's out-of-date local copy with the standalone
PA repository.
- duplicate //build_overrides/partition_alloc.gni from chromium.
- DEPS in lss for the moment, since PA still seems to include it.
Change-Id: If64a9dad18e1e1ce64ca5357328cdebe47eac3ea
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/96059
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/.gitignore b/.gitignore
index f94b732..40c6e92 100644
--- a/.gitignore
+++ b/.gitignore
@@ -19,6 +19,7 @@
/third_party/libjpeg_turbo
/third_party/llvm
/third_party/llvm-build
+/third_party/lss
/third_party/markupsafe
/third_party/nasm
/third_party/skia
diff --git a/DEPS b/DEPS
index 94cd569..63f64b5 100644
--- a/DEPS
+++ b/DEPS
@@ -112,6 +112,10 @@
# and whatever else without interference from each other.
'libunwind_revision': '42aa6de5544ec1ccc27da640a044bd3f474ee75a',
# Three lines of non-changing comments so that
+ # the commit queue can handle CLs rolling lss
+ # and whatever else without interference from each other.
+ 'lss_revision': '0d6435b731ef91d5182eaecff82ae96764222c48',
+ # Three lines of non-changing comments so that
# the commit queue can handle CLs rolling markupsafe
# and whatever else without interference from each other.
'markupsafe_revision': '1b882ef6372b58bfd55a3285f37ed801be9137cd',
@@ -120,6 +124,10 @@
# and whatever else without interference from each other.
'nasm_source_revision': '9215e8e1d0fe474ffd3e16c1a07a0f97089e6224',
# Three lines of non-changing comments so that
+ # the commit queue can handle CLs rolling partition_allocator
+ # and whatever else without interference from each other.
+ 'partition_allocator_revision': 'd47a38e4a0a8220648fba8e9ddfc046a04f8788d',
+ # Three lines of non-changing comments so that
# the commit queue can handle CLs rolling pdfium_tests
# and whatever else without interference from each other.
'pdfium_tests_revision': 'b9373ffb65b305827e0ceb85bfaec40dd7122032',
@@ -159,6 +167,11 @@
]
deps = {
+ 'base/allocator/partition_allocator':
+ Var('chromium_git') +
+ '/chromium/src/base/allocator/partition_allocator.git@' +
+ Var('partition_allocator_revision'),
+
'base/trace_event/common':
Var('chromium_git') + '/chromium/src/base/trace_event/common.git@' +
Var('trace_event_revision'),
@@ -282,6 +295,11 @@
Var('chromium_git') + '/chromium/deps/libjpeg_turbo.git@' +
Var('jpeg_turbo_revision'),
+ 'third_party/lss': {
+ 'url': Var('chromium_git') + '/linux-syscall-support.git' + '@' + Var('lss_revision'),
+ 'condition': 'checkout_android or checkout_linux',
+ },
+
'third_party/markupsafe':
Var('chromium_git') + '/chromium/src/third_party/markupsafe.git@' +
Var('markupsafe_revision'),
diff --git a/build_overrides/partition_alloc.gni b/build_overrides/partition_alloc.gni
new file mode 100644
index 0000000..0cf7009
--- /dev/null
+++ b/build_overrides/partition_alloc.gni
@@ -0,0 +1,11 @@
+# Copyright 2022 The PDFium Authors
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+# See base/allocator/partition_allocator/external_builds.md
+use_partition_alloc_as_malloc_default = false
+enable_mte_checked_ptr_support_default = false
+enable_backup_ref_ptr_support_default = false
+put_ref_count_in_previous_slot_default = false
+enable_backup_ref_ptr_slow_checks_default = false
+enable_dangling_raw_ptr_checks_default = false
diff --git a/core/fxcrt/BUILD.gn b/core/fxcrt/BUILD.gn
index d1389e6..d926496 100644
--- a/core/fxcrt/BUILD.gn
+++ b/core/fxcrt/BUILD.gn
@@ -133,7 +133,7 @@
]
if (pdf_use_partition_alloc) {
sources += [ "fx_memory_pa.cpp" ]
- deps += [ "../../third_party:pdfium_partition_alloc" ]
+ deps += [ "//base/allocator/partition_allocator:partition_alloc" ]
} else {
sources += [ "fx_memory_malloc.cpp" ]
}
diff --git a/core/fxcrt/DEPS b/core/fxcrt/DEPS
index 2be0352..5b61cbd 100644
--- a/core/fxcrt/DEPS
+++ b/core/fxcrt/DEPS
@@ -1,3 +1,4 @@
include_rules = [
+ '+base/allocator',
'+third_party/icu',
]
diff --git a/core/fxcrt/fx_memory_pa.cpp b/core/fxcrt/fx_memory_pa.cpp
index fc993a5..b661249 100644
--- a/core/fxcrt/fx_memory_pa.cpp
+++ b/core/fxcrt/fx_memory_pa.cpp
@@ -6,26 +6,36 @@
#include "core/fxcrt/fx_memory.h"
+#include "base/allocator/partition_allocator/partition_alloc.h"
#include "core/fxcrt/fx_safe_types.h"
-#include "third_party/base/allocator/partition_allocator/partition_alloc.h"
#include "third_party/base/no_destructor.h"
namespace {
-pdfium::base::PartitionAllocatorGeneric& GetArrayBufferPartitionAllocator() {
- static pdfium::base::NoDestructor<pdfium::base::PartitionAllocatorGeneric>
+constexpr partition_alloc::PartitionOptions kOptions = {
+ partition_alloc::PartitionOptions::AlignedAlloc::kDisallowed,
+ partition_alloc::PartitionOptions::ThreadCache::kDisabled,
+ partition_alloc::PartitionOptions::Quarantine::kDisallowed,
+ partition_alloc::PartitionOptions::Cookie::kAllowed,
+ partition_alloc::PartitionOptions::BackupRefPtr::kDisabled,
+ partition_alloc::PartitionOptions::BackupRefPtrZapping::kDisabled,
+ partition_alloc::PartitionOptions::UseConfigurablePool::kNo,
+};
+
+partition_alloc::PartitionAllocator& GetArrayBufferPartitionAllocator() {
+ static pdfium::base::NoDestructor<partition_alloc::PartitionAllocator>
s_array_buffer_allocator;
return *s_array_buffer_allocator;
}
-pdfium::base::PartitionAllocatorGeneric& GetGeneralPartitionAllocator() {
- static pdfium::base::NoDestructor<pdfium::base::PartitionAllocatorGeneric>
+partition_alloc::PartitionAllocator& GetGeneralPartitionAllocator() {
+ static pdfium::base::NoDestructor<partition_alloc::PartitionAllocator>
s_general_allocator;
return *s_general_allocator;
}
-pdfium::base::PartitionAllocatorGeneric& GetStringPartitionAllocator() {
- static pdfium::base::NoDestructor<pdfium::base::PartitionAllocatorGeneric>
+partition_alloc::PartitionAllocator& GetStringPartitionAllocator() {
+ static pdfium::base::NoDestructor<partition_alloc::PartitionAllocator>
s_string_allocator;
return *s_string_allocator;
}
@@ -40,9 +50,9 @@
total *= num_members;
if (!total.IsValid())
return nullptr;
- constexpr int kFlags = pdfium::base::PartitionAllocReturnNull;
- return pdfium::base::PartitionAllocGenericFlags(
- GetGeneralPartitionAllocator().root(), kFlags, total.ValueOrDie(),
+
+ return GetGeneralPartitionAllocator().root()->AllocWithFlags(
+ partition_alloc::AllocFlags::kReturnNull, total.ValueOrDie(),
"GeneralPartition");
}
@@ -52,11 +62,10 @@
if (!total.IsValid())
return nullptr;
- constexpr int kFlags = pdfium::base::PartitionAllocReturnNull |
- pdfium::base::PartitionAllocZeroFill;
- return pdfium::base::PartitionAllocGenericFlags(
- GetGeneralPartitionAllocator().root(), kFlags, total.ValueOrDie(),
- "GeneralPartition");
+ return GetGeneralPartitionAllocator().root()->AllocWithFlags(
+ partition_alloc::AllocFlags::kReturnNull |
+ partition_alloc::AllocFlags::kZeroFill,
+ total.ValueOrDie(), "GeneralPartition");
}
void* Realloc(void* ptr, size_t num_members, size_t member_size) {
@@ -65,9 +74,8 @@
if (!size.IsValid())
return nullptr;
- return pdfium::base::PartitionReallocGenericFlags(
- GetGeneralPartitionAllocator().root(),
- pdfium::base::PartitionAllocReturnNull, ptr, size.ValueOrDie(),
+ return GetGeneralPartitionAllocator().root()->ReallocWithFlags(
+ partition_alloc::AllocFlags::kReturnNull, ptr, size.ValueOrDie(),
"GeneralPartition");
}
@@ -77,9 +85,8 @@
if (!total.IsValid())
return nullptr;
- constexpr int kFlags = pdfium::base::PartitionAllocReturnNull;
- return pdfium::base::PartitionAllocGenericFlags(
- GetStringPartitionAllocator().root(), kFlags, total.ValueOrDie(),
+ return GetStringPartitionAllocator().root()->AllocWithFlags(
+ partition_alloc::AllocFlags::kReturnNull, total.ValueOrDie(),
"StringPartition");
}
@@ -89,17 +96,17 @@
void FX_InitializeMemoryAllocators() {
static bool s_partition_allocators_initialized = false;
if (!s_partition_allocators_initialized) {
- pdfium::base::PartitionAllocGlobalInit(FX_OutOfMemoryTerminate);
- GetArrayBufferPartitionAllocator().init();
- GetGeneralPartitionAllocator().init();
- GetStringPartitionAllocator().init();
+ partition_alloc::PartitionAllocGlobalInit(FX_OutOfMemoryTerminate);
+ GetArrayBufferPartitionAllocator().init(kOptions);
+ GetGeneralPartitionAllocator().init(kOptions);
+ GetStringPartitionAllocator().init(kOptions);
s_partition_allocators_initialized = true;
}
}
void* FX_ArrayBufferAllocate(size_t length) {
- return GetArrayBufferPartitionAllocator().root()->AllocFlags(
- pdfium::base::PartitionAllocZeroFill, length, "FXArrayBuffer");
+ return GetArrayBufferPartitionAllocator().root()->AllocWithFlags(
+ partition_alloc::AllocFlags::kZeroFill, length, "FXArrayBuffer");
}
void* FX_ArrayBufferAllocateUninitialized(size_t length) {
@@ -121,5 +128,5 @@
// So this check is hiding (what I consider to be) bugs, and we should try to
// fix them. https://bugs.chromium.org/p/pdfium/issues/detail?id=690
if (ptr)
- pdfium::base::PartitionFree(ptr);
+ partition_alloc::ThreadSafePartitionRoot::Free(ptr);
}