#pragma once #include #include #include #include /* Do not include runtime headers here! */ /** ABI Types * Changes to these types breaks the contract between sledgert and the *.so modules that it runs. This means that all * modules must be recompiled. Avoid this! */ struct sledge_abi__wasm_table_entry { uint32_t type_id; void *func_pointer; }; struct sledge_abi__wasm_table { uint32_t length; uint32_t capacity; struct sledge_abi__wasm_table_entry *buffer; /* Backing heap allocation */ }; struct sledge_abi__wasm_memory { uint64_t size; /* Initial Size in bytes */ uint64_t capacity; /* Size backed by actual pages */ uint64_t max; /* Soft cap in bytes. Defaults to 4GB */ uint8_t *buffer; /* Backing heap allocation. Different lifetime because realloc might move this */ }; /* This structure is the runtime representation of the unique state of a module instance * Currently this is not spec-compliant, as it only supports a single table and a single memory and it excludes many * entities https://webassembly.github.io/spec/core/exec/runtime.html#module-instances */ struct sledge_abi__wasm_module_instance { uint64_t wasmg_0; /* Used to refer to the shadow stack */ struct sledge_abi__wasm_table *table; /* Note: memory has an opaque type due to private state. Do not reorder members below this! */ struct sledge_abi__wasm_memory memory; /* Private runtime state follows */ }; /* Based on example traps listed at https://webassembly.org/docs/security/ */ enum sledge_abi__wasm_trap { WASM_TRAP_INVALID_INDEX = 1, WASM_TRAP_MISMATCHED_TYPE = 2, WASM_TRAP_PROTECTED_CALL_STACK_OVERFLOW = 3, WASM_TRAP_OUT_OF_BOUNDS_LINEAR_MEMORY = 4, WASM_TRAP_ILLEGAL_ARITHMETIC_OPERATION = 5, WASM_TRAP_UNREACHABLE = 6, WASM_TRAP_COUNT }; /* Symbols expected from sledgert */ extern void sledge_abi__wasm_trap_raise(enum sledge_abi__wasm_trap trapno); extern int32_t sledge_abi__wasm_memory_expand(struct sledge_abi__wasm_memory *wasm_memory, uint32_t page_count); void sledge_abi__wasm_memory_initialize_region(struct sledge_abi__wasm_memory *wasm_memory, uint32_t offset, uint32_t region_size, uint8_t region[]); extern int32_t sledge_abi__wasm_globals_get_i32(uint32_t idx); extern int64_t sledge_abi__wasm_globals_get_i64(uint32_t idx); extern void sledge_abi__wasm_globals_set_i32(uint32_t idx, int32_t value, bool is_mutable); extern void sledge_abi__wasm_globals_set_i64(uint32_t idx, int64_t value, bool is_mutable); /* Wasm initialization functions generated by the aWsm compiler */ extern void sledge_abi__init_globals(void); extern void sledge_abi__init_mem(void); extern void sledge_abi__init_tbl(void); extern int32_t sledge_abi__entrypoint(void); extern uint32_t sledge_abi__wasm_memory_starting_pages(void); extern uint32_t sledge_abi__wasm_memory_max_pages(void); typedef void (*sledge_abi__init_globals_fn_t)(void); #define SLEDGE_ABI__INITIALIZE_GLOBALS "sledge_abi__init_globals" typedef void (*sledge_abi__init_mem_fn_t)(void); #define SLEDGE_ABI__INITIALIZE_MEMORY "sledge_abi__init_mem" typedef void (*sledge_abi__init_tbl_fn_t)(void); #define SLEDGE_ABI__INITIALIZE_TABLE "sledge_abi__init_tbl" typedef int32_t (*sledge_abi__entrypoint_fn_t)(void); #define SLEDGE_ABI__ENTRYPOINT "sledge_abi__entrypoint" typedef uint32_t (*sledge_abi__wasm_memory_starting_pages_fn_t)(void); #define SLEDGE_ABI__STARTING_PAGES "sledge_abi__wasm_memory_starting_pages" typedef uint32_t (*sledge_abi__wasm_memory_max_pages_fn_t)(void); #define SLEDGE_ABI__MAX_PAGES "sledge_abi__wasm_memory_max_pages" typedef uint32_t (*sledge_abi__wasm_memory_globals_len_fn_t)(void); #define SLEDGE_ABI__GLOBALS_LEN "sledge_abi__wasm_globals_len" typedef uint32_t __wasi_clockid_t; typedef uint64_t __wasi_dircookie_t; typedef uint32_t __wasi_exitcode_t; typedef int32_t __wasi_fd_t; typedef int64_t __wasi_filedelta_t; typedef uint64_t __wasi_filesize_t; typedef uint32_t __wasi_lookupflags_t; typedef uint64_t __wasi_rights_t; typedef uint32_t __wasi_size_t; typedef uint64_t __wasi_timestamp_t; #ifndef unlikely #define unlikely(x) __builtin_expect(!!(x), 0) #endif #ifndef likely #define likely(x) __builtin_expect(!!(x), 1) #endif uint32_t sledge_abi__wasi_snapshot_preview1_args_get(__wasi_size_t argv_retoffset, __wasi_size_t argv_buf_retoffset); uint32_t sledge_abi__wasi_snapshot_preview1_args_sizes_get(__wasi_size_t argc_retoffset, __wasi_size_t argv_buf_len_retoffset); uint32_t sledge_abi__wasi_snapshot_preview1_clock_res_get(__wasi_clockid_t id, __wasi_size_t resolution_retoffset); uint32_t sledge_abi__wasi_snapshot_preview1_clock_time_get(__wasi_clockid_t clock_id, __wasi_timestamp_t precision, __wasi_size_t time_retoffset); uint32_t sledge_abi__wasi_snapshot_preview1_environ_get(__wasi_size_t env_retoffset, __wasi_size_t env_buf_retoffset); uint32_t sledge_abi__wasi_snapshot_preview1_environ_sizes_get(__wasi_size_t envc_retoffset, __wasi_size_t env_buf_len_retoffset); uint32_t sledge_abi__wasi_snapshot_preview1_fd_advise(__wasi_fd_t fd, __wasi_filesize_t file_offset, __wasi_filesize_t len, uint32_t advice_extended); uint32_t sledge_abi__wasi_snapshot_preview1_fd_allocate(__wasi_fd_t fd, __wasi_filesize_t offset, __wasi_filesize_t len); uint32_t sledge_abi__wasi_snapshot_preview1_fd_close(__wasi_fd_t fd); uint32_t sledge_abi__wasi_snapshot_preview1_fd_datasync(__wasi_fd_t fd); uint32_t sledge_abi__wasi_snapshot_preview1_fd_fdstat_get(__wasi_fd_t fd, __wasi_size_t fdstat_retoffset); uint32_t sledge_abi__wasi_snapshot_preview1_fd_fdstat_set_flags(__wasi_fd_t fd, uint32_t fdflags_extended); uint32_t sledge_abi__wasi_snapshot_preview1_fd_fdstat_set_rights(__wasi_fd_t fd, __wasi_rights_t fs_rights_base, __wasi_rights_t fs_rights_inheriting); uint32_t sledge_abi__wasi_snapshot_preview1_fd_filestat_get(__wasi_fd_t fd, __wasi_size_t filestat_retoffset); uint32_t sledge_abi__wasi_snapshot_preview1_fd_filestat_set_size(__wasi_fd_t fd, __wasi_filesize_t size); uint32_t sledge_abi__wasi_snapshot_preview1_fd_filestat_set_times(__wasi_fd_t fd, __wasi_timestamp_t atim, __wasi_timestamp_t mtim, uint32_t fstflags_extended); uint32_t sledge_abi__wasi_snapshot_preview1_fd_pread(__wasi_fd_t fd, __wasi_size_t iovs_baseoffset, __wasi_size_t iovs_len, __wasi_filesize_t offset, __wasi_size_t nread_retoffset); uint32_t sledge_abi__wasi_snapshot_preview1_fd_prestat_get(__wasi_fd_t fd, __wasi_size_t prestat_retoffset); uint32_t sledge_abi__wasi_snapshot_preview1_fd_prestat_dir_name(__wasi_fd_t fd, __wasi_size_t dirname_retoffset, __wasi_size_t dirname_len); uint32_t sledge_abi__wasi_snapshot_preview1_fd_pwrite(__wasi_fd_t fd, __wasi_size_t iovs_baseoffset, __wasi_size_t iovs_len, __wasi_filesize_t file_offset, __wasi_size_t nwritten_retoffset); uint32_t sledge_abi__wasi_snapshot_preview1_fd_read(__wasi_fd_t fd, __wasi_size_t iovs_baseoffset, __wasi_size_t iovs_len, __wasi_size_t nread_retoffset); uint32_t sledge_abi__wasi_snapshot_preview1_fd_readdir(__wasi_fd_t fd, __wasi_size_t buf_baseoffset, __wasi_size_t buf_len, __wasi_dircookie_t cookie, __wasi_size_t nread_retoffset); uint32_t sledge_abi__wasi_snapshot_preview1_fd_renumber(__wasi_fd_t fd, __wasi_fd_t to); uint32_t sledge_abi__wasi_snapshot_preview1_fd_seek(__wasi_fd_t fd, __wasi_filedelta_t file_offset, uint32_t whence_extended, __wasi_size_t newoffset_retoffset); uint32_t sledge_abi__wasi_snapshot_preview1_fd_sync(__wasi_fd_t fd); uint32_t sledge_abi__wasi_snapshot_preview1_fd_tell(__wasi_fd_t fd, __wasi_size_t fileoffset_retoffset); uint32_t sledge_abi__wasi_snapshot_preview1_fd_write(__wasi_fd_t fd, __wasi_size_t iovs_baseoffset, __wasi_size_t iovs_len, __wasi_size_t nwritten_retoffset); uint32_t sledge_abi__wasi_snapshot_preview1_path_create_directory(__wasi_fd_t fd, __wasi_size_t path_baseoffset, __wasi_size_t path_len); uint32_t sledge_abi__wasi_snapshot_preview1_path_filestat_get(__wasi_fd_t fd, __wasi_lookupflags_t flags, __wasi_size_t path_baseoffset, __wasi_size_t path_len, __wasi_size_t filestat_retoffset); uint32_t sledge_abi__wasi_snapshot_preview1_path_filestat_set_times(__wasi_fd_t fd, __wasi_lookupflags_t flags, __wasi_size_t path_baseoffset, __wasi_size_t path_len, __wasi_timestamp_t atim, __wasi_timestamp_t mtim, uint32_t fstflags_extended); uint32_t sledge_abi__wasi_snapshot_preview1_path_link(__wasi_fd_t old_fd, __wasi_lookupflags_t old_flags, __wasi_size_t old_path_baseoffset, __wasi_size_t old_path_len, __wasi_fd_t new_fd, __wasi_size_t new_path_baseoffset, __wasi_size_t new_path_len); uint32_t sledge_abi__wasi_snapshot_preview1_path_open(__wasi_fd_t dirfd, __wasi_lookupflags_t lookupflags, __wasi_size_t path_baseoffset, __wasi_size_t path_len, uint32_t oflags_extended, __wasi_rights_t fs_rights_base, __wasi_rights_t fs_rights_inheriting, uint32_t fdflags_extended, __wasi_size_t fd_retoffset); uint32_t sledge_abi__wasi_snapshot_preview1_path_readlink(__wasi_fd_t fd, __wasi_size_t path_baseoffset, __wasi_size_t path_len, __wasi_size_t buf_baseretoffset, __wasi_size_t buf_len, __wasi_size_t nread_retoffset); uint32_t sledge_abi__wasi_snapshot_preview1_path_remove_directory(__wasi_fd_t fd, __wasi_size_t path_baseoffset, __wasi_size_t path_len); uint32_t sledge_abi__wasi_snapshot_preview1_path_rename(__wasi_fd_t fd, __wasi_size_t old_path_baseoffset, __wasi_size_t old_path_len, __wasi_fd_t new_fd, __wasi_size_t new_path_baseoffset, __wasi_size_t new_path_len); uint32_t sledge_abi__wasi_snapshot_preview1_path_symlink(__wasi_size_t old_path_baseoffset, __wasi_size_t old_path_len, __wasi_fd_t fd, __wasi_size_t new_path_baseoffset, __wasi_size_t new_path_len); uint32_t sledge_abi__wasi_snapshot_preview1_path_unlink_file(__wasi_fd_t fd, __wasi_size_t path_baseoffset, __wasi_size_t path_len); uint32_t sledge_abi__wasi_snapshot_preview1_poll_oneoff(__wasi_size_t in_baseoffset, __wasi_size_t out_baseoffset, __wasi_size_t nsubscriptions, __wasi_size_t nevents_retoffset); void sledge_abi__wasi_snapshot_preview1_proc_exit(__wasi_exitcode_t exitcode); uint32_t sledge_abi__wasi_snapshot_preview1_proc_raise(uint32_t sig_extended); uint32_t sledge_abi__wasi_snapshot_preview1_random_get(__wasi_size_t buf_baseretoffset, __wasi_size_t buf_len); uint32_t sledge_abi__wasi_snapshot_preview1_sched_yield(void); uint32_t sledge_abi__wasi_snapshot_preview1_sock_recv(__wasi_fd_t fd, __wasi_size_t ri_data_baseretoffset, __wasi_size_t ri_data_len, uint32_t ri_flags_extended, __wasi_size_t ri_data_nbytes_retoffset, __wasi_size_t message_nbytes_retoffset); uint32_t sledge_abi__wasi_snapshot_preview1_sock_send(__wasi_fd_t fd, __wasi_size_t si_data_baseoffset, __wasi_size_t si_data_len, uint32_t si_flags_extended, __wasi_size_t nbytes_retoffset); uint32_t sledge_abi__wasi_snapshot_preview1_sock_shutdown(__wasi_fd_t fd, uint32_t how); uint32_t sledge_abi__scratch_storage_get_size(uint32_t key_offset, uint32_t key_len); int sledge_abi__scratch_storage_get(uint32_t key_offset, uint32_t key_size, uint32_t buf_offset, uint32_t buf_len); int sledge_abi__scratch_storage_set(uint32_t key_offset, uint32_t key_len, uint32_t value_offset, uint32_t value_len); int sledge_abi__scratch_storage_delete(uint32_t key_offset, uint32_t key_len); void sledge_abi__scratch_storage_upsert(uint32_t key_offset, uint32_t key_len, uint32_t value_offset, uint32_t value_len);