#include "partition_alloc/page_allocator.h"
#include <atomic>
#include <cstdint>
#include "partition_alloc/address_space_randomization.h"
#include "partition_alloc/build_config.h"
#include "partition_alloc/page_allocator_internal.h"
#include "partition_alloc/partition_alloc_base/bits.h"
#include "partition_alloc/partition_alloc_base/thread_annotations.h"
#include "partition_alloc/partition_alloc_check.h"
#include "partition_alloc/partition_lock.h"
#if PA_BUILDFLAG(IS_WIN)
#include <windows.h>
#endif
#if PA_BUILDFLAG(IS_WIN)
#include "partition_alloc/page_allocator_internals_win.h"
#elif PA_BUILDFLAG(IS_POSIX)
#include "partition_alloc/page_allocator_internals_posix.h"
#elif PA_BUILDFLAG(IS_FUCHSIA)
#include "partition_alloc/page_allocator_internals_fuchsia.h"
#else
#error Platform not supported.
#endif
namespace partition_alloc {
namespace {
internal::Lock g_reserve_lock;
internal::Lock& GetReserveLock() { … }
std::atomic<size_t> g_total_mapped_address_space;
uintptr_t s_reservation_address PA_GUARDED_BY(GetReserveLock()) = …;
size_t s_reservation_size PA_GUARDED_BY(GetReserveLock()) = …;
uintptr_t AllocPagesIncludingReserved(
uintptr_t address,
size_t length,
PageAccessibilityConfiguration accessibility,
PageTag page_tag,
int file_descriptor_for_shared_alloc = -1) { … }
uintptr_t TrimMapping(uintptr_t base_address,
size_t base_length,
size_t trim_length,
uintptr_t alignment,
uintptr_t alignment_offset,
PageAccessibilityConfiguration accessibility) { … }
}
uintptr_t NextAlignedWithOffset(uintptr_t address,
uintptr_t alignment,
uintptr_t requested_offset) { … }
namespace internal {
uintptr_t SystemAllocPages(uintptr_t hint,
size_t length,
PageAccessibilityConfiguration accessibility,
PageTag page_tag,
int file_descriptor_for_shared_alloc) { … }
}
uintptr_t AllocPages(size_t length,
size_t align,
PageAccessibilityConfiguration accessibility,
PageTag page_tag,
int file_descriptor_for_shared_alloc) { … }
uintptr_t AllocPages(uintptr_t address,
size_t length,
size_t align,
PageAccessibilityConfiguration accessibility,
PageTag page_tag) { … }
void* AllocPages(void* address,
size_t length,
size_t align,
PageAccessibilityConfiguration accessibility,
PageTag page_tag) { … }
uintptr_t AllocPagesWithAlignOffset(
uintptr_t address,
size_t length,
size_t align,
size_t align_offset,
PageAccessibilityConfiguration accessibility,
PageTag page_tag,
int file_descriptor_for_shared_alloc) { … }
void FreePages(uintptr_t address, size_t length) { … }
void FreePages(void* address, size_t length) { … }
bool TrySetSystemPagesAccess(uintptr_t address,
size_t length,
PageAccessibilityConfiguration accessibility) { … }
bool TrySetSystemPagesAccess(void* address,
size_t length,
PageAccessibilityConfiguration accessibility) { … }
void SetSystemPagesAccess(uintptr_t address,
size_t length,
PageAccessibilityConfiguration accessibility) { … }
void SetSystemPagesAccess(void* address,
size_t length,
PageAccessibilityConfiguration accessibility) { … }
void DecommitSystemPages(
uintptr_t address,
size_t length,
PageAccessibilityDisposition accessibility_disposition) { … }
void DecommitSystemPages(
void* address,
size_t length,
PageAccessibilityDisposition accessibility_disposition) { … }
bool DecommitAndZeroSystemPages(uintptr_t address,
size_t length,
PageTag page_tag) { … }
bool DecommitAndZeroSystemPages(void* address,
size_t length,
PageTag page_tag) { … }
void RecommitSystemPages(
uintptr_t address,
size_t length,
PageAccessibilityConfiguration accessibility,
PageAccessibilityDisposition accessibility_disposition) { … }
bool TryRecommitSystemPages(
uintptr_t address,
size_t length,
PageAccessibilityConfiguration accessibility,
PageAccessibilityDisposition accessibility_disposition) { … }
void DiscardSystemPages(uintptr_t address, size_t length) { … }
void DiscardSystemPages(void* address, size_t length) { … }
bool ReserveAddressSpace(size_t size) { … }
bool ReleaseReservation() { … }
bool HasReservationForTesting() { … }
uint32_t GetAllocPageErrorCode() { … }
size_t GetTotalMappedSize() { … }
#if PA_BUILDFLAG(IS_WIN)
namespace {
bool g_retry_on_commit_failure = false;
}
void SetRetryOnCommitFailure(bool retry_on_commit_failure) {
g_retry_on_commit_failure = retry_on_commit_failure;
}
bool GetRetryOnCommitFailure() {
return g_retry_on_commit_failure;
}
#endif
}