diff --git a/src/runtime/Memory.cpp b/src/runtime/Memory.cpp index 71eafbaf8..184175fcb 100644 --- a/src/runtime/Memory.cpp +++ b/src/runtime/Memory.cpp @@ -43,7 +43,7 @@ Memory::Memory(uint64_t initialSizeInByte, uint64_t maximumSizeInByte, bool isSh , m_targetBuffers(nullptr) , m_isShared(isShared) { - ASSERT(initialSizeInByte <= std::numeric_limits::max()); + RELEASE_ASSERT(initialSizeInByte <= std::numeric_limits::max()); #if defined(WALRUS_USE_MMAP) if (m_maximumSizeInByte) { #ifndef WALRUS_32_MEMORY_INITIAL_MMAP_RESERVED_ADDRESS_SIZE @@ -58,7 +58,7 @@ Memory::Memory(uint64_t initialSizeInByte, uint64_t maximumSizeInByte, bool isSh #else WALRUS_64_MEMORY_INITIAL_MMAP_RESERVED_ADDRESS_SIZE; #endif - m_reservedSizeInByte = std::min(initialReservedSize, m_maximumSizeInByte); + m_reservedSizeInByte = std::min(std::max(initialReservedSize, initialSizeInByte), m_maximumSizeInByte); m_buffer = reinterpret_cast(mmap(NULL, m_reservedSizeInByte, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0)); RELEASE_ASSERT(MAP_FAILED != m_buffer); mprotect(m_buffer, initialSizeInByte, (PROT_READ | PROT_WRITE)); diff --git a/test/jit/memory_large.wast b/test/jit/memory_large.wast new file mode 100644 index 000000000..91f9a706f --- /dev/null +++ b/test/jit/memory_large.wast @@ -0,0 +1,19 @@ +(module + (; 1GB memory, can be quite large for a 32 bit system. ;) + (memory 16384 16384) + + (func (export "set") (param i32 i32) + local.get 0 + local.get 1 + i32.store8 + ) + + (func (export "get") (param i32) (result i32) + local.get 0 + i32.load8_u + ) +) + +(invoke "set" (i32.const 0x3fffffff) (i32.const 0xaa)) +(assert_return (invoke "get" (i32.const 0x3fffffff)) (i32.const 0xaa)) +(assert_trap (invoke "get" (i32.const 0x40000000)) "out of bounds memory access")