memory.current memory.grow

extensions
Volodymyr Shymanskyy 5 years ago
parent 7a3c03558c
commit 6726d84dee

@ -920,7 +920,7 @@ _ (GetBlockScope (o, & scope, target));
if (scope->opcode == c_waOp_loop)
{
m3NotImplemented();
m3NotImplemented(); // TODO
}
else
{
@ -1039,6 +1039,32 @@ _ (EmitOp (o, op_CallIndirect));
_catch: return result;
}
M3Result Compile_Memory_Current (IM3Compilation o, u8 i_opcode)
{
M3Result result;
i8 reserved;
_ (ReadLEB_i7 (& reserved, & o->wasm, o->wasmEnd));
_ (EmitOp (o, op_MemCurrent));
EmitPointer (o, o->module);
_catch: return result;
}
M3Result Compile_Memory_Grow (IM3Compilation o, u8 i_opcode)
{
M3Result result;
i8 reserved;
_ (ReadLEB_i7 (& reserved, & o->wasm, o->wasmEnd));
_ (EmitOp (o, op_MemGrow));
EmitPointer (o, o->module);
_catch: return result;
}
M3Result ReadBlockType (IM3Compilation o, u8 * o_blockType)
{
@ -1324,8 +1350,8 @@ const M3OpInfo c_operations [] =
M3OP( "i64.store16", -2, none, d_binOpList (i64, Store_i16), Compile_Load_Store ), // 0x3d
M3OP( "i64.store32", -2, none, d_binOpList (i64, Store_i32), Compile_Load_Store ), // 0x3e
M3OP( "current_memory", 1, i_32, d_emptyOpList(), NULL ), // 0x3f TODO
M3OP( "grow_memory", 0, i_32, d_emptyOpList(), NULL ), // 0x40 TODO
M3OP( "memory.current", 1, i_32, d_emptyOpList(), Compile_Memory_Current ), // 0x3f
M3OP( "memory.grow", 0, i_32, d_emptyOpList(), Compile_Memory_Grow ), // 0x40
M3OP( "i32.const", 1, i_32, d_emptyOpList(), Compile_Const_i32 ), // 0x41
M3OP( "i64.const", 1, i_64, d_emptyOpList(), Compile_Const_i64 ), // 0x42

@ -12,7 +12,7 @@
m3ret_t ReportOutOfBoundsMemoryError (pc_t i_pc, u8 * i_mem, u32 i_offset)
{
M3MemoryHeader * info = (M3MemoryHeader *) (i_mem - sizeof (M3MemoryHeader));
M3MemoryHeader * info = (M3MemoryHeader*)(i_mem) - 1;
u8 * mem8 = i_mem + i_offset;
ErrorModule (c_m3Err_trapOutOfBoundsMemoryAccess, info->module, "memory bounds: [%p %p); accessed: %p; offset: %u overflow: %zd bytes", i_mem, info->end, mem8, i_offset, mem8 - (u8 *) info->end);
@ -81,6 +81,37 @@ d_m3OpDef (CallIndirect)
}
d_m3OpDef (MemCurrent)
{
IM3Module module = immediate (IM3Module);
IM3Memory io_memory = &module->memory;
size_t actualSize = io_memory->virtualSize; //(u8 *) memory->mallocated->end - (u8 *) memory->wasmPages;
_r0 = actualSize / c_m3MemPageSize;
return nextOp ();
}
d_m3OpDef (MemGrow)
{
IM3Module module = immediate (IM3Module);
IM3Memory io_memory = &module->memory;
size_t actualSize = io_memory->virtualSize;
size_t requiredSize = actualSize + (_r0 * c_m3MemPageSize);
io_memory->virtualSize = requiredSize;
_r0 = actualSize / c_m3MemPageSize;
// TODO: cannot do an actual reallocation here, as _mem will only be affected in subsequent operations
// i.e. return ((IM3Operation)(* _pc))(_pc + 1, _sp, io_memory->wasmPages, _r0, _fp0);
return nextOp ();
}
// it's a debate: should the compilation be trigger be the caller or callee page.
// it's a much easier to put it in the caller pager. if it's in the callee, either the entire page
// has be left dangling or it's just a stub that jumps to a newly acquire page. In Gestalt, I opted

@ -503,6 +503,8 @@ d_m3OpDecl (Call)
d_m3OpDecl (CallIndirect)
d_m3OpDecl (Entry)
d_m3OpDecl (MemCurrent)
d_m3OpDecl (MemGrow)
d_m3Op (Const)
{

Loading…
Cancel
Save