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

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

Issue 2416543002: [wasm] Fix bounds check for zero initial memory. (Closed)
Patch Set: Fix bot failure Created 4 years, 2 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/wasm/wasm-module.h ('k') | test/mjsunit/wasm/grow-memory.js » ('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 #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 2038 matching lines...) Expand 10 before | Expand all | Expand 10 after
2049 Handle<WasmDebugInfo> wasm::GetDebugInfo(Handle<JSObject> wasm) { 2049 Handle<WasmDebugInfo> wasm::GetDebugInfo(Handle<JSObject> wasm) {
2050 Handle<Object> info(wasm->GetInternalField(kWasmDebugInfo), 2050 Handle<Object> info(wasm->GetInternalField(kWasmDebugInfo),
2051 wasm->GetIsolate()); 2051 wasm->GetIsolate());
2052 if (!info->IsUndefined(wasm->GetIsolate())) 2052 if (!info->IsUndefined(wasm->GetIsolate()))
2053 return Handle<WasmDebugInfo>::cast(info); 2053 return Handle<WasmDebugInfo>::cast(info);
2054 Handle<WasmDebugInfo> new_info = WasmDebugInfo::New(wasm); 2054 Handle<WasmDebugInfo> new_info = WasmDebugInfo::New(wasm);
2055 wasm->SetInternalField(kWasmDebugInfo, *new_info); 2055 wasm->SetInternalField(kWasmDebugInfo, *new_info);
2056 return new_info; 2056 return new_info;
2057 } 2057 }
2058 2058
2059 bool wasm::UpdateWasmModuleMemory(Handle<JSObject> object, Address old_start,
2060 Address new_start, uint32_t old_size,
2061 uint32_t new_size) {
2062 DisallowHeapAllocation no_allocation;
2063 if (!IsWasmObject(*object)) {
2064 return false;
2065 }
2066
2067 // Get code table associated with the module js_object
2068 Object* obj = object->GetInternalField(kWasmModuleCodeTable);
2069 Handle<FixedArray> code_table(FixedArray::cast(obj));
2070
2071 // Iterate through the code objects in the code table and update relocation
2072 // information
2073 for (int i = 0; i < code_table->length(); ++i) {
2074 obj = code_table->get(i);
2075 Handle<Code> code(Code::cast(obj));
2076
2077 int mode_mask = RelocInfo::ModeMask(RelocInfo::WASM_MEMORY_REFERENCE) |
2078 RelocInfo::ModeMask(RelocInfo::WASM_MEMORY_SIZE_REFERENCE);
2079 for (RelocIterator it(*code, mode_mask); !it.done(); it.next()) {
2080 RelocInfo::Mode mode = it.rinfo()->rmode();
2081 if (RelocInfo::IsWasmMemoryReference(mode) ||
2082 RelocInfo::IsWasmMemorySizeReference(mode)) {
2083 it.rinfo()->update_wasm_memory_reference(old_start, new_start, old_size,
2084 new_size);
2085 }
2086 }
2087 }
2088 return true;
2089 }
2090
2091 Handle<FixedArray> wasm::BuildFunctionTable(Isolate* isolate, uint32_t index, 2059 Handle<FixedArray> wasm::BuildFunctionTable(Isolate* isolate, uint32_t index,
2092 const WasmModule* module) { 2060 const WasmModule* module) {
2093 const WasmIndirectFunctionTable* table = &module->function_tables[index]; 2061 const WasmIndirectFunctionTable* table = &module->function_tables[index];
2094 DCHECK_EQ(table->size, table->values.size()); 2062 DCHECK_EQ(table->size, table->values.size());
2095 DCHECK_GE(table->max_size, table->size); 2063 DCHECK_GE(table->max_size, table->size);
2096 Handle<FixedArray> values = 2064 Handle<FixedArray> values =
2097 isolate->factory()->NewFixedArray(2 * table->max_size, TENURED); 2065 isolate->factory()->NewFixedArray(2 * table->max_size, TENURED);
2098 for (uint32_t i = 0; i < table->size; ++i) { 2066 for (uint32_t i = 0; i < table->size; ++i) {
2099 const WasmFunction* function = &module->functions[table->values[i]]; 2067 const WasmFunction* function = &module->functions[table->values[i]];
2100 int32_t index = table->map.Find(function->sig); 2068 int32_t index = table->map.Find(function->sig);
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
2232 Handle<JSArrayBuffer> buffer; 2200 Handle<JSArrayBuffer> buffer;
2233 if (!maybe_mem_buffer.ToHandle(&buffer)) { 2201 if (!maybe_mem_buffer.ToHandle(&buffer)) {
2234 return 0; 2202 return 0;
2235 } else { 2203 } else {
2236 return buffer->byte_length()->Number() / WasmModule::kPageSize; 2204 return buffer->byte_length()->Number() / WasmModule::kPageSize;
2237 } 2205 }
2238 } 2206 }
2239 2207
2240 int32_t wasm::GrowInstanceMemory(Isolate* isolate, Handle<JSObject> instance, 2208 int32_t wasm::GrowInstanceMemory(Isolate* isolate, Handle<JSObject> instance,
2241 uint32_t pages) { 2209 uint32_t pages) {
2242 if (pages == 0) { 2210 if (!IsWasmObject(*instance)) return false;
2243 return GetInstanceMemorySize(isolate, instance); 2211 if (pages == 0) return GetInstanceMemorySize(isolate, instance);
2244 } 2212
2245 Address old_mem_start = nullptr; 2213 Address old_mem_start = nullptr;
2246 uint32_t old_size = 0, new_size = 0; 2214 uint32_t old_size = 0, new_size = 0;
2247 2215
2248 MaybeHandle<JSArrayBuffer> maybe_mem_buffer = 2216 MaybeHandle<JSArrayBuffer> maybe_mem_buffer =
2249 GetInstanceMemory(isolate, instance); 2217 GetInstanceMemory(isolate, instance);
2250 Handle<JSArrayBuffer> old_buffer; 2218 Handle<JSArrayBuffer> old_buffer;
2251 if (!maybe_mem_buffer.ToHandle(&old_buffer)) { 2219 if (!maybe_mem_buffer.ToHandle(&old_buffer)) {
2252 // If module object does not have linear memory associated with it, 2220 // If module object does not have linear memory associated with it,
2253 // Allocate new array buffer of given size. 2221 // Allocate new array buffer of given size.
2254 // TODO(gdeepti): Fix bounds check to take into account size of memtype. 2222 // TODO(gdeepti): Fix bounds check to take into account size of memtype.
(...skipping 16 matching lines...) Expand all
2271 WasmModule::kMaxMemPages * WasmModule::kPageSize <= new_size) { 2239 WasmModule::kMaxMemPages * WasmModule::kPageSize <= new_size) {
2272 return -1; 2240 return -1;
2273 } 2241 }
2274 Handle<JSArrayBuffer> buffer = NewArrayBuffer(isolate, new_size); 2242 Handle<JSArrayBuffer> buffer = NewArrayBuffer(isolate, new_size);
2275 if (buffer.is_null()) return -1; 2243 if (buffer.is_null()) return -1;
2276 Address new_mem_start = static_cast<Address>(buffer->backing_store()); 2244 Address new_mem_start = static_cast<Address>(buffer->backing_store());
2277 if (old_size != 0) { 2245 if (old_size != 0) {
2278 memcpy(new_mem_start, old_mem_start, old_size); 2246 memcpy(new_mem_start, old_mem_start, old_size);
2279 } 2247 }
2280 SetInstanceMemory(instance, *buffer); 2248 SetInstanceMemory(instance, *buffer);
2281 if (!UpdateWasmModuleMemory(instance, old_mem_start, new_mem_start, old_size, 2249 RelocateInstanceCode(instance, old_mem_start, new_mem_start, old_size,
2282 new_size)) { 2250 new_size);
2283 return -1;
2284 }
2285 DCHECK(old_size % WasmModule::kPageSize == 0); 2251 DCHECK(old_size % WasmModule::kPageSize == 0);
2286 return (old_size / WasmModule::kPageSize); 2252 return (old_size / WasmModule::kPageSize);
2287 } 2253 }
2288 2254
2289 void testing::ValidateInstancesChain(Isolate* isolate, 2255 void testing::ValidateInstancesChain(Isolate* isolate,
2290 Handle<JSObject> module_obj, 2256 Handle<JSObject> module_obj,
2291 int instance_count) { 2257 int instance_count) {
2292 CHECK_GE(instance_count, 0); 2258 CHECK_GE(instance_count, 0);
2293 DisallowHeapAllocation no_gc; 2259 DisallowHeapAllocation no_gc;
2294 WasmCompiledModule* compiled_module = 2260 WasmCompiledModule* compiled_module =
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2328 } 2294 }
2329 2295
2330 void testing::ValidateOrphanedInstance(Isolate* isolate, 2296 void testing::ValidateOrphanedInstance(Isolate* isolate,
2331 Handle<JSObject> instance) { 2297 Handle<JSObject> instance) {
2332 DisallowHeapAllocation no_gc; 2298 DisallowHeapAllocation no_gc;
2333 CHECK(IsWasmObject(*instance)); 2299 CHECK(IsWasmObject(*instance));
2334 WasmCompiledModule* compiled_module = GetCompiledModule(*instance); 2300 WasmCompiledModule* compiled_module = GetCompiledModule(*instance);
2335 CHECK(compiled_module->has_weak_module_object()); 2301 CHECK(compiled_module->has_weak_module_object());
2336 CHECK(compiled_module->ptr_to_weak_module_object()->cleared()); 2302 CHECK(compiled_module->ptr_to_weak_module_object()->cleared());
2337 } 2303 }
OLDNEW
« no previous file with comments | « src/wasm/wasm-module.h ('k') | test/mjsunit/wasm/grow-memory.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698