7#include "core/fxcrt/fx_memory.h"
9#include "core/fxcrt/compiler_specific.h"
10#include "core/fxcrt/fx_safe_types.h"
12#if defined(PDF_USE_PARTITION_ALLOC)
13#include "partition_alloc/partition_alloc.h"
15#error "File compiled under wrong build option."
20const partition_alloc::PartitionOptions kOptions = {};
23#ifndef V8_ENABLE_SANDBOX
24 partition_alloc::PartitionAllocator array_buffer_allocator{kOptions};
27 partition_alloc::PartitionAllocator general_allocator{kOptions};
28 partition_alloc::PartitionAllocator string_allocator{kOptions};
31Allocators* g_allocators =
nullptr;
33#ifndef V8_ENABLE_SANDBOX
34partition_alloc::PartitionAllocator& GetArrayBufferPartitionAllocator() {
35 return g_allocators->array_buffer_allocator;
39partition_alloc::PartitionAllocator& GetGeneralPartitionAllocator() {
40 return g_allocators->general_allocator;
43partition_alloc::PartitionAllocator& GetStringPartitionAllocator() {
44 return g_allocators->string_allocator;
51void*
Alloc(size_t num_members, size_t member_size) {
52 FX_SAFE_SIZE_T total = member_size;
57 return GetGeneralPartitionAllocator()
59 ->AllocInline<partition_alloc::AllocFlags::kReturnNull>(
60 total.ValueOrDie(),
"GeneralPartition");
63void*
Calloc(size_t num_members, size_t member_size) {
64 FX_SAFE_SIZE_T total = member_size;
69 return GetGeneralPartitionAllocator()
71 ->AllocInline<partition_alloc::AllocFlags::kReturnNull |
72 partition_alloc::AllocFlags::kZeroFill>(total.ValueOrDie(),
76void*
Realloc(
void* ptr, size_t num_members, size_t member_size) {
77 FX_SAFE_SIZE_T size = num_members;
82 return GetGeneralPartitionAllocator()
84 ->Realloc<partition_alloc::AllocFlags::kReturnNull>(
85 ptr, size.ValueOrDie(),
"GeneralPartition");
98 GetGeneralPartitionAllocator().root()->Free(ptr);
102void*
StringAlloc(size_t num_members, size_t member_size) {
103 FX_SAFE_SIZE_T total = member_size;
104 total *= num_members;
105 if (!total.IsValid())
108 return GetStringPartitionAllocator()
110 ->AllocInline<partition_alloc::AllocFlags::kReturnNull>(
111 total.ValueOrDie(),
"StringPartition");
124 GetStringPartitionAllocator().root()->Free(ptr);
132 g_allocators =
new Allocators();
138 g_allocators =
nullptr;
141#ifndef V8_ENABLE_SANDBOX
143 return GetArrayBufferPartitionAllocator()
145 ->AllocInline<partition_alloc::AllocFlags::kZeroFill>(length,
150 return GetArrayBufferPartitionAllocator().root()->Alloc(length,
155 GetArrayBufferPartitionAllocator().root()->Free(data);
void * FX_ArrayBufferAllocate(size_t length)
void FX_DestroyMemoryAllocators()
void FX_InitializeMemoryAllocators()
void FX_ArrayBufferFree(void *data)
void * FX_ArrayBufferAllocateUninitialized(size_t length)
void * Alloc(size_t num_members, size_t member_size)
void * StringAlloc(size_t num_members, size_t member_size)
void * Realloc(void *ptr, size_t num_members, size_t member_size)
void StringDealloc(void *ptr)
void * Calloc(size_t num_members, size_t member_size)