| 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 <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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 45 | 45 | 
| 46 byte* raw_buffer_ptr(MaybeHandle<JSArrayBuffer> buffer, int offset) { | 46 byte* raw_buffer_ptr(MaybeHandle<JSArrayBuffer> buffer, int offset) { | 
| 47   return static_cast<byte*>(buffer.ToHandleChecked()->backing_store()) + offset; | 47   return static_cast<byte*>(buffer.ToHandleChecked()->backing_store()) + offset; | 
| 48 } | 48 } | 
| 49 | 49 | 
| 50 MaybeHandle<String> ExtractStringFromModuleBytes( | 50 MaybeHandle<String> ExtractStringFromModuleBytes( | 
| 51     Isolate* isolate, Handle<WasmCompiledModule> compiled_module, | 51     Isolate* isolate, Handle<WasmCompiledModule> compiled_module, | 
| 52     uint32_t offset, uint32_t size) { | 52     uint32_t offset, uint32_t size) { | 
| 53   // TODO(wasm): cache strings from modules if it's a performance win. | 53   // TODO(wasm): cache strings from modules if it's a performance win. | 
| 54   Handle<SeqOneByteString> module_bytes = compiled_module->module_bytes(); | 54   Handle<SeqOneByteString> module_bytes = compiled_module->module_bytes(); | 
| 55   DCHECK_GE(static_cast<size_t>(module_bytes->length()), offset); | 55   DCHECK_GE(module_bytes->length(), offset); | 
| 56   DCHECK_GE(static_cast<size_t>(module_bytes->length() - offset), size); | 56   DCHECK_GE(module_bytes->length() - offset, size); | 
| 57   Address raw = module_bytes->GetCharsAddress() + offset; | 57   Address raw = module_bytes->GetCharsAddress() + offset; | 
| 58   if (!unibrow::Utf8::Validate(reinterpret_cast<const byte*>(raw), size)) | 58   if (!unibrow::Utf8::Validate(reinterpret_cast<const byte*>(raw), size)) | 
| 59     return {};  // UTF8 decoding error for name. | 59     return {};  // UTF8 decoding error for name. | 
| 60   return isolate->factory()->NewStringFromUtf8SubString( | 60   return isolate->factory()->NewStringFromUtf8SubString( | 
| 61       module_bytes, static_cast<int>(offset), static_cast<int>(size)); | 61       module_bytes, static_cast<int>(offset), static_cast<int>(size)); | 
| 62 } | 62 } | 
| 63 | 63 | 
| 64 void ReplaceReferenceInCode(Handle<Code> code, Handle<Object> old_ref, | 64 void ReplaceReferenceInCode(Handle<Code> code, Handle<Object> old_ref, | 
| 65                             Handle<Object> new_ref) { | 65                             Handle<Object> new_ref) { | 
| 66   for (RelocIterator it(*code, 1 << RelocInfo::EMBEDDED_OBJECT); !it.done(); | 66   for (RelocIterator it(*code, 1 << RelocInfo::EMBEDDED_OBJECT); !it.done(); | 
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 103   // things that would be unsafe if they expected guard pages where there | 103   // things that would be unsafe if they expected guard pages where there | 
| 104   // weren't any. | 104   // weren't any. | 
| 105   if (enable_guard_regions && kGuardRegionsSupported) { | 105   if (enable_guard_regions && kGuardRegionsSupported) { | 
| 106     // TODO(eholk): On Windows we want to make sure we don't commit the guard | 106     // TODO(eholk): On Windows we want to make sure we don't commit the guard | 
| 107     // pages yet. | 107     // pages yet. | 
| 108 | 108 | 
| 109     // We always allocate the largest possible offset into the heap, so the | 109     // We always allocate the largest possible offset into the heap, so the | 
| 110     // addressable memory after the guard page can be made inaccessible. | 110     // addressable memory after the guard page can be made inaccessible. | 
| 111     const size_t alloc_size = | 111     const size_t alloc_size = | 
| 112         RoundUp(kWasmMaxHeapOffset, base::OS::CommitPageSize()); | 112         RoundUp(kWasmMaxHeapOffset, base::OS::CommitPageSize()); | 
| 113     DCHECK_EQ(0u, size % base::OS::CommitPageSize()); | 113     DCHECK_EQ(0, size % base::OS::CommitPageSize()); | 
| 114 | 114 | 
| 115     // AllocateGuarded makes the whole region inaccessible by default. | 115     // AllocateGuarded makes the whole region inaccessible by default. | 
| 116     void* memory = base::OS::AllocateGuarded(alloc_size); | 116     void* memory = base::OS::AllocateGuarded(alloc_size); | 
| 117     if (memory == nullptr) { | 117     if (memory == nullptr) { | 
| 118       return nullptr; | 118       return nullptr; | 
| 119     } | 119     } | 
| 120 | 120 | 
| 121     // Make the part we care about accessible. | 121     // Make the part we care about accessible. | 
| 122     base::OS::Unprotect(memory, size); | 122     base::OS::Unprotect(memory, size); | 
| 123 | 123 | 
| (...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 881         isolate, &module_env, wasm_code, exp.index); | 881         isolate, &module_env, wasm_code, exp.index); | 
| 882     int export_index = static_cast<int>(functions.size() + func_index); | 882     int export_index = static_cast<int>(functions.size() + func_index); | 
| 883     code_table->set(export_index, *wrapper_code); | 883     code_table->set(export_index, *wrapper_code); | 
| 884     func_index++; | 884     func_index++; | 
| 885   } | 885   } | 
| 886 | 886 | 
| 887   { | 887   { | 
| 888     // TODO(wasm): only save the sections necessary to deserialize a | 888     // TODO(wasm): only save the sections necessary to deserialize a | 
| 889     // {WasmModule}. E.g. function bodies could be omitted. | 889     // {WasmModule}. E.g. function bodies could be omitted. | 
| 890     size_t module_bytes_len = module_end - module_start; | 890     size_t module_bytes_len = module_end - module_start; | 
| 891     DCHECK_LE(module_bytes_len, static_cast<size_t>(kMaxInt)); | 891     DCHECK_LE(module_bytes_len, kMaxInt); | 
| 892     Vector<const uint8_t> module_bytes_vec(module_start, | 892     Vector<const uint8_t> module_bytes_vec(module_start, | 
| 893                                            static_cast<int>(module_bytes_len)); | 893                                            static_cast<int>(module_bytes_len)); | 
| 894     Handle<String> module_bytes_string = | 894     Handle<String> module_bytes_string = | 
| 895         factory->NewStringFromOneByte(module_bytes_vec, TENURED) | 895         factory->NewStringFromOneByte(module_bytes_vec, TENURED) | 
| 896             .ToHandleChecked(); | 896             .ToHandleChecked(); | 
| 897     DCHECK(module_bytes_string->IsSeqOneByteString()); | 897     DCHECK(module_bytes_string->IsSeqOneByteString()); | 
| 898     ret->set_module_bytes(Handle<SeqOneByteString>::cast(module_bytes_string)); | 898     ret->set_module_bytes(Handle<SeqOneByteString>::cast(module_bytes_string)); | 
| 899   } | 899   } | 
| 900 | 900 | 
| 901   return ret; | 901   return ret; | 
| (...skipping 1105 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2007 | 2007 | 
| 2008   DCHECK_EQ(origin == kAsmJsOrigin, !asm_js_script.is_null()); | 2008   DCHECK_EQ(origin == kAsmJsOrigin, !asm_js_script.is_null()); | 
| 2009   DCHECK(!compiled_module->has_script()); | 2009   DCHECK(!compiled_module->has_script()); | 
| 2010   DCHECK(!compiled_module->has_asm_js_offset_tables()); | 2010   DCHECK(!compiled_module->has_asm_js_offset_tables()); | 
| 2011   if (origin == kAsmJsOrigin) { | 2011   if (origin == kAsmJsOrigin) { | 
| 2012     // Set script for the asm.js source, and the offset table mapping wasm byte | 2012     // Set script for the asm.js source, and the offset table mapping wasm byte | 
| 2013     // offsets to source positions. | 2013     // offsets to source positions. | 
| 2014     compiled_module->set_script(asm_js_script); | 2014     compiled_module->set_script(asm_js_script); | 
| 2015     size_t offset_tables_len = | 2015     size_t offset_tables_len = | 
| 2016         asm_js_offset_tables_end - asm_js_offset_tables_start; | 2016         asm_js_offset_tables_end - asm_js_offset_tables_start; | 
| 2017     DCHECK_GE(static_cast<size_t>(kMaxInt), offset_tables_len); | 2017     DCHECK_GE(kMaxInt, offset_tables_len); | 
| 2018     Handle<ByteArray> offset_tables = | 2018     Handle<ByteArray> offset_tables = | 
| 2019         isolate->factory()->NewByteArray(static_cast<int>(offset_tables_len)); | 2019         isolate->factory()->NewByteArray(static_cast<int>(offset_tables_len)); | 
| 2020     memcpy(offset_tables->GetDataStartAddress(), asm_js_offset_tables_start, | 2020     memcpy(offset_tables->GetDataStartAddress(), asm_js_offset_tables_start, | 
| 2021            offset_tables_len); | 2021            offset_tables_len); | 
| 2022     compiled_module->set_asm_js_offset_tables(offset_tables); | 2022     compiled_module->set_asm_js_offset_tables(offset_tables); | 
| 2023   } else { | 2023   } else { | 
| 2024     // Create a new Script object representing this wasm module, store it in the | 2024     // Create a new Script object representing this wasm module, store it in the | 
| 2025     // compiled wasm module, and register it at the debugger. | 2025     // compiled wasm module, and register it at the debugger. | 
| 2026     Handle<Script> script = | 2026     Handle<Script> script = | 
| 2027         isolate->factory()->NewScript(isolate->factory()->empty_string()); | 2027         isolate->factory()->NewScript(isolate->factory()->empty_string()); | 
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2266 MaybeHandle<String> WasmCompiledModule::GetFunctionName( | 2266 MaybeHandle<String> WasmCompiledModule::GetFunctionName( | 
| 2267     Handle<WasmCompiledModule> compiled_module, uint32_t func_index) { | 2267     Handle<WasmCompiledModule> compiled_module, uint32_t func_index) { | 
| 2268   DCHECK_LT(func_index, compiled_module->module()->functions.size()); | 2268   DCHECK_LT(func_index, compiled_module->module()->functions.size()); | 
| 2269   WasmFunction& function = compiled_module->module()->functions[func_index]; | 2269   WasmFunction& function = compiled_module->module()->functions[func_index]; | 
| 2270   Isolate* isolate = compiled_module->GetIsolate(); | 2270   Isolate* isolate = compiled_module->GetIsolate(); | 
| 2271   MaybeHandle<String> string = ExtractStringFromModuleBytes( | 2271   MaybeHandle<String> string = ExtractStringFromModuleBytes( | 
| 2272       isolate, compiled_module, function.name_offset, function.name_length); | 2272       isolate, compiled_module, function.name_offset, function.name_length); | 
| 2273   if (!string.is_null()) return string.ToHandleChecked(); | 2273   if (!string.is_null()) return string.ToHandleChecked(); | 
| 2274   return {}; | 2274   return {}; | 
| 2275 } | 2275 } | 
| OLD | NEW | 
|---|