Pass IMRuntime to raw funcs

extensions
Volodymyr Shymanskyy 5 years ago
parent 869e28158c
commit 0944d211dc

@ -14,7 +14,7 @@
#define m3ApiGetArg(TYPE, NAME) TYPE NAME = * ((TYPE *) (_sp++));
#define m3ApiGetArgMem(TYPE, NAME) TYPE NAME = (TYPE) (_mem + * (u32 *) _sp++);
#define m3ApiRawFunction(NAME) void NAME (u64 * _sp, u8 * _mem)
#define m3ApiRawFunction(NAME) void NAME (IM3Runtime runtime, u64 * _sp, u8 * _mem)
#define m3ApiReturn(VALUE) { *raw_return = (VALUE); return; }
#endif /* m3_api_defs_h */

@ -314,21 +314,24 @@ m3ApiRawFunction(m3_wasi_unstable_path_open)
}
uint32_t m3_wasi_unstable_fd_read(IM3Runtime runtime,
__wasi_fd_t fd,
uint32_t iovs_offset,
__wasi_size_t iovs_len,
__wasi_size_t* nread)
m3ApiRawFunction(m3_wasi_unstable_fd_read)
{
if (runtime == NULL || nread == NULL) { return __WASI_EINVAL; }
m3ApiReturnType (uint32_t)
m3ApiGetArg (__wasi_fd_t , fd)
m3ApiGetArg (uint32_t , iovs_offset)
m3ApiGetArg (__wasi_size_t , iovs_len)
m3ApiGetArgMem (__wasi_size_t* , nread)
if (runtime == NULL || nread == NULL) { m3ApiReturn(__WASI_EINVAL); }
struct iovec iovs[iovs_len];
copy_iov_to_host(iovs, runtime, iovs_offset, iovs_len);
ssize_t ret = readv(fd, iovs, iovs_len);
if (ret < 0) { return errno_to_wasi(errno); }
if (ret < 0) { m3ApiReturn(errno_to_wasi(errno)); }
*nread = ret;
return __WASI_ESUCCESS;
m3ApiReturn(__WASI_ESUCCESS);
}
uint32_t m3_wasi_unstable_fd_write(IM3Runtime runtime,
@ -474,7 +477,7 @@ _ (SuppressLookupFailure (m3_LinkRawFunction (module, namespace, "path_open",
_ (SuppressLookupFailure (m3_LinkCFunction (module, namespace, "fd_fdstat_get", "i(Ri*)", &m3_wasi_unstable_fd_fdstat_get)));
_ (SuppressLookupFailure (m3_LinkCFunction (module, namespace, "fd_write", "i(Riii*)", &m3_wasi_unstable_fd_write)));
_ (SuppressLookupFailure (m3_LinkCFunction (module, namespace, "fd_read", "i(Riii*)", &m3_wasi_unstable_fd_read)));
_ (SuppressLookupFailure (m3_LinkRawFunction (module, namespace, "fd_read", &m3_wasi_unstable_fd_read)));
_ (SuppressLookupFailure (m3_LinkCFunction (module, namespace, "fd_seek", "i(Riii*)", &m3_wasi_unstable_fd_seek)));
_ (SuppressLookupFailure (m3_LinkCFunction (module, namespace, "fd_datasync", "i(i)", &m3_wasi_unstable_fd_datasync)));
_ (SuppressLookupFailure (m3_LinkCFunction (module, namespace, "fd_close", "i(i)", &m3_wasi_unstable_fd_close)));

@ -30,7 +30,7 @@ M3State;
typedef m3ret_t (* M3ArgPusher) (d_m3BindingArgList, M3State * i_state);
typedef f64 (* M3ArgPusherFpReturn) (d_m3BindingArgList, M3State * i_state);
typedef m3ret_t (* M3RawCall) (u64 * _sp, void * _mem);
typedef m3ret_t (* M3RawCall) (IM3Runtime runtime, u64 * _sp, void * _mem);
m3ret_t PushArg_runtime (d_m3BindingArgList, M3State * _state)
@ -389,8 +389,9 @@ M3Result m3_LinkCFunction (IM3Module io_module,
d_m3RetSig CallRawFunction (d_m3OpSig)
{
M3RawCall call = (M3RawCall) (* _pc);
call (_sp, _mem);
M3RawCall call = (M3RawCall) (* _pc++);
IM3Runtime runtime = (IM3Runtime) (* _pc++);
call (runtime, _sp, _mem);
return NULL;
}
@ -408,6 +409,7 @@ M3Result LinkRawFunction (IM3Module io_module, IM3Function io_function, cons
EmitWord (page, CallRawFunction);
EmitWord (page, i_function);
EmitWord (page, io_module->runtime);
ReleaseCodePage (io_module->runtime, page);
}

Loading…
Cancel
Save