Correct implementation of memcmp

This commit is contained in:
Gav
2018-01-29 17:19:56 +01:00
parent 1e0b133841
commit c8c0879f3d
10 changed files with 18 additions and 14 deletions
+6
View File
@@ -59,5 +59,11 @@ error_chain! {
description("runtime failure"),
display("Runtime error"),
}
/// Runtime failed.
InvalidMemoryReference {
description("invalid memory reference"),
display("Invalid memory reference"),
}
}
}
+1 -1
View File
@@ -36,7 +36,7 @@ extern crate byteorder;
extern crate rustc_hex;
extern crate native_runtime;
extern crate runtime_std;
extern crate memcmp;
extern crate libc;
#[macro_use]
extern crate error_chain;
+8 -4
View File
@@ -16,10 +16,11 @@
//! Rust implementation of Polkadot contracts.
use libc::{memcmp, c_void};
use std::sync::Arc;
use std::collections::HashMap;
use parity_wasm::{deserialize_buffer, ModuleInstanceInterface, ProgramInstance};
use parity_wasm::interpreter::{ItemIndex};
use parity_wasm::interpreter::{ItemIndex, DummyUserError};
use parity_wasm::RuntimeValue::{I32, I64};
use primitives::contract::CallData;
use state_machine::{Externalities, CodeExecutor};
@@ -96,10 +97,13 @@ impl_function_executor!(this: FunctionExecutor<'e, E>,
ext_memcmp(s1: *const u8, s2: *const u8, n: usize) -> i32 => {
if let (Ok(sl1), Ok(sl2))
= (this.memory.get(s1, n as usize), this.memory.get(s2, n as usize)) {
use memcmp::Memcmp;
(&sl1).memcmp(&sl2) as i32
unsafe {
memcmp(sl1.as_ptr() as *const u8 as *const c_void,
sl2.as_ptr() as *const u8 as *const c_void,
n as usize) as i32
}
} else {
0
return Err(DummyUserError.into());
}
},
ext_memcpy(dest: *mut u8, src: *const u8, count: usize) -> *mut u8 => {