|
|
@ -27,7 +27,8 @@
|
|
|
|
extern char** environ;
|
|
|
|
extern char** environ;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
uvwasi_t uvwasi;
|
|
|
|
static m3_wasi_context_t* wasi_context;
|
|
|
|
|
|
|
|
static uvwasi_t uvwasi;
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct wasi_iovec_t
|
|
|
|
typedef struct wasi_iovec_t
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -45,14 +46,16 @@ m3ApiRawFunction(m3_wasi_unstable_args_get)
|
|
|
|
m3ApiGetArgMem (uint32_t * , argv)
|
|
|
|
m3ApiGetArgMem (uint32_t * , argv)
|
|
|
|
m3ApiGetArgMem (char * , argv_buf)
|
|
|
|
m3ApiGetArgMem (char * , argv_buf)
|
|
|
|
|
|
|
|
|
|
|
|
if (runtime == NULL) { m3ApiReturn(UVWASI_EINVAL); }
|
|
|
|
m3_wasi_context_t* context = (m3_wasi_context_t*)userdata;
|
|
|
|
|
|
|
|
|
|
|
|
for (u32 i = 0; i < runtime->argc; ++i)
|
|
|
|
if (context == NULL) { m3ApiReturn(UVWASI_EINVAL); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (u32 i = 0; i < context->argc; ++i)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
m3ApiWriteMem32(&argv[i], m3ApiPtrToOffset(argv_buf));
|
|
|
|
m3ApiWriteMem32(&argv[i], m3ApiPtrToOffset(argv_buf));
|
|
|
|
|
|
|
|
|
|
|
|
size_t len = strlen (runtime->argv[i]);
|
|
|
|
size_t len = strlen (context->argv[i]);
|
|
|
|
memcpy (argv_buf, runtime->argv[i], len);
|
|
|
|
memcpy (argv_buf, context->argv[i], len);
|
|
|
|
argv_buf += len;
|
|
|
|
argv_buf += len;
|
|
|
|
* argv_buf++ = 0;
|
|
|
|
* argv_buf++ = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -66,15 +69,17 @@ m3ApiRawFunction(m3_wasi_unstable_args_sizes_get)
|
|
|
|
m3ApiGetArgMem (uvwasi_size_t * , argc)
|
|
|
|
m3ApiGetArgMem (uvwasi_size_t * , argc)
|
|
|
|
m3ApiGetArgMem (uvwasi_size_t * , argv_buf_size)
|
|
|
|
m3ApiGetArgMem (uvwasi_size_t * , argv_buf_size)
|
|
|
|
|
|
|
|
|
|
|
|
if (runtime == NULL) { m3ApiReturn(UVWASI_EINVAL); }
|
|
|
|
m3_wasi_context_t* context = (m3_wasi_context_t*)userdata;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (context == NULL) { m3ApiReturn(UVWASI_EINVAL); }
|
|
|
|
|
|
|
|
|
|
|
|
uvwasi_size_t buflen = 0;
|
|
|
|
uvwasi_size_t buflen = 0;
|
|
|
|
for (u32 i = 0; i < runtime->argc; ++i)
|
|
|
|
for (u32 i = 0; i < context->argc; ++i)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
buflen += strlen (runtime->argv[i]) + 1;
|
|
|
|
buflen += strlen (context->argv[i]) + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
m3ApiWriteMem32(argc, runtime->argc);
|
|
|
|
m3ApiWriteMem32(argc, context->argc);
|
|
|
|
m3ApiWriteMem32(argv_buf_size, buflen);
|
|
|
|
m3ApiWriteMem32(argv_buf_size, buflen);
|
|
|
|
|
|
|
|
|
|
|
|
m3ApiReturn(UVWASI_ESUCCESS);
|
|
|
|
m3ApiReturn(UVWASI_ESUCCESS);
|
|
|
@ -428,7 +433,11 @@ m3ApiRawFunction(m3_wasi_unstable_proc_exit)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
m3ApiGetArg (uint32_t, code)
|
|
|
|
m3ApiGetArg (uint32_t, code)
|
|
|
|
|
|
|
|
|
|
|
|
runtime->exit_code = code;
|
|
|
|
m3_wasi_context_t* context = (m3_wasi_context_t*)userdata;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (context) {
|
|
|
|
|
|
|
|
context->exit_code = code;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
m3ApiTrap(m3Err_trapExit);
|
|
|
|
m3ApiTrap(m3Err_trapExit);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -443,6 +452,11 @@ M3Result SuppressLookupFailure(M3Result i_result)
|
|
|
|
return i_result;
|
|
|
|
return i_result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m3_wasi_context_t* m3_GetWasiContext()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return wasi_context;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
M3Result m3_LinkWASI (IM3Module module)
|
|
|
|
M3Result m3_LinkWASI (IM3Module module)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -482,6 +496,11 @@ M3Result m3_LinkWASI (IM3Module module)
|
|
|
|
return "uvwasi_init failed";
|
|
|
|
return "uvwasi_init failed";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wasi_context = (m3_wasi_context_t*)malloc(sizeof(m3_wasi_context_t));
|
|
|
|
|
|
|
|
wasi_context->exit_code = 0;
|
|
|
|
|
|
|
|
wasi_context->argc = 0;
|
|
|
|
|
|
|
|
wasi_context->argv = 0;
|
|
|
|
|
|
|
|
|
|
|
|
static const char* namespaces[2] = { "wasi_unstable", "wasi_snapshot_preview1" };
|
|
|
|
static const char* namespaces[2] = { "wasi_unstable", "wasi_snapshot_preview1" };
|
|
|
|
|
|
|
|
|
|
|
|
// fd_seek is incompatible
|
|
|
|
// fd_seek is incompatible
|
|
|
@ -492,8 +511,8 @@ _ (SuppressLookupFailure (m3_LinkRawFunction (module, "wasi_snapshot_preview1"
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const char* wasi = namespaces[i];
|
|
|
|
const char* wasi = namespaces[i];
|
|
|
|
|
|
|
|
|
|
|
|
_ (SuppressLookupFailure (m3_LinkRawFunction (module, wasi, "args_get", "i(**)", &m3_wasi_unstable_args_get)));
|
|
|
|
_ (SuppressLookupFailure (m3_LinkRawFunctionEx (module, wasi, "args_get", "i(**)", &m3_wasi_unstable_args_get, wasi_context)));
|
|
|
|
_ (SuppressLookupFailure (m3_LinkRawFunction (module, wasi, "args_sizes_get", "i(**)", &m3_wasi_unstable_args_sizes_get)));
|
|
|
|
_ (SuppressLookupFailure (m3_LinkRawFunctionEx (module, wasi, "args_sizes_get", "i(**)", &m3_wasi_unstable_args_sizes_get, wasi_context)));
|
|
|
|
_ (SuppressLookupFailure (m3_LinkRawFunction (module, wasi, "clock_res_get", "i(i*)", &m3_wasi_unstable_clock_res_get)));
|
|
|
|
_ (SuppressLookupFailure (m3_LinkRawFunction (module, wasi, "clock_res_get", "i(i*)", &m3_wasi_unstable_clock_res_get)));
|
|
|
|
_ (SuppressLookupFailure (m3_LinkRawFunction (module, wasi, "clock_time_get", "i(iI*)", &m3_wasi_unstable_clock_time_get)));
|
|
|
|
_ (SuppressLookupFailure (m3_LinkRawFunction (module, wasi, "clock_time_get", "i(iI*)", &m3_wasi_unstable_clock_time_get)));
|
|
|
|
_ (SuppressLookupFailure (m3_LinkRawFunction (module, wasi, "environ_get", "i(**)", &m3_wasi_unstable_environ_get)));
|
|
|
|
_ (SuppressLookupFailure (m3_LinkRawFunction (module, wasi, "environ_get", "i(**)", &m3_wasi_unstable_environ_get)));
|
|
|
@ -533,7 +552,7 @@ _ (SuppressLookupFailure (m3_LinkRawFunction (module, wasi, "path_open",
|
|
|
|
//_ (SuppressLookupFailure (m3_LinkRawFunction (module, wasi, "path_unlink_file", "i(i*i)", )));
|
|
|
|
//_ (SuppressLookupFailure (m3_LinkRawFunction (module, wasi, "path_unlink_file", "i(i*i)", )));
|
|
|
|
|
|
|
|
|
|
|
|
_ (SuppressLookupFailure (m3_LinkRawFunction (module, wasi, "poll_oneoff", "i(**i*)", &m3_wasi_unstable_poll_oneoff)));
|
|
|
|
_ (SuppressLookupFailure (m3_LinkRawFunction (module, wasi, "poll_oneoff", "i(**i*)", &m3_wasi_unstable_poll_oneoff)));
|
|
|
|
_ (SuppressLookupFailure (m3_LinkRawFunction (module, wasi, "proc_exit", "v(i)", &m3_wasi_unstable_proc_exit)));
|
|
|
|
_ (SuppressLookupFailure (m3_LinkRawFunctionEx (module, wasi, "proc_exit", "v(i)", &m3_wasi_unstable_proc_exit, wasi_context)));
|
|
|
|
//_ (SuppressLookupFailure (m3_LinkRawFunction (module, wasi, "proc_raise", "i(i)", )));
|
|
|
|
//_ (SuppressLookupFailure (m3_LinkRawFunction (module, wasi, "proc_raise", "i(i)", )));
|
|
|
|
_ (SuppressLookupFailure (m3_LinkRawFunction (module, wasi, "random_get", "i(*i)", &m3_wasi_unstable_random_get)));
|
|
|
|
_ (SuppressLookupFailure (m3_LinkRawFunction (module, wasi, "random_get", "i(*i)", &m3_wasi_unstable_random_get)));
|
|
|
|
//_ (SuppressLookupFailure (m3_LinkRawFunction (module, wasi, "sched_yield", "i()", )));
|
|
|
|
//_ (SuppressLookupFailure (m3_LinkRawFunction (module, wasi, "sched_yield", "i()", )));
|
|
|
|