Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(373)

Unified Diff: src/wasm/wasm-module.cc

Issue 1900153002: [wasm] Enforce strict ordering of WASM module sections. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/wasm/wasm-module.h ('k') | test/mjsunit/wasm/wasm-module-builder.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/wasm/wasm-module.cc
diff --git a/src/wasm/wasm-module.cc b/src/wasm/wasm-module.cc
index 68ef6ba97dbac7f9ba9971acdb5abcac07be5939..e15b8d1f55318c7dcc8a51ad1746c06b4b8c3fc6 100644
--- a/src/wasm/wasm-module.cc
+++ b/src/wasm/wasm-module.cc
@@ -20,19 +20,28 @@ namespace internal {
namespace wasm {
static const char* wasmSections[] = {
-#define F(enumerator, string) string,
+#define F(enumerator, order, string) string,
FOR_EACH_WASM_SECTION_TYPE(F)
#undef F
+ "<unknown>" // entry for "Max"
};
static uint8_t wasmSectionsLengths[]{
-#define F(enumerator, string) sizeof(string) - 1,
+#define F(enumerator, order, string) sizeof(string) - 1,
FOR_EACH_WASM_SECTION_TYPE(F)
#undef F
+ 9 // entry for "Max"
+};
+
+static uint8_t wasmSectionsOrders[]{
+#define F(enumerator, order, string) order,
+ FOR_EACH_WASM_SECTION_TYPE(F)
+#undef F
+ 0 // entry for "Max"
};
static_assert(sizeof(wasmSections) / sizeof(wasmSections[0]) ==
- (size_t)WasmSection::Code::Max,
+ (size_t)WasmSection::Code::Max + 1,
"expected enum WasmSection::Code to be monotonic from 0");
WasmSection::Code WasmSection::begin() { return (WasmSection::Code)0; }
@@ -49,6 +58,20 @@ size_t WasmSection::getNameLength(WasmSection::Code code) {
return wasmSectionsLengths[(size_t)code];
}
+int WasmSection::getOrder(WasmSection::Code code) {
+ return wasmSectionsOrders[(size_t)code];
+}
+
+WasmSection::Code WasmSection::lookup(const byte* string, uint32_t length) {
+ // TODO(jfb) Linear search, it may be better to do a common-prefix search.
+ for (Code i = begin(); i != end(); i = next(i)) {
+ if (getNameLength(i) == length && 0 == memcmp(getName(i), string, length)) {
+ return i;
+ }
+ }
+ return Code::Max;
+}
+
std::ostream& operator<<(std::ostream& os, const WasmModule& module) {
os << "WASM module with ";
os << (module.min_mem_pages * module.kPageSize) << " min mem";
« no previous file with comments | « src/wasm/wasm-module.h ('k') | test/mjsunit/wasm/wasm-module-builder.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698