| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412 |
- /*
- * 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"
- #include "wasm_runtime_common.h"
- #include "wasmtime_ssp.h"
- #if WASM_ENABLE_THREAD_MGR != 0
- #include "../../../thread-mgr/thread_manager.h"
- #endif
- 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 *wasi_ctx_t;
- wasi_ctx_t
- wasm_runtime_get_wasi_ctx(wasm_module_inst_t module_inst);
- #if WASM_ENABLE_THREAD_MGR != 0
- static inline uint64_t
- min_uint64(uint64_t a, uint64_t b)
- {
- return a > b ? b : a;
- }
- #endif
- static inline uint32_t
- min_uint32(uint32_t a, uint32_t b)
- {
- return a > b ? b : a;
- }
- static inline struct fd_table *
- wasi_ctx_get_curfds(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(wasi_ctx_t wasi_ctx)
- {
- if (!wasi_ctx)
- return NULL;
- return wasi_ctx->prestats;
- }
- static inline struct addr_pool *
- wasi_ctx_get_addr_pool(wasi_ctx_t wasi_ctx)
- {
- if (!wasi_ctx)
- return NULL;
- return wasi_ctx->addr_pool;
- }
- static inline char **
- wasi_ctx_get_ns_lookup_list(wasi_ctx_t wasi_ctx)
- {
- if (!wasi_ctx)
- return NULL;
- return wasi_ctx->ns_lookup_list;
- }
- 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, total_size)
- || argv_buf_size >= UINT32_MAX
- || !validate_native_addr(argv_buf, (uint64)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] = (uint32)addr_native_to_app(argv[i]);
- 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, (uint64)sizeof(uint32))
- || !validate_native_addr(argv_buf_size_app, (uint64)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, (uint64)sizeof(wasi_timestamp_t)))
- return (wasi_errno_t)-1;
- return os_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, (uint64)sizeof(wasi_timestamp_t)))
- return (wasi_errno_t)-1;
- return os_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, total_size)
- || environ_buf_size >= UINT32_MAX
- || !validate_native_addr(environ_buf, (uint64)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] = (uint32)addr_native_to_app(environs[i]);
- 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, (uint64)sizeof(uint32))
- || !validate_native_addr(environ_buf_size_app, (uint64)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(wasi_ctx);
- wasi_prestat_t prestat;
- wasi_errno_t err;
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- if (!validate_native_addr(prestat_app, (uint64)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(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(wasi_ctx);
- struct fd_prestats *prestats = wasi_ctx_get_prestats(wasi_ctx);
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- return wasmtime_ssp_fd_close(exec_env, 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(wasi_ctx);
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- return wasmtime_ssp_fd_datasync(exec_env, 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(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, (uint64)sizeof(uint32))
- || total_size >= UINT32_MAX
- || !validate_native_addr(iovec_app, total_size))
- return (wasi_errno_t)-1;
- total_size = sizeof(wasi_iovec_t) * (uint64)iovs_len;
- if (total_size == 0) {
- total_size = 1; /* avoid user-triggered 0-sized allocation */
- }
- 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((uint64)iovec_app->buf_offset,
- (uint64)iovec_app->buf_len)) {
- err = (wasi_errno_t)-1;
- goto fail;
- }
- iovec->buf = (void *)addr_app_to_native((uint64)iovec_app->buf_offset);
- iovec->buf_len = iovec_app->buf_len;
- }
- err = wasmtime_ssp_fd_pread(exec_env, 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(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, (uint64)sizeof(uint32))
- || total_size >= UINT32_MAX
- || !validate_native_addr((void *)iovec_app, total_size))
- return (wasi_errno_t)-1;
- total_size = sizeof(wasi_ciovec_t) * (uint64)iovs_len;
- if (total_size == 0) {
- total_size = 1; /* avoid user-triggered 0-sized allocation */
- }
- 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((uint64)iovec_app->buf_offset,
- (uint64)iovec_app->buf_len)) {
- err = (wasi_errno_t)-1;
- goto fail;
- }
- ciovec->buf = (char *)addr_app_to_native((uint64)iovec_app->buf_offset);
- ciovec->buf_len = iovec_app->buf_len;
- }
- err = wasmtime_ssp_fd_pwrite(exec_env, 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(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, (uint64)sizeof(uint32))
- || total_size >= UINT32_MAX
- || !validate_native_addr((void *)iovec_app, total_size))
- return (wasi_errno_t)-1;
- total_size = sizeof(wasi_iovec_t) * (uint64)iovs_len;
- if (total_size == 0) {
- total_size = 1; /* avoid user-triggered 0-sized allocation */
- }
- 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((uint64)iovec_app->buf_offset,
- (uint64)iovec_app->buf_len)) {
- err = (wasi_errno_t)-1;
- goto fail;
- }
- iovec->buf = (void *)addr_app_to_native((uint64)iovec_app->buf_offset);
- iovec->buf_len = iovec_app->buf_len;
- }
- err = wasmtime_ssp_fd_read(exec_env, 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(wasi_ctx);
- struct fd_prestats *prestats = wasi_ctx_get_prestats(wasi_ctx);
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- return wasmtime_ssp_fd_renumber(exec_env, 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(wasi_ctx);
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- if (!validate_native_addr(newoffset, (uint64)sizeof(wasi_filesize_t)))
- return (wasi_errno_t)-1;
- return wasmtime_ssp_fd_seek(exec_env, 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(wasi_ctx);
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- if (!validate_native_addr(newoffset, (uint64)sizeof(wasi_filesize_t)))
- return (wasi_errno_t)-1;
- return wasmtime_ssp_fd_tell(exec_env, 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(wasi_ctx);
- wasi_fdstat_t fdstat;
- wasi_errno_t err;
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- if (!validate_native_addr(fdstat_app, (uint64)sizeof(wasi_fdstat_t)))
- return (wasi_errno_t)-1;
- err = wasmtime_ssp_fd_fdstat_get(exec_env, 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(wasi_ctx);
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- return wasmtime_ssp_fd_fdstat_set_flags(exec_env, 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(wasi_ctx);
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- return wasmtime_ssp_fd_fdstat_set_rights(
- exec_env, 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(wasi_ctx);
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- return wasmtime_ssp_fd_sync(exec_env, 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(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, (uint64)sizeof(uint32))
- || total_size >= UINT32_MAX
- || !validate_native_addr((void *)iovec_app, total_size))
- return (wasi_errno_t)-1;
- total_size = sizeof(wasi_ciovec_t) * (uint64)iovs_len;
- if (total_size == 0) {
- total_size = 1; /* avoid user-triggered 0-sized allocation */
- }
- 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((uint64)iovec_app->buf_offset,
- (uint64)iovec_app->buf_len)) {
- err = (wasi_errno_t)-1;
- goto fail;
- }
- ciovec->buf = (char *)addr_app_to_native((uint64)iovec_app->buf_offset);
- ciovec->buf_len = iovec_app->buf_len;
- }
- err = wasmtime_ssp_fd_write(exec_env, 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(wasi_ctx);
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- return wasmtime_ssp_fd_advise(exec_env, 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(wasi_ctx);
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- return wasmtime_ssp_fd_allocate(exec_env, 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(wasi_ctx);
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- return wasmtime_ssp_path_create_directory(exec_env, 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(wasi_ctx);
- struct fd_prestats *prestats = wasi_ctx_get_prestats(wasi_ctx);
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- return wasmtime_ssp_path_link(exec_env, 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(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, (uint64)sizeof(wasi_fd_t)))
- return (wasi_errno_t)-1;
- err = wasmtime_ssp_path_open(exec_env, 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(wasi_ctx);
- size_t bufused;
- wasi_errno_t err;
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- if (!validate_native_addr(bufused_app, (uint64)sizeof(uint32)))
- return (wasi_errno_t)-1;
- err = wasmtime_ssp_fd_readdir(exec_env, 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(wasi_ctx);
- size_t bufused;
- wasi_errno_t err;
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- if (!validate_native_addr(bufused_app, (uint64)sizeof(uint32)))
- return (wasi_errno_t)-1;
- err = wasmtime_ssp_path_readlink(exec_env, 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(wasi_ctx);
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- return wasmtime_ssp_path_rename(exec_env, 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(wasi_ctx);
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- if (!validate_native_addr(filestat, (uint64)sizeof(wasi_filestat_t)))
- return (wasi_errno_t)-1;
- return wasmtime_ssp_fd_filestat_get(exec_env, 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(wasi_ctx);
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- return wasmtime_ssp_fd_filestat_set_times(exec_env, 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(wasi_ctx);
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- return wasmtime_ssp_fd_filestat_set_size(exec_env, 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(wasi_ctx);
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- if (!validate_native_addr(filestat, (uint64)sizeof(wasi_filestat_t)))
- return (wasi_errno_t)-1;
- return wasmtime_ssp_path_filestat_get(exec_env, 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(wasi_ctx);
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- return wasmtime_ssp_path_filestat_set_times(exec_env, 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(wasi_ctx);
- struct fd_prestats *prestats = wasi_ctx_get_prestats(wasi_ctx);
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- return wasmtime_ssp_path_symlink(exec_env, 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(wasi_ctx);
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- return wasmtime_ssp_path_unlink_file(exec_env, 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(wasi_ctx);
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- return wasmtime_ssp_path_remove_directory(exec_env, curfds, fd, path,
- path_len);
- }
- #if WASM_ENABLE_THREAD_MGR != 0
- static __wasi_timestamp_t
- get_timeout_for_poll_oneoff(const wasi_subscription_t *in,
- uint32 nsubscriptions)
- {
- __wasi_timestamp_t timeout = (__wasi_timestamp_t)-1;
- uint32 i = 0;
- for (i = 0; i < nsubscriptions; ++i) {
- const __wasi_subscription_t *s = &in[i];
- if (s->u.type == __WASI_EVENTTYPE_CLOCK
- && (s->u.u.clock.flags & __WASI_SUBSCRIPTION_CLOCK_ABSTIME) == 0) {
- timeout = min_uint64(timeout, s->u.u.clock.timeout);
- }
- }
- return timeout;
- }
- static void
- update_clock_subscription_data(wasi_subscription_t *in, uint32 nsubscriptions,
- const wasi_timestamp_t new_timeout)
- {
- uint32 i = 0;
- for (i = 0; i < nsubscriptions; ++i) {
- __wasi_subscription_t *s = &in[i];
- if (s->u.type == __WASI_EVENTTYPE_CLOCK) {
- s->u.u.clock.timeout = new_timeout;
- }
- }
- }
- static wasi_errno_t
- execute_interruptible_poll_oneoff(
- #if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
- #endif
- const __wasi_subscription_t *in, __wasi_event_t *out, size_t nsubscriptions,
- size_t *nevents, wasm_exec_env_t exec_env)
- {
- if (nsubscriptions == 0) {
- *nevents = 0;
- return __WASI_ESUCCESS;
- }
- wasi_errno_t err;
- __wasi_timestamp_t elapsed = 0;
- bool all_outs_are_type_clock;
- uint32 i;
- const __wasi_timestamp_t timeout = get_timeout_for_poll_oneoff(
- in, (uint32)nsubscriptions),
- time_quant = (__wasi_timestamp_t)1e9;
- const uint64 size_to_copy =
- nsubscriptions * (uint64)sizeof(wasi_subscription_t);
- __wasi_subscription_t *in_copy = NULL;
- if (size_to_copy >= UINT32_MAX
- || !(in_copy = (__wasi_subscription_t *)wasm_runtime_malloc(
- (uint32)size_to_copy))) {
- return __WASI_ENOMEM;
- }
- bh_memcpy_s(in_copy, (uint32)size_to_copy, in, (uint32)size_to_copy);
- while (timeout == (__wasi_timestamp_t)-1 || elapsed <= timeout) {
- /* update timeout for clock subscription events */
- update_clock_subscription_data(
- in_copy, (uint32)nsubscriptions,
- min_uint64(time_quant, timeout - elapsed));
- err = wasmtime_ssp_poll_oneoff(exec_env, curfds, in_copy, out,
- nsubscriptions, nevents);
- elapsed += time_quant;
- if (err) {
- wasm_runtime_free(in_copy);
- return err;
- }
- if (wasm_cluster_is_thread_terminated(exec_env)) {
- wasm_runtime_free(in_copy);
- return __WASI_EINTR;
- }
- else if (*nevents > 0) {
- all_outs_are_type_clock = true;
- for (i = 0; i < *nevents; i++) {
- if (out[i].type != __WASI_EVENTTYPE_CLOCK) {
- all_outs_are_type_clock = false;
- break;
- }
- }
- if (!all_outs_are_type_clock) {
- wasm_runtime_free(in_copy);
- return __WASI_ESUCCESS;
- }
- }
- }
- wasm_runtime_free(in_copy);
- return __WASI_ESUCCESS;
- }
- #endif
- 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(wasi_ctx);
- size_t nevents = 0;
- wasi_errno_t err;
- if (!wasi_ctx)
- return (wasi_errno_t)-1;
- if (!validate_native_addr((void *)in, (uint64)sizeof(wasi_subscription_t))
- || !validate_native_addr(out, (uint64)sizeof(wasi_event_t))
- || !validate_native_addr(nevents_app, (uint64)sizeof(uint32)))
- return (wasi_errno_t)-1;
- #if WASM_ENABLE_THREAD_MGR == 0
- err = wasmtime_ssp_poll_oneoff(exec_env, curfds, in, out, nsubscriptions,
- &nevents);
- #else
- err = execute_interruptible_poll_oneoff(curfds, in, out, nsubscriptions,
- &nevents, exec_env);
- #endif
- 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);
- wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
- /* 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");
- wasi_ctx->exit_code = rval;
- }
- 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)
- {
- (void)exec_env;
- return wasmtime_ssp_random_get(buf, buf_len);
- }
- static wasi_errno_t
- wasi_sock_accept(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_fdflags_t flags,
- wasi_fd_t *fd_new)
- {
- 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 = NULL;
- if (!wasi_ctx)
- return __WASI_EACCES;
- if (!validate_native_addr(fd_new, sizeof(*fd_new)))
- return __WASI_EINVAL;
- curfds = wasi_ctx_get_curfds(wasi_ctx);
- return wasi_ssp_sock_accept(exec_env, curfds, fd, flags, fd_new);
- }
- static wasi_errno_t
- wasi_sock_addr_local(wasm_exec_env_t exec_env, wasi_fd_t fd,
- __wasi_addr_t *addr)
- {
- 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 = NULL;
- if (!wasi_ctx)
- return __WASI_EACCES;
- if (!validate_native_addr(addr, (uint64)sizeof(__wasi_addr_t)))
- return __WASI_EINVAL;
- curfds = wasi_ctx_get_curfds(wasi_ctx);
- return wasi_ssp_sock_addr_local(exec_env, curfds, fd, addr);
- }
- static wasi_errno_t
- wasi_sock_addr_remote(wasm_exec_env_t exec_env, wasi_fd_t fd,
- __wasi_addr_t *addr)
- {
- 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 = NULL;
- if (!wasi_ctx)
- return __WASI_EACCES;
- if (!validate_native_addr(addr, (uint64)sizeof(__wasi_addr_t)))
- return __WASI_EINVAL;
- curfds = wasi_ctx_get_curfds(wasi_ctx);
- return wasi_ssp_sock_addr_remote(exec_env, curfds, fd, addr);
- }
- static wasi_errno_t
- wasi_sock_addr_resolve(wasm_exec_env_t exec_env, const char *host,
- const char *service, __wasi_addr_info_hints_t *hints,
- __wasi_addr_info_t *addr_info,
- __wasi_size_t addr_info_size,
- __wasi_size_t *max_info_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 = NULL;
- char **ns_lookup_list = NULL;
- if (!wasi_ctx)
- return __WASI_EACCES;
- if (!validate_native_addr(hints, sizeof(*hints)))
- return __WASI_EINVAL;
- uint64_t addr_info_byte_size = sizeof(*addr_info) * addr_info_size;
- if (addr_info_byte_size / addr_info_size != sizeof(*addr_info))
- return __WASI_EINVAL;
- if (!validate_native_addr(addr_info, addr_info_byte_size))
- return __WASI_EINVAL;
- if (!validate_native_addr(max_info_size, sizeof(*max_info_size)))
- return __WASI_EINVAL;
- curfds = wasi_ctx_get_curfds(wasi_ctx);
- ns_lookup_list = wasi_ctx_get_ns_lookup_list(wasi_ctx);
- return wasi_ssp_sock_addr_resolve(exec_env, curfds, ns_lookup_list, host,
- service, hints, addr_info, addr_info_size,
- max_info_size);
- }
- static wasi_errno_t
- wasi_sock_bind(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_addr_t *addr)
- {
- 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 = NULL;
- struct addr_pool *addr_pool = NULL;
- if (!wasi_ctx)
- return __WASI_EACCES;
- if (!validate_native_addr(addr, sizeof(*addr)))
- return __WASI_EINVAL;
- curfds = wasi_ctx_get_curfds(wasi_ctx);
- addr_pool = wasi_ctx_get_addr_pool(wasi_ctx);
- return wasi_ssp_sock_bind(exec_env, curfds, addr_pool, fd, addr);
- }
- static wasi_errno_t
- wasi_sock_close(wasm_exec_env_t exec_env, wasi_fd_t fd)
- {
- (void)exec_env;
- (void)fd;
- return __WASI_ENOSYS;
- }
- static wasi_errno_t
- wasi_sock_connect(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_addr_t *addr)
- {
- 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 = NULL;
- struct addr_pool *addr_pool = NULL;
- if (!wasi_ctx)
- return __WASI_EACCES;
- if (!validate_native_addr(addr, sizeof(*addr)))
- return __WASI_EINVAL;
- curfds = wasi_ctx_get_curfds(wasi_ctx);
- addr_pool = wasi_ctx_get_addr_pool(wasi_ctx);
- return wasi_ssp_sock_connect(exec_env, curfds, addr_pool, fd, addr);
- }
- static wasi_errno_t
- wasi_sock_get_broadcast(wasm_exec_env_t exec_env, wasi_fd_t fd,
- bool *is_enabled)
- {
- 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 = NULL;
- if (!wasi_ctx)
- return __WASI_EACCES;
- if (!validate_native_addr(is_enabled, (uint64)sizeof(bool)))
- return __WASI_EINVAL;
- curfds = wasi_ctx_get_curfds(wasi_ctx);
- return wasmtime_ssp_sock_get_broadcast(exec_env, curfds, fd, is_enabled);
- }
- static wasi_errno_t
- wasi_sock_get_keep_alive(wasm_exec_env_t exec_env, wasi_fd_t fd,
- bool *is_enabled)
- {
- 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 = NULL;
- if (!wasi_ctx)
- return __WASI_EACCES;
- if (!validate_native_addr(is_enabled, (uint64)sizeof(bool)))
- return __WASI_EINVAL;
- curfds = wasi_ctx_get_curfds(wasi_ctx);
- return wasmtime_ssp_sock_get_keep_alive(exec_env, curfds, fd, is_enabled);
- }
- static wasi_errno_t
- wasi_sock_get_linger(wasm_exec_env_t exec_env, wasi_fd_t fd, bool *is_enabled,
- int *linger_s)
- {
- 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 = NULL;
- if (!wasi_ctx)
- return __WASI_EACCES;
- if (!validate_native_addr(is_enabled, (uint64)sizeof(bool))
- || !validate_native_addr(linger_s, (uint64)sizeof(int)))
- return __WASI_EINVAL;
- curfds = wasi_ctx_get_curfds(wasi_ctx);
- return wasmtime_ssp_sock_get_linger(exec_env, curfds, fd, is_enabled,
- linger_s);
- }
- static wasi_errno_t
- wasi_sock_get_recv_buf_size(wasm_exec_env_t exec_env, wasi_fd_t fd,
- size_t *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 = NULL;
- if (!wasi_ctx)
- return __WASI_EACCES;
- if (!validate_native_addr(size, (uint64)sizeof(wasi_size_t)))
- return __WASI_EINVAL;
- curfds = wasi_ctx_get_curfds(wasi_ctx);
- return wasmtime_ssp_sock_get_recv_buf_size(exec_env, curfds, fd, size);
- }
- static wasi_errno_t
- wasi_sock_get_recv_timeout(wasm_exec_env_t exec_env, wasi_fd_t fd,
- uint64_t *timeout_us)
- {
- 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 = NULL;
- if (!wasi_ctx)
- return __WASI_EACCES;
- if (!validate_native_addr(timeout_us, (uint64)sizeof(uint64_t)))
- return __WASI_EINVAL;
- curfds = wasi_ctx_get_curfds(wasi_ctx);
- return wasmtime_ssp_sock_get_recv_timeout(exec_env, curfds, fd, timeout_us);
- }
- static wasi_errno_t
- wasi_sock_get_reuse_addr(wasm_exec_env_t exec_env, wasi_fd_t fd,
- bool *is_enabled)
- {
- 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 = NULL;
- if (!wasi_ctx)
- return __WASI_EACCES;
- if (!validate_native_addr(is_enabled, (uint64)sizeof(bool)))
- return __WASI_EINVAL;
- curfds = wasi_ctx_get_curfds(wasi_ctx);
- return wasmtime_ssp_sock_get_reuse_addr(exec_env, curfds, fd, is_enabled);
- }
- static wasi_errno_t
- wasi_sock_get_reuse_port(wasm_exec_env_t exec_env, wasi_fd_t fd,
- bool *is_enabled)
- {
- 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 = NULL;
- if (!wasi_ctx)
- return __WASI_EACCES;
- if (!validate_native_addr(is_enabled, (uint64)sizeof(bool)))
- return __WASI_EINVAL;
- curfds = wasi_ctx_get_curfds(wasi_ctx);
- return wasmtime_ssp_sock_get_reuse_port(exec_env, curfds, fd, is_enabled);
- }
- static wasi_errno_t
- wasi_sock_get_send_buf_size(wasm_exec_env_t exec_env, wasi_fd_t fd,
- size_t *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 = NULL;
- if (!wasi_ctx)
- return __WASI_EACCES;
- if (!validate_native_addr(size, (uint64)sizeof(__wasi_size_t)))
- return __WASI_EINVAL;
- curfds = wasi_ctx_get_curfds(wasi_ctx);
- return wasmtime_ssp_sock_get_send_buf_size(exec_env, curfds, fd, size);
- }
- static wasi_errno_t
- wasi_sock_get_send_timeout(wasm_exec_env_t exec_env, wasi_fd_t fd,
- uint64_t *timeout_us)
- {
- 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 = NULL;
- if (!wasi_ctx)
- return __WASI_EACCES;
- if (!validate_native_addr(timeout_us, (uint64)sizeof(uint64_t)))
- return __WASI_EINVAL;
- curfds = wasi_ctx_get_curfds(wasi_ctx);
- return wasmtime_ssp_sock_get_send_timeout(exec_env, curfds, fd, timeout_us);
- }
- static wasi_errno_t
- wasi_sock_get_tcp_fastopen_connect(wasm_exec_env_t exec_env, wasi_fd_t fd,
- bool *is_enabled)
- {
- 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 = NULL;
- if (!wasi_ctx)
- return __WASI_EACCES;
- if (!validate_native_addr(is_enabled, (uint64)sizeof(bool)))
- return __WASI_EINVAL;
- curfds = wasi_ctx_get_curfds(wasi_ctx);
- return wasmtime_ssp_sock_get_tcp_fastopen_connect(exec_env, curfds, fd,
- is_enabled);
- }
- static wasi_errno_t
- wasi_sock_get_tcp_no_delay(wasm_exec_env_t exec_env, wasi_fd_t fd,
- bool *is_enabled)
- {
- 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 = NULL;
- if (!wasi_ctx)
- return __WASI_EACCES;
- if (!validate_native_addr(is_enabled, (uint64)sizeof(bool)))
- return __WASI_EINVAL;
- curfds = wasi_ctx_get_curfds(wasi_ctx);
- return wasmtime_ssp_sock_get_tcp_no_delay(exec_env, curfds, fd, is_enabled);
- }
- static wasi_errno_t
- wasi_sock_get_tcp_quick_ack(wasm_exec_env_t exec_env, wasi_fd_t fd,
- bool *is_enabled)
- {
- 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 = NULL;
- if (!wasi_ctx)
- return __WASI_EACCES;
- if (!validate_native_addr(is_enabled, (uint64)sizeof(bool)))
- return __WASI_EINVAL;
- curfds = wasi_ctx_get_curfds(wasi_ctx);
- return wasmtime_ssp_sock_get_tcp_quick_ack(exec_env, curfds, fd,
- is_enabled);
- }
- static wasi_errno_t
- wasi_sock_get_tcp_keep_idle(wasm_exec_env_t exec_env, wasi_fd_t fd,
- uint32_t *time_s)
- {
- 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 = NULL;
- if (!wasi_ctx)
- return __WASI_EACCES;
- if (!validate_native_addr(time_s, (uint64)sizeof(uint32_t)))
- return __WASI_EINVAL;
- curfds = wasi_ctx_get_curfds(wasi_ctx);
- return wasmtime_ssp_sock_get_tcp_keep_idle(exec_env, curfds, fd, time_s);
- }
- static wasi_errno_t
- wasi_sock_get_tcp_keep_intvl(wasm_exec_env_t exec_env, wasi_fd_t fd,
- uint32_t *time_s)
- {
- 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 = NULL;
- if (!wasi_ctx)
- return __WASI_EACCES;
- if (!validate_native_addr(time_s, (uint64)sizeof(uint32_t)))
- return __WASI_EINVAL;
- curfds = wasi_ctx_get_curfds(wasi_ctx);
- return wasmtime_ssp_sock_get_tcp_keep_intvl(exec_env, curfds, fd, time_s);
- }
- static wasi_errno_t
- wasi_sock_get_ip_multicast_loop(wasm_exec_env_t exec_env, wasi_fd_t fd,
- bool ipv6, bool *is_enabled)
- {
- 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 = NULL;
- if (!wasi_ctx)
- return __WASI_EACCES;
- if (!validate_native_addr(is_enabled, (uint64)sizeof(bool)))
- return __WASI_EINVAL;
- curfds = wasi_ctx_get_curfds(wasi_ctx);
- return wasmtime_ssp_sock_get_ip_multicast_loop(exec_env, curfds, fd, ipv6,
- is_enabled);
- }
- static wasi_errno_t
- wasi_sock_get_ip_ttl(wasm_exec_env_t exec_env, wasi_fd_t fd, uint8_t *ttl_s)
- {
- 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 = NULL;
- if (!wasi_ctx)
- return __WASI_EACCES;
- if (!validate_native_addr(ttl_s, (uint64)sizeof(uint8_t)))
- return __WASI_EINVAL;
- curfds = wasi_ctx_get_curfds(wasi_ctx);
- return wasmtime_ssp_sock_get_ip_ttl(exec_env, curfds, fd, ttl_s);
- }
- static wasi_errno_t
- wasi_sock_get_ip_multicast_ttl(wasm_exec_env_t exec_env, wasi_fd_t fd,
- uint8_t *ttl_s)
- {
- 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 = NULL;
- if (!wasi_ctx)
- return __WASI_EACCES;
- if (!validate_native_addr(ttl_s, (uint64)sizeof(uint8_t)))
- return __WASI_EINVAL;
- curfds = wasi_ctx_get_curfds(wasi_ctx);
- return wasmtime_ssp_sock_get_ip_multicast_ttl(exec_env, curfds, fd, ttl_s);
- }
- static wasi_errno_t
- wasi_sock_get_ipv6_only(wasm_exec_env_t exec_env, wasi_fd_t fd,
- bool *is_enabled)
- {
- 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 = NULL;
- if (!wasi_ctx)
- return __WASI_EACCES;
- if (!validate_native_addr(is_enabled, (uint64)sizeof(bool)))
- return __WASI_EINVAL;
- curfds = wasi_ctx_get_curfds(wasi_ctx);
- return wasmtime_ssp_sock_get_ipv6_only(exec_env, curfds, fd, is_enabled);
- }
- static wasi_errno_t
- wasi_sock_listen(wasm_exec_env_t exec_env, wasi_fd_t fd, uint32 backlog)
- {
- 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 = NULL;
- if (!wasi_ctx)
- return __WASI_EACCES;
- curfds = wasi_ctx_get_curfds(wasi_ctx);
- return wasi_ssp_sock_listen(exec_env, curfds, fd, backlog);
- }
- static wasi_errno_t
- wasi_sock_open(wasm_exec_env_t exec_env, wasi_fd_t poolfd,
- wasi_address_family_t af, wasi_sock_type_t socktype,
- wasi_fd_t *sockfd)
- {
- 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 = NULL;
- if (!wasi_ctx)
- return __WASI_EACCES;
- if (!validate_native_addr(sockfd, sizeof(*sockfd)))
- return __WASI_EINVAL;
- curfds = wasi_ctx_get_curfds(wasi_ctx);
- return wasi_ssp_sock_open(exec_env, curfds, poolfd, af, socktype, sockfd);
- }
- static wasi_errno_t
- wasi_sock_set_broadcast(wasm_exec_env_t exec_env, wasi_fd_t fd, bool is_enabled)
- {
- 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 = NULL;
- if (!wasi_ctx)
- return __WASI_EACCES;
- curfds = wasi_ctx_get_curfds(wasi_ctx);
- return wasmtime_ssp_sock_set_broadcast(exec_env, curfds, fd, is_enabled);
- }
- static wasi_errno_t
- wasi_sock_set_keep_alive(wasm_exec_env_t exec_env, wasi_fd_t fd,
- bool is_enabled)
- {
- 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 = NULL;
- if (!wasi_ctx)
- return __WASI_EACCES;
- curfds = wasi_ctx_get_curfds(wasi_ctx);
- return wasmtime_ssp_sock_set_keep_alive(exec_env, curfds, fd, is_enabled);
- }
- static wasi_errno_t
- wasi_sock_set_linger(wasm_exec_env_t exec_env, wasi_fd_t fd, bool is_enabled,
- int linger_s)
- {
- 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 = NULL;
- if (!wasi_ctx)
- return __WASI_EACCES;
- curfds = wasi_ctx_get_curfds(wasi_ctx);
- return wasmtime_ssp_sock_set_linger(exec_env, curfds, fd, is_enabled,
- linger_s);
- }
- static wasi_errno_t
- wasi_sock_set_recv_buf_size(wasm_exec_env_t exec_env, wasi_fd_t fd, size_t 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 = NULL;
- if (!wasi_ctx)
- return __WASI_EACCES;
- curfds = wasi_ctx_get_curfds(wasi_ctx);
- return wasmtime_ssp_sock_set_recv_buf_size(exec_env, curfds, fd, size);
- }
- static wasi_errno_t
- wasi_sock_set_recv_timeout(wasm_exec_env_t exec_env, wasi_fd_t fd,
- uint64_t timeout_us)
- {
- 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 = NULL;
- if (!wasi_ctx)
- return __WASI_EACCES;
- curfds = wasi_ctx_get_curfds(wasi_ctx);
- return wasmtime_ssp_sock_set_recv_timeout(exec_env, curfds, fd, timeout_us);
- }
- static wasi_errno_t
- wasi_sock_set_reuse_addr(wasm_exec_env_t exec_env, wasi_fd_t fd,
- bool is_enabled)
- {
- 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 = NULL;
- if (!wasi_ctx)
- return __WASI_EACCES;
- curfds = wasi_ctx_get_curfds(wasi_ctx);
- return wasmtime_ssp_sock_set_reuse_addr(exec_env, curfds, fd, is_enabled);
- }
- static wasi_errno_t
- wasi_sock_set_reuse_port(wasm_exec_env_t exec_env, wasi_fd_t fd,
- bool is_enabled)
- {
- 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 = NULL;
- if (!wasi_ctx)
- return __WASI_EACCES;
- curfds = wasi_ctx_get_curfds(wasi_ctx);
- return wasmtime_ssp_sock_set_reuse_port(exec_env, curfds, fd, is_enabled);
- }
- static wasi_errno_t
- wasi_sock_set_send_buf_size(wasm_exec_env_t exec_env, wasi_fd_t fd, size_t 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 = NULL;
- if (!wasi_ctx)
- return __WASI_EACCES;
- curfds = wasi_ctx_get_curfds(wasi_ctx);
- return wasmtime_ssp_sock_set_send_buf_size(exec_env, curfds, fd, size);
- }
- static wasi_errno_t
- wasi_sock_set_send_timeout(wasm_exec_env_t exec_env, wasi_fd_t fd,
- uint64_t timeout_us)
- {
- 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 = NULL;
- if (!wasi_ctx)
- return __WASI_EACCES;
- curfds = wasi_ctx_get_curfds(wasi_ctx);
- return wasmtime_ssp_sock_set_send_timeout(exec_env, curfds, fd, timeout_us);
- }
- static wasi_errno_t
- wasi_sock_set_tcp_fastopen_connect(wasm_exec_env_t exec_env, wasi_fd_t fd,
- bool is_enabled)
- {
- 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 = NULL;
- if (!wasi_ctx)
- return __WASI_EACCES;
- curfds = wasi_ctx_get_curfds(wasi_ctx);
- return wasmtime_ssp_sock_set_tcp_fastopen_connect(exec_env, curfds, fd,
- is_enabled);
- }
- static wasi_errno_t
- wasi_sock_set_tcp_no_delay(wasm_exec_env_t exec_env, wasi_fd_t fd,
- bool is_enabled)
- {
- 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 = NULL;
- if (!wasi_ctx)
- return __WASI_EACCES;
- curfds = wasi_ctx_get_curfds(wasi_ctx);
- return wasmtime_ssp_sock_set_tcp_no_delay(exec_env, curfds, fd, is_enabled);
- }
- static wasi_errno_t
- wasi_sock_set_tcp_quick_ack(wasm_exec_env_t exec_env, wasi_fd_t fd,
- bool is_enabled)
- {
- 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 = NULL;
- if (!wasi_ctx)
- return __WASI_EACCES;
- curfds = wasi_ctx_get_curfds(wasi_ctx);
- return wasmtime_ssp_sock_set_tcp_quick_ack(exec_env, curfds, fd,
- is_enabled);
- }
- static wasi_errno_t
- wasi_sock_set_tcp_keep_idle(wasm_exec_env_t exec_env, wasi_fd_t fd,
- uint32_t time_s)
- {
- 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 = NULL;
- if (!wasi_ctx)
- return __WASI_EACCES;
- curfds = wasi_ctx_get_curfds(wasi_ctx);
- return wasmtime_ssp_sock_set_tcp_keep_idle(exec_env, curfds, fd, time_s);
- }
- static wasi_errno_t
- wasi_sock_set_tcp_keep_intvl(wasm_exec_env_t exec_env, wasi_fd_t fd,
- uint32_t time_s)
- {
- 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 = NULL;
- if (!wasi_ctx)
- return __WASI_EACCES;
- curfds = wasi_ctx_get_curfds(wasi_ctx);
- return wasmtime_ssp_sock_set_tcp_keep_intvl(exec_env, curfds, fd, time_s);
- }
- static wasi_errno_t
- wasi_sock_set_ip_multicast_loop(wasm_exec_env_t exec_env, wasi_fd_t fd,
- bool ipv6, bool is_enabled)
- {
- 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 = NULL;
- if (!wasi_ctx)
- return __WASI_EACCES;
- curfds = wasi_ctx_get_curfds(wasi_ctx);
- return wasmtime_ssp_sock_set_ip_multicast_loop(exec_env, curfds, fd, ipv6,
- is_enabled);
- }
- static wasi_errno_t
- wasi_sock_set_ip_add_membership(wasm_exec_env_t exec_env, wasi_fd_t fd,
- __wasi_addr_ip_t *imr_multiaddr,
- uint32_t imr_interface)
- {
- 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 = NULL;
- if (!wasi_ctx)
- return __WASI_EACCES;
- if (!validate_native_addr(imr_multiaddr, (uint64)sizeof(__wasi_addr_ip_t)))
- return __WASI_EINVAL;
- curfds = wasi_ctx_get_curfds(wasi_ctx);
- return wasmtime_ssp_sock_set_ip_add_membership(
- exec_env, curfds, fd, imr_multiaddr, imr_interface);
- }
- static wasi_errno_t
- wasi_sock_set_ip_drop_membership(wasm_exec_env_t exec_env, wasi_fd_t fd,
- __wasi_addr_ip_t *imr_multiaddr,
- uint32_t imr_interface)
- {
- 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 = NULL;
- if (!wasi_ctx)
- return __WASI_EACCES;
- if (!validate_native_addr(imr_multiaddr, (uint64)sizeof(__wasi_addr_ip_t)))
- return __WASI_EINVAL;
- curfds = wasi_ctx_get_curfds(wasi_ctx);
- return wasmtime_ssp_sock_set_ip_drop_membership(
- exec_env, curfds, fd, imr_multiaddr, imr_interface);
- }
- static wasi_errno_t
- wasi_sock_set_ip_ttl(wasm_exec_env_t exec_env, wasi_fd_t fd, uint8_t ttl_s)
- {
- 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 = NULL;
- if (!wasi_ctx)
- return __WASI_EACCES;
- curfds = wasi_ctx_get_curfds(wasi_ctx);
- return wasmtime_ssp_sock_set_ip_ttl(exec_env, curfds, fd, ttl_s);
- }
- static wasi_errno_t
- wasi_sock_set_ip_multicast_ttl(wasm_exec_env_t exec_env, wasi_fd_t fd,
- uint8_t ttl_s)
- {
- 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 = NULL;
- if (!wasi_ctx)
- return __WASI_EACCES;
- curfds = wasi_ctx_get_curfds(wasi_ctx);
- return wasmtime_ssp_sock_set_ip_multicast_ttl(exec_env, curfds, fd, ttl_s);
- }
- static wasi_errno_t
- wasi_sock_set_ipv6_only(wasm_exec_env_t exec_env, wasi_fd_t fd, bool is_enabled)
- {
- 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 = NULL;
- if (!wasi_ctx)
- return __WASI_EACCES;
- curfds = wasi_ctx_get_curfds(wasi_ctx);
- return wasmtime_ssp_sock_set_ipv6_only(exec_env, curfds, fd, is_enabled);
- }
- static wasi_errno_t
- allocate_iovec_app_buffer(wasm_module_inst_t module_inst,
- const iovec_app_t *data, uint32 data_len,
- uint8 **buf_ptr, uint64 *buf_len)
- {
- uint64 total_size = 0;
- uint32 i;
- uint8 *buf_begin = NULL;
- if (data_len == 0) {
- return __WASI_EINVAL;
- }
- total_size = sizeof(iovec_app_t) * (uint64)data_len;
- if (total_size >= UINT32_MAX
- || !validate_native_addr((void *)data, total_size))
- return __WASI_EINVAL;
- for (total_size = 0, i = 0; i < data_len; i++, data++) {
- total_size += data->buf_len;
- }
- if (total_size == 0) {
- return __WASI_EINVAL;
- }
- if (total_size >= UINT32_MAX
- || !(buf_begin = wasm_runtime_malloc((uint32)total_size))) {
- return __WASI_ENOMEM;
- }
- *buf_len = total_size;
- *buf_ptr = buf_begin;
- return __WASI_ESUCCESS;
- }
- static wasi_errno_t
- copy_buffer_to_iovec_app(wasm_module_inst_t module_inst, uint8 *buf_begin,
- uint32 buf_size, iovec_app_t *data, uint32 data_len,
- uint32 size_to_copy)
- {
- uint8 *buf = buf_begin;
- uint32 i;
- uint32 size_to_copy_into_iovec;
- if (buf_size < size_to_copy) {
- return __WASI_EINVAL;
- }
- for (i = 0; i < data_len; data++, i++) {
- char *native_addr;
- if (!validate_app_addr((uint64)data->buf_offset,
- (uint64)data->buf_len)) {
- return __WASI_EINVAL;
- }
- if (buf >= buf_begin + buf_size
- /* integer overflow */
- || data->buf_len > UINTPTR_MAX - (uintptr_t)buf
- || buf + data->buf_len > buf_begin + buf_size
- || size_to_copy == 0) {
- break;
- }
- /**
- * If our app buffer size is smaller than the amount to be copied,
- * only copy the amount in the app buffer. Otherwise, we fill the iovec
- * buffer and reduce size to copy on the next iteration
- */
- size_to_copy_into_iovec = min_uint32(data->buf_len, size_to_copy);
- native_addr = (void *)addr_app_to_native((uint64)data->buf_offset);
- bh_memcpy_s(native_addr, size_to_copy_into_iovec, buf,
- size_to_copy_into_iovec);
- buf += size_to_copy_into_iovec;
- size_to_copy -= size_to_copy_into_iovec;
- }
- return __WASI_ESUCCESS;
- }
- static wasi_errno_t
- wasi_sock_recv_from(wasm_exec_env_t exec_env, wasi_fd_t sock,
- iovec_app_t *ri_data, uint32 ri_data_len,
- wasi_riflags_t ri_flags, __wasi_addr_t *src_addr,
- uint32 *ro_data_len)
- {
- /**
- * ri_data_len is the length of a list of iovec_app_t, which head is
- * ri_data. ro_data_len is the number of bytes received
- **/
- 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(wasi_ctx);
- uint64 total_size;
- uint8 *buf_begin = NULL;
- wasi_errno_t err;
- size_t recv_bytes = 0;
- if (!wasi_ctx) {
- return __WASI_EINVAL;
- }
- /* note: src_addr is NULL when called by wasi_sock_recv */
- if (src_addr != NULL && !validate_native_addr(src_addr, sizeof(*src_addr)))
- return __WASI_EINVAL;
- if (!validate_native_addr(ro_data_len, (uint64)sizeof(uint32)))
- return __WASI_EINVAL;
- err = allocate_iovec_app_buffer(module_inst, ri_data, ri_data_len,
- &buf_begin, &total_size);
- if (err != __WASI_ESUCCESS) {
- goto fail;
- }
- memset(buf_begin, 0, total_size);
- *ro_data_len = 0;
- err = wasmtime_ssp_sock_recv_from(exec_env, curfds, sock, buf_begin,
- total_size, ri_flags, src_addr,
- &recv_bytes);
- if (err != __WASI_ESUCCESS) {
- goto fail;
- }
- *ro_data_len = (uint32)recv_bytes;
- err = copy_buffer_to_iovec_app(module_inst, buf_begin, (uint32)total_size,
- ri_data, ri_data_len, (uint32)recv_bytes);
- fail:
- if (buf_begin) {
- wasm_runtime_free(buf_begin);
- }
- return err;
- }
- 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_data_len,
- wasi_roflags_t *ro_flags)
- {
- wasm_module_inst_t module_inst = get_module_inst(exec_env);
- wasi_errno_t error;
- if (!validate_native_addr(ro_data_len, sizeof(*ro_data_len)))
- return __WASI_EINVAL;
- if (!validate_native_addr(ro_flags, (uint64)sizeof(wasi_roflags_t)))
- return __WASI_EINVAL;
- // We call `recvfrom` with NULL source address as `recv` doesn't
- // return the source address and this parameter is not used.
- *ro_data_len = 0;
- error = wasi_sock_recv_from(exec_env, sock, ri_data, ri_data_len, ri_flags,
- NULL, ro_data_len);
- return error;
- }
- static wasi_errno_t
- convert_iovec_app_to_buffer(wasm_module_inst_t module_inst,
- const iovec_app_t *si_data, uint32 si_data_len,
- uint8 **buf_ptr, uint64 *buf_len)
- {
- uint32 i;
- const iovec_app_t *si_data_orig = si_data;
- uint8 *buf = NULL;
- wasi_errno_t error;
- error = allocate_iovec_app_buffer(module_inst, si_data, si_data_len,
- buf_ptr, buf_len);
- if (error != __WASI_ESUCCESS) {
- return error;
- }
- buf = *buf_ptr;
- si_data = si_data_orig;
- for (i = 0; i < si_data_len; i++, si_data++) {
- char *native_addr;
- if (!validate_app_addr((uint64)si_data->buf_offset,
- (uint64)si_data->buf_len)) {
- wasm_runtime_free(*buf_ptr);
- return __WASI_EINVAL;
- }
- native_addr = (char *)addr_app_to_native((uint64)si_data->buf_offset);
- bh_memcpy_s(buf, si_data->buf_len, native_addr, si_data->buf_len);
- buf += si_data->buf_len;
- }
- return __WASI_ESUCCESS;
- }
- 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_data_len)
- {
- /**
- * si_data_len is the length of a list of iovec_app_t, which head is
- * si_data. so_data_len is the number of bytes sent
- **/
- 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(wasi_ctx);
- uint64 buf_size = 0;
- uint8 *buf = NULL;
- wasi_errno_t err;
- size_t send_bytes = 0;
- if (!wasi_ctx) {
- return __WASI_EINVAL;
- }
- if (!validate_native_addr(so_data_len, (uint64)sizeof(uint32)))
- return __WASI_EINVAL;
- err = convert_iovec_app_to_buffer(module_inst, si_data, si_data_len, &buf,
- &buf_size);
- if (err != __WASI_ESUCCESS)
- return err;
- *so_data_len = 0;
- err = wasmtime_ssp_sock_send(exec_env, curfds, sock, buf, buf_size,
- &send_bytes);
- *so_data_len = (uint32)send_bytes;
- wasm_runtime_free(buf);
- return err;
- }
- static wasi_errno_t
- wasi_sock_send_to(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, const __wasi_addr_t *dest_addr,
- uint32 *so_data_len)
- {
- /**
- * si_data_len is the length of a list of iovec_app_t, which head is
- * si_data. so_data_len is the number of bytes sent
- **/
- 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(wasi_ctx);
- uint64 buf_size = 0;
- uint8 *buf = NULL;
- wasi_errno_t err;
- size_t send_bytes = 0;
- struct addr_pool *addr_pool = wasi_ctx_get_addr_pool(wasi_ctx);
- if (!wasi_ctx) {
- return __WASI_EINVAL;
- }
- if (!validate_native_addr((void *)dest_addr, sizeof(*dest_addr)))
- return __WASI_EINVAL;
- if (!validate_native_addr(so_data_len, (uint64)sizeof(uint32)))
- return __WASI_EINVAL;
- err = convert_iovec_app_to_buffer(module_inst, si_data, si_data_len, &buf,
- &buf_size);
- if (err != __WASI_ESUCCESS)
- return err;
- *so_data_len = 0;
- err = wasmtime_ssp_sock_send_to(exec_env, curfds, addr_pool, sock, buf,
- buf_size, si_flags, dest_addr, &send_bytes);
- *so_data_len = (uint32)send_bytes;
- wasm_runtime_free(buf);
- 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(wasi_ctx);
- if (!wasi_ctx)
- return __WASI_EINVAL;
- return wasmtime_ssp_sock_shutdown(exec_env, curfds, sock);
- }
- static wasi_errno_t
- wasi_sched_yield(wasm_exec_env_t exec_env)
- {
- (void)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_accept, "(ii*)i"),
- REG_NATIVE_FUNC(sock_addr_local, "(i*)i"),
- REG_NATIVE_FUNC(sock_addr_remote, "(i*)i"),
- REG_NATIVE_FUNC(sock_addr_resolve, "($$**i*)i"),
- REG_NATIVE_FUNC(sock_bind, "(i*)i"),
- REG_NATIVE_FUNC(sock_close, "(i)i"),
- REG_NATIVE_FUNC(sock_connect, "(i*)i"),
- REG_NATIVE_FUNC(sock_get_broadcast, "(i*)i"),
- REG_NATIVE_FUNC(sock_get_keep_alive, "(i*)i"),
- REG_NATIVE_FUNC(sock_get_linger, "(i**)i"),
- REG_NATIVE_FUNC(sock_get_recv_buf_size, "(i*)i"),
- REG_NATIVE_FUNC(sock_get_recv_timeout, "(i*)i"),
- REG_NATIVE_FUNC(sock_get_reuse_addr, "(i*)i"),
- REG_NATIVE_FUNC(sock_get_reuse_port, "(i*)i"),
- REG_NATIVE_FUNC(sock_get_send_buf_size, "(i*)i"),
- REG_NATIVE_FUNC(sock_get_send_timeout, "(i*)i"),
- REG_NATIVE_FUNC(sock_get_tcp_fastopen_connect, "(i*)i"),
- REG_NATIVE_FUNC(sock_get_tcp_keep_idle, "(i*)i"),
- REG_NATIVE_FUNC(sock_get_tcp_keep_intvl, "(i*)i"),
- REG_NATIVE_FUNC(sock_get_tcp_no_delay, "(i*)i"),
- REG_NATIVE_FUNC(sock_get_tcp_quick_ack, "(i*)i"),
- REG_NATIVE_FUNC(sock_get_ip_multicast_loop, "(ii*)i"),
- REG_NATIVE_FUNC(sock_get_ip_multicast_ttl, "(i*)i"),
- REG_NATIVE_FUNC(sock_get_ip_ttl, "(i*)i"),
- REG_NATIVE_FUNC(sock_get_ipv6_only, "(i*)i"),
- REG_NATIVE_FUNC(sock_listen, "(ii)i"),
- REG_NATIVE_FUNC(sock_open, "(iii*)i"),
- REG_NATIVE_FUNC(sock_recv, "(i*ii**)i"),
- REG_NATIVE_FUNC(sock_recv_from, "(i*ii**)i"),
- REG_NATIVE_FUNC(sock_send, "(i*ii*)i"),
- REG_NATIVE_FUNC(sock_send_to, "(i*ii**)i"),
- REG_NATIVE_FUNC(sock_set_broadcast, "(ii)i"),
- REG_NATIVE_FUNC(sock_set_keep_alive, "(ii)i"),
- REG_NATIVE_FUNC(sock_set_linger, "(iii)i"),
- REG_NATIVE_FUNC(sock_set_recv_buf_size, "(ii)i"),
- REG_NATIVE_FUNC(sock_set_recv_timeout, "(iI)i"),
- REG_NATIVE_FUNC(sock_set_reuse_addr, "(ii)i"),
- REG_NATIVE_FUNC(sock_set_reuse_port, "(ii)i"),
- REG_NATIVE_FUNC(sock_set_send_buf_size, "(ii)i"),
- REG_NATIVE_FUNC(sock_set_send_timeout, "(iI)i"),
- REG_NATIVE_FUNC(sock_set_tcp_fastopen_connect, "(ii)i"),
- REG_NATIVE_FUNC(sock_set_tcp_keep_idle, "(ii)i"),
- REG_NATIVE_FUNC(sock_set_tcp_keep_intvl, "(ii)i"),
- REG_NATIVE_FUNC(sock_set_tcp_no_delay, "(ii)i"),
- REG_NATIVE_FUNC(sock_set_tcp_quick_ack, "(ii)i"),
- REG_NATIVE_FUNC(sock_set_ip_multicast_loop, "(iii)i"),
- REG_NATIVE_FUNC(sock_set_ip_multicast_ttl, "(ii)i"),
- REG_NATIVE_FUNC(sock_set_ip_add_membership, "(i*i)i"),
- REG_NATIVE_FUNC(sock_set_ip_drop_membership, "(i*i)i"),
- REG_NATIVE_FUNC(sock_set_ip_ttl, "(ii)i"),
- REG_NATIVE_FUNC(sock_set_ipv6_only, "(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);
- }
|