summaryrefslogtreecommitdiff
path: root/src/interp
diff options
context:
space:
mode:
Diffstat (limited to 'src/interp')
-rw-r--r--src/interp/binary-reader-interp.cc22
-rw-r--r--src/interp/interp-wasm-c-api.cc5
-rw-r--r--src/interp/interp.cc10
3 files changed, 26 insertions, 11 deletions
diff --git a/src/interp/binary-reader-interp.cc b/src/interp/binary-reader-interp.cc
index dc7ec410..1d3daf8e 100644
--- a/src/interp/binary-reader-interp.cc
+++ b/src/interp/binary-reader-interp.cc
@@ -105,7 +105,8 @@ class BinaryReaderInterp : public BinaryReaderNop {
std::string_view module_name,
std::string_view field_name,
Index memory_index,
- const Limits* page_limits) override;
+ const Limits* page_limits,
+ uint32_t page_size) override;
Result OnImportGlobal(Index import_index,
std::string_view module_name,
std::string_view field_name,
@@ -127,7 +128,9 @@ class BinaryReaderInterp : public BinaryReaderNop {
const Limits* elem_limits) override;
Result OnMemoryCount(Index count) override;
- Result OnMemory(Index index, const Limits* limits) override;
+ Result OnMemory(Index index,
+ const Limits* limits,
+ uint32_t page_size) override;
Result OnGlobalCount(Index count) override;
Result BeginGlobal(Index index, Type type, bool mutable_) override;
@@ -537,9 +540,10 @@ Result BinaryReaderInterp::OnImportMemory(Index import_index,
std::string_view module_name,
std::string_view field_name,
Index memory_index,
- const Limits* page_limits) {
- CHECK_RESULT(validator_.OnMemory(GetLocation(), *page_limits));
- MemoryType memory_type{*page_limits};
+ const Limits* page_limits,
+ uint32_t page_size) {
+ CHECK_RESULT(validator_.OnMemory(GetLocation(), *page_limits, page_size));
+ MemoryType memory_type{*page_limits, page_size};
module_.imports.push_back(ImportDesc{ImportType(
std::string(module_name), std::string(field_name), memory_type.Clone())});
memory_types_.push_back(memory_type);
@@ -608,9 +612,11 @@ Result BinaryReaderInterp::OnMemoryCount(Index count) {
return Result::Ok;
}
-Result BinaryReaderInterp::OnMemory(Index index, const Limits* limits) {
- CHECK_RESULT(validator_.OnMemory(GetLocation(), *limits));
- MemoryType memory_type{*limits};
+Result BinaryReaderInterp::OnMemory(Index index,
+ const Limits* limits,
+ uint32_t page_size) {
+ CHECK_RESULT(validator_.OnMemory(GetLocation(), *limits, page_size));
+ MemoryType memory_type{*limits, page_size};
module_.memories.push_back(MemoryDesc{memory_type});
memory_types_.push_back(memory_type);
return Result::Ok;
diff --git a/src/interp/interp-wasm-c-api.cc b/src/interp/interp-wasm-c-api.cc
index cfa8a897..bb4598a4 100644
--- a/src/interp/interp-wasm-c-api.cc
+++ b/src/interp/interp-wasm-c-api.cc
@@ -160,7 +160,10 @@ struct wasm_tabletype_t : wasm_externtype_t {
struct wasm_memorytype_t : wasm_externtype_t {
wasm_memorytype_t(const wasm_limits_t* limits)
- : wasm_externtype_t{std::make_unique<MemoryType>(ToWabtLimits(*limits))},
+ : wasm_externtype_t{std::make_unique<MemoryType>(
+ ToWabtLimits(*limits),
+ WABT_DEFAULT_PAGE_SIZE)}, // wasm-c-api doesn't support
+ // custom-page-sizes yet
limits{*limits} {}
wasm_memorytype_t(MemoryType mt)
diff --git a/src/interp/interp.cc b/src/interp/interp.cc
index a3dd9b4a..f93fa5a6 100644
--- a/src/interp/interp.cc
+++ b/src/interp/interp.cc
@@ -136,6 +136,12 @@ std::unique_ptr<ExternType> MemoryType::Clone() const {
Result Match(const MemoryType& expected,
const MemoryType& actual,
std::string* out_msg) {
+ if (expected.page_size != actual.page_size) {
+ *out_msg = StringPrintf(
+ "page_size mismatch in imported memory, expected %u but got %u.",
+ expected.page_size, actual.page_size);
+ return Result::Error;
+ }
return Match(expected.limits, actual.limits, out_msg);
}
@@ -576,7 +582,7 @@ Result Table::Copy(Store& store,
//// Memory ////
Memory::Memory(class Store&, MemoryType type)
: Extern(skind), type_(type), pages_(type.limits.initial) {
- data_.resize(pages_ * WABT_PAGE_SIZE);
+ data_.resize(pages_ * type_.page_size);
}
void Memory::Mark(class Store&) {}
@@ -597,7 +603,7 @@ Result Memory::Grow(u64 count) {
auto old_size = data_.size();
#endif
pages_ = new_pages;
- data_.resize(new_pages * WABT_PAGE_SIZE);
+ data_.resize(new_pages * type_.page_size);
#if WABT_BIG_ENDIAN
std::move_backward(data_.begin(), data_.begin() + old_size, data_.end());
std::fill(data_.begin(), data_.end() - old_size, 0);