Skip to content

Commit

Permalink
further fixes for eos-vm integration
Browse files Browse the repository at this point in the history
  • Loading branch information
larryk85 committed May 9, 2019
1 parent b7641fd commit 5a9bf2c
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 144 deletions.
58 changes: 14 additions & 44 deletions libraries/chain/include/eosio/chain/webassembly/eos-vm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ namespace eosio { namespace wasm_backend {
typedef uint64_t type;
};

template <typename S, typename Args, size_t I, typename T, typename WAlloc, typename Cleanups>
constexpr auto get_value(operand_stack& op, Cleanups&, WAlloc*, T&& val)
-> std::enable_if_t<std::is_same_v<i64_const_t, T> && std::is_same_v<chain::name, std::decay_t<S>>, S> {
template <typename S, typename Args, typename T, typename WAlloc>
constexpr auto get_value(WAlloc*, T&& val)
-> std::enable_if_t<std::is_same_v<i64_const_t, T> && std::is_same_v<chain::name, std::decay_t<S>>, S> {
return {(uint64_t)val.data.ui};
}

Expand All @@ -28,43 +28,13 @@ namespace eosio { namespace wasm_backend {
typedef uint32_t type;
};

template <typename S, typename Args, size_t I, typename T, typename WAlloc, typename Cleanups>
constexpr auto get_value(operand_stack& op, Cleanups& cleanups, WAlloc* walloc, T&& val)
-> std::enable_if_t<std::is_same_v<i32_const_t, T> &&
std::is_same_v< eosio::chain::array_ptr<typename S::type>, S> &&
!std::is_lvalue_reference_v<S> && !std::is_pointer_v<S>, S> {
//size_t i = std::tuple_size<Args>::value-1;
template <typename S, typename Args, typename T, typename WAlloc>
constexpr auto get_value(WAlloc* walloc, T&& val)
-> std::enable_if_t<std::is_same_v<i32_const_t, T> &&
std::is_same_v< eosio::chain::array_ptr<typename S::type>, S> &&
!std::is_lvalue_reference_v<S> && !std::is_pointer_v<S>, S> {
using ptr_ty = typename S::type;
using under_ty = std::remove_pointer_t<ptr_ty>;
auto* ptr = (ptr_ty*)((walloc->template get_base_ptr<char>())+val.data.ui);
/*
if constexpr (std::tuple_size<Args>::value > I) {
const auto& next_arg = std::get<to_wasm_t<typename std::tuple_element<I, Args>::type>>(op.get_back(i-I)).data.ui;
size_t sz = 0;
if constexpr ( (std::tuple_size<Args>::value > I+1)
&& std::is_same_v<decltype(next_arg), eosio::chain::array_ptr<under_ty>>) {
sz = std::get<to_wasm_t<typename std::tuple_element<I+1, Args>::type>>(op.get_back(i-(I+1))).data.ui;
std::cout << "sz0 " << sz << "\n";
} else {
sz = next_arg;
std::cout << "sz1 " << sz << " sizeof " << sizeof(under_ty) << " alignof " << alignof(under_ty) << "\n";
}
if ((uintptr_t)ptr % 16 != 0) {
std::cout << "aligning\n";
align_ptr_triple apt;
apt.s = sizeof(under_ty)*sz;
std::vector<std::remove_const_t<under_ty>> cpy(sz > 0 ? sz : 1);
apt.o = (void*)ptr;
ptr = (decltype(ptr))cpy.data();
apt.n = (void*)ptr;
//memcpy((std::remove_const_t<under_ty>*)apt.n, (const under_ty*)apt.o, apt.s);
memmove( static_cast<char*>(apt.n), static_cast<const char*>(apt.o), apt.s);
if constexpr (!std::is_const_v<under_ty>)
cleanups.emplace_back(std::move(apt));
}
}
*/
return eosio::chain::array_ptr<under_ty>(ptr);
return eosio::chain::array_ptr<ptr_ty>((ptr_ty*)((walloc->template get_base_ptr<char>())+val.data.ui));
}

template <typename Ctx>
Expand All @@ -82,11 +52,11 @@ namespace eosio { namespace wasm_backend {
typedef uint32_t type;
};

template <typename S, typename Args, size_t I, typename T, typename WAlloc, typename Cleanups>
constexpr auto get_value(operand_stack& op, Cleanups&, WAlloc* walloc, T&& val)
-> std::enable_if_t<std::is_same_v<i32_const_t, T> &&
std::is_same_v< eosio::chain::null_terminated_ptr, S> &&
!std::is_lvalue_reference_v<S> && !std::is_pointer_v<S>, S> {
template <typename S, typename Args, typename T, typename WAlloc>
constexpr auto get_value(WAlloc* walloc, T&& val)
-> std::enable_if_t<std::is_same_v<i32_const_t, T> &&
std::is_same_v< eosio::chain::null_terminated_ptr, S> &&
!std::is_lvalue_reference_v<S> && !std::is_pointer_v<S>, S> {
return eosio::chain::null_terminated_ptr((char*)(walloc->template get_base_ptr<uint8_t>()+val.data.ui));
}

Expand Down
196 changes: 97 additions & 99 deletions libraries/chain/wasm_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -904,24 +904,24 @@ class authorization_api : public context_aware_api {
public:
using context_aware_api::context_aware_api;

void require_authorization( const account_name& account ) {
void require_auth( account_name account ) {
context.require_authorization( account );
}

bool has_authorization( const account_name& account )const {
bool has_auth( account_name account )const {
return context.has_authorization( account );
}

void require_authorization2(const account_name& account,
const permission_name& permission) {
void require_auth2( account_name account,
permission_name permission) {
context.require_authorization( account, permission );
}

void require_recipient( account_name recipient ) {
context.require_recipient( recipient );
}

bool is_account( const account_name& account )const {
bool is_account( account_name account )const {
return context.is_account( account );
}

Expand Down Expand Up @@ -1015,8 +1015,6 @@ class action_api : public context_aware_api {
}

int action_data_size() {
std::cout << "THIS " << this << "\n";
std::cout << "ADS " << context.get_action().data.size() << "\n";
return context.get_action().data.size();
}

Expand Down Expand Up @@ -1698,53 +1696,53 @@ class call_depth_api : public context_aware_api {
};

REGISTER_INJECTED_INTRINSICS(call_depth_api,
(call_depth_assert, void() )
(call_depth_assert, void() )
);

REGISTER_INTRINSICS(compiler_builtins,
(__ashlti3, void(int, int64_t, int64_t, int) )
(__ashrti3, void(int, int64_t, int64_t, int) )
(__lshlti3, void(int, int64_t, int64_t, int) )
(__lshrti3, void(int, int64_t, int64_t, int) )
(__divti3, void(int, int64_t, int64_t, int64_t, int64_t) )
(__udivti3, void(int, int64_t, int64_t, int64_t, int64_t) )
(__modti3, void(int, int64_t, int64_t, int64_t, int64_t) )
(__umodti3, void(int, int64_t, int64_t, int64_t, int64_t) )
(__multi3, void(int, int64_t, int64_t, int64_t, int64_t) )
(__addtf3, void(int, int64_t, int64_t, int64_t, int64_t) )
(__subtf3, void(int, int64_t, int64_t, int64_t, int64_t) )
(__multf3, void(int, int64_t, int64_t, int64_t, int64_t) )
(__divtf3, void(int, int64_t, int64_t, int64_t, int64_t) )
(__eqtf2, int(int64_t, int64_t, int64_t, int64_t) )
(__netf2, int(int64_t, int64_t, int64_t, int64_t) )
(__getf2, int(int64_t, int64_t, int64_t, int64_t) )
(__gttf2, int(int64_t, int64_t, int64_t, int64_t) )
(__lttf2, int(int64_t, int64_t, int64_t, int64_t) )
(__letf2, int(int64_t, int64_t, int64_t, int64_t) )
(__cmptf2, int(int64_t, int64_t, int64_t, int64_t) )
(__unordtf2, int(int64_t, int64_t, int64_t, int64_t) )
(__negtf2, void (int, int64_t, int64_t) )
(__floatsitf, void (int, int) )
(__floatunsitf, void (int, int) )
(__floatditf, void (int, int64_t) )
(__floatunditf, void (int, int64_t) )
(__floattidf, double (int64_t, int64_t) )
(__floatuntidf, double (int64_t, int64_t) )
(__floatsidf, double(int) )
(__extendsftf2, void(int, float) )
(__extenddftf2, void(int, double) )
(__fixtfti, void(int, int64_t, int64_t) )
(__fixtfdi, int64_t(int64_t, int64_t) )
(__fixtfsi, int(int64_t, int64_t) )
(__fixunstfti, void(int, int64_t, int64_t) )
(__fixunstfdi, int64_t(int64_t, int64_t) )
(__fixunstfsi, int(int64_t, int64_t) )
(__fixsfti, void(int, float) )
(__fixdfti, void(int, double) )
(__fixunssfti, void(int, float) )
(__fixunsdfti, void(int, double) )
(__trunctfdf2, double(int64_t, int64_t) )
(__trunctfsf2, float(int64_t, int64_t) )
(__ashlti3, void(int, int64_t, int64_t, int) )
(__ashrti3, void(int, int64_t, int64_t, int) )
(__lshlti3, void(int, int64_t, int64_t, int) )
(__lshrti3, void(int, int64_t, int64_t, int) )
(__divti3, void(int, int64_t, int64_t, int64_t, int64_t) )
(__udivti3, void(int, int64_t, int64_t, int64_t, int64_t) )
(__modti3, void(int, int64_t, int64_t, int64_t, int64_t) )
(__umodti3, void(int, int64_t, int64_t, int64_t, int64_t) )
(__multi3, void(int, int64_t, int64_t, int64_t, int64_t) )
(__addtf3, void(int, int64_t, int64_t, int64_t, int64_t) )
(__subtf3, void(int, int64_t, int64_t, int64_t, int64_t) )
(__multf3, void(int, int64_t, int64_t, int64_t, int64_t) )
(__divtf3, void(int, int64_t, int64_t, int64_t, int64_t) )
(__eqtf2, int(int64_t, int64_t, int64_t, int64_t) )
(__netf2, int(int64_t, int64_t, int64_t, int64_t) )
(__getf2, int(int64_t, int64_t, int64_t, int64_t) )
(__gttf2, int(int64_t, int64_t, int64_t, int64_t) )
(__lttf2, int(int64_t, int64_t, int64_t, int64_t) )
(__letf2, int(int64_t, int64_t, int64_t, int64_t) )
(__cmptf2, int(int64_t, int64_t, int64_t, int64_t) )
(__unordtf2, int(int64_t, int64_t, int64_t, int64_t) )
(__negtf2, void (int, int64_t, int64_t) )
(__floatsitf, void (int, int) )
(__floatunsitf, void (int, int) )
(__floatditf, void (int, int64_t) )
(__floatunditf, void (int, int64_t) )
(__floattidf, double (int64_t, int64_t) )
(__floatuntidf, double (int64_t, int64_t) )
(__floatsidf, double(int) )
(__extendsftf2, void(int, float) )
(__extenddftf2, void(int, double) )
(__fixtfti, void(int, int64_t, int64_t) )
(__fixtfdi, int64_t(int64_t, int64_t) )
(__fixtfsi, int(int64_t, int64_t) )
(__fixunstfti, void(int, int64_t, int64_t) )
(__fixunstfdi, int64_t(int64_t, int64_t) )
(__fixunstfsi, int(int64_t, int64_t) )
(__fixsfti, void(int, float) )
(__fixdfti, void(int, double) )
(__fixunssfti, void(int, float) )
(__fixunsdfti, void(int, double) )
(__trunctfdf2, double(int64_t, int64_t) )
(__trunctfsf2, float(int64_t, int64_t) )
);

REGISTER_INTRINSICS(privileged_api,
Expand All @@ -1761,48 +1759,48 @@ REGISTER_INTRINSICS(privileged_api,
);

REGISTER_INJECTED_INTRINSICS(transaction_context,
(checktime, void())
(checktime, void() )
);

REGISTER_INTRINSICS(producer_api,
(get_active_producers, int(int, int) )
);

#define DB_SECONDARY_INDEX_METHODS_SIMPLE(IDX) \
(db_##IDX##_store, int(int64_t,int64_t,int64_t,int64_t,int))\
(db_##IDX##_remove, void(int))\
(db_##IDX##_update, void(int,int64_t,int))\
(db_##IDX##_find_primary, int(int64_t,int64_t,int64_t,int,int64_t))\
(db_##IDX##_find_secondary, int(int64_t,int64_t,int64_t,int,int))\
(db_##IDX##_lowerbound, int(int64_t,int64_t,int64_t,int,int))\
(db_##IDX##_upperbound, int(int64_t,int64_t,int64_t,int,int))\
(db_##IDX##_end, int(int64_t,int64_t,int64_t))\
(db_##IDX##_next, int(int, int))\
(db_##IDX##_previous, int(int, int))
(db_##IDX##_store, int(int64_t,int64_t,int64_t,int64_t,int) )\
(db_##IDX##_remove, void(int) )\
(db_##IDX##_update, void(int,int64_t,int) )\
(db_##IDX##_find_primary, int(int64_t,int64_t,int64_t,int,int64_t) )\
(db_##IDX##_find_secondary, int(int64_t,int64_t,int64_t,int,int) )\
(db_##IDX##_lowerbound, int(int64_t,int64_t,int64_t,int,int) )\
(db_##IDX##_upperbound, int(int64_t,int64_t,int64_t,int,int) )\
(db_##IDX##_end, int(int64_t,int64_t,int64_t) )\
(db_##IDX##_next, int(int, int) )\
(db_##IDX##_previous, int(int, int) )

#define DB_SECONDARY_INDEX_METHODS_ARRAY(IDX) \
(db_##IDX##_store, int(int64_t,int64_t,int64_t,int64_t,int,int))\
(db_##IDX##_remove, void(int))\
(db_##IDX##_update, void(int,int64_t,int,int))\
(db_##IDX##_find_primary, int(int64_t,int64_t,int64_t,int,int,int64_t))\
(db_##IDX##_find_secondary, int(int64_t,int64_t,int64_t,int,int,int))\
(db_##IDX##_lowerbound, int(int64_t,int64_t,int64_t,int,int,int))\
(db_##IDX##_upperbound, int(int64_t,int64_t,int64_t,int,int,int))\
(db_##IDX##_end, int(int64_t,int64_t,int64_t))\
(db_##IDX##_next, int(int, int))\
(db_##IDX##_previous, int(int, int))
(db_##IDX##_store, int(int64_t,int64_t,int64_t,int64_t,int,int) )\
(db_##IDX##_remove, void(int) )\
(db_##IDX##_update, void(int,int64_t,int,int) )\
(db_##IDX##_find_primary, int(int64_t,int64_t,int64_t,int,int,int64_t) )\
(db_##IDX##_find_secondary, int(int64_t,int64_t,int64_t,int,int,int) )\
(db_##IDX##_lowerbound, int(int64_t,int64_t,int64_t,int,int,int) )\
(db_##IDX##_upperbound, int(int64_t,int64_t,int64_t,int,int,int) )\
(db_##IDX##_end, int(int64_t,int64_t,int64_t) )\
(db_##IDX##_next, int(int, int) )\
(db_##IDX##_previous, int(int, int) )

REGISTER_INTRINSICS( database_api,
(db_store_i64, int(int64_t,int64_t,int64_t,int64_t,int,int))
(db_update_i64, void(int,int64_t,int,int))
(db_remove_i64, void(int))
(db_get_i64, int(int, int, int))
(db_next_i64, int(int, int))
(db_previous_i64, int(int, int))
(db_find_i64, int(int64_t,int64_t,int64_t,int64_t))
(db_lowerbound_i64, int(int64_t,int64_t,int64_t,int64_t))
(db_upperbound_i64, int(int64_t,int64_t,int64_t,int64_t))
(db_end_i64, int(int64_t,int64_t,int64_t))
(db_store_i64, int(int64_t,int64_t,int64_t,int64_t,int,int) )
(db_update_i64, void(int,int64_t,int,int) )
(db_remove_i64, void(int) )
(db_get_i64, int(int, int, int) )
(db_next_i64, int(int, int) )
(db_previous_i64, int(int, int) )
(db_find_i64, int(int64_t,int64_t,int64_t,int64_t) )
(db_lowerbound_i64, int(int64_t,int64_t,int64_t,int64_t) )
(db_upperbound_i64, int(int64_t,int64_t,int64_t,int64_t) )
(db_end_i64, int(int64_t,int64_t,int64_t) )

DB_SECONDARY_INDEX_METHODS_SIMPLE(idx64)
DB_SECONDARY_INDEX_METHODS_SIMPLE(idx128)
Expand All @@ -1828,8 +1826,8 @@ REGISTER_INTRINSICS(crypto_api,
REGISTER_INTRINSICS(permission_api,
(check_transaction_authorization, int(int, int, int, int, int, int) )
(check_permission_authorization, int(int64_t, int64_t, int, int, int, int, int64_t) )
(get_permission_last_used, int64_t(int64_t, int64_t) )
(get_account_creation_time, int64_t(int64_t) )
(get_permission_last_used, int64_t(int64_t, int64_t) )
(get_account_creation_time, int64_t(int64_t) )
);


Expand All @@ -1851,15 +1849,15 @@ REGISTER_INTRINSICS(context_free_system_api,
REGISTER_INTRINSICS(action_api,
(read_action_data, int(int, int) )
(action_data_size, int() )
(current_receiver, int64_t() )
(current_receiver, int64_t() )
);

REGISTER_INTRINSICS(authorization_api,
(require_recipient, void(int64_t) )
(require_authorization, void(int64_t), "require_auth", void(authorization_api::*)(const account_name&) )
(require_authorization2, void(int64_t, int64_t), "require_auth2", void(authorization_api::*)(const account_name&, const permission_name& permission) )
(has_authorization, int(int64_t), "has_auth", bool(authorization_api::*)(const account_name&)const )
(is_account, int(int64_t) )
(require_recipient, void(int64_t) )
(require_auth, void(int64_t) )
(require_auth2, void(int64_t, int64_t) )
(has_auth, int(int64_t) )
(is_account, int(int64_t) )
);

REGISTER_INTRINSICS(console_api,
Expand All @@ -1877,19 +1875,19 @@ REGISTER_INTRINSICS(console_api,
);

REGISTER_INTRINSICS(context_free_transaction_api,
(read_transaction, int(int, int) )
(transaction_size, int() )
(expiration, int() )
(tapos_block_prefix, int() )
(tapos_block_num, int() )
(get_action, int (int, int, int, int) )
(read_transaction, int(int, int) )
(transaction_size, int() )
(expiration, int() )
(tapos_block_prefix, int() )
(tapos_block_num, int() )
(get_action, int(int, int, int, int) )
);

REGISTER_INTRINSICS(transaction_api,
(send_inline, void(int, int) )
(send_context_free_inline, void(int, int) )
(send_inline, void(int, int) )
(send_context_free_inline, void(int, int) )
(send_deferred, void(int, int64_t, int, int, int32_t) )
(cancel_deferred, int(int) )
(cancel_deferred, int(int) )
);

REGISTER_INTRINSICS(context_free_api,
Expand Down
1 change: 0 additions & 1 deletion libraries/chain/webassembly/eos-vm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class eos_vm_instantiated_module : public wasm_instantiated_module_interface {
//if (!(const auto& res = _instantiated_module->run_start()))
// EOS_ASSERT(false, wasm_execution_error, "eos-vm start function failure (${s})", ("s", res.to_string()));

std::cout << "CTX " << &context << "\n";
const auto& res = _instantiated_module->call(&context, "env", "apply",
(uint64_t)context.get_receiver(),
(uint64_t)context.get_action().account,
Expand Down

0 comments on commit 5a9bf2c

Please sign in to comment.