diff --git a/Cargo.lock b/Cargo.lock index 6d4ab0eac72c4..566c4abe82e19 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1943,18 +1943,6 @@ dependencies = [ "getopts 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "pwasm-alloc" -version = "0.1.0" -dependencies = [ - "pwasm-libc 0.1.0", - "rustc_version 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "pwasm-libc" -version = "0.1.0" - [[package]] name = "pwasm-utils" version = "0.3.1" @@ -2449,8 +2437,6 @@ dependencies = [ name = "sr-std" version = "0.1.0" dependencies = [ - "pwasm-alloc 0.1.0", - "pwasm-libc 0.1.0", "rustc_version 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/Cargo.toml b/Cargo.toml index 81ec49dc999ae..802c47a2b706f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -57,7 +57,6 @@ exclude = [ "node/runtime/wasm", "core/executor/wasm", "pwasm-alloc", - "pwasm-libc", "core/test-runtime/wasm", ] diff --git a/core/executor/src/wasm_executor.rs b/core/executor/src/wasm_executor.rs index 70d02d01891c5..8918a34296ef7 100644 --- a/core/executor/src/wasm_executor.rs +++ b/core/executor/src/wasm_executor.rs @@ -16,7 +16,6 @@ //! Rust implementation of Substrate contracts. -use std::cmp::Ordering; use std::collections::HashMap; use wasmi::{ @@ -161,33 +160,6 @@ impl_function_executor!(this: FunctionExecutor<'e, E>, println!("{}", number); Ok(()) }, - ext_memcmp(s1: *const u8, s2: *const u8, n: usize) -> i32 => { - let sl1 = this.memory.get(s1, n as usize).map_err(|_| UserError("Invalid attempt to read from memory in first arg of ext_memcmp"))?; - let sl2 = this.memory.get(s2, n as usize).map_err(|_| UserError("Invalid attempt to read from memory in second arg of ext_memcmp"))?; - Ok(match sl1.cmp(&sl2) { - Ordering::Greater => 1, - Ordering::Less => -1, - Ordering::Equal => 0, - }) - }, - ext_memcpy(dest: *mut u8, src: *const u8, count: usize) -> *mut u8 => { - this.memory.copy_nonoverlapping(src as usize, dest as usize, count as usize) - .map_err(|_| UserError("Invalid attempt to copy_nonoverlapping in ext_memcpy"))?; - debug_trace!(target: "sr-io", "memcpy {} from {}, {} bytes", dest, src, count); - Ok(dest) - }, - ext_memmove(dest: *mut u8, src: *const u8, count: usize) -> *mut u8 => { - this.memory.copy(src as usize, dest as usize, count as usize) - .map_err(|_| UserError("Invalid attempt to copy in ext_memmove"))?; - debug_trace!(target: "sr-io", "memmove {} from {}, {} bytes", dest, src, count); - Ok(dest) - }, - ext_memset(dest: *mut u8, val: u32, count: usize) -> *mut u8 => { - debug_trace!(target: "sr-io", "memset {} with {}, {} bytes", dest, val, count); - this.memory.clear(dest as usize, val as u8, count as usize) - .map_err(|_| UserError("Invalid attempt to clear in ext_memset"))?; - Ok(dest) - }, ext_malloc(size: usize) -> *mut u8 => { let r = this.heap.allocate(size); debug_trace!(target: "sr-io", "malloc {} bytes at {}", size, r); diff --git a/core/executor/wasm/Cargo.lock b/core/executor/wasm/Cargo.lock index 9ae42e7b30242..9879fa610f4ab 100644 --- a/core/executor/wasm/Cargo.lock +++ b/core/executor/wasm/Cargo.lock @@ -63,18 +63,6 @@ dependencies = [ "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "pwasm-alloc" -version = "0.1.0" -dependencies = [ - "pwasm-libc 0.1.0", - "rustc_version 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "pwasm-libc" -version = "0.1.0" - [[package]] name = "quote" version = "0.6.5" @@ -149,8 +137,6 @@ dependencies = [ name = "sr-std" version = "0.1.0" dependencies = [ - "pwasm-alloc 0.1.0", - "pwasm-libc 0.1.0", "rustc_version 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/core/sr-std/Cargo.toml b/core/sr-std/Cargo.toml index 459d0f72d1a3c..8f4774ec5d1e6 100644 --- a/core/sr-std/Cargo.toml +++ b/core/sr-std/Cargo.toml @@ -7,10 +7,6 @@ build = "build.rs" [build-dependencies] rustc_version = "0.2" -[dependencies] -pwasm-alloc = { path = "../../pwasm-alloc" } -pwasm-libc = { path = "../../pwasm-libc" } - [features] default = ["std"] std = [] diff --git a/core/sr-std/without_std.rs b/core/sr-std/without_std.rs index 5219cba062703..bfa9020504fdf 100644 --- a/core/sr-std/without_std.rs +++ b/core/sr-std/without_std.rs @@ -16,10 +16,33 @@ #[cfg(feature = "nightly")] extern crate alloc; -#[cfg(feature = "nightly")] -extern crate pwasm_libc; -#[cfg(feature = "nightly")] -extern crate pwasm_alloc; + +extern "C" { + fn ext_malloc(size: usize) -> *mut u8; + fn ext_free(ptr: *mut u8); +} + +/// Wasm allocator +pub struct WasmAllocator; + +#[global_allocator] +static ALLOCATOR: WasmAllocator = WasmAllocator; + +mod __impl { + use core::alloc::{GlobalAlloc, Layout}; + + use super::WasmAllocator; + + unsafe impl GlobalAlloc for WasmAllocator { + unsafe fn alloc(&self, layout: Layout) -> *mut u8 { + super::ext_malloc(layout.size()) as *mut u8 + } + + unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) { + super::ext_free(ptr as *mut u8) + } + } +} pub use alloc::boxed; pub use alloc::rc; diff --git a/core/test-runtime/wasm/Cargo.lock b/core/test-runtime/wasm/Cargo.lock index b4a0da92bba36..4c22f9f1318ff 100644 --- a/core/test-runtime/wasm/Cargo.lock +++ b/core/test-runtime/wasm/Cargo.lock @@ -363,18 +363,6 @@ dependencies = [ "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "pwasm-alloc" -version = "0.1.0" -dependencies = [ - "pwasm-libc 0.1.0", - "rustc_version 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "pwasm-libc" -version = "0.1.0" - [[package]] name = "quote" version = "0.6.3" @@ -540,8 +528,6 @@ dependencies = [ name = "sr-std" version = "0.1.0" dependencies = [ - "pwasm-alloc 0.1.0", - "pwasm-libc 0.1.0", "rustc_version 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/doc/packages/substrate.adoc b/doc/packages/substrate.adoc index f82ed0ee688bc..153900d783d0d 100644 --- a/doc/packages/substrate.adoc +++ b/doc/packages/substrate.adoc @@ -31,8 +31,6 @@ include::../../core/primitives/README.adoc[] include::../../pwasm-alloc/README.adoc[] -include::../../pwasm-libc/README.adoc[] - include::../../core/rpc/README.adoc[] include::../../core/rpc-servers/README.adoc[] diff --git a/node/runtime/wasm/Cargo.lock b/node/runtime/wasm/Cargo.lock index 37115314320fe..3cc27b56897d9 100644 --- a/node/runtime/wasm/Cargo.lock +++ b/node/runtime/wasm/Cargo.lock @@ -404,18 +404,6 @@ dependencies = [ "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "pwasm-alloc" -version = "0.1.0" -dependencies = [ - "pwasm-libc 0.1.0", - "rustc_version 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "pwasm-libc" -version = "0.1.0" - [[package]] name = "pwasm-utils" version = "0.3.1" @@ -611,8 +599,6 @@ dependencies = [ name = "sr-std" version = "0.1.0" dependencies = [ - "pwasm-alloc 0.1.0", - "pwasm-libc 0.1.0", "rustc_version 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/pwasm-alloc/Cargo.toml b/pwasm-alloc/Cargo.toml deleted file mode 100644 index d5dbe87e6adfe..0000000000000 --- a/pwasm-alloc/Cargo.toml +++ /dev/null @@ -1,23 +0,0 @@ -[package] -name = "pwasm-alloc" -version = "0.1.0" -authors = ["Nikolay Volf "] -license = "MIT/Apache-2.0" -readme = "README.md" -repository = "https://github.com/paritytech/pwasm-std" -homepage = "https://github.com/paritytech/pwasm-std" -documentation = "https://paritytech.github.io/pwasm-std/pwasm_std/" -description = "Parity WebAssembly standard library internal allocator" -keywords = ["wasm", "parity", "webassembly", "blockchain"] -categories = ["no-std", "embedded"] -build = "build.rs" - -[dependencies] -pwasm-libc = { path = "../pwasm-libc", version = "0.1" } - -[build-dependencies] -rustc_version = "0.2" - -[features] -strict = [] -nightly = [] diff --git a/pwasm-alloc/README.adoc b/pwasm-alloc/README.adoc deleted file mode 100644 index 5ddc97ea1b901..0000000000000 --- a/pwasm-alloc/README.adoc +++ /dev/null @@ -1,25 +0,0 @@ - -= Pwasm-alloc - -Parity WASM contracts standard library libc bindings. - -See https://paritytech.github.io/pwasm-std/pwasm_alloc/ for the documentation. - -== License - -`pwasm_alloc` is primarily distributed under the terms of both the MIT -license and the Apache License (Version 2.0), at your choice. - -See LICENSE-APACHE, and LICENSE-MIT for details. - -.Summary -[source, toml] ----- -include::Cargo.toml[lines=2..5] ----- - -.Description ----- -include::src/lib.rs[tag=description] ----- - diff --git a/pwasm-alloc/build.rs b/pwasm-alloc/build.rs deleted file mode 100644 index 35eb154f3a69a..0000000000000 --- a/pwasm-alloc/build.rs +++ /dev/null @@ -1,14 +0,0 @@ -//! Set a nightly feature - -extern crate rustc_version; -use rustc_version::{version, version_meta, Channel}; - -fn main() { - // Assert we haven't travelled back in time - assert!(version().unwrap().major >= 1); - - // Set cfg flags depending on release channel - if let Channel::Nightly = version_meta().unwrap().channel { - println!("cargo:rustc-cfg=feature=\"nightly\""); - } -} diff --git a/pwasm-alloc/src/lib.rs b/pwasm-alloc/src/lib.rs deleted file mode 100644 index b08eef6854808..0000000000000 --- a/pwasm-alloc/src/lib.rs +++ /dev/null @@ -1,34 +0,0 @@ -#![warn(missing_docs)] -#![cfg_attr(feature = "strict", deny(warnings))] -#![no_std] -#![crate_type = "rlib"] - -// tag::description[] -//! Custom allocator crate for wasm -// end::description[] - -/// Wasm allocator -pub struct WasmAllocator; - -#[cfg(feature = "nightly")] -#[global_allocator] -static ALLOCATOR: WasmAllocator = WasmAllocator; - -#[cfg(feature = "nightly")] -mod __impl { - extern crate pwasm_libc; - - use core::alloc::{GlobalAlloc, Layout}; - - use super::WasmAllocator; - - unsafe impl GlobalAlloc for WasmAllocator { - unsafe fn alloc(&self, layout: Layout) -> *mut u8 { - pwasm_libc::malloc(layout.size()) as *mut u8 - } - - unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) { - pwasm_libc::free(ptr as *mut u8) - } - } -} diff --git a/pwasm-libc/Cargo.toml b/pwasm-libc/Cargo.toml deleted file mode 100644 index d3ff1f1f320e6..0000000000000 --- a/pwasm-libc/Cargo.toml +++ /dev/null @@ -1,15 +0,0 @@ -[package] -name = "pwasm-libc" -version = "0.1.0" -authors = ["Sergey Pepyakin "] -license = "MIT/Apache-2.0" -readme = "README.md" -repository = "https://github.com/paritytech/pwasm-std" -homepage = "https://github.com/paritytech/pwasm-std" -documentation = "https://paritytech.github.io/pwasm-std/pwasm_std/" -description = "Parity WebAssembly standard library libc bindings" -keywords = ["wasm", "parity", "webassembly", "blockchain"] -categories = ["no-std", "embedded"] - -[features] -strict = [] diff --git a/pwasm-libc/README.adoc b/pwasm-libc/README.adoc deleted file mode 100644 index e1cba6632f1df..0000000000000 --- a/pwasm-libc/README.adoc +++ /dev/null @@ -1,24 +0,0 @@ - -= Pwasm-libc - -Parity WASM contracts standard library libc bindings - -https://paritytech.github.io/pwasm-std/pwasm_libc/[Documentation] - -== License - -`pwasm-libc` is primarily distributed under the terms of both the MIT -license and the Apache License (Version 2.0), at your choice. - -See LICENSE-APACHE, and LICENSE-MIT for details. - -.Summary -[source, toml] ----- -include::Cargo.toml[lines=2..5] ----- - -.Description ----- -include::src/lib.rs[tag=description] ----- diff --git a/pwasm-libc/src/lib.rs b/pwasm-libc/src/lib.rs deleted file mode 100644 index 6b97ff378890b..0000000000000 --- a/pwasm-libc/src/lib.rs +++ /dev/null @@ -1,55 +0,0 @@ -#![warn(missing_docs)] -#![cfg_attr(feature = "strict", deny(warnings))] -#![no_std] - -// tag::description[] -//! libc externs crate -// end::description[] - -extern "C" { - fn ext_memcpy(dest: *mut u8, src: *const u8, n: usize) -> *mut u8; - fn ext_memmove(dest: *mut u8, src: *const u8, n: usize) -> *mut u8; - fn ext_memset(dest: *mut u8, c: i32, n: usize) -> *mut u8; - fn ext_memcmp(s1: *const u8, s2: *const u8, n: usize) -> i32; - fn ext_malloc(size: usize) -> *mut u8; - fn ext_free(ptr: *mut u8); -} - -// Declaring these function here prevents Emscripten from including it's own verisons -// into final binary. - -/// memcpy extern -#[no_mangle] -pub unsafe extern "C" fn memcpy(dest: *mut u8, src: *const u8, n: usize) -> *mut u8 { - ext_memcpy(dest, src, n) -} - -/// memcmp extern -#[no_mangle] -pub unsafe extern "C" fn memcmp(s1: *const u8, s2: *const u8, n: usize) -> i32 { - ext_memcmp(s1, s2, n) -} - -/// memmove extern -#[no_mangle] -pub unsafe extern "C" fn memmove(dest: *mut u8, src: *const u8, n: usize) -> *mut u8 { - ext_memmove(dest, src, n) -} - -/// memset extern -#[no_mangle] -pub unsafe extern "C" fn memset(dest: *mut u8, c: i32, n: usize) -> *mut u8 { - ext_memset(dest, c, n) -} - -/// malloc extern -#[no_mangle] -pub unsafe extern "C" fn malloc(size: usize) -> *mut u8 { - ext_malloc(size) -} - -/// free extern -#[no_mangle] -pub unsafe extern "C" fn free(ptr: *mut u8) { - ext_free(ptr); -}