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

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

Issue 1740373002: [wasm] Add a magic word and a version number to the binary. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 10 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/module-decoder.cc
diff --git a/src/wasm/module-decoder.cc b/src/wasm/module-decoder.cc
index 9ba0b3b663f5bdd5c8e6f53861272faeb83d05ab..777acdfb1c043f1f10a62579c986c9f944b2587f 100644
--- a/src/wasm/module-decoder.cc
+++ b/src/wasm/module-decoder.cc
@@ -60,6 +60,22 @@ class ModuleDecoder : public Decoder {
bool sections[kMaxModuleSectionCode];
memset(sections, 0, sizeof(sections));
+ const byte* pos = pc_;
+ uint32_t magic_number = consume_u32("wasm magic");
+ if (magic_number != kWasmMagic) {
+ error(pos, pos, "expected magic bytes 0 a s m");
JF 2016/02/27 19:43:04 "0 a s m" will be incorrect if we change kWasmMagi
titzer 2016/02/27 23:05:09 Done.
+ return toResult(module);
+ }
+
+ pos = pc_;
+ uint32_t magic_version = consume_u32("wasm version");
+ if (magic_version != kWasmVersion) {
+ error(pos, pos, "expected version %02x %02x %02x %02x",
+ (kWasmVersion & 0xff), (kWasmVersion >> 8) & 0xff,
+ (kWasmVersion >> 16) & 0xff, (kWasmVersion >> 24) & 0xff);
JF 2016/02/27 19:43:04 Same here, print magic_version.
titzer 2016/02/27 23:05:09 Done.
+ return toResult(module);
+ }
+
// Decode the module sections.
while (pc_ < limit_) {
TRACE("DecodeSection\n");

Powered by Google App Engine
This is Rietveld 408576698