mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
This commit is contained in:
@@ -474,6 +474,16 @@ namespace hook
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// if an error occured return a string prefixed with `prefix` followed by the error description
|
||||||
|
static std::optional<std::string> getWasmError(std::string prefix, WasmEdge_Result& res)
|
||||||
|
{
|
||||||
|
if (WasmEdge_ResultOK(res))
|
||||||
|
return {};
|
||||||
|
|
||||||
|
const char* msg = WasmEdge_ResultGetMessage(res);
|
||||||
|
return prefix + ": " + (msg ? msg : "unknown error");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate that a web assembly blob can be loaded by wasmedge
|
* Validate that a web assembly blob can be loaded by wasmedge
|
||||||
*/
|
*/
|
||||||
@@ -487,13 +497,13 @@ namespace hook
|
|||||||
WasmEdge_Result res =
|
WasmEdge_Result res =
|
||||||
WasmEdge_VMLoadWasmFromBuffer(vm.ctx, reinterpret_cast<const uint8_t*>(wasm), len);
|
WasmEdge_VMLoadWasmFromBuffer(vm.ctx, reinterpret_cast<const uint8_t*>(wasm), len);
|
||||||
|
|
||||||
if (!WasmEdge_ResultOK(res))
|
if (auto err = getWasmError("VMLoadWasmFromBuffer failed", res); err)
|
||||||
return "VMLoadWasmFromBuffer failed";
|
return *err;
|
||||||
|
|
||||||
res = WasmEdge_VMValidate(vm.ctx);
|
res = WasmEdge_VMValidate(vm.ctx);
|
||||||
|
|
||||||
if (!WasmEdge_ResultOK(res))
|
if (auto err = getWasmError("VMValidate failed", res); err)
|
||||||
return "VMValidate failed";
|
return *err;
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@@ -529,13 +539,11 @@ namespace hook
|
|||||||
}
|
}
|
||||||
|
|
||||||
WasmEdge_Result res = WasmEdge_VMRegisterModuleFromImport(vm.ctx, this->importObj);
|
WasmEdge_Result res = WasmEdge_VMRegisterModuleFromImport(vm.ctx, this->importObj);
|
||||||
if (!WasmEdge_ResultOK(res))
|
|
||||||
|
if (auto err = getWasmError("Import phase failed", res); err)
|
||||||
{
|
{
|
||||||
hookCtx.result.exitType = hook_api::ExitType::WASM_ERROR;
|
hookCtx.result.exitType = hook_api::ExitType::WASM_ERROR;
|
||||||
JLOG(j.trace())
|
JLOG(j.trace()) << "HookError[" << HC_ACC() << "]: " << *err;
|
||||||
<< "HookError[" << HC_ACC() << "]: Import phase failed "
|
|
||||||
<< WasmEdge_ResultGetMessage(res);
|
|
||||||
hookCtx.result.exitType = hook_api::ExitType::WASM_ERROR;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -547,11 +555,9 @@ namespace hook
|
|||||||
callback ? cbakFunctionName : hookFunctionName,
|
callback ? cbakFunctionName : hookFunctionName,
|
||||||
params, 1, returns, 1);
|
params, 1, returns, 1);
|
||||||
|
|
||||||
if (!WasmEdge_ResultOK(res))
|
if (auto err = getWasmError("WASM VM error", res); err)
|
||||||
{
|
{
|
||||||
JLOG(j.warn())
|
JLOG(j.warn()) << "HookError[" << HC_ACC() << "]: " << *err;
|
||||||
<< "HookError[" << HC_ACC() << "]: WASM VM error "
|
|
||||||
<< WasmEdge_ResultGetMessage(res);
|
|
||||||
hookCtx.result.exitType = hook_api::ExitType::WASM_ERROR;
|
hookCtx.result.exitType = hook_api::ExitType::WASM_ERROR;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user