Check stack depending on function

extensions
Volodymyr Shymanskyy 5 years ago
parent 43e856e5fa
commit bbbda3519b

@ -310,9 +310,7 @@ M3Result ResizeMemory (IM3Runtime io_runtime, u32 i_numPages)
memory->mallocated->length = numPageBytes;
memory->mallocated->runtime = io_runtime;
// TODO: track max function stack height and use this instead of hard-coded constant
d_m3Assert(io_runtime->numStackSlots > d_m3MaxFunctionStackHeight);
memory->mallocated->maxStack = (m3reg_t *) io_runtime->stack + (io_runtime->numStackSlots - d_m3MaxFunctionStackHeight);
memory->mallocated->maxStack = (m3reg_t *) io_runtime->stack + io_runtime->numStackSlots;
m3log (runtime, "resized old: %p; mem: %p; end: %p; pages: %d", oldMallocated, memory->mallocated, memory->mallocated->end, memory->numPages);
}

@ -46,6 +46,8 @@ typedef struct M3Function
IM3Operation callOp;
pc_t compiled;
u32 maxStackSlots;
u32 numLocals; // not including args
u32 numConstants;

@ -188,13 +188,14 @@ d_m3OpDef (Compile)
d_m3OpDef (Entry)
{
IM3Function function = immediate (IM3Function);
#if defined(d_m3SkipStackCheck)
if (true)
#else
if ((void *) _sp <= _mem->maxStack)
if ((void*)(_sp + function->maxStackSlots) < _mem->maxStack)
#endif
{
IM3Function function = immediate (IM3Function);
function->hits++; m3log (exec, " enter %p > %s %s", _pc - 2, function->name ? function->name : ".unnamed", SPrintFunctionArgList (function, _sp));
u32 numLocals = function->numLocals;

@ -331,6 +331,9 @@ _ (NormalizeType (& normalizedType, varType));
func->wasm = start;
func->wasmEnd = i_bytes;
func->numLocals = numLocalVars;
// TODO: track max function stack height and use this instead of hard-coded constant
func->maxStackSlots = 4;
}
else _throw (m3Err_wasmSectionOverrun);
}

Loading…
Cancel
Save