mirror of
https://github.com/Xahau/xahaud.git
synced 2025-11-19 10:05:48 +00:00
update to wasmedge 0.11 (untested)
This commit is contained in:
@@ -134,10 +134,10 @@ target_link_libraries (xrpl_core
|
||||
PUBLIC
|
||||
OpenSSL::Crypto
|
||||
Ripple::boost
|
||||
NIH::WasmEdge
|
||||
Ripple::syslibs
|
||||
NIH::secp256k1
|
||||
NIH::ed25519-donna
|
||||
NIH::WasmEdge
|
||||
date::date
|
||||
Ripple::opts)
|
||||
#[=================================[
|
||||
|
||||
@@ -9,7 +9,6 @@ add_library (wasmedge STATIC IMPORTED GLOBAL)
|
||||
ExternalProject_Add (wasmedge_src
|
||||
PREFIX ${nih_cache_path}
|
||||
GIT_REPOSITORY https://github.com/WasmEdge/WasmEdge.git
|
||||
GIT_TAG 0.9.0
|
||||
CMAKE_ARGS
|
||||
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
|
||||
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
|
||||
@@ -32,8 +31,7 @@ ExternalProject_Add (wasmedge_src
|
||||
LOG_CONFIGURE ON
|
||||
COMMAND
|
||||
pwd
|
||||
COMMAND
|
||||
sed -iE 's/uint64_t Index;/uint64_t Index = 0;/g' ../lib/aot/compiler.cpp
|
||||
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
||||
BUILD_COMMAND
|
||||
${CMAKE_COMMAND}
|
||||
--build .
|
||||
@@ -42,7 +40,7 @@ ExternalProject_Add (wasmedge_src
|
||||
TEST_COMMAND ""
|
||||
INSTALL_COMMAND ""
|
||||
BUILD_BYPRODUCTS
|
||||
<BINARY_DIR>/lib/api/libwasmedge_c.a
|
||||
<BINARY_DIR>/lib/api/libwasmedge.a
|
||||
)
|
||||
ExternalProject_Get_Property (wasmedge_src BINARY_DIR)
|
||||
set (wasmedge_src_BINARY_DIR "${BINARY_DIR}")
|
||||
@@ -50,9 +48,9 @@ add_dependencies (wasmedge wasmedge_src)
|
||||
target_include_directories (ripple_libs SYSTEM INTERFACE "${wasmedge_src_BINARY_DIR}/include/api")
|
||||
set_target_properties (wasmedge PROPERTIES
|
||||
IMPORTED_LOCATION_DEBUG
|
||||
"${wasmedge_src_BINARY_DIR}/lib/api/libwasmedge_c.a"
|
||||
"${wasmedge_src_BINARY_DIR}/lib/api/libwasmedge.a"
|
||||
IMPORTED_LOCATION_RELEASE
|
||||
"${wasmedge_src_BINARY_DIR}/lib/api/libwasmedge_c.a"
|
||||
"${wasmedge_src_BINARY_DIR}/lib/api/libwasmedge.a"
|
||||
INTERFACE_INCLUDE_DIRECTORIES
|
||||
"${BINARY_DIR}/include/api")
|
||||
target_link_libraries (ripple_libs INTERFACE wasmedge)
|
||||
|
||||
@@ -77,9 +77,10 @@
|
||||
CAT2(TYP_,T)
|
||||
|
||||
#define DECLARE_HOOK_FUNCTION(R, F, ...)\
|
||||
R F(hook::HookContext& hookCtx, WasmEdge_MemoryInstanceContext& memoryCtx, __VA_ARGS__);\
|
||||
R F(hook::HookContext& hookCtx, WasmEdge_CallingFrameContext const& frameCtx, __VA_ARGS__);\
|
||||
extern WasmEdge_Result WasmFunction##F(\
|
||||
void *data_ptr, WasmEdge_MemoryInstanceContext *memCtx,\
|
||||
void *data_ptr,\
|
||||
const WasmEdge_CallingFrameContext* frameCtx,\
|
||||
const WasmEdge_Value *in, WasmEdge_Value *out);\
|
||||
extern WasmEdge_ValType WasmFunctionParams##F[];\
|
||||
extern WasmEdge_ValType WasmFunctionResult##F[];\
|
||||
@@ -88,9 +89,10 @@
|
||||
|
||||
|
||||
#define DECLARE_HOOK_FUNCNARG(R, F)\
|
||||
R F(hook::HookContext& hookCtx, WasmEdge_MemoryInstanceContext& memoryCtx);\
|
||||
R F(hook::HookContext& hookCtx, WasmEdge_CallingFrameContext const& frameCtx);\
|
||||
extern WasmEdge_Result WasmFunction##F(\
|
||||
void *data_ptr, WasmEdge_MemoryInstanceContext *memCtx,\
|
||||
void *data_ptr,\
|
||||
const WasmEdge_CallingFrameContext* frameCtx,\
|
||||
const WasmEdge_Value *in, WasmEdge_Value *out);\
|
||||
extern WasmEdge_ValType WasmFunctionResult##F[];\
|
||||
extern WasmEdge_FunctionTypeContext* WasmFunctionType##F;\
|
||||
@@ -98,13 +100,15 @@
|
||||
|
||||
#define DEFINE_HOOK_FUNCTION(R, F, ...)\
|
||||
WasmEdge_Result hook_api::WasmFunction##F(\
|
||||
void *data_ptr, WasmEdge_MemoryInstanceContext *memCtx,\
|
||||
void *data_ptr,\
|
||||
const WasmEdge_CallingFrameContext* frameCtx,\
|
||||
const WasmEdge_Value *in, WasmEdge_Value *out)\
|
||||
{\
|
||||
int _stack = 0;\
|
||||
FOR_VARS(VAR_ASSIGN, 2, __VA_ARGS__);\
|
||||
hook::HookContext* hookCtx = reinterpret_cast<hook::HookContext*>(data_ptr);\
|
||||
R return_code = hook_api::F(*hookCtx, *memCtx, STRIP_TYPES(__VA_ARGS__));\
|
||||
R return_code = hook_api::F(*hookCtx, *const_cast<WasmEdge_CallingFrameContext*>(frameCtx),\
|
||||
STRIP_TYPES(__VA_ARGS__));\
|
||||
if (return_code == RC_ROLLBACK || return_code == RC_ACCEPT)\
|
||||
return WasmEdge_Result_Terminate;\
|
||||
out[0] = RET_ASSIGN(R, return_code);\
|
||||
@@ -116,15 +120,16 @@
|
||||
WasmFunctionParams##F, VA_NARGS(NULL, __VA_ARGS__),\
|
||||
WasmFunctionResult##F, 1);\
|
||||
WasmEdge_String hook_api::WasmFunctionName##F = WasmEdge_StringCreateByCString(#F);\
|
||||
R hook_api::F(hook::HookContext& hookCtx, WasmEdge_MemoryInstanceContext& memoryCtx, __VA_ARGS__)
|
||||
R hook_api::F(hook::HookContext& hookCtx, WasmEdge_CallingFrameContext const& frameCtx, __VA_ARGS__)
|
||||
|
||||
#define DEFINE_HOOK_FUNCNARG(R, F)\
|
||||
WasmEdge_Result hook_api::WasmFunction##F(\
|
||||
void *data_ptr, WasmEdge_MemoryInstanceContext *memCtx,\
|
||||
void *data_ptr,\
|
||||
const WasmEdge_CallingFrameContext* frameCtx,\
|
||||
const WasmEdge_Value *in, WasmEdge_Value *out)\
|
||||
{\
|
||||
hook::HookContext* hookCtx = reinterpret_cast<hook::HookContext*>(data_ptr);\
|
||||
R return_code = hook_api::F(*hookCtx, *memCtx);\
|
||||
R return_code = hook_api::F(*hookCtx, *const_cast<WasmEdge_CallingFrameContext*>(frameCtx));\
|
||||
if (return_code == RC_ROLLBACK || return_code == RC_ACCEPT)\
|
||||
return WasmEdge_Result_Terminate;\
|
||||
out[0] = CAT2(RET_,R(return_code));\
|
||||
@@ -134,14 +139,16 @@
|
||||
WasmEdge_FunctionTypeContext* hook_api::WasmFunctionType##F = \
|
||||
WasmEdge_FunctionTypeCreate({}, 0, WasmFunctionResult##F, 1);\
|
||||
WasmEdge_String hook_api::WasmFunctionName##F = WasmEdge_StringCreateByCString(#F);\
|
||||
R hook_api::F(hook::HookContext& hookCtx, WasmEdge_MemoryInstanceContext& memoryCtx)
|
||||
R hook_api::F(hook::HookContext& hookCtx, WasmEdge_CallingFrameContext const& frameCtx)
|
||||
|
||||
#define HOOK_SETUP()\
|
||||
[[maybe_unused]] ApplyContext& applyCtx = hookCtx.applyCtx;\
|
||||
[[maybe_unused]] auto& view = applyCtx.view();\
|
||||
[[maybe_unused]] auto j = applyCtx.app.journal("View");\
|
||||
[[maybe_unused]] unsigned char* memory = WasmEdge_MemoryInstanceGetPointer(&memoryCtx, 0, 0);\
|
||||
[[maybe_unused]] const uint64_t memory_length = WasmEdge_MemoryInstanceGetPageSize(&memoryCtx) * \
|
||||
[[maybe_unused]] WasmEdge_MemoryInstanceContext* memoryCtx =\
|
||||
WasmEdge_CallingFrameGetMemoryInstance(&frameCtx, 0);\
|
||||
[[maybe_unused]] unsigned char* memory = WasmEdge_MemoryInstanceGetPointer(memoryCtx, 0, 0);\
|
||||
[[maybe_unused]] const uint64_t memory_length = WasmEdge_MemoryInstanceGetPageSize(memoryCtx) * \
|
||||
WasmEdge_kPageSize;
|
||||
|
||||
#define WRITE_WASM_MEMORY(bytes_written, guest_dst_ptr, guest_dst_len,\
|
||||
@@ -156,7 +163,7 @@
|
||||
<< " bytes past end of wasm memory";\
|
||||
return OUT_OF_BOUNDS;\
|
||||
}\
|
||||
WasmEdge_MemoryInstanceSetData(&memoryCtx, \
|
||||
WasmEdge_MemoryInstanceSetData(memoryCtx, \
|
||||
reinterpret_cast<const uint8_t*>(host_src_ptr), guest_dst_ptr, bytes_to_write);\
|
||||
bytes_written += bytes_to_write;\
|
||||
}
|
||||
|
||||
@@ -394,7 +394,7 @@ namespace hook
|
||||
hook_api::WasmFunctionType##F,\
|
||||
hook_api::WasmFunction##F,\
|
||||
(void*)(&ctx), 0);\
|
||||
WasmEdge_ImportObjectAddFunction(importObj, hook_api::WasmFunctionName##F, hf);\
|
||||
WasmEdge_ModuleInstanceAddFunction (importObj, hook_api::WasmFunctionName##F, hf);\
|
||||
}
|
||||
|
||||
#define HR_ACC() hookResult.account << "-" << hookResult.otxnAccount
|
||||
@@ -404,8 +404,8 @@ namespace hook
|
||||
static WasmEdge_String exportName = WasmEdge_StringCreateByCString("env");
|
||||
static WasmEdge_String tableName = WasmEdge_StringCreateByCString("table");
|
||||
static auto* tableType =
|
||||
WasmEdge_TableTypeCreate(WasmEdge_RefType_FuncRef, {.HasMax = true, .Min = 10, .Max = 20});
|
||||
static auto* memType = WasmEdge_MemoryTypeCreate({.HasMax = true, .Min = 1, .Max = 1});
|
||||
WasmEdge_TableTypeCreate(WasmEdge_RefType_FuncRef, {.HasMax = true, .Shared = false, .Min = 10, .Max = 20});
|
||||
static auto* memType = WasmEdge_MemoryTypeCreate({.HasMax = true, .Shared = false, .Min = 1, .Max = 1});
|
||||
static WasmEdge_String memName = WasmEdge_StringCreateByCString("memory");
|
||||
static WasmEdge_String cbakFunctionName = WasmEdge_StringCreateByCString("cbak");
|
||||
static WasmEdge_String hookFunctionName = WasmEdge_StringCreateByCString("hook");
|
||||
@@ -430,7 +430,7 @@ namespace hook
|
||||
|
||||
public:
|
||||
HookContext hookCtx;
|
||||
WasmEdge_ImportObjectContext* importObj;
|
||||
WasmEdge_ModuleInstanceContext* importObj;
|
||||
|
||||
/**
|
||||
* Validate that a web assembly blob can be loaded by wasmedge
|
||||
@@ -529,7 +529,7 @@ namespace hook
|
||||
|
||||
HookExecutor(HookContext& ctx)
|
||||
: hookCtx(ctx)
|
||||
, importObj(WasmEdge_ImportObjectCreate(exportName))
|
||||
, importObj(WasmEdge_ModuleInstanceCreate(exportName))
|
||||
{
|
||||
ctx.module = this;
|
||||
|
||||
@@ -624,14 +624,14 @@ namespace hook
|
||||
ADD_HOOK_FUNCTION(str_concat, ctx);
|
||||
|
||||
WasmEdge_TableInstanceContext* hostTable = WasmEdge_TableInstanceCreate(tableType);
|
||||
WasmEdge_ImportObjectAddTable(importObj, tableName, hostTable);
|
||||
WasmEdge_ModuleInstanceAddTable(importObj, tableName, hostTable);
|
||||
WasmEdge_MemoryInstanceContext* hostMem = WasmEdge_MemoryInstanceCreate(memType);
|
||||
WasmEdge_ImportObjectAddMemory(importObj, memName, hostMem);
|
||||
WasmEdge_ModuleInstanceAddMemory(importObj, memName, hostMem);
|
||||
}
|
||||
|
||||
~HookExecutor()
|
||||
{
|
||||
WasmEdge_ImportObjectDelete(importObj);
|
||||
WasmEdge_ModuleInstanceDelete(importObj);
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -1228,7 +1228,7 @@ DEFINE_HOOK_FUNCTION(
|
||||
{
|
||||
return
|
||||
state_foreign_set(
|
||||
hookCtx, memoryCtx,
|
||||
hookCtx, frameCtx,
|
||||
read_ptr, read_len,
|
||||
kread_ptr, kread_len,
|
||||
0, 0,
|
||||
@@ -1622,7 +1622,7 @@ DEFINE_HOOK_FUNCTION(
|
||||
{
|
||||
return
|
||||
state_foreign(
|
||||
hookCtx, memoryCtx,
|
||||
hookCtx, frameCtx,
|
||||
write_ptr, write_len,
|
||||
kread_ptr, kread_len,
|
||||
0, 0,
|
||||
@@ -1907,7 +1907,7 @@ DEFINE_HOOK_FUNCNARG(
|
||||
int64_t,
|
||||
etxn_generation)
|
||||
{
|
||||
return otxn_generation(hookCtx, memoryCtx) + 1;
|
||||
return otxn_generation(hookCtx, frameCtx) + 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -2880,7 +2880,7 @@ DEFINE_HOOK_FUNCTION(
|
||||
|
||||
auto const& hash = emitDetails.getFieldH256(sfEmitHookHash);
|
||||
|
||||
uint32_t gen_proper = etxn_generation(hookCtx, memoryCtx);
|
||||
uint32_t gen_proper = etxn_generation(hookCtx, frameCtx);
|
||||
|
||||
if (gen != gen_proper)
|
||||
{
|
||||
@@ -2891,7 +2891,7 @@ DEFINE_HOOK_FUNCTION(
|
||||
return EMISSION_FAILURE;
|
||||
}
|
||||
|
||||
uint64_t bur_proper = etxn_burden(hookCtx, memoryCtx);
|
||||
uint64_t bur_proper = etxn_burden(hookCtx, frameCtx);
|
||||
if (bur != bur_proper)
|
||||
{
|
||||
JLOG(j.trace())
|
||||
@@ -2969,7 +2969,7 @@ DEFINE_HOOK_FUNCTION(
|
||||
}
|
||||
|
||||
// rule 7 check the emitted txn pays the appropriate fee
|
||||
int64_t minfee = etxn_fee_base(hookCtx, memoryCtx, read_ptr, read_len);
|
||||
int64_t minfee = etxn_fee_base(hookCtx, frameCtx, read_ptr, read_len);
|
||||
|
||||
if (minfee < 0)
|
||||
{
|
||||
@@ -3242,7 +3242,7 @@ DEFINE_HOOK_FUNCNARG(
|
||||
if (hookCtx.expected_etxn_count <= -1)
|
||||
return PREREQUISITE_NOT_MET;
|
||||
|
||||
uint64_t last_burden = (uint64_t)otxn_burden(hookCtx, memoryCtx); // always non-negative so cast is safe
|
||||
uint64_t last_burden = (uint64_t)otxn_burden(hookCtx, frameCtx); // always non-negative so cast is safe
|
||||
|
||||
uint64_t burden = last_burden * hookCtx.expected_etxn_count;
|
||||
if (burden < last_burden) // this overflow will never happen but handle it anyway
|
||||
@@ -3803,7 +3803,7 @@ DEFINE_HOOK_FUNCTION(
|
||||
{
|
||||
int64_t ret =
|
||||
sto_emplace(
|
||||
hookCtx, memoryCtx,
|
||||
hookCtx, frameCtx,
|
||||
write_ptr, write_len,
|
||||
read_ptr, read_len,
|
||||
0, 0, field_id);
|
||||
@@ -3954,9 +3954,9 @@ DEFINE_HOOK_FUNCTION(
|
||||
if (hookCtx.expected_etxn_count <= -1)
|
||||
return PREREQUISITE_NOT_MET;
|
||||
|
||||
uint32_t generation = (uint32_t)(etxn_generation(hookCtx, memoryCtx)); // always non-negative so cast is safe
|
||||
uint32_t generation = (uint32_t)(etxn_generation(hookCtx, frameCtx)); // always non-negative so cast is safe
|
||||
|
||||
int64_t burden = etxn_burden(hookCtx, memoryCtx);
|
||||
int64_t burden = etxn_burden(hookCtx, frameCtx);
|
||||
if (burden < 1)
|
||||
return FEE_TOO_LARGE;
|
||||
|
||||
@@ -3979,11 +3979,11 @@ DEFINE_HOOK_FUNCTION(
|
||||
*out++ = ( burden >> 8U ) & 0xFFU;
|
||||
*out++ = ( burden >> 0U ) & 0xFFU;
|
||||
*out++ = 0x5BU; // sfEmitParentTxnID preamble /* upto = 16 | size = 33 */
|
||||
if (otxn_id(hookCtx, memoryCtx, out - memory, 32, 1) != 32)
|
||||
if (otxn_id(hookCtx, frameCtx, out - memory, 32, 1) != 32)
|
||||
return INTERNAL_ERROR;
|
||||
out += 32;
|
||||
*out++ = 0x5CU; // sfEmitNonce /* upto = 49 | size = 33 */
|
||||
if (etxn_nonce(hookCtx, memoryCtx, out - memory, 32) != 32)
|
||||
if (etxn_nonce(hookCtx, frameCtx, out - memory, 32) != 32)
|
||||
return INTERNAL_ERROR;
|
||||
out += 32;
|
||||
*out++= 0x5DU; // sfEmitHookHash preamble /* upto = 82 | size = 33 */
|
||||
@@ -3994,7 +3994,7 @@ DEFINE_HOOK_FUNCTION(
|
||||
{
|
||||
*out++ = 0x8AU; // sfEmitCallback preamble /* upto = 115 | size = 22 */
|
||||
*out++ = 0x14U; // preamble cont
|
||||
if (hook_account(hookCtx, memoryCtx, out - memory, 20) != 20)
|
||||
if (hook_account(hookCtx, frameCtx, out - memory, 20) != 20)
|
||||
return INTERNAL_ERROR;
|
||||
out += 20;
|
||||
}
|
||||
|
||||
@@ -351,7 +351,7 @@ run(int argc, char** argv)
|
||||
|
||||
|
||||
beast::setCurrentThreadName(
|
||||
"xahaud: main " + BuildInfo::getVersionString());
|
||||
"rippled: main " + BuildInfo::getVersionString());
|
||||
|
||||
po::variables_map vm;
|
||||
|
||||
@@ -779,7 +779,7 @@ run(int argc, char** argv)
|
||||
}
|
||||
|
||||
// We have an RPC command to process:
|
||||
beast::setCurrentThreadName("xahaud: rpc");
|
||||
beast::setCurrentThreadName("rippled: rpc");
|
||||
return RPCCall::fromCommandLine(
|
||||
*config, vm["parameters"].as<std::vector<std::string>>(), *logs);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user