summaryrefslogtreecommitdiff
path: root/src/validator.cc
diff options
context:
space:
mode:
authorBen Smith <binjimin@gmail.com>2018-02-13 11:37:18 -0800
committerGitHub <noreply@github.com>2018-02-13 11:37:18 -0800
commitb20496162dfa5d8f847f3b1608373dd70478af9e (patch)
treea6c374b15ffcd951f87dcc6ce4b9a99c4f0454ff /src/validator.cc
parentbfa5e1cc2e3b1fd0ff733fb4b5b2fffd0a878fe3 (diff)
downloadwabt-b20496162dfa5d8f847f3b1608373dd70478af9e.tar.gz
wabt-b20496162dfa5d8f847f3b1608373dd70478af9e.tar.bz2
wabt-b20496162dfa5d8f847f3b1608373dd70478af9e.zip
Don't allow memory to be shared by default (#756)
Shared memory is only allowed with the `--enable-threads` flag.
Diffstat (limited to 'src/validator.cc')
-rw-r--r--src/validator.cc37
1 files changed, 19 insertions, 18 deletions
diff --git a/src/validator.cc b/src/validator.cc
index 85715b47..717f39ee 100644
--- a/src/validator.cc
+++ b/src/validator.cc
@@ -129,9 +129,10 @@ class Validator {
Type expected_type,
const char* desc);
void CheckGlobal(const Location* loc, const Global* global);
- void CheckLimits(const Location* loc, const Limits* limits,
- uint64_t absolute_max, const char* desc,
- LimitsShareable sharing);
+ void CheckLimits(const Location* loc,
+ const Limits* limits,
+ uint64_t absolute_max,
+ const char* desc);
void CheckTable(const Location* loc, const Table* table);
void CheckElemSegments(const Module* module);
void CheckMemory(const Location* loc, const Memory* memory);
@@ -784,8 +785,7 @@ void Validator::CheckGlobal(const Location* loc, const Global* global) {
}
void Validator::CheckLimits(const Location* loc, const Limits* limits,
- uint64_t absolute_max, const char* desc,
- LimitsShareable sharing) {
+ uint64_t absolute_max, const char* desc) {
if (limits->initial > absolute_max) {
PrintError(loc, "initial %s (%" PRIu64 ") must be <= (%" PRIu64 ")", desc,
limits->initial, absolute_max);
@@ -803,23 +803,17 @@ void Validator::CheckLimits(const Location* loc, const Limits* limits,
desc, limits->max, desc, limits->initial);
}
}
- if (limits->is_shared) {
- if (sharing == LimitsShareable::NotAllowed) {
- PrintError(loc, "tables may not be shared");
- return;
- }
- if (!limits->has_max) {
- PrintError(loc, "shared memories must have max sizes");
- }
- }
}
void Validator::CheckTable(const Location* loc, const Table* table) {
if (current_table_index_ == 1) {
PrintError(loc, "only one table allowed");
}
- CheckLimits(loc, &table->elem_limits, UINT32_MAX, "elems",
- LimitsShareable::NotAllowed);
+ CheckLimits(loc, &table->elem_limits, UINT32_MAX, "elems");
+
+ if (table->elem_limits.is_shared) {
+ PrintError(loc, "tables may not be shared");
+ }
}
void Validator::CheckElemSegments(const Module* module) {
@@ -845,8 +839,15 @@ void Validator::CheckMemory(const Location* loc, const Memory* memory) {
if (current_memory_index_ == 1) {
PrintError(loc, "only one memory block allowed");
}
- CheckLimits(loc, &memory->page_limits, WABT_MAX_PAGES, "pages",
- LimitsShareable::Allowed);
+ CheckLimits(loc, &memory->page_limits, WABT_MAX_PAGES, "pages");
+
+ if (memory->page_limits.is_shared) {
+ if (!options_->features.threads_enabled()) {
+ PrintError(loc, "memories may not be shared");
+ } else if (!memory->page_limits.has_max) {
+ PrintError(loc, "shared memories must have max sizes");
+ }
+ }
}
void Validator::CheckDataSegments(const Module* module) {