This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Merged
Changes from 1 commit
Commits
Show all changes
51 commits
Select commit
Hold shift + click to select a range
4f5c5b6
Introduce first groundwork for Wasm executor.
gavofyork 6237848
Remove old Rust-runtime code.
gavofyork 293cf5d
Avoid commiting compled files.
gavofyork 66b636e
Add runtime precompile.
gavofyork c7e7456
Rename so module makes more sense.
gavofyork 0cfd67e
Further renaming.
gavofyork 3011edf
Ensure tests work.
gavofyork a74b4fa
Allow bringing in of externalities.
gavofyork 6dac275
Nice macros for imports.
gavofyork 08f7b26
Allow passing in of data through allocators.
gavofyork 1ace6b2
Can now pass in bytes to WasmExecutor.
gavofyork 27e5fed
Additional cleanup.
gavofyork 13dcd89
Switch usages of `OutData` to `u64`
gavofyork 84b9f84
convert to safe but extremely verbose type conversion.
gavofyork 7f31899
Remove StaticExternalities distinction.
gavofyork edf061e
Remove another unused use.
gavofyork edb6bea
Refactor wasm utils out
gavofyork 9f59f48
Remove extraneous copies that weren't really testing anything.
gavofyork 287b29d
Try to use wasm 0.15
gavofyork 1bd55fe
Make it work!
gavofyork 36e254a
Call-time externalities working.
gavofyork cd651a3
Add basic externalities.
gavofyork a8f9cca
Merge branch 'with-wasm-0.15' into with-wasm
gavofyork 4404846
Fix grumbles and note unwraps to be sorted.
gavofyork b1d963a
Test storage externality.
gavofyork 319d9c0
Fix nits.
gavofyork 7ec9221
Merge branch 'master' into with-wasm
gavofyork 2934d94
Compile collation logic.
gavofyork 5998aa1
Move back to refs. Yey.
gavofyork 3f4085a
Remove "object" id for storage access.
gavofyork 4be0537
Fix test.
gavofyork 01d7019
Fix up rest of tests.
gavofyork db1adee
remove unwrap.
gavofyork 87c54f7
Expose set/get code in externalities
gavofyork 471ea1e
Add validator set.
gavofyork fa35993
Introduce validator set into externalities and test.
gavofyork a0f64df
Add another external function.
gavofyork e736d46
Remove code and validators; use storage for everything.
gavofyork 234297c
Introduce validators function.
gavofyork 3f8a96d
Tests (and a fix) for the validators getter.
gavofyork 6636520
Allow calls into runtime to return data.
gavofyork 964659e
Remove unneeded trace.
gavofyork 8ca1b7b
Make runtime printing a bit nicer.
gavofyork 74156a2
Create separate runtimes for testing and polkadot.
gavofyork 611a7ac
Remove commented code.
gavofyork c3afecc
Use new path.
gavofyork ea4d6c5
Refactor into shared support module.
gavofyork 709693d
Fix warning.
gavofyork ec1e6b6
Remove unwraps.
gavofyork 5c0ec3d
Make macro a little less unhygenic.
gavofyork 79ab46f
Add wasm files.
gavofyork File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Refactor into shared support module.
- Loading branch information
commit ea4d6c5d330425a52db20957c1ab0e16d44eaa8e
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,5 +7,4 @@ authors = ["Parity Technologies <[email protected]>"] | |
| crate-type = ["cdylib"] | ||
|
|
||
| [dependencies] | ||
| pwasm-libc = { path = "../pwasm-libc", version = "0.1" } | ||
| pwasm-alloc = { path = "../pwasm-alloc", version = "0.1" } | ||
| runtime-support = { path = "../support", version = "0.1" } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| [package] | ||
| name = "runtime-support" | ||
| version = "0.1.0" | ||
| authors = ["Parity Technologies <[email protected]>"] | ||
|
|
||
| [dependencies] | ||
| pwasm-libc = { path = "../pwasm-libc", version = "0.1" } | ||
| pwasm-alloc = { path = "../pwasm-alloc", version = "0.1" } | ||
|
|
||
| [features] | ||
| strict = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| #![no_std] | ||
| #![feature(lang_items)] | ||
| #![cfg_attr(feature = "strict", deny(warnings))] | ||
|
|
||
| #![feature(alloc)] | ||
|
|
||
| extern crate alloc; | ||
| use alloc::vec::Vec; | ||
|
|
||
| extern crate pwasm_libc; | ||
| extern crate pwasm_alloc; | ||
|
|
||
| #[lang = "panic_fmt"] | ||
| #[no_mangle] | ||
| pub fn panic_fmt() -> ! { | ||
| loop {} | ||
| } | ||
|
|
||
| extern "C" { | ||
| fn ext_print(utf8_data: *const u8, utf8_len: i32); | ||
| fn ext_print_num(value: u64); | ||
| fn ext_set_storage(key_data: *const u8, key_len: i32, value_data: *const u8, value_len: i32); | ||
| fn ext_get_allocated_storage(key_data: *const u8, key_len: i32, written_out: *mut i32) -> *mut u8; | ||
| } | ||
|
|
||
| pub fn storage(key: &[u8]) -> Vec<u8> { | ||
| let mut length: i32 = 0; | ||
| unsafe { | ||
| let ptr = ext_get_allocated_storage(&key[0], key.len() as i32, &mut length); | ||
| Vec::from_raw_parts(ptr, length as usize, length as usize) | ||
| } | ||
| } | ||
|
|
||
| pub fn set_storage(key: &[u8], value: &[u8]) { | ||
| unsafe { | ||
| ext_set_storage( | ||
| &key[0] as *const u8, key.len() as i32, | ||
| &value[0] as *const u8, value.len() as i32 | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| pub fn code() -> Vec<u8> { | ||
| storage(b"\0code") | ||
| } | ||
|
|
||
| pub fn set_code(new: &[u8]) { | ||
| set_storage(b"\0code", new) | ||
| } | ||
|
|
||
| fn value_vec(mut value: usize, initial: Vec<u8>) -> Vec<u8> { | ||
| let mut acc = initial; | ||
| while value > 0 { | ||
| acc.push(value as u8); | ||
| value /= 256; | ||
| } | ||
| acc | ||
| } | ||
|
|
||
| pub fn set_validator(index: usize, validator: &[u8]) { | ||
| set_storage(&value_vec(index, b"\0validator".to_vec()), validator); | ||
| } | ||
|
|
||
| pub fn validator(index: usize) -> Vec<u8> { | ||
| storage(&value_vec(index, b"\0validator".to_vec())) | ||
| } | ||
|
|
||
| pub fn set_validator_count(count: usize) { | ||
| (count..validator_count()).for_each(|i| set_validator(i, &[])); | ||
| set_storage(b"\0validator_count", &value_vec(count, Vec::new())); | ||
| } | ||
|
|
||
| pub fn validator_count() -> usize { | ||
| storage(b"\0validator_count").into_iter().rev().fold(0, |acc, i| (acc << 8) + (i as usize)) | ||
| } | ||
|
|
||
| pub fn validators() -> Vec<Vec<u8>> { | ||
| (0..validator_count()).into_iter().map(validator).collect() | ||
| } | ||
|
|
||
| pub fn set_validators(validators: &[&[u8]]) { | ||
| set_validator_count(validators.len()); | ||
| validators.iter().enumerate().for_each(|(v, i)| set_validator(v, i)); | ||
| } | ||
|
|
||
| pub trait Printable { | ||
| fn print(self); | ||
| } | ||
|
|
||
| impl<'a> Printable for &'a [u8] { | ||
| fn print(self) { | ||
| unsafe { | ||
| ext_print(&self[0] as *const u8, self.len() as i32); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl Printable for u64 { | ||
| fn print(self) { | ||
| unsafe { ext_print_num(self); } | ||
| } | ||
| } | ||
|
|
||
| pub fn print<T: Printable + Sized>(value: T) { | ||
| value.print(); | ||
| } | ||
|
|
||
| #[macro_export] | ||
| macro_rules! impl_stub { | ||
| ($name:ident) => { | ||
| pub mod _internal { | ||
| #[no_mangle] | ||
| pub fn $name(input_data: *mut u8, input_len: usize) -> u64 { | ||
| let input = unsafe { | ||
| super::alloc::vec::Vec::from_raw_parts(input_data, input_len, input_len) | ||
| }; | ||
|
|
||
| let output = super::$name(input); | ||
| &output[0] as *const u8 as u64 + ((output.len() as u64) << 32) | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,5 +7,4 @@ authors = ["Parity Technologies <[email protected]>"] | |
| crate-type = ["cdylib"] | ||
|
|
||
| [dependencies] | ||
| pwasm-libc = { path = "../pwasm-libc", version = "0.1" } | ||
| pwasm-alloc = { path = "../pwasm-alloc", version = "0.1" } | ||
| runtime-support = { path = "../support", version = "0.1" } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a little unhygienic. could we use
$crate::alloc?Also, is there a guarantee that input data is heap-allocated and can really be freed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes - that's given by the other side which (as might be imagined) calls the heap allocator.