未验证 提交 18271545 编写于 作者: D Daniel Larimer 提交者: GitHub

Merge pull request #3572 from EOSIO/fix/analysis_fixes

Resolved issues #3540 and #3541
......@@ -375,6 +375,8 @@ int apply_context::get_action( uint32_t type, uint32_t index, char* buffer, size
return -1;
act_ptr = &trx.actions[index];
}
FC_ASSERT(act_ptr, "action is not found" );
auto ps = fc::raw::pack_size( *act_ptr );
if( ps <= buffer_size ) {
......
......@@ -157,6 +157,7 @@ class binaryen_runtime : public eosio::chain::wasm_runtime_interface {
template<typename T>
inline array_ptr<T> array_ptr_impl (interpreter_interface* interface, uint32_t ptr, uint32_t length)
{
FC_ASSERT( length < INT_MAX/(uint32_t)sizeof(T), "length will overflow" );
return array_ptr<T>((T*)(interface->get_validated_pointer(ptr, length * (uint32_t)sizeof(T))));
}
......@@ -326,7 +327,7 @@ struct intrinsic_invoker_impl<Ret, std::tuple<Input, Inputs...>> {
static Ret translate_one(interpreter_interface* interface, Inputs... rest, LiteralList& args, int offset) {
auto& last = args.at(offset);
auto native = convert_literal_to_native<Input>(last);
return Then(interface, native, rest..., args, offset - 1);
return Then(interface, native, rest..., args, (uint32_t)offset - 1);
};
template<then_type Then>
......@@ -351,35 +352,35 @@ struct intrinsic_invoker_impl<Ret, std::tuple<array_ptr<T>, size_t, Inputs...>>
template<then_type Then, typename U=T>
static auto translate_one(interpreter_interface* interface, Inputs... rest, LiteralList& args, int offset) -> std::enable_if_t<std::is_const<U>::value, Ret> {
static_assert(!std::is_pointer<U>::value, "Currently don't support array of pointers");
uint32_t ptr = args.at(offset - 1).geti32();
size_t length = args.at(offset).geti32();
uint32_t ptr = args.at((uint32_t)offset - 1).geti32();
size_t length = args.at((uint32_t)offset).geti32();
T* base = array_ptr_impl<T>(interface, ptr, length);
if ( reinterpret_cast<uintptr_t>(base) % alignof(T) != 0 ) {
wlog( "misaligned array of const values" );
std::remove_const_t<T> copy[length];
T* copy_ptr = &copy[0];
memcpy( (void*)copy_ptr, (void*)base, length * sizeof(T) );
return Then(interface, static_cast<array_ptr<T>>(copy_ptr), length, rest..., args, offset - 2);
return Then(interface, static_cast<array_ptr<T>>(copy_ptr), length, rest..., args, (uint32_t)offset - 2);
}
return Then(interface, static_cast<array_ptr<T>>(base), length, rest..., args, offset - 2);
return Then(interface, static_cast<array_ptr<T>>(base), length, rest..., args, (uint32_t)offset - 2);
};
template<then_type Then, typename U=T>
static auto translate_one(interpreter_interface* interface, Inputs... rest, LiteralList& args, int offset) -> std::enable_if_t<!std::is_const<U>::value, Ret> {
static_assert(!std::is_pointer<U>::value, "Currently don't support array of pointers");
uint32_t ptr = args.at(offset - 1).geti32();
size_t length = args.at(offset).geti32();
uint32_t ptr = args.at((uint32_t)offset - 1).geti32();
size_t length = args.at((uint32_t)offset).geti32();
T* base = array_ptr_impl<T>(interface, ptr, length);
if ( reinterpret_cast<uintptr_t>(base) % alignof(T) != 0 ) {
wlog( "misaligned array of values" );
std::remove_const_t<T> copy[length];
T* copy_ptr = &copy[0];
memcpy( (void*)copy_ptr, (void*)base, length * sizeof(T) );
Ret ret = Then(interface, static_cast<array_ptr<T>>(copy_ptr), length, rest..., args, offset - 2);
Ret ret = Then(interface, static_cast<array_ptr<T>>(copy_ptr), length, rest..., args, (uint32_t)offset - 2);
memcpy( (void*)base, (void*)copy_ptr, length * sizeof(T) );
return ret;
}
return Then(interface, static_cast<array_ptr<T>>(base), length, rest..., args, offset - 2);
return Then(interface, static_cast<array_ptr<T>>(base), length, rest..., args, (uint32_t)offset - 2);
};
template<then_type Then>
......@@ -403,8 +404,8 @@ struct intrinsic_invoker_impl<Ret, std::tuple<null_terminated_ptr, Inputs...>> {
template<then_type Then>
static Ret translate_one(interpreter_interface* interface, Inputs... rest, LiteralList& args, int offset) {
uint32_t ptr = args.at(offset).geti32();
return Then(interface, null_terminated_ptr_impl(interface, ptr), rest..., args, offset - 1);
uint32_t ptr = args.at((uint32_t)offset).geti32();
return Then(interface, null_terminated_ptr_impl(interface, ptr), rest..., args, (uint32_t)offset - 1);
};
template<then_type Then>
......@@ -428,11 +429,11 @@ struct intrinsic_invoker_impl<Ret, std::tuple<array_ptr<T>, array_ptr<U>, size_t
template<then_type Then>
static Ret translate_one(interpreter_interface* interface, Inputs... rest, LiteralList& args, int offset) {
uint32_t ptr_t = args.at(offset - 2).geti32();
uint32_t ptr_u = args.at(offset - 1).geti32();
size_t length = args.at(offset).geti32();
uint32_t ptr_t = args.at((uint32_t)offset - 2).geti32();
uint32_t ptr_u = args.at((uint32_t)offset - 1).geti32();
size_t length = args.at((uint32_t)offset).geti32();
static_assert(std::is_same<std::remove_const_t<T>, char>::value && std::is_same<std::remove_const_t<U>, char>::value, "Currently only support array of (const)chars");
return Then(interface, array_ptr_impl<T>(interface, ptr_t, length), array_ptr_impl<U>(interface, ptr_u, length), length, args, offset - 3);
return Then(interface, array_ptr_impl<T>(interface, ptr_t, length), array_ptr_impl<U>(interface, ptr_u, length), length, args, (uint32_t)offset - 3);
};
template<then_type Then>
......@@ -454,10 +455,10 @@ struct intrinsic_invoker_impl<Ret, std::tuple<array_ptr<char>, int, size_t>> {
template<then_type Then>
static Ret translate_one(interpreter_interface* interface, LiteralList& args, int offset) {
uint32_t ptr = args.at(offset - 2).geti32();
uint32_t value = args.at(offset - 1).geti32();
size_t length = args.at(offset).geti32();
return Then(interface, array_ptr_impl<char>(interface, ptr, length), value, length, args, offset - 3);
uint32_t ptr = args.at((uint32_t)offset - 2).geti32();
uint32_t value = args.at((uint32_t)offset - 1).geti32();
size_t length = args.at((uint32_t)offset).geti32();
return Then(interface, array_ptr_impl<char>(interface, ptr, length), value, length, args, (uint32_t)offset - 3);
};
template<then_type Then>
......@@ -481,31 +482,31 @@ struct intrinsic_invoker_impl<Ret, std::tuple<T *, Inputs...>> {
template<then_type Then, typename U=T>
static auto translate_one(interpreter_interface* interface, Inputs... rest, LiteralList& args, int offset) -> std::enable_if_t<std::is_const<U>::value, Ret> {
uint32_t ptr = args.at(offset).geti32();
uint32_t ptr = args.at((uint32_t)offset).geti32();
T* base = array_ptr_impl<T>(interface, ptr, 1);
if ( reinterpret_cast<uintptr_t>(base) % alignof(T) != 0 ) {
wlog( "misaligned const pointer" );
std::remove_const_t<T> copy;
T* copy_ptr = &copy;
memcpy( (void*)copy_ptr, (void*)base, sizeof(T) );
return Then(interface, copy_ptr, rest..., args, offset - 1);
return Then(interface, copy_ptr, rest..., args, (uint32_t)offset - 1);
}
return Then(interface, base, rest..., args, offset - 1);
return Then(interface, base, rest..., args, (uint32_t)offset - 1);
};
template<then_type Then, typename U=T>
static auto translate_one(interpreter_interface* interface, Inputs... rest, LiteralList& args, int offset) -> std::enable_if_t<!std::is_const<U>::value, Ret> {
uint32_t ptr = args.at(offset).geti32();
uint32_t ptr = args.at((uint32_t)offset).geti32();
T* base = array_ptr_impl<T>(interface, ptr, 1);
if ( reinterpret_cast<uintptr_t>(base) % alignof(T) != 0 ) {
wlog( "misaligned pointer" );
T copy;
memcpy( (void*)&copy, (void*)base, sizeof(T) );
Ret ret = Then(interface, &copy, rest..., args, offset - 1);
Ret ret = Then(interface, &copy, rest..., args, (uint32_t)offset - 1);
memcpy( (void*)base, (void*)&copy, sizeof(T) );
return ret;
}
return Then(interface, base, rest..., args, offset - 1);
return Then(interface, base, rest..., args, (uint32_t)offset - 1);
};
template<then_type Then>
......@@ -529,9 +530,9 @@ struct intrinsic_invoker_impl<Ret, std::tuple<const name&, Inputs...>> {
template<then_type Then>
static Ret translate_one(interpreter_interface* interface, Inputs... rest, LiteralList& args, int offset) {
uint64_t wasm_value = args.at(offset).geti64();
uint64_t wasm_value = args.at((uint32_t)offset).geti64();
auto value = name(wasm_value);
return Then(interface, value, rest..., args, offset - 1);
return Then(interface, value, rest..., args, (uint32_t)offset - 1);
}
template<then_type Then>
......@@ -555,9 +556,9 @@ struct intrinsic_invoker_impl<Ret, std::tuple<const fc::time_point_sec&, Inputs.
template<then_type Then>
static Ret translate_one(interpreter_interface* interface, Inputs... rest, LiteralList& args, int offset) {
uint32_t wasm_value = args.at(offset).geti32();
uint32_t wasm_value = args.at((uint32_t)offset).geti32();
auto value = fc::time_point_sec(wasm_value);
return Then(interface, value, rest..., args, offset - 1);
return Then(interface, value, rest..., args, (uint32_t)offset - 1);
}
template<then_type Then>
......@@ -583,7 +584,7 @@ struct intrinsic_invoker_impl<Ret, std::tuple<T &, Inputs...>> {
template<then_type Then, typename U=T>
static auto translate_one(interpreter_interface* interface, Inputs... rest, LiteralList& args, int offset) -> std::enable_if_t<std::is_const<U>::value, Ret> {
// references cannot be created for null pointers
uint32_t ptr = args.at(offset).geti32();
uint32_t ptr = args.at((uint32_t)offset).geti32();
FC_ASSERT(ptr != 0);
T* base = array_ptr_impl<T>(interface, ptr, 1);
if ( reinterpret_cast<uintptr_t>(base) % alignof(T) != 0 ) {
......@@ -591,26 +592,26 @@ struct intrinsic_invoker_impl<Ret, std::tuple<T &, Inputs...>> {
std::remove_const_t<T> copy;
T* copy_ptr = &copy;
memcpy( (void*)copy_ptr, (void*)base, sizeof(T) );
return Then(interface, *copy_ptr, rest..., args, offset - 1);
return Then(interface, *copy_ptr, rest..., args, (uint32_t)offset - 1);
}
return Then(interface, *base, rest..., args, offset - 1);
return Then(interface, *base, rest..., args, (uint32_t)offset - 1);
}
template<then_type Then, typename U=T>
static auto translate_one(interpreter_interface* interface, Inputs... rest, LiteralList& args, int offset) -> std::enable_if_t<!std::is_const<U>::value, Ret> {
// references cannot be created for null pointers
uint32_t ptr = args.at(offset).geti32();
uint32_t ptr = args.at((uint32_t)offset).geti32();
FC_ASSERT(ptr != 0);
T* base = array_ptr_impl<T>(interface, ptr, 1);
if ( reinterpret_cast<uintptr_t>(base) % alignof(T) != 0 ) {
wlog( "misaligned reference" );
T copy;
memcpy( (void*)&copy, (void*)base, sizeof(T) );
Ret ret = Then(interface, copy, rest..., args, offset - 1);
Ret ret = Then(interface, copy, rest..., args, (uint32_t)offset - 1);
memcpy( (void*)base, (void*)&copy, sizeof(T) );
return ret;
}
return Then(interface, *base, rest..., args, offset - 1);
return Then(interface, *base, rest..., args, (uint32_t)offset - 1);
}
......
......@@ -170,7 +170,7 @@ inline auto convert_native_to_wasm(running_instance_context& ctx, char* ptr) {
char* top_of_memory = base + IR::numBytesPerPage*Runtime::getMemoryNumPages(mem);
if(ptr < base || ptr >= top_of_memory)
Runtime::causeException(Exception::Cause::accessViolation);
return (int)(ptr - base);
return (U32)(ptr - base);
}
template<typename T>
......@@ -379,7 +379,7 @@ struct intrinsic_invoker_impl<Ret, std::tuple<array_ptr<T>, size_t, Inputs...>,
static auto translate_one(running_instance_context& ctx, Inputs... rest, Translated... translated, I32 ptr, I32 size) -> std::enable_if_t<std::is_const<U>::value, Ret> {
static_assert(!std::is_pointer<U>::value, "Currently don't support array of pointers");
const auto length = size_t(size);
T* base = array_ptr_impl<T>(ctx, ptr, length);
T* base = array_ptr_impl<T>(ctx, (U32)ptr, length);
if ( reinterpret_cast<uintptr_t>(base) % alignof(T) != 0 ) {
wlog( "misaligned array of const values" );
std::remove_const_t<T> copy[length];
......@@ -394,7 +394,7 @@ struct intrinsic_invoker_impl<Ret, std::tuple<array_ptr<T>, size_t, Inputs...>,
static auto translate_one(running_instance_context& ctx, Inputs... rest, Translated... translated, I32 ptr, I32 size) -> std::enable_if_t<!std::is_const<U>::value, Ret> {
static_assert(!std::is_pointer<U>::value, "Currently don't support array of pointers");
const auto length = size_t(size);
T* base = array_ptr_impl<T>(ctx, ptr, length);
T* base = array_ptr_impl<T>(ctx, (U32)ptr, length);
if ( reinterpret_cast<uintptr_t>(base) % alignof(T) != 0 ) {
wlog( "misaligned array of values" );
std::remove_const_t<T> copy[length];
......@@ -429,7 +429,7 @@ struct intrinsic_invoker_impl<Ret, std::tuple<null_terminated_ptr, Inputs...>, s
template<then_type Then>
static Ret translate_one(running_instance_context& ctx, Inputs... rest, Translated... translated, I32 ptr) {
return Then(ctx, null_terminated_ptr_impl(ctx, ptr), rest..., translated...);
return Then(ctx, null_terminated_ptr_impl(ctx, (U32)ptr), rest..., translated...);
};
template<then_type Then>
......@@ -456,7 +456,7 @@ struct intrinsic_invoker_impl<Ret, std::tuple<array_ptr<T>, array_ptr<U>, size_t
static Ret translate_one(running_instance_context& ctx, Inputs... rest, Translated... translated, I32 ptr_t, I32 ptr_u, I32 size) {
static_assert(std::is_same<std::remove_const_t<T>, char>::value && std::is_same<std::remove_const_t<U>, char>::value, "Currently only support array of (const)chars");
const auto length = size_t(size);
return Then(ctx, array_ptr_impl<T>(ctx, ptr_t, length), array_ptr_impl<U>(ctx, ptr_u, length), length, rest..., translated...);
return Then(ctx, array_ptr_impl<T>(ctx, (U32)ptr_t, length), array_ptr_impl<U>(ctx, (U32)ptr_u, length), length, rest..., translated...);
};
template<then_type Then>
......@@ -480,7 +480,7 @@ struct intrinsic_invoker_impl<Ret, std::tuple<array_ptr<char>, int, size_t>, std
template<then_type Then>
static Ret translate_one(running_instance_context& ctx, I32 ptr, I32 value, I32 size) {
const auto length = size_t(size);
return Then(ctx, array_ptr_impl<char>(ctx, ptr, length), value, length);
return Then(ctx, array_ptr_impl<char>(ctx, (U32)ptr, length), value, length);
};
template<then_type Then>
......@@ -505,7 +505,7 @@ struct intrinsic_invoker_impl<Ret, std::tuple<T *, Inputs...>, std::tuple<Transl
template<then_type Then, typename U=T>
static auto translate_one(running_instance_context& ctx, Inputs... rest, Translated... translated, I32 ptr) -> std::enable_if_t<std::is_const<U>::value, Ret> {
T* base = array_ptr_impl<T>(ctx, ptr, 1);
T* base = array_ptr_impl<T>(ctx, (U32)ptr, 1);
if ( reinterpret_cast<uintptr_t>(base) % alignof(T) != 0 ) {
wlog( "misaligned const pointer" );
std::remove_const_t<T> copy;
......@@ -518,7 +518,7 @@ struct intrinsic_invoker_impl<Ret, std::tuple<T *, Inputs...>, std::tuple<Transl
template<then_type Then, typename U=T>
static auto translate_one(running_instance_context& ctx, Inputs... rest, Translated... translated, I32 ptr) -> std::enable_if_t<!std::is_const<U>::value, Ret> {
T* base = array_ptr_impl<T>(ctx, ptr, 1);
T* base = array_ptr_impl<T>(ctx, (U32)ptr, 1);
if ( reinterpret_cast<uintptr_t>(base) % alignof(T) != 0 ) {
wlog( "misaligned pointer" );
std::remove_const_t<T> copy;
......@@ -580,11 +580,11 @@ struct intrinsic_invoker_impl<Ret, std::tuple<T &, Inputs...>, std::tuple<Transl
template<then_type Then, typename U=T>
static auto translate_one(running_instance_context& ctx, Inputs... rest, Translated... translated, I32 ptr) -> std::enable_if_t<std::is_const<U>::value, Ret> {
// references cannot be created for null pointers
FC_ASSERT(ptr != 0);
FC_ASSERT((U32)ptr != 0);
MemoryInstance* mem = ctx.memory;
if(!mem || ptr+sizeof(T) >= IR::numBytesPerPage*Runtime::getMemoryNumPages(mem))
if(!mem || (U32)ptr+sizeof(T) >= IR::numBytesPerPage*Runtime::getMemoryNumPages(mem))
Runtime::causeException(Exception::Cause::accessViolation);
T &base = *(T*)(getMemoryBaseAddress(mem)+ptr);
T &base = *(T*)(getMemoryBaseAddress(mem)+(U32)ptr);
if ( reinterpret_cast<uintptr_t>(&base) % alignof(T) != 0 ) {
wlog( "misaligned const reference" );
std::remove_const_t<T> copy;
......@@ -598,11 +598,11 @@ struct intrinsic_invoker_impl<Ret, std::tuple<T &, Inputs...>, std::tuple<Transl
template<then_type Then, typename U=T>
static auto translate_one(running_instance_context& ctx, Inputs... rest, Translated... translated, I32 ptr) -> std::enable_if_t<!std::is_const<U>::value, Ret> {
// references cannot be created for null pointers
FC_ASSERT(ptr != 0);
FC_ASSERT((U32)ptr != 0);
MemoryInstance* mem = ctx.memory;
if(!mem || ptr+sizeof(T) >= IR::numBytesPerPage*Runtime::getMemoryNumPages(mem))
if(!mem || (U32)ptr+sizeof(T) >= IR::numBytesPerPage*Runtime::getMemoryNumPages(mem))
Runtime::causeException(Exception::Cause::accessViolation);
T &base = *(T*)(getMemoryBaseAddress(mem)+ptr);
T &base = *(T*)(getMemoryBaseAddress(mem)+(U32)ptr);
if ( reinterpret_cast<uintptr_t>(&base) % alignof(T) != 0 ) {
wlog( "misaligned reference" );
std::remove_const_t<T> copy;
......
......@@ -102,7 +102,7 @@ namespace LLVMJIT
if(hasRegisteredEHFrames)
{
hasRegisteredEHFrames = false;
deregisterEHFrames(ehFramesAddr,ehFramesLoadAddr,ehFramesNumBytes);
llvm::RTDyldMemoryManager::deregisterEHFrames(ehFramesAddr,ehFramesLoadAddr,ehFramesNumBytes);
}
// Decommit the image pages, but leave them reserved to catch any references to them that might erroneously remain.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册