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

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

Issue 2636173002: [wasm] Enforce memory and table limits during instantiation. (Closed)
Patch Set: [wasm] Enforce memory and table limits during instantiation. Created 3 years, 11 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-objects.h ('k') | test/mjsunit/wasm/compiled-module-serialization.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 "src/wasm/wasm-objects.h" 5 #include "src/wasm/wasm-objects.h"
6 #include "src/utils.h" 6 #include "src/utils.h"
7 7
8 #include "src/debug/debug-interface.h" 8 #include "src/debug/debug-interface.h"
9 #include "src/wasm/module-decoder.h" 9 #include "src/wasm/module-decoder.h"
10 #include "src/wasm/wasm-module.h" 10 #include "src/wasm/wasm-module.h"
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 115
116 bool WasmModuleObject::IsWasmModuleObject(Object* object) { 116 bool WasmModuleObject::IsWasmModuleObject(Object* object) {
117 return object->IsJSObject() && 117 return object->IsJSObject() &&
118 JSObject::cast(object)->GetInternalFieldCount() == kFieldCount; 118 JSObject::cast(object)->GetInternalFieldCount() == kFieldCount;
119 } 119 }
120 120
121 DEFINE_OBJ_GETTER(WasmModuleObject, compiled_module, kCompiledModule, 121 DEFINE_OBJ_GETTER(WasmModuleObject, compiled_module, kCompiledModule,
122 WasmCompiledModule) 122 WasmCompiledModule)
123 123
124 Handle<WasmTableObject> WasmTableObject::New(Isolate* isolate, uint32_t initial, 124 Handle<WasmTableObject> WasmTableObject::New(Isolate* isolate, uint32_t initial,
125 uint32_t maximum, 125 int64_t maximum,
126 Handle<FixedArray>* js_functions) { 126 Handle<FixedArray>* js_functions) {
127 Handle<JSFunction> table_ctor( 127 Handle<JSFunction> table_ctor(
128 isolate->native_context()->wasm_table_constructor()); 128 isolate->native_context()->wasm_table_constructor());
129 Handle<JSObject> table_obj = isolate->factory()->NewJSObject(table_ctor); 129 Handle<JSObject> table_obj = isolate->factory()->NewJSObject(table_ctor);
130 *js_functions = isolate->factory()->NewFixedArray(initial); 130 *js_functions = isolate->factory()->NewFixedArray(initial);
131 Object* null = isolate->heap()->null_value(); 131 Object* null = isolate->heap()->null_value();
132 for (int i = 0; i < static_cast<int>(initial); ++i) { 132 for (int i = 0; i < static_cast<int>(initial); ++i) {
133 (*js_functions)->set(i, null); 133 (*js_functions)->set(i, null);
134 } 134 }
135 table_obj->SetInternalField(kFunctions, *(*js_functions)); 135 table_obj->SetInternalField(kFunctions, *(*js_functions));
136 table_obj->SetInternalField(kMaximum, 136 Handle<Object> max = isolate->factory()->NewNumber(maximum);
137 static_cast<Object*>(Smi::FromInt(maximum))); 137 table_obj->SetInternalField(kMaximum, *max);
138 138
139 Handle<FixedArray> dispatch_tables = isolate->factory()->NewFixedArray(0); 139 Handle<FixedArray> dispatch_tables = isolate->factory()->NewFixedArray(0);
140 table_obj->SetInternalField(kDispatchTables, *dispatch_tables); 140 table_obj->SetInternalField(kDispatchTables, *dispatch_tables);
141 Handle<Symbol> table_sym(isolate->native_context()->wasm_table_sym()); 141 Handle<Symbol> table_sym(isolate->native_context()->wasm_table_sym());
142 Object::SetProperty(table_obj, table_sym, table_obj, STRICT).Check(); 142 Object::SetProperty(table_obj, table_sym, table_obj, STRICT).Check();
143 return Handle<WasmTableObject>::cast(table_obj); 143 return Handle<WasmTableObject>::cast(table_obj);
144 } 144 }
145 145
146 DEFINE_OBJ_GETTER(WasmTableObject, dispatch_tables, kDispatchTables, FixedArray) 146 DEFINE_OBJ_GETTER(WasmTableObject, dispatch_tables, kDispatchTables, FixedArray)
147 147
(...skipping 21 matching lines...) Expand all
169 table_obj->SetInternalField(WasmTableObject::kDispatchTables, 169 table_obj->SetInternalField(WasmTableObject::kDispatchTables,
170 *new_dispatch_tables); 170 *new_dispatch_tables);
171 171
172 return new_dispatch_tables; 172 return new_dispatch_tables;
173 } 173 }
174 174
175 DEFINE_OBJ_ACCESSORS(WasmTableObject, functions, kFunctions, FixedArray) 175 DEFINE_OBJ_ACCESSORS(WasmTableObject, functions, kFunctions, FixedArray)
176 176
177 uint32_t WasmTableObject::current_length() { return functions()->length(); } 177 uint32_t WasmTableObject::current_length() { return functions()->length(); }
178 178
179 uint32_t WasmTableObject::maximum_length() { 179 bool WasmTableObject::has_maximum_length() {
180 return SafeUint32(GetInternalField(kMaximum)); 180 return GetInternalField(kMaximum)->Number() >= 0;
181 }
182
183 int64_t WasmTableObject::maximum_length() {
184 return static_cast<int64_t>(GetInternalField(kMaximum)->Number());
181 } 185 }
182 186
183 WasmTableObject* WasmTableObject::cast(Object* object) { 187 WasmTableObject* WasmTableObject::cast(Object* object) {
184 DCHECK(object && object->IsJSObject()); 188 DCHECK(object && object->IsJSObject());
185 // TODO(titzer): brand check for WasmTableObject. 189 // TODO(titzer): brand check for WasmTableObject.
186 return reinterpret_cast<WasmTableObject*>(object); 190 return reinterpret_cast<WasmTableObject*>(object);
187 } 191 }
188 192
189 void WasmTableObject::Grow(Isolate* isolate, Handle<WasmTableObject> table, 193 void WasmTableObject::Grow(Isolate* isolate, Handle<WasmTableObject> table,
190 uint32_t count) { 194 uint32_t count) {
191 Handle<FixedArray> dispatch_tables(table->dispatch_tables()); 195 Handle<FixedArray> dispatch_tables(table->dispatch_tables());
192 wasm::GrowDispatchTables(isolate, dispatch_tables, 196 wasm::GrowDispatchTables(isolate, dispatch_tables,
193 table->functions()->length(), count); 197 table->functions()->length(), count);
194 } 198 }
195 199
196 Handle<WasmMemoryObject> WasmMemoryObject::New(Isolate* isolate, 200 Handle<WasmMemoryObject> WasmMemoryObject::New(Isolate* isolate,
197 Handle<JSArrayBuffer> buffer, 201 Handle<JSArrayBuffer> buffer,
198 int maximum) { 202 int32_t maximum) {
199 Handle<JSFunction> memory_ctor( 203 Handle<JSFunction> memory_ctor(
200 isolate->native_context()->wasm_memory_constructor()); 204 isolate->native_context()->wasm_memory_constructor());
201 Handle<JSObject> memory_obj = 205 Handle<JSObject> memory_obj =
202 isolate->factory()->NewJSObject(memory_ctor, TENURED); 206 isolate->factory()->NewJSObject(memory_ctor, TENURED);
203 memory_obj->SetInternalField(kArrayBuffer, *buffer); 207 memory_obj->SetInternalField(kArrayBuffer, *buffer);
204 memory_obj->SetInternalField(kMaximum, 208 Handle<Object> max = isolate->factory()->NewNumber(maximum);
205 static_cast<Object*>(Smi::FromInt(maximum))); 209 memory_obj->SetInternalField(kMaximum, *max);
206 Handle<Symbol> memory_sym(isolate->native_context()->wasm_memory_sym()); 210 Handle<Symbol> memory_sym(isolate->native_context()->wasm_memory_sym());
207 Object::SetProperty(memory_obj, memory_sym, memory_obj, STRICT).Check(); 211 Object::SetProperty(memory_obj, memory_sym, memory_obj, STRICT).Check();
208 return Handle<WasmMemoryObject>::cast(memory_obj); 212 return Handle<WasmMemoryObject>::cast(memory_obj);
209 } 213 }
210 214
211 DEFINE_OBJ_ACCESSORS(WasmMemoryObject, buffer, kArrayBuffer, JSArrayBuffer) 215 DEFINE_OBJ_ACCESSORS(WasmMemoryObject, buffer, kArrayBuffer, JSArrayBuffer)
212 DEFINE_OPTIONAL_OBJ_ACCESSORS(WasmMemoryObject, instances_link, kInstancesLink, 216 DEFINE_OPTIONAL_OBJ_ACCESSORS(WasmMemoryObject, instances_link, kInstancesLink,
213 WasmInstanceWrapper) 217 WasmInstanceWrapper)
214 218
215 uint32_t WasmMemoryObject::current_pages() { 219 uint32_t WasmMemoryObject::current_pages() {
216 return SafeUint32(buffer()->byte_length()) / wasm::WasmModule::kPageSize; 220 return SafeUint32(buffer()->byte_length()) / wasm::WasmModule::kPageSize;
217 } 221 }
218 222
223 bool WasmMemoryObject::has_maximum_pages() {
224 return GetInternalField(kMaximum)->Number() >= 0;
225 }
226
219 int32_t WasmMemoryObject::maximum_pages() { 227 int32_t WasmMemoryObject::maximum_pages() {
220 return SafeInt32(GetInternalField(kMaximum)); 228 return static_cast<int32_t>(GetInternalField(kMaximum)->Number());
221 } 229 }
222 230
223 WasmMemoryObject* WasmMemoryObject::cast(Object* object) { 231 WasmMemoryObject* WasmMemoryObject::cast(Object* object) {
224 DCHECK(object && object->IsJSObject()); 232 DCHECK(object && object->IsJSObject());
225 // TODO(titzer): brand check for WasmMemoryObject. 233 // TODO(titzer): brand check for WasmMemoryObject.
226 return reinterpret_cast<WasmMemoryObject*>(object); 234 return reinterpret_cast<WasmMemoryObject*>(object);
227 } 235 }
228 236
229 void WasmMemoryObject::AddInstance(Isolate* isolate, 237 void WasmMemoryObject::AddInstance(Isolate* isolate,
230 Handle<WasmInstanceObject> instance) { 238 Handle<WasmInstanceObject> instance) {
(...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 !array->get(kPreviousInstanceWrapper)->IsFixedArray()) 855 !array->get(kPreviousInstanceWrapper)->IsFixedArray())
848 return false; 856 return false;
849 return true; 857 return true;
850 } 858 }
851 859
852 void WasmInstanceWrapper::set_instance_object(Handle<JSObject> instance, 860 void WasmInstanceWrapper::set_instance_object(Handle<JSObject> instance,
853 Isolate* isolate) { 861 Isolate* isolate) {
854 Handle<WeakCell> cell = isolate->factory()->NewWeakCell(instance); 862 Handle<WeakCell> cell = isolate->factory()->NewWeakCell(instance);
855 set(kWrapperInstanceObject, *cell); 863 set(kWrapperInstanceObject, *cell);
856 } 864 }
OLDNEW
« no previous file with comments | « src/wasm/wasm-objects.h ('k') | test/mjsunit/wasm/compiled-module-serialization.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698