Title: [253280] trunk
Revision
253280
Author
[email protected]
Date
2019-12-08 17:35:16 -0800 (Sun, 08 Dec 2019)

Log Message

[WebAssembly] Fix LLIntGenerator's checkConsistency contract
https://bugs.webkit.org/show_bug.cgi?id=204998
<rdar://problem/57733405>

Reviewed by Mark Lam.

JSTests:

* wasm/regress/stack-consistency.js: Added.

Source/_javascript_Core:

We check the consistency of the WebAssembly parser's _expression_ stack every time the LLIntGenerator calls
push to allocate a new stack value. However, if we call push more than once (e.g. in a loop), the stack
is no longer consistent, since those values have not yet been placed in the parser's _expression_ stack, so
the generator and parser's stacks are out of sync. Instead, whenever we need to push multiple values, we
should first manually call checkConsistency before any pushes, and all pushes after that should be replaced
with push(NoConsistencyCheck).

* wasm/WasmLLIntGenerator.cpp:
(JSC::Wasm::LLIntGenerator::callInformationForCaller):
(JSC::Wasm::LLIntGenerator::addArguments):
(JSC::Wasm::LLIntGenerator::addLocal):

Modified Paths

Added Paths

Diff

Modified: trunk/JSTests/ChangeLog (253279 => 253280)


--- trunk/JSTests/ChangeLog	2019-12-08 23:27:25 UTC (rev 253279)
+++ trunk/JSTests/ChangeLog	2019-12-09 01:35:16 UTC (rev 253280)
@@ -1,3 +1,13 @@
+2019-12-08  Tadeu Zagallo  <[email protected]>
+
+        [WebAssembly] Fix LLIntGenerator's checkConsistency contract
+        https://bugs.webkit.org/show_bug.cgi?id=204998
+        <rdar://problem/57733405>
+
+        Reviewed by Mark Lam.
+
+        * wasm/regress/stack-consistency.js: Added.
+
 2019-12-08  Caio Lima  <[email protected]>
 
         [ARMv7] Skip flaky stress tests

Added: trunk/JSTests/wasm/regress/stack-consistency.js (0 => 253280)


--- trunk/JSTests/wasm/regress/stack-consistency.js	                        (rev 0)
+++ trunk/JSTests/wasm/regress/stack-consistency.js	2019-12-09 01:35:16 UTC (rev 253280)
@@ -0,0 +1,12 @@
+import { instantiate } from "../wabt-wrapper.js";
+
+instantiate(`
+(module
+  (func $foo (result i32 i32) unreachable)
+  (func (param i32) (result i32 i32 i32)
+        (local.get 0)
+        (loop (param i32) (result i32 i32 i32)
+              call $foo)
+        )
+  )
+`);

Modified: trunk/Source/_javascript_Core/ChangeLog (253279 => 253280)


--- trunk/Source/_javascript_Core/ChangeLog	2019-12-08 23:27:25 UTC (rev 253279)
+++ trunk/Source/_javascript_Core/ChangeLog	2019-12-09 01:35:16 UTC (rev 253280)
@@ -1,3 +1,23 @@
+2019-12-08  Tadeu Zagallo  <[email protected]>
+
+        [WebAssembly] Fix LLIntGenerator's checkConsistency contract
+        https://bugs.webkit.org/show_bug.cgi?id=204998
+        <rdar://problem/57733405>
+
+        Reviewed by Mark Lam.
+
+        We check the consistency of the WebAssembly parser's _expression_ stack every time the LLIntGenerator calls
+        push to allocate a new stack value. However, if we call push more than once (e.g. in a loop), the stack
+        is no longer consistent, since those values have not yet been placed in the parser's _expression_ stack, so
+        the generator and parser's stacks are out of sync. Instead, whenever we need to push multiple values, we
+        should first manually call checkConsistency before any pushes, and all pushes after that should be replaced
+        with push(NoConsistencyCheck).
+
+        * wasm/WasmLLIntGenerator.cpp:
+        (JSC::Wasm::LLIntGenerator::callInformationForCaller):
+        (JSC::Wasm::LLIntGenerator::addArguments):
+        (JSC::Wasm::LLIntGenerator::addLocal):
+
 2019-12-07  Mark Lam  <[email protected]>
 
         Object.prototype.isPrototypeOf() should check if the passed in value is a non-object first.

Modified: trunk/Source/_javascript_Core/wasm/WasmLLIntGenerator.cpp (253279 => 253280)


--- trunk/Source/_javascript_Core/wasm/WasmLLIntGenerator.cpp	2019-12-08 23:27:25 UTC (rev 253279)
+++ trunk/Source/_javascript_Core/wasm/WasmLLIntGenerator.cpp	2019-12-09 01:35:16 UTC (rev 253280)
@@ -591,8 +591,9 @@
     m_stackSize = initialStackSize;
 
     auto commitResults = [this, temporaryResults = WTFMove(temporaryResults)](ResultList& results) {
+        checkConsistency();
         for (auto temporaryResult : temporaryResults) {
-            ExpressionType result = push();
+            ExpressionType result = push(NoConsistencyCheck);
             WasmMov::emit(this, result, temporaryResult);
             results.append(result);
         }
@@ -647,6 +648,8 @@
 
 auto LLIntGenerator::addArguments(const Signature& signature) -> PartialResult
 {
+    checkConsistency();
+
     m_codeBlock->m_numArguments = signature.argumentCount();
     m_normalizedArguments.resize(m_codeBlock->m_numArguments);
 
@@ -661,7 +664,7 @@
 
     Vector<VirtualRegister> registerArguments(gprCount + fprCount);
     for (uint32_t i = 0; i < gprCount + fprCount; i++)
-        registerArguments[i] = push();
+        registerArguments[i] = push(NoConsistencyCheck);
 
     const auto addArgument = [&](uint32_t index, uint32_t& count, uint32_t max) {
         if (count < max)
@@ -695,12 +698,14 @@
 
 auto LLIntGenerator::addLocal(Type type, uint32_t count) -> PartialResult
 {
+    checkConsistency();
+
     m_codeBlock->m_numVars += count;
     switch (type) {
     case Type::Anyref:
     case Type::Funcref:
         while (count--)
-            m_unitializedLocals.append(push());
+            m_unitializedLocals.append(push(NoConsistencyCheck));
         break;
     default:
         m_stackSize += count;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to