Wasmtime
wasi.h File Reference
#include "wasm.h"
#include <stdint.h>
#include <wasmtime/conf.h>

Go to the source code of this file.

Typedefs

typedef struct wasi_config_t wasi_config_t
 Convenience alias for wasi_config_t.
 
typedef size_t wasi_file_perms
 The max permissions granted a file within a preopened directory, which is a bitmask with flag values from wasi_file_perms_flags.
 

Functions

void wasi_config_delete (wasi_config_t *)
 Deletes a configuration object.
 
wasi_config_twasi_config_new ()
 Creates a new empty configuration object. More...
 
void wasi_config_inherit_network (wasi_config_t *config)
 Allow all network addresses accessible to the host. More...
 
void wasi_config_allow_ip_name_lookup (wasi_config_t *config, bool enable)
 Allow usage of wasi:sockets/ip-name-lookup More...
 
bool wasi_config_set_argv (wasi_config_t *config, size_t argc, const char *argv[])
 Sets the argv list for this configuration object. More...
 
void wasi_config_inherit_argv (wasi_config_t *config)
 Indicates that the argv list should be inherited from this process's argv list.
 
bool wasi_config_set_env (wasi_config_t *config, size_t envc, const char *names[], const char *values[])
 Sets the list of environment variables available to the WASI instance. More...
 
void wasi_config_inherit_env (wasi_config_t *config)
 Indicates that the entire environment of the calling process should be inherited by this WASI configuration.
 
bool wasi_config_set_stdin_file (wasi_config_t *config, const char *path)
 Configures standard input to be taken from the specified file. More...
 
void wasi_config_set_stdin_bytes (wasi_config_t *config, wasm_byte_vec_t *binary)
 Configures standard input to be taken from the specified wasm_byte_vec_t. More...
 
void wasi_config_inherit_stdin (wasi_config_t *config)
 Configures this process's own stdin stream to be used as stdin for this WASI configuration.
 
bool wasi_config_set_stdout_file (wasi_config_t *config, const char *path)
 Configures standard output to be written to the specified file. More...
 
void wasi_config_inherit_stdout (wasi_config_t *config)
 Configures this process's own stdout stream to be used as stdout for this WASI configuration.
 
void wasi_config_set_stdout_custom (wasi_config_t *config, ptrdiff_t(*callback)(void *, const unsigned char *, size_t), void *data, void(*finalizer)(void *))
 Configures standard output to be directed to callback. More...
 
bool wasi_config_set_stderr_file (wasi_config_t *config, const char *path)
 Configures standard output to be written to the specified file. More...
 
void wasi_config_inherit_stderr (wasi_config_t *config)
 Configures this process's own stderr stream to be used as stderr for this WASI configuration.
 
void wasi_config_set_stderr_custom (wasi_config_t *config, ptrdiff_t(*callback)(void *, const unsigned char *, size_t), void *data, void(*finalizer)(void *))
 Configures standard error output to be directed to callback. More...
 
bool wasi_config_preopen_dir (wasi_config_t *config, const char *host_path, const char *guest_path, bool fs_mutable)
 Configures a "preopened directory" to be available to WASI APIs. More...
 

Detailed Description

C API for WASI

Function Documentation

◆ wasi_config_allow_ip_name_lookup()

void wasi_config_allow_ip_name_lookup ( wasi_config_t config,
bool  enable 
)

Allow usage of wasi:sockets/ip-name-lookup

By default this is disabled.

◆ wasi_config_inherit_network()

void wasi_config_inherit_network ( wasi_config_t config)

Allow all network addresses accessible to the host.

This method will inherit all network addresses meaning that any address can be bound by the guest or connected to by the guest using any protocol.

◆ wasi_config_new()

wasi_config_t * wasi_config_new ( )

Creates a new empty configuration object.

The caller is expected to deallocate the returned configuration

◆ wasi_config_preopen_dir()

bool wasi_config_preopen_dir ( wasi_config_t config,
const char *  host_path,
const char *  guest_path,
bool  fs_mutable 
)

Configures a "preopened directory" to be available to WASI APIs.

By default WASI programs do not have access to anything on the filesystem. This API can be used to grant WASI programs access to a directory on the filesystem, but only that directory (its whole contents but nothing above it).

The host_path argument here is a path name on the host filesystem, and guest_path is the name by which it will be known in wasm.

The fs_mutable argument is the permissions that wasm will have to operate on guest_path. If true, operations that mutate the filesystem will be permitted under that path. If false, only read operations will be permitted on under that path.

◆ wasi_config_set_argv()

bool wasi_config_set_argv ( wasi_config_t config,
size_t  argc,
const char *  argv[] 
)

Sets the argv list for this configuration object.

By default WASI programs have an empty argv list, but this can be used to explicitly specify what the argv list for the program is.

The arguments are copied into the config object as part of this function call, so the argv pointer only needs to stay alive for this function call.

This function returns true if all arguments were registered successfully, or false if an argument was not valid UTF-8.

◆ wasi_config_set_env()

bool wasi_config_set_env ( wasi_config_t config,
size_t  envc,
const char *  names[],
const char *  values[] 
)

Sets the list of environment variables available to the WASI instance.

By default WASI programs have a blank environment, but this can be used to define some environment variables for them.

It is required that the names and values lists both have envc entries.

The env vars are copied into the config object as part of this function call, so the names and values pointers only need to stay alive for this function call.

This function returns true if all environment variables were successfully registered. This returns false if environment variables are not valid UTF-8.

◆ wasi_config_set_stderr_custom()

void wasi_config_set_stderr_custom ( wasi_config_t config,
ptrdiff_t(*)(void *, const unsigned char *, size_t)  callback,
void *  data,
void(*)(void *)  finalizer 
)

Configures standard error output to be directed to callback.

Parameters
configThe config to operate on
callbackA non-null callback must be provided, that will get called for each write with the buffer. A positive return value indicates the amount of bytes written. Negative return values are treated as OS error codes.
dataAn optional user provided data that will be passed to callback
finalizerAn optional callback to be called to destroy data

◆ wasi_config_set_stderr_file()

bool wasi_config_set_stderr_file ( wasi_config_t config,
const char *  path 
)

Configures standard output to be written to the specified file.

By default WASI programs have no stderr, but this configures the specified file to be used as stderr.

If the stderr location could not be opened for writing then false is returned. Otherwise true is returned.

◆ wasi_config_set_stdin_bytes()

void wasi_config_set_stdin_bytes ( wasi_config_t config,
wasm_byte_vec_t binary 
)

Configures standard input to be taken from the specified wasm_byte_vec_t.

By default WASI programs have no stdin, but this configures the specified bytes to be used as stdin for this configuration.

This function takes ownership of the binary argument.

◆ wasi_config_set_stdin_file()

bool wasi_config_set_stdin_file ( wasi_config_t config,
const char *  path 
)

Configures standard input to be taken from the specified file.

By default WASI programs have no stdin, but this configures the specified file to be used as stdin for this configuration.

If the stdin location does not exist or it cannot be opened for reading then false is returned. Otherwise true is returned.

◆ wasi_config_set_stdout_custom()

void wasi_config_set_stdout_custom ( wasi_config_t config,
ptrdiff_t(*)(void *, const unsigned char *, size_t)  callback,
void *  data,
void(*)(void *)  finalizer 
)

Configures standard output to be directed to callback.

Parameters
configThe config to operate on
callbackA non-null callback must be provided, that will get called for each write with the buffer. A positive return value indicates the amount of bytes written. Negative return values are treated as OS error codes.
dataAn optional user provided data that will be passed to callback
finalizerAn optional callback to be called to destroy data

◆ wasi_config_set_stdout_file()

bool wasi_config_set_stdout_file ( wasi_config_t config,
const char *  path 
)

Configures standard output to be written to the specified file.

By default WASI programs have no stdout, but this configures the specified file to be used as stdout.

If the stdout location could not be opened for writing then false is returned. Otherwise true is returned.