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

Side by Side Diff: src/wasm/wasm-module.h

Issue 1910213004: [wasm] Replace WasmName by Vector<const char> (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@wasm-offset-table-2
Patch Set: nicer bounds check Created 4 years, 7 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 unified diff | Download patch
« no previous file with comments | « src/compiler/wasm-compiler.cc ('k') | src/wasm/wasm-module.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #ifndef V8_WASM_MODULE_H_ 5 #ifndef V8_WASM_MODULE_H_
6 #define V8_WASM_MODULE_H_ 6 #define V8_WASM_MODULE_H_
7 7
8 #include "src/wasm/wasm-opcodes.h" 8 #include "src/wasm/wasm-opcodes.h"
9 #include "src/wasm/wasm-result.h" 9 #include "src/wasm/wasm-result.h"
10 10
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 std::vector<uint16_t> function_table; // function table. 186 std::vector<uint16_t> function_table; // function table.
187 std::vector<WasmImport> import_table; // import table. 187 std::vector<WasmImport> import_table; // import table.
188 std::vector<WasmExport> export_table; // export table. 188 std::vector<WasmExport> export_table; // export table.
189 189
190 WasmModule(); 190 WasmModule();
191 191
192 // Get a string stored in the module bytes representing a name. 192 // Get a string stored in the module bytes representing a name.
193 WasmName GetName(uint32_t offset, uint32_t length) const { 193 WasmName GetName(uint32_t offset, uint32_t length) const {
194 if (length == 0) return {"<?>", 3}; // no name. 194 if (length == 0) return {"<?>", 3}; // no name.
195 CHECK(BoundsCheck(offset, offset + length)); 195 CHECK(BoundsCheck(offset, offset + length));
196 return {reinterpret_cast<const char*>(module_start + offset), length}; 196 DCHECK_GE(static_cast<int>(length), 0);
197 return {reinterpret_cast<const char*>(module_start + offset),
198 static_cast<int>(length)};
197 } 199 }
198 200
199 // Get a string stored in the module bytes representing a name. 201 // Get a string stored in the module bytes representing a name.
200 WasmName GetNameOrNull(uint32_t offset, uint32_t length) const { 202 WasmName GetNameOrNull(uint32_t offset, uint32_t length) const {
201 if (length == 0) return {NULL, 0}; // no name. 203 if (length == 0) return {NULL, 0}; // no name.
202 CHECK(BoundsCheck(offset, offset + length)); 204 CHECK(BoundsCheck(offset, offset + length));
203 return {reinterpret_cast<const char*>(module_start + offset), length}; 205 DCHECK_GE(static_cast<int>(length), 0);
206 return {reinterpret_cast<const char*>(module_start + offset),
207 static_cast<int>(length)};
204 } 208 }
205 209
206 // Checks the given offset range is contained within the module bytes. 210 // Checks the given offset range is contained within the module bytes.
207 bool BoundsCheck(uint32_t start, uint32_t end) const { 211 bool BoundsCheck(uint32_t start, uint32_t end) const {
208 size_t size = module_end - module_start; 212 size_t size = module_end - module_start;
209 return start < size && end < size; 213 return start < size && end < size;
210 } 214 }
211 215
212 // Creates a new instantiation of the module in the given isolate. 216 // Creates a new instantiation of the module in the given isolate.
213 MaybeHandle<JSObject> Instantiate(Isolate* isolate, Handle<JSObject> ffi, 217 MaybeHandle<JSObject> Instantiate(Isolate* isolate, Handle<JSObject> ffi,
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 322
319 // For testing. Decode, verify, and run the last exported function in the 323 // For testing. Decode, verify, and run the last exported function in the
320 // given decoded module. 324 // given decoded module.
321 int32_t CompileAndRunWasmModule(Isolate* isolate, WasmModule* module); 325 int32_t CompileAndRunWasmModule(Isolate* isolate, WasmModule* module);
322 326
323 } // namespace wasm 327 } // namespace wasm
324 } // namespace internal 328 } // namespace internal
325 } // namespace v8 329 } // namespace v8
326 330
327 #endif // V8_WASM_MODULE_H_ 331 #endif // V8_WASM_MODULE_H_
OLDNEW
« no previous file with comments | « src/compiler/wasm-compiler.cc ('k') | src/wasm/wasm-module.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698