Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remote code loading framework. #416

Merged
merged 46 commits into from
May 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
14bfd75
Code loader framework.
losfair May 2, 2019
af58ea5
Kernel mode code loading.
losfair May 4, 2019
7a4b217
Remove runtime dependence for BrTable
losfair May 4, 2019
af0b147
Add emit_u64 to Emitter API
losfair May 4, 2019
c4e4efc
kwasm imports
losfair May 4, 2019
a590d7c
Tables
losfair May 4, 2019
46e4cb0
Get memory intrinsics at runtime.
losfair May 4, 2019
3c64bd0
Kernel mode example.
losfair May 4, 2019
cc01e40
Split load/run
losfair May 5, 2019
7bc09ee
kwasmd.
losfair May 5, 2019
61510f8
Enforce runtime memory and stack bound check when using kernel loader.
losfair May 6, 2019
b343fd4
Pass in param count for import functions in kernel loader.
losfair May 6, 2019
0895dc6
Check param count.
losfair May 6, 2019
0bbd6e6
Fix function offset.
losfair May 7, 2019
accb80b
Pipe example
losfair May 7, 2019
620a6dd
Disable memory bound checking for kernel loader.
losfair May 8, 2019
af1ac9a
Improve performance of memory access.
losfair May 13, 2019
3bcdfb4
Asynchronous networking extension.
losfair May 13, 2019
884a7e1
kwasm-net fixes and optimizations.
losfair May 13, 2019
4f77f4d
HTTP server example.
losfair May 14, 2019
2963b0a
Make `schedule()` faster.
losfair May 14, 2019
9df3e4a
Fix http server example.
losfair May 14, 2019
db9705f
Merge remote-tracking branch 'origin/master' into feature/remote-code…
losfair May 14, 2019
2a160c7
Fix wasmer-runtime-core dependency version.
losfair May 14, 2019
722ea39
Cleanup loader code.
losfair May 14, 2019
32f9aee
Cargo fmt
losfair May 14, 2019
1e7a928
Add comments.
losfair May 14, 2019
d60e237
Only compile kwasm-net for wasm32-wasi.
losfair May 14, 2019
98dd2c0
Fix wasm example crates.
losfair May 14, 2019
ee09209
Fix clippy error.
losfair May 14, 2019
d641909
Fix clippy error
losfair May 14, 2019
5ec931e
Fix kwasmd compilation
losfair May 14, 2019
fac4c45
Fix LLVM backend.
losfair May 14, 2019
d75a292
Fix compilation issue on Windows.
losfair May 14, 2019
d72abf3
Rename `kwasm-loader` to `wasmer-kernel-loader`.
losfair May 15, 2019
6df4e40
Cargo fmt
losfair May 15, 2019
a1a58d4
Merge remote-tracking branch 'origin/master' into feature/remote-code…
losfair May 15, 2019
13b4fe3
Temporarily disable caching for macos test.
losfair May 15, 2019
408f89c
Rename `loader:kwasm` to `loader:kernel` for consistency.
losfair May 15, 2019
3bbf775
Renamed kwasm-net to wasmer-kernel-net
syrusakbary May 15, 2019
720d984
Make kernel loader available by default
syrusakbary May 15, 2019
82bf7ea
Improved error messages when running on a specific loader
syrusakbary May 15, 2019
0ab8a04
Re-enable circleci cache
syrusakbary May 15, 2019
b289929
Rename `wasmer-kernel-net` to `kernel-net`.
losfair May 16, 2019
a177954
Rename `wasi-networking` to `echo-server`.
losfair May 16, 2019
100039a
Merge remote-tracking branch 'origin/master' into feature/remote-code…
losfair May 16, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ jobs:
- restore_cache:
keys:
- v8-cargo-cache-darwin-stable-{{ arch }}-{{ checksum "Cargo.lock" }}
- v8-cargo-cache-darwin-stable-{{ arch }}
# - v8-cargo-cache-darwin-stable-{{ arch }}
- run:
name: Install crate dependencies
command: |
Expand Down Expand Up @@ -372,7 +372,6 @@ jobs:
-d build_parameters[CIRCLE_JOB]=bench \
https://circleci.com/api/v1.1/project/github/wasmerio/wasmer-bench/tree/master
fi

workflows:
version: 2
main:
Expand Down
718 changes: 391 additions & 327 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ include = [
]

[dependencies]
byteorder = "1.3.1"
errno = "0.2.4"
structopt = "0.2.11"
wabt = "0.7.2"
Expand All @@ -32,9 +33,10 @@ wasmer-runtime-core = { path = "lib/runtime-core" }
wasmer-emscripten = { path = "lib/emscripten" }
wasmer-llvm-backend = { path = "lib/llvm-backend", optional = true }
wasmer-wasi = { path = "lib/wasi", optional = true }
wasmer-kernel-loader = { path = "lib/kernel-loader", optional = true }

[workspace]
members = ["lib/clif-backend", "lib/singlepass-backend", "lib/runtime", "lib/runtime-abi", "lib/runtime-core", "lib/emscripten", "lib/spectests", "lib/win-exception-handler", "lib/runtime-c-api", "lib/llvm-backend", "lib/wasi", "lib/middleware-common", "examples/plugin-for-example"]
members = ["lib/clif-backend", "lib/singlepass-backend", "lib/runtime", "lib/runtime-abi", "lib/runtime-core", "lib/emscripten", "lib/spectests", "lib/win-exception-handler", "lib/runtime-c-api", "lib/llvm-backend", "lib/wasi", "lib/middleware-common", "lib/kernel-loader", "lib/kernel-net", "examples/plugin-for-example"]

[build-dependencies]
wabt = "0.7.2"
Expand All @@ -43,6 +45,7 @@ rustc_version = "0.2.3"

[features]
default = ["fast-tests", "wasi"]
"loader:kernel" = ["wasmer-kernel-loader"]
debug = ["wasmer-runtime-core/debug"]
extra-debug = ["wasmer-clif-backend/debug", "wasmer-runtime-core/debug"]
# This feature will allow cargo test to run much faster
Expand Down
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,27 +67,27 @@ test-emscripten-singlepass:
cargo test --manifest-path lib/emscripten/Cargo.toml --features singlepass -- --test-threads=1 $(runargs)

singlepass-debug-release:
cargo +nightly build --features "backend:singlepass debug" --release
cargo +nightly build --features backend:singlepass,debug --release

singlepass-release:
cargo +nightly build --features "backend:singlepass" --release
cargo +nightly build --features backend:singlepass --release

singlepass-build:
cargo +nightly build --features "backend:singlepass debug"
cargo +nightly build --features backend:singlepass,debug

release:
# If you are in OS-X, you will need mingw-w64 for cross compiling to windows
# brew install mingw-w64
cargo build --release

production-release:
cargo build --release --features backend:singlepass,backend:llvm
cargo build --release --features backend:singlepass,backend:llvm,loader:kernel

debug-release:
cargo build --release --features "debug"
cargo build --release --features debug

extra-debug-release:
cargo build --release --features "extra-debug"
cargo build --release --features extra-debug

publish-release:
ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -delete ${VERSION} ./artifacts/
13 changes: 13 additions & 0 deletions examples/echo-server/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions examples/echo-server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "echo-server"
version = "0.1.0"
authors = ["Heyang Zhou <zhy20000919@hotmail.com>"]
edition = "2018"

[workspace]

[dependencies]
kernel-net = { path = "../../lib/kernel-net" }
49 changes: 49 additions & 0 deletions examples/echo-server/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#![feature(wasi_ext)]

use kernel_net::{schedule, Epoll, Tcp4Listener, TcpStream};
use std::sync::Arc;

fn do_echo(stream: Arc<TcpStream>, buf: Vec<u8>) {
let stream2 = stream.clone();
stream.read_async(buf, move |result| match result {
Ok(buf) => {
if buf.len() == 0 {
return;
}
let stream = stream2.clone();
stream2.write_all_async(buf, move |result| match result {
Ok(buf) => {
schedule(|| {
do_echo(stream, buf);
});
}
Err(code) => {
println!("failed to write; code = {}", code);
}
});
}
Err(code) => {
println!("failed to read; code = {}", code);
}
});
}

fn main() {
let epoll = Arc::new(Epoll::new());
let listener = Arc::new(Tcp4Listener::new("0.0.0.0", 2001, 128).unwrap());

listener.accept_async(epoll.clone(), |stream| match stream {
Ok(stream) => {
do_echo(stream, Vec::with_capacity(16384));
Ok(())
}
Err(code) => {
println!("failed to accept; code = {}", code);
Err(())
}
});
println!("start epoll");
unsafe {
epoll.run();
}
}
13 changes: 13 additions & 0 deletions examples/http-server/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions examples/http-server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "http-server"
version = "0.1.0"
authors = ["Heyang Zhou <zhy20000919@hotmail.com>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[workspace]

[dependencies]
kernel-net = { path = "../../lib/kernel-net" }
72 changes: 72 additions & 0 deletions examples/http-server/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#![feature(wasi_ext)]

use kernel_net::{schedule, Epoll, Tcp4Listener, TcpStream};
use std::sync::Arc;

fn serve(stream: Arc<TcpStream>, mut all: Vec<u8>) {
let stream2 = stream.clone();
stream.read_async(
Vec::with_capacity(512),
move |result| {
match result {
Ok(buf) => {
if buf.len() == 0 {
return;
}
all.extend_from_slice(&buf);
if all.len() > 4096 {
println!("header too large");
return;
}
let s = match ::std::str::from_utf8(&all) {
Ok(x) => x,
Err(e) => {
println!("not utf8: {:?}", e);
return;
}
};
if let Some(_pos) = s.find("\r\n\r\n") {
let body = format!(
"Hello, world!\n",
).into_bytes();
let stream = stream2.clone();
stream2.write_all_async(
format!(
"HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nConnection: close\r\nContent-Length: {}\r\n\r\n",
body.len()
).into_bytes(),
|_| {
stream.write_all_async(body, |_| {});
}
);
} else {
schedule(|| serve(stream2, all));
}
}
Err(code) => {
println!("failed to read; code = {}", code);
}
}
}
);
}

fn main() {
let epoll = Arc::new(Epoll::new());
let listener = Arc::new(Tcp4Listener::new("0.0.0.0", 2011, 128).unwrap());

listener.accept_async(epoll.clone(), |stream| match stream {
Ok(stream) => {
serve(stream, vec![]);
Ok(())
}
Err(code) => {
println!("failed to accept; code = {}", code);
Err(())
}
});
println!("start epoll");
unsafe {
epoll.run();
}
}
9 changes: 9 additions & 0 deletions examples/pipe/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "pipe"
version = "0.1.0"
authors = ["Heyang Zhou <zhy20000919@hotmail.com>"]
edition = "2018"

[workspace]

[dependencies]
13 changes: 13 additions & 0 deletions examples/pipe/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use std::io::{Read, Write};

fn main() {
let mut stdin = ::std::io::stdin();
let mut stdout = ::std::io::stdout();
let mut buf: Vec<u8> = vec![0; 512];
let mut total: u64 = 0;
while total < 1048576u64 * 2048 {
let n = stdin.read(&mut buf).unwrap();
stdout.write_all(&buf[..n]).unwrap();
total += n as u64;
}
}
9 changes: 9 additions & 0 deletions lib/kernel-loader/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "wasmer-kernel-loader"
version = "0.1.0"
authors = ["Heyang Zhou <zhy20000919@hotmail.com>"]
edition = "2018"

[dependencies]
libc = "0.2.49"
wasmer-runtime-core = { path = "../runtime-core" }
Loading