Skip to content

Commit

Permalink
[PA] Improve formatting (5 of N)
Browse files Browse the repository at this point in the history
Change-Id: Ib1377c056997f8cf58c9a761b336271827886846
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4322777
Reviewed-by: Kalvin Lee <kdlee@chromium.org>
Commit-Queue: Bartek Nowierski <bartekn@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1115543}
  • Loading branch information
bartekn-chromium authored and Chromium LUCI CQ committed Mar 10, 2023
1 parent 196d39f commit c7cd53f
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 19 deletions.
17 changes: 11 additions & 6 deletions base/allocator/partition_allocator/page_allocator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,11 @@ uintptr_t NextAlignedWithOffset(uintptr_t address,

uintptr_t actual_offset = address & (alignment - 1);
uintptr_t new_address;
if (actual_offset <= requested_offset)
if (actual_offset <= requested_offset) {
new_address = address + requested_offset - actual_offset;
else
} else {
new_address = address + alignment + requested_offset - actual_offset;
}
PA_DCHECK(new_address >= address);
PA_DCHECK(new_address - address < alignment);
PA_DCHECK(new_address % alignment == requested_offset);
Expand All @@ -135,8 +136,9 @@ uintptr_t SystemAllocPages(uintptr_t hint,
PA_DCHECK(!(hint & internal::PageAllocationGranularityOffsetMask()));
uintptr_t ret = internal::SystemAllocPagesInternal(
hint, length, accessibility, page_tag, file_descriptor_for_shared_alloc);
if (ret)
if (ret) {
g_total_mapped_address_space.fetch_add(length, std::memory_order_relaxed);
}

return ret;
}
Expand Down Expand Up @@ -210,14 +212,16 @@ uintptr_t AllocPagesWithAlignOffset(
file_descriptor_for_shared_alloc);
if (ret) {
// If the alignment is to our liking, we're done.
if ((ret & align_offset_mask) == align_offset)
if ((ret & align_offset_mask) == align_offset) {
return ret;
}
// Free the memory and try again.
FreePages(ret, length);
} else {
// |ret| is null; if this try was unhinted, we're OOM.
if (internal::kHintIsAdvisory || !address)
if (internal::kHintIsAdvisory || !address) {
return 0;
}
}

#if defined(ARCH_CPU_32_BITS)
Expand Down Expand Up @@ -368,8 +372,9 @@ bool ReserveAddressSpace(size_t size) {
bool ReleaseReservation() {
// To avoid deadlock, call only FreePages.
internal::ScopedGuard guard(GetReserveLock());
if (!s_reservation_address)
if (!s_reservation_address) {
return false;
}

FreePages(s_reservation_address, s_reservation_size);
s_reservation_address = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

#include <stddef.h>

#include "base/allocator/partition_allocator/partition_alloc_base/component_export.h"
#include "base/allocator/partition_allocator/partition_alloc_base/compiler_specific.h"
#include "base/allocator/partition_allocator/partition_alloc_base/component_export.h"
#include "build/build_config.h"

#if BUILDFLAG(IS_APPLE) && defined(ARCH_CPU_64_BITS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,8 @@ uintptr_t SystemAllocPagesInternal(
}

uint64_t address;
status =
zx::vmar::root_self()->map(options, vmar_offset, vmo,
/*vmo_offset=*/0, length, &address);
status = zx::vmar::root_self()->map(options, vmar_offset, vmo,
/*vmo_offset=*/0, length, &address);
if (status != ZX_OK) {
// map() is expected to fail if |hint| is set to an already-in-use location.
if (!hint) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,9 @@ bool UseMapJit() {
base::ScopedCFTypeRef<CFTypeRef> jit_entitlement(
SecTaskCopyValueForEntitlement(
task.get(), CFSTR("com.apple.security.cs.allow-jit"), nullptr));
if (!jit_entitlement)
if (!jit_entitlement) {
return false;
}

return base::mac::CFCast<CFBooleanRef>(jit_entitlement.get()) ==
kCFBooleanTrue;
Expand Down Expand Up @@ -248,8 +249,9 @@ void SetSystemPagesAccessInternal(
//
// In this case, we are almost certainly bumping into the sandbox limit, mark
// the crash as OOM. See SandboxLinux::LimitAddressSpace() for details.
if (ret == -1 && errno == ENOMEM && (access_flags & PROT_WRITE))
if (ret == -1 && errno == ENOMEM && (access_flags & PROT_WRITE)) {
OOM_CRASH(length);
}

PA_PCHECK(0 == ret);
}
Expand Down Expand Up @@ -365,8 +367,9 @@ bool TryRecommitSystemPagesInternal(
if (accessibility_disposition ==
PageAccessibilityDisposition::kRequireUpdate) {
bool ok = TrySetSystemPagesAccess(address, length, accessibility);
if (!ok)
if (!ok) {
return false;
}
}

#if BUILDFLAG(IS_APPLE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ void* VirtualAllocWithRetry(void* address,
// Only retry for commit failures. If this is an address space problem
// (e.g. caller asked for an address which is not available), this is
// unlikely to be resolved by waiting.
if (ret || !should_retry || !IsOutOfMemory(GetLastError()))
if (ret || !should_retry || !IsOutOfMemory(GetLastError())) {
break;
}

Sleep(kDelayMs);
}
Expand Down Expand Up @@ -142,8 +143,9 @@ bool TrySetSystemPagesAccessInternal(
PageAccessibilityConfiguration accessibility) {
void* ptr = reinterpret_cast<void*>(address);
if (accessibility.permissions ==
PageAccessibilityConfiguration::kInaccessible)
PageAccessibilityConfiguration::kInaccessible) {
return VirtualFree(ptr, length, MEM_DECOMMIT) != 0;
}
// Call the retry path even though this function can fail, because callers of
// this are likely to crash the process when this function fails, and we don't
// want that for transient failures.
Expand All @@ -167,8 +169,9 @@ void SetSystemPagesAccessInternal(
if (!VirtualAllocWithRetry(ptr, length, MEM_COMMIT,
GetAccessFlags(accessibility))) {
int32_t error = GetLastError();
if (error == ERROR_COMMITMENT_LIMIT)
if (error == ERROR_COMMITMENT_LIMIT) {
OOM_CRASH(length);
}
// We check `GetLastError` for `ERROR_SUCCESS` here so that in a crash
// report we get the error number.
PA_CHECK(ERROR_SUCCESS == error);
Expand Down
9 changes: 6 additions & 3 deletions base/allocator/partition_allocator/page_allocator_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,9 @@ TEST(PartitionAllocPageAllocatorTest, AllocFailure) {

size_t size = HugeMemoryAmount();
// Skip the test for sanitizers and platforms with ASLR turned off.
if (size == 0)
if (size == 0) {
return;
}

uintptr_t result =
AllocPages(size, PageAllocationGranularity(),
Expand Down Expand Up @@ -160,8 +161,9 @@ TEST(PartitionAllocPageAllocatorTest, MAYBE_ReserveAddressSpace) {

size_t size = HugeMemoryAmount();
// Skip the test for sanitizers and platforms with ASLR turned off.
if (size == 0)
if (size == 0) {
return;
}

bool success = ReserveAddressSpace(size);
if (!success) {
Expand Down Expand Up @@ -517,8 +519,9 @@ TEST(PartitionAllocPageAllocatorTest, PageTagging) {
#endif // BUILDFLAG(IS_ANDROID)

TEST(PartitionAllocPageAllocatorTest, DecommitErasesMemory) {
if (!DecommittedMemoryIsAlwaysZeroed())
if (!DecommittedMemoryIsAlwaysZeroed()) {
return;
}

size_t size = PageAllocationGranularity();
uintptr_t buffer = AllocPages(size, PageAllocationGranularity(),
Expand Down

0 comments on commit c7cd53f

Please sign in to comment.