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

Side by Side Diff: src/wasm/module-decoder.cc

Issue 2493823003: [wasm] Allocate a single script per wasm module (Closed)
Patch Set: Fix signed/unsigned issues Created 4 years, 1 month 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/wasm/module-decoder.h" 5 #include "src/wasm/module-decoder.h"
6 6
7 #include "src/base/functional.h" 7 #include "src/base/functional.h"
8 #include "src/base/platform/platform.h" 8 #include "src/base/platform/platform.h"
9 #include "src/flags.h" 9 #include "src/flags.h"
10 #include "src/macro-assembler.h" 10 #include "src/macro-assembler.h"
(...skipping 1134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1145 if (function_start > function_end) return FunctionError("start > end"); 1145 if (function_start > function_end) return FunctionError("start > end");
1146 if (size > kMaxFunctionSize) 1146 if (size > kMaxFunctionSize)
1147 return FunctionError("size > maximum function size"); 1147 return FunctionError("size > maximum function size");
1148 isolate->counters()->wasm_function_size_bytes()->AddSample( 1148 isolate->counters()->wasm_function_size_bytes()->AddSample(
1149 static_cast<int>(size)); 1149 static_cast<int>(size));
1150 WasmFunction* function = new WasmFunction(); 1150 WasmFunction* function = new WasmFunction();
1151 ModuleDecoder decoder(zone, function_start, function_end, kWasmOrigin); 1151 ModuleDecoder decoder(zone, function_start, function_end, kWasmOrigin);
1152 return decoder.DecodeSingleFunction(module_env, function); 1152 return decoder.DecodeSingleFunction(module_env, function);
1153 } 1153 }
1154 1154
1155 FunctionOffsetsResult DecodeWasmFunctionOffsets( 1155 FunctionOffsetsResult DecodeWasmFunctionOffsets(const byte* module_start,
1156 const byte* module_start, const byte* module_end, 1156 const byte* module_end) {
1157 uint32_t num_imported_functions) {
1158 // Find and decode the code section. 1157 // Find and decode the code section.
1159 Vector<const byte> code_section = 1158 Vector<const byte> code_section =
1160 FindSection(module_start, module_end, kCodeSectionCode); 1159 FindSection(module_start, module_end, kCodeSectionCode);
1161 Decoder decoder(code_section.start(), code_section.end()); 1160 Decoder decoder(code_section.start(), code_section.end());
1162 FunctionOffsets table; 1161 FunctionOffsets table;
1163 if (!code_section.start()) { 1162 if (!code_section.start()) {
1164 decoder.error("no code section"); 1163 decoder.error("no code section");
1165 return decoder.toResult(std::move(table)); 1164 return decoder.toResult(std::move(table));
1166 } 1165 }
1167 1166
1168 uint32_t functions_count = decoder.consume_u32v("functions count"); 1167 uint32_t functions_count = decoder.consume_u32v("functions count");
1169 // Reserve space for the entries, taking care of invalid input. 1168 // Reserve space for the entries, taking care of invalid input.
1170 if (functions_count < static_cast<unsigned>(code_section.length()) / 2) { 1169 if (functions_count < static_cast<unsigned>(code_section.length()) / 2) {
1171 table.reserve(num_imported_functions + functions_count); 1170 table.reserve(functions_count);
1172 } 1171 }
1173 1172
1174 // Add null entries for the imported functions.
1175 table.resize(num_imported_functions);
1176
1177 int section_offset = static_cast<int>(code_section.start() - module_start); 1173 int section_offset = static_cast<int>(code_section.start() - module_start);
1178 DCHECK_LE(0, section_offset); 1174 DCHECK_LE(0, section_offset);
1179 for (uint32_t i = 0; i < functions_count && decoder.ok(); ++i) { 1175 for (uint32_t i = 0; i < functions_count && decoder.ok(); ++i) {
1180 uint32_t size = decoder.consume_u32v("body size"); 1176 uint32_t size = decoder.consume_u32v("body size");
1181 int offset = static_cast<int>(section_offset + decoder.pc_offset()); 1177 int offset = static_cast<int>(section_offset + decoder.pc_offset());
1182 table.push_back(std::make_pair(offset, static_cast<int>(size))); 1178 table.push_back(std::make_pair(offset, static_cast<int>(size)));
1183 DCHECK(table.back().first >= 0 && table.back().second >= 0); 1179 DCHECK(table.back().first >= 0 && table.back().second >= 0);
1184 decoder.consume_bytes(size); 1180 decoder.consume_bytes(size);
1185 } 1181 }
1186 if (decoder.more()) decoder.error("unexpected additional bytes"); 1182 if (decoder.more()) decoder.error("unexpected additional bytes");
1187 1183
1188 return decoder.toResult(std::move(table)); 1184 return decoder.toResult(std::move(table));
1189 } 1185 }
1190 1186
1191 AsmJsOffsetsResult DecodeAsmJsOffsets(const byte* tables_start, 1187 AsmJsOffsetsResult DecodeAsmJsOffsets(const byte* tables_start,
1192 const byte* tables_end, 1188 const byte* tables_end) {
1193 uint32_t num_imported_functions) {
1194 AsmJsOffsets table; 1189 AsmJsOffsets table;
1195 1190
1196 Decoder decoder(tables_start, tables_end); 1191 Decoder decoder(tables_start, tables_end);
1197 uint32_t functions_count = decoder.consume_u32v("functions count"); 1192 uint32_t functions_count = decoder.consume_u32v("functions count");
1198 // Reserve space for the entries, taking care of invalid input. 1193 // Reserve space for the entries, taking care of invalid input.
1199 if (functions_count < static_cast<unsigned>(tables_end - tables_start)) { 1194 if (functions_count < static_cast<unsigned>(tables_end - tables_start)) {
1200 table.reserve(num_imported_functions + functions_count); 1195 table.reserve(functions_count);
1201 } 1196 }
1202 1197
1203 // Add null entries for the imported functions.
1204 table.resize(num_imported_functions);
1205
1206 for (uint32_t i = 0; i < functions_count && decoder.ok(); ++i) { 1198 for (uint32_t i = 0; i < functions_count && decoder.ok(); ++i) {
1207 uint32_t size = decoder.consume_u32v("table size"); 1199 uint32_t size = decoder.consume_u32v("table size");
1208 if (size == 0) { 1200 if (size == 0) {
1209 table.push_back(std::vector<std::pair<int, int>>()); 1201 table.push_back(std::vector<std::pair<int, int>>());
1210 continue; 1202 continue;
1211 } 1203 }
1212 if (!decoder.checkAvailable(size)) { 1204 if (!decoder.checkAvailable(size)) {
1213 decoder.error("illegal asm function offset table size"); 1205 decoder.error("illegal asm function offset table size");
1214 } 1206 }
1215 const byte* table_end = decoder.pc() + size; 1207 const byte* table_end = decoder.pc() + size;
(...skipping 13 matching lines...) Expand all
1229 table.push_back(std::move(func_asm_offsets)); 1221 table.push_back(std::move(func_asm_offsets));
1230 } 1222 }
1231 if (decoder.more()) decoder.error("unexpected additional bytes"); 1223 if (decoder.more()) decoder.error("unexpected additional bytes");
1232 1224
1233 return decoder.toResult(std::move(table)); 1225 return decoder.toResult(std::move(table));
1234 } 1226 }
1235 1227
1236 } // namespace wasm 1228 } // namespace wasm
1237 } // namespace internal 1229 } // namespace internal
1238 } // namespace v8 1230 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698