forked from WebKit/WebKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JSC] wasm unaligned atomic accesses should trap with "Unaligned" rat…
…her than "Out of bounds" https://bugs.webkit.org/show_bug.cgi?id=278412 rdar://103442167 Reviewed by Yusuke Suzuki. Introduce a new wasm trap for "Unaligned memory access" and use it when atomic alignment is checked. Previously, unaligned atomic accesses would produce an "Out of bounds memory access" trap. * JSTests/wasm/stress/atomic-unaligned-traps.js: Added. (genAtomicInstr): (genWat): (async test): * Source/JavaScriptCore/llint/InPlaceInterpreter64.asm: * Source/JavaScriptCore/llint/WebAssembly32_64.asm: * Source/JavaScriptCore/llint/WebAssembly64.asm: * Source/JavaScriptCore/wasm/WasmBBQJIT32_64.cpp: (JSC::Wasm::BBQJITImpl::BBQJIT::emitAtomicLoadOp): (JSC::Wasm::BBQJITImpl::BBQJIT::emitAtomicStoreOp): (JSC::Wasm::BBQJITImpl::BBQJIT::emitAtomicBinaryRMWOp): (JSC::Wasm::BBQJITImpl::BBQJIT::emitAtomicCompareExchange): * Source/JavaScriptCore/wasm/WasmBBQJIT64.cpp: (JSC::Wasm::BBQJITImpl::BBQJIT::emitAtomicLoadOp): (JSC::Wasm::BBQJITImpl::BBQJIT::emitAtomicStoreOp): (JSC::Wasm::BBQJITImpl::BBQJIT::emitAtomicBinaryRMWOp): (JSC::Wasm::BBQJITImpl::BBQJIT::emitAtomicCompareExchange): * Source/JavaScriptCore/wasm/WasmExceptionType.h: (JSC::Wasm::isTypeErrorExceptionType): * Source/JavaScriptCore/wasm/WasmOMGIRGenerator.cpp: (JSC::Wasm::OMGIRGenerator::fixupPointerPlusOffsetForAtomicOps): * Source/JavaScriptCore/wasm/WasmOMGIRGenerator32_64.cpp: (JSC::Wasm::OMGIRGenerator::fixupPointerPlusOffsetForAtomicOps): Canonical link: https://commits.webkit.org/282561@main
- Loading branch information
1 parent
ae24b30
commit 8e565ca
Showing
9 changed files
with
104 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { instantiate } from "../wabt-wrapper.js"; | ||
import * as assert from "../assert.js"; | ||
|
||
const verbose = false; | ||
|
||
function genAtomicInstr(op, subOp, typeSz, accessSz) { | ||
let opSz = ''; | ||
|
||
if (subOp != '') | ||
subOp = '.' + subOp; // rmw ops | ||
|
||
if (typeSz != accessSz) { | ||
opSz = `${accessSz}`; | ||
if (op != 'store') | ||
subOp += '_u'; | ||
} | ||
return `i${typeSz}.atomic.${op}${opSz}${subOp}` | ||
} | ||
|
||
function genWat(op, subOp, typeSz, accessSz) { | ||
const instr = genAtomicInstr(op, subOp, typeSz, accessSz); | ||
let expected = '', operand = '', retVal = ''; | ||
if (op == 'store') { | ||
operand = `i${typeSz}.const 42`; | ||
retVal = `i${typeSz}.const 7`; | ||
} else if (op == 'rmw') { | ||
operand = `i${typeSz}.const 80`; | ||
if (subOp == 'cmpxchg') | ||
expected = `i${typeSz}.const 13`; | ||
} | ||
let wat = ` | ||
(module | ||
(func (export "test") (param $addr i32) (result i${typeSz}) | ||
local.get $addr | ||
${expected} | ||
${operand} | ||
${instr} | ||
${retVal} | ||
) | ||
(memory 1) | ||
) | ||
`; | ||
if (verbose) | ||
print(wat + '\n'); | ||
return wat; | ||
} | ||
|
||
async function test(op, subOp, typeSz, accessSz) { | ||
const instance = await instantiate(genWat(op, subOp, typeSz, accessSz), {}, {threads: true}); | ||
const {test} = instance.exports; | ||
assert.throws(() => { | ||
test(1); | ||
}, WebAssembly.RuntimeError, `Unaligned memory access`); | ||
} | ||
|
||
for (const op of ['load', 'store']) { | ||
for (const typeSz of [32, 64]) { | ||
for (let accessSz = typeSz; accessSz >= 16; accessSz /= 2) | ||
await assert.asyncTest(test(op, '', typeSz, accessSz)); | ||
} | ||
} | ||
|
||
// RMW operators | ||
for (const subOp of ['add', 'sub', 'and', 'or', 'xor', 'xchg', 'cmpxchg']) { | ||
for (const typeSz of [32, 64]) { | ||
for (let accessSz = typeSz; accessSz >= 16; accessSz /= 2) | ||
await assert.asyncTest(test('rmw', subOp, typeSz, accessSz)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters