Skip to content

Commit 741045a

Browse files
committed
wasmtime: Fix and Add preopen_dir for modules & components
Signed-off-by: Maximilian Hüter <[email protected]>
1 parent e8cbc72 commit 741045a

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

src/libcrun/handlers/wasmtime.c

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,12 @@ libwasmtime_run_module (void *cookie, char *const argv[], wasm_engine_t *engine,
192192
void (*wasmtime_store_delete) (wasmtime_store_t *store);
193193
void (*wasmtime_error_message) (const wasmtime_error_t *error, wasm_name_t *message);
194194
void (*wasmtime_error_delete) (wasmtime_error_t *error);
195-
bool (*wasi_config_preopen_dir) (wasi_config_t *config, const char *path, const char *guest_path);
195+
bool (*wasi_config_preopen_dir) (
196+
wasi_config_t *config,
197+
const char *path,
198+
const char *guest_path,
199+
wasi_dir_perms dir_perms,
200+
wasi_file_perms file_perms);
196201

197202
wasm_engine_delete = dlsym (cookie, "wasm_engine_delete");
198203
wasm_byte_vec_delete = dlsym (cookie, "wasm_byte_vec_delete");
@@ -270,7 +275,12 @@ libwasmtime_run_module (void *cookie, char *const argv[], wasm_engine_t *engine,
270275
wasi_config_inherit_stdin (wasi_config);
271276
wasi_config_inherit_stdout (wasi_config);
272277
wasi_config_inherit_stderr (wasi_config);
273-
wasi_config_preopen_dir (wasi_config, ".", ".");
278+
wasi_config_preopen_dir (
279+
wasi_config,
280+
".",
281+
".",
282+
WASMTIME_WASI_DIR_PERMS_READ | WASMTIME_WASI_DIR_PERMS_WRITE,
283+
WASMTIME_WASI_FILE_PERMS_READ | WASMTIME_WASI_FILE_PERMS_WRITE);
274284
wasm_trap_t *trap = NULL;
275285
err = wasmtime_context_set_wasi (context, wasi_config);
276286
if (err != NULL)
@@ -369,6 +379,12 @@ libwasmtime_run_component (void *cookie, char *const argv[], wasm_engine_t *engi
369379
void (*wasmtime_component_linker_delete) (wasmtime_component_linker_t *linker);
370380
void (*wasmtime_error_message) (const wasmtime_error_t *error, wasm_name_t *message);
371381
void (*wasmtime_error_delete) (wasmtime_error_t *error);
382+
bool (*wasi_config_preopen_dir) (
383+
wasi_config_t *config,
384+
const char *path,
385+
const char *guest_path,
386+
wasi_dir_perms dir_perms,
387+
wasi_file_perms file_perms);
372388

373389
wasm_engine_delete = dlsym (cookie, "wasm_engine_delete");
374390
wasm_byte_vec_delete = dlsym (cookie, "wasm_byte_vec_delete");
@@ -394,6 +410,7 @@ libwasmtime_run_component (void *cookie, char *const argv[], wasm_engine_t *engi
394410
wasmtime_component_linker_delete = dlsym (cookie, "wasmtime_component_linker_delete");
395411
wasmtime_error_message = dlsym (cookie, "wasmtime_error_message");
396412
wasmtime_error_delete = dlsym (cookie, "wasmtime_error_delete");
413+
wasi_config_preopen_dir = dlsym (cookie, "wasi_config_preopen_dir");
397414

398415
if (wasm_engine_delete == NULL || wasm_byte_vec_delete == NULL || wasmtime_store_new == NULL
399416
|| wasmtime_store_delete == NULL || wasmtime_store_context == NULL || wasmtime_component_new == NULL
@@ -403,7 +420,7 @@ libwasmtime_run_component (void *cookie, char *const argv[], wasm_engine_t *engi
403420
|| wasmtime_component_linker_instantiate == NULL || wasmtime_component_instance_get_export_index == NULL
404421
|| wasmtime_component_instance_get_func == NULL || wasmtime_component_func_call == NULL || wasmtime_component_export_index_delete == NULL
405422
|| wasmtime_component_delete == NULL || wasmtime_component_linker_delete == NULL || wasmtime_error_message == NULL
406-
|| wasmtime_error_delete == NULL)
423+
|| wasmtime_error_delete == NULL || wasi_config_preopen_dir == NULL)
407424
error (EXIT_FAILURE, 0, "could not find symbol in `libwasmtime.so`");
408425

409426
// Set up wasmtime context
@@ -432,6 +449,12 @@ libwasmtime_run_component (void *cookie, char *const argv[], wasm_engine_t *engi
432449
wasmtime_wasip2_config_inherit_stdin (wasi_config);
433450
wasmtime_wasip2_config_inherit_stdout (wasi_config);
434451
wasmtime_wasip2_config_inherit_stderr (wasi_config);
452+
wasi_config_preopen_dir (
453+
(wasi_config_t *) wasi_config,
454+
".",
455+
".",
456+
WASMTIME_WASI_DIR_PERMS_READ | WASMTIME_WASI_DIR_PERMS_WRITE,
457+
WASMTIME_WASI_FILE_PERMS_READ | WASMTIME_WASI_FILE_PERMS_WRITE);
435458

436459
for (arg = argv; *arg != NULL; ++arg)
437460
wasmtime_wasip2_config_arg (wasi_config, *arg, strlen (*arg));

0 commit comments

Comments
 (0)