This project is a trusted application based on WaTZ and ported to the latest version of OPTEE. It supports running AoT format WebAssembly (Wasm) programs within a Trusted Execution Environment (TEE).
- 2025-3-1: Updated to the latest version of
wasm-micro-runtime, supporting new features such as the multi-memory proposal.
This project is based on specific versions of unine-watz, wasm-micro-runtime, and optee_os, ensuring compatibility across different modules within the latest OPTEE environment.
- The project is based on version
a436628ofunine-watz(Apache License 2.0) and has removed the original project's remote authentication components. - The project references the latest version of
wasm-micro-runtime(Apache License 2.0), supporting more WebAssembly features. - The project is based on version
19662e4ofoptee_os, with the addition of themprotectsystem call.
cd third_party/wasm-micro-runtime/product-mini/platforms/linux-trustzone
mkdir -p build
cd build
cmake ..
make- Use
./third_party/optee_osto overwrite theoptee_osin the original project. - Move the
./optee_wamrfolder intooptee_examples. - Recompile OP-TEE.
After entering the Normal World, use the following command to run a Wasm program:
optee_wamr <heap_size> <aot_path>
- The
AoTfile is compiled usingwamrcfromthird_party/wasm-micro-runtime, specifying the--target=aarch64option. See Build wamrc AOT compiler for details on compilingwamrc. - The
heap_sizeis the amount of heap space allocated to the Wasm program, measured in bytes. It should be at least larger than the AoT file.
Add the external functions you need to import in the optee_wamr/ta/wasi.c and optee_wamr/ta/wasi.h files. For details, refer to: Exporting Native API Steps
Compile the hello.c file to get the hello.wasm file:
/opt/wasi-sdk/bin/clang -O3 -o hello.wasm hello.cThen use wamrc to compile the hello.aot file:
wamrc --target=aarch64 --disable-simd hello.wasm -o hello.aotRun the command optee_wamr 1000000 ./hello.aot in OPTEE to output Hello WebAssembly!.
Compile the external_function.rs file to get the external_function.wasm file:
rustc -C link-self-contained=no \
-C link-args=--no-entry \
-C link-args=-zstack-size=32768 \
--target wasm32v1-none external_function.rsThen use wamrc to compile the external_function.aot file:
wamrc --target=aarch64 --disable-simd external_function.wasm -o external_function.aotRun the command optee_wamr 1000000 ./external_function.aot in OPTEE to output Hello Rust World! in the Secure World.
Compile the wasm-rust project to get the wasm-rust.aot file:
cd test/wasm-rust
./build.shImport the external library wee_alloc as the memory allocator, so that dynamic memory allocation can be used in the Rust-compiled wasm.