/**1* \file wasi.h2*3* C API for WASI4*/56#ifndef WASI_H7#define WASI_H89#include "wasm.h"10#include <stdint.h>11#include <wasmtime/conf.h>1213#ifdef WASMTIME_FEATURE_WASI1415#ifndef WASI_API_EXTERN16#ifdef _WIN3217#define WASI_API_EXTERN __declspec(dllimport)18#else19#define WASI_API_EXTERN20#endif21#endif2223#ifdef __cplusplus24extern "C" {25#endif2627#define own2829#define WASI_DECLARE_OWN(name) \30typedef struct wasi_##name##_t wasi_##name##_t; \31WASI_API_EXTERN void wasi_##name##_delete(own wasi_##name##_t *);3233/**34* \typedef wasi_config_t35* \brief Convenience alias for #wasi_config_t36*37* \struct wasi_config_t38* \brief TODO39*40* \fn void wasi_config_delete(wasi_config_t *);41* \brief Deletes a configuration object.42*/43WASI_DECLARE_OWN(config)4445/**46* \brief Creates a new empty configuration object.47*48* The caller is expected to deallocate the returned configuration49*/50WASI_API_EXTERN own wasi_config_t *wasi_config_new();5152/**53* \brief Sets the argv list for this configuration object.54*55* By default WASI programs have an empty argv list, but this can be used to56* explicitly specify what the argv list for the program is.57*58* The arguments are copied into the `config` object as part of this function59* call, so the `argv` pointer only needs to stay alive for this function call.60*61* This function returns `true` if all arguments were registered successfully,62* or `false` if an argument was not valid UTF-8.63*/64WASI_API_EXTERN bool wasi_config_set_argv(wasi_config_t *config, size_t argc,65const char *argv[]);6667/**68* \brief Indicates that the argv list should be inherited from this process's69* argv list.70*/71WASI_API_EXTERN void wasi_config_inherit_argv(wasi_config_t *config);7273/**74* \brief Sets the list of environment variables available to the WASI instance.75*76* By default WASI programs have a blank environment, but this can be used to77* define some environment variables for them.78*79* It is required that the `names` and `values` lists both have `envc` entries.80*81* The env vars are copied into the `config` object as part of this function82* call, so the `names` and `values` pointers only need to stay alive for this83* function call.84*85* This function returns `true` if all environment variables were successfully86* registered. This returns `false` if environment variables are not valid87* UTF-8.88*/89WASI_API_EXTERN bool wasi_config_set_env(wasi_config_t *config, size_t envc,90const char *names[],91const char *values[]);9293/**94* \brief Indicates that the entire environment of the calling process should be95* inherited by this WASI configuration.96*/97WASI_API_EXTERN void wasi_config_inherit_env(wasi_config_t *config);9899/**100* \brief Configures standard input to be taken from the specified file.101*102* By default WASI programs have no stdin, but this configures the specified103* file to be used as stdin for this configuration.104*105* If the stdin location does not exist or it cannot be opened for reading then106* `false` is returned. Otherwise `true` is returned.107*/108WASI_API_EXTERN bool wasi_config_set_stdin_file(wasi_config_t *config,109const char *path);110111/**112* \brief Configures standard input to be taken from the specified113* #wasm_byte_vec_t.114*115* By default WASI programs have no stdin, but this configures the specified116* bytes to be used as stdin for this configuration.117*118* This function takes ownership of the `binary` argument.119*/120WASI_API_EXTERN void wasi_config_set_stdin_bytes(wasi_config_t *config,121wasm_byte_vec_t *binary);122123/**124* \brief Configures this process's own stdin stream to be used as stdin for125* this WASI configuration.126*/127WASI_API_EXTERN void wasi_config_inherit_stdin(wasi_config_t *config);128129/**130* \brief Configures standard output to be written to the specified file.131*132* By default WASI programs have no stdout, but this configures the specified133* file to be used as stdout.134*135* If the stdout location could not be opened for writing then `false` is136* returned. Otherwise `true` is returned.137*/138WASI_API_EXTERN bool wasi_config_set_stdout_file(wasi_config_t *config,139const char *path);140141/**142* \brief Configures this process's own stdout stream to be used as stdout for143* this WASI configuration.144*/145WASI_API_EXTERN void wasi_config_inherit_stdout(wasi_config_t *config);146147/**148* \brief Configures standard output to be written to the specified file.149*150* By default WASI programs have no stderr, but this configures the specified151* file to be used as stderr.152*153* If the stderr location could not be opened for writing then `false` is154* returned. Otherwise `true` is returned.155*/156WASI_API_EXTERN bool wasi_config_set_stderr_file(wasi_config_t *config,157const char *path);158159/**160* \brief Configures this process's own stderr stream to be used as stderr for161* this WASI configuration.162*/163WASI_API_EXTERN void wasi_config_inherit_stderr(wasi_config_t *config);164165/**166* \brief The permissions granted for a directory when preopening it.167*/168enum wasi_dir_perms_flags {169/**170* \brief This directory can be read, for example its entries can be iterated171*/172WASMTIME_WASI_DIR_PERMS_READ = 1,173174/**175* \brief This directory can be written to, for example new files can be176* created within it.177*/178WASMTIME_WASI_DIR_PERMS_WRITE = 2,179};180181/**182* \brief The permissions granted for directories when preopening them,183* which is a bitmask with flag values from wasi_dir_perms_flags.184*/185typedef size_t wasi_dir_perms;186187/**188* \brief The permissions granted for files when preopening a directory.189*/190enum wasi_file_perms_flags {191/**192* \brief Files can be read.193*/194WASMTIME_WASI_FILE_PERMS_READ = 1,195196/**197* \brief Files can be written to.198*/199WASMTIME_WASI_FILE_PERMS_WRITE = 2,200};201202/**203* \brief The max permissions granted a file within a preopened directory,204* which is a bitmask with flag values from wasi_file_perms_flags.205*/206typedef size_t wasi_file_perms;207208/**209* \brief Configures a "preopened directory" to be available to WASI APIs.210*211* By default WASI programs do not have access to anything on the filesystem.212* This API can be used to grant WASI programs access to a directory on the213* filesystem, but only that directory (its whole contents but nothing above214* it).215*216* The `host_path` argument here is a path name on the host filesystem, and217* `guest_path` is the name by which it will be known in wasm.218*219* The `dir_perms` argument is the permissions that wasm will have to operate on220* `guest_path`. This can be used, for example, to provide readonly access to a221* directory. This argument is a bitmask with the following flag values:222* - WASMTIME_WASI_DIR_PERMS_READ223* - WASMTIME_WASI_DIR_PERMS_WRITE224*225* The `file_perms` argument is similar to `dir_perms` but corresponds to the226* maximum set of permissions that can be used for any file in this directory.227* This argument is a bitmask with the following flag values:228* - WASMTIME_WASI_FILE_PERMS_READ229* - WASMTIME_WASI_FILE_PERMS_WRITE230*/231WASI_API_EXTERN bool wasi_config_preopen_dir(wasi_config_t *config,232const char *host_path,233const char *guest_path,234wasi_dir_perms dir_perms,235wasi_file_perms file_perms);236237#undef own238239#ifdef __cplusplus240} // extern "C"241#endif242243#endif // WASMTIME_FEATURE_WASI244245#endif // #ifdef WASI_H246247248