PA: Temporary option for new PartitionAlloc location.
To make the partition_alloc directory a standalone library, I am going to:
1. Move from files from:
/base/allocator/partition_allocator/*
toward
/base/allocator/partition_allocator/src/partition_alloc/*
2. Make PartitionAlloc to declare its include_dirs.
3. PartitionAlloc dependants will be able put PartitionAlloc wherever
they want (e.g. probably in their third_party/partition_alloc) and
to use:
#include "partition_alloc/..."
instead of:
#include "base/allocator/partition_allocator/src/partition_alloc/..."
Unfortunately, the partition_alloc library is already used by PDFium.
Step (1) would break it. To achieve step 1 without breaking pdfium, this
patch adds an option for chromium to set the location of PartitionAlloc.
This is temporary and will be removed after step 1 is completed in
Chrome.
It a kind of 3-step change.
Bug:chromuium:1467773
Change-Id: I9f312f6a47976659a1e792c663006f3a75ec7fca
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/111490
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Arthur Sonzogni <arthursonzogni@chromium.org>
diff --git a/BUILD.gn b/BUILD.gn
index 07a5b93..3ab1ec6 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -46,6 +46,9 @@
if (pdf_use_partition_alloc) {
defines += [ "PDF_USE_PARTITION_ALLOC" ]
}
+ if (pdf_use_partition_alloc_new_location) {
+ defines += [ "PDF_USE_PARTITION_ALLOC_NEW_LOCATION" ]
+ }
if (is_win) {
# Assume UTF-8 by default to avoid code page dependencies.
diff --git a/build_overrides/partition_alloc.gni b/build_overrides/partition_alloc.gni
index 56f913c..4a1cd1f 100644
--- a/build_overrides/partition_alloc.gni
+++ b/build_overrides/partition_alloc.gni
@@ -11,7 +11,7 @@
# TODO(https://crbug.com/pdfium/2068) - make work with windows.
_use_shim = !_is_using_sanitizers && !is_win
-# See base/allocator/partition_allocator/external_builds.md
+# See base/allocator/partition_allocator/src/partition_alloc/external_builds.md
use_allocator_shim_default = _use_shim
use_partition_alloc_as_malloc_default = _use_shim
enable_backup_ref_ptr_support_default = _use_shim
diff --git a/core/fxcrt/BUILD.gn b/core/fxcrt/BUILD.gn
index c9bdfa0..ea428af 100644
--- a/core/fxcrt/BUILD.gn
+++ b/core/fxcrt/BUILD.gn
@@ -11,10 +11,17 @@
deps = [ "../../third_party:pdfium_compiler_specific" ]
configs += [ "../../:pdfium_strict_config" ]
if (pdf_use_partition_alloc) {
- public_deps = [
- "//base/allocator/partition_allocator:partition_alloc_buildflags",
- "//base/allocator/partition_allocator:raw_ptr",
- ]
+ if (pdf_use_partition_alloc_new_location) {
+ public_deps = [
+ "//base/allocator/partition_allocator/src/partition_alloc:partition_alloc_buildflags",
+ "//base/allocator/partition_allocator/src/partition_alloc:raw_ptr",
+ ]
+ } else {
+ public_deps = [
+ "//base/allocator/partition_allocator:partition_alloc_buildflags",
+ "//base/allocator/partition_allocator:raw_ptr",
+ ]
+ }
}
}
@@ -142,11 +149,19 @@
]
if (pdf_use_partition_alloc) {
sources += [ "fx_memory_pa.cpp" ]
- deps += [
- "//base/allocator/partition_allocator:partition_alloc",
- "//base/allocator/partition_allocator:partition_alloc_buildflags",
- "//base/allocator/partition_allocator:raw_ptr",
- ]
+ if (pdf_use_partition_alloc_new_location) {
+ deps += [
+ "//base/allocator/partition_allocator/src/partition_alloc",
+ "//base/allocator/partition_allocator/src/partition_alloc:partition_alloc_buildflags",
+ "//base/allocator/partition_allocator/src/partition_alloc:raw_ptr",
+ ]
+ } else {
+ deps += [
+ "//base/allocator/partition_allocator:partition_alloc",
+ "//base/allocator/partition_allocator:partition_alloc_buildflags",
+ "//base/allocator/partition_allocator:raw_ptr",
+ ]
+ }
} else {
sources += [ "fx_memory_malloc.cpp" ]
}
@@ -247,7 +262,11 @@
deps = [ ":unit_test_support" ]
pdfium_root_dir = "../../"
if (pdf_use_partition_alloc) {
- deps += [ "//base/allocator/partition_allocator:partition_alloc" ]
+ if (pdf_use_partition_alloc_new_location) {
+ deps += [ "//base/allocator/partition_allocator/src/partition_alloc" ]
+ } else {
+ deps += [ "//base/allocator/partition_allocator:partition_alloc" ]
+ }
}
if (pdf_enable_xfa) {
sources += [ "cfx_memorystream_unittest.cpp" ]
diff --git a/core/fxcrt/fx_memory_pa.cpp b/core/fxcrt/fx_memory_pa.cpp
index 2473fbc..e75d082 100644
--- a/core/fxcrt/fx_memory_pa.cpp
+++ b/core/fxcrt/fx_memory_pa.cpp
@@ -6,7 +6,11 @@
#include "core/fxcrt/fx_memory.h"
+#if defined(PDF_USE_PARTITION_ALLOC_NEW_LOCATION)
+#include "base/allocator/partition_allocator/src/partition_alloc/partition_alloc.h"
+#else
#include "base/allocator/partition_allocator/partition_alloc.h"
+#endif
#include "core/fxcrt/fx_safe_types.h"
#include "third_party/base/no_destructor.h"
diff --git a/core/fxcrt/fx_memory_unittest.cpp b/core/fxcrt/fx_memory_unittest.cpp
index 7d3fe4d..7f6a7ac 100644
--- a/core/fxcrt/fx_memory_unittest.cpp
+++ b/core/fxcrt/fx_memory_unittest.cpp
@@ -11,8 +11,12 @@
#include "testing/gtest/include/gtest/gtest.h"
#if defined(PDF_USE_PARTITION_ALLOC)
+#if defined(PDF_USE_PARTITION_ALLOC_NEW_LOCATION)
+#include "base/allocator/partition_allocator/src/partition_alloc/partition_address_space.h"
+#else
#include "base/allocator/partition_allocator/partition_address_space.h"
#endif
+#endif
namespace {
diff --git a/core/fxcrt/unowned_ptr.h b/core/fxcrt/unowned_ptr.h
index fa78beb..d642483 100644
--- a/core/fxcrt/unowned_ptr.h
+++ b/core/fxcrt/unowned_ptr.h
@@ -39,7 +39,11 @@
#include "build/build_config.h"
#if defined(PDF_USE_PARTITION_ALLOC)
+#if defined(PDF_USE_PARTITION_ALLOC_NEW_LOCATION)
+#include "base/allocator/partition_allocator/src/partition_alloc/partition_alloc_buildflags.h"
+#else
#include "base/allocator/partition_allocator/partition_alloc_buildflags.h"
+#endif
// Can only use base::raw_ptr<> impls that force nullptr initialization.
#if BUILDFLAG(ENABLE_BACKUP_REF_PTR_SUPPORT) || BUILDFLAG(USE_ASAN_UNOWNED_PTR)
@@ -52,7 +56,11 @@
#endif // PDF_USE_PARTITION_ALLOC
#if defined(UNOWNED_PTR_IS_BASE_RAW_PTR)
+#if defined(PDF_USE_PARTITION_ALLOC_NEW_LOCATION)
+#include "base/allocator/partition_allocator/src/partition_alloc/pointers/raw_ptr.h"
+#else
#include "base/allocator/partition_allocator/pointers/raw_ptr.h"
+#endif
template <typename T>
using UnownedPtr = raw_ptr<T>;
diff --git a/core/fxcrt/unowned_ptr_unittest.cpp b/core/fxcrt/unowned_ptr_unittest.cpp
index 8c55108..99b2892 100644
--- a/core/fxcrt/unowned_ptr_unittest.cpp
+++ b/core/fxcrt/unowned_ptr_unittest.cpp
@@ -14,8 +14,12 @@
#include "third_party/base/containers/contains.h"
#if defined(PDF_USE_PARTITION_ALLOC)
+#if defined(PDF_USE_PARTITION_ALLOC_NEW_LOCATION)
+#include "base/allocator/partition_allocator/src/partition_alloc/shim/allocator_shim_default_dispatch_to_partition_alloc.h"
+#else
#include "base/allocator/partition_allocator/shim/allocator_shim_default_dispatch_to_partition_alloc.h"
#endif
+#endif
namespace fxcrt {
namespace {
diff --git a/pdfium.gni b/pdfium.gni
index ffa740a..f349a26 100644
--- a/pdfium.gni
+++ b/pdfium.gni
@@ -48,6 +48,10 @@
# malloc is controlled by args in build_overrides/partition_alloc.gni.
pdf_use_partition_alloc = pdf_use_partition_alloc_override
+ # Temporary config allowing chromium to switch its location of the
+ # partition_alloc library. https://crbug.com/1467773
+ pdf_use_partition_alloc_new_location = false
+
# Build PDFium to use Skia (experimental) for all PDFium graphics.
# If enabled, coexists in build with AGG graphics and the default
# renderer is selectable at runtime.
diff --git a/samples/BUILD.gn b/samples/BUILD.gn
index 981750b..000cfb6 100644
--- a/samples/BUILD.gn
+++ b/samples/BUILD.gn
@@ -24,6 +24,9 @@
if (pdf_use_partition_alloc) {
defines += [ "PDF_USE_PARTITION_ALLOC" ]
}
+ if (pdf_use_partition_alloc_new_location) {
+ defines += [ "PDF_USE_PARTITION_ALLOC_NEW_LOCATION" ]
+ }
if (enable_callgrind) {
defines += [ "ENABLE_CALLGRIND" ]
}
diff --git a/testing/BUILD.gn b/testing/BUILD.gn
index 331c2af..4044dec 100644
--- a/testing/BUILD.gn
+++ b/testing/BUILD.gn
@@ -56,7 +56,11 @@
"allocator_shim_config.cpp",
"allocator_shim_config.h",
]
- deps += [ "//base/allocator/partition_allocator:partition_alloc" ]
+ if (pdf_use_partition_alloc_new_location) {
+ deps += [ "//base/allocator/partition_allocator/src/partition_alloc" ]
+ } else {
+ deps += [ "//base/allocator/partition_allocator:partition_alloc" ]
+ }
}
if (pdf_enable_v8) {
sources += [
diff --git a/testing/allocator_shim_config.cpp b/testing/allocator_shim_config.cpp
index 8f0380d..232e735 100644
--- a/testing/allocator_shim_config.cpp
+++ b/testing/allocator_shim_config.cpp
@@ -4,8 +4,13 @@
#include "testing/allocator_shim_config.h"
+#if defined(PDF_USE_PARTITION_ALLOC_NEW_LOCATION)
+#include "base/allocator/partition_allocator/src/partition_alloc/partition_alloc_buildflags.h"
+#include "base/allocator/partition_allocator/src/partition_alloc/shim/allocator_shim.h"
+#else
#include "base/allocator/partition_allocator/partition_alloc_buildflags.h"
#include "base/allocator/partition_allocator/shim/allocator_shim.h"
+#endif
namespace pdfium {