Giter VIP home page Giter VIP logo

cervus's Introduction

cervus

Join the chat at https://gitter.im/cervus-v/cervus

A WebAssembly subsystem for Linux.

Screenshot

What is it?

Cervus implements a WebAssembly "usermode" on top of the Linux kernel (which tries to follow the CommonWA specification), enabling wasm applications to run directly in ring 0, while still ensuring safety and security.

But why?

  • Managed execution (making it possible to perform optimizations based on tracing/partial evaluation)
  • Avoid performance overhead introduced by system calls & address space switches
  • Zero-copy I/O is possible

Things that are working and not working

Working:

  • An interpreter based on HexagonE
  • Binary translation & loading based on wasm-core
  • Most of CommonWA ("everything is a URL", file I/O, command-line arguments)
  • IPC (only broadcast supported by now, with URL prefix ipc-broadcast://)

Not working:

  • Floating point
  • JIT
  • Everything else

Build

Kernel module

Requirements:

  • xargo
  • latest nightly rust
  • kernel headers
  • gnu make & gcc
./build_all.sh
sudo insmod glue/cervus.ko

Loader (cvctl)

This installs the cvload and cvrun binaries:

cd cvctl
cargo install

Applications

Cervus implements most of CommonWA (tracked at #2), whose examples can be found at cwa-rs/examples.

For example, to build and run the cat example:

sudo chmod 666 /dev/cvctl
cd cwa-rs
cargo build --target wasm32-unknown-unknown --release --example cat
cvrun target/wasm32-unknown-unknown/release/examples/cat.wasm file:///etc/lsb-release

To launch an IPC broadcast sender and then read from it:

cargo build --target wasm32-unknown-unknown --release --example broadcast_sender
cvrun target/wasm32-unknown-unknown/release/examples/broadcast_sender.wasm your_broadcast

(in another terminal)

cvrun target/wasm32-unknown-unknown/release/examples/cat.wasm ipc-broadcast://your_broadcast | dd of=/dev/null bs=4K

Contribute

I'm busy with my College Entrance Examination until ~June 10, 2018, before which I cannot actively maintain this project. However, there are a few things that can be relatively easily worked on:

  • A JIT based on Cretonne

Since Cretonne supports no_std, this should be relatively easy compared to other JIT approaches.

Interface with the rest of the system by implementing the Backend trait, for which the interpreter-based backend located in src/backend/hexagon_e is a good example to start with.

  • Network API

Blocking network APIs can be added as virtual system calls.

License

Cervus itself has to use the GPL 2.0 license because it links to the Linux kernel. However, user code that runs on Cervus is not limited by this.

cervus's People

Contributors

gitter-badger avatar joe8bit avatar losfair avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cervus's Issues

Unwind on panic

Currently, the rust panic behavior is to trigger a kernel panic, and all "normal" error handling is done with the Result type. However, in the kernel we have to deal with situations like OOM, which might happen everywhere and typically results in a panic/abort.

An unwinding-based method for handling panics may be possible, with "resource contexts":

  1. Before calling into rust, the C code sets up a Context associated with the current OS thread and store it in a global linear map indexed by the current pointer. The Context should include the stack pointer to unwind to on panic, and resource registries.
  2. All memory & kernel resources allocated in the rust code are then registered to the Context.
  3. If a panic happens during execution, the panic handler reads out the original stack pointer and sets rsp to it. Then, the C code detects that and frees all previously allocated resources.

Unresolved questions:

  • How should we associate the Context with the current thread? Global map with current as index works but is expensive. Do we have something like thread-local storage in the kernel?

GPLv2 + "Or Any Later Version"? :)

Small request; it's always better to have our GPLs future-proofed, so it'd be nice if this could also be licensed under the GPLv3 and later versions as may arise from the FSF. I know that, linking against the Linux kernel, derived code would need to be GPLv2 to be linked to Cervus anyway. But maybe someday the Linux kernel will also upgrade its license, who knows? :)

Protected wasm memory access with virtual memory

To avoid bound-checking every time a memory access happens, we need to make use of the virtual memory - allocate a 4GB continuous virtual address range (maybe from the user space range?) and check access & map pages on-demand.

However, we need to figure out how to hook into the page fault handling process and do the needed work.

Implement WASI strandard

Hello there! WASI seems to be a very hot new thing in the WebAssembly world. It's a WASM-outside-web standard from Mozilla which gains more and more support seeing Wasmtime and Wasmer both promising to adopt it.

How does Cervus fit into the picture? Also, what it the status of the project at the moment?

Spectre?

Would be good to have a brief comment in the Readme about Spectre. Is this written assuming that Spectre will be solved in hardware at some future point? Is it only meant for trusted code?

A Linux Subsystem for Cervus.

Nitpicking, but the current description is wrong (if you want to follow the naming scheme Microsoft Windows uses). It's the "Windows Subsystem for Linux", not the "Linux Subsystem for Windows".

Better error types

Currently, we have a lot error types: KernelError, BackendError, IoError and CwaError. This increases complexity and brings inconsistency.

However these error types can be categorized into either "internal error" or "API error", and we can try to reduce them into KernelError and ApiError, before we are ready to finally merge these two types.

Network I/O

Now that we have (blocking) file IO, basic networking can also be implemented :)

Work needed:

  • TCP
  • UDP
  • Raw socket
  • Unix socket (?)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.