WasmEdge on seL4

Video demo | Build logs | Build artifact

In this article, we demonstrate how to run WasmEdge on the seL4 RTOS, there are two parts:

  1. Guest Linux OS on seL4: This is the controller of WasmEdge runtime, which will send wasm program to WasmEdge runner that is a agent on seL4 to execute.
  2. WasmEdge runner on seL4: This is the wasm program runtime, which will execute the given wasm program from Guest Linux OS.

The figure below illustrates the architecture of the system.

wasmedge-sel4

This demo is based on the seL4 simulator on Linux.

Getting Started

System requirements

Hardware:

  • at least 4GB of RAM
  • at least 20GB of disk storage (the wasmedge_sel4 directory will contain over 11 GB of data after the following installation completes)

Software: Ubuntu 20.04 with dev tools packages (ep. Python) installed. We recommend the GitHub Actions Ubuntu 20.04 VM (See a list of installed apt packages). Or, you could use our Docker image (see the Dockerfile).

  1. $ docker pull wasmedge/sel4_build
  2. $ docker run --rm -v $(pwd):/app -it wasmedge/sel4_build
  3. (docker) root#

If you do not want to build the seL4 system simulator yourself, you can download the build artifact from our GitHub Actions, and skip directly to Boot wasmedge-seL4

Automatic installation: all-in-one script

Use our all-in-one build script:

  1. wget -qO- https://raw.githubusercontent.com/second-state/wasmedge-seL4/main/build.sh | bash

And this will clone and build our wasmedge on seL4 to an image.

After finishing the build script, you will have a folder sel4_wasmedge.

If this automatic installation completed successfully, skip over the manual installation information and proceed to boot wasmedge-sel4

Manual installation: managing memory usage

The above all-in-one script will work in most cases. However, if your system resources were stressed and you encountered an error such as ninja: build stopped: subcommand failed please note that you can decrease the parallelization of the install by explicitly passing in a -j parameter to the ninja command (on the last line of the build.sh file). You see, Ninja runs the most amount of parallel processes by default and so the following procedure is a way to explicitly set/reduce parallelization.

Manually fetch the `wasmedge-sel4 repository.

  1. cd ~
  2. git clone https://github.com/second-state/wasmedge-seL4.git
  3. cd wasmedge-seL4

Manually edit the build.sh file.

  1. vi build.sh

Add the following -j parameter to the last line of the file i.e.

  1. ninja -j 2

Make the build.sh file executable.

  1. sudo chmod a+x build.sh

Run the edited `build.sh file.

  1. ./build.sh

Once this manual installation is complete, follow along with the following steps; boot wasmedge-sel4

Boot wasmedge-seL4

  1. cd sel4_wasmedge/build
  2. ./simulate

Expected output:

  1. $ ./simulate: qemu-system-aarch64 -machine virt,virtualization=on,highmem=off,secure=off -cpu cortex-a53 -nographic -m size=2048 -kernel images/capdl-loader-image-arm-qemu-arm-virt
  2. ELF-loader started on CPU: ARM Ltd. Cortex-A53 r0p4
  3. paddr=[6abd8000..750cf0af]
  4. No DTB passed in from boot loader.
  5. Looking for DTB in CPIO archive...found at 6ad18f58.
  6. Loaded DTB from 6ad18f58.
  7. paddr=[60243000..60244fff]
  8. ELF-loading image 'kernel' to 60000000
  9. paddr=[60000000..60242fff]
  10. vaddr=[ff8060000000..ff8060242fff]
  11. virt_entry=ff8060000000
  12. ELF-loading image 'capdl-loader' to 60245000
  13. paddr=[60245000..6a7ddfff]
  14. vaddr=[400000..a998fff]
  15. virt_entry=408f38
  16. Enabling hypervisor MMU and paging
  17. Jumping to kernel-image entry point...
  18. Bootstrapping kernel
  19. Warning: Could not infer GIC interrupt target ID, assuming 0.
  20. Booting all finished, dropped to user space
  21. <<seL4(CPU 0) [decodeUntypedInvocation/205 T0xff80bf85d400 "rootserver" @4006f8]: Untyped Retype: Insufficient memory (1 * 2097152 bytes needed, 0 bytes available).>>
  22. Loading Linux: 'linux' dtb: 'linux-dtb'
  23. ...(omitted)...
  24. Starting syslogd: OK
  25. Starting klogd: OK
  26. Running sysctl: OK
  27. Initializing random number generator... [ 3.512482] random: dd: uninitialized urandom read (512 bytes read)
  28. done.
  29. Starting network: OK
  30. [ 4.086059] connection: loading out-of-tree module taints kernel.
  31. [ 4.114686] Event Bar (dev-0) initalised
  32. [ 4.123771] 2 Dataports (dev-0) initalised
  33. [ 4.130626] Event Bar (dev-1) initalised
  34. [ 4.136096] 2 Dataports (dev-1) initalised
  35. Welcome to Buildroot
  36. buildroot login:

Login on guest linux

Enter root to login

  1. buildroot login: root

Expected output:

  1. buildroot login: root
  2. #

Execute wasm examples

Example A: nbody-c.wasm

Run nbody simulation.

  1. wasmedge_emit /usr/bin/nbody-c.wasm 10

Expected output:

  1. [1900-01-00 00:00:00.000] [info] executing wasm file
  2. -0.169075164
  3. -0.169073022
  4. [1900-01-00 00:00:00.000] [info] execution success, exit code:0

Example B: hello.wasm

Run an easy application to print hello, sel4 and a simple calculation.

  1. wasmedge_emit /usr/bin/hello.wasm

Expected output:

  1. [1900-01-00 00:00:00.000] [info] executing wasm file
  2. hello, sel4
  3. 1+2-3*4 = -9
  4. [1900-01-00 00:00:00.000] [info] execution success, exit code:0