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

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

Issue 2319983002: [wasm] GrowMemory should use array_buffer_allocator instead of realloc. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Review changes Created 4 years, 3 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 | « no previous file | 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 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 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/runtime/runtime-utils.h" 5 #include "src/runtime/runtime-utils.h"
6 6
7 #include "src/arguments.h" 7 #include "src/arguments.h"
8 #include "src/assembler.h" 8 #include "src/assembler.h"
9 #include "src/compiler/wasm-compiler.h" 9 #include "src/compiler/wasm-compiler.h"
10 #include "src/conversions.h" 10 #include "src/conversions.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 // If the old memory was zero-sized, we should have been in the 79 // If the old memory was zero-sized, we should have been in the
80 // "undefined" case above. 80 // "undefined" case above.
81 DCHECK_NOT_NULL(old_mem_start); 81 DCHECK_NOT_NULL(old_mem_start);
82 DCHECK_NE(0, old_size); 82 DCHECK_NE(0, old_size);
83 83
84 new_size = old_size + delta_pages * wasm::WasmModule::kPageSize; 84 new_size = old_size + delta_pages * wasm::WasmModule::kPageSize;
85 if (new_size > 85 if (new_size >
86 wasm::WasmModule::kMaxMemPages * wasm::WasmModule::kPageSize) { 86 wasm::WasmModule::kMaxMemPages * wasm::WasmModule::kPageSize) {
87 return *isolate->factory()->NewNumberFromInt(-1); 87 return *isolate->factory()->NewNumberFromInt(-1);
88 } 88 }
89 new_mem_start = static_cast<Address>(realloc(old_mem_start, new_size)); 89 new_mem_start =
90 static_cast<Address>(isolate->array_buffer_allocator()->Allocate(
91 static_cast<uint32_t>(new_size)));
90 if (new_mem_start == NULL) { 92 if (new_mem_start == NULL) {
91 return *isolate->factory()->NewNumberFromInt(-1); 93 return *isolate->factory()->NewNumberFromInt(-1);
92 } 94 }
93 old_buffer->set_is_external(true); 95 #if DEBUG
94 isolate->heap()->UnregisterArrayBuffer(*old_buffer); 96 // Double check the API allocator actually zero-initialized the memory.
95 // Zero initializing uninitialized memory from realloc 97 for (size_t i = old_size; i < new_size; i++) {
96 memset(new_mem_start + old_size, 0, new_size - old_size); 98 DCHECK_EQ(0, new_mem_start[i]);
99 }
100 #endif
101 // Copy contents of the old buffer to the new buffer
102 memcpy(new_mem_start, old_mem_start, old_size);
97 } 103 }
98 104
99 Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer(); 105 Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer();
100 JSArrayBuffer::Setup(buffer, isolate, false, new_mem_start, new_size); 106 JSArrayBuffer::Setup(buffer, isolate, false, new_mem_start, new_size);
101 buffer->set_is_neuterable(false); 107 buffer->set_is_neuterable(false);
102 108
103 // Set new buffer to be wasm memory 109 // Set new buffer to be wasm memory
104 module_object->SetInternalField(kWasmMemArrayBuffer, *buffer); 110 module_object->SetInternalField(kWasmMemArrayBuffer, *buffer);
105
106 CHECK(wasm::UpdateWasmModuleMemory(module_object, old_mem_start, 111 CHECK(wasm::UpdateWasmModuleMemory(module_object, old_mem_start,
107 new_mem_start, old_size, new_size)); 112 new_mem_start, old_size, new_size));
108 113
109 return *isolate->factory()->NewNumberFromInt(old_size / 114 return *isolate->factory()->NewNumberFromInt(old_size /
110 wasm::WasmModule::kPageSize); 115 wasm::WasmModule::kPageSize);
111 } 116 }
112 117
113 RUNTIME_FUNCTION(Runtime_WasmThrowTypeError) { 118 RUNTIME_FUNCTION(Runtime_WasmThrowTypeError) {
114 HandleScope scope(isolate); 119 HandleScope scope(isolate);
115 DCHECK_EQ(0, args.length()); 120 DCHECK_EQ(0, args.length());
116 THROW_NEW_ERROR_RETURN_FAILURE( 121 THROW_NEW_ERROR_RETURN_FAILURE(
117 isolate, NewTypeError(MessageTemplate::kWasmTrapTypeError)); 122 isolate, NewTypeError(MessageTemplate::kWasmTrapTypeError));
118 } 123 }
119 } // namespace internal 124 } // namespace internal
120 } // namespace v8 125 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/wasm/grow-memory.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698