Commit 084207d9 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Use engine's allocator consistently

Using the Isolate's allocator when creating the WasmModule can lead to
use-after-free situations when the NativeModule is shared across
Isolates.

R=mstarzinger@chromium.org

Bug: v8:9079
Change-Id: I5a564852179cc5b9d4cbad2a002d3b6e14b01968
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1550404Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60605}
parent ab55cc73
...@@ -613,9 +613,10 @@ MaybeHandle<WasmModuleObject> DeserializeNativeModule( ...@@ -613,9 +613,10 @@ MaybeHandle<WasmModuleObject> DeserializeNativeModule(
ModuleWireBytes wire_bytes(wire_bytes_vec); ModuleWireBytes wire_bytes(wire_bytes_vec);
// TODO(titzer): module features should be part of the serialization format. // TODO(titzer): module features should be part of the serialization format.
WasmFeatures enabled_features = WasmFeaturesFromIsolate(isolate); WasmFeatures enabled_features = WasmFeaturesFromIsolate(isolate);
ModuleResult decode_result = DecodeWasmModule( ModuleResult decode_result =
enabled_features, wire_bytes.start(), wire_bytes.end(), false, DecodeWasmModule(enabled_features, wire_bytes.start(), wire_bytes.end(),
i::wasm::kWasmOrigin, isolate->counters(), isolate->allocator()); false, i::wasm::kWasmOrigin, isolate->counters(),
isolate->wasm_engine()->allocator());
if (decode_result.failed()) return {}; if (decode_result.failed()) return {};
CHECK_NOT_NULL(decode_result.value()); CHECK_NOT_NULL(decode_result.value());
WasmModule* module = decode_result.value().get(); WasmModule* module = decode_result.value().get();
......
...@@ -264,7 +264,7 @@ size_t GetFunctionOffset(i::Isolate* isolate, const uint8_t* buffer, ...@@ -264,7 +264,7 @@ size_t GetFunctionOffset(i::Isolate* isolate, const uint8_t* buffer,
size_t size, size_t index) { size_t size, size_t index) {
ModuleResult result = DecodeWasmModule( ModuleResult result = DecodeWasmModule(
kAllWasmFeatures, buffer, buffer + size, false, ModuleOrigin::kWasmOrigin, kAllWasmFeatures, buffer, buffer + size, false, ModuleOrigin::kWasmOrigin,
isolate->counters(), isolate->allocator()); isolate->counters(), isolate->wasm_engine()->allocator());
CHECK(result.ok()); CHECK(result.ok());
const WasmFunction* func = &result.value()->functions[1]; const WasmFunction* func = &result.value()->functions[1];
return func->code.offset(); return func->code.offset();
......
...@@ -46,7 +46,7 @@ std::shared_ptr<WasmModule> DecodeWasmModuleForTesting( ...@@ -46,7 +46,7 @@ std::shared_ptr<WasmModule> DecodeWasmModuleForTesting(
auto enabled_features = WasmFeaturesFromIsolate(isolate); auto enabled_features = WasmFeaturesFromIsolate(isolate);
ModuleResult decoding_result = DecodeWasmModule( ModuleResult decoding_result = DecodeWasmModule(
enabled_features, module_start, module_end, verify_functions, origin, enabled_features, module_start, module_end, verify_functions, origin,
isolate->counters(), isolate->allocator()); isolate->counters(), isolate->wasm_engine()->allocator());
if (decoding_result.failed()) { if (decoding_result.failed()) {
// Module verification failed. throw. // Module verification failed. throw.
......
...@@ -116,7 +116,8 @@ void GenerateTestCase(Isolate* isolate, ModuleWireBytes wire_bytes, ...@@ -116,7 +116,8 @@ void GenerateTestCase(Isolate* isolate, ModuleWireBytes wire_bytes,
auto enabled_features = i::wasm::WasmFeaturesFromIsolate(isolate); auto enabled_features = i::wasm::WasmFeaturesFromIsolate(isolate);
ModuleResult module_res = DecodeWasmModule( ModuleResult module_res = DecodeWasmModule(
enabled_features, wire_bytes.start(), wire_bytes.end(), kVerifyFunctions, enabled_features, wire_bytes.start(), wire_bytes.end(), kVerifyFunctions,
ModuleOrigin::kWasmOrigin, isolate->counters(), isolate->allocator()); ModuleOrigin::kWasmOrigin, isolate->counters(),
isolate->wasm_engine()->allocator());
CHECK(module_res.ok()); CHECK(module_res.ok());
WasmModule* module = module_res.value().get(); WasmModule* module = module_res.value().get();
CHECK_NOT_NULL(module); CHECK_NOT_NULL(module);
......
...@@ -186,7 +186,7 @@ class WasmModuleVerifyTest : public TestWithIsolateAndZone { ...@@ -186,7 +186,7 @@ class WasmModuleVerifyTest : public TestWithIsolateAndZone {
} }
ModuleResult result = DecodeWasmModule( ModuleResult result = DecodeWasmModule(
enabled_features_, temp, temp + total, false, kWasmOrigin, enabled_features_, temp, temp + total, false, kWasmOrigin,
isolate()->counters(), isolate()->allocator()); isolate()->counters(), isolate()->wasm_engine()->allocator());
delete[] temp; delete[] temp;
return result; return result;
} }
...@@ -194,7 +194,7 @@ class WasmModuleVerifyTest : public TestWithIsolateAndZone { ...@@ -194,7 +194,7 @@ class WasmModuleVerifyTest : public TestWithIsolateAndZone {
const byte* module_end) { const byte* module_end) {
return DecodeWasmModule(enabled_features_, module_start, module_end, false, return DecodeWasmModule(enabled_features_, module_start, module_end, false,
kWasmOrigin, isolate()->counters(), kWasmOrigin, isolate()->counters(),
isolate()->allocator()); isolate()->wasm_engine()->allocator());
} }
}; };
......
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