extensions
Volodymyr Shymanskyy 4 years ago
parent 3b970de48c
commit cc10d740c4

@ -288,11 +288,11 @@ m3ApiRawFunction(m3_wasi_unstable_fd_read)
m3ApiGetArg (__wasi_size_t , iovs_len)
m3ApiGetArgMem (__wasi_size_t * , nread)
// TODO: check iovs_len
#if defined(M3_COMPILER_MSVC)
if (iovs_len > 32) m3ApiReturn(UVWASI_EINVAL);
uvwasi_ciovec_t iovs[32];
#else
if (iovs_len > 128) m3ApiReturn(UVWASI_EINVAL);
uvwasi_ciovec_t iovs[iovs_len];
#endif
size_t num_read;
@ -316,11 +316,11 @@ m3ApiRawFunction(m3_wasi_unstable_fd_write)
m3ApiGetArg (__wasi_size_t , iovs_len)
m3ApiGetArgMem (__wasi_size_t * , nwritten)
// TODO: check iovs_len
#if defined(M3_COMPILER_MSVC)
if (iovs_len > 32) m3ApiReturn(UVWASI_EINVAL);
uvwasi_ciovec_t iovs[32];
#else
if (iovs_len > 128) m3ApiReturn(UVWASI_EINVAL);
uvwasi_ciovec_t iovs[iovs_len];
#endif
size_t num_written;
@ -450,7 +450,7 @@ M3Result m3_LinkWASI (IM3Module module)
{
M3Result result = m3Err_none;
#define ENV_COUNT 8
#define ENV_COUNT 9
char* env[ENV_COUNT];
env[0] = "TERM=xterm-256color";
@ -460,7 +460,8 @@ M3Result m3_LinkWASI (IM3Module module)
env[4] = "HOME=/";
env[5] = "PATH=/";
env[6] = "WASM3=1";
env[7] = NULL;
env[7] = "WASM3_ARCH=" M3_ARCH;
env[8] = NULL;
#define PREOPENS_COUNT 2

@ -91,13 +91,10 @@ _ (AllocFuncType (& funcType, (u32) maxNumArgs));
{
_throwif (m3Err_malformedFunctionSignature, funcType->numArgs >= maxNumArgs); // forgot trailing ')' ?
if (type != c_m3Type_runtime)
{
if (type == c_m3Type_ptr)
type = c_m3Type_i32;
if (type == c_m3Type_ptr)
type = c_m3Type_i32;
funcType->argTypes [funcType->numArgs++] = type;
}
funcType->argTypes [funcType->numArgs++] = type;
}
}

@ -217,8 +217,9 @@ M3Result AllocateSlotsWithinRange (IM3Compilation o, u16 * o_slot, u8 i_type,
u16 numSlots = GetTypeNumSlots (i_type);
u16 searchOffset = numSlots - 1;
if (d_m3Use32BitSlots)
if (d_m3Use32BitSlots) {
AlignSlotIndexToType (& i_startSlot, i_type);
}
// search for 1 or 2 consecutive slots in the execution stack
u16 i = i_startSlot;

@ -224,17 +224,17 @@ bool IsFpType (u8 i_wasmType);
bool Is64BitType (u8 i_m3Type);
u32 SizeOfType (u8 i_m3Type);
M3Result Read_u64 (u64 * o_value, const u8 ** io_bytes, cbytes_t i_end);
M3Result Read_u32 (u32 * o_value, const u8 ** io_bytes, cbytes_t i_end);
M3Result Read_u64 (u64 * o_value, bytes_t * io_bytes, cbytes_t i_end);
M3Result Read_u32 (u32 * o_value, bytes_t * io_bytes, cbytes_t i_end);
M3Result Read_f64 (f64 * o_value, bytes_t * io_bytes, cbytes_t i_end);
M3Result Read_f32 (f32 * o_value, bytes_t * io_bytes, cbytes_t i_end);
M3Result Read_u8 (u8 * o_value, const u8 ** io_bytes, cbytes_t i_end);
M3Result Read_u8 (u8 * o_value, bytes_t * io_bytes, cbytes_t i_end);
M3Result ReadLebUnsigned (u64 * o_value, u32 i_maxNumBits, bytes_t * io_bytes, cbytes_t i_end);
M3Result ReadLebSigned (i64 * o_value, u32 i_maxNumBits, bytes_t * io_bytes, cbytes_t i_end);
M3Result ReadLEB_u32 (u32 * o_value, bytes_t* io_bytes, cbytes_t i_end);
M3Result ReadLEB_u7 (u8 * o_value, bytes_t * io_bytes, cbytes_t i_end);
M3Result ReadLEB_i7 (i8 * o_value, bytes_t * io_bytes, cbytes_t i_end);
M3Result ReadLEB_u32 (u32 * o_value, bytes_t * io_bytes, cbytes_t i_end);
M3Result ReadLEB_u7 (u8 * o_value, bytes_t * io_bytes, cbytes_t i_end);
M3Result ReadLEB_i7 (i8 * o_value, bytes_t * io_bytes, cbytes_t i_end);
M3Result ReadLEB_i32 (i32 * o_value, bytes_t * io_bytes, cbytes_t i_end);
M3Result ReadLEB_i64 (i64 * o_value, bytes_t * io_bytes, cbytes_t i_end);
M3Result Read_utf8 (cstr_t * o_utf8, bytes_t * io_bytes, cbytes_t i_end);

@ -10,20 +10,6 @@
#include "m3_compile.h"
static inline
IM3Memory GetMemoryInfo (M3MemoryHeader * header)
{
IM3Memory memory = & header->runtime->memory;
return memory;
}
static inline
IM3Runtime GetRuntime (M3MemoryHeader * header)
{
return header->runtime;
}
void ReportError2 (IM3Function i_function, m3ret_t i_result)
{
i_function->module->runtime->runtimeError = (M3Result)i_result;
@ -32,7 +18,7 @@ void ReportError2 (IM3Function i_function, m3ret_t i_result)
d_m3OpDef (GetGlobal_s32)
{
u32 * global = immediate (u32 *);
slot (u32) = * global; // printf ("get global: %p %" PRIi64 "\n", global, *global);
slot (u32) = * global; // printf ("get global: %p %" PRIi64 "\n", global, *global);
nextOp ();
}
@ -69,7 +55,7 @@ d_m3OpDef (Call)
{
pc_t callPC = immediate (pc_t);
i32 stackOffset = immediate (i32);
IM3Memory memory = GetMemoryInfo (_mem);
IM3Memory memory = m3MemInfo (_mem);
m3stack_t sp = _sp + stackOffset;
@ -90,7 +76,7 @@ d_m3OpDef (CallIndirect)
IM3Module module = immediate (IM3Module);
IM3FuncType type = immediate (IM3FuncType);
i32 stackOffset = immediate (i32);
IM3Memory memory = GetMemoryInfo (_mem);
IM3Memory memory = m3MemInfo (_mem);
m3stack_t sp = _sp + stackOffset;
@ -131,9 +117,8 @@ d_m3OpDef (CallIndirect)
d_m3OpDef (CallRawFunction)
{
M3RawCall call = (M3RawCall) (* _pc++);
IM3Runtime runtime = GetRuntime (_mem);
m3ret_t possible_trap = call (runtime, (u64 *) _sp, m3MemData(_mem));
m3ret_t possible_trap = call (m3MemRuntime(_mem), (u64 *) _sp, m3MemData(_mem));
return possible_trap;
}
@ -141,16 +126,15 @@ d_m3OpDef (CallRawFunctionEx)
{
M3RawCallEx call = (M3RawCallEx) (* _pc++);
void * cookie = immediate (void *);
IM3Runtime runtime = GetRuntime (_mem);
m3ret_t possible_trap = call (runtime, (u64 *)_sp, m3MemData(_mem), cookie);
m3ret_t possible_trap = call (m3MemRuntime(_mem), (u64 *)_sp, m3MemData(_mem), cookie);
return possible_trap;
}
d_m3OpDef (MemCurrent)
{
IM3Memory memory = GetMemoryInfo (_mem);
IM3Memory memory = m3MemInfo (_mem);
_r0 = memory->numPages;
@ -160,7 +144,7 @@ d_m3OpDef (MemCurrent)
d_m3OpDef (MemGrow)
{
IM3Runtime runtime = GetRuntime (_mem);
IM3Runtime runtime = m3MemRuntime(_mem);
IM3Memory memory = & runtime->memory;
u32 numPagesToGrow = (u32) _r0;
@ -268,7 +252,7 @@ d_m3OpDef (Loop)
m3ret_t r;
IM3Memory memory = GetMemoryInfo (_mem);
IM3Memory memory = m3MemInfo (_mem);
do
{

@ -18,7 +18,9 @@ d_m3BeginExternC
# define d_m3OpDefaultArgs 0, 0.
# define d_m3ClearRegisters _r0 = 0; _fp0 = 0.;
# define m3MemData(mem) (u8*)((M3MemoryHeader*)(mem)+1)
# define m3MemData(mem) (u8*)(((M3MemoryHeader*)(mem))+1)
# define m3MemRuntime(mem) (((M3MemoryHeader*)(mem))->runtime)
# define m3MemInfo(mem) (&(((M3MemoryHeader*)(mem))->runtime->memory))
typedef m3ret_t (vectorcall * IM3Operation) (d_m3OpSig);

@ -55,9 +55,7 @@ enum // EWaTypes
c_m3Type_void,
c_m3Type_ptr,
c_m3Type_trap,
c_m3Type_runtime
c_m3Type_trap
};

Loading…
Cancel
Save