wasm_run.h (2685B)
1 #ifndef KIT_DRIVER_WASM_RUN_H 2 #define KIT_DRIVER_WASM_RUN_H 3 4 #include <kit/interp.h> 5 #include <kit/jit.h> 6 #include <stdint.h> 7 8 #include "env.h" 9 10 typedef enum DriverWasmImportMode { 11 DRIVER_WASM_IMPORT_DENY = 0, 12 DRIVER_WASM_IMPORT_WASI = 1, 13 DRIVER_WASM_IMPORT_TEST = 2, 14 } DriverWasmImportMode; 15 16 typedef enum DriverWasmEnvMode { 17 DRIVER_WASM_ENV_NONE = 0, 18 DRIVER_WASM_ENV_ALLOWLIST = 1, 19 DRIVER_WASM_ENV_INHERIT = 2, 20 } DriverWasmEnvMode; 21 22 typedef enum DriverWasmStdioMode { 23 DRIVER_WASM_STDIO_NULL = 0, 24 DRIVER_WASM_STDIO_INHERIT = 1, 25 } DriverWasmStdioMode; 26 27 typedef enum DriverWasmClockMode { 28 DRIVER_WASM_CLOCK_NONE = 0, 29 DRIVER_WASM_CLOCK_MONOTONIC = 1, 30 DRIVER_WASM_CLOCK_REALTIME = 2, 31 } DriverWasmClockMode; 32 33 typedef enum DriverWasmRandomMode { 34 DRIVER_WASM_RANDOM_NONE = 0, 35 DRIVER_WASM_RANDOM_HOST = 1, 36 DRIVER_WASM_RANDOM_SEED = 2, 37 } DriverWasmRandomMode; 38 39 typedef struct DriverWasmRunOptions { 40 DriverEnv* env; 41 size_t argv_bound; 42 int used; 43 44 uint64_t max_instance_bytes; 45 uint64_t max_total_memory_bytes; 46 uint32_t max_memories; 47 48 uint8_t imports; /* DriverWasmImportMode */ 49 uint8_t env_mode; 50 uint8_t stdio_mode; 51 uint8_t clock_mode; 52 uint8_t random_mode; 53 uint8_t reserved[3]; 54 55 const char** env_pass; 56 const char** env_set; 57 const char** map_dirs; 58 const char** map_files; 59 uint32_t nenv_pass; 60 uint32_t nenv_set; 61 uint32_t nmap_dirs; 62 uint32_t nmap_files; 63 const char* const* args; 64 uint32_t nargs; 65 const char* cwd; 66 const char* random_seed; 67 } DriverWasmRunOptions; 68 69 int driver_wasm_run_options_init(DriverWasmRunOptions*, DriverEnv*, 70 size_t argv_bound); 71 void driver_wasm_run_options_fini(DriverWasmRunOptions*); 72 73 /* Try to consume argv[*index] as a Wasm sandbox option. 74 * Returns 1 on consume, 0 when the flag is unrelated, and -1 on usage error. */ 75 int driver_wasm_run_try_consume(DriverWasmRunOptions*, const char* tool, 76 int argc, char** argv, int* index); 77 78 int driver_wasm_run_options_used(const DriverWasmRunOptions*); 79 80 /* Returns 0 when the image is not a kit-lowered Wasm module. Otherwise runs 81 * the Wasm init + entry sequence, stores the result in *rc_out, and returns 1. */ 82 int driver_wasm_run_call_entry(const DriverWasmRunOptions*, const char* tool, 83 KitCompiler*, KitJit*, void* entry, 84 int* rc_out); 85 86 int driver_wasm_run_call_entry_interp(const DriverWasmRunOptions*, 87 const char* tool, KitCompiler*, KitJit*, 88 KitInterpProgram*, const char* entry_name, 89 int* rc_out); 90 91 #endif