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

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: 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
Index: src/wasm/wasm-module.cc
diff --git a/src/wasm/wasm-module.cc b/src/wasm/wasm-module.cc
index 79b7c405fe2f3de4208c1bef5014d6a86964a9af..8b2caeec70951f8af60a241560a967d9d49913ad 100644
--- a/src/wasm/wasm-module.cc
+++ b/src/wasm/wasm-module.cc
@@ -20,13 +20,19 @@ 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
};
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
+};
+
+static uint8_t wasmSectionsOrders[]{
+#define F(enumerator, order, string) order,
FOR_EACH_WASM_SECTION_TYPE(F)
#undef F
};
@@ -49,6 +55,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";

Powered by Google App Engine
This is Rietveld 408576698