implemented WASI args

extensions
Steven Massey 5 years ago
parent 283cda22ee
commit b4af46d9fb

@ -54,9 +54,10 @@ M3Result repl_call (IM3Runtime runtime, const char* name, int argc, const char*
if (argc) {
if (!strcmp(name, "main") || !strcmp(name, "_main")) {
return "passing arguments to libc main() not implemented";
} else if (!strcmp(name, "_start")) {
return "passing arguments to wasi _start() not implemented";
}
// else if (!strcmp(name, "_start")) {
// return "passing arguments to wasi _start() not implemented";
// }
}
result = m3_CallWithArgs (func, argc, argv);

@ -128,26 +128,39 @@ void copy_iov_to_host(struct iovec* host_iov, IM3Runtime runtime, uint32_t iov_o
* WASI API implementation
*/
uint32_t m3_wasi_unstable_args_get(IM3Runtime runtime,
uint32_t argv_offset,
uint32_t argv_buf_offset)
uint32_t m3_wasi_unstable_args_get (IM3Runtime runtime,
u32 * argv_offset,
u8 * argv_buf_offset)
{
if (runtime == NULL) { return __WASI_EINVAL; }
// TODO
return __WASI_ESUCCESS;
if (runtime)
{
for (u32 i = 0; i < runtime->argc; ++i)
{
argv_offset [i] = addr2offset (runtime, argv_buf_offset);
size_t len = strlen (runtime->argv [i]);
memcpy (argv_buf_offset, runtime->argv [i], len);
argv_buf_offset += len;
* argv_buf_offset++ = 0;
}
return __WASI_ESUCCESS;
}
else return __WASI_EINVAL;
}
uint32_t m3_wasi_unstable_args_sizes_get(IM3Runtime runtime,
uint32_t argc_offset,
uint32_t argv_buf_size_offset)
uint32_t m3_wasi_unstable_args_sizes_get (IM3Runtime runtime,
__wasi_size_t * argc,
__wasi_size_t * argv_buf_size)
{
if (runtime == NULL) { return __WASI_EINVAL; }
__wasi_size_t *argc = offset2addr(runtime, argc_offset);
__wasi_size_t *argv_buf_size = offset2addr(runtime, argv_buf_size_offset);
*argc = 0;
*argc = runtime->argc;
*argv_buf_size = 0;
for (int i = 0; i < runtime->argc; ++i)
* argv_buf_size += strlen (runtime->argv [i]) + 1;
return __WASI_ESUCCESS;
}
@ -384,9 +397,9 @@ M3Result m3_LinkWASI (IM3Module module)
{
M3Result result = c_m3Err_none;
_ (SuppressLookupFailure (m3_LinkFunction (module, "args_sizes_get", "i(Rii)", &m3_wasi_unstable_args_sizes_get)));
_ (SuppressLookupFailure (m3_LinkFunction (module, "args_sizes_get", "i(R**)", &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, "args_get", "i(R**)", &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(Riii)", &m3_wasi_unstable_fd_prestat_dir_name)));

@ -348,11 +348,18 @@ _ (EvaluateExpression (io_module, & segmentOffset, c_m3Type_i32, & start,
u32 minMemorySize = segment->size + segmentOffset + 1; m3log (runtime, "loading data segment: %d offset: %d", i, segmentOffset);
// io_memory
//_ (Module_EnsureMemorySize (io_module, io_memory, minMemorySize));
memcpy (io_memory->wasmPages + segmentOffset, segment->data, segment->size);
if (io_memory->wasmPages)
{
u8 * dest = io_memory->wasmPages + segmentOffset;
if (dest + segment->size <= (u8 *) io_memory->mallocated->end)
memcpy (dest, segment->data, segment->size);
else
_throw ("data segment overflowing linear memory");
}
else _throw ("unallocated linear memory");
}
_catch: return result;
@ -528,7 +535,11 @@ M3Result m3_CallWithArgs (IM3Function i_function, uint32_t i_argc, const char
IM3Module module = i_function->module;
IM3Runtime runtime = module->runtime;
runtime->argc = i_argc;
runtime->argv = i_argv;
if (strcmp (i_function->name, "_start") == 0) // WASI
i_argc = 0;
IM3FuncType ftype = i_function->funcType;
//#if d_m3AllocateLinearMemory
@ -609,6 +620,7 @@ _ ((M3Result)Call (i_function->compiled, stack, linearMemory, d_m3OpDefaul
_catch: return result;
}
M3Result m3_CallMain (IM3Function i_function, uint32_t i_argc, const char * const * i_argv)
{
M3Result result = c_m3Err_none;

@ -215,6 +215,9 @@ typedef struct M3Runtime
u32 stackSize;
u32 numStackSlots;
u32 argc;
ccstr_t * argv;
M3Result runtimeError;
M3Memory memory;

Loading…
Cancel
Save