1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 04:17:35 +00:00

LibWasm: Implement memory.grow, memory.size and drop

These allow a very basic memory-using program to work.
This commit is contained in:
Ali Mohammad Pur 2021-05-03 22:45:47 +04:30 committed by Andreas Kling
parent 3402381d7a
commit 95b9821f26
3 changed files with 39 additions and 4 deletions

View file

@ -297,7 +297,20 @@ public:
auto& data() const { return m_data; }
auto& data() { return m_data; }
void grow(size_t new_size) { m_data.grow(new_size); }
bool grow(size_t size_to_grow)
{
if (size_to_grow == 0)
return true;
auto new_size = m_data.size() + size_to_grow;
if (m_type.limits().max().value_or(new_size) < new_size)
return false;
auto previous_size = m_size;
m_data.grow(new_size);
m_size = new_size;
// The spec requires that we zero out everything on grow
__builtin_memset(m_data.offset_pointer(previous_size), 0, size_to_grow);
return true;
}
private:
const MemoryType& m_type;