2017-07-10 17:42:10 +02:00
|
|
|
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
|
|
|
|
// This file is part of Parity.
|
|
|
|
|
|
|
|
// Parity is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// Parity is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2017-08-01 13:33:49 +02:00
|
|
|
//! Wasm env module bindings
|
2017-07-10 17:42:10 +02:00
|
|
|
|
|
|
|
use parity_wasm::elements::ValueType::*;
|
2017-08-20 06:02:59 +02:00
|
|
|
use parity_wasm::interpreter::{self, UserFunctionDescriptor};
|
2017-07-10 17:42:10 +02:00
|
|
|
use parity_wasm::interpreter::UserFunctionDescriptor::*;
|
2017-09-10 18:02:31 +02:00
|
|
|
use super::runtime::{Runtime, UserTrap};
|
2017-07-10 17:42:10 +02:00
|
|
|
|
|
|
|
pub const SIGNATURES: &'static [UserFunctionDescriptor] = &[
|
|
|
|
Static(
|
|
|
|
"_storage_read",
|
|
|
|
&[I32; 2],
|
2017-11-20 14:38:54 +01:00
|
|
|
None,
|
2017-07-10 17:42:10 +02:00
|
|
|
),
|
|
|
|
Static(
|
|
|
|
"_storage_write",
|
|
|
|
&[I32; 2],
|
2017-11-20 14:38:54 +01:00
|
|
|
None,
|
2017-07-10 17:42:10 +02:00
|
|
|
),
|
2017-10-04 18:09:18 +02:00
|
|
|
Static(
|
|
|
|
"_balance",
|
|
|
|
&[I32; 2],
|
|
|
|
None,
|
|
|
|
),
|
2017-07-10 17:42:10 +02:00
|
|
|
Static(
|
2017-11-12 22:21:15 +01:00
|
|
|
"_ext_malloc",
|
2017-07-10 17:42:10 +02:00
|
|
|
&[I32],
|
|
|
|
Some(I32),
|
|
|
|
),
|
|
|
|
Static(
|
2017-11-12 22:21:15 +01:00
|
|
|
"_ext_free",
|
2017-07-10 17:42:10 +02:00
|
|
|
&[I32],
|
|
|
|
None,
|
|
|
|
),
|
|
|
|
Static(
|
|
|
|
"gas",
|
|
|
|
&[I32],
|
|
|
|
None,
|
|
|
|
),
|
|
|
|
Static(
|
|
|
|
"_debug",
|
|
|
|
&[I32; 2],
|
|
|
|
None,
|
|
|
|
),
|
|
|
|
Static(
|
|
|
|
"_suicide",
|
|
|
|
&[I32],
|
|
|
|
None,
|
|
|
|
),
|
|
|
|
Static(
|
|
|
|
"_create",
|
|
|
|
&[I32; 4],
|
|
|
|
Some(I32),
|
|
|
|
),
|
|
|
|
Static(
|
2017-07-24 16:45:15 +02:00
|
|
|
"_ccall",
|
2017-12-22 19:54:35 +01:00
|
|
|
&[I64, I32, I32, I32, I32, I32, I32],
|
2017-07-24 16:45:15 +02:00
|
|
|
Some(I32),
|
2017-07-10 17:42:10 +02:00
|
|
|
),
|
|
|
|
Static(
|
2017-07-24 16:45:15 +02:00
|
|
|
"_dcall",
|
2017-12-22 19:54:35 +01:00
|
|
|
&[I64, I32, I32, I32, I32, I32],
|
2017-07-24 16:45:15 +02:00
|
|
|
Some(I32),
|
2017-07-10 17:42:10 +02:00
|
|
|
),
|
|
|
|
Static(
|
2017-07-24 16:45:15 +02:00
|
|
|
"_scall",
|
2017-12-22 19:54:35 +01:00
|
|
|
&[I64, I32, I32, I32, I32, I32],
|
2017-07-24 16:45:15 +02:00
|
|
|
Some(I32),
|
2017-07-10 17:42:10 +02:00
|
|
|
),
|
|
|
|
Static(
|
2017-07-24 16:45:15 +02:00
|
|
|
"abort",
|
2017-07-10 17:42:10 +02:00
|
|
|
&[I32],
|
|
|
|
None,
|
|
|
|
),
|
|
|
|
Static(
|
2017-07-24 16:45:15 +02:00
|
|
|
"_emscripten_memcpy_big",
|
|
|
|
&[I32; 3],
|
2017-07-10 17:42:10 +02:00
|
|
|
Some(I32),
|
|
|
|
),
|
2017-11-12 22:21:15 +01:00
|
|
|
Static(
|
|
|
|
"_ext_memcpy",
|
|
|
|
&[I32; 3],
|
|
|
|
Some(I32),
|
|
|
|
),
|
|
|
|
Static(
|
|
|
|
"_ext_memset",
|
|
|
|
&[I32; 3],
|
|
|
|
Some(I32),
|
|
|
|
),
|
|
|
|
Static(
|
|
|
|
"_ext_memmove",
|
|
|
|
&[I32; 3],
|
|
|
|
Some(I32),
|
|
|
|
),
|
2017-09-10 18:02:31 +02:00
|
|
|
Static(
|
|
|
|
"_panic",
|
|
|
|
&[I32; 2],
|
|
|
|
None,
|
|
|
|
),
|
|
|
|
Static(
|
|
|
|
"_blockhash",
|
2017-11-12 22:21:15 +01:00
|
|
|
&[I64, I32],
|
2017-11-26 21:18:58 +01:00
|
|
|
None,
|
2017-09-10 18:02:31 +02:00
|
|
|
),
|
|
|
|
Static(
|
|
|
|
"_coinbase",
|
|
|
|
&[I32],
|
|
|
|
None,
|
|
|
|
),
|
2017-10-04 13:15:59 +02:00
|
|
|
Static(
|
|
|
|
"_sender",
|
|
|
|
&[I32],
|
|
|
|
None,
|
|
|
|
),
|
|
|
|
Static(
|
|
|
|
"_origin",
|
|
|
|
&[I32],
|
|
|
|
None,
|
|
|
|
),
|
|
|
|
Static(
|
|
|
|
"_address",
|
|
|
|
&[I32],
|
|
|
|
None,
|
|
|
|
),
|
|
|
|
Static(
|
|
|
|
"_value",
|
|
|
|
&[I32],
|
|
|
|
None,
|
|
|
|
),
|
2017-09-10 18:02:31 +02:00
|
|
|
Static(
|
|
|
|
"_timestamp",
|
|
|
|
&[],
|
2017-11-12 22:21:15 +01:00
|
|
|
Some(I64),
|
2017-09-10 18:02:31 +02:00
|
|
|
),
|
|
|
|
Static(
|
|
|
|
"_blocknumber",
|
|
|
|
&[],
|
2017-11-12 22:21:15 +01:00
|
|
|
Some(I64),
|
2017-09-10 18:02:31 +02:00
|
|
|
),
|
|
|
|
Static(
|
|
|
|
"_difficulty",
|
|
|
|
&[I32],
|
|
|
|
None,
|
|
|
|
),
|
|
|
|
Static(
|
|
|
|
"_gaslimit",
|
|
|
|
&[I32],
|
|
|
|
None,
|
|
|
|
),
|
2017-11-05 16:54:35 +01:00
|
|
|
Static(
|
|
|
|
"_elog",
|
|
|
|
&[I32; 4],
|
|
|
|
None,
|
|
|
|
),
|
2017-08-14 11:33:52 +02:00
|
|
|
|
|
|
|
// TODO: Get rid of it also somehow?
|
2017-07-27 14:36:55 +02:00
|
|
|
Static(
|
|
|
|
"_llvm_trap",
|
|
|
|
&[I32; 0],
|
|
|
|
None
|
|
|
|
),
|
2017-08-20 06:02:59 +02:00
|
|
|
|
|
|
|
Static(
|
|
|
|
"_llvm_bswap_i64",
|
2017-11-12 22:21:15 +01:00
|
|
|
&[I64],
|
|
|
|
Some(I64)
|
2017-08-20 06:02:59 +02:00
|
|
|
),
|
2017-07-10 17:42:10 +02:00
|
|
|
];
|
2017-08-20 06:02:59 +02:00
|
|
|
|
2017-09-10 18:02:31 +02:00
|
|
|
pub fn native_bindings<'a>(runtime: &'a mut Runtime) -> interpreter::UserDefinedElements<'a, UserTrap> {
|
|
|
|
interpreter::UserDefinedElements {
|
|
|
|
executor: Some(runtime),
|
|
|
|
globals: ::std::collections::HashMap::new(),
|
2017-08-20 06:02:59 +02:00
|
|
|
functions: ::std::borrow::Cow::from(SIGNATURES),
|
|
|
|
}
|
2017-10-04 18:09:18 +02:00
|
|
|
}
|