Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

memory check #1911

Merged
merged 8 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions core/runtime/wasm_edge/memory_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ namespace kagome::runtime::wasm_edge {
if (new_size > size()) {
auto old_page_num = WasmEdge_MemoryInstanceGetPageSize(mem_instance_);
auto new_page_num = (new_size + kMemoryPageSize - 1) / kMemoryPageSize;
[[maybe_unused]] auto res = WasmEdge_MemoryInstanceGrowPage(
mem_instance_, new_page_num - old_page_num);
BOOST_ASSERT(WasmEdge_ResultOK(res));
auto res = WasmEdge_MemoryInstanceGrowPage(mem_instance_,
new_page_num - old_page_num);
if (not WasmEdge_ResultOK(res)) {
throw std::runtime_error{"WasmEdge_MemoryInstanceGrowPage"};
turuslan marked this conversation as resolved.
Show resolved Hide resolved
}
SL_DEBUG(logger_,
"Grow memory to {} pages ({} bytes) - {}",
new_page_num,
Expand Down
20 changes: 13 additions & 7 deletions core/runtime/wasm_edge/memory_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ namespace kagome::runtime::wasm_edge {
template <typename T>
T loadInt(WasmPointer addr) const {
T data{};
[[maybe_unused]] auto res = WasmEdge_MemoryInstanceGetData(
auto res = WasmEdge_MemoryInstanceGetData(
mem_instance_, reinterpret_cast<uint8_t *>(&data), addr, sizeof(T));
BOOST_ASSERT(WasmEdge_ResultOK(res));
if (not WasmEdge_ResultOK(res)) {
throw std::runtime_error{"WasmEdge_MemoryInstanceGetData"};
turuslan marked this conversation as resolved.
Show resolved Hide resolved
}
if constexpr (std::is_integral_v<T>) {
SL_TRACE_FUNC_CALL(logger_, data, addr);
} else {
Expand Down Expand Up @@ -95,7 +97,9 @@ namespace kagome::runtime::wasm_edge {

common::BufferView loadN(WasmPointer addr, WasmSize n) const override {
auto ptr = WasmEdge_MemoryInstanceGetPointer(mem_instance_, addr, n);
BOOST_ASSERT(ptr);
if (ptr == nullptr) {
throw std::runtime_error{"WasmEdge_MemoryInstanceGetPointer"};
}
SL_TRACE_FUNC_CALL(logger_, fmt::ptr(ptr), addr, n);
return common::BufferView{ptr, static_cast<size_t>(n)};
}
Expand All @@ -110,9 +114,11 @@ namespace kagome::runtime::wasm_edge {

template <typename T>
void storeInt(WasmPointer addr, T value) const {
[[maybe_unused]] auto res = WasmEdge_MemoryInstanceSetData(
auto res = WasmEdge_MemoryInstanceSetData(
mem_instance_, reinterpret_cast<uint8_t *>(&value), addr, sizeof(T));
BOOST_ASSERT(WasmEdge_ResultOK(res));
if (not WasmEdge_ResultOK(res)) {
throw std::runtime_error{"WasmEdge_MemoryInstanceSetData"};
}
if constexpr (std::is_integral_v<T>) {
SL_TRACE_FUNC_CALL(
logger_, WasmEdge_ResultGetMessage(res), addr, value);
Expand Down Expand Up @@ -148,8 +154,8 @@ namespace kagome::runtime::wasm_edge {
void storeBuffer(WasmPointer addr, common::BufferView value) override {
auto res = WasmEdge_MemoryInstanceSetData(
mem_instance_, value.data(), addr, value.size());
if (!WasmEdge_ResultOK(res)) {
SL_ERROR(logger_, "{}", WasmEdge_ResultGetMessage(res));
if (not WasmEdge_ResultOK(res)) {
throw std::runtime_error{"WasmEdge_MemoryInstanceSetData"};
}
SL_TRACE_FUNC_CALL(logger_, WasmEdge_ResultGetMessage(res), addr);
}
Expand Down
Loading