blob: fb08d2214dc8b98465a90b4ca98d771b23546e81 [file] [log] [blame]
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/memory/checked_ptr.h"
#include "base/allocator/buildflags.h"
// USE_BACKUP_REF_PTR implies USE_PARTITION_ALLOC, needed for code under
// allocator/partition_allocator/ to be built.
#if BUILDFLAG(USE_BACKUP_REF_PTR)
#include "base/allocator/partition_allocator/partition_alloc.h"
#include "base/allocator/partition_allocator/partition_ref_count.h"
#include "base/allocator/partition_allocator/partition_root.h"
#include "base/check.h"
namespace base {
namespace internal {
void BackupRefPtrImpl::AcquireInternal(void* ptr) {
DCHECK(IsManagedByPartitionAllocBRPPool(ptr));
void* slot_start = PartitionAllocGetSlotStart(ptr);
PartitionRefCountPointer(slot_start)->Acquire();
}
void BackupRefPtrImpl::ReleaseInternal(void* ptr) {
DCHECK(IsManagedByPartitionAllocBRPPool(ptr));
void* slot_start = PartitionAllocGetSlotStart(ptr);
if (PartitionRefCountPointer(slot_start)->Release())
PartitionAllocFreeForRefCounting(slot_start);
}
bool BackupRefPtrImpl::IsPointeeAlive(void* ptr) {
DCHECK(IsManagedByPartitionAllocBRPPool(ptr));
void* slot_start = PartitionAllocGetSlotStart(ptr);
return PartitionRefCountPointer(slot_start)->IsAlive();
}
bool BackupRefPtrImpl::IsValidDelta(void* ptr, ptrdiff_t delta) {
return PartitionAllocIsValidPtrDelta(ptr, delta);
}
} // namespace internal
} // namespace base
#endif // BUILDFLAG(USE_BACKUP_REF_PTR)