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

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

Issue 1967023004: [wasm] Add UTF-8 validation (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: add titzer's comments 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
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/macro-assembler.h" 5 #include "src/macro-assembler.h"
6 #include "src/objects.h" 6 #include "src/objects.h"
7 #include "src/property-descriptor.h" 7 #include "src/property-descriptor.h"
8 #include "src/v8.h" 8 #include "src/v8.h"
9 9
10 #include "src/simulator.h" 10 #include "src/simulator.h"
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 546
547 // First pass: compile each function and initialize the code table. 547 // First pass: compile each function and initialize the code table.
548 for (uint32_t i = FLAG_skip_compiling_wasm_funcs; i < functions.size(); 548 for (uint32_t i = FLAG_skip_compiling_wasm_funcs; i < functions.size();
549 i++) { 549 i++) {
550 const WasmFunction& func = functions[i]; 550 const WasmFunction& func = functions[i];
551 if (thrower.error()) break; 551 if (thrower.error()) break;
552 DCHECK_EQ(i, func.func_index); 552 DCHECK_EQ(i, func.func_index);
553 553
554 WasmName str = GetName(func.name_offset, func.name_length); 554 WasmName str = GetName(func.name_offset, func.name_length);
555 WasmName str_null = {nullptr, 0}; 555 WasmName str_null = {nullptr, 0};
556 Handle<String> name = factory->InternalizeUtf8String(str);
557 Handle<Code> code = Handle<Code>::null(); 556 Handle<Code> code = Handle<Code>::null();
558 Handle<JSFunction> function = Handle<JSFunction>::null(); 557 Handle<JSFunction> function = Handle<JSFunction>::null();
558 Handle<String> functionName;
559 if (func.external) { 559 if (func.external) {
560 // Lookup external function in FFI object. 560 // Lookup external function in FFI object.
561 MaybeHandle<JSFunction> function = 561 MaybeHandle<JSFunction> function =
562 LookupFunction(thrower, factory, ffi, i, str, str_null); 562 LookupFunction(thrower, factory, ffi, i, str, str_null);
563 if (function.is_null()) return MaybeHandle<JSObject>(); 563 if (function.is_null()) return MaybeHandle<JSObject>();
564 code = compiler::CompileWasmToJSWrapper(isolate, &module_env, 564 code = compiler::CompileWasmToJSWrapper(isolate, &module_env,
565 function.ToHandleChecked(), 565 function.ToHandleChecked(),
566 func.sig, str, str_null); 566 func.sig, str, str_null);
567 } else { 567 } else {
568 if (FLAG_wasm_parallel_compilation) { 568 if (FLAG_wasm_parallel_compilation) {
569 code = results[i]; 569 code = results[i];
570 } else { 570 } else {
571 // Compile the function. 571 // Compile the function.
572 code = compiler::CompileWasmFunction(&thrower, isolate, &module_env, 572 code = compiler::CompileWasmFunction(&thrower, isolate, &module_env,
573 &func); 573 &func);
574 } 574 }
575 if (code.is_null()) { 575 if (code.is_null()) {
576 thrower.Error("Compilation of #%d:%.*s failed.", i, str.length(), 576 thrower.Error("Compilation of #%d:%.*s failed.", i, str.length(),
577 str.start()); 577 str.start());
578 return MaybeHandle<JSObject>(); 578 return MaybeHandle<JSObject>();
579 } 579 }
580 if (func.exported) { 580 if (func.exported) {
581 functionName = factory->InternalizeUtf8String(str);
581 function = compiler::CompileJSToWasmWrapper( 582 function = compiler::CompileJSToWasmWrapper(
582 isolate, &module_env, name, code, instance.js_object, i); 583 isolate, &module_env, functionName, code, instance.js_object, i);
583 record_code_size(function->code()); 584 record_code_size(function->code());
584 } 585 }
585 } 586 }
586 if (!code.is_null()) { 587 if (!code.is_null()) {
587 // Install the code into the linker table. 588 // Install the code into the linker table.
588 linker.Finish(i, code); 589 linker.Finish(i, code);
589 code_table->set(i, *code); 590 code_table->set(i, *code);
590 record_code_size(*code); 591 record_code_size(*code);
591 } 592 }
592 if (func.exported) { 593 if (!function.is_null()) {
593 // Exported functions are installed as read-only properties on the 594 // Exported functions are installed as read-only properties on the
594 // module. 595 // module.
595 desc.set_value(function); 596 desc.set_value(function);
596 Maybe<bool> status = JSReceiver::DefineOwnProperty( 597 Maybe<bool> status = JSReceiver::DefineOwnProperty(
597 isolate, instance.js_object, name, &desc, Object::THROW_ON_ERROR); 598 isolate, instance.js_object, functionName, &desc,
599 Object::THROW_ON_ERROR);
598 if (!status.IsJust()) 600 if (!status.IsJust())
599 thrower.Error("export of %.*s failed.", str.length(), str.start()); 601 thrower.Error("export of %.*s failed.", str.length(), str.start());
600 } 602 }
601 } 603 }
602 604
603 // Second pass: patch all direct call sites. 605 // Second pass: patch all direct call sites.
604 linker.Link(instance.function_table, this->function_table); 606 linker.Link(instance.function_table, this->function_table);
605 instance.js_object->SetInternalField(kWasmModuleFunctionTable, 607 instance.js_object->SetInternalField(kWasmModuleFunctionTable,
606 Smi::FromInt(0)); 608 Smi::FromInt(0));
607 609
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
809 wasm->GetInternalField(kWasmFunctionNamesArray), wasm->GetIsolate()); 811 wasm->GetInternalField(kWasmFunctionNamesArray), wasm->GetIsolate());
810 if (func_names_arr_obj->IsUndefined()) 812 if (func_names_arr_obj->IsUndefined())
811 return func_names_arr_obj; // Return undefined. 813 return func_names_arr_obj; // Return undefined.
812 return GetWasmFunctionNameFromTable( 814 return GetWasmFunctionNameFromTable(
813 Handle<ByteArray>::cast(func_names_arr_obj), func_index); 815 Handle<ByteArray>::cast(func_names_arr_obj), func_index);
814 } 816 }
815 817
816 } // namespace wasm 818 } // namespace wasm
817 } // namespace internal 819 } // namespace internal
818 } // namespace v8 820 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698