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

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

Issue 2500443004: [wasm] OOB traps: build protected instruction list during codegen (Closed)
Patch Set: Fixing Windows better 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 <memory> 5 #include <memory>
6 6
7 #include "src/base/atomic-utils.h" 7 #include "src/base/atomic-utils.h"
8 #include "src/code-stubs.h" 8 #include "src/code-stubs.h"
9 9
10 #include "src/macro-assembler.h" 10 #include "src/macro-assembler.h"
(...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 DCHECK_LE(module_bytes_len, static_cast<size_t>(kMaxInt)); 794 DCHECK_LE(module_bytes_len, static_cast<size_t>(kMaxInt));
795 Vector<const uint8_t> module_bytes_vec(module_start, 795 Vector<const uint8_t> module_bytes_vec(module_start,
796 static_cast<int>(module_bytes_len)); 796 static_cast<int>(module_bytes_len));
797 Handle<String> module_bytes_string = 797 Handle<String> module_bytes_string =
798 factory->NewStringFromOneByte(module_bytes_vec, TENURED) 798 factory->NewStringFromOneByte(module_bytes_vec, TENURED)
799 .ToHandleChecked(); 799 .ToHandleChecked();
800 DCHECK(module_bytes_string->IsSeqOneByteString()); 800 DCHECK(module_bytes_string->IsSeqOneByteString());
801 ret->set_module_bytes(Handle<SeqOneByteString>::cast(module_bytes_string)); 801 ret->set_module_bytes(Handle<SeqOneByteString>::cast(module_bytes_string));
802 } 802 }
803 803
804 Handle<FixedArray> protected_instructions =
805 PackProtectedInstructions(temp_instance.protected_instructions, factory);
806 ret->set_protected_instructions(protected_instructions);
807
804 return ret; 808 return ret;
805 } 809 }
806 810
811 Handle<FixedArray> WasmModule::PackProtectedInstructions(
titzer 2016/11/16 18:06:47 I think this can also move into the compiler.
Eric Holk 2016/11/18 02:19:46 Done.
812 const std::vector<ProtectedInstructionList>& protected_instructions,
813 Factory* factory) const {
814 const int num_instructions = static_cast<int>(protected_instructions.size());
815 Handle<FixedArray> all_protected =
816 factory->NewFixedArray(num_instructions, TENURED);
817 for (int j = 0; j < num_instructions; ++j) {
818 const ProtectedInstructionList& func = protected_instructions[j];
819 const int func_instructions = static_cast<int>(func.size());
820 Handle<FixedArray> fn_protected =
821 factory->NewFixedArray(func_instructions * kTrapDataSize, TENURED);
822 for (unsigned i = 0; i < func.size(); ++i) {
823 const ProtectedInstructionData& instruction = func[i];
824 fn_protected->set(kTrapDataSize * i + kTrapCodeOffset,
825 Smi::FromInt(instruction.instr_offset));
826 fn_protected->set(kTrapDataSize * i + kTrapLandingOffset,
827 Smi::FromInt(instruction.landing_offset));
828 }
829
830 all_protected->set(j, *fn_protected);
831 }
832 return all_protected;
833 }
834
807 static WasmFunction* GetWasmFunctionForImportWrapper(Isolate* isolate, 835 static WasmFunction* GetWasmFunctionForImportWrapper(Isolate* isolate,
808 Handle<Object> target) { 836 Handle<Object> target) {
809 if (target->IsJSFunction()) { 837 if (target->IsJSFunction()) {
810 Handle<JSFunction> func = Handle<JSFunction>::cast(target); 838 Handle<JSFunction> func = Handle<JSFunction>::cast(target);
811 if (func->code()->kind() == Code::JS_TO_WASM_FUNCTION) { 839 if (func->code()->kind() == Code::JS_TO_WASM_FUNCTION) {
812 auto exported = Handle<WasmExportedFunction>::cast(func); 840 auto exported = Handle<WasmExportedFunction>::cast(func);
813 Handle<WasmInstanceObject> other_instance(exported->instance(), isolate); 841 Handle<WasmInstanceObject> other_instance(exported->instance(), isolate);
814 int func_index = exported->function_index(); 842 int func_index = exported->function_index();
815 return &other_instance->module()->functions[func_index]; 843 return &other_instance->module()->functions[func_index];
816 } 844 }
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
1110 if (function_table_count > 0) InitializeTables(code_table, instance); 1138 if (function_table_count > 0) InitializeTables(code_table, instance);
1111 1139
1112 if (num_imported_functions > 0 || !owner.is_null()) { 1140 if (num_imported_functions > 0 || !owner.is_null()) {
1113 // If the code was cloned, or new imports were compiled, patch. 1141 // If the code was cloned, or new imports were compiled, patch.
1114 PatchDirectCalls(old_code_table, code_table, num_imported_functions); 1142 PatchDirectCalls(old_code_table, code_table, num_imported_functions);
1115 } 1143 }
1116 1144
1117 FlushICache(isolate_, code_table); 1145 FlushICache(isolate_, code_table);
1118 1146
1119 //-------------------------------------------------------------------------- 1147 //--------------------------------------------------------------------------
1148 // Unpack and notify signal handler of protected instructions.
1149 //--------------------------------------------------------------------------
1150 {
1151 Handle<FixedArray> protected_instructions =
1152 compiled_module_->protected_instructions();
1153
1154 for (int i = 0; i < protected_instructions->length(); ++i) {
1155 Handle<FixedArray> fn_protect =
1156 protected_instructions->GetValueChecked<FixedArray>(isolate_, i);
1157
1158 ProtectedInstructionList unpacked;
1159 for (int i = 0; i < fn_protect->length();
1160 i += WasmModule::kTrapDataSize) {
1161 ProtectedInstructionData data;
1162 data.instr_offset = fn_protect
1163 ->GetValueChecked<Smi>(
1164 isolate_, i + WasmModule::kTrapCodeOffset)
1165 ->value();
1166 data.landing_offset =
1167 fn_protect
1168 ->GetValueChecked<Smi>(isolate_,
1169 i + WasmModule::kTrapLandingOffset)
1170 ->value();
1171 unpacked.push_back(data);
1172 }
1173 // TODO(eholk): Register the protected instruction information once the
1174 // trap handler is in place.
1175 }
1176 }
1177
1120 // Set up and link the new instance. 1178 // Set up and link the new instance.
1121 //-------------------------------------------------------------------------- 1179 //--------------------------------------------------------------------------
1122 { 1180 {
1123 Handle<Object> global_handle = 1181 Handle<Object> global_handle =
1124 isolate_->global_handles()->Create(*instance); 1182 isolate_->global_handles()->Create(*instance);
1125 Handle<WeakCell> link_to_clone = factory->NewWeakCell(compiled_module_); 1183 Handle<WeakCell> link_to_clone = factory->NewWeakCell(compiled_module_);
1126 Handle<WeakCell> link_to_owning_instance = factory->NewWeakCell(instance); 1184 Handle<WeakCell> link_to_owning_instance = factory->NewWeakCell(instance);
1127 MaybeHandle<WeakCell> link_to_original; 1185 MaybeHandle<WeakCell> link_to_original;
1128 MaybeHandle<WasmCompiledModule> original; 1186 MaybeHandle<WasmCompiledModule> original;
1129 if (!owner.is_null()) { 1187 if (!owner.is_null()) {
(...skipping 974 matching lines...) Expand 10 before | Expand all | Expand 10 after
2104 CHECK_NOT_NULL(result.val); 2162 CHECK_NOT_NULL(result.val);
2105 module = const_cast<WasmModule*>(result.val); 2163 module = const_cast<WasmModule*>(result.val);
2106 } 2164 }
2107 2165
2108 Handle<WasmModuleWrapper> module_wrapper = 2166 Handle<WasmModuleWrapper> module_wrapper =
2109 WasmModuleWrapper::New(isolate, module); 2167 WasmModuleWrapper::New(isolate, module);
2110 2168
2111 compiled_module->set_module_wrapper(module_wrapper); 2169 compiled_module->set_module_wrapper(module_wrapper);
2112 DCHECK(WasmCompiledModule::IsWasmCompiledModule(*compiled_module)); 2170 DCHECK(WasmCompiledModule::IsWasmCompiledModule(*compiled_module));
2113 } 2171 }
OLDNEW
« src/wasm/wasm-module.h ('K') | « src/wasm/wasm-module.h ('k') | src/wasm/wasm-objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698