The mailing list of Linux kernel developers has published patches implementing the "Wasm" architecture for the Linux kernel, allowing it to compile the kernel into WebAssembly intermediate code for subsequent direct execution in a web browser without the involvement of emulators. In addition, the project has enabled the Linux kernel to run executable files in the ".wasm" format and prepared a "web console" driver to simulate console operations in the browser. A toolkit has also been created to simplify the assembly of browser-executable system environments.
An environment has been formed based on the BusyBox utilities compiled in WebAssembly and the musl system library. Xterm.js has been used as a terminal emulator to work with such an environment. A demonstration website has been launched to allow evaluation of the port's functionality without needing to compile it independently. Full support for Chromium-based browsers has been declared, along with partial support for Firefox, where debugging capabilities are limited. On modern computers, loading the Wasm build of the kernel in the browser takes less than a second.
The project has been developing for about two years and currently allows loading the kernel in browsers and executing typical programs. The work is still not complete, and the port has certain issues and limitations. For example, support for vfork and longjmp calls has not yet been implemented (BusyBox has been patched to work without them), there is no ability to interrupt tasks, the MMU is unavailable (the kernel and processes work in the same address space), modifying already loaded code is impossible, and the console tends to hang after about 5 minutes due to timer issues. It is noted that the existing limitations are surmountable, but some of them require the implementation of additional extensions to WebAssembly in browsers. Such extensions have been proposed for MMU and thread suspension.
The inability to pause thread execution in WebAssembly does not align with the task scheduler's operation in the kernel, but multitasking has been achieved indirectly by binding each thread/task to its own virtual CPU processed within a separate Web Worker. This method allows for parallel execution of processes through the browser engine and the host OS kernel without utilizing preemptive multitasking and task switching within the browser's kernel. Interrupts and signals do not work properly in this scheme, and to deliver timer interrupts and IPI (Inter-Processor Interrupt), a separate virtual CPU is used.
The project's scope goes beyond merely launching Linux environments in browsers. For example, the port can be used to create cross-platform WebAssembly programs that utilize Linux-specific system calls. The implementation of such system calls can be separately transformed into WebAssembly and attached to the application, allowing it to be used without being tied to the system kernel. The port will also be useful for organizing isolated execution of applications using WASI (WebAssembly System Interface).
Among the plans, there are experiments mentioned regarding the support for graphics in environments with a kernel built in WebAssembly — based on the browser API WebGL, there are plans to implement EGL and ensure the operation of OpenGL ES. Additionally, support for the Debugging format Dwarf is planned for line-by-line code debugging.
Source: opennet.ru
