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

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

Issue 2396433008: [wasm] Add guard regions to end of WebAssembly.Memory buffers (Closed)
Patch Set: Cleanup Created 4 years, 1 month 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 "src/api-natives.h" 5 #include "src/api-natives.h"
6 #include "src/api.h" 6 #include "src/api.h"
7 #include "src/asmjs/asm-js.h" 7 #include "src/asmjs/asm-js.h"
8 #include "src/asmjs/asm-typer.h" 8 #include "src/asmjs/asm-typer.h"
9 #include "src/asmjs/asm-wasm-builder.h" 9 #include "src/asmjs/asm-wasm-builder.h"
10 #include "src/assert-scope.h" 10 #include "src/assert-scope.h"
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 i::Handle<i::JSObject> i_obj = 323 i::Handle<i::JSObject> i_obj =
324 i::Handle<i::JSObject>::cast(v8::Utils::OpenHandle(*obj)); 324 i::Handle<i::JSObject>::cast(v8::Utils::OpenHandle(*obj));
325 325
326 i::Handle<i::JSReceiver> ffi = i::Handle<i::JSObject>::null(); 326 i::Handle<i::JSReceiver> ffi = i::Handle<i::JSObject>::null();
327 if (args.Length() > 1 && args[1]->IsObject()) { 327 if (args.Length() > 1 && args[1]->IsObject()) {
328 Local<Object> obj = Local<Object>::Cast(args[1]); 328 Local<Object> obj = Local<Object>::Cast(args[1]);
329 ffi = i::Handle<i::JSReceiver>::cast(v8::Utils::OpenHandle(*obj)); 329 ffi = i::Handle<i::JSReceiver>::cast(v8::Utils::OpenHandle(*obj));
330 } 330 }
331 331
332 i::Handle<i::JSArrayBuffer> memory = i::Handle<i::JSArrayBuffer>::null(); 332 i::Handle<i::JSArrayBuffer> memory = i::Handle<i::JSArrayBuffer>::null();
333 if (args.Length() > 2 && args[2]->IsArrayBuffer()) { 333 if (args.Length() > 2 && args[2]->IsObject()) {
334 Local<Object> obj = Local<Object>::Cast(args[2]); 334 Local<Object> obj = Local<Object>::Cast(args[2]);
335 i::Handle<i::Object> mem_obj = v8::Utils::OpenHandle(*obj); 335 i::Handle<i::Object> mem_obj = v8::Utils::OpenHandle(*obj);
336 memory = i::Handle<i::JSArrayBuffer>(i::JSArrayBuffer::cast(*mem_obj)); 336 if (i::WasmJs::IsWasmMemoryObject(i_isolate, mem_obj)) {
337 memory = i::WasmJs::GetWasmMemoryArrayBuffer(i_isolate, mem_obj);
338 }
337 } 339 }
338 i::MaybeHandle<i::JSObject> instance = 340 i::MaybeHandle<i::JSObject> instance =
339 i::wasm::WasmModule::Instantiate(i_isolate, &thrower, i_obj, ffi, memory); 341 i::wasm::WasmModule::Instantiate(i_isolate, &thrower, i_obj, ffi, memory);
340 if (instance.is_null()) { 342 if (instance.is_null()) {
341 if (!thrower.error()) thrower.RuntimeError("Could not instantiate module"); 343 if (!thrower.error()) thrower.RuntimeError("Could not instantiate module");
342 return; 344 return;
343 } 345 }
344 DCHECK(!i_isolate->has_pending_exception()); 346 DCHECK(!i_isolate->has_pending_exception());
345 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); 347 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue();
346 return_value.Set(Utils::ToLocal(instance.ToHandleChecked())); 348 return_value.Set(Utils::ToLocal(instance.ToHandleChecked()));
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 // There has been an exception, just return. 460 // There has been an exception, just return.
459 return; 461 return;
460 } 462 }
461 if (has_maximum.FromJust()) { 463 if (has_maximum.FromJust()) {
462 if (!GetIntegerProperty(isolate, &thrower, context, descriptor, maximum_key, 464 if (!GetIntegerProperty(isolate, &thrower, context, descriptor, maximum_key,
463 &maximum, initial, 65536)) { 465 &maximum, initial, 65536)) {
464 return; 466 return;
465 } 467 }
466 } 468 }
467 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 469 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
468 i::Handle<i::JSArrayBuffer> buffer =
469 i_isolate->factory()->NewJSArrayBuffer(i::SharedFlag::kNotShared);
470 size_t size = static_cast<size_t>(i::wasm::WasmModule::kPageSize) * 470 size_t size = static_cast<size_t>(i::wasm::WasmModule::kPageSize) *
471 static_cast<size_t>(initial); 471 static_cast<size_t>(initial);
472 i::JSArrayBuffer::SetupAllocatingData(buffer, i_isolate, size); 472 i::Handle<i::JSArrayBuffer> buffer =
473 i::wasm::NewArrayBuffer(i_isolate, size, i::FLAG_wasm_guard_pages);
473 474
474 i::Handle<i::JSObject> memory_obj = i::WasmJs::CreateWasmMemoryObject( 475 i::Handle<i::JSObject> memory_obj = i::WasmJs::CreateWasmMemoryObject(
475 i_isolate, buffer, has_maximum.FromJust(), maximum); 476 i_isolate, buffer, has_maximum.FromJust(), maximum);
476 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); 477 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue();
477 return_value.Set(Utils::ToLocal(memory_obj)); 478 return_value.Set(Utils::ToLocal(memory_obj));
478 } 479 }
479 480
480 void WebAssemblyTableGetLength( 481 void WebAssemblyTableGetLength(
481 const v8::FunctionCallbackInfo<v8::Value>& args) { 482 const v8::FunctionCallbackInfo<v8::Value>& args) {
482 v8::Isolate* isolate = args.GetIsolate(); 483 v8::Isolate* isolate = args.GetIsolate();
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
987 if (!memory_object->IsUndefined(isolate)) { 988 if (!memory_object->IsUndefined(isolate)) {
988 DCHECK(IsWasmMemoryObject(isolate, memory_object)); 989 DCHECK(IsWasmMemoryObject(isolate, memory_object));
989 // TODO(gdeepti): This should be a weak list of instance objects 990 // TODO(gdeepti): This should be a weak list of instance objects
990 // for instances that share memory. 991 // for instances that share memory.
991 JSObject::cast(*memory_object) 992 JSObject::cast(*memory_object)
992 ->SetInternalField(kWasmMemoryInstanceObject, *instance); 993 ->SetInternalField(kWasmMemoryInstanceObject, *instance);
993 } 994 }
994 } 995 }
995 } // namespace internal 996 } // namespace internal
996 } // namespace v8 997 } // namespace v8
OLDNEW
« src/objects-inl.h ('K') | « src/objects-inl.h ('k') | src/wasm/wasm-module.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698