Skip to content

Commit

Permalink
Use partition_alloc PA_BUILDFLAG(...) outside PA. #cleanup
Browse files Browse the repository at this point in the history
This is an automated #cleanup patch.

Migrate:
- from  BUILDFLAG (legacy chromium macro)
- to PA_BUILDFLAG (new partition_alloc macro)

The first is going to be removed in favor of the second.

The previous patch modified every occurrences inside partition_alloc,
this one does the same, but outside of partition_alloc.

Follow-ups will:
- Update dawn.
- Update pdfium.

Bug: chromium:1508847
Change-Id: Icc3fa34ee376e5ae866e9d456c363cb4180d4a49
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5490530
Reviewed-by: danakj <[email protected]>
Owners-Override: danakj <[email protected]>
Commit-Queue: Arthur Sonzogni <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1294381}
  • Loading branch information
ArthurSonzogni authored and Chromium LUCI CQ committed Apr 30, 2024
1 parent ef463f0 commit 62e877a
Show file tree
Hide file tree
Showing 90 changed files with 484 additions and 475 deletions.
2 changes: 1 addition & 1 deletion PRESUBMIT_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4761,7 +4761,7 @@ def testPermissibleUsage(self):
# own thing at their own risk.
MockFile('okay3.cc', ['PA_DCHECK_IS_ON']),
MockFile('okay4.cc', ['#if PA_DCHECK_IS_ON']),
MockFile('okay6.cc', ['BUILDFLAG(PA_DCHECK_IS_ON)']),
MockFile('okay6.cc', ['PA_BUILDFLAG(PA_DCHECK_IS_ON)']),
]
errors = PRESUBMIT.CheckDCHECK_IS_ONHasBraces(input_api, MockOutputApi())
self.assertEqual(0, len(errors))
Expand Down
5 changes: 3 additions & 2 deletions base/allocator/allocator_check.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@
namespace base::allocator {

bool IsAllocatorInitialized() {
#if BUILDFLAG(IS_WIN) && BUILDFLAG(USE_ALLOCATOR_SHIM)
#if BUILDFLAG(IS_WIN) && PA_BUILDFLAG(USE_ALLOCATOR_SHIM)
// Set by allocator_shim_override_ucrt_symbols_win.h when the
// shimmed _set_new_mode() is called.
return allocator_shim::g_is_win_shim_layer_initialized;
#elif BUILDFLAG(IS_APPLE) && !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) && \
!BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC) && BUILDFLAG(USE_ALLOCATOR_SHIM)
!PA_BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC) && \
PA_BUILDFLAG(USE_ALLOCATOR_SHIM)
// From allocator_interception_mac.mm.
return allocator_shim::g_replaced_default_zone;
#else
Expand Down
10 changes: 5 additions & 5 deletions base/allocator/dispatcher/dispatcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <atomic>
#endif

#if BUILDFLAG(USE_PARTITION_ALLOC)
#if PA_BUILDFLAG(USE_PARTITION_ALLOC)
#include "partition_alloc/partition_alloc_hooks.h"
#endif

Expand Down Expand Up @@ -51,13 +51,13 @@ struct Dispatcher::Impl {
// connected. This way we prevent notifications although no observers are
// present.
static void ConnectToEmitters(const internal::DispatchData& dispatch_data) {
#if BUILDFLAG(USE_ALLOCATOR_SHIM)
#if PA_BUILDFLAG(USE_ALLOCATOR_SHIM)
if (auto* const allocator_dispatch = dispatch_data.GetAllocatorDispatch()) {
allocator_shim::InsertAllocatorDispatch(allocator_dispatch);
}
#endif

#if BUILDFLAG(USE_PARTITION_ALLOC)
#if PA_BUILDFLAG(USE_PARTITION_ALLOC)
{
auto* const allocation_hook = dispatch_data.GetAllocationObserverHook();
auto* const free_hook = dispatch_data.GetFreeObserverHook();
Expand All @@ -70,14 +70,14 @@ struct Dispatcher::Impl {
}

static void DisconnectFromEmitters(internal::DispatchData& dispatch_data) {
#if BUILDFLAG(USE_ALLOCATOR_SHIM)
#if PA_BUILDFLAG(USE_ALLOCATOR_SHIM)
if (auto* const allocator_dispatch = dispatch_data.GetAllocatorDispatch()) {
allocator_shim::RemoveAllocatorDispatchForTesting(
allocator_dispatch); // IN-TEST
}
#endif

#if BUILDFLAG(USE_PARTITION_ALLOC)
#if PA_BUILDFLAG(USE_PARTITION_ALLOC)
partition_alloc::PartitionAllocHooks::SetObserverHooks(nullptr, nullptr);
#endif
}
Expand Down
11 changes: 6 additions & 5 deletions base/allocator/dispatcher/dispatcher_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
#include "build/build_config.h"
#include "partition_alloc/partition_alloc_buildflags.h"

#if BUILDFLAG(USE_PARTITION_ALLOC)
#if PA_BUILDFLAG(USE_PARTITION_ALLOC)
#include "partition_alloc/partition_alloc_for_testing.h"
#endif

#if BUILDFLAG(USE_ALLOCATOR_SHIM)
#if PA_BUILDFLAG(USE_ALLOCATOR_SHIM)
#include "partition_alloc/shim/allocator_shim.h"
#endif

Expand Down Expand Up @@ -94,7 +94,8 @@ TEST_F(BaseAllocatorDispatcherTest, VerifyInitialization) {
DispatcherInitializerGuard g(testing::CreateTupleOfPointers(observers));
}

#if BUILDFLAG(USE_PARTITION_ALLOC) && !defined(MEMORY_TOOL_REPLACES_ALLOCATOR)
#if PA_BUILDFLAG(USE_PARTITION_ALLOC) && \
!defined(MEMORY_TOOL_REPLACES_ALLOCATOR)
// Don't enable this test when MEMORY_TOOL_REPLACES_ALLOCATOR is defined,
// because it makes PartitionAlloc take a different path that doesn't provide
// notifications to observer hooks.
Expand All @@ -117,13 +118,13 @@ TEST_F(BaseAllocatorDispatcherTest, VerifyNotificationUsingPartitionAllocator) {
}
#endif

#if BUILDFLAG(USE_ALLOCATOR_SHIM)
#if PA_BUILDFLAG(USE_ALLOCATOR_SHIM)
struct AllocatorShimAllocator {
void* Alloc(size_t size) { return allocator_shim::UncheckedAlloc(size); }
void Free(void* data) { allocator_shim::UncheckedFree(data); }
};

#if BUILDFLAG(IS_APPLE) && !BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
#if BUILDFLAG(IS_APPLE) && !PA_BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
// Disable the test when running on any of Apple's OSs without PartitionAlloc
// being the default allocator. In this case, all allocations are routed to
// MallocImpl, which then causes the test to terminate unexpectedly.
Expand Down
4 changes: 2 additions & 2 deletions base/allocator/dispatcher/internal/dispatch_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace base::allocator::dispatcher::internal {

#if BUILDFLAG(USE_PARTITION_ALLOC)
#if PA_BUILDFLAG(USE_PARTITION_ALLOC)

DispatchData& DispatchData::SetAllocationObserverHooks(
AllocationObserverHook* allocation_observer_hook,
Expand All @@ -28,7 +28,7 @@ DispatchData::FreeObserverHook* DispatchData::GetFreeObserverHook() const {
}
#endif

#if BUILDFLAG(USE_ALLOCATOR_SHIM)
#if PA_BUILDFLAG(USE_ALLOCATOR_SHIM)
DispatchData& DispatchData::SetAllocatorDispatch(
AllocatorDispatch* allocator_dispatch) {
allocator_dispatch_ = allocator_dispatch;
Expand Down
10 changes: 5 additions & 5 deletions base/allocator/dispatcher/internal/dispatch_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@
#include "build/build_config.h"
#include "partition_alloc/partition_alloc_buildflags.h"

#if BUILDFLAG(USE_PARTITION_ALLOC)
#if PA_BUILDFLAG(USE_PARTITION_ALLOC)
#include "partition_alloc/partition_alloc_hooks.h"
#endif

#if BUILDFLAG(USE_ALLOCATOR_SHIM)
#if PA_BUILDFLAG(USE_ALLOCATOR_SHIM)
#include "partition_alloc/shim/allocator_shim.h"
#endif

namespace base::allocator::dispatcher::internal {

#if BUILDFLAG(USE_ALLOCATOR_SHIM)
#if PA_BUILDFLAG(USE_ALLOCATOR_SHIM)
using allocator_shim::AllocatorDispatch;
#endif

// A simple utility class to pass all the information required to properly hook
// into the memory allocation subsystems from DispatcherImpl to the Dispatcher.
struct BASE_EXPORT DispatchData {
#if BUILDFLAG(USE_PARTITION_ALLOC)
#if PA_BUILDFLAG(USE_PARTITION_ALLOC)
using AllocationObserverHook =
partition_alloc::PartitionAllocHooks::AllocationObserverHook;
using FreeObserverHook =
Expand All @@ -44,7 +44,7 @@ struct BASE_EXPORT DispatchData {
public:
#endif

#if BUILDFLAG(USE_ALLOCATOR_SHIM)
#if PA_BUILDFLAG(USE_ALLOCATOR_SHIM)
DispatchData& SetAllocatorDispatch(AllocatorDispatch* allocator_dispatch);
AllocatorDispatch* GetAllocatorDispatch() const;

Expand Down
30 changes: 15 additions & 15 deletions base/allocator/dispatcher/internal/dispatcher_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@
#include "base/compiler_specific.h"
#include "partition_alloc/partition_alloc_buildflags.h"

#if BUILDFLAG(USE_PARTITION_ALLOC)
#if PA_BUILDFLAG(USE_PARTITION_ALLOC)
#include "partition_alloc/partition_alloc_allocation_data.h"
#endif

#if BUILDFLAG(USE_ALLOCATOR_SHIM)
#if PA_BUILDFLAG(USE_ALLOCATOR_SHIM)
#include "partition_alloc/shim/allocator_shim.h"
#endif

#include <tuple>

namespace base::allocator::dispatcher::internal {

#if BUILDFLAG(USE_ALLOCATOR_SHIM)
#if PA_BUILDFLAG(USE_ALLOCATOR_SHIM)
using allocator_shim::AllocatorDispatch;
#endif

Expand Down Expand Up @@ -83,25 +83,25 @@ struct DispatcherImpl {
private:
static DispatchData CreateDispatchData() {
return DispatchData()
#if BUILDFLAG(USE_PARTITION_ALLOC)
#if PA_BUILDFLAG(USE_PARTITION_ALLOC)
.SetAllocationObserverHooks(&PartitionAllocatorAllocationHook,
&PartitionAllocatorFreeHook)
#endif
#if BUILDFLAG(USE_ALLOCATOR_SHIM)
#if PA_BUILDFLAG(USE_ALLOCATOR_SHIM)
.SetAllocatorDispatch(&allocator_dispatch_)
#endif
;
}

#if BUILDFLAG(USE_PARTITION_ALLOC)
#if PA_BUILDFLAG(USE_PARTITION_ALLOC)
static void PartitionAllocatorAllocationHook(
const partition_alloc::AllocationNotificationData& pa_notification_data) {
AllocationNotificationData dispatcher_notification_data(
pa_notification_data.address(), pa_notification_data.size(),
pa_notification_data.type_name(),
AllocationSubsystem::kPartitionAllocator);

#if BUILDFLAG(HAS_MEMORY_TAGGING)
#if PA_BUILDFLAG(HAS_MEMORY_TAGGING)
dispatcher_notification_data.SetMteReportingMode(
ConvertToMTEMode(pa_notification_data.mte_reporting_mode()));
#endif
Expand All @@ -115,16 +115,16 @@ struct DispatcherImpl {
pa_notification_data.address(),
AllocationSubsystem::kPartitionAllocator);

#if BUILDFLAG(HAS_MEMORY_TAGGING)
#if PA_BUILDFLAG(HAS_MEMORY_TAGGING)
dispatcher_notification_data.SetMteReportingMode(
ConvertToMTEMode(pa_notification_data.mte_reporting_mode()));
#endif

DoNotifyFree(dispatcher_notification_data);
}
#endif // BUILDFLAG(USE_PARTITION_ALLOC)
#endif // PA_BUILDFLAG(USE_PARTITION_ALLOC)

#if BUILDFLAG(USE_ALLOCATOR_SHIM)
#if PA_BUILDFLAG(USE_ALLOCATOR_SHIM)
static void* AllocFn(const AllocatorDispatch* self,
size_t size,
void* context) {
Expand Down Expand Up @@ -286,7 +286,7 @@ struct DispatcherImpl {
}

static AllocatorDispatch allocator_dispatch_;
#endif // BUILDFLAG(USE_ALLOCATOR_SHIM)
#endif // PA_BUILDFLAG(USE_ALLOCATOR_SHIM)

ALWAYS_INLINE static void DoNotifyAllocation(
const AllocationNotificationData& notification_data) {
Expand All @@ -305,7 +305,7 @@ struct DispatcherImpl {
template <typename... ObserverTypes>
std::tuple<ObserverTypes*...> DispatcherImpl<ObserverTypes...>::s_observers;

#if BUILDFLAG(USE_ALLOCATOR_SHIM)
#if PA_BUILDFLAG(USE_ALLOCATOR_SHIM)
template <typename... ObserverTypes>
AllocatorDispatch DispatcherImpl<ObserverTypes...>::allocator_dispatch_ = {
AllocFn, // alloc_function
Expand All @@ -326,7 +326,7 @@ AllocatorDispatch DispatcherImpl<ObserverTypes...>::allocator_dispatch_ = {
AlignedFreeFn, // aligned_free_function
nullptr // next
};
#endif // BUILDFLAG(USE_ALLOCATOR_SHIM)
#endif // PA_BUILDFLAG(USE_ALLOCATOR_SHIM)

// Specialization of DispatcherImpl in case we have no observers to notify. In
// this special case we return a set of null pointers as the Dispatcher must not
Expand All @@ -335,10 +335,10 @@ template <>
struct DispatcherImpl<> {
static DispatchData GetNotificationHooks(std::tuple<> /*observers*/) {
return DispatchData()
#if BUILDFLAG(USE_PARTITION_ALLOC)
#if PA_BUILDFLAG(USE_PARTITION_ALLOC)
.SetAllocationObserverHooks(nullptr, nullptr)
#endif
#if BUILDFLAG(USE_ALLOCATOR_SHIM)
#if PA_BUILDFLAG(USE_ALLOCATOR_SHIM)
.SetAllocatorDispatch(nullptr)
#endif
;
Expand Down
20 changes: 10 additions & 10 deletions base/allocator/dispatcher/internal/dispatcher_internal_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "partition_alloc/partition_alloc_buildflags.h"
#include "testing/gtest/include/gtest/gtest.h"

#if BUILDFLAG(USE_PARTITION_ALLOC)
#if PA_BUILDFLAG(USE_PARTITION_ALLOC)
#include "partition_alloc/partition_alloc_allocation_data.h"
#endif

Expand Down Expand Up @@ -57,14 +57,14 @@ auto FreeNotificationMatches(
std::move(subsystem_matcher)));
}

#if BUILDFLAG(USE_PARTITION_ALLOC)
#if PA_BUILDFLAG(USE_PARTITION_ALLOC)
::partition_alloc::AllocationNotificationData CreatePAAllocationData(
void* address,
size_t size,
partition_alloc::TagViolationReportingMode mte_mode =
partition_alloc::TagViolationReportingMode::kUndefined) {
return ::partition_alloc::AllocationNotificationData(address, size, nullptr)
#if BUILDFLAG(HAS_MEMORY_TAGGING)
#if PA_BUILDFLAG(HAS_MEMORY_TAGGING)
.SetMteReportingMode(mte_mode)
#endif
;
Expand All @@ -75,12 +75,12 @@ ::partition_alloc::FreeNotificationData CreatePAFreeData(
partition_alloc::TagViolationReportingMode mte_mode =
partition_alloc::TagViolationReportingMode::kUndefined) {
return ::partition_alloc::FreeNotificationData(address)
#if BUILDFLAG(HAS_MEMORY_TAGGING)
#if PA_BUILDFLAG(HAS_MEMORY_TAGGING)
.SetMteReportingMode(mte_mode)
#endif
;
}
#endif // BUILDFLAG(USE_PARTITION_ALLOC)
#endif // PA_BUILDFLAG(USE_PARTITION_ALLOC)

struct AllocationEventDispatcherInternalTest : public DispatcherTest {
static void* GetAllocatedAddress() {
Expand All @@ -92,7 +92,7 @@ struct AllocationEventDispatcherInternalTest : public DispatcherTest {
return reinterpret_cast<void*>(0x876543210);
}

#if BUILDFLAG(USE_ALLOCATOR_SHIM)
#if PA_BUILDFLAG(USE_ALLOCATOR_SHIM)
AllocatorDispatch* GetNextAllocatorDispatch() { return &allocator_dispatch_; }
static void* alloc_function(const AllocatorDispatch*, size_t, void*) {
return GetAllocatedAddress();
Expand Down Expand Up @@ -197,7 +197,7 @@ TEST(AllocationEventDispatcherInternalDeathTest,
#endif // defined(GTEST_HAS_DEATH_TEST) && GTEST_HAS_DEATH_TEST &&
// DCHECK_IS_ON()

#if BUILDFLAG(USE_PARTITION_ALLOC)
#if PA_BUILDFLAG(USE_PARTITION_ALLOC)
TEST_F(AllocationEventDispatcherInternalTest,
VerifyPartitionAllocatorHooksAreSet) {
std::array<ObserverMock, 1> observers;
Expand Down Expand Up @@ -253,9 +253,9 @@ TEST_F(AllocationEventDispatcherInternalTest,

dispatch_data.GetFreeObserverHook()(CreatePAFreeData(this));
}
#endif // BUILDFLAG(USE_PARTITION_ALLOC)
#endif // PA_BUILDFLAG(USE_PARTITION_ALLOC)

#if BUILDFLAG(USE_ALLOCATOR_SHIM)
#if PA_BUILDFLAG(USE_ALLOCATOR_SHIM)
TEST_F(AllocationEventDispatcherInternalTest, VerifyAllocatorShimDataIsSet) {
std::array<ObserverMock, 1> observers;

Expand Down Expand Up @@ -619,5 +619,5 @@ TEST_F(AllocationEventDispatcherInternalTest,
allocator_dispatch->aligned_free_function(allocator_dispatch,
GetFreedAddress(), nullptr);
}
#endif // BUILDFLAG(USE_ALLOCATOR_SHIM)
#endif // PA_BUILDFLAG(USE_ALLOCATOR_SHIM)
} // namespace base::allocator::dispatcher::internal
Loading

0 comments on commit 62e877a

Please sign in to comment.