memgrow fix

extensions
Steven Massey 5 years ago
parent a0220ba37b
commit e4d9be40bf

@ -78,7 +78,7 @@ enum // EWaTypes
c_m3Type_ptr,
c_m3Type_trap,
c_m3Type_module
c_m3Type_runtime
};

@ -379,33 +379,34 @@ M3Result SuppressLookupFailure(M3Result i_result)
return i_result;
}
M3Result m3_LinkWASI (IM3Module module)
{
M3Result result = c_m3Err_none;
_ (SuppressLookupFailure (m3_LinkFunction (module, "args_sizes_get", "i(Mii)", &m3_wasi_unstable_args_sizes_get)));
_ (SuppressLookupFailure (m3_LinkFunction (module, "environ_sizes_get", "i(Mii)", &m3_wasi_unstable_environ_sizes_get)));
_ (SuppressLookupFailure (m3_LinkFunction (module, "args_get", "i(Mii)", &m3_wasi_unstable_args_get)));
_ (SuppressLookupFailure (m3_LinkFunction (module, "environ_get", "i(Mii)", &m3_wasi_unstable_environ_get)));
_ (SuppressLookupFailure (m3_LinkFunction (module, "args_sizes_get", "i(Rii)", &m3_wasi_unstable_args_sizes_get)));
_ (SuppressLookupFailure (m3_LinkFunction (module, "environ_sizes_get", "i(Rii)", &m3_wasi_unstable_environ_sizes_get)));
_ (SuppressLookupFailure (m3_LinkFunction (module, "args_get", "i(Rii)", &m3_wasi_unstable_args_get)));
_ (SuppressLookupFailure (m3_LinkFunction (module, "environ_get", "i(Rii)", &m3_wasi_unstable_environ_get)));
_ (SuppressLookupFailure (m3_LinkFunction (module, "fd_prestat_dir_name", "i(Miii)", &m3_wasi_unstable_fd_prestat_dir_name)));
_ (SuppressLookupFailure (m3_LinkFunction (module, "fd_prestat_get", "i(Mii)", &m3_wasi_unstable_fd_prestat_get)));
_ (SuppressLookupFailure (m3_LinkFunction (module, "fd_prestat_dir_name", "i(Riii)", &m3_wasi_unstable_fd_prestat_dir_name)));
_ (SuppressLookupFailure (m3_LinkFunction (module, "fd_prestat_get", "i(Rii)", &m3_wasi_unstable_fd_prestat_get)));
_ (SuppressLookupFailure (m3_LinkFunction (module, "fd_fdstat_get", "i(Mi*)", &m3_wasi_unstable_fd_fdstat_get)));
_ (SuppressLookupFailure (m3_LinkFunction (module, "fd_write", "i(Miii*)", &m3_wasi_unstable_fd_write)));
_ (SuppressLookupFailure (m3_LinkFunction (module, "fd_read", "i(Miii*)", &m3_wasi_unstable_fd_read)));
_ (SuppressLookupFailure (m3_LinkFunction (module, "fd_seek", "i(Miii*)", &m3_wasi_unstable_fd_seek)));
_ (SuppressLookupFailure (m3_LinkFunction (module, "fd_datasync", "i(i)", &m3_wasi_unstable_fd_datasync)));
_ (SuppressLookupFailure (m3_LinkFunction (module, "fd_close", "i(i)", &m3_wasi_unstable_fd_close)));
_ (SuppressLookupFailure (m3_LinkFunction (module, "fd_fdstat_get", "i(Ri*)", &m3_wasi_unstable_fd_fdstat_get)));
_ (SuppressLookupFailure (m3_LinkFunction (module, "fd_write", "i(Riii*)", &m3_wasi_unstable_fd_write)));
_ (SuppressLookupFailure (m3_LinkFunction (module, "fd_read", "i(Riii*)", &m3_wasi_unstable_fd_read)));
_ (SuppressLookupFailure (m3_LinkFunction (module, "fd_seek", "i(Riii*)", &m3_wasi_unstable_fd_seek)));
_ (SuppressLookupFailure (m3_LinkFunction (module, "fd_datasync", "i(i)", &m3_wasi_unstable_fd_datasync)));
_ (SuppressLookupFailure (m3_LinkFunction (module, "fd_close", "i(i)", &m3_wasi_unstable_fd_close)));
//_ (SuppressLookupFailure (m3_LinkFunction (module, "sock_send", "i(Miii*)", &...)));
//_ (SuppressLookupFailure (m3_LinkFunction (module, "sock_recv", "i(Miii*)", &...)));
//_ (SuppressLookupFailure (m3_LinkFunction (module, "sock_send", "i(Riii*)", &...)));
//_ (SuppressLookupFailure (m3_LinkFunction (module, "sock_recv", "i(Riii*)", &...)));
_ (SuppressLookupFailure (m3_LinkFunction (module, "random_get", "v(*i)", &m3_wasi_unstable_random_get)));
_ (SuppressLookupFailure (m3_LinkFunction (module, "random_get", "v(*i)", &m3_wasi_unstable_random_get)));
_ (SuppressLookupFailure (m3_LinkFunction (module, "clock_res_get", "v(Mi*)", &m3_wasi_unstable_clock_res_get)));
_ (SuppressLookupFailure (m3_LinkFunction (module, "clock_time_get", "v(MiI*)", &m3_wasi_unstable_clock_time_get)));
_ (SuppressLookupFailure (m3_LinkFunction (module, "proc_exit", "v(i)", &m3_wasi_unstable_proc_exit)));
_ (SuppressLookupFailure (m3_LinkFunction (module, "clock_res_get", "v(Ri*)", &m3_wasi_unstable_clock_res_get)));
_ (SuppressLookupFailure (m3_LinkFunction (module, "clock_time_get", "v(RiI*)", &m3_wasi_unstable_clock_time_get)));
_ (SuppressLookupFailure (m3_LinkFunction (module, "proc_exit", "v(i)", &m3_wasi_unstable_proc_exit)));
_catch:
return result;

@ -168,7 +168,7 @@ u8 ConvertTypeCharToTypeId (char i_code)
else if (i_code == 'F') type = c_m3Type_f64;
else if (i_code == 'i') type = c_m3Type_i32;
else if (i_code == 'I') type = c_m3Type_i64;
else if (i_code == 'M') type = c_m3Type_module;
else if (i_code == 'R') type = c_m3Type_runtime;
}
return type;
@ -233,7 +233,7 @@ M3Result ValidateSignature (IM3Function i_function, bool * o_traps, u8 * o_nor
}
else
{
if (type != c_m3Type_module)
if (type != c_m3Type_runtime)
++numArgs;
}
}
@ -291,7 +291,7 @@ M3Result m3_LinkFunction (IM3Module io_module, const char * const i_functionN
else if (IsIntType (type)) * pusher = c_m3IntPushers [intIndex++];
else if (type == c_m3Type_f32) * pusher = c_m3Float32Pushers [floatIndex++];
else if (type == c_m3Type_f64) * pusher = c_m3Float64Pushers [floatIndex++];
else if (type == c_m3Type_module)
else if (type == c_m3Type_runtime)
{
* pusher = PushArg_runtime;
d_m3Assert (i == 0); // can only push to arg0

@ -187,8 +187,6 @@ void DeallocateSlot (IM3Compilation o, i16 i_slotIndex)
{ d_m3Assert (i_slotIndex >= o->firstSlotIndex);
o->numAllocatedExecSlots--; d_m3Assert (o->m3Slots [i_slotIndex]);
o->m3Slots [i_slotIndex] = 0;
// printf ("dealloc %d\n", (i32) i_stackIndex);
}
@ -1362,7 +1360,6 @@ _ (PreserveRegisterIfOccupied (o, type));
for (u32 i = 0; i < 3; i++)
{
if (IsValidSlot (slots [i]))
// if (slots [i] != c_slotUnused)
EmitConstant (o, slots [i]);
}
_ (PushRegister (o, type));
@ -1424,7 +1421,7 @@ _ (PreserveRegisterIfOccupied (o, op->type));
{
if (IsStackTopInRegister (o))
{
operation = op->operations [0]; // printf ("r <- s+r\n");
operation = op->operations [0];
}
else if (IsStackTopMinus1InRegister (o))
{
@ -1432,12 +1429,11 @@ _ (PreserveRegisterIfOccupied (o, op->type));
if (not operation) // must be commutative, then
operation = op->operations [0];
// printf ("r <- r+s\n");
}
else
{
_ (PreserveRegisterIfOccupied (o, op->type));
operation = op->operations [2]; // printf ("r <- s+s\n");
operation = op->operations [2];
}
}
@ -1512,9 +1508,9 @@ _ (Compile_Operator (o, i_opcode));
#define d_unaryOpList(TYPE, NAME) { op_##TYPE##_##NAME##_r, op_##TYPE##_##NAME##_s, NULL, NULL }
#define d_binOpList(TYPE, NAME) { op_##TYPE##_##NAME##_sr, op_##TYPE##_##NAME##_rs, op_##TYPE##_##NAME##_ss, NULL }
#define d_commutativeBinOpList(TYPE, NAME) { op_##TYPE##_##NAME##_sr, NULL, op_##TYPE##_##NAME##_ss, NULL }
#define d_convertOpList(OP) { op_##OP##_r_r, op_##OP##_r_s, op_##OP##_s_r, op_##OP##_s_s }
const M3OpInfo c_operations [] =
{
M3OP( "unreachable", 0, none, d_singleOp (Unreachable), Compile_Unreachable ), // 0x00
@ -1776,9 +1772,6 @@ M3Result Compile_BlockStatements (IM3Compilation o)
result = (* compiler) (o, opcode);
else
result = c_m3Err_noCompiler;
// if (opcode == c_waOp_branch or opcode == c_waOp_branchTable)
o->previousOpcode = opcode; // m3logif (stack, dump_type_stack (o))
@ -1826,9 +1819,7 @@ _ (PushRegister (o, o->block.type));
else
_ (UnwindBlockStack (o));
_catch: //d_m3Assert (not result);
return result;
_catch: return result;
}

@ -142,7 +142,7 @@ void * m3Realloc (void * i_ptr, size_t i_newSize, size_t i_oldSize)
if (i_ptr)
{
if (i_newSize > i_oldSize)
memset ((u8*)ptr + i_oldSize, 0x0, i_newSize - i_oldSize);
memset ((u8*) ptr + i_oldSize, 0x0, i_newSize - i_oldSize);
}
else memset (ptr, 0x0, i_newSize);
}

@ -21,7 +21,7 @@ M3Result EnsureCodePageNumLines (IM3Compilation o, u32 i_numLines)
if (page)
{
m3log (emit, "bridging new code page from: %d (free slots: %d)", o->page->info.sequence, NumFreeLines (o->page));
m3log (emit, "bridging new code page from: %d %p (free slots: %d)", o->page->info.sequence, GetPC (o), NumFreeLines (o->page));
EmitWord (o->page, op_Bridge);
EmitWord (o->page, GetPagePC (page));

@ -242,7 +242,7 @@ M3Result ResizeMemory (IM3Runtime io_runtime, u32 i_numPages)
{
M3Result result = c_m3Err_none;
u32 i_numPagesToAlloc = i_numPages;
u32 numPagesToAlloc = i_numPages;
M3Memory * memory = & io_runtime->memory;
@ -256,9 +256,9 @@ M3Result ResizeMemory (IM3Runtime io_runtime, u32 i_numPages)
i_numPagesToAlloc = 256;
#endif
if (i_numPages <= memory->maxPages)
if (numPagesToAlloc <= memory->maxPages)
{
size_t numPageBytes = i_numPagesToAlloc * c_m3MemPageSize;
size_t numPageBytes = numPagesToAlloc * c_m3MemPageSize;
size_t numBytes = numPageBytes + sizeof (M3MemoryHeader);
size_t numPreviousBytes = memory->numPages * c_m3MemPageSize;
@ -269,12 +269,14 @@ M3Result ResizeMemory (IM3Runtime io_runtime, u32 i_numPages)
if (memory->mallocated)
{
memory->numPages = i_numPages;
memory->numPages = numPagesToAlloc;
memory->wasmPages = (u8 *) (memory->mallocated + 1);
memory->mallocated->end = memory->wasmPages + (memory->numPages * c_m3MemPageSize);
memory->mallocated->end = memory->wasmPages + numPageBytes;
memory->mallocated->runtime = io_runtime;
memory->mallocated->maxStack = (m3reg_t *) io_runtime->stack + io_runtime->numStackSlots * sizeof (m3reg_t) - c_m3MaxFunctionStackHeight;
m3log (runtime, "resized mem: %p; end: %p; pages: %d\n", memory->wasmPages, memory->mallocated->end, memory->numPages);
}
else result = c_m3Err_mallocFailed;
}

@ -33,7 +33,7 @@ d_m3OpDef (Call)
{
pc_t callPC = immediate (pc_t);
i32 stackOffset = immediate (i32);
M3Memory * memory = immediate (M3Memory *);
IM3Memory memory = immediate (IM3Memory);
m3stack_t sp = _sp + stackOffset;
@ -127,15 +127,18 @@ d_m3OpDef (MemGrow)
IM3Memory memory = & runtime->memory;
u32 numPagesToGrow = (u32) _r0;
u32 requiredPages = memory->numPages + numPagesToGrow;
_r0 = memory->numPages;
if (numPagesToGrow == 0)
return nextOp ();
M3Result r = ResizeMemory (runtime, requiredPages);
if (r)
_r0 = -1;
if (numPagesToGrow)
{
u32 requiredPages = memory->numPages + numPagesToGrow;
M3Result r = ResizeMemory (runtime, requiredPages);
if (r)
_r0 = -1;
_mem = memory->wasmPages;
}
return nextOp ();
}
@ -284,7 +287,7 @@ d_m3OpDef (Loop)
{
m3ret_t r;
M3Memory * memory = immediate (M3Memory *);
IM3Memory memory = immediate (IM3Memory);
// smassey: a downside of this ^^^^ (embedding a memory pointer in the codepage)
// is that codepages are tied to specific runtime.
// originally, i was hoping that multiple runtimes (threads) could share

@ -11,7 +11,6 @@
#include "m3_env.h"
//M3Result Module_EnsureMemorySize (IM3Module i_module, IM3Memory io_memory, size_t i_memorySize);
i32 AllocatePrivateHeap (M3Memory * io_memory, i32 i_size);

Loading…
Cancel
Save