Commit 269983f3 authored by Andreas Haas's avatar Andreas Haas Committed by Commit Bot

[wasm] Add a field for the Wrapper Tracer to WebAssembly API objects.

Issue 6051 description: "Blink blindly assumes that it can get an
aligned pointer from the 0-th internal field of any object that has two
internal fields."

R=titzer@chromium.org, jochen@chromium.org

BUG=v8:6051

Change-Id: I814b76e508ffd9fe2326bd0e728129f2a013b807
Reviewed-on: https://chromium-review.googlesource.com/451319Reviewed-by: 's avatarJochen Eisinger <jochen@chromium.org>
Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#43653}
parent 5f00d289
...@@ -362,6 +362,7 @@ Handle<WasmDebugInfo> WasmDebugInfo::New(Handle<WasmInstanceObject> instance) { ...@@ -362,6 +362,7 @@ Handle<WasmDebugInfo> WasmDebugInfo::New(Handle<WasmInstanceObject> instance) {
Isolate* isolate = instance->GetIsolate(); Isolate* isolate = instance->GetIsolate();
Factory* factory = isolate->factory(); Factory* factory = isolate->factory();
Handle<FixedArray> arr = factory->NewFixedArray(kFieldCount, TENURED); Handle<FixedArray> arr = factory->NewFixedArray(kFieldCount, TENURED);
arr->set(kWrapperTracerHeader, Smi::kZero);
arr->set(kInstance, *instance); arr->set(kInstance, *instance);
return Handle<WasmDebugInfo>::cast(arr); return Handle<WasmDebugInfo>::cast(arr);
} }
......
...@@ -263,6 +263,8 @@ Handle<WasmTableObject> WasmTableObject::New(Isolate* isolate, uint32_t initial, ...@@ -263,6 +263,8 @@ Handle<WasmTableObject> WasmTableObject::New(Isolate* isolate, uint32_t initial,
Handle<JSFunction> table_ctor( Handle<JSFunction> table_ctor(
isolate->native_context()->wasm_table_constructor()); isolate->native_context()->wasm_table_constructor());
Handle<JSObject> table_obj = isolate->factory()->NewJSObject(table_ctor); Handle<JSObject> table_obj = isolate->factory()->NewJSObject(table_ctor);
table_obj->SetInternalField(kWrapperTracerHeader, Smi::kZero);
*js_functions = isolate->factory()->NewFixedArray(initial); *js_functions = isolate->factory()->NewFixedArray(initial);
Object* null = isolate->heap()->null_value(); Object* null = isolate->heap()->null_value();
for (int i = 0; i < static_cast<int>(initial); ++i) { for (int i = 0; i < static_cast<int>(initial); ++i) {
...@@ -340,6 +342,8 @@ Handle<WasmMemoryObject> WasmMemoryObject::New(Isolate* isolate, ...@@ -340,6 +342,8 @@ Handle<WasmMemoryObject> WasmMemoryObject::New(Isolate* isolate,
isolate->native_context()->wasm_memory_constructor()); isolate->native_context()->wasm_memory_constructor());
Handle<JSObject> memory_obj = Handle<JSObject> memory_obj =
isolate->factory()->NewJSObject(memory_ctor, TENURED); isolate->factory()->NewJSObject(memory_ctor, TENURED);
memory_obj->SetInternalField(kWrapperTracerHeader, Smi::kZero);
memory_obj->SetInternalField(kArrayBuffer, *buffer); memory_obj->SetInternalField(kArrayBuffer, *buffer);
Handle<Object> max = isolate->factory()->NewNumber(maximum); Handle<Object> max = isolate->factory()->NewNumber(maximum);
memory_obj->SetInternalField(kMaximum, *max); memory_obj->SetInternalField(kMaximum, *max);
...@@ -447,6 +451,8 @@ Handle<WasmInstanceObject> WasmInstanceObject::New( ...@@ -447,6 +451,8 @@ Handle<WasmInstanceObject> WasmInstanceObject::New(
isolate->native_context()->wasm_instance_constructor()); isolate->native_context()->wasm_instance_constructor());
Handle<JSObject> instance_object = Handle<JSObject> instance_object =
isolate->factory()->NewJSObject(instance_cons, TENURED); isolate->factory()->NewJSObject(instance_cons, TENURED);
instance_object->SetInternalField(kWrapperTracerHeader, Smi::kZero);
Handle<Symbol> instance_sym(isolate->native_context()->wasm_instance_sym()); Handle<Symbol> instance_sym(isolate->native_context()->wasm_instance_sym());
Object::SetProperty(instance_object, instance_sym, instance_object, STRICT) Object::SetProperty(instance_object, instance_sym, instance_object, STRICT)
.Check(); .Check();
...@@ -499,6 +505,8 @@ Handle<WasmExportedFunction> WasmExportedFunction::New( ...@@ -499,6 +505,8 @@ Handle<WasmExportedFunction> WasmExportedFunction::New(
shared->set_internal_formal_parameter_count(arity); shared->set_internal_formal_parameter_count(arity);
Handle<JSFunction> function = isolate->factory()->NewFunction( Handle<JSFunction> function = isolate->factory()->NewFunction(
isolate->wasm_function_map(), name, export_wrapper); isolate->wasm_function_map(), name, export_wrapper);
function->SetInternalField(kWrapperTracerHeader, Smi::kZero);
function->set_shared(*shared); function->set_shared(*shared);
function->SetInternalField(kInstance, *instance); function->SetInternalField(kInstance, *instance);
...@@ -554,7 +562,7 @@ Handle<WasmSharedModuleData> WasmSharedModuleData::New( ...@@ -554,7 +562,7 @@ Handle<WasmSharedModuleData> WasmSharedModuleData::New(
Handle<ByteArray> asm_js_offset_table) { Handle<ByteArray> asm_js_offset_table) {
Handle<FixedArray> arr = Handle<FixedArray> arr =
isolate->factory()->NewFixedArray(kFieldCount, TENURED); isolate->factory()->NewFixedArray(kFieldCount, TENURED);
arr->set(kWrapperTracerHeader, Smi::kZero);
arr->set(kModuleWrapper, *module_wrapper); arr->set(kModuleWrapper, *module_wrapper);
if (!module_bytes.is_null()) { if (!module_bytes.is_null()) {
arr->set(kModuleBytes, *module_bytes); arr->set(kModuleBytes, *module_bytes);
......
...@@ -44,6 +44,7 @@ class WasmInstanceWrapper; ...@@ -44,6 +44,7 @@ class WasmInstanceWrapper;
// Representation of a WebAssembly.Module JavaScript-level object. // Representation of a WebAssembly.Module JavaScript-level object.
class WasmModuleObject : public JSObject { class WasmModuleObject : public JSObject {
public: public:
// If a second field is added, we need a kWrapperTracerHeader field as well.
// TODO(titzer): add the brand as an internal field instead of a property. // TODO(titzer): add the brand as an internal field instead of a property.
enum Fields { kCompiledModule, kFieldCount }; enum Fields { kCompiledModule, kFieldCount };
...@@ -58,8 +59,15 @@ class WasmModuleObject : public JSObject { ...@@ -58,8 +59,15 @@ class WasmModuleObject : public JSObject {
// Representation of a WebAssembly.Table JavaScript-level object. // Representation of a WebAssembly.Table JavaScript-level object.
class WasmTableObject : public JSObject { class WasmTableObject : public JSObject {
public: public:
// The 0-th field is used by the Blink Wrapper Tracer.
// TODO(titzer): add the brand as an internal field instead of a property. // TODO(titzer): add the brand as an internal field instead of a property.
enum Fields { kFunctions, kMaximum, kDispatchTables, kFieldCount }; enum Fields {
kWrapperTracerHeader,
kFunctions,
kMaximum,
kDispatchTables,
kFieldCount
};
DECLARE_CASTS(WasmTableObject); DECLARE_CASTS(WasmTableObject);
DECLARE_ACCESSORS(functions, FixedArray); DECLARE_ACCESSORS(functions, FixedArray);
...@@ -83,8 +91,15 @@ class WasmTableObject : public JSObject { ...@@ -83,8 +91,15 @@ class WasmTableObject : public JSObject {
// Representation of a WebAssembly.Memory JavaScript-level object. // Representation of a WebAssembly.Memory JavaScript-level object.
class WasmMemoryObject : public JSObject { class WasmMemoryObject : public JSObject {
public: public:
// The 0-th field is used by the Blink Wrapper Tracer.
// TODO(titzer): add the brand as an internal field instead of a property. // TODO(titzer): add the brand as an internal field instead of a property.
enum Fields : uint8_t { kArrayBuffer, kMaximum, kInstancesLink, kFieldCount }; enum Fields : uint8_t {
kWrapperTracerHeader,
kArrayBuffer,
kMaximum,
kInstancesLink,
kFieldCount
};
DECLARE_CASTS(WasmMemoryObject); DECLARE_CASTS(WasmMemoryObject);
DECLARE_ACCESSORS(buffer, JSArrayBuffer); DECLARE_ACCESSORS(buffer, JSArrayBuffer);
...@@ -107,8 +122,10 @@ class WasmMemoryObject : public JSObject { ...@@ -107,8 +122,10 @@ class WasmMemoryObject : public JSObject {
// Representation of a WebAssembly.Instance JavaScript-level object. // Representation of a WebAssembly.Instance JavaScript-level object.
class WasmInstanceObject : public JSObject { class WasmInstanceObject : public JSObject {
public: public:
// The 0-th field is used by the Blink Wrapper Tracer.
// TODO(titzer): add the brand as an internal field instead of a property. // TODO(titzer): add the brand as an internal field instead of a property.
enum Fields { enum Fields {
kWrapperTracerHeader,
kCompiledModule, kCompiledModule,
kMemoryObject, kMemoryObject,
kMemoryArrayBuffer, kMemoryArrayBuffer,
...@@ -142,7 +159,8 @@ class WasmInstanceObject : public JSObject { ...@@ -142,7 +159,8 @@ class WasmInstanceObject : public JSObject {
// Representation of an exported WASM function. // Representation of an exported WASM function.
class WasmExportedFunction : public JSFunction { class WasmExportedFunction : public JSFunction {
public: public:
enum Fields { kInstance, kIndex, kFieldCount }; // The 0-th field is used by the Blink Wrapper Tracer.
enum Fields { kWrapperTracerHeader, kInstance, kIndex, kFieldCount };
DECLARE_CASTS(WasmExportedFunction); DECLARE_CASTS(WasmExportedFunction);
...@@ -158,7 +176,9 @@ class WasmExportedFunction : public JSFunction { ...@@ -158,7 +176,9 @@ class WasmExportedFunction : public JSFunction {
// Information shared by all WasmCompiledModule objects for the same module. // Information shared by all WasmCompiledModule objects for the same module.
class WasmSharedModuleData : public FixedArray { class WasmSharedModuleData : public FixedArray {
// The 0-th field is used by the Blink Wrapper Tracer.
enum Fields { enum Fields {
kWrapperTracerHeader,
kModuleWrapper, kModuleWrapper,
kModuleBytes, kModuleBytes,
kScript, kScript,
...@@ -408,7 +428,9 @@ class WasmCompiledModule : public FixedArray { ...@@ -408,7 +428,9 @@ class WasmCompiledModule : public FixedArray {
class WasmDebugInfo : public FixedArray { class WasmDebugInfo : public FixedArray {
public: public:
// The 0-th field is used by the Blink Wrapper Tracer.
enum Fields { enum Fields {
kWrapperTracerHeader,
kInstance, kInstance,
kInterpreterHandle, kInterpreterHandle,
kInterpretedFunctions, kInterpretedFunctions,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment