OLD | NEW |
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 1250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1261 if (decoder.pc() != table_end) { | 1261 if (decoder.pc() != table_end) { |
1262 decoder.error("broken asm offset table"); | 1262 decoder.error("broken asm offset table"); |
1263 } | 1263 } |
1264 table.push_back(std::move(func_asm_offsets)); | 1264 table.push_back(std::move(func_asm_offsets)); |
1265 } | 1265 } |
1266 if (decoder.more()) decoder.error("unexpected additional bytes"); | 1266 if (decoder.more()) decoder.error("unexpected additional bytes"); |
1267 | 1267 |
1268 return decoder.toResult(std::move(table)); | 1268 return decoder.toResult(std::move(table)); |
1269 } | 1269 } |
1270 | 1270 |
| 1271 std::vector<CustomSectionOffset> DecodeCustomSections(const byte* start, |
| 1272 const byte* end) { |
| 1273 Decoder decoder(start, end); |
| 1274 decoder.consume_bytes(4, "wasm magic"); |
| 1275 decoder.consume_bytes(4, "wasm version"); |
| 1276 |
| 1277 std::vector<CustomSectionOffset> result; |
| 1278 |
| 1279 while (decoder.more()) { |
| 1280 byte section_code = decoder.consume_u8("section code"); |
| 1281 uint32_t section_length = decoder.consume_u32v("section length"); |
| 1282 uint32_t section_start = decoder.pc_offset(); |
| 1283 if (section_code != 0) { |
| 1284 // Skip known sections. |
| 1285 decoder.consume_bytes(section_length, "section bytes"); |
| 1286 continue; |
| 1287 } |
| 1288 uint32_t name_length = decoder.consume_u32v("name length"); |
| 1289 uint32_t name_offset = decoder.pc_offset(); |
| 1290 decoder.consume_bytes(name_length, "section name"); |
| 1291 uint32_t payload_offset = decoder.pc_offset(); |
| 1292 uint32_t payload_length = section_length - (payload_offset - section_start); |
| 1293 decoder.consume_bytes(payload_length); |
| 1294 result.push_back({section_start, name_offset, name_length, payload_offset, |
| 1295 payload_length, section_length}); |
| 1296 } |
| 1297 |
| 1298 return result; |
| 1299 } |
| 1300 |
1271 } // namespace wasm | 1301 } // namespace wasm |
1272 } // namespace internal | 1302 } // namespace internal |
1273 } // namespace v8 | 1303 } // namespace v8 |
OLD | NEW |