Wasmtime
wasi.h
Go to the documentation of this file.
1
7#ifndef WASI_H
8#define WASI_H
9
10#include "wasm.h"
11#include <stdint.h>
12#include <wasmtime/conf.h>
13
14#ifdef WASMTIME_FEATURE_WASI
15
16#ifndef WASI_API_EXTERN
17#ifdef _WIN32
18#define WASI_API_EXTERN __declspec(dllimport)
19#else
20#define WASI_API_EXTERN
21#endif
22#endif
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28#define own
29
30#define WASI_DECLARE_OWN(name) \
31 typedef struct wasi_##name##_t wasi_##name##_t; \
32 WASI_API_EXTERN void wasi_##name##_delete(own wasi_##name##_t *);
33
44WASI_DECLARE_OWN(config)
45
46
51WASI_API_EXTERN own wasi_config_t *wasi_config_new();
52
60WASI_API_EXTERN void wasi_config_inherit_network(wasi_config_t *config);
61
68 bool enable);
69
82WASI_API_EXTERN bool wasi_config_set_argv(wasi_config_t *config, size_t argc,
83 const char *argv[]);
84
89WASI_API_EXTERN void wasi_config_inherit_argv(wasi_config_t *config);
90
107WASI_API_EXTERN bool wasi_config_set_env(wasi_config_t *config, size_t envc,
108 const char *names[],
109 const char *values[]);
110
115WASI_API_EXTERN void wasi_config_inherit_env(wasi_config_t *config);
116
126WASI_API_EXTERN bool wasi_config_set_stdin_file(wasi_config_t *config,
127 const char *path);
128
138WASI_API_EXTERN void wasi_config_set_stdin_bytes(wasi_config_t *config,
139 wasm_byte_vec_t *binary);
140
145WASI_API_EXTERN void wasi_config_inherit_stdin(wasi_config_t *config);
146
156WASI_API_EXTERN bool wasi_config_set_stdout_file(wasi_config_t *config,
157 const char *path);
158
163WASI_API_EXTERN void wasi_config_inherit_stdout(wasi_config_t *config);
164
175WASI_API_EXTERN void wasi_config_set_stdout_custom(
176 wasi_config_t *config,
177 ptrdiff_t (*callback)(void *, const unsigned char *, size_t), void *data,
178 void (*finalizer)(void *));
179
189WASI_API_EXTERN bool wasi_config_set_stderr_file(wasi_config_t *config,
190 const char *path);
191
196WASI_API_EXTERN void wasi_config_inherit_stderr(wasi_config_t *config);
197
208WASI_API_EXTERN void wasi_config_set_stderr_custom(
209 wasi_config_t *config,
210 ptrdiff_t (*callback)(void *, const unsigned char *, size_t), void *data,
211 void (*finalizer)(void *));
212
221
227};
228
233typedef size_t wasi_dir_perms;
234
243
248};
249
254typedef size_t wasi_file_perms;
255
279WASI_API_EXTERN bool wasi_config_preopen_dir(wasi_config_t *config,
280 const char *host_path,
281 const char *guest_path,
282 wasi_dir_perms dir_perms,
283 wasi_file_perms file_perms);
284
285#undef own
286
287#ifdef __cplusplus
288} // extern "C"
289#endif
290
291#endif // WASMTIME_FEATURE_WASI
292
293#endif // #ifdef WASI_H
Build-time defines for how the C API was built.
A list of bytes.
Definition: wasm.h:102
void wasi_config_inherit_env(wasi_config_t *config)
Indicates that the entire environment of the calling process should be inherited by this WASI configu...
size_t wasi_dir_perms
The permissions granted for directories when preopening them, which is a bitmask with flag values fro...
Definition: wasi.h:233
void wasi_config_inherit_argv(wasi_config_t *config)
Indicates that the argv list should be inherited from this process's argv list.
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.
bool wasi_config_set_stdout_file(wasi_config_t *config, const char *path)
Configures standard output to be written to the specified file.
void wasi_config_inherit_network(wasi_config_t *config)
Allow all network addresses accessible to the host.
wasi_dir_perms_flags
The permissions granted for a directory when preopening it.
Definition: wasi.h:216
@ WASMTIME_WASI_DIR_PERMS_WRITE
This directory can be written to, for example new files can be created within it.
Definition: wasi.h:226
@ WASMTIME_WASI_DIR_PERMS_READ
This directory can be read, for example its entries can be iterated.
Definition: wasi.h:220
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.
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.
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.
wasi_file_perms_flags
The permissions granted for files when preopening a directory.
Definition: wasi.h:238
@ WASMTIME_WASI_FILE_PERMS_WRITE
Files can be written to.
Definition: wasi.h:247
@ WASMTIME_WASI_FILE_PERMS_READ
Files can be read.
Definition: wasi.h:242
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.
bool wasi_config_set_argv(wasi_config_t *config, size_t argc, const char *argv[])
Sets the argv list for this configuration object.
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.
bool wasi_config_set_stderr_file(wasi_config_t *config, const char *path)
Configures standard output to be written to the specified file.
void wasi_config_allow_ip_name_lookup(wasi_config_t *config, bool enable)
Allow usage of wasi:sockets/ip-name-lookup
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.
size_t wasi_file_perms
The max permissions granted a file within a preopened directory, which is a bitmask with flag values ...
Definition: wasi.h:254
bool wasi_config_set_stdin_file(wasi_config_t *config, const char *path)
Configures standard input to be taken from the specified file.
wasi_config_t * wasi_config_new()
Creates a new empty configuration object.
bool wasi_config_preopen_dir(wasi_config_t *config, const char *host_path, const char *guest_path, wasi_dir_perms dir_perms, wasi_file_perms file_perms)
Configures a "preopened directory" to be available to WASI APIs.