#pragma once
#if ENABLE(WEBASSEMBLY)
#include "WasmPageCount.h"
#include <wtf/RefCounted.h>
#include <wtf/RefPtr.h>
namespace WTF {
class PrintStream;
}
namespace JSC {
class VM;
namespace Wasm {
enum class MemoryMode : uint8_t {
BoundsChecking,
Signaling,
NumberOfMemoryModes
};
static constexpr size_t NumberOfMemoryModes = static_cast<size_t>(MemoryMode::NumberOfMemoryModes);
JS_EXPORT_PRIVATE const char* makeString(MemoryMode);
class Memory : public RefCounted<Memory> {
WTF_MAKE_NONCOPYABLE(Memory);
WTF_MAKE_FAST_ALLOCATED;
public:
void dump(WTF::PrintStream&) const;
explicit operator bool() const { return !!m_memory; }
static void initializePreallocations();
static RefPtr<Memory> create(VM&, PageCount initial, PageCount maximum);
Memory() = default;
~Memory();
static size_t fastMappedRedzoneBytes();
static size_t fastMappedBytes(); static size_t maxFastMemoryCount();
static bool addressIsInActiveFastMemory(void*);
void* memory() const { return m_memory; }
size_t size() const { return m_size; }
size_t indexingMask() const { return m_indexingMask; }
PageCount sizeInPages() const { return PageCount::fromBytes(m_size); }
PageCount initial() const { return m_initial; }
PageCount maximum() const { return m_maximum; }
MemoryMode mode() const { return m_mode; }
bool grow(PageCount);
void check() { ASSERT(!deletionHasBegun()); }
static ptrdiff_t offsetOfIndexingMask() { return OBJECT_OFFSETOF(Memory, m_indexingMask); }
private:
Memory(void* memory, PageCount initial, PageCount maximum, size_t mappedCapacity, MemoryMode);
Memory(PageCount initial, PageCount maximum);
void* m_memory { nullptr };
size_t m_size { 0 };
size_t m_indexingMask { 0 };
PageCount m_initial;
PageCount m_maximum;
size_t m_mappedCapacity { 0 };
MemoryMode m_mode { MemoryMode::BoundsChecking };
};
} }
#else
namespace JSC { namespace Wasm {
class Memory {
public:
static size_t maxFastMemoryCount() { return 0; }
static bool addressIsInActiveFastMemory(void*) { return false; }
};
} }
#endif // ENABLE(WEBASSEMLY)