From 43130dd5c2bad2e82119465aa657d23b5e701fbb Mon Sep 17 00:00:00 2001 From: NikVolf Date: Thu, 13 Apr 2017 01:03:41 +0300 Subject: [PATCH] rust contract sample --- runner/index.html | 33 ++++++++++++++++++++++++++++++--- samples/contract2.rs | 19 +++++++++++++++++++ 2 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 samples/contract2.rs diff --git a/runner/index.html b/runner/index.html index 8a1e22b..c07a073 100644 --- a/runner/index.html +++ b/runner/index.html @@ -28,6 +28,16 @@ (import "env" "_abort" (func (;3;) (type 1))) (import "env" "___setErrNo" (func (;4;) (type 2))) + (import "env" "invoke_vi" (func (;4;) (type 3))) + (import "env" "invoke_v" (func (;5;) (type 1))) + (import "env" "_rust_begin_unwind" (func (;6;) (type 4))) + (import "env" "_emscripten_memcpy_big" (func (;9;) (type 5))) + (import "env" "___gxx_personality_v0" (func (;10;) (type 6))) + (import "env" "_llvm_trap" (func (;11;) (type 0))) + (import "env" "___resumeException" (func (;12;) (type 1))) + (import "env" "___cxa_find_matching_catch_2" (func (;13;) (type 2))) + (import "env" "___gxx_personality_v0" (func (;14;) (type 7))) + (import "env" "memory" (memory (;0;) 256 256)) (import "env" "table" (table (;0;) 0 0 anyfunc)) (import "env" "memoryBase" (global (;3;) i32)) @@ -40,8 +50,25 @@ env.enlargeMemory = env.enlargeMemory || function() { throw "error enlarging memory"; }; env.getTotalMemory = env.getTotalMemory || function() { return 65536 * 256; }; env.abortOnCannotGrowMemory = env.abortOnCannotGrowMemory || function() { throw "abort growing memory"; }; - env._abort = env.abortOnCannotGrowMemory || function() { throw "abort"; }; - env.___setErrNo = env.abortOnCannotGrowMemory || function() { throw "setting error no"; }; + env._abort = env._abort || function() { throw "_abort"; }; + env.abort = env.abort || function() { throw "abort"; }; + env.___setErrNo = env.___setErrNo || function() { throw "setting error no"; }; + + // dead symbols in rust wasm32-unknown-emscripten target + // todo: strip/raise issue in rust compiler + env.invoke_vi = function() { throw "invoke_vi: unreachable!"; } + env.invoke_v = function() { throw "invoke_v: unreachable!"; } + + // todo: also test unwind about those two + env._rust_begin_unwind = function() { throw "_rust_begin_unwind: unreachable!"; } + env._llvm_trap = function() { throw "_llvm_trap: unreachable!"; } + + env._emscripten_memcpy_big = function() { throw "_emscripten_memcpy_big: unreachable!"; } + env.___gxx_personality_v0 = function() { throw "___gxx_personality_v0: unreachable!"; } + env.___resumeException = function() { throw "___resumeException: unreachable!"; } + env.___cxa_find_matching_catch_2 = function() { throw "___cxa_find_matching_catch_2: unreachable!"; } + env.___gxx_personality_v0 = function() { throw "___gxx_personality_v0: unreachable!"; } + env.memoryBase = env.memoryBase || 0; env.tableBase = env.tableBase || 0; @@ -53,7 +80,7 @@ imports.env.memory = new WebAssembly.Memory({ initial: 256, maximum: 256 }); } if (!imports.env.table) { - imports.env.table = new WebAssembly.Table({ initial: 0, maximum: 0, element: 'anyfunc' }); + imports.env.table = new WebAssembly.Table({ initial: 8, maximum: 8, element: 'anyfunc' }); } return new WebAssembly.Instance(module, imports); }); diff --git a/samples/contract2.rs b/samples/contract2.rs new file mode 100644 index 0000000..cc37b1d --- /dev/null +++ b/samples/contract2.rs @@ -0,0 +1,19 @@ +#![feature(link_args)] +#![feature(lang_items)] +#![feature(drop_types_in_const)] +#![no_main] + +#[link_args = "-s WASM=1 -s NO_EXIT_RUNTIME=1 -s NO_FILESYSTEM=1"] +extern {} + +static mut DATA: Option> = None; + +#[no_mangle] +pub fn call() { + let mut vec = Vec::new(); + unsafe { if let Some(ref v) = DATA { vec.extend(v); }; } + vec.push(1u8); + unsafe { + DATA = Some(vec); + } +} \ No newline at end of file