| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175 |
- /*
- * Copyright (C) 2019 Intel Corporation. All rights reserved.
- * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
- */
- #include "libc_wasi_wrapper.h"
- #include "bh_platform.h"
- #include "wasm_export.h"
- void
- wasm_runtime_set_exception(wasm_module_inst_t module, const char *exception);
- /* clang-format off */
- #define get_module_inst(exec_env) \
- wasm_runtime_get_module_inst(exec_env)
- #define get_wasi_ctx(module_inst) \
- wasm_runtime_get_wasi_ctx(module_inst)
- #define validate_app_addr(offset, size) \
- wasm_runtime_validate_app_addr(module_inst, offset, size)
- #define validate_native_addr(addr, size) \
- wasm_runtime_validate_native_addr(module_inst, addr, size)
- #define addr_app_to_native(offset) \
- wasm_runtime_addr_app_to_native(module_inst, offset)
- #define addr_native_to_app(ptr) \
- wasm_runtime_addr_native_to_app(module_inst, ptr)
- #define module_malloc(size, p_native_addr) \
- wasm_runtime_module_malloc(module_inst, size, p_native_addr)
- #define module_free(offset) \
- wasm_runtime_module_free(module_inst, offset)
- /* clang-format on */
- typedef struct wasi_prestat_app {
- wasi_preopentype_t pr_type;
- uint32 pr_name_len;
- } wasi_prestat_app_t;
- typedef struct iovec_app {
- uint32 buf_offset;
- uint32 buf_len;
- } iovec_app_t;
- typedef struct WASIContext {
- struct fd_table *curfds;
- struct fd_prestats *prestats;
- struct argv_environ_values *argv_environ;
- char *argv_buf;
- char **argv_list;
- char *env_buf;
- char **env_list;
- } * wasi_ctx_t;
- wasi_ctx_t
- wasm_runtime_get_wasi_ctx(wasm_module_inst_t module_inst);
- static inline struct fd_table *
- wasi_ctx_get_curfds(wasm_module_inst_t module_inst, wasi_ctx_t wasi_ctx)
- {
- if (!wasi_ctx)
- return NULL;
- return wasi_ctx->curfds;
- }
- static inline struct argv_environ_values *
- wasi_ctx_get_argv_environ(wasm_module_inst_t module_inst, wasi_ctx_t wasi_ctx)
- {
- if (!wasi_ctx)
- return NULL;
- return wasi_ctx->argv_environ;
- }
- static inline struct fd_prestats *
- wasi_ctx_get_prestats(wasm_module_inst_t module_inst, wasi_ctx_t wasi_ctx)
- {
- if (!wasi_ctx)
- return NULL;
- return wasi_ctx->prestats;
- }
- static wasi_errno_t
- wasi_args_get(wasm_exec_env_t exec_env, uint32 *argv_offsets, char *argv_buf)
- {
- wasm_module_inst_t module_inst = get_module_inst(exec_env);
- wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
- struct argv_environ_values *argv_environ =
- wasi_ctx_get_argv_environ(module_inst, wasi_ctx);
- size_t argc, argv_buf_size, i;
- char **argv;
- uint64 total_size;
- wasi_errno_t err;
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- err = wasmtime_ssp_args_sizes_get(argv_environ, &argc, &argv_buf_size);
- if (err)
- return err;
- total_size = sizeof(int32) * ((uint64)argc + 1);
- if (total_size >= UINT32_MAX
- || !validate_native_addr(argv_offsets, (uint32)total_size)
- || argv_buf_size >= UINT32_MAX
- || !validate_native_addr(argv_buf, (uint32)argv_buf_size))
- return (wasi_errno_t)-1;
- total_size = sizeof(char *) * ((uint64)argc + 1);
- if (total_size >= UINT32_MAX
- || !(argv = wasm_runtime_malloc((uint32)total_size)))
- return (wasi_errno_t)-1;
- err = wasmtime_ssp_args_get(argv_environ, argv, argv_buf);
- if (err) {
- wasm_runtime_free(argv);
- return err;
- }
- for (i = 0; i < argc; i++)
- argv_offsets[i] = addr_native_to_app(argv[i]);
- argv_offsets[argc] = 0;
- wasm_runtime_free(argv);
- return 0;
- }
- static wasi_errno_t
- wasi_args_sizes_get(wasm_exec_env_t exec_env, uint32 *argc_app,
- uint32 *argv_buf_size_app)
- {
- wasm_module_inst_t module_inst = get_module_inst(exec_env);
- wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
- struct argv_environ_values *argv_environ;
- size_t argc, argv_buf_size;
- wasi_errno_t err;
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- if (!validate_native_addr(argc_app, sizeof(uint32))
- || !validate_native_addr(argv_buf_size_app, sizeof(uint32)))
- return (wasi_errno_t)-1;
- argv_environ = wasi_ctx->argv_environ;
- err = wasmtime_ssp_args_sizes_get(argv_environ, &argc, &argv_buf_size);
- if (err)
- return err;
- *argc_app = (uint32)argc;
- *argv_buf_size_app = (uint32)argv_buf_size;
- return 0;
- }
- static wasi_errno_t
- wasi_clock_res_get(wasm_exec_env_t exec_env,
- wasi_clockid_t clock_id, /* uint32 clock_id */
- wasi_timestamp_t *resolution /* uint64 *resolution */)
- {
- wasm_module_inst_t module_inst = get_module_inst(exec_env);
- if (!validate_native_addr(resolution, sizeof(wasi_timestamp_t)))
- return (wasi_errno_t)-1;
- return wasmtime_ssp_clock_res_get(clock_id, resolution);
- }
- static wasi_errno_t
- wasi_clock_time_get(wasm_exec_env_t exec_env,
- wasi_clockid_t clock_id, /* uint32 clock_id */
- wasi_timestamp_t precision, /* uint64 precision */
- wasi_timestamp_t *time /* uint64 *time */)
- {
- wasm_module_inst_t module_inst = get_module_inst(exec_env);
- if (!validate_native_addr(time, sizeof(wasi_timestamp_t)))
- return (wasi_errno_t)-1;
- return wasmtime_ssp_clock_time_get(clock_id, precision, time);
- }
- static wasi_errno_t
- wasi_environ_get(wasm_exec_env_t exec_env, uint32 *environ_offsets,
- char *environ_buf)
- {
- wasm_module_inst_t module_inst = get_module_inst(exec_env);
- wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
- struct argv_environ_values *argv_environ =
- wasi_ctx_get_argv_environ(module_inst, wasi_ctx);
- size_t environ_count, environ_buf_size, i;
- uint64 total_size;
- char **environs;
- wasi_errno_t err;
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- err = wasmtime_ssp_environ_sizes_get(argv_environ, &environ_count,
- &environ_buf_size);
- if (err)
- return err;
- total_size = sizeof(int32) * ((uint64)environ_count + 1);
- if (total_size >= UINT32_MAX
- || !validate_native_addr(environ_offsets, (uint32)total_size)
- || environ_buf_size >= UINT32_MAX
- || !validate_native_addr(environ_buf, (uint32)environ_buf_size))
- return (wasi_errno_t)-1;
- total_size = sizeof(char *) * (((uint64)environ_count + 1));
- if (total_size >= UINT32_MAX
- || !(environs = wasm_runtime_malloc((uint32)total_size)))
- return (wasi_errno_t)-1;
- err = wasmtime_ssp_environ_get(argv_environ, environs, environ_buf);
- if (err) {
- wasm_runtime_free(environs);
- return err;
- }
- for (i = 0; i < environ_count; i++)
- environ_offsets[i] = addr_native_to_app(environs[i]);
- environ_offsets[environ_count] = 0;
- wasm_runtime_free(environs);
- return 0;
- }
- static wasi_errno_t
- wasi_environ_sizes_get(wasm_exec_env_t exec_env, uint32 *environ_count_app,
- uint32 *environ_buf_size_app)
- {
- wasm_module_inst_t module_inst = get_module_inst(exec_env);
- wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
- struct argv_environ_values *argv_environ =
- wasi_ctx_get_argv_environ(module_inst, wasi_ctx);
- size_t environ_count, environ_buf_size;
- wasi_errno_t err;
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- if (!validate_native_addr(environ_count_app, sizeof(uint32))
- || !validate_native_addr(environ_buf_size_app, sizeof(uint32)))
- return (wasi_errno_t)-1;
- err = wasmtime_ssp_environ_sizes_get(argv_environ, &environ_count,
- &environ_buf_size);
- if (err)
- return err;
- *environ_count_app = (uint32)environ_count;
- *environ_buf_size_app = (uint32)environ_buf_size;
- return 0;
- }
- static wasi_errno_t
- wasi_fd_prestat_get(wasm_exec_env_t exec_env, wasi_fd_t fd,
- wasi_prestat_app_t *prestat_app)
- {
- wasm_module_inst_t module_inst = get_module_inst(exec_env);
- wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
- struct fd_prestats *prestats = wasi_ctx_get_prestats(module_inst, wasi_ctx);
- wasi_prestat_t prestat;
- wasi_errno_t err;
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- if (!validate_native_addr(prestat_app, sizeof(wasi_prestat_app_t)))
- return (wasi_errno_t)-1;
- err = wasmtime_ssp_fd_prestat_get(prestats, fd, &prestat);
- if (err)
- return err;
- prestat_app->pr_type = prestat.pr_type;
- prestat_app->pr_name_len = (uint32)prestat.u.dir.pr_name_len;
- return 0;
- }
- static wasi_errno_t
- wasi_fd_prestat_dir_name(wasm_exec_env_t exec_env, wasi_fd_t fd, char *path,
- uint32 path_len)
- {
- wasm_module_inst_t module_inst = get_module_inst(exec_env);
- wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
- struct fd_prestats *prestats = wasi_ctx_get_prestats(module_inst, wasi_ctx);
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- return wasmtime_ssp_fd_prestat_dir_name(prestats, fd, path, path_len);
- }
- static wasi_errno_t
- wasi_fd_close(wasm_exec_env_t exec_env, wasi_fd_t fd)
- {
- wasm_module_inst_t module_inst = get_module_inst(exec_env);
- wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
- struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- struct fd_prestats *prestats = wasi_ctx_get_prestats(module_inst, wasi_ctx);
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- return wasmtime_ssp_fd_close(curfds, prestats, fd);
- }
- static wasi_errno_t
- wasi_fd_datasync(wasm_exec_env_t exec_env, wasi_fd_t fd)
- {
- wasm_module_inst_t module_inst = get_module_inst(exec_env);
- wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
- struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- return wasmtime_ssp_fd_datasync(curfds, fd);
- }
- static wasi_errno_t
- wasi_fd_pread(wasm_exec_env_t exec_env, wasi_fd_t fd, iovec_app_t *iovec_app,
- uint32 iovs_len, wasi_filesize_t offset, uint32 *nread_app)
- {
- wasm_module_inst_t module_inst = get_module_inst(exec_env);
- wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
- struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- wasi_iovec_t *iovec, *iovec_begin;
- uint64 total_size;
- size_t nread;
- uint32 i;
- wasi_errno_t err;
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- total_size = sizeof(iovec_app_t) * (uint64)iovs_len;
- if (!validate_native_addr(nread_app, (uint32)sizeof(uint32))
- || total_size >= UINT32_MAX
- || !validate_native_addr(iovec_app, (uint32)total_size))
- return (wasi_errno_t)-1;
- total_size = sizeof(wasi_iovec_t) * (uint64)iovs_len;
- if (total_size >= UINT32_MAX
- || !(iovec_begin = wasm_runtime_malloc((uint32)total_size)))
- return (wasi_errno_t)-1;
- iovec = iovec_begin;
- for (i = 0; i < iovs_len; i++, iovec_app++, iovec++) {
- if (!validate_app_addr(iovec_app->buf_offset, iovec_app->buf_len)) {
- err = (wasi_errno_t)-1;
- goto fail;
- }
- iovec->buf = (void *)addr_app_to_native(iovec_app->buf_offset);
- iovec->buf_len = iovec_app->buf_len;
- }
- err = wasmtime_ssp_fd_pread(curfds, fd, iovec_begin, iovs_len, offset,
- &nread);
- if (err)
- goto fail;
- *nread_app = (uint32)nread;
- /* success */
- err = 0;
- fail:
- wasm_runtime_free(iovec_begin);
- return err;
- }
- static wasi_errno_t
- wasi_fd_pwrite(wasm_exec_env_t exec_env, wasi_fd_t fd,
- const iovec_app_t *iovec_app, uint32 iovs_len,
- wasi_filesize_t offset, uint32 *nwritten_app)
- {
- wasm_module_inst_t module_inst = get_module_inst(exec_env);
- wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
- struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- wasi_ciovec_t *ciovec, *ciovec_begin;
- uint64 total_size;
- size_t nwritten;
- uint32 i;
- wasi_errno_t err;
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- total_size = sizeof(iovec_app_t) * (uint64)iovs_len;
- if (!validate_native_addr(nwritten_app, (uint32)sizeof(uint32))
- || total_size >= UINT32_MAX
- || !validate_native_addr((void *)iovec_app, (uint32)total_size))
- return (wasi_errno_t)-1;
- total_size = sizeof(wasi_ciovec_t) * (uint64)iovs_len;
- if (total_size >= UINT32_MAX
- || !(ciovec_begin = wasm_runtime_malloc((uint32)total_size)))
- return (wasi_errno_t)-1;
- ciovec = ciovec_begin;
- for (i = 0; i < iovs_len; i++, iovec_app++, ciovec++) {
- if (!validate_app_addr(iovec_app->buf_offset, iovec_app->buf_len)) {
- err = (wasi_errno_t)-1;
- goto fail;
- }
- ciovec->buf = (char *)addr_app_to_native(iovec_app->buf_offset);
- ciovec->buf_len = iovec_app->buf_len;
- }
- err = wasmtime_ssp_fd_pwrite(curfds, fd, ciovec_begin, iovs_len, offset,
- &nwritten);
- if (err)
- goto fail;
- *nwritten_app = (uint32)nwritten;
- /* success */
- err = 0;
- fail:
- wasm_runtime_free(ciovec_begin);
- return err;
- }
- static wasi_errno_t
- wasi_fd_read(wasm_exec_env_t exec_env, wasi_fd_t fd,
- const iovec_app_t *iovec_app, uint32 iovs_len, uint32 *nread_app)
- {
- wasm_module_inst_t module_inst = get_module_inst(exec_env);
- wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
- struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- wasi_iovec_t *iovec, *iovec_begin;
- uint64 total_size;
- size_t nread;
- uint32 i;
- wasi_errno_t err;
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- total_size = sizeof(iovec_app_t) * (uint64)iovs_len;
- if (!validate_native_addr(nread_app, (uint32)sizeof(uint32))
- || total_size >= UINT32_MAX
- || !validate_native_addr((void *)iovec_app, (uint32)total_size))
- return (wasi_errno_t)-1;
- total_size = sizeof(wasi_iovec_t) * (uint64)iovs_len;
- if (total_size >= UINT32_MAX
- || !(iovec_begin = wasm_runtime_malloc((uint32)total_size)))
- return (wasi_errno_t)-1;
- iovec = iovec_begin;
- for (i = 0; i < iovs_len; i++, iovec_app++, iovec++) {
- if (!validate_app_addr(iovec_app->buf_offset, iovec_app->buf_len)) {
- err = (wasi_errno_t)-1;
- goto fail;
- }
- iovec->buf = (void *)addr_app_to_native(iovec_app->buf_offset);
- iovec->buf_len = iovec_app->buf_len;
- }
- err = wasmtime_ssp_fd_read(curfds, fd, iovec_begin, iovs_len, &nread);
- if (err)
- goto fail;
- *nread_app = (uint32)nread;
- /* success */
- err = 0;
- fail:
- wasm_runtime_free(iovec_begin);
- return err;
- }
- static wasi_errno_t
- wasi_fd_renumber(wasm_exec_env_t exec_env, wasi_fd_t from, wasi_fd_t to)
- {
- wasm_module_inst_t module_inst = get_module_inst(exec_env);
- wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
- struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- struct fd_prestats *prestats = wasi_ctx_get_prestats(module_inst, wasi_ctx);
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- return wasmtime_ssp_fd_renumber(curfds, prestats, from, to);
- }
- static wasi_errno_t
- wasi_fd_seek(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_filedelta_t offset,
- wasi_whence_t whence, wasi_filesize_t *newoffset)
- {
- wasm_module_inst_t module_inst = get_module_inst(exec_env);
- wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
- struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- if (!validate_native_addr(newoffset, sizeof(wasi_filesize_t)))
- return (wasi_errno_t)-1;
- return wasmtime_ssp_fd_seek(curfds, fd, offset, whence, newoffset);
- }
- static wasi_errno_t
- wasi_fd_tell(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_filesize_t *newoffset)
- {
- wasm_module_inst_t module_inst = get_module_inst(exec_env);
- wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
- struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- if (!validate_native_addr(newoffset, sizeof(wasi_filesize_t)))
- return (wasi_errno_t)-1;
- return wasmtime_ssp_fd_tell(curfds, fd, newoffset);
- }
- static wasi_errno_t
- wasi_fd_fdstat_get(wasm_exec_env_t exec_env, wasi_fd_t fd,
- wasi_fdstat_t *fdstat_app)
- {
- wasm_module_inst_t module_inst = get_module_inst(exec_env);
- wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
- struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- wasi_fdstat_t fdstat;
- wasi_errno_t err;
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- if (!validate_native_addr(fdstat_app, sizeof(wasi_fdstat_t)))
- return (wasi_errno_t)-1;
- err = wasmtime_ssp_fd_fdstat_get(curfds, fd, &fdstat);
- if (err)
- return err;
- memcpy(fdstat_app, &fdstat, sizeof(wasi_fdstat_t));
- return 0;
- }
- static wasi_errno_t
- wasi_fd_fdstat_set_flags(wasm_exec_env_t exec_env, wasi_fd_t fd,
- wasi_fdflags_t flags)
- {
- wasm_module_inst_t module_inst = get_module_inst(exec_env);
- wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
- struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- return wasmtime_ssp_fd_fdstat_set_flags(curfds, fd, flags);
- }
- static wasi_errno_t
- wasi_fd_fdstat_set_rights(wasm_exec_env_t exec_env, wasi_fd_t fd,
- wasi_rights_t fs_rights_base,
- wasi_rights_t fs_rights_inheriting)
- {
- wasm_module_inst_t module_inst = get_module_inst(exec_env);
- wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
- struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- return wasmtime_ssp_fd_fdstat_set_rights(curfds, fd, fs_rights_base,
- fs_rights_inheriting);
- }
- static wasi_errno_t
- wasi_fd_sync(wasm_exec_env_t exec_env, wasi_fd_t fd)
- {
- wasm_module_inst_t module_inst = get_module_inst(exec_env);
- wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
- struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- return wasmtime_ssp_fd_sync(curfds, fd);
- }
- static wasi_errno_t
- wasi_fd_write(wasm_exec_env_t exec_env, wasi_fd_t fd,
- const iovec_app_t *iovec_app, uint32 iovs_len,
- uint32 *nwritten_app)
- {
- wasm_module_inst_t module_inst = get_module_inst(exec_env);
- wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
- struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- wasi_ciovec_t *ciovec, *ciovec_begin;
- uint64 total_size;
- size_t nwritten;
- uint32 i;
- wasi_errno_t err;
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- total_size = sizeof(iovec_app_t) * (uint64)iovs_len;
- if (!validate_native_addr(nwritten_app, (uint32)sizeof(uint32))
- || total_size >= UINT32_MAX
- || !validate_native_addr((void *)iovec_app, (uint32)total_size))
- return (wasi_errno_t)-1;
- total_size = sizeof(wasi_ciovec_t) * (uint64)iovs_len;
- if (total_size >= UINT32_MAX
- || !(ciovec_begin = wasm_runtime_malloc((uint32)total_size)))
- return (wasi_errno_t)-1;
- ciovec = ciovec_begin;
- for (i = 0; i < iovs_len; i++, iovec_app++, ciovec++) {
- if (!validate_app_addr(iovec_app->buf_offset, iovec_app->buf_len)) {
- err = (wasi_errno_t)-1;
- goto fail;
- }
- ciovec->buf = (char *)addr_app_to_native(iovec_app->buf_offset);
- ciovec->buf_len = iovec_app->buf_len;
- }
- err = wasmtime_ssp_fd_write(curfds, fd, ciovec_begin, iovs_len, &nwritten);
- if (err)
- goto fail;
- *nwritten_app = (uint32)nwritten;
- /* success */
- err = 0;
- fail:
- wasm_runtime_free(ciovec_begin);
- return err;
- }
- static wasi_errno_t
- wasi_fd_advise(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_filesize_t offset,
- wasi_filesize_t len, wasi_advice_t advice)
- {
- wasm_module_inst_t module_inst = get_module_inst(exec_env);
- wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
- struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- return wasmtime_ssp_fd_advise(curfds, fd, offset, len, advice);
- }
- static wasi_errno_t
- wasi_fd_allocate(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_filesize_t offset,
- wasi_filesize_t len)
- {
- wasm_module_inst_t module_inst = get_module_inst(exec_env);
- wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
- struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- return wasmtime_ssp_fd_allocate(curfds, fd, offset, len);
- }
- static wasi_errno_t
- wasi_path_create_directory(wasm_exec_env_t exec_env, wasi_fd_t fd,
- const char *path, uint32 path_len)
- {
- wasm_module_inst_t module_inst = get_module_inst(exec_env);
- wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
- struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- return wasmtime_ssp_path_create_directory(curfds, fd, path, path_len);
- }
- static wasi_errno_t
- wasi_path_link(wasm_exec_env_t exec_env, wasi_fd_t old_fd,
- wasi_lookupflags_t old_flags, const char *old_path,
- uint32 old_path_len, wasi_fd_t new_fd, const char *new_path,
- uint32 new_path_len)
- {
- wasm_module_inst_t module_inst = get_module_inst(exec_env);
- wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
- struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- struct fd_prestats *prestats = wasi_ctx_get_prestats(module_inst, wasi_ctx);
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- return wasmtime_ssp_path_link(curfds, prestats, old_fd, old_flags, old_path,
- old_path_len, new_fd, new_path, new_path_len);
- }
- static wasi_errno_t
- wasi_path_open(wasm_exec_env_t exec_env, wasi_fd_t dirfd,
- wasi_lookupflags_t dirflags, const char *path, uint32 path_len,
- wasi_oflags_t oflags, wasi_rights_t fs_rights_base,
- wasi_rights_t fs_rights_inheriting, wasi_fdflags_t fs_flags,
- wasi_fd_t *fd_app)
- {
- wasm_module_inst_t module_inst = get_module_inst(exec_env);
- wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
- struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- wasi_fd_t fd = (wasi_fd_t)-1; /* set fd_app -1 if path open failed */
- wasi_errno_t err;
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- if (!validate_native_addr(fd_app, sizeof(wasi_fd_t)))
- return (wasi_errno_t)-1;
- err = wasmtime_ssp_path_open(curfds, dirfd, dirflags, path, path_len,
- oflags, fs_rights_base, fs_rights_inheriting,
- fs_flags, &fd);
- *fd_app = fd;
- return err;
- }
- static wasi_errno_t
- wasi_fd_readdir(wasm_exec_env_t exec_env, wasi_fd_t fd, void *buf,
- uint32 buf_len, wasi_dircookie_t cookie, uint32 *bufused_app)
- {
- wasm_module_inst_t module_inst = get_module_inst(exec_env);
- wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
- struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- size_t bufused;
- wasi_errno_t err;
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- if (!validate_native_addr(bufused_app, sizeof(uint32)))
- return (wasi_errno_t)-1;
- err = wasmtime_ssp_fd_readdir(curfds, fd, buf, buf_len, cookie, &bufused);
- if (err)
- return err;
- *bufused_app = (uint32)bufused;
- return 0;
- }
- static wasi_errno_t
- wasi_path_readlink(wasm_exec_env_t exec_env, wasi_fd_t fd, const char *path,
- uint32 path_len, char *buf, uint32 buf_len,
- uint32 *bufused_app)
- {
- wasm_module_inst_t module_inst = get_module_inst(exec_env);
- wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
- struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- size_t bufused;
- wasi_errno_t err;
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- if (!validate_native_addr(bufused_app, sizeof(uint32)))
- return (wasi_errno_t)-1;
- err = wasmtime_ssp_path_readlink(curfds, fd, path, path_len, buf, buf_len,
- &bufused);
- if (err)
- return err;
- *bufused_app = (uint32)bufused;
- return 0;
- }
- static wasi_errno_t
- wasi_path_rename(wasm_exec_env_t exec_env, wasi_fd_t old_fd,
- const char *old_path, uint32 old_path_len, wasi_fd_t new_fd,
- const char *new_path, uint32 new_path_len)
- {
- wasm_module_inst_t module_inst = get_module_inst(exec_env);
- wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
- struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- return wasmtime_ssp_path_rename(curfds, old_fd, old_path, old_path_len,
- new_fd, new_path, new_path_len);
- }
- static wasi_errno_t
- wasi_fd_filestat_get(wasm_exec_env_t exec_env, wasi_fd_t fd,
- wasi_filestat_t *filestat)
- {
- wasm_module_inst_t module_inst = get_module_inst(exec_env);
- wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
- struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- if (!validate_native_addr(filestat, sizeof(wasi_filestat_t)))
- return (wasi_errno_t)-1;
- return wasmtime_ssp_fd_filestat_get(curfds, fd, filestat);
- }
- static wasi_errno_t
- wasi_fd_filestat_set_times(wasm_exec_env_t exec_env, wasi_fd_t fd,
- wasi_timestamp_t st_atim, wasi_timestamp_t st_mtim,
- wasi_fstflags_t fstflags)
- {
- wasm_module_inst_t module_inst = get_module_inst(exec_env);
- wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
- struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- return wasmtime_ssp_fd_filestat_set_times(curfds, fd, st_atim, st_mtim,
- fstflags);
- }
- static wasi_errno_t
- wasi_fd_filestat_set_size(wasm_exec_env_t exec_env, wasi_fd_t fd,
- wasi_filesize_t st_size)
- {
- wasm_module_inst_t module_inst = get_module_inst(exec_env);
- wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
- struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- return wasmtime_ssp_fd_filestat_set_size(curfds, fd, st_size);
- }
- static wasi_errno_t
- wasi_path_filestat_get(wasm_exec_env_t exec_env, wasi_fd_t fd,
- wasi_lookupflags_t flags, const char *path,
- uint32 path_len, wasi_filestat_t *filestat)
- {
- wasm_module_inst_t module_inst = get_module_inst(exec_env);
- wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
- struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- if (!validate_native_addr(filestat, sizeof(wasi_filestat_t)))
- return (wasi_errno_t)-1;
- return wasmtime_ssp_path_filestat_get(curfds, fd, flags, path, path_len,
- filestat);
- }
- static wasi_errno_t
- wasi_path_filestat_set_times(wasm_exec_env_t exec_env, wasi_fd_t fd,
- wasi_lookupflags_t flags, const char *path,
- uint32 path_len, wasi_timestamp_t st_atim,
- wasi_timestamp_t st_mtim, wasi_fstflags_t fstflags)
- {
- wasm_module_inst_t module_inst = get_module_inst(exec_env);
- wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
- struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- return wasmtime_ssp_path_filestat_set_times(
- curfds, fd, flags, path, path_len, st_atim, st_mtim, fstflags);
- }
- static wasi_errno_t
- wasi_path_symlink(wasm_exec_env_t exec_env, const char *old_path,
- uint32 old_path_len, wasi_fd_t fd, const char *new_path,
- uint32 new_path_len)
- {
- wasm_module_inst_t module_inst = get_module_inst(exec_env);
- wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
- struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- struct fd_prestats *prestats = wasi_ctx_get_prestats(module_inst, wasi_ctx);
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- return wasmtime_ssp_path_symlink(curfds, prestats, old_path, old_path_len,
- fd, new_path, new_path_len);
- }
- static wasi_errno_t
- wasi_path_unlink_file(wasm_exec_env_t exec_env, wasi_fd_t fd, const char *path,
- uint32 path_len)
- {
- wasm_module_inst_t module_inst = get_module_inst(exec_env);
- wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
- struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- return wasmtime_ssp_path_unlink_file(curfds, fd, path, path_len);
- }
- static wasi_errno_t
- wasi_path_remove_directory(wasm_exec_env_t exec_env, wasi_fd_t fd,
- const char *path, uint32 path_len)
- {
- wasm_module_inst_t module_inst = get_module_inst(exec_env);
- wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
- struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- return wasmtime_ssp_path_remove_directory(curfds, fd, path, path_len);
- }
- static wasi_errno_t
- wasi_poll_oneoff(wasm_exec_env_t exec_env, const wasi_subscription_t *in,
- wasi_event_t *out, uint32 nsubscriptions, uint32 *nevents_app)
- {
- wasm_module_inst_t module_inst = get_module_inst(exec_env);
- wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
- struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- size_t nevents;
- wasi_errno_t err;
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- if (!validate_native_addr((void *)in, sizeof(wasi_subscription_t))
- || !validate_native_addr(out, sizeof(wasi_event_t))
- || !validate_native_addr(nevents_app, sizeof(uint32)))
- return (wasi_errno_t)-1;
- err = wasmtime_ssp_poll_oneoff(curfds, in, out, nsubscriptions, &nevents);
- if (err)
- return err;
- *nevents_app = (uint32)nevents;
- return 0;
- }
- static void
- wasi_proc_exit(wasm_exec_env_t exec_env, wasi_exitcode_t rval)
- {
- wasm_module_inst_t module_inst = get_module_inst(exec_env);
- /* Here throwing exception is just to let wasm app exit,
- the upper layer should clear the exception and return
- as normal */
- wasm_runtime_set_exception(module_inst, "wasi proc exit");
- }
- static wasi_errno_t
- wasi_proc_raise(wasm_exec_env_t exec_env, wasi_signal_t sig)
- {
- wasm_module_inst_t module_inst = get_module_inst(exec_env);
- char buf[32];
- snprintf(buf, sizeof(buf), "%s%d", "wasi proc raise ", sig);
- wasm_runtime_set_exception(module_inst, buf);
- return 0;
- }
- static wasi_errno_t
- wasi_random_get(wasm_exec_env_t exec_env, void *buf, uint32 buf_len)
- {
- return wasmtime_ssp_random_get(buf, buf_len);
- }
- static wasi_errno_t
- wasi_sock_recv(wasm_exec_env_t exec_env, wasi_fd_t sock, iovec_app_t *ri_data,
- uint32 ri_data_len, wasi_riflags_t ri_flags,
- uint32 *ro_datalen_app, wasi_roflags_t *ro_flags)
- {
- wasm_module_inst_t module_inst = get_module_inst(exec_env);
- wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
- struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- wasi_iovec_t *iovec, *iovec_begin;
- uint64 total_size;
- size_t ro_datalen;
- uint32 i;
- wasi_errno_t err;
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- total_size = sizeof(iovec_app_t) * (uint64)ri_data_len;
- if (!validate_native_addr(ro_datalen_app, (uint32)sizeof(uint32))
- || !validate_native_addr(ro_flags, (uint32)sizeof(wasi_roflags_t))
- || total_size >= UINT32_MAX
- || !validate_native_addr(ri_data, (uint32)total_size))
- return (wasi_errno_t)-1;
- total_size = sizeof(wasi_iovec_t) * (uint64)ri_data_len;
- if (total_size >= UINT32_MAX
- || !(iovec_begin = wasm_runtime_malloc((uint32)total_size)))
- return (wasi_errno_t)-1;
- iovec = iovec_begin;
- for (i = 0; i < ri_data_len; i++, ri_data++, iovec++) {
- if (!validate_app_addr(ri_data->buf_offset, ri_data->buf_len)) {
- err = (wasi_errno_t)-1;
- goto fail;
- }
- iovec->buf = (void *)addr_app_to_native(ri_data->buf_offset);
- iovec->buf_len = ri_data->buf_len;
- }
- err = wasmtime_ssp_sock_recv(curfds, sock, iovec_begin, ri_data_len,
- ri_flags, &ro_datalen, ro_flags);
- if (err)
- goto fail;
- *(uint32 *)ro_datalen_app = (uint32)ro_datalen;
- /* success */
- err = 0;
- fail:
- wasm_runtime_free(iovec_begin);
- return err;
- }
- static wasi_errno_t
- wasi_sock_send(wasm_exec_env_t exec_env, wasi_fd_t sock,
- const iovec_app_t *si_data, uint32 si_data_len,
- wasi_siflags_t si_flags, uint32 *so_datalen_app)
- {
- wasm_module_inst_t module_inst = get_module_inst(exec_env);
- wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
- struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- wasi_ciovec_t *ciovec, *ciovec_begin;
- uint64 total_size;
- size_t so_datalen;
- uint32 i;
- wasi_errno_t err;
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- total_size = sizeof(iovec_app_t) * (uint64)si_data_len;
- if (!validate_native_addr(so_datalen_app, sizeof(uint32))
- || total_size >= UINT32_MAX
- || !validate_native_addr((void *)si_data, (uint32)total_size))
- return (wasi_errno_t)-1;
- total_size = sizeof(wasi_ciovec_t) * (uint64)si_data_len;
- if (total_size >= UINT32_MAX
- || !(ciovec_begin = wasm_runtime_malloc((uint32)total_size)))
- return (wasi_errno_t)-1;
- ciovec = ciovec_begin;
- for (i = 0; i < si_data_len; i++, si_data++, ciovec++) {
- if (!validate_app_addr(si_data->buf_offset, si_data->buf_len)) {
- err = (wasi_errno_t)-1;
- goto fail;
- }
- ciovec->buf = (char *)addr_app_to_native(si_data->buf_offset);
- ciovec->buf_len = si_data->buf_len;
- }
- err = wasmtime_ssp_sock_send(curfds, sock, ciovec_begin, si_data_len,
- si_flags, &so_datalen);
- if (err)
- goto fail;
- *so_datalen_app = (uint32)so_datalen;
- /* success */
- err = 0;
- fail:
- wasm_runtime_free(ciovec_begin);
- return err;
- }
- static wasi_errno_t
- wasi_sock_shutdown(wasm_exec_env_t exec_env, wasi_fd_t sock, wasi_sdflags_t how)
- {
- wasm_module_inst_t module_inst = get_module_inst(exec_env);
- wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
- struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- return wasmtime_ssp_sock_shutdown(curfds, sock, how);
- }
- static wasi_errno_t
- wasi_sched_yield(wasm_exec_env_t exec_env)
- {
- return wasmtime_ssp_sched_yield();
- }
- /* clang-format off */
- #define REG_NATIVE_FUNC(func_name, signature) \
- { #func_name, wasi_##func_name, signature, NULL }
- /* clang-format on */
- static NativeSymbol native_symbols_libc_wasi[] = {
- REG_NATIVE_FUNC(args_get, "(**)i"),
- REG_NATIVE_FUNC(args_sizes_get, "(**)i"),
- REG_NATIVE_FUNC(clock_res_get, "(i*)i"),
- REG_NATIVE_FUNC(clock_time_get, "(iI*)i"),
- REG_NATIVE_FUNC(environ_get, "(**)i"),
- REG_NATIVE_FUNC(environ_sizes_get, "(**)i"),
- REG_NATIVE_FUNC(fd_prestat_get, "(i*)i"),
- REG_NATIVE_FUNC(fd_prestat_dir_name, "(i*~)i"),
- REG_NATIVE_FUNC(fd_close, "(i)i"),
- REG_NATIVE_FUNC(fd_datasync, "(i)i"),
- REG_NATIVE_FUNC(fd_pread, "(i*iI*)i"),
- REG_NATIVE_FUNC(fd_pwrite, "(i*iI*)i"),
- REG_NATIVE_FUNC(fd_read, "(i*i*)i"),
- REG_NATIVE_FUNC(fd_renumber, "(ii)i"),
- REG_NATIVE_FUNC(fd_seek, "(iIi*)i"),
- REG_NATIVE_FUNC(fd_tell, "(i*)i"),
- REG_NATIVE_FUNC(fd_fdstat_get, "(i*)i"),
- REG_NATIVE_FUNC(fd_fdstat_set_flags, "(ii)i"),
- REG_NATIVE_FUNC(fd_fdstat_set_rights, "(iII)i"),
- REG_NATIVE_FUNC(fd_sync, "(i)i"),
- REG_NATIVE_FUNC(fd_write, "(i*i*)i"),
- REG_NATIVE_FUNC(fd_advise, "(iIIi)i"),
- REG_NATIVE_FUNC(fd_allocate, "(iII)i"),
- REG_NATIVE_FUNC(path_create_directory, "(i*~)i"),
- REG_NATIVE_FUNC(path_link, "(ii*~i*~)i"),
- REG_NATIVE_FUNC(path_open, "(ii*~iIIi*)i"),
- REG_NATIVE_FUNC(fd_readdir, "(i*~I*)i"),
- REG_NATIVE_FUNC(path_readlink, "(i*~*~*)i"),
- REG_NATIVE_FUNC(path_rename, "(i*~i*~)i"),
- REG_NATIVE_FUNC(fd_filestat_get, "(i*)i"),
- REG_NATIVE_FUNC(fd_filestat_set_times, "(iIIi)i"),
- REG_NATIVE_FUNC(fd_filestat_set_size, "(iI)i"),
- REG_NATIVE_FUNC(path_filestat_get, "(ii*~*)i"),
- REG_NATIVE_FUNC(path_filestat_set_times, "(ii*~IIi)i"),
- REG_NATIVE_FUNC(path_symlink, "(*~i*~)i"),
- REG_NATIVE_FUNC(path_unlink_file, "(i*~)i"),
- REG_NATIVE_FUNC(path_remove_directory, "(i*~)i"),
- REG_NATIVE_FUNC(poll_oneoff, "(**i*)i"),
- REG_NATIVE_FUNC(proc_exit, "(i)"),
- REG_NATIVE_FUNC(proc_raise, "(i)i"),
- REG_NATIVE_FUNC(random_get, "(*~)i"),
- REG_NATIVE_FUNC(sock_recv, "(i*ii**)i"),
- REG_NATIVE_FUNC(sock_send, "(i*ii*)i"),
- REG_NATIVE_FUNC(sock_shutdown, "(ii)i"),
- REG_NATIVE_FUNC(sched_yield, "()i"),
- };
- uint32
- get_libc_wasi_export_apis(NativeSymbol **p_libc_wasi_apis)
- {
- *p_libc_wasi_apis = native_symbols_libc_wasi;
- return sizeof(native_symbols_libc_wasi) / sizeof(NativeSymbol);
- }
|