├── .github └── workflows │ └── ci.yml ├── .gitignore ├── .gitmodules ├── CMakeLists.txt ├── LICENSE ├── Makefile ├── README.md ├── bin └── extism-wamr.c ├── build-scripts └── esp-idf │ ├── README.md │ └── extism-wamr │ ├── CMakeLists.txt │ └── Kconfig ├── compile_flags.txt ├── idf_component.yml ├── src ├── extism-runtime.h ├── extism-wamr.h ├── extism.c ├── internal.h ├── kernel.c └── symbols.c ├── update-kernel.sh └── wasm └── count-vowels.wasm /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | on: 2 | pull_request: 3 | workflow_dispatch: 4 | 5 | name: CI 6 | 7 | jobs: 8 | lib: 9 | name: Extism runtime lib 10 | runs-on: ${{ matrix.os }} 11 | strategy: 12 | matrix: 13 | os: [ubuntu-latest, macos-latest] 14 | rust: 15 | - stable 16 | steps: 17 | - name: Checkout sources 18 | uses: actions/checkout@v3 19 | - name: Build 20 | run: make 21 | - name: Test 22 | run: make test 23 | - name: Upload artifact 24 | uses: actions/upload-artifact@v3 25 | with: 26 | name: libextism-${{ matrix.os }} 27 | path: | 28 | ./extism-wamr 29 | ./libextism-wamr.a 30 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | CMakeCache.txt 2 | CMakeFiles 3 | *.a 4 | *.o 5 | *.so 6 | *.dylib 7 | *.cmake 8 | Testing 9 | extism-wamr 10 | test_wrgsbase.c 11 | build 12 | extism-runtime.wasm 13 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "wasm-micro-runtime"] 2 | path = wasm-micro-runtime 3 | url = https://github.com/bytecodealliance/wasm-micro-runtime.git 4 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.14) 2 | 3 | if (NOT DEFINED CMAKE_BUILD_TYPE) 4 | set (CMAKE_BUILD_TYPE Release) 5 | endif() 6 | 7 | set(CMAKE_C_STANDARD 11) 8 | set(CMAKE_C_STANDARD_REQUIRED TRUE) 9 | 10 | if(ESP_PLATFORM) 11 | include (${COMPONENT_DIR}/build-scripts/esp-idf/extism-wamr/CMakeLists.txt) 12 | return() 13 | endif() 14 | 15 | 16 | project(extism-wamr) 17 | enable_testing() 18 | 19 | # Configure WAMR 20 | 21 | if(NOT DEFINED WAMR_BUILD_TARGET) 22 | if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm64") 23 | set (WAMR_BUILD_TARGET "aarch64") 24 | else() 25 | set (WAMR_BUILD_TARGET ${CMAKE_SYSTEM_PROCESSOR}) 26 | endif() 27 | endif() 28 | 29 | if(NOT DEFINED WAMR_BUILD_PLATFORM) 30 | string(TOLOWER ${CMAKE_SYSTEM_NAME} WAMR_BUILD_PLATFORM) 31 | elseif(${WAMR_BUILD_PLATFORM} MATCHES "esp-idf") 32 | string(TOLOWER ${CMAKE_SYSTEM_NAME} WAMR_BUILD_PLATFORM) 33 | set(ESP_PLATFORM 1) 34 | endif() 35 | 36 | set (CMAKE_C_FLAGS_RELEASE "-O3") 37 | set (CMAKE_C_FLAGS_DEBUG "-g") 38 | 39 | if (NOT DEFINED WAMR_BUILD_INTERP) 40 | set (WAMR_BUILD_INTERP 1) 41 | endif() 42 | 43 | if (NOT DEFINED WAMR_BUILD_FAST_INTERP) 44 | set (WAMR_BUILD_FAST_INTERP 1) 45 | endif() 46 | 47 | if (NOT DEFINED WAMR_BUILD_LIBC_BUILTIN) 48 | set (WAMR_BUILD_LIBC_BUILTIN 1) 49 | endif() 50 | 51 | if (NOT DEFINED WAMR_BUILD_LIBC_WASI) 52 | set (WAMR_BUILD_LIBC_WASI 1) 53 | endif() 54 | 55 | if (NOT DEFINED WAMR_BUILD_TAIL_CALL) 56 | set (WAMR_BUILD_TAIL_CALL 1) 57 | endif() 58 | 59 | if (NOT DEFINED WAMR_BUILD_GC) 60 | set (WAMR_BUILD_GC 1) 61 | endif() 62 | 63 | # Multi-module is required 64 | set (WAMR_BUILD_MULTI_MODULE 1) 65 | 66 | set (WAMR_ROOT_DIR wasm-micro-runtime) 67 | 68 | 69 | include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake) 70 | add_library(vmlib ${WAMR_RUNTIME_LIB_SOURCE}) 71 | 72 | # extism-wamr 73 | 74 | add_library (extism-wamr STATIC src/symbols.c src/kernel.c src/extism.c) 75 | target_link_libraries (extism-wamr vmlib m) 76 | if(MSVC) 77 | target_compile_options(extism-wamr PRIVATE /W4 /WX) 78 | else() 79 | target_compile_options(extism-wamr PRIVATE -Wall -Wextra -Werror) 80 | endif() 81 | 82 | # Install 83 | 84 | set_target_properties(extism-wamr PROPERTIES PUBLIC_HEADER "src/extism-wamr.h") 85 | 86 | install(TARGETS extism-wamr 87 | LIBRARY DESTINATION "lib" 88 | PUBLIC_HEADER DESTINATION "include" 89 | ) 90 | 91 | add_executable(extism-wamr-exe bin/extism-wamr.c) 92 | set_target_properties(extism-wamr-exe PROPERTIES OUTPUT_NAME "extism-wamr") 93 | target_link_libraries(extism-wamr-exe extism-wamr) 94 | add_test( 95 | NAME extism-wamr-exe 96 | COMMAND extism-wamr-exe ${PROJECT_SOURCE_DIR}/wasm/count-vowels.wasm count_vowels aaa 97 | ) 98 | install(TARGETS extism-wamr-exe 99 | RUNTIME DESTINATION "bin" 100 | ) 101 | 102 | 103 | 104 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2024 Extism Authors 2 | 3 | Redistribution and use in source and binary forms, with or without modification, 4 | are permitted provided that the following conditions are met: 5 | 6 | 1. Redistributions of source code must retain the above copyright notice, this 7 | list of conditions and the following disclaimer. 8 | 9 | 2. Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | 13 | 3. Neither the name of the copyright holder nor the names of its contributors 14 | may be used to endorse or promote products derived from this software without 15 | specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: build 2 | build: extism-wamr 3 | mkdir -p build && cd build && cmake .. && $(MAKE) 4 | cp build/libextism-wamr.a . 5 | cp build/extism-wamr . 6 | 7 | .PHONY: build 8 | debug: extism-wamr 9 | mkdir -p build && cd build && cmake -DCMAKE_BUILD_TYPE=Debug .. && $(MAKE) 10 | cp build/libextism-wamr.a . 11 | cp build/extism-wamr . 12 | 13 | test: build 14 | cd build && make test 15 | 16 | clean: 17 | rm -rf ./build 18 | 19 | extism-wamr: 20 | git submodule update --init 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WAMR SDK 2 | 3 | A lightweight [WAMR](https://github.com/bytecodealliance/wasm-micro-runtime) backend for Extism 4 | 5 | Supports a limited set of features compared to [extism/extism](https://github.com/extism/extism): 6 | 7 | - Host functions 8 | - Memory limits 9 | 10 | In progress: 11 | 12 | - Linking multiple Wasm modules 13 | 14 | 15 | ## Building 16 | 17 | Requires: 18 | - CMake 19 | - C compiler 20 | 21 | ```bash 22 | mkdir build 23 | cd build 24 | cmake .. 25 | make 26 | ``` 27 | 28 | or: 29 | 30 | ```bash 31 | make 32 | ``` 33 | 34 | ## Getting started 35 | 36 | - `extism_runtime_init` should always be called before creating any plugins, and there 37 | is only a single global runtime that host functions can be loaded into 38 | - The plugins listed in `ExtismManifest` that depend on other Wasm modules must have all 39 | dependencies listed first in the manifest with module names specified. 40 | 41 | ### Creating and calling a plugin 42 | 43 | ```c 44 | #include 45 | #include 46 | #include 47 | 48 | // Read a file from disk - an implementation of `read_file` can be found 49 | // in `bin/extism-wamr.c` 50 | uint8_t *read_file(const char *, size_t *); 51 | 52 | // Return the input as-is 53 | uint64_t host_reflect(ExtismExecEnv *env, uint64_t x) { return x; } 54 | 55 | // Run an Extism plugin and print the output 56 | ExtismStatus run_wasm(const char *wasm_file, const char *func_name, const char *input, size_t input_len){ 57 | char errbuf[1024]; 58 | size_t datalen = 0, len = 0; 59 | uint8_t *data = read_file(wasm_file, &datalen); 60 | if (data == NULL) { 61 | return ExtismStatusErr; 62 | } 63 | 64 | // Initialize the runtime, this must be done before anything else 65 | extism_runtime_init(); 66 | 67 | // Specify the modules to be loaded, setting `name` to `NULL` marks a module 68 | // at the main module 69 | ExtismWasm wasm = { 70 | .data = data, 71 | .length = datalen, 72 | .name = NULL, 73 | }; 74 | ExtismManifest manifest; 75 | extism_manifest_init(&manifest, &wasm, 1, NULL, 0, NULL); 76 | 77 | // Define a host function 78 | extism_host_function("extism:host/user", "host_reflect", "(I)I", host_reflect, 79 | NULL); 80 | 81 | // Create the plugin instance 82 | ExtismPlugin *plugin = extism_plugin_new(&manifest, errbuf, 1024); 83 | if (plugin == NULL) { 84 | fputs("ERROR: ", stderr); 85 | fputs(errbuf, stderr); 86 | fputs("\n", stderr); 87 | free(data); 88 | extism_runtime_cleanup(); 89 | return ExtismStatusErr; 90 | } 91 | 92 | // Call `func_name` 93 | if ((status = extism_plugin_call(plugin, func_name, (const void *)input, 94 | input_len)) != ExtismStatusOk) { 95 | // Print error if it fails 96 | const char *s = extism_plugin_error(plugin, &len); 97 | fprintf(stderr, "ERROR(%d): ", status); 98 | fwrite(s, len, 1, stderr); 99 | fputc('\n', stderr); 100 | } else { 101 | // Otherwise print the output 102 | uint8_t *output = extism_plugin_output(plugin, &len); 103 | if (len > 0) { 104 | fwrite(output, len, 1, stdout); 105 | fputc('\n', stdout); 106 | } 107 | } 108 | 109 | // Cleanup 110 | extism_plugin_free(plugin); 111 | extism_runtime_cleanup(); 112 | free(data); 113 | return ExtismStatusOk; 114 | } 115 | 116 | ``` 117 | 118 | -------------------------------------------------------------------------------- /bin/extism-wamr.c: -------------------------------------------------------------------------------- 1 | #include "../src/extism-wamr.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | uint8_t *read_file(const char *filename, size_t *len) { 9 | 10 | FILE *fp = fopen(filename, "rb"); 11 | if (fp == NULL) { 12 | return NULL; 13 | } 14 | fseek(fp, 0, SEEK_END); 15 | size_t length = ftell(fp); 16 | fseek(fp, 0, SEEK_SET); 17 | 18 | uint8_t *data = malloc(length); 19 | if (data == NULL) { 20 | fclose(fp); 21 | return NULL; 22 | } 23 | 24 | assert(fread(data, 1, length, fp) == length); 25 | fclose(fp); 26 | 27 | *len = length; 28 | return data; 29 | } 30 | 31 | uint64_t host_reflect(ExtismExecEnv *env, uint64_t x) { return x; } 32 | 33 | int main(int argc, char *argv[]) { 34 | size_t len = 0, datalen = 0; 35 | char errbuf[1024]; 36 | 37 | // Setup loop 38 | const char *env = getenv("EXTISM_WAMR_LOOP"); 39 | int loop = atoi(env == NULL ? "1" : env); 40 | 41 | const char *num_pages = getenv("EXTISM_WAMR_HEAP_PAGES"); 42 | int pages = atoi(num_pages == NULL ? "10" : num_pages); 43 | 44 | ExtismStatus status; 45 | 46 | if (argc < 3) { 47 | fprintf(stderr, "Usage: %s ", argv[0]); 48 | return 1; 49 | } 50 | 51 | uint8_t *data = read_file(argv[1], &datalen); 52 | if (data == NULL) { 53 | return 2; 54 | } 55 | 56 | // Initialize the runtime, this must be done before a plugin can be created 57 | extism_runtime_init(); 58 | 59 | // Specify the modules to be loaded, setting `name` to `NULL` marks a module 60 | // at the main module 61 | ExtismWasm wasm = { 62 | .data = data, 63 | .length = datalen, 64 | .name = NULL, 65 | }; 66 | ExtismManifest manifest; 67 | ExtismMemoryConfig mem; 68 | mem.stack_size = 8192; 69 | mem.heap_size = 65536 * pages; 70 | extism_manifest_init(&manifest, &wasm, 1, NULL, 0, &mem); 71 | 72 | // Host functions 73 | extism_host_function("extism:host/user", "host_reflect", "(I)I", host_reflect, 74 | NULL); 75 | 76 | // Create the plugin 77 | ExtismPlugin *plugin = extism_plugin_new(&manifest, errbuf, 1024); 78 | if (plugin == NULL) { 79 | fputs("ERROR: ", stderr); 80 | fputs(errbuf, stderr); 81 | fputs("\n", stderr); 82 | free(data); 83 | extism_runtime_cleanup(); 84 | return 1; 85 | } 86 | 87 | const char *input = argc > 3 ? argv[3] : ""; 88 | size_t input_len = argc > 3 ? strlen(argv[3]) : 0; 89 | 90 | for (int i = 0; i < loop; i++) { 91 | // Call a function 92 | if ((status = extism_plugin_call(plugin, argv[2], (const void *)input, 93 | input_len)) != ExtismStatusOk) { 94 | // Print error if it fails 95 | const char *s = extism_plugin_error(plugin, &len); 96 | fprintf(stderr, "ERROR(%d): ", status); 97 | fwrite(s, len, 1, stderr); 98 | fputc('\n', stderr); 99 | } else { 100 | // Otherwise print the output 101 | uint8_t *output = extism_plugin_output(plugin, &len); 102 | if (len > 0) { 103 | fwrite(output, len, 1, stdout); 104 | fputc('\n', stdout); 105 | } 106 | } 107 | } 108 | 109 | // Cleanup 110 | extism_plugin_free(plugin); 111 | extism_runtime_cleanup(); 112 | free(data); 113 | return 0; 114 | } 115 | -------------------------------------------------------------------------------- /build-scripts/esp-idf/README.md: -------------------------------------------------------------------------------- 1 | # extism-wamr as ESP-IDF component 2 | 3 | You can build an ESP-IDF project with extism-wamr as a component: 4 | 5 | - Make sure you have the ESP-IDF properly installed and setup 6 | - In particular have the following paths set: 7 | - `EXTISM_WAMR_PATH` to point to your wamr-sdk repository 8 | - `IDF_PATH` to point to your ESP-IDF 9 | - `source $IDF_PATH/export.sh` 10 | - Create a new project, e.g.: `idf.py create-project wamr-hello` 11 | - In the newly created project folder edit the `CMakeList.txt`: 12 | 13 | ``` 14 | cmake_minimum_required(VERSION 3.5) 15 | 16 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 17 | 18 | set (COMPONENTS ${IDF_TARGET} main freertos esptool_py extism-wamr) 19 | 20 | list(APPEND EXTRA_COMPONENT_DIRS "$ENV{EXTISM_WAMR_PATH}/build-scripts/esp-idf") 21 | 22 | project(wamr-hello) 23 | ``` 24 | - Develop your project in it's `main` component folder. 25 | 26 | -------------------------------------------------------------------------------- /build-scripts/esp-idf/extism-wamr/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2021 Intel Corporation and others. All rights reserved. 2 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 3 | 4 | # Set WAMR's build options 5 | 6 | if (NOT CMAKE_BUILD_EARLY_EXPANSION) 7 | 8 | if (CONFIG_IDF_TARGET_ARCH_RISCV) 9 | set (WAMR_BUILD_TARGET "RISCV32") 10 | elseif (CONFIG_IDF_TARGET_ARCH_XTENSA) 11 | set (WAMR_BUILD_TARGET "XTENSA") 12 | else () 13 | message (FATAL_ERROR "Arch ${CONFIG_IDF_TARGET_ARCH} is not supported") 14 | endif () 15 | 16 | set (WAMR_BUILD_PLATFORM "esp-idf") 17 | 18 | if (CONFIG_WAMR_BUILD_DEBUG) 19 | set (CMAKE_BUILD_TYPE Debug) 20 | else () 21 | set (CMAKE_BUILD_TYPE Release) 22 | endif () 23 | 24 | if (CONFIG_WAMR_ENABLE_INTERP) 25 | set (WAMR_BUILD_INTERP 1) 26 | endif () 27 | 28 | if (CONFIG_WAMR_INTERP_FAST) 29 | set (WAMR_BUILD_FAST_INTERP 1) 30 | endif () 31 | 32 | if (CONFIG_WAMR_ENABLE_AOT) 33 | set (WAMR_BUILD_AOT 1) 34 | endif () 35 | 36 | if (CONFIG_WAMR_ENABLE_LIBC_BUILTIN) 37 | set (WAMR_BUILD_LIBC_BUILTIN 1) 38 | endif () 39 | 40 | if (CONFIG_WAMR_INTERP_LOADER_MINI) 41 | set (WAMR_BUILD_MINI_LOADER 1) 42 | endif () 43 | 44 | if (CONFIG_WAMR_ENABLE_MULTI_MODULE) 45 | set (WAMR_BUILD_MULTI_MODULE 1) 46 | endif () 47 | 48 | if (CONFIG_WAMR_ENABLE_SHARED_MEMORY) 49 | set (WAMR_BUILD_SHARED_MEMORY 1) 50 | endif () 51 | 52 | if (CONFIG_WAMR_ENABLE_MEMORY_PROFILING) 53 | set (WAMR_BUILD_MEMORY_PROFILING 1) 54 | endif () 55 | 56 | if (CONFIG_WAMR_ENABLE_PERF_PROFILING) 57 | set (WAMR_BUILD_PERF_PROFILING 1) 58 | endif () 59 | 60 | if (CONFIG_WAMR_ENABLE_REF_TYPES) 61 | set (WAMR_BUILD_REF_TYPES 1) 62 | endif () 63 | 64 | if (CONFIG_WAMR_ENABLE_LIBC_WASI) 65 | set (WAMR_BUILD_LIBC_WASI 1) 66 | endif () 67 | 68 | if (CONFIG_WAMR_ENABLE_LIB_PTHREAD) 69 | set (WAMR_BUILD_LIB_PTHREAD 1) 70 | endif () 71 | 72 | if (CONFIG_WAMR_ENABLE_TAIL_CALL) 73 | set (WAMR_BUILD_TAIL_CALL 1) 74 | endif () 75 | 76 | if (CONFIG_WAMR_ENABLE_GC) 77 | set (WAMR_BUILD_GC 1) 78 | endif () 79 | 80 | set (WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../wasm-micro-runtime) 81 | set (SRC_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../src) 82 | include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake) 83 | 84 | list (APPEND srcs "${WAMR_RUNTIME_LIB_SOURCE}" 85 | "${PLATFORM_SHARED_SOURCE}" 86 | "${SRC_DIR}/symbols.c" 87 | "${SRC_DIR}/kernel.c" 88 | "${SRC_DIR}/extism.c" 89 | 90 | ) 91 | 92 | set (include_dirs "${IWASM_DIR}/include" 93 | "${UTILS_SHARED_DIR}" 94 | "${PLATFORM_SHARED_DIR}" 95 | "${PLATFORM_SHARED_DIR}/../include" 96 | "${IWASM_COMMON_DIR}" 97 | "${SRC_DIR}" 98 | ) 99 | endif () 100 | 101 | 102 | 103 | idf_component_register(SRCS ${srcs} 104 | INCLUDE_DIRS ${include_dirs} 105 | REQUIRES pthread lwip esp_timer 106 | KCONFIG ${CMAKE_CURRENT_LIST_DIR}/Kconfig) 107 | 108 | target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format") 109 | 110 | if (CONFIG_IDF_TARGET_ARCH_RISCV) 111 | target_compile_definitions(${COMPONENT_LIB} PUBLIC -DBUILD_TARGET_RISCV32_ILP32=1) 112 | elseif (CONFIG_IDF_TARGET_ARCH_XTENSA) 113 | target_compile_definitions(${COMPONENT_LIB} PUBLIC -DBUILD_TARGET_XTENSA=1) 114 | endif () 115 | 116 | if (CONFIG_WAMR_ENABLE_AOT) 117 | target_compile_definitions(${COMPONENT_LIB} PUBLIC -DWASM_ENABLE_AOT=1) 118 | endif () 119 | 120 | if (CONFIG_WAMR_ENABLE_INTERP) 121 | target_compile_definitions(${COMPONENT_LIB} PUBLIC -DWASM_ENABLE_INTERP=1) 122 | endif () 123 | -------------------------------------------------------------------------------- /build-scripts/esp-idf/extism-wamr/Kconfig: -------------------------------------------------------------------------------- 1 | menu "Extism WAMR" 2 | choice WAMR_BUILD_TYPE 3 | prompt "Build type" 4 | default WAMR_BUILD_RELEASE 5 | 6 | config WAMR_BUILD_RELEASE 7 | bool "Release" 8 | 9 | config WAMR_BUILD_DEBUG 10 | bool "Debug" 11 | endchoice 12 | 13 | config WAMR_ENABLE_AOT 14 | bool "AOT" 15 | default n 16 | 17 | menuconfig WAMR_ENABLE_INTERP 18 | bool "Interpreter" 19 | default y 20 | 21 | if WAMR_ENABLE_INTERP 22 | 23 | choice WAMR_INTERP_MODE 24 | prompt "Interpreter mode" 25 | default WAMR_INTERP_FAST 26 | 27 | config WAMR_INTERP_CLASSIC 28 | bool "Classic" 29 | 30 | config WAMR_INTERP_FAST 31 | bool "Fast" 32 | endchoice 33 | 34 | choice WAMR_INTERP_LOADER_MODE 35 | prompt "Loader mode" 36 | default WAMR_INTERP_LOADER_NORMAL 37 | 38 | config WAMR_INTERP_LOADER_NORMAL 39 | bool "Normal" 40 | 41 | config WAMR_INTERP_LOADER_MINI 42 | bool "Mini" 43 | endchoice 44 | endif 45 | 46 | config WAMR_ENABLE_LIB_PTHREAD 47 | bool "Lib pthread" 48 | default y 49 | 50 | config WAMR_ENABLE_LIBC_BUILTIN 51 | bool "Libc builtin" 52 | default y 53 | 54 | config WAMR_ENABLE_LIBC_WASI 55 | bool "Libc WASI" 56 | default y 57 | 58 | config WAMR_ENABLE_MEMORY_PROFILING 59 | bool "Memory profiling" 60 | default n 61 | 62 | config WAMR_ENABLE_MULTI_MODULE 63 | bool "Multi module" 64 | default y 65 | 66 | config WAMR_ENABLE_PERF_PROFILING 67 | bool "Performance profiling" 68 | default n 69 | 70 | config WAMR_ENABLE_REF_TYPES 71 | bool "Reference types" 72 | default y 73 | 74 | config WAMR_ENABLE_SHARED_MEMORY 75 | bool "Shared memory" 76 | default n 77 | 78 | config WAMR_ENABLE_GC 79 | bool "GC" 80 | default n 81 | 82 | config WAMR_ENABLE_TAIL_CALL 83 | bool "Tail calls" 84 | default n 85 | endmenu 86 | -------------------------------------------------------------------------------- /compile_flags.txt: -------------------------------------------------------------------------------- 1 | -I./wasm-micro-runtime/core/iwasm/common 2 | -I./wasm-micro-runtime/core/iwasm/interpreter 3 | -I./wasm-micro-runtime/core/shared/utils 4 | -I./wasm-micro-runtime/core/shared/platform/linux 5 | 6 | -------------------------------------------------------------------------------- /idf_component.yml: -------------------------------------------------------------------------------- 1 | version: "2.0.0" 2 | description: Extism WAMR SDK 3 | repository: https://github.com/extism/wamr-sdk 4 | documentation: https://github.com/extism/wamr-sdk 5 | issues: https://github.com/extism/wamr-sdk/issues 6 | dependencies: 7 | idf: ">=4.4" 8 | targets: 9 | - esp32 10 | - esp32s3 11 | - esp32c3 12 | - esp32c6 13 | # examples: 14 | # - path: product-mini/platforms/esp-idf 15 | -------------------------------------------------------------------------------- /src/extism-runtime.h: -------------------------------------------------------------------------------- 1 | unsigned char extism_runtime_wasm[] = { 2 | 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x27, 0x08, 0x60, 3 | 0x00, 0x01, 0x7e, 0x60, 0x01, 0x7e, 0x01, 0x7e, 0x60, 0x02, 0x7e, 0x7e, 4 | 0x00, 0x60, 0x03, 0x7f, 0x7f, 0x7f, 0x01, 0x7f, 0x60, 0x01, 0x7e, 0x00, 5 | 0x60, 0x01, 0x7e, 0x01, 0x7f, 0x60, 0x02, 0x7e, 0x7f, 0x00, 0x60, 0x00, 6 | 0x00, 0x03, 0x17, 0x16, 0x03, 0x03, 0x01, 0x04, 0x01, 0x01, 0x05, 0x01, 7 | 0x05, 0x01, 0x06, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x07, 0x04, 8 | 0x00, 0x00, 0x05, 0x03, 0x01, 0x00, 0x10, 0x06, 0x16, 0x03, 0x6f, 0x01, 9 | 0xd0, 0x6f, 0x0b, 0x7f, 0x00, 0x41, 0x80, 0x80, 0xc0, 0x00, 0x0b, 0x7f, 10 | 0x00, 0x41, 0x80, 0x80, 0xc0, 0x00, 0x0b, 0x07, 0xb1, 0x02, 0x18, 0x06, 11 | 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x02, 0x00, 0x05, 0x61, 0x6c, 0x6c, 12 | 0x6f, 0x63, 0x00, 0x02, 0x04, 0x66, 0x72, 0x65, 0x65, 0x00, 0x03, 0x0d, 13 | 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x5f, 0x75, 0x6e, 0x73, 0x61, 0x66, 14 | 0x65, 0x00, 0x04, 0x06, 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x00, 0x05, 15 | 0x07, 0x6c, 0x6f, 0x61, 0x64, 0x5f, 0x75, 0x38, 0x00, 0x06, 0x08, 0x6c, 16 | 0x6f, 0x61, 0x64, 0x5f, 0x75, 0x36, 0x34, 0x00, 0x07, 0x0d, 0x69, 0x6e, 17 | 0x70, 0x75, 0x74, 0x5f, 0x6c, 0x6f, 0x61, 0x64, 0x5f, 0x75, 0x38, 0x00, 18 | 0x08, 0x0e, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x5f, 0x6c, 0x6f, 0x61, 0x64, 19 | 0x5f, 0x75, 0x36, 0x34, 0x00, 0x09, 0x08, 0x73, 0x74, 0x6f, 0x72, 0x65, 20 | 0x5f, 0x75, 0x38, 0x00, 0x0a, 0x09, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x5f, 21 | 0x75, 0x36, 0x34, 0x00, 0x0b, 0x09, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x5f, 22 | 0x73, 0x65, 0x74, 0x00, 0x0c, 0x0a, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 23 | 0x5f, 0x73, 0x65, 0x74, 0x00, 0x0d, 0x0c, 0x69, 0x6e, 0x70, 0x75, 0x74, 24 | 0x5f, 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x00, 0x0e, 0x0c, 0x69, 0x6e, 25 | 0x70, 0x75, 0x74, 0x5f, 0x6f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x00, 0x0f, 26 | 0x0d, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x5f, 0x6c, 0x65, 0x6e, 0x67, 27 | 0x74, 0x68, 0x00, 0x10, 0x0d, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x5f, 28 | 0x6f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x00, 0x11, 0x05, 0x72, 0x65, 0x73, 29 | 0x65, 0x74, 0x00, 0x12, 0x09, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x5f, 0x73, 30 | 0x65, 0x74, 0x00, 0x13, 0x09, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x5f, 0x67, 31 | 0x65, 0x74, 0x00, 0x14, 0x0c, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x5f, 32 | 0x62, 0x79, 0x74, 0x65, 0x73, 0x00, 0x15, 0x0a, 0x5f, 0x5f, 0x64, 0x61, 33 | 0x74, 0x61, 0x5f, 0x65, 0x6e, 0x64, 0x03, 0x02, 0x0b, 0x5f, 0x5f, 0x68, 34 | 0x65, 0x61, 0x70, 0x5f, 0x62, 0x61, 0x73, 0x65, 0x03, 0x01, 0x0e, 0x65, 35 | 0x78, 0x74, 0x69, 0x73, 0x6d, 0x5f, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x78, 36 | 0x74, 0x03, 0x00, 0x0a, 0xe0, 0x17, 0x16, 0xb9, 0x01, 0x03, 0x01, 0x7f, 37 | 0x01, 0x7f, 0x01, 0x7f, 0x02, 0x40, 0x02, 0x40, 0x20, 0x02, 0x41, 0x10, 38 | 0x4f, 0x0d, 0x00, 0x20, 0x00, 0x21, 0x03, 0x0c, 0x01, 0x0b, 0x20, 0x00, 39 | 0x41, 0x00, 0x20, 0x00, 0x6b, 0x41, 0x03, 0x71, 0x22, 0x04, 0x6a, 0x21, 40 | 0x05, 0x02, 0x40, 0x20, 0x04, 0x45, 0x0d, 0x00, 0x20, 0x00, 0x21, 0x03, 41 | 0x03, 0x40, 0x20, 0x03, 0x20, 0x01, 0x3a, 0x00, 0x00, 0x20, 0x03, 0x41, 42 | 0x01, 0x6a, 0x22, 0x03, 0x20, 0x05, 0x49, 0x0d, 0x00, 0x0b, 0x0b, 0x20, 43 | 0x05, 0x20, 0x02, 0x20, 0x04, 0x6b, 0x22, 0x04, 0x41, 0x7c, 0x71, 0x22, 44 | 0x02, 0x6a, 0x21, 0x03, 0x02, 0x40, 0x20, 0x02, 0x41, 0x01, 0x48, 0x0d, 45 | 0x00, 0x20, 0x01, 0x41, 0xff, 0x01, 0x71, 0x41, 0x81, 0x82, 0x84, 0x08, 46 | 0x6c, 0x21, 0x02, 0x03, 0x40, 0x20, 0x05, 0x20, 0x02, 0x36, 0x02, 0x00, 47 | 0x20, 0x05, 0x41, 0x04, 0x6a, 0x22, 0x05, 0x20, 0x03, 0x49, 0x0d, 0x00, 48 | 0x0b, 0x0b, 0x20, 0x04, 0x41, 0x03, 0x71, 0x21, 0x02, 0x0b, 0x02, 0x40, 49 | 0x20, 0x02, 0x45, 0x0d, 0x00, 0x20, 0x03, 0x20, 0x02, 0x6a, 0x21, 0x05, 50 | 0x03, 0x40, 0x20, 0x03, 0x20, 0x01, 0x3a, 0x00, 0x00, 0x20, 0x03, 0x41, 51 | 0x01, 0x6a, 0x22, 0x03, 0x20, 0x05, 0x49, 0x0d, 0x00, 0x0b, 0x0b, 0x20, 52 | 0x00, 0x0b, 0x0a, 0x00, 0x20, 0x00, 0x20, 0x01, 0x20, 0x02, 0x10, 0x00, 53 | 0x0b, 0xdb, 0x03, 0x06, 0x01, 0x7f, 0x01, 0x7e, 0x01, 0x7e, 0x01, 0x7e, 54 | 0x01, 0x7f, 0x01, 0x7f, 0x02, 0x40, 0x20, 0x00, 0x50, 0x45, 0x0d, 0x00, 55 | 0x42, 0x00, 0x0f, 0x0b, 0x41, 0x00, 0x41, 0x00, 0x2d, 0x00, 0x01, 0x22, 56 | 0x01, 0x41, 0x01, 0x20, 0x01, 0x1b, 0x3a, 0x00, 0x01, 0x02, 0x40, 0x02, 57 | 0x40, 0x02, 0x40, 0x02, 0x40, 0x02, 0x40, 0x20, 0x01, 0x0d, 0x00, 0x02, 58 | 0x40, 0x3f, 0x00, 0x0d, 0x00, 0x41, 0x01, 0x40, 0x00, 0x41, 0x7f, 0x46, 59 | 0x0d, 0x02, 0x0b, 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 0x21, 0x41, 0x00, 60 | 0x42, 0x00, 0x37, 0x03, 0x29, 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 0x31, 61 | 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 0x39, 0x41, 0x00, 0x42, 0x00, 0x37, 62 | 0x03, 0x19, 0x41, 0x00, 0x42, 0xc0, 0xff, 0x03, 0x37, 0x03, 0x11, 0x41, 63 | 0x00, 0x42, 0x00, 0x37, 0x03, 0x09, 0x41, 0xc1, 0x00, 0x41, 0x00, 0x41, 64 | 0x90, 0x01, 0x10, 0x01, 0x1a, 0x0b, 0x41, 0x00, 0x29, 0x03, 0x11, 0x21, 65 | 0x02, 0x02, 0x40, 0x02, 0x40, 0x02, 0x40, 0x02, 0x40, 0x41, 0x00, 0x29, 66 | 0x03, 0x09, 0x22, 0x03, 0x42, 0xc1, 0x00, 0x7c, 0x22, 0x04, 0x42, 0xc2, 67 | 0x00, 0x54, 0x0d, 0x00, 0x20, 0x00, 0xa7, 0x21, 0x05, 0x41, 0xc1, 0x00, 68 | 0x21, 0x01, 0x03, 0x40, 0x02, 0x40, 0x02, 0x40, 0x02, 0x40, 0x20, 0x01, 69 | 0x2d, 0x00, 0x00, 0x0e, 0x03, 0x06, 0x00, 0x01, 0x00, 0x0b, 0x20, 0x01, 70 | 0x28, 0x02, 0x04, 0x21, 0x06, 0x0c, 0x01, 0x0b, 0x20, 0x01, 0x28, 0x02, 71 | 0x04, 0x22, 0x06, 0x20, 0x05, 0x4f, 0x0d, 0x03, 0x0b, 0x20, 0x04, 0x20, 72 | 0x01, 0x20, 0x06, 0x6a, 0x41, 0x0c, 0x6a, 0x22, 0x01, 0xad, 0x56, 0x0d, 73 | 0x00, 0x0b, 0x0b, 0x20, 0x00, 0x42, 0x0c, 0x7c, 0x22, 0x04, 0x20, 0x02, 74 | 0x20, 0x03, 0x7d, 0x42, 0x40, 0x7c, 0x22, 0x02, 0x5a, 0x0d, 0x02, 0x0c, 75 | 0x05, 0x0b, 0x20, 0x06, 0x20, 0x05, 0x6b, 0x22, 0x06, 0x41, 0x80, 0x01, 76 | 0x49, 0x0d, 0x00, 0x20, 0x01, 0x41, 0x00, 0x36, 0x02, 0x08, 0x20, 0x01, 77 | 0x20, 0x06, 0x41, 0x74, 0x6a, 0x22, 0x06, 0x36, 0x02, 0x04, 0x20, 0x01, 78 | 0x20, 0x06, 0x6a, 0x22, 0x01, 0x41, 0x14, 0x6a, 0x41, 0x00, 0x36, 0x02, 79 | 0x00, 0x20, 0x01, 0x41, 0x10, 0x6a, 0x20, 0x05, 0x36, 0x02, 0x00, 0x20, 80 | 0x01, 0x41, 0x0c, 0x6a, 0x22, 0x01, 0x41, 0x02, 0x3a, 0x00, 0x00, 0x0b, 81 | 0x20, 0x01, 0x41, 0x01, 0x3a, 0x00, 0x00, 0x20, 0x01, 0x20, 0x05, 0x36, 82 | 0x02, 0x08, 0x0c, 0x04, 0x0b, 0x20, 0x04, 0x20, 0x02, 0x7d, 0x22, 0x02, 83 | 0x42, 0xff, 0xff, 0x03, 0x83, 0x42, 0x00, 0x52, 0x20, 0x02, 0x42, 0x10, 84 | 0x88, 0xa7, 0x6a, 0x22, 0x01, 0x40, 0x00, 0x41, 0x7f, 0x47, 0x0d, 0x01, 85 | 0x41, 0x00, 0x21, 0x01, 0x0c, 0x03, 0x0b, 0x00, 0x0b, 0x41, 0x00, 0x41, 86 | 0x00, 0x29, 0x03, 0x11, 0x20, 0x01, 0xad, 0x42, 0x10, 0x86, 0x7c, 0x37, 87 | 0x03, 0x11, 0x0b, 0x41, 0x00, 0x41, 0x00, 0x29, 0x03, 0x09, 0x20, 0x04, 88 | 0x7c, 0x37, 0x03, 0x09, 0x20, 0x03, 0xa7, 0x22, 0x01, 0x41, 0xc9, 0x00, 89 | 0x6a, 0x20, 0x00, 0xa7, 0x22, 0x06, 0x36, 0x02, 0x00, 0x20, 0x01, 0x41, 90 | 0xc5, 0x00, 0x6a, 0x20, 0x06, 0x36, 0x02, 0x00, 0x20, 0x01, 0x41, 0xc1, 91 | 0x00, 0x6a, 0x22, 0x01, 0x41, 0x01, 0x3a, 0x00, 0x00, 0x0b, 0x20, 0x01, 92 | 0x41, 0x0c, 0x6a, 0xad, 0x42, 0x00, 0x20, 0x01, 0x1b, 0x0b, 0xea, 0x01, 93 | 0x03, 0x01, 0x7f, 0x01, 0x7e, 0x01, 0x7f, 0x02, 0x40, 0x02, 0x40, 0x20, 94 | 0x00, 0x42, 0x00, 0x51, 0x0d, 0x00, 0x41, 0x00, 0x41, 0x00, 0x2d, 0x00, 95 | 0x01, 0x22, 0x01, 0x41, 0x01, 0x20, 0x01, 0x1b, 0x3a, 0x00, 0x01, 0x02, 96 | 0x40, 0x20, 0x01, 0x0d, 0x00, 0x02, 0x40, 0x3f, 0x00, 0x0d, 0x00, 0x41, 97 | 0x01, 0x40, 0x00, 0x41, 0x7f, 0x46, 0x0d, 0x03, 0x0b, 0x41, 0x00, 0x42, 98 | 0x00, 0x37, 0x03, 0x21, 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 0x29, 0x41, 99 | 0x00, 0x42, 0x00, 0x37, 0x03, 0x31, 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 100 | 0x39, 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 0x19, 0x41, 0x00, 0x42, 0xc0, 101 | 0xff, 0x03, 0x37, 0x03, 0x11, 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 0x09, 102 | 0x41, 0xc1, 0x00, 0x41, 0x00, 0x41, 0x90, 0x01, 0x10, 0x01, 0x1a, 0x0b, 103 | 0x20, 0x00, 0x42, 0xc0, 0x00, 0x54, 0x0d, 0x00, 0x3f, 0x00, 0xad, 0x42, 104 | 0x10, 0x86, 0x20, 0x00, 0x54, 0x0d, 0x00, 0x20, 0x00, 0x42, 0xc1, 0x00, 105 | 0x7c, 0x21, 0x02, 0x41, 0xc1, 0x00, 0x21, 0x01, 0x02, 0x40, 0x03, 0x40, 106 | 0x20, 0x01, 0x41, 0x0c, 0x6a, 0x21, 0x03, 0x02, 0x40, 0x20, 0x01, 0x2d, 107 | 0x00, 0x00, 0x41, 0x01, 0x47, 0x0d, 0x00, 0x20, 0x03, 0xad, 0x20, 0x00, 108 | 0x51, 0x0d, 0x02, 0x0b, 0x20, 0x02, 0x20, 0x03, 0x20, 0x01, 0x28, 0x02, 109 | 0x04, 0x6a, 0x22, 0x01, 0xad, 0x56, 0x0d, 0x00, 0x0c, 0x02, 0x0b, 0x00, 110 | 0x0b, 0x20, 0x01, 0x41, 0x02, 0x3a, 0x00, 0x00, 0x41, 0x00, 0x29, 0x03, 111 | 0x21, 0x20, 0x00, 0x52, 0x0d, 0x00, 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 112 | 0x29, 0x0b, 0x0f, 0x0b, 0x00, 0x0b, 0x38, 0x02, 0x01, 0x7e, 0x01, 0x7f, 113 | 0x42, 0x00, 0x21, 0x01, 0x02, 0x40, 0x20, 0x00, 0x42, 0x3f, 0x58, 0x0d, 114 | 0x00, 0x3f, 0x00, 0xad, 0x42, 0x10, 0x86, 0x20, 0x00, 0x54, 0x0d, 0x00, 115 | 0x20, 0x00, 0xa7, 0x41, 0x74, 0x6a, 0x22, 0x02, 0x2d, 0x00, 0x00, 0x41, 116 | 0x01, 0x47, 0x0d, 0x00, 0x20, 0x02, 0x35, 0x02, 0x08, 0x21, 0x01, 0x0b, 117 | 0x20, 0x01, 0x0b, 0xd5, 0x01, 0x03, 0x01, 0x7f, 0x01, 0x7e, 0x01, 0x7f, 118 | 0x02, 0x40, 0x02, 0x40, 0x02, 0x40, 0x20, 0x00, 0x50, 0x0d, 0x00, 0x41, 119 | 0x00, 0x41, 0x00, 0x2d, 0x00, 0x01, 0x22, 0x01, 0x41, 0x01, 0x20, 0x01, 120 | 0x1b, 0x3a, 0x00, 0x01, 0x02, 0x40, 0x20, 0x01, 0x0d, 0x00, 0x02, 0x40, 121 | 0x3f, 0x00, 0x0d, 0x00, 0x41, 0x01, 0x40, 0x00, 0x41, 0x7f, 0x46, 0x0d, 122 | 0x04, 0x0b, 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 0x21, 0x41, 0x00, 0x42, 123 | 0x00, 0x37, 0x03, 0x29, 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 0x31, 0x41, 124 | 0x00, 0x42, 0x00, 0x37, 0x03, 0x39, 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 125 | 0x19, 0x41, 0x00, 0x42, 0xc0, 0xff, 0x03, 0x37, 0x03, 0x11, 0x41, 0x00, 126 | 0x42, 0x00, 0x37, 0x03, 0x09, 0x41, 0xc1, 0x00, 0x41, 0x00, 0x41, 0x90, 127 | 0x01, 0x10, 0x01, 0x1a, 0x0b, 0x20, 0x00, 0x42, 0xc0, 0x00, 0x54, 0x0d, 128 | 0x00, 0x3f, 0x00, 0xad, 0x42, 0x10, 0x86, 0x20, 0x00, 0x54, 0x0d, 0x00, 129 | 0x20, 0x00, 0x42, 0xc1, 0x00, 0x7c, 0x21, 0x02, 0x41, 0xc1, 0x00, 0x21, 130 | 0x01, 0x03, 0x40, 0x20, 0x01, 0x41, 0x0c, 0x6a, 0x21, 0x03, 0x02, 0x40, 131 | 0x20, 0x01, 0x2d, 0x00, 0x00, 0x41, 0x01, 0x47, 0x0d, 0x00, 0x20, 0x03, 132 | 0xad, 0x20, 0x00, 0x51, 0x0d, 0x03, 0x0b, 0x20, 0x02, 0x20, 0x03, 0x20, 133 | 0x01, 0x28, 0x02, 0x04, 0x6a, 0x22, 0x01, 0xad, 0x56, 0x0d, 0x00, 0x0b, 134 | 0x0b, 0x42, 0x00, 0x0f, 0x0b, 0x20, 0x01, 0x35, 0x02, 0x08, 0x0f, 0x0b, 135 | 0x00, 0x0b, 0x28, 0x01, 0x01, 0x7f, 0x41, 0x00, 0x21, 0x01, 0x02, 0x40, 136 | 0x20, 0x00, 0x42, 0xc0, 0x00, 0x54, 0x0d, 0x00, 0x3f, 0x00, 0xad, 0x42, 137 | 0x10, 0x86, 0x20, 0x00, 0x54, 0x0d, 0x00, 0x20, 0x00, 0xa7, 0x2d, 0x00, 138 | 0x00, 0x21, 0x01, 0x0b, 0x20, 0x01, 0x0b, 0x2f, 0x02, 0x01, 0x7e, 0x01, 139 | 0x7e, 0x42, 0x00, 0x21, 0x01, 0x02, 0x40, 0x20, 0x00, 0x42, 0x07, 0x7c, 140 | 0x22, 0x02, 0x42, 0xc0, 0x00, 0x54, 0x0d, 0x00, 0x20, 0x02, 0x3f, 0x00, 141 | 0xad, 0x42, 0x10, 0x86, 0x56, 0x0d, 0x00, 0x20, 0x00, 0xa7, 0x29, 0x03, 142 | 0x00, 0x21, 0x01, 0x0b, 0x20, 0x01, 0x0b, 0x92, 0x01, 0x02, 0x01, 0x7f, 143 | 0x01, 0x7f, 0x41, 0x00, 0x21, 0x01, 0x41, 0x00, 0x41, 0x00, 0x2d, 0x00, 144 | 0x01, 0x22, 0x02, 0x41, 0x01, 0x20, 0x02, 0x1b, 0x3a, 0x00, 0x01, 0x02, 145 | 0x40, 0x02, 0x40, 0x20, 0x02, 0x0d, 0x00, 0x02, 0x40, 0x3f, 0x00, 0x0d, 146 | 0x00, 0x41, 0x01, 0x40, 0x00, 0x41, 0x7f, 0x46, 0x0d, 0x02, 0x0b, 0x41, 147 | 0x00, 0x42, 0x00, 0x37, 0x03, 0x21, 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 148 | 0x29, 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 0x31, 0x41, 0x00, 0x42, 0x00, 149 | 0x37, 0x03, 0x39, 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 0x19, 0x41, 0x00, 150 | 0x42, 0xc0, 0xff, 0x03, 0x37, 0x03, 0x11, 0x41, 0x00, 0x42, 0x00, 0x37, 151 | 0x03, 0x09, 0x41, 0xc1, 0x00, 0x41, 0x00, 0x41, 0x90, 0x01, 0x10, 0x01, 152 | 0x1a, 0x0b, 0x02, 0x40, 0x41, 0x00, 0x29, 0x03, 0x29, 0x20, 0x00, 0x58, 153 | 0x0d, 0x00, 0x41, 0x00, 0x29, 0x03, 0x21, 0x20, 0x00, 0x7c, 0xa7, 0x2d, 154 | 0x00, 0x00, 0x21, 0x01, 0x0b, 0x20, 0x01, 0x0f, 0x0b, 0x00, 0x0b, 0x95, 155 | 0x01, 0x02, 0x01, 0x7f, 0x01, 0x7e, 0x41, 0x00, 0x41, 0x00, 0x2d, 0x00, 156 | 0x01, 0x22, 0x01, 0x41, 0x01, 0x20, 0x01, 0x1b, 0x3a, 0x00, 0x01, 0x02, 157 | 0x40, 0x02, 0x40, 0x20, 0x01, 0x0d, 0x00, 0x02, 0x40, 0x3f, 0x00, 0x0d, 158 | 0x00, 0x41, 0x01, 0x40, 0x00, 0x41, 0x7f, 0x46, 0x0d, 0x02, 0x0b, 0x41, 159 | 0x00, 0x42, 0x00, 0x37, 0x03, 0x21, 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 160 | 0x29, 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 0x31, 0x41, 0x00, 0x42, 0x00, 161 | 0x37, 0x03, 0x39, 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 0x19, 0x41, 0x00, 162 | 0x42, 0xc0, 0xff, 0x03, 0x37, 0x03, 0x11, 0x41, 0x00, 0x42, 0x00, 0x37, 163 | 0x03, 0x09, 0x41, 0xc1, 0x00, 0x41, 0x00, 0x41, 0x90, 0x01, 0x10, 0x01, 164 | 0x1a, 0x0b, 0x42, 0x00, 0x21, 0x02, 0x02, 0x40, 0x20, 0x00, 0x42, 0x08, 165 | 0x7c, 0x41, 0x00, 0x29, 0x03, 0x29, 0x56, 0x0d, 0x00, 0x41, 0x00, 0x29, 166 | 0x03, 0x21, 0x20, 0x00, 0x7c, 0xa7, 0x29, 0x03, 0x00, 0x21, 0x02, 0x0b, 167 | 0x20, 0x02, 0x0f, 0x0b, 0x00, 0x0b, 0x20, 0x00, 0x02, 0x40, 0x20, 0x00, 168 | 0x42, 0xc0, 0x00, 0x54, 0x0d, 0x00, 0x3f, 0x00, 0xad, 0x42, 0x10, 0x86, 169 | 0x20, 0x00, 0x54, 0x0d, 0x00, 0x20, 0x00, 0xa7, 0x20, 0x01, 0x3a, 0x00, 170 | 0x00, 0x0b, 0x0b, 0x27, 0x01, 0x01, 0x7e, 0x02, 0x40, 0x20, 0x00, 0x42, 171 | 0x07, 0x7c, 0x22, 0x02, 0x42, 0xc0, 0x00, 0x54, 0x0d, 0x00, 0x20, 0x02, 172 | 0x3f, 0x00, 0xad, 0x42, 0x10, 0x86, 0x56, 0x0d, 0x00, 0x20, 0x00, 0xa7, 173 | 0x20, 0x01, 0x37, 0x03, 0x00, 0x0b, 0x0b, 0xb6, 0x01, 0x02, 0x01, 0x7f, 174 | 0x01, 0x7e, 0x41, 0x00, 0x41, 0x00, 0x2d, 0x00, 0x01, 0x22, 0x02, 0x41, 175 | 0x01, 0x20, 0x02, 0x1b, 0x3a, 0x00, 0x01, 0x02, 0x40, 0x02, 0x40, 0x20, 176 | 0x02, 0x0d, 0x00, 0x02, 0x40, 0x3f, 0x00, 0x0d, 0x00, 0x41, 0x01, 0x40, 177 | 0x00, 0x41, 0x7f, 0x46, 0x0d, 0x02, 0x0b, 0x41, 0x00, 0x42, 0x00, 0x37, 178 | 0x03, 0x21, 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 0x29, 0x41, 0x00, 0x42, 179 | 0x00, 0x37, 0x03, 0x31, 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 0x39, 0x41, 180 | 0x00, 0x42, 0x00, 0x37, 0x03, 0x19, 0x41, 0x00, 0x42, 0xc0, 0xff, 0x03, 181 | 0x37, 0x03, 0x11, 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 0x09, 0x41, 0xc1, 182 | 0x00, 0x41, 0x00, 0x41, 0x90, 0x01, 0x10, 0x01, 0x1a, 0x0b, 0x02, 0x40, 183 | 0x20, 0x00, 0x42, 0xc1, 0x00, 0x54, 0x0d, 0x00, 0x41, 0x00, 0x29, 0x03, 184 | 0x11, 0x42, 0xc1, 0x00, 0x7c, 0x20, 0x00, 0x58, 0x0d, 0x00, 0x20, 0x00, 185 | 0x20, 0x01, 0x7c, 0x42, 0x7f, 0x7c, 0x22, 0x03, 0x42, 0xc1, 0x00, 0x54, 186 | 0x0d, 0x00, 0x41, 0x00, 0x29, 0x03, 0x11, 0x42, 0xc1, 0x00, 0x7c, 0x20, 187 | 0x03, 0x58, 0x0d, 0x00, 0x41, 0x00, 0x20, 0x00, 0x37, 0x03, 0x21, 0x41, 188 | 0x00, 0x20, 0x01, 0x37, 0x03, 0x29, 0x0b, 0x0f, 0x0b, 0x00, 0x0b, 0xb6, 189 | 0x01, 0x02, 0x01, 0x7f, 0x01, 0x7e, 0x41, 0x00, 0x41, 0x00, 0x2d, 0x00, 190 | 0x01, 0x22, 0x02, 0x41, 0x01, 0x20, 0x02, 0x1b, 0x3a, 0x00, 0x01, 0x02, 191 | 0x40, 0x02, 0x40, 0x20, 0x02, 0x0d, 0x00, 0x02, 0x40, 0x3f, 0x00, 0x0d, 192 | 0x00, 0x41, 0x01, 0x40, 0x00, 0x41, 0x7f, 0x46, 0x0d, 0x02, 0x0b, 0x41, 193 | 0x00, 0x42, 0x00, 0x37, 0x03, 0x21, 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 194 | 0x29, 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 0x31, 0x41, 0x00, 0x42, 0x00, 195 | 0x37, 0x03, 0x39, 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 0x19, 0x41, 0x00, 196 | 0x42, 0xc0, 0xff, 0x03, 0x37, 0x03, 0x11, 0x41, 0x00, 0x42, 0x00, 0x37, 197 | 0x03, 0x09, 0x41, 0xc1, 0x00, 0x41, 0x00, 0x41, 0x90, 0x01, 0x10, 0x01, 198 | 0x1a, 0x0b, 0x02, 0x40, 0x20, 0x00, 0x42, 0xc1, 0x00, 0x54, 0x0d, 0x00, 199 | 0x41, 0x00, 0x29, 0x03, 0x11, 0x42, 0xc1, 0x00, 0x7c, 0x20, 0x00, 0x58, 200 | 0x0d, 0x00, 0x20, 0x00, 0x20, 0x01, 0x7c, 0x42, 0x7f, 0x7c, 0x22, 0x03, 201 | 0x42, 0xc1, 0x00, 0x54, 0x0d, 0x00, 0x41, 0x00, 0x29, 0x03, 0x11, 0x42, 202 | 0xc1, 0x00, 0x7c, 0x20, 0x03, 0x58, 0x0d, 0x00, 0x41, 0x00, 0x20, 0x00, 203 | 0x37, 0x03, 0x31, 0x41, 0x00, 0x20, 0x01, 0x37, 0x03, 0x39, 0x0b, 0x0f, 204 | 0x0b, 0x00, 0x0b, 0x74, 0x01, 0x01, 0x7f, 0x41, 0x00, 0x41, 0x00, 0x2d, 205 | 0x00, 0x01, 0x22, 0x00, 0x41, 0x01, 0x20, 0x00, 0x1b, 0x3a, 0x00, 0x01, 206 | 0x02, 0x40, 0x02, 0x40, 0x20, 0x00, 0x0d, 0x00, 0x02, 0x40, 0x3f, 0x00, 207 | 0x0d, 0x00, 0x41, 0x01, 0x40, 0x00, 0x41, 0x7f, 0x46, 0x0d, 0x02, 0x0b, 208 | 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 0x21, 0x41, 0x00, 0x42, 0x00, 0x37, 209 | 0x03, 0x29, 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 0x31, 0x41, 0x00, 0x42, 210 | 0x00, 0x37, 0x03, 0x39, 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 0x19, 0x41, 211 | 0x00, 0x42, 0xc0, 0xff, 0x03, 0x37, 0x03, 0x11, 0x41, 0x00, 0x42, 0x00, 212 | 0x37, 0x03, 0x09, 0x41, 0xc1, 0x00, 0x41, 0x00, 0x41, 0x90, 0x01, 0x10, 213 | 0x01, 0x1a, 0x0b, 0x41, 0x00, 0x29, 0x03, 0x29, 0x0f, 0x0b, 0x00, 0x0b, 214 | 0x74, 0x01, 0x01, 0x7f, 0x41, 0x00, 0x41, 0x00, 0x2d, 0x00, 0x01, 0x22, 215 | 0x00, 0x41, 0x01, 0x20, 0x00, 0x1b, 0x3a, 0x00, 0x01, 0x02, 0x40, 0x02, 216 | 0x40, 0x20, 0x00, 0x0d, 0x00, 0x02, 0x40, 0x3f, 0x00, 0x0d, 0x00, 0x41, 217 | 0x01, 0x40, 0x00, 0x41, 0x7f, 0x46, 0x0d, 0x02, 0x0b, 0x41, 0x00, 0x42, 218 | 0x00, 0x37, 0x03, 0x21, 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 0x29, 0x41, 219 | 0x00, 0x42, 0x00, 0x37, 0x03, 0x31, 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 220 | 0x39, 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 0x19, 0x41, 0x00, 0x42, 0xc0, 221 | 0xff, 0x03, 0x37, 0x03, 0x11, 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 0x09, 222 | 0x41, 0xc1, 0x00, 0x41, 0x00, 0x41, 0x90, 0x01, 0x10, 0x01, 0x1a, 0x0b, 223 | 0x41, 0x00, 0x29, 0x03, 0x21, 0x0f, 0x0b, 0x00, 0x0b, 0x74, 0x01, 0x01, 224 | 0x7f, 0x41, 0x00, 0x41, 0x00, 0x2d, 0x00, 0x01, 0x22, 0x00, 0x41, 0x01, 225 | 0x20, 0x00, 0x1b, 0x3a, 0x00, 0x01, 0x02, 0x40, 0x02, 0x40, 0x20, 0x00, 226 | 0x0d, 0x00, 0x02, 0x40, 0x3f, 0x00, 0x0d, 0x00, 0x41, 0x01, 0x40, 0x00, 227 | 0x41, 0x7f, 0x46, 0x0d, 0x02, 0x0b, 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 228 | 0x21, 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 0x29, 0x41, 0x00, 0x42, 0x00, 229 | 0x37, 0x03, 0x31, 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 0x39, 0x41, 0x00, 230 | 0x42, 0x00, 0x37, 0x03, 0x19, 0x41, 0x00, 0x42, 0xc0, 0xff, 0x03, 0x37, 231 | 0x03, 0x11, 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 0x09, 0x41, 0xc1, 0x00, 232 | 0x41, 0x00, 0x41, 0x90, 0x01, 0x10, 0x01, 0x1a, 0x0b, 0x41, 0x00, 0x29, 233 | 0x03, 0x39, 0x0f, 0x0b, 0x00, 0x0b, 0x74, 0x01, 0x01, 0x7f, 0x41, 0x00, 234 | 0x41, 0x00, 0x2d, 0x00, 0x01, 0x22, 0x00, 0x41, 0x01, 0x20, 0x00, 0x1b, 235 | 0x3a, 0x00, 0x01, 0x02, 0x40, 0x02, 0x40, 0x20, 0x00, 0x0d, 0x00, 0x02, 236 | 0x40, 0x3f, 0x00, 0x0d, 0x00, 0x41, 0x01, 0x40, 0x00, 0x41, 0x7f, 0x46, 237 | 0x0d, 0x02, 0x0b, 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 0x21, 0x41, 0x00, 238 | 0x42, 0x00, 0x37, 0x03, 0x29, 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 0x31, 239 | 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 0x39, 0x41, 0x00, 0x42, 0x00, 0x37, 240 | 0x03, 0x19, 0x41, 0x00, 0x42, 0xc0, 0xff, 0x03, 0x37, 0x03, 0x11, 0x41, 241 | 0x00, 0x42, 0x00, 0x37, 0x03, 0x09, 0x41, 0xc1, 0x00, 0x41, 0x00, 0x41, 242 | 0x90, 0x01, 0x10, 0x01, 0x1a, 0x0b, 0x41, 0x00, 0x29, 0x03, 0x31, 0x0f, 243 | 0x0b, 0x00, 0x0b, 0xaa, 0x01, 0x01, 0x01, 0x7f, 0x41, 0x00, 0x41, 0x00, 244 | 0x2d, 0x00, 0x01, 0x22, 0x00, 0x41, 0x01, 0x20, 0x00, 0x1b, 0x3a, 0x00, 245 | 0x01, 0x02, 0x40, 0x02, 0x40, 0x20, 0x00, 0x0d, 0x00, 0x02, 0x40, 0x3f, 246 | 0x00, 0x0d, 0x00, 0x41, 0x01, 0x40, 0x00, 0x41, 0x7f, 0x46, 0x0d, 0x02, 247 | 0x0b, 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 0x21, 0x41, 0x00, 0x42, 0x00, 248 | 0x37, 0x03, 0x29, 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 0x31, 0x41, 0x00, 249 | 0x42, 0x00, 0x37, 0x03, 0x39, 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 0x19, 250 | 0x41, 0x00, 0x42, 0xc0, 0xff, 0x03, 0x37, 0x03, 0x11, 0x41, 0x00, 0x42, 251 | 0x00, 0x37, 0x03, 0x09, 0x41, 0xc1, 0x00, 0x41, 0x00, 0x41, 0x90, 0x01, 252 | 0x10, 0x01, 0x1a, 0x0b, 0x41, 0x00, 0x28, 0x02, 0x09, 0x21, 0x00, 0x41, 253 | 0x00, 0x42, 0x00, 0x37, 0x03, 0x09, 0x41, 0xc1, 0x00, 0x41, 0x00, 0x20, 254 | 0x00, 0x10, 0x01, 0x1a, 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 0x19, 0x41, 255 | 0x00, 0x42, 0x00, 0x37, 0x03, 0x39, 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 256 | 0x31, 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 0x29, 0x41, 0x00, 0x42, 0x00, 257 | 0x37, 0x03, 0x21, 0x0f, 0x0b, 0x00, 0x0b, 0x97, 0x01, 0x01, 0x01, 0x7f, 258 | 0x41, 0x00, 0x41, 0x00, 0x2d, 0x00, 0x01, 0x22, 0x01, 0x41, 0x01, 0x20, 259 | 0x01, 0x1b, 0x3a, 0x00, 0x01, 0x02, 0x40, 0x02, 0x40, 0x20, 0x01, 0x0d, 260 | 0x00, 0x02, 0x40, 0x3f, 0x00, 0x0d, 0x00, 0x41, 0x01, 0x40, 0x00, 0x41, 261 | 0x7f, 0x46, 0x0d, 0x02, 0x0b, 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 0x21, 262 | 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 0x29, 0x41, 0x00, 0x42, 0x00, 0x37, 263 | 0x03, 0x31, 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 0x39, 0x41, 0x00, 0x42, 264 | 0x00, 0x37, 0x03, 0x19, 0x41, 0x00, 0x42, 0xc0, 0xff, 0x03, 0x37, 0x03, 265 | 0x11, 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 0x09, 0x41, 0xc1, 0x00, 0x41, 266 | 0x00, 0x41, 0x90, 0x01, 0x10, 0x01, 0x1a, 0x0b, 0x02, 0x40, 0x02, 0x40, 267 | 0x20, 0x00, 0x50, 0x0d, 0x00, 0x20, 0x00, 0x42, 0xc1, 0x00, 0x54, 0x0d, 268 | 0x01, 0x41, 0x00, 0x29, 0x03, 0x11, 0x42, 0xc1, 0x00, 0x7c, 0x20, 0x00, 269 | 0x58, 0x0d, 0x01, 0x0b, 0x41, 0x00, 0x20, 0x00, 0x37, 0x03, 0x19, 0x0b, 270 | 0x0f, 0x0b, 0x00, 0x0b, 0x74, 0x01, 0x01, 0x7f, 0x41, 0x00, 0x41, 0x00, 271 | 0x2d, 0x00, 0x01, 0x22, 0x00, 0x41, 0x01, 0x20, 0x00, 0x1b, 0x3a, 0x00, 272 | 0x01, 0x02, 0x40, 0x02, 0x40, 0x20, 0x00, 0x0d, 0x00, 0x02, 0x40, 0x3f, 273 | 0x00, 0x0d, 0x00, 0x41, 0x01, 0x40, 0x00, 0x41, 0x7f, 0x46, 0x0d, 0x02, 274 | 0x0b, 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 0x21, 0x41, 0x00, 0x42, 0x00, 275 | 0x37, 0x03, 0x29, 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 0x31, 0x41, 0x00, 276 | 0x42, 0x00, 0x37, 0x03, 0x39, 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 0x19, 277 | 0x41, 0x00, 0x42, 0xc0, 0xff, 0x03, 0x37, 0x03, 0x11, 0x41, 0x00, 0x42, 278 | 0x00, 0x37, 0x03, 0x09, 0x41, 0xc1, 0x00, 0x41, 0x00, 0x41, 0x90, 0x01, 279 | 0x10, 0x01, 0x1a, 0x0b, 0x41, 0x00, 0x29, 0x03, 0x19, 0x0f, 0x0b, 0x00, 280 | 0x0b, 0x74, 0x01, 0x01, 0x7f, 0x41, 0x00, 0x41, 0x00, 0x2d, 0x00, 0x01, 281 | 0x22, 0x00, 0x41, 0x01, 0x20, 0x00, 0x1b, 0x3a, 0x00, 0x01, 0x02, 0x40, 282 | 0x02, 0x40, 0x20, 0x00, 0x0d, 0x00, 0x02, 0x40, 0x3f, 0x00, 0x0d, 0x00, 283 | 0x41, 0x01, 0x40, 0x00, 0x41, 0x7f, 0x46, 0x0d, 0x02, 0x0b, 0x41, 0x00, 284 | 0x42, 0x00, 0x37, 0x03, 0x21, 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 0x29, 285 | 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 0x31, 0x41, 0x00, 0x42, 0x00, 0x37, 286 | 0x03, 0x39, 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 0x19, 0x41, 0x00, 0x42, 287 | 0xc0, 0xff, 0x03, 0x37, 0x03, 0x11, 0x41, 0x00, 0x42, 0x00, 0x37, 0x03, 288 | 0x09, 0x41, 0xc1, 0x00, 0x41, 0x00, 0x41, 0x90, 0x01, 0x10, 0x01, 0x1a, 289 | 0x0b, 0x41, 0x00, 0x29, 0x03, 0x11, 0x0f, 0x0b, 0x00, 0x0b 290 | }; 291 | unsigned int extism_runtime_wasm_len = 3454; 292 | -------------------------------------------------------------------------------- /src/extism-wamr.h: -------------------------------------------------------------------------------- 1 | #ifndef _EXTISM_WAMR_H 2 | #define _EXTISM_WAMR_H 3 | 4 | #include 5 | #include 6 | 7 | // Extism plugin 8 | typedef struct ExtismPlugin ExtismPlugin; 9 | 10 | // Extism execution environment, this should be used as the first argument when 11 | // defining a host function 12 | typedef struct ExtismExecEnv ExtismExecEnv; 13 | 14 | // Status type 15 | typedef enum { 16 | ExtismStatusOk, 17 | ExtismStatusErr, 18 | ExtismStatusErrNoWasm, 19 | ExtismStatusErrUndefined, 20 | ExtismStatusCallFailed, 21 | } ExtismStatus; 22 | 23 | // Determines the maximum number of modules that can be specified in a manifest 24 | // at once 25 | #define EXTISM_MAX_LINKED_MODULES 4 26 | 27 | // Maximum number of config values 28 | #define EXTISM_MAX_CONFIG 16 29 | 30 | // `ExtismWasm` is used to specify Wasm data when creating plugins 31 | typedef struct { 32 | // Module name 33 | char *name; 34 | // Wasm module 35 | uint8_t *data; 36 | // Data length 37 | size_t length; 38 | } ExtismWasm; 39 | 40 | // `ExtismConfig` is used to store a key/value pair that can be accessed using 41 | // `extism_config_get` from inside a plugin 42 | typedef struct { 43 | const char *key; 44 | const char *value; 45 | } ExtismConfig; 46 | 47 | // `ExtismVar` is used to store a key/value pair that can be accessed using 48 | // `extism_var_get` and updated using `extism_var_set` from inside a plugin 49 | typedef struct { 50 | char *key; 51 | char *value; 52 | size_t length; 53 | } ExtismVar; 54 | 55 | // `ExtismMemoryConfig` can be used to specify the amount of memory a plugin 56 | // should be given access to 57 | typedef struct { 58 | uint32_t stack_size; 59 | size_t heap_size; 60 | } ExtismMemoryConfig; 61 | 62 | // `ExtismManifest` is used configure which Wasm module should be loaded 63 | typedef struct { 64 | // Wasm modules 65 | ExtismWasm wasm[EXTISM_MAX_LINKED_MODULES]; 66 | ExtismConfig config[EXTISM_MAX_CONFIG]; 67 | // Number of modules, an config items used 68 | size_t wasm_count, config_count; 69 | // Memory config 70 | ExtismMemoryConfig memory; 71 | } ExtismManifest; 72 | 73 | // Initializes an `ExtismManifest` value 74 | void extism_manifest_init(ExtismManifest *manifest, const ExtismWasm *wasm, 75 | size_t nwasm, const ExtismConfig *config, 76 | size_t nconfig, const ExtismMemoryConfig *memory); 77 | 78 | // Initiailze runtime, this must be called before anything else and only one 79 | // runtime can be initialized at a time 80 | void extism_runtime_init(); 81 | 82 | // Cleanup runtime initialized with `extism_runtime_init`, this cleans up 83 | // associated memory and unloads any host functions 84 | void extism_runtime_cleanup(); 85 | 86 | // Create a new plugin from a manifest, the `errbuf` is used to access any error 87 | // messages returned by WAMR 88 | ExtismPlugin *extism_plugin_new(const ExtismManifest *manifest, char *errbuf, 89 | size_t errlen); 90 | 91 | // Free a plugin 92 | void extism_plugin_free(ExtismPlugin *plugin); 93 | 94 | // Call a function with the given input 95 | ExtismStatus extism_plugin_call(ExtismPlugin *plugin, const char *func_name, 96 | const void *input, size_t input_length); 97 | 98 | // Similar to `extism_plugin_call` but allows passing WASI arguments/stdio 99 | ExtismStatus extism_plugin_call_wasi(ExtismPlugin *plugin, 100 | const char *func_name, const void *input, 101 | size_t input_length, char **argv, int argc, 102 | int stdinfd, int stdoutfd, int stderrfd); 103 | 104 | // Call a function with the given input and host context 105 | ExtismStatus extism_plugin_call_with_host_context(ExtismPlugin *plugin, 106 | const char *func_name, 107 | const void *input, 108 | size_t input_length, 109 | void *ctx); 110 | 111 | // Get the output of a plugin 112 | uint8_t *extism_plugin_output(ExtismPlugin *plugin, size_t *length); 113 | 114 | // Get the error result of a plugin 115 | const char *extism_plugin_error(ExtismPlugin *plugin, size_t *length); 116 | 117 | // Register a host function with the runtime 118 | void extism_host_function(const char *module, const char *name, 119 | const char *signature, void *func, void *user_data); 120 | 121 | // A pointer to the start of an allocation in Extism memory 122 | typedef uint64_t ExtismHandle; 123 | 124 | // Get host pointer given an Extism memory offset 125 | void *extism_plugin_memory(ExtismPlugin *plugin, ExtismHandle offs); 126 | 127 | // Allocate Extism memory 128 | ExtismHandle extism_plugin_memory_alloc(ExtismPlugin *plugin, void *data, 129 | size_t size); 130 | 131 | // Get length of allocation in Extism memory 132 | uint64_t extism_plugin_memory_length(ExtismPlugin *plugin, ExtismHandle offs); 133 | 134 | // Allocate Extism memory 135 | void extism_plugin_memory_free(ExtismPlugin *plugin, ExtismHandle offs); 136 | 137 | // Get user-data from inside host functions 138 | void *extism_host_function_data(ExtismExecEnv *env); 139 | 140 | // Get host context from inside a host function 141 | void *extism_host_context(ExtismExecEnv *env); 142 | 143 | // These functions are used to switch context between the kernel and plugin 144 | // modules in host functions, these shouldn't be needed in most cases. 145 | void extism_plugin_use_kernel(ExtismPlugin *); 146 | void extism_plugin_use_plugin(ExtismPlugin *); 147 | 148 | #endif // _EXTISM_WAMR_H 149 | -------------------------------------------------------------------------------- /src/extism.c: -------------------------------------------------------------------------------- 1 | #include "extism-wamr.h" 2 | #include "internal.h" 3 | 4 | #include 5 | 6 | // SYMBOLS contains the global runtime symbols, this is reset when 7 | // `extism_runtime_free` is called 8 | static struct Symbols SYMBOLS = {.capacity = 0, .length = 0}; 9 | 10 | static ExtismStatus init_plugin(ExtismPlugin *plugin, 11 | const ExtismManifest *manifest, char *errmsg, 12 | size_t errlen) { 13 | plugin->exec = NULL; 14 | plugin->instance = NULL; 15 | plugin->main = NULL; 16 | plugin->var_count = 0; 17 | plugin->module_count = manifest->wasm_count; 18 | plugin->manifest = manifest; 19 | 20 | // Initialize kernel 21 | init_kernel(&plugin->kernel, &manifest->memory); 22 | 23 | #define FN(name, args) \ 24 | {.symbol = #name, \ 25 | .signature = args, \ 26 | .func_ptr = k_##name, \ 27 | .attachment = plugin} 28 | NativeSymbol kernel[] = { 29 | FN(alloc, "(I)I"), FN(free, "(I)"), 30 | FN(output_set, "(II)"), FN(output_length, "()I"), 31 | FN(output_offset, "()I"), FN(input_set, "(I, I)"), 32 | FN(input_length, "()I"), FN(input_offset, "()I"), 33 | FN(load_u8, "(I)i"), FN(input_load_u8, "(I)i"), 34 | FN(load_u64, "(I)I"), FN(input_load_u64, "(I)I"), 35 | FN(store_u8, "(Ii)"), FN(store_u64, "(II)"), 36 | FN(error_set, "(I)"), FN(error_get, "()I"), 37 | FN(length, "(I)I"), FN(reset, "()"), 38 | FN(log_info, "(I)"), FN(log_debug, "(I)"), 39 | FN(log_warn, "(I)"), FN(log_error, "(I)"), 40 | FN(config_get, "(I)I"), FN(var_get, "(I)I"), 41 | FN(var_set, "(II)"), FN(http_request, "(II)I"), 42 | FN(http_status_code, "()i"), FN(length_unsafe, "(I)I")}; 43 | #undef FN 44 | size_t nkernel = sizeof(kernel) / sizeof(NativeSymbol); 45 | 46 | wasm_runtime_register_natives( 47 | "extism:host/env", add_symbols(&SYMBOLS, kernel, nkernel), nkernel); 48 | 49 | for (size_t i = 0; i < plugin->module_count; i++) { 50 | bool name_is_null = manifest->wasm[i].name == NULL; 51 | bool name_is_main = (!name_is_null && strlen(manifest->wasm[i].name) == 4 && 52 | strncmp(manifest->wasm[i].name, "main", 4) == 0); 53 | if (!name_is_null && !name_is_main) { 54 | LoadArgs args; 55 | args.name = manifest->wasm[i].name; 56 | plugin->modules[i] = 57 | wasm_runtime_load_ex(manifest->wasm[i].data, manifest->wasm[i].length, 58 | &args, errmsg, errlen); 59 | } else { 60 | plugin->modules[i] = wasm_runtime_load( 61 | manifest->wasm[i].data, manifest->wasm[i].length, errmsg, errlen); 62 | plugin->main = plugin->modules[i]; 63 | } 64 | } 65 | 66 | if (plugin->main == NULL) { 67 | return ExtismStatusErrNoWasm; 68 | } 69 | 70 | plugin->instance = 71 | wasm_runtime_instantiate(plugin->main, manifest->memory.stack_size / 2, 72 | manifest->memory.heap_size / 2, errmsg, errlen); 73 | if (plugin->instance == NULL) { 74 | puts(errmsg); 75 | return ExtismStatusErr; 76 | } 77 | 78 | plugin->exec = 79 | wasm_exec_env_create(plugin->instance, manifest->memory.stack_size); 80 | if (plugin->exec == NULL) { 81 | wasm_runtime_deinstantiate(plugin->instance); 82 | plugin->instance = NULL; 83 | return ExtismStatusErr; 84 | } 85 | 86 | // Initialize Haskell runtime 87 | wasm_function_inst_t hs_init = 88 | wasm_runtime_lookup_function(plugin->instance, "hs_init"); 89 | if (hs_init != NULL) { 90 | wasm_val_t params[] = {{.kind = WASM_I32, .of = {.i32 = 0}}, 91 | {.kind = WASM_I32, .of = {.i32 = 0}}}; 92 | wasm_runtime_call_wasm_a(plugin->exec, hs_init, 0, NULL, 2, params); 93 | } 94 | 95 | return ExtismStatusOk; 96 | } 97 | 98 | ExtismPlugin *extism_plugin_new(const ExtismManifest *manifest, char *errmsg, 99 | size_t errlen) { 100 | ExtismPlugin *plugin = os_malloc(sizeof(ExtismPlugin)); 101 | if (init_plugin(plugin, manifest, errmsg, errlen) != ExtismStatusOk) { 102 | extism_plugin_free(plugin); 103 | return NULL; 104 | } 105 | return plugin; 106 | } 107 | 108 | static void cleanup_kernel(struct ExtismKernel *kernel) { 109 | if (kernel->instance) { 110 | wasm_runtime_deinstantiate(kernel->instance); 111 | } 112 | if (kernel->module) { 113 | wasm_runtime_unload(kernel->module); 114 | } 115 | } 116 | 117 | static void cleanup_plugin(ExtismPlugin *plugin) { 118 | if (plugin->exec) { 119 | wasm_function_inst_t hs_exit = 120 | wasm_runtime_lookup_function(plugin->instance, "hs_exit"); 121 | if (hs_exit != NULL) { 122 | 123 | wasm_runtime_call_wasm_a(plugin->exec, hs_exit, 0, NULL, 0, NULL); 124 | } 125 | 126 | wasm_exec_env_destroy(plugin->exec); 127 | } 128 | 129 | if (plugin->instance) { 130 | wasm_runtime_deinstantiate(plugin->instance); 131 | } 132 | 133 | for (size_t i = 0; i < plugin->module_count; i++) { 134 | wasm_runtime_unload(plugin->modules[i]); 135 | } 136 | 137 | for (size_t i = 0; i < plugin->var_count; i++) { 138 | os_free(plugin->vars[i].key); 139 | os_free(plugin->vars[i].value); 140 | } 141 | 142 | cleanup_kernel(&plugin->kernel); 143 | } 144 | 145 | void extism_plugin_free(ExtismPlugin *plugin) { 146 | cleanup_plugin(plugin); 147 | os_free(plugin); 148 | } 149 | 150 | uint64_t plugin_alloc(ExtismPlugin *plugin, const void *s, size_t size) { 151 | wasm_val_t params[] = {{.kind = WASM_I64, .of = {.i64 = size}}}; 152 | wasm_val_t results[] = {{.kind = WASM_I64, .of = {.i64 = 0}}}; 153 | extism_plugin_use_kernel(plugin); 154 | assert(wasm_runtime_call_wasm_a(plugin->exec, plugin->kernel.alloc, 1, 155 | results, 1, params)); 156 | uint64_t offset = results[0].of.i64; 157 | if (offset == 0) { 158 | return 0; 159 | } 160 | 161 | if (s) { 162 | memcpy(extism_plugin_memory(plugin, offset), s, size); 163 | } 164 | 165 | extism_plugin_use_plugin(plugin); 166 | return offset; 167 | } 168 | 169 | static void plugin_set_input(ExtismPlugin *plugin, uint64_t offs, 170 | size_t length) { 171 | wasm_val_t params[] = {{.kind = WASM_I64, .of = {.i64 = offs}}, 172 | {.kind = WASM_I64, .of = {.i64 = length}}}; 173 | WITH_KERNEL(plugin, 174 | wasm_runtime_call_wasm_a(plugin->exec, plugin->kernel.input_set, 175 | 0, NULL, 2, params)); 176 | } 177 | 178 | static uint64_t plugin_output_offset(ExtismPlugin *plugin) { 179 | wasm_val_t results[] = {{.kind = WASM_I64, .of = {.i64 = 0}}}; 180 | WITH_KERNEL(plugin, wasm_runtime_call_wasm_a(plugin->exec, 181 | plugin->kernel.output_offset, 1, 182 | results, 0, NULL)); 183 | return results[0].of.i64; 184 | } 185 | 186 | static uint64_t plugin_output_length(ExtismPlugin *plugin) { 187 | wasm_val_t results[] = {{.kind = WASM_I64, .of = {.i64 = 0}}}; 188 | WITH_KERNEL(plugin, wasm_runtime_call_wasm_a(plugin->exec, 189 | plugin->kernel.output_length, 1, 190 | results, 0, NULL)); 191 | return results[0].of.i64; 192 | } 193 | 194 | static uint64_t plugin_length(ExtismPlugin *plugin, uint64_t offs) { 195 | wasm_val_t params[] = {{.kind = WASM_I64, .of = {.i64 = offs}}}; 196 | wasm_val_t results[] = {{.kind = WASM_I64, .of = {.i64 = 0}}}; 197 | WITH_KERNEL(plugin, 198 | wasm_runtime_call_wasm_a(plugin->exec, plugin->kernel.length, 1, 199 | results, 1, params)); 200 | return results[0].of.i64; 201 | } 202 | 203 | static uint64_t plugin_error(ExtismPlugin *plugin) { 204 | wasm_val_t results[] = {{.kind = WASM_I64, .of = {.i64 = 0}}}; 205 | WITH_KERNEL(plugin, 206 | wasm_runtime_call_wasm_a(plugin->exec, plugin->kernel.error_get, 207 | 1, results, 0, NULL)); 208 | return results[0].of.i64; 209 | } 210 | 211 | void plugin_set_error(ExtismPlugin *plugin, const char *s) { 212 | uint64_t offs = plugin_alloc(plugin, s, strlen(s)); 213 | wasm_val_t params[] = {{.kind = WASM_I64, .of = {.i64 = offs}}}; 214 | WITH_KERNEL(plugin, 215 | wasm_runtime_call_wasm_a(plugin->exec, plugin->kernel.error_set, 216 | 0, NULL, 1, params)); 217 | } 218 | 219 | static void plugin_reset(ExtismPlugin *plugin) { 220 | WITH_KERNEL(plugin, 221 | wasm_runtime_call_wasm_a(plugin->exec, plugin->kernel.reset, 0, 222 | NULL, 0, NULL)); 223 | } 224 | 225 | ExtismStatus extism_plugin_call(ExtismPlugin *plugin, const char *func_name, 226 | const void *input, size_t input_length) { 227 | return extism_plugin_call_with_host_context(plugin, func_name, input, 228 | input_length, NULL); 229 | } 230 | 231 | ExtismStatus extism_plugin_call_with_host_context(ExtismPlugin *plugin, 232 | const char *func_name, 233 | const void *input, 234 | size_t input_length, 235 | void *ctx) { 236 | wasm_function_inst_t f = 237 | wasm_runtime_lookup_function(plugin->instance, func_name); 238 | if (f == NULL) { 239 | plugin_set_error(plugin, "Function is undefined"); 240 | return ExtismStatusErrUndefined; 241 | } 242 | 243 | plugin_reset(plugin); 244 | uint64_t input_offs = plugin_alloc(plugin, input, input_length); 245 | plugin_set_input(plugin, input_offs, input_length); 246 | 247 | wasm_val_t results[] = {{.kind = WASM_I32, .of = {.i32 = 0}}}; 248 | 249 | uint32_t result_count = wasm_func_get_result_count(f, plugin->instance); 250 | 251 | wasm_global_inst_t host_ctx; 252 | if (wasm_runtime_get_export_global_inst(plugin->kernel.instance, 253 | "extism_context", &host_ctx)) { 254 | host_ctx.global_data = ctx; 255 | } 256 | 257 | extism_plugin_use_plugin(plugin); 258 | if (!wasm_runtime_call_wasm_a(plugin->exec, f, result_count, results, 0, 259 | NULL)) { 260 | plugin_set_error(plugin, wasm_runtime_get_exception(plugin->instance)); 261 | return ExtismStatusCallFailed; 262 | } 263 | 264 | return ExtismStatusOk; 265 | } 266 | 267 | ExtismStatus extism_plugin_call_wasi(ExtismPlugin *plugin, 268 | const char *func_name, const void *input, 269 | size_t input_length, char **argv, int argc, 270 | int stdinfd, int stdoutfd, int stderrfd) { 271 | wasm_runtime_set_wasi_args_ex(plugin->main, NULL, 0, NULL, 0, NULL, 0, argv, 272 | argc, stdinfd, stdoutfd, stderrfd); 273 | return extism_plugin_call(plugin, func_name, input, input_length); 274 | } 275 | 276 | uint8_t *extism_plugin_output(ExtismPlugin *plugin, size_t *length) { 277 | if (length) { 278 | *length = plugin_output_length(plugin); 279 | } 280 | uint64_t offs = plugin_output_offset(plugin); 281 | return wasm_runtime_addr_app_to_native(plugin->kernel.instance, offs); 282 | } 283 | 284 | const char *extism_plugin_error(ExtismPlugin *plugin, size_t *length) { 285 | uint64_t offs = plugin_error(plugin); 286 | if (offs == 0) { 287 | return NULL; 288 | } 289 | size_t errlen = plugin_length(plugin, offs); 290 | if (length) { 291 | *length = errlen; 292 | } 293 | return wasm_runtime_addr_app_to_native(plugin->kernel.instance, offs); 294 | } 295 | 296 | // Adds a function to `SYMBOLS` 297 | void extism_host_function(const char *module, const char *name, 298 | const char *signature, void *func, void *user_data) { 299 | NativeSymbol f; 300 | f.symbol = name; 301 | f.attachment = user_data; 302 | f.func_ptr = func; 303 | f.signature = signature; 304 | wasm_runtime_register_natives(module, add_symbols(&SYMBOLS, &f, 1), 1); 305 | } 306 | 307 | // Get host pointer 308 | void *extism_plugin_memory(ExtismPlugin *plugin, uint64_t offs) { 309 | void *ptr = NULL; 310 | WITH_KERNEL(plugin, { 311 | ptr = wasm_runtime_addr_app_to_native(plugin->kernel.instance, offs); 312 | }); 313 | return ptr; 314 | } 315 | 316 | // Allocate Extism memory 317 | uint64_t extism_plugin_memory_alloc(ExtismPlugin *plugin, void *data, 318 | size_t size) { 319 | return plugin_alloc(plugin, data, size); 320 | } 321 | 322 | // Get length of allocation in Extism memory 323 | uint64_t extism_plugin_memory_length(ExtismPlugin *plugin, uint64_t offs) { 324 | return plugin_length(plugin, offs); 325 | } 326 | 327 | // Allocate Extism memory 328 | void extism_plugin_memory_free(ExtismPlugin *plugin, uint64_t offs) { 329 | wasm_val_t params[] = {{.kind = WASM_I64, .of = {.i64 = offs}}}; 330 | WITH_KERNEL(plugin, 331 | wasm_runtime_call_wasm_a(plugin->exec, plugin->kernel.length, 0, 332 | NULL, 1, params)); 333 | } 334 | 335 | void extism_manifest_init(ExtismManifest *manifest, const ExtismWasm *wasm, 336 | size_t nwasm, const ExtismConfig *config, 337 | size_t nconfig, const ExtismMemoryConfig *memory) { 338 | if (memory) { 339 | manifest->memory.stack_size = memory->stack_size; 340 | manifest->memory.heap_size = memory->heap_size; 341 | } else { 342 | manifest->memory.stack_size = 4096 * 2; 343 | manifest->memory.heap_size = 65536 * 10; 344 | } 345 | 346 | assert(nwasm <= EXTISM_MAX_LINKED_MODULES); 347 | memcpy(manifest->wasm, wasm, nwasm * sizeof(ExtismWasm)); 348 | manifest->wasm_count = nwasm; 349 | 350 | assert(nconfig <= EXTISM_MAX_CONFIG); 351 | memcpy(manifest->config, config, nconfig * sizeof(ExtismConfig)); 352 | manifest->config_count = nconfig; 353 | } 354 | 355 | void extism_plugin_use_kernel(ExtismPlugin *plugin) { 356 | wasm_runtime_set_module_inst(plugin->exec, plugin->kernel.instance); 357 | } 358 | 359 | void extism_plugin_use_plugin(ExtismPlugin *plugin) { 360 | wasm_runtime_set_module_inst(plugin->exec, plugin->instance); 361 | } 362 | 363 | void extism_runtime_init() { 364 | init_symbols(&SYMBOLS, 32); 365 | #ifdef ESP32 366 | RuntimeInitArgs init; 367 | memset(&init, 0, sizeof(RuntimeInitArgs)); 368 | init.mem_alloc_type = Alloc_With_Allocator; 369 | init.mem_alloc_option.allocator.malloc_func = (void *)os_malloc; 370 | init.mem_alloc_option.allocator.realloc_func = (void *)os_realloc; 371 | init.mem_alloc_option.allocator.free_func = (void *)os_free; 372 | wasm_runtime_full_init(&init); 373 | #else 374 | wasm_runtime_init(); 375 | #endif 376 | } 377 | 378 | void extism_runtime_cleanup() { 379 | wasm_runtime_destroy(); 380 | reset_symbols(&SYMBOLS); 381 | } 382 | 383 | void *extism_host_function_data(ExtismExecEnv *env) { 384 | return wasm_runtime_get_function_attachment((wasm_exec_env_t)env); 385 | } 386 | -------------------------------------------------------------------------------- /src/internal.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "extism-wamr.h" 3 | 4 | #include "wasm_exec_env.h" 5 | #include "wasm_native.h" 6 | 7 | #include 8 | 9 | struct ExtismKernel { 10 | wasm_module_t module; 11 | wasm_module_inst_t instance; 12 | wasm_function_inst_t alloc; 13 | wasm_function_inst_t free; 14 | wasm_function_inst_t length; 15 | wasm_function_inst_t length_unsafe; 16 | wasm_function_inst_t reset; 17 | wasm_function_inst_t input_offset; 18 | wasm_function_inst_t input_length; 19 | wasm_function_inst_t input_set; 20 | wasm_function_inst_t output_offset; 21 | wasm_function_inst_t output_length; 22 | wasm_function_inst_t output_set; 23 | wasm_function_inst_t error_set; 24 | wasm_function_inst_t error_get; 25 | wasm_function_inst_t load_u8; 26 | wasm_function_inst_t input_load_u8; 27 | wasm_function_inst_t store_u8; 28 | wasm_function_inst_t load_u64; 29 | wasm_function_inst_t input_load_u64; 30 | wasm_function_inst_t store_u64; 31 | }; 32 | 33 | typedef struct ExtismPlugin { 34 | ExtismVar vars[EXTISM_MAX_CONFIG]; 35 | size_t var_count; 36 | const ExtismManifest *manifest; 37 | struct ExtismKernel kernel; 38 | wasm_module_t modules[EXTISM_MAX_LINKED_MODULES]; 39 | wasm_module_t main; 40 | size_t module_count; 41 | wasm_exec_env_t exec; 42 | wasm_module_inst_t instance; 43 | } ExtismPlugin; 44 | 45 | void init_kernel(struct ExtismKernel *kernel, const ExtismMemoryConfig *memory); 46 | void link_kernel(ExtismPlugin *plugin); 47 | uint64_t k_alloc(wasm_exec_env_t env, uint64_t size); 48 | void k_reset(wasm_exec_env_t env); 49 | void k_free(wasm_exec_env_t env, uint64_t offs); 50 | uint64_t k_length(wasm_exec_env_t env, uint64_t offs); 51 | uint64_t k_length_unsafe(wasm_exec_env_t env, uint64_t offs); 52 | void k_output_set(wasm_exec_env_t env, uint64_t offs, uint64_t length); 53 | uint64_t k_output_length(wasm_exec_env_t env); 54 | uint64_t k_output_offset(wasm_exec_env_t env); 55 | void k_input_set(wasm_exec_env_t env, uint64_t offs, uint64_t length); 56 | uint64_t k_input_length(wasm_exec_env_t env); 57 | uint64_t k_input_offset(wasm_exec_env_t env); 58 | uint32_t k_load_u8(wasm_exec_env_t env, uint64_t offs); 59 | uint32_t k_input_load_u8(wasm_exec_env_t env, uint64_t offs); 60 | uint64_t k_load_u64(wasm_exec_env_t env, uint64_t offs); 61 | uint64_t k_input_load_u64(wasm_exec_env_t env, uint64_t offs); 62 | void k_store_u8(wasm_exec_env_t env, uint64_t offs, uint32_t ch); 63 | void k_store_u64(wasm_exec_env_t env, uint64_t offs, uint64_t v); 64 | uint64_t k_error_get(wasm_exec_env_t env); 65 | void k_error_set(wasm_exec_env_t env, uint64_t offs); 66 | void k_log_warn(wasm_exec_env_t env, uint64_t msg); 67 | void k_log_info(wasm_exec_env_t env, uint64_t msg); 68 | void k_log_debug(wasm_exec_env_t env, uint64_t msg); 69 | void k_log_error(wasm_exec_env_t env, uint64_t msg); 70 | uint64_t k_config_get(wasm_exec_env_t env, uint64_t k); 71 | uint64_t k_var_get(wasm_exec_env_t env, uint64_t k); 72 | void k_var_set(wasm_exec_env_t env, uint64_t k, uint64_t v); 73 | uint64_t k_http_request(wasm_exec_env_t env, uint64_t req, uint64_t body); 74 | uint32_t k_http_status_code(wasm_exec_env_t env); 75 | 76 | void plugin_set_error(ExtismPlugin *plugin, const char *s); 77 | uint64_t plugin_alloc(ExtismPlugin *plugin, const void *s, size_t size); 78 | 79 | #define WITH_KERNEL(plugin, x) \ 80 | extism_plugin_use_kernel(plugin); \ 81 | x; \ 82 | extism_plugin_use_plugin(plugin); 83 | 84 | struct Symbols { 85 | NativeSymbol *symbols; 86 | size_t length, capacity; 87 | }; 88 | 89 | void init_symbols(struct Symbols *symbols, size_t total); 90 | NativeSymbol *add_symbols(struct Symbols *s, const NativeSymbol *sym, size_t n); 91 | void reset_symbols(struct Symbols *s); 92 | -------------------------------------------------------------------------------- /src/kernel.c: -------------------------------------------------------------------------------- 1 | #include "internal.h" 2 | 3 | #include "extism-runtime.h" 4 | #include "lib_export.h" 5 | 6 | #include 7 | #include 8 | 9 | #if defined(__arm__) || defined(__aarch64__) 10 | static uint64_t read_u64(const void *ptr) { 11 | union { 12 | uint64_t n; 13 | char data[8]; 14 | } tmp; 15 | const char *cp = (const char *)ptr; 16 | tmp.data[0] = *cp++; 17 | tmp.data[1] = *cp++; 18 | tmp.data[2] = *cp++; 19 | tmp.data[3] = *cp++; 20 | tmp.data[4] = *cp++; 21 | tmp.data[5] = *cp++; 22 | tmp.data[6] = *cp++; 23 | tmp.data[7] = *cp; 24 | return tmp.n; 25 | } 26 | static void write_u64(void *ptr, uint64_t x) { 27 | union { 28 | uint64_t n; 29 | char data[8]; 30 | } tmp; 31 | tmp.n = x; 32 | char *cp = (char *)ptr; 33 | *cp++ = tmp.data[0]; 34 | *cp++ = tmp.data[1]; 35 | *cp++ = tmp.data[2]; 36 | *cp++ = tmp.data[3]; 37 | *cp++ = tmp.data[4]; 38 | *cp++ = tmp.data[5]; 39 | *cp++ = tmp.data[6]; 40 | *cp++ = tmp.data[7]; 41 | } 42 | #else 43 | static uint64_t read_u64(const void *x) { return *(uint64_t *)x; } 44 | static void write_u64(void *ptr, uint64_t x) { *(uint64_t *)ptr = x; } 45 | #endif 46 | 47 | // KERNEL_CALL depends on `plugin` and `kernel` variables 48 | #define KERNEL_CALL(x) \ 49 | WITH_KERNEL(plugin, { \ 50 | if (!x) { \ 51 | const char *s = wasm_runtime_get_exception(kernel->instance); \ 52 | plugin_set_error(plugin, s); \ 53 | extism_plugin_use_plugin(plugin); \ 54 | wasm_runtime_set_exception(plugin->instance, s); \ 55 | wasm_runtime_terminate(plugin->instance); \ 56 | } \ 57 | }) 58 | 59 | #define KERNEL_INIT(p, k) \ 60 | ExtismPlugin *p = wasm_runtime_get_function_attachment(env); \ 61 | struct ExtismKernel *k = &p->kernel; 62 | 63 | uint64_t k_alloc(wasm_exec_env_t env, uint64_t size) { 64 | KERNEL_INIT(plugin, kernel); 65 | wasm_val_t params[] = {{.kind = WASM_I64, .of = {.i64 = size}}}; 66 | wasm_val_t results[] = {{.kind = WASM_I64, .of = {.i64 = 0}}}; 67 | KERNEL_CALL( 68 | wasm_runtime_call_wasm_a(env, kernel->alloc, 1, results, 1, params)); 69 | return results[0].of.i64; 70 | } 71 | 72 | void k_reset(wasm_exec_env_t env) { 73 | KERNEL_INIT(plugin, kernel); 74 | KERNEL_CALL(wasm_runtime_call_wasm_a(env, kernel->reset, 0, NULL, 0, NULL)); 75 | } 76 | 77 | void k_free(wasm_exec_env_t env, uint64_t offs) { 78 | KERNEL_INIT(plugin, kernel); 79 | wasm_val_t params[] = {{.kind = WASM_I64, .of = {.i64 = offs}}}; 80 | KERNEL_CALL(wasm_runtime_call_wasm_a(env, kernel->free, 0, NULL, 1, params)); 81 | } 82 | 83 | uint64_t k_length(wasm_exec_env_t env, uint64_t offs) { 84 | KERNEL_INIT(plugin, kernel); 85 | wasm_val_t params[] = {{.kind = WASM_I64, .of = {.i64 = offs}}}; 86 | wasm_val_t results[] = {{.kind = WASM_I64, .of = {.i64 = 0}}}; 87 | KERNEL_CALL( 88 | wasm_runtime_call_wasm_a(env, kernel->length, 1, results, 1, params)); 89 | return results[0].of.i64; 90 | } 91 | 92 | uint64_t k_length_unsafe(wasm_exec_env_t env, uint64_t offs) { 93 | KERNEL_INIT(plugin, kernel); 94 | wasm_val_t params[] = {{.kind = WASM_I64, .of = {.i64 = offs}}}; 95 | wasm_val_t results[] = {{.kind = WASM_I64, .of = {.i64 = 0}}}; 96 | KERNEL_CALL(wasm_runtime_call_wasm_a(env, kernel->length_unsafe, 1, results, 97 | 1, params)); 98 | return results[0].of.i64; 99 | } 100 | 101 | void k_output_set(wasm_exec_env_t env, uint64_t offs, uint64_t length) { 102 | KERNEL_INIT(plugin, kernel); 103 | wasm_val_t params[] = {{.kind = WASM_I64, .of = {.i64 = offs}}, 104 | {.kind = WASM_I64, .of = {.i64 = length}}}; 105 | KERNEL_CALL( 106 | wasm_runtime_call_wasm_a(env, kernel->output_set, 0, NULL, 2, params)); 107 | } 108 | 109 | uint64_t k_output_length(wasm_exec_env_t env) { 110 | KERNEL_INIT(plugin, kernel); 111 | wasm_val_t results[] = {{.kind = WASM_I64, .of = {.i64 = 0}}}; 112 | KERNEL_CALL(wasm_runtime_call_wasm_a(env, kernel->output_length, 1, results, 113 | 0, NULL)); 114 | return results[0].of.i64; 115 | } 116 | 117 | uint64_t k_output_offset(wasm_exec_env_t env) { 118 | KERNEL_INIT(plugin, kernel); 119 | wasm_val_t results[] = {{.kind = WASM_I64, .of = {.i64 = 0}}}; 120 | KERNEL_CALL(wasm_runtime_call_wasm_a(env, kernel->output_offset, 1, results, 121 | 0, NULL)); 122 | return results[0].of.i64; 123 | } 124 | 125 | void k_input_set(wasm_exec_env_t env, uint64_t offs, uint64_t length) { 126 | KERNEL_INIT(plugin, kernel); 127 | wasm_val_t params[] = {{.kind = WASM_I64, .of = {.i64 = offs}}, 128 | {.kind = WASM_I64, .of = {.i64 = length}}}; 129 | KERNEL_CALL( 130 | wasm_runtime_call_wasm_a(env, kernel->input_set, 0, NULL, 2, params)); 131 | } 132 | 133 | uint64_t k_input_length(wasm_exec_env_t env) { 134 | KERNEL_INIT(plugin, kernel); 135 | wasm_val_t results[] = {{.kind = WASM_I64, .of = {.i64 = 0}}}; 136 | KERNEL_CALL( 137 | wasm_runtime_call_wasm_a(env, kernel->input_length, 1, results, 0, NULL)); 138 | return results[0].of.i64; 139 | } 140 | 141 | uint64_t k_input_offset(wasm_exec_env_t env) { 142 | KERNEL_INIT(plugin, kernel); 143 | wasm_val_t results[] = {{.kind = WASM_I64, .of = {.i64 = 0}}}; 144 | KERNEL_CALL( 145 | wasm_runtime_call_wasm_a(env, kernel->input_offset, 1, results, 0, NULL)); 146 | return results[0].of.i64; 147 | } 148 | 149 | uint32_t k_load_u8(wasm_exec_env_t env, uint64_t offs) { 150 | KERNEL_INIT(plugin, kernel); 151 | (void)kernel; 152 | uint8_t *ptr = extism_plugin_memory(plugin, offs); 153 | return ptr[0]; 154 | } 155 | 156 | uint32_t k_input_load_u8(wasm_exec_env_t env, uint64_t offs) { 157 | KERNEL_INIT(plugin, kernel); 158 | uint64_t x = k_input_offset(env); 159 | (void)kernel; 160 | uint8_t *ptr = extism_plugin_memory(plugin, x + offs); 161 | return ptr[0]; 162 | } 163 | 164 | uint64_t k_load_u64(wasm_exec_env_t env, uint64_t offs) { 165 | KERNEL_INIT(plugin, kernel); 166 | (void)kernel; 167 | uint8_t *ptr = extism_plugin_memory(plugin, offs); 168 | return read_u64(ptr); 169 | } 170 | 171 | uint64_t k_input_load_u64(wasm_exec_env_t env, uint64_t offs) { 172 | KERNEL_INIT(plugin, kernel); 173 | uint64_t input_offs = k_input_offset(env); 174 | (void)kernel; 175 | uint8_t *ptr = extism_plugin_memory(plugin, input_offs + offs); 176 | return read_u64(ptr); 177 | } 178 | 179 | void k_store_u8(wasm_exec_env_t env, uint64_t offs, uint32_t ch) { 180 | KERNEL_INIT(plugin, kernel); 181 | (void)kernel; 182 | uint8_t *ptr = extism_plugin_memory(plugin, offs); 183 | ptr[0] = (uint8_t)ch; 184 | } 185 | 186 | void k_store_u64(wasm_exec_env_t env, uint64_t offs, uint64_t v) { 187 | KERNEL_INIT(plugin, kernel); 188 | (void)kernel; 189 | uint8_t *ptr = extism_plugin_memory(plugin, offs); 190 | write_u64(ptr, v); 191 | } 192 | 193 | uint64_t k_error_get(wasm_exec_env_t env) { 194 | KERNEL_INIT(plugin, kernel); 195 | wasm_val_t results[] = {{.kind = WASM_I64, .of = {.i64 = 0}}}; 196 | KERNEL_CALL( 197 | wasm_runtime_call_wasm_a(env, kernel->error_get, 1, results, 0, NULL)); 198 | return results[0].of.i64; 199 | } 200 | 201 | void k_error_set(wasm_exec_env_t env, uint64_t offs) { 202 | KERNEL_INIT(plugin, kernel); 203 | wasm_val_t params[] = {{.kind = WASM_I64, .of = {.i64 = offs}}}; 204 | KERNEL_CALL( 205 | wasm_runtime_call_wasm_a(env, kernel->error_set, 0, NULL, 1, params)); 206 | } 207 | 208 | uint64_t k_config_get(wasm_exec_env_t env, uint64_t k) { 209 | ExtismPlugin *plugin = wasm_runtime_get_function_attachment(env); 210 | uint64_t len = k_length(env, k); 211 | if (len == 0) { 212 | return 0; 213 | } 214 | 215 | void *ptr; 216 | WITH_KERNEL(plugin, { 217 | ptr = wasm_runtime_addr_app_to_native(plugin->kernel.instance, k); 218 | }); 219 | 220 | for (size_t i = 0; i < plugin->manifest->config_count; i++) { 221 | if (strlen(plugin->manifest->config[i].key) == len && 222 | strncmp(plugin->manifest->config[i].key, ptr, len) == 0) { 223 | return plugin_alloc(plugin, plugin->manifest->config[i].value, 224 | strlen(plugin->manifest->config[i].value)); 225 | } 226 | } 227 | 228 | return 0; 229 | } 230 | uint64_t k_var_get(wasm_exec_env_t env, uint64_t k) { 231 | ExtismPlugin *plugin = wasm_runtime_get_function_attachment(env); 232 | uint64_t len = k_length(env, k); 233 | if (len == 0) { 234 | return 0; 235 | } 236 | 237 | void *ptr; 238 | WITH_KERNEL(plugin, { 239 | ptr = wasm_runtime_addr_app_to_native(plugin->kernel.instance, k); 240 | }); 241 | 242 | for (size_t i = 0; i < plugin->var_count; i++) { 243 | if (strlen(plugin->vars[i].key) == len && 244 | strncmp(plugin->vars[i].key, ptr, len) == 0) { 245 | return plugin_alloc(plugin, plugin->vars[i].value, 246 | plugin->vars[i].length); 247 | } 248 | } 249 | 250 | return 0; 251 | } 252 | void k_var_set(wasm_exec_env_t env, uint64_t k, uint64_t v) { 253 | ExtismPlugin *plugin = wasm_runtime_get_function_attachment(env); 254 | uint64_t klen = k_length(env, k); 255 | if (klen == 0) { 256 | return; 257 | } 258 | 259 | uint64_t vlen = k_length(env, v); 260 | if (vlen == 0) { 261 | return; 262 | } 263 | 264 | void *ptr, *vptr; 265 | WITH_KERNEL(plugin, { 266 | ptr = wasm_runtime_addr_app_to_native(plugin->kernel.instance, k); 267 | vptr = wasm_runtime_addr_app_to_native(plugin->kernel.instance, v); 268 | }); 269 | 270 | for (size_t i = 0; i < plugin->var_count; i++) { 271 | if (strlen(plugin->vars[i].key) == klen && 272 | strncmp(plugin->vars[i].key, ptr, klen) == 0) { 273 | if (plugin->vars[i].length != vlen) { 274 | os_free(plugin->vars[i].value); 275 | plugin->vars[i].value = os_malloc(vlen); 276 | } 277 | memcpy(plugin->vars[i].value, vptr, vlen); 278 | plugin->vars[i].length = vlen; 279 | return; 280 | } 281 | } 282 | 283 | if (plugin->var_count < EXTISM_MAX_CONFIG) { 284 | plugin->vars[plugin->var_count].key = os_malloc(klen + 1); 285 | memcpy(plugin->vars[plugin->var_count].key, ptr, klen); 286 | plugin->vars[plugin->var_count].key[klen] = '\0'; 287 | plugin->vars[plugin->var_count].value = os_malloc(vlen); 288 | memcpy(plugin->vars[plugin->var_count].value, vptr, vlen); 289 | plugin->vars[plugin->var_count].length = vlen; 290 | plugin->var_count += 1; 291 | } else { 292 | wasm_runtime_set_exception(plugin->instance, "Variable store is full"); 293 | wasm_runtime_terminate(plugin->instance); 294 | } 295 | } 296 | uint64_t k_http_request(wasm_exec_env_t env, uint64_t req, uint64_t body) { 297 | (void)req; 298 | (void)body; 299 | ExtismPlugin *plugin = wasm_runtime_get_function_attachment(env); 300 | wasm_runtime_set_exception(plugin->instance, 301 | "extism:host/env::http_request not implemented"); 302 | wasm_runtime_terminate(plugin->instance); 303 | return 0; 304 | } 305 | uint32_t k_http_status_code(wasm_exec_env_t env) { 306 | 307 | ExtismPlugin *plugin = wasm_runtime_get_function_attachment(env); 308 | wasm_runtime_set_exception( 309 | plugin->instance, "extism:host/env::http_status_code not implemented"); 310 | wasm_runtime_terminate(plugin->instance); 311 | return 0; 312 | } 313 | 314 | #define LOG_FN(name, prefix) \ 315 | void k_log_##name(wasm_exec_env_t env, uint64_t msg) { \ 316 | ExtismPlugin *plugin = wasm_runtime_get_function_attachment(env); \ 317 | uint64_t len = k_length(env, msg); \ 318 | if (len == 0) \ 319 | return; \ 320 | void *ptr; \ 321 | WITH_KERNEL(plugin, { \ 322 | ptr = wasm_runtime_addr_app_to_native(plugin->kernel.instance, msg); \ 323 | }); \ 324 | fputs(prefix ": ", stderr); \ 325 | fwrite(ptr, len, 1, stderr); \ 326 | fputs("\n", stderr); \ 327 | } 328 | 329 | LOG_FN(info, "INFO") 330 | LOG_FN(warn, "WARN") 331 | LOG_FN(debug, "DEBUG") 332 | LOG_FN(error, "ERROR") 333 | 334 | static wasm_module_t load_extism_kernel(char errormsg[128]) { 335 | wasm_module_t module = wasm_runtime_load( 336 | extism_runtime_wasm, extism_runtime_wasm_len, errormsg, 128); 337 | if (module == NULL) { 338 | // TODO: log error 339 | puts(errormsg); 340 | return NULL; 341 | } 342 | 343 | return module; 344 | } 345 | 346 | void init_kernel(struct ExtismKernel *kernel, 347 | const ExtismMemoryConfig *memory) { 348 | assert(kernel); 349 | char errormsg[128]; 350 | kernel->module = load_extism_kernel(errormsg); 351 | assert(kernel->module); 352 | 353 | kernel->instance = 354 | wasm_runtime_instantiate(kernel->module, memory->stack_size / 2, 355 | memory->stack_size / 2, errormsg, 128); 356 | if (kernel->instance == NULL) { 357 | puts(errormsg); 358 | exit(1); 359 | } 360 | assert(kernel->instance); 361 | 362 | // Kernel functions 363 | #define KERNEL_FN(x) \ 364 | kernel->x = wasm_runtime_lookup_function(kernel->instance, #x); \ 365 | assert(kernel->x); 366 | 367 | KERNEL_FN(alloc); 368 | KERNEL_FN(free); 369 | KERNEL_FN(length); 370 | KERNEL_FN(length_unsafe); 371 | KERNEL_FN(reset); 372 | KERNEL_FN(input_set); 373 | KERNEL_FN(input_offset); 374 | KERNEL_FN(input_length); 375 | KERNEL_FN(output_offset); 376 | KERNEL_FN(output_length); 377 | KERNEL_FN(output_set); 378 | KERNEL_FN(error_get); 379 | KERNEL_FN(error_set); 380 | KERNEL_FN(load_u8); 381 | KERNEL_FN(input_load_u8); 382 | KERNEL_FN(store_u8); 383 | KERNEL_FN(load_u64); 384 | KERNEL_FN(input_load_u64); 385 | KERNEL_FN(store_u64); 386 | #undef KERNEL_FN 387 | // End kernel functions 388 | } 389 | -------------------------------------------------------------------------------- /src/symbols.c: -------------------------------------------------------------------------------- 1 | #include "internal.h" 2 | #include 3 | 4 | void init_symbols(struct Symbols *sym, size_t total) { 5 | if (sym->capacity != 0 && sym->symbols != NULL) { 6 | sym->length = 0; 7 | if (sym->capacity >= total) { 8 | return; 9 | } 10 | free(sym->symbols); 11 | } 12 | 13 | sym->symbols = os_malloc(total * sizeof(NativeSymbol)); 14 | assert(sym->symbols); 15 | sym->capacity = total; 16 | sym->length = 0; 17 | } 18 | 19 | NativeSymbol *add_symbols(struct Symbols *s, const NativeSymbol *sym, 20 | size_t n) { 21 | if (s->length == s->capacity) { 22 | void *ptr = 23 | realloc(s->symbols, (s->capacity + (n * 2)) * sizeof(NativeSymbol)); 24 | assert(ptr); 25 | s->symbols = ptr; 26 | } 27 | memcpy(&s->symbols[s->length], sym, sizeof(NativeSymbol) * n); 28 | s->length += n; 29 | return &s->symbols[s->length - n]; 30 | } 31 | 32 | void reset_symbols(struct Symbols *s) { 33 | os_free(s->symbols); 34 | s->symbols = NULL; 35 | s->length = 0; 36 | s->capacity = 0; 37 | } 38 | -------------------------------------------------------------------------------- /update-kernel.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | curl -L -O https://github.com/extism/extism/raw/main/runtime/src/extism-runtime.wasm 3 | xxd -i extism-runtime.wasm > src/extism-runtime.h 4 | -------------------------------------------------------------------------------- /wasm/count-vowels.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/extism/wamr-sdk/fb0a73532462feaf61d2bdcdf52ba82ed4d0ece2/wasm/count-vowels.wasm --------------------------------------------------------------------------------