Commit 15428f19 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Register protected instructions after deserialization

R=mstarzinger@chromium.org

Bug: chromium:856938
Change-Id: I57699de23b5c35a531c7601fd14a91f075abb0da
Reviewed-on: https://chromium-review.googlesource.com/1117182
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54085}
parent 37ca8c3d
...@@ -539,7 +539,7 @@ WasmCode* NativeModule::AddCode( ...@@ -539,7 +539,7 @@ WasmCode* NativeModule::AddCode(
} }
} }
if (use_trap_handler_) { if (!ret->protected_instructions_.is_empty()) {
ret->RegisterTrapHandlerData(); ret->RegisterTrapHandlerData();
} }
set_code(index, ret); set_code(index, ret);
...@@ -568,6 +568,9 @@ WasmCode* NativeModule::AddDeserializedCode( ...@@ -568,6 +568,9 @@ WasmCode* NativeModule::AddDeserializedCode(
std::move(reloc_info), std::move(source_position_table), std::move(reloc_info), std::move(source_position_table),
WasmCode::kFunction, tier, WasmCode::kNoFlushICache); WasmCode::kFunction, tier, WasmCode::kNoFlushICache);
if (!code->protected_instructions_.is_empty()) {
code->RegisterTrapHandlerData();
}
set_code(index, code); set_code(index, code);
PatchJumpTable(index, code->instruction_start(), WasmCode::kFlushICache); PatchJumpTable(index, code->instruction_start(), WasmCode::kFlushICache);
// Note: we do not flush the i-cache here, since the code needs to be // Note: we do not flush the i-cache here, since the code needs to be
......
...@@ -8,6 +8,7 @@ load("test/mjsunit/wasm/wasm-constants.js"); ...@@ -8,6 +8,7 @@ load("test/mjsunit/wasm/wasm-constants.js");
load("test/mjsunit/wasm/wasm-module-builder.js"); load("test/mjsunit/wasm/wasm-module-builder.js");
(function SerializeAndDeserializeModule() { (function SerializeAndDeserializeModule() {
print(arguments.callee.name);
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
builder.addImportedMemory("", "memory", 1); builder.addImportedMemory("", "memory", 1);
var kSig_v_i = makeSig([kWasmI32], []); var kSig_v_i = makeSig([kWasmI32], []);
...@@ -75,6 +76,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -75,6 +76,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
})(); })();
(function DeserializeInvalidObject() { (function DeserializeInvalidObject() {
print(arguments.callee.name);
var invalid_buffer = new ArrayBuffer(10); var invalid_buffer = new ArrayBuffer(10);
module = %DeserializeWasmModule(invalid_buffer, invalid_buffer); module = %DeserializeWasmModule(invalid_buffer, invalid_buffer);
...@@ -82,6 +84,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -82,6 +84,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
})(); })();
(function RelationBetweenModuleAndClone() { (function RelationBetweenModuleAndClone() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder(); let builder = new WasmModuleBuilder();
builder.addFunction("main", kSig_i_v) builder.addFunction("main", kSig_i_v)
.addBody([kExprI32Const, 42]) .addBody([kExprI32Const, 42])
...@@ -99,6 +102,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -99,6 +102,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
})(); })();
(function SerializeWrappersWithSameSignature() { (function SerializeWrappersWithSameSignature() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder(); let builder = new WasmModuleBuilder();
builder.addFunction("main", kSig_i_v) builder.addFunction("main", kSig_i_v)
.addBody([kExprI32Const, 42]) .addBody([kExprI32Const, 42])
...@@ -119,6 +123,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -119,6 +123,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
})(); })();
(function SerializeAfterInstantiation() { (function SerializeAfterInstantiation() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder(); let builder = new WasmModuleBuilder();
builder.addFunction("main", kSig_i_v) builder.addFunction("main", kSig_i_v)
.addBody([kExprI32Const, 42]) .addBody([kExprI32Const, 42])
...@@ -141,6 +146,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -141,6 +146,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
(function SerializeAfterInstantiationWithMemory() { (function SerializeAfterInstantiationWithMemory() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder(); let builder = new WasmModuleBuilder();
builder.addImportedMemory("", "memory", 1); builder.addImportedMemory("", "memory", 1);
builder.addFunction("main", kSig_i_v) builder.addFunction("main", kSig_i_v)
...@@ -164,6 +170,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -164,6 +170,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
})(); })();
(function GlobalsArePrivateBetweenClones() { (function GlobalsArePrivateBetweenClones() {
print(arguments.callee.name);
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
builder.addGlobal(kWasmI32, true); builder.addGlobal(kWasmI32, true);
builder.addFunction("read", kSig_i_v) builder.addFunction("read", kSig_i_v)
...@@ -191,6 +198,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -191,6 +198,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
})(); })();
(function SharedTableTest() { (function SharedTableTest() {
print(arguments.callee.name);
let kTableSize = 3; let kTableSize = 3;
var sig_index1; var sig_index1;
...@@ -264,6 +272,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -264,6 +272,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
})(); })();
(function StackOverflowAfterSerialization() { (function StackOverflowAfterSerialization() {
print(arguments.callee.name);
const builder = new WasmModuleBuilder(); const builder = new WasmModuleBuilder();
var fun = builder.addFunction('main', kSig_v_v); var fun = builder.addFunction('main', kSig_v_v);
fun.addBody([kExprCallFunction, fun.index]); fun.addBody([kExprCallFunction, fun.index]);
...@@ -277,3 +286,26 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -277,3 +286,26 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
assertThrows(instance.exports.main, RangeError); assertThrows(instance.exports.main, RangeError);
})(); })();
(function TrapAfterDeserialization() {
print(arguments.callee.name);
function GenerateSerializedModule() {
const builder = new WasmModuleBuilder();
builder.addMemory(1, 1);
builder.addFunction('main', kSig_i_i)
.addBody([kExprGetLocal, 0, kExprI32LoadMem, 0, 0])
.exportFunc();
const wire_bytes = builder.toBuffer();
const module = new WebAssembly.Module(wire_bytes);
const buffer = %SerializeWasmModule(module);
return [wire_bytes, buffer];
}
const [wire_bytes, buffer] = GenerateSerializedModule();
module = %DeserializeWasmModule(buffer, wire_bytes);
const instance = new WebAssembly.Instance(module);
assertEquals(0, instance.exports.main(0));
assertEquals(0, instance.exports.main(kPageSize - 4));
assertTraps(
kTrapMemOutOfBounds, _ => instance.exports.main(kPageSize - 3));
})();
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