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

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

Issue 2526783002: [base] Define CHECK comparison for signed vs. unsigned (Closed)
Patch Set: Extend test case Created 4 years 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 // things that would be unsafe if they expected guard pages where there 104 // things that would be unsafe if they expected guard pages where there
105 // weren't any. 105 // weren't any.
106 if (enable_guard_regions && kGuardRegionsSupported) { 106 if (enable_guard_regions && kGuardRegionsSupported) {
107 // TODO(eholk): On Windows we want to make sure we don't commit the guard 107 // TODO(eholk): On Windows we want to make sure we don't commit the guard
108 // pages yet. 108 // pages yet.
109 109
110 // We always allocate the largest possible offset into the heap, so the 110 // We always allocate the largest possible offset into the heap, so the
111 // addressable memory after the guard page can be made inaccessible. 111 // addressable memory after the guard page can be made inaccessible.
112 const size_t alloc_size = 112 const size_t alloc_size =
113 RoundUp(kWasmMaxHeapOffset, base::OS::CommitPageSize()); 113 RoundUp(kWasmMaxHeapOffset, base::OS::CommitPageSize());
114 DCHECK_EQ(0u, size % base::OS::CommitPageSize()); 114 DCHECK_EQ(0, size % base::OS::CommitPageSize());
115 115
116 // AllocateGuarded makes the whole region inaccessible by default. 116 // AllocateGuarded makes the whole region inaccessible by default.
117 void* memory = base::OS::AllocateGuarded(alloc_size); 117 void* memory = base::OS::AllocateGuarded(alloc_size);
118 if (memory == nullptr) { 118 if (memory == nullptr) {
119 return nullptr; 119 return nullptr;
120 } 120 }
121 121
122 // Make the part we care about accessible. 122 // Make the part we care about accessible.
123 base::OS::Unprotect(memory, size); 123 base::OS::Unprotect(memory, size);
124 124
(...skipping 803 matching lines...) Expand 10 before | Expand all | Expand 10 after
928 isolate, &module_env, wasm_code, exp.index); 928 isolate, &module_env, wasm_code, exp.index);
929 int export_index = static_cast<int>(functions.size() + func_index); 929 int export_index = static_cast<int>(functions.size() + func_index);
930 code_table->set(export_index, *wrapper_code); 930 code_table->set(export_index, *wrapper_code);
931 func_index++; 931 func_index++;
932 } 932 }
933 933
934 { 934 {
935 // TODO(wasm): only save the sections necessary to deserialize a 935 // TODO(wasm): only save the sections necessary to deserialize a
936 // {WasmModule}. E.g. function bodies could be omitted. 936 // {WasmModule}. E.g. function bodies could be omitted.
937 size_t module_bytes_len = module_end - module_start; 937 size_t module_bytes_len = module_end - module_start;
938 DCHECK_LE(module_bytes_len, static_cast<size_t>(kMaxInt)); 938 DCHECK_LE(module_bytes_len, kMaxInt);
939 Vector<const uint8_t> module_bytes_vec(module_start, 939 Vector<const uint8_t> module_bytes_vec(module_start,
940 static_cast<int>(module_bytes_len)); 940 static_cast<int>(module_bytes_len));
941 Handle<String> module_bytes_string = 941 Handle<String> module_bytes_string =
942 factory->NewStringFromOneByte(module_bytes_vec, TENURED) 942 factory->NewStringFromOneByte(module_bytes_vec, TENURED)
943 .ToHandleChecked(); 943 .ToHandleChecked();
944 DCHECK(module_bytes_string->IsSeqOneByteString()); 944 DCHECK(module_bytes_string->IsSeqOneByteString());
945 ret->set_module_bytes(Handle<SeqOneByteString>::cast(module_bytes_string)); 945 ret->set_module_bytes(Handle<SeqOneByteString>::cast(module_bytes_string));
946 } 946 }
947 947
948 return ret; 948 return ret;
(...skipping 1412 matching lines...) Expand 10 before | Expand all | Expand 10 after
2361 MaybeHandle<String> WasmCompiledModule::GetFunctionName( 2361 MaybeHandle<String> WasmCompiledModule::GetFunctionName(
2362 Handle<WasmCompiledModule> compiled_module, uint32_t func_index) { 2362 Handle<WasmCompiledModule> compiled_module, uint32_t func_index) {
2363 DCHECK_LT(func_index, compiled_module->module()->functions.size()); 2363 DCHECK_LT(func_index, compiled_module->module()->functions.size());
2364 WasmFunction& function = compiled_module->module()->functions[func_index]; 2364 WasmFunction& function = compiled_module->module()->functions[func_index];
2365 Isolate* isolate = compiled_module->GetIsolate(); 2365 Isolate* isolate = compiled_module->GetIsolate();
2366 MaybeHandle<String> string = ExtractStringFromModuleBytes( 2366 MaybeHandle<String> string = ExtractStringFromModuleBytes(
2367 isolate, compiled_module, function.name_offset, function.name_length); 2367 isolate, compiled_module, function.name_offset, function.name_length);
2368 if (!string.is_null()) return string.ToHandleChecked(); 2368 if (!string.is_null()) return string.ToHandleChecked();
2369 return {}; 2369 return {};
2370 } 2370 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698