summaryrefslogtreecommitdiff
path: root/src/shell-interface.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/shell-interface.h')
-rw-r--r--src/shell-interface.h29
1 files changed, 23 insertions, 6 deletions
diff --git a/src/shell-interface.h b/src/shell-interface.h
index 0c81680f5..6c6ddf7f2 100644
--- a/src/shell-interface.h
+++ b/src/shell-interface.h
@@ -223,27 +223,31 @@ struct ShellExternalInterface : ModuleInstance::ExternalInterface {
memory.set<std::array<uint8_t, 16>>(addr, value);
}
- void tableStore(Name tableName, Address addr, const Literal& entry) override {
+ Index tableSize(Name tableName) override {
+ return (Index)tables[tableName].size();
+ }
+
+ void tableStore(Name tableName, Index index, const Literal& entry) override {
auto& table = tables[tableName];
- if (addr >= table.size()) {
+ if (index >= table.size()) {
trap("out of bounds table access");
} else {
- table[addr] = entry;
+ table[index] = entry;
}
}
- Literal tableLoad(Name tableName, Address addr) override {
+ Literal tableLoad(Name tableName, Index index) override {
auto it = tables.find(tableName);
if (it == tables.end()) {
trap("tableGet on non-existing table");
}
auto& table = it->second;
- if (addr >= table.size()) {
+ if (index >= table.size()) {
trap("out of bounds table access");
}
- return table[addr];
+ return table[index];
}
bool growMemory(Address /*oldSize*/, Address newSize) override {
@@ -256,6 +260,19 @@ struct ShellExternalInterface : ModuleInstance::ExternalInterface {
return true;
}
+ bool growTable(Name name,
+ const Literal& value,
+ Index /*oldSize*/,
+ Index newSize) override {
+ // Apply a reasonable limit on table size, 1GB, to avoid DOS on the
+ // interpreter.
+ if (newSize > 1024 * 1024 * 1024) {
+ return false;
+ }
+ tables[name].resize(newSize, value);
+ return true;
+ }
+
void trap(const char* why) override {
std::cout << "[trap " << why << "]\n";
throw TrapException();