5 #ifndef V8_WASM_WASM_MEMORY_H_ 6 #define V8_WASM_WASM_MEMORY_H_ 9 #include <unordered_map> 11 #include "src/base/platform/mutex.h" 12 #include "src/flags.h" 13 #include "src/handles.h" 14 #include "src/objects/js-array-buffer.h" 35 enum ReservationLimit { kSoftLimit, kHardLimit };
36 bool ReserveAddressSpace(
size_t num_bytes, ReservationLimit limit);
38 void RegisterAllocation(
Isolate* isolate,
void* allocation_base,
39 size_t allocation_length,
void* buffer_start,
40 size_t buffer_length);
43 void* allocation_base =
nullptr;
44 size_t allocation_length = 0;
45 void* buffer_start =
nullptr;
46 size_t buffer_length = 0;
51 void* buffer_start,
size_t buffer_length)
52 : allocation_base(allocation_base),
53 allocation_length(allocation_length),
54 buffer_start(buffer_start),
55 buffer_length(buffer_length) {
56 DCHECK_LE(reinterpret_cast<uintptr_t>(allocation_base),
57 reinterpret_cast<uintptr_t>(buffer_start));
59 reinterpret_cast<uintptr_t>(allocation_base) + allocation_length,
60 reinterpret_cast<uintptr_t>(buffer_start));
62 reinterpret_cast<uintptr_t>(allocation_base) + allocation_length,
63 reinterpret_cast<uintptr_t>(buffer_start) + buffer_length);
70 void ReleaseReservation(
size_t num_bytes);
75 bool IsWasmMemory(
const void* buffer_start);
79 bool HasFullGuardRegions(
const void* buffer_start);
83 const AllocationData* FindAllocationData(
const void* buffer_start);
88 bool FreeMemoryIfIsWasmMemory(
Isolate* isolate,
const void* buffer_start);
93 enum class AllocationStatus {
98 kAddressSpaceLimitReachedFailure,
105 void AddAddressSpaceSample(
Isolate* isolate);
114 std::atomic<size_t> reserved_address_space_{0};
121 size_t allocated_address_space_ = 0;
125 std::unordered_map<const void*, AllocationData> allocations_;
127 DISALLOW_COPY_AND_ASSIGN(WasmMemoryTracker);
133 MaybeHandle<JSArrayBuffer> NewArrayBuffer(
134 Isolate*,
size_t size, SharedFlag shared = SharedFlag::kNotShared);
137 Isolate*,
void* backing_store,
size_t size,
bool is_external,
138 SharedFlag shared = SharedFlag::kNotShared);
147 #endif // V8_WASM_WASM_MEMORY_H_