#include "src/objects/backing-store.h"
#include <cstring>
#include <optional>
#include "src/base/bits.h"
#include "src/execution/isolate.h"
#include "src/handles/global-handles.h"
#include "src/logging/counters.h"
#include "src/sandbox/sandbox.h"
#if V8_ENABLE_WEBASSEMBLY
#include "src/trap-handler/trap-handler.h"
#include "src/wasm/wasm-constants.h"
#include "src/wasm/wasm-engine.h"
#include "src/wasm/wasm-limits.h"
#include "src/wasm/wasm-module.h"
#include "src/wasm/wasm-objects-inl.h"
#endif
#define TRACE_BS …
namespace v8::internal {
namespace {
#if V8_ENABLE_WEBASSEMBLY && V8_TARGET_ARCH_64_BIT
constexpr size_t kFullGuardSize32 = …;
constexpr size_t kFullGuardSize64 = …;
#endif
std::atomic<uint32_t> next_backing_store_id_{ … };
enum class AllocationStatus { … };
base::AddressRegion GetReservedRegion(bool has_guard_regions,
bool is_wasm_memory64, void* buffer_start,
size_t byte_capacity) { … }
size_t GetReservationSize(bool has_guard_regions, size_t byte_capacity,
bool is_wasm_memory64) { … }
void RecordStatus(Isolate* isolate, AllocationStatus status) { … }
}
struct SharedWasmMemoryData { … };
BackingStore::BackingStore(void* buffer_start, size_t byte_length,
size_t max_byte_length, size_t byte_capacity,
SharedFlag shared, ResizableFlag resizable,
bool is_wasm_memory, bool is_wasm_memory64,
bool has_guard_regions, bool custom_deleter,
bool empty_deleter)
: … { … }
BackingStore::~BackingStore() { … }
std::unique_ptr<BackingStore> BackingStore::Allocate(
Isolate* isolate, size_t byte_length, SharedFlag shared,
InitializedFlag initialized) { … }
void BackingStore::SetAllocatorFromIsolate(Isolate* isolate) { … }
std::unique_ptr<BackingStore> BackingStore::TryAllocateAndPartiallyCommitMemory(
Isolate* isolate, size_t byte_length, size_t max_byte_length,
size_t page_size, size_t initial_pages, size_t maximum_pages,
WasmMemoryFlag wasm_memory, SharedFlag shared) { … }
#if V8_ENABLE_WEBASSEMBLY
std::unique_ptr<BackingStore> BackingStore::AllocateWasmMemory(
Isolate* isolate, size_t initial_pages, size_t maximum_pages,
WasmMemoryFlag wasm_memory, SharedFlag shared) { … }
std::unique_ptr<BackingStore> BackingStore::CopyWasmMemory(
Isolate* isolate, size_t new_pages, size_t max_pages,
WasmMemoryFlag wasm_memory) { … }
std::optional<size_t> BackingStore::GrowWasmMemoryInPlace(Isolate* isolate,
size_t delta_pages,
size_t max_pages) { … }
void BackingStore::AttachSharedWasmMemoryObject(
Isolate* isolate, Handle<WasmMemoryObject> memory_object) { … }
void BackingStore::BroadcastSharedWasmMemoryGrow(Isolate* isolate) const { … }
void BackingStore::RemoveSharedWasmMemoryObjects(Isolate* isolate) { … }
void BackingStore::UpdateSharedWasmMemoryObjects(Isolate* isolate) { … }
#endif
BackingStore::ResizeOrGrowResult BackingStore::ResizeInPlace(
Isolate* isolate, size_t new_byte_length) { … }
BackingStore::ResizeOrGrowResult BackingStore::GrowInPlace(
Isolate* isolate, size_t new_byte_length) { … }
std::unique_ptr<BackingStore> BackingStore::WrapAllocation(
void* allocation_base, size_t allocation_length,
v8::BackingStore::DeleterCallback deleter, void* deleter_data,
SharedFlag shared) { … }
std::unique_ptr<BackingStore> BackingStore::EmptyBackingStore(
SharedFlag shared) { … }
bool BackingStore::Reallocate(Isolate* isolate, size_t new_byte_length) { … }
v8::ArrayBuffer::Allocator* BackingStore::get_v8_api_array_buffer_allocator() { … }
SharedWasmMemoryData* BackingStore::get_shared_wasm_memory_data() const { … }
namespace {
struct GlobalBackingStoreRegistryImpl { … };
DEFINE_LAZY_LEAKY_OBJECT_GETTER(…)
}
void GlobalBackingStoreRegistry::Register(
std::shared_ptr<BackingStore> backing_store) { … }
void GlobalBackingStoreRegistry::Unregister(BackingStore* backing_store) { … }
void GlobalBackingStoreRegistry::Purge(Isolate* isolate) { … }
#if V8_ENABLE_WEBASSEMBLY
void GlobalBackingStoreRegistry::AddSharedWasmMemoryObject(
Isolate* isolate, BackingStore* backing_store,
Handle<WasmMemoryObject> memory_object) { … }
void GlobalBackingStoreRegistry::BroadcastSharedWasmMemoryGrow(
Isolate* isolate, const BackingStore* backing_store) { … }
void GlobalBackingStoreRegistry::UpdateSharedWasmMemoryObjects(
Isolate* isolate) { … }
#endif
}
#undef TRACE_BS