Skip to content

Commit

Permalink
Split up raw_ptr.cc implementation files.
Browse files Browse the repository at this point in the history
Intent is to move things which aren't part of raw_ptr directly or
the no-op impl out into separate impl files.

-- Rename Impls to match file naming convention.

Change-Id: Ie3fde3bb7d6e46438a36c21053480023084a6d30
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4189361
Reviewed-by: Bartek Nowierski <bartekn@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1096952}
  • Loading branch information
tsepez authored and Chromium LUCI CQ committed Jan 25, 2023
1 parent 0ecc83c commit ab6742e
Show file tree
Hide file tree
Showing 13 changed files with 796 additions and 710 deletions.
2 changes: 1 addition & 1 deletion base/allocator/partition_alloc_support.cc
Expand Up @@ -468,7 +468,7 @@ std::string ExtractDanglingPtrSignature(std::string stacktrace) {
// We are looking for the callers of the function releasing the raw_ptr and
// freeing memory:
const StringPiece callees[] = {
"internal::BackupRefPtrImpl<>::ReleaseInternal()",
"internal::RawPtrBackupRefImpl<>::ReleaseInternal()",
"internal::PartitionFree()",
"base::(anonymous namespace)::FreeFn()",
};
Expand Down
18 changes: 17 additions & 1 deletion base/allocator/partition_allocator/BUILD.gn
Expand Up @@ -373,7 +373,23 @@ source_set("raw_ptr") {
"pointers/raw_ptr_exclusion.h",
"pointers/raw_ref.h",
]
sources = [ "pointers/raw_ptr.cc" ]
sources = []
if (enable_backup_ref_ptr_support) {
sources += [
"pointers/raw_ptr_backup_ref_impl.cc",
"pointers/raw_ptr_backup_ref_impl.h",
]
} else if (use_hookable_raw_ptr) {
sources += [
"pointers/raw_ptr_hookable_impl.cc",
"pointers/raw_ptr_hookable_impl.h",
]
} else if (use_asan_unowned_ptr) {
sources += [
"pointers/raw_ptr_asan_unowned_impl.cc",
"pointers/raw_ptr_asan_unowned_impl.h",
]
}
if (use_partition_alloc) {
public_deps = [ ":partition_alloc" ]
}
Expand Down
12 changes: 6 additions & 6 deletions base/allocator/partition_allocator/partition_alloc.gni
Expand Up @@ -55,7 +55,7 @@ declare_args() {

declare_args() {
# Build support for Use-after-Free protection via BackupRefPtr (BRP) or
# MTECheckedPtr, and switch the raw_ptr<T> implementation to BackupRefPtrImpl
# MTECheckedPtr, and switch the raw_ptr<T> implementation to RawPtrBackupRefImpl
# and MTECheckedPtrImp, respectively. They're mutually exclusive.
#
# These are effective only for memory allocated from PartitionAlloc, so it is
Expand Down Expand Up @@ -208,15 +208,15 @@ assert(
assert(!enable_backup_ref_ptr_support || !use_asan_unowned_ptr,
"Both BackupRefPtr and AsanUnownedPtr can't be enabled at the same time")

# HookableRawPtrImpl and BackupRefPtr are mutually exclusive variants of raw_ptr.
# RawPtrHookableImpl and BackupRefPtr are mutually exclusive variants of raw_ptr.
assert(
!use_hookable_raw_ptr || !enable_backup_ref_ptr_support,
"Both HookableRawPtrImpl and BackupRefPtr can't be enabled at the same time")
"Both RawPtrHookableImpl and BackupRefPtr can't be enabled at the same time")

# HookableRawPtrImpl and AsanUnownedPtr are mutually exclusive variants of raw_ptr.
# RawPtrHookableImpl and AsanUnownedPtr are mutually exclusive variants of raw_ptr.
assert(
!use_hookable_raw_ptr || !use_asan_unowned_ptr,
"Both HookableRawPtrImpl and AsanUnownedPtr can't be enabled at the same time")
"Both RawPtrHookableImpl and AsanUnownedPtr can't be enabled at the same time")

assert(!use_asan_backup_ref_ptr || is_asan,
"AsanBackupRefPtr requires AddressSanitizer")
Expand All @@ -231,7 +231,7 @@ assert(build_with_chromium || !use_asan_backup_ref_ptr,
"AsanBackupRefPtr is not supported outside Chromium")

assert(!use_asan_backup_ref_ptr || use_hookable_raw_ptr,
"AsanBackupRefPtr requires HookableRawPtrImpl")
"AsanBackupRefPtr requires RawPtrHookableImpl")

declare_args() {
enable_pkeys = is_linux && target_cpu == "x64"
Expand Down
2 changes: 1 addition & 1 deletion base/allocator/partition_allocator/partition_ref_count.h
Expand Up @@ -25,7 +25,7 @@ namespace partition_alloc::internal {

#if BUILDFLAG(ENABLE_BACKUP_REF_PTR_SUPPORT)

// Special-purpose atomic reference count class used by BackupRefPtrImpl.
// Special-purpose atomic reference count class used by RawPtrBackupRefImpl.
// The least significant bit of the count is reserved for tracking the liveness
// state of an allocation: it's set when the allocation is created and cleared
// on free(). So the count can be:
Expand Down

0 comments on commit ab6742e

Please sign in to comment.